Home | History | Annotate | Line # | Download | only in mcbus
mcbus.c revision 1.8.4.2
      1  1.8.4.2  nathanw /* $NetBSD: mcbus.c,v 1.8.4.2 2002/10/18 02:34:17 nathanw Exp $ */
      2  1.8.4.2  nathanw 
      3  1.8.4.2  nathanw /*
      4  1.8.4.2  nathanw  * Copyright (c) 1998 by Matthew Jacob
      5  1.8.4.2  nathanw  * NASA AMES Research Center.
      6  1.8.4.2  nathanw  * All rights reserved.
      7  1.8.4.2  nathanw  *
      8  1.8.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.8.4.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.8.4.2  nathanw  * are met:
     11  1.8.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.8.4.2  nathanw  *    notice immediately at the beginning of the file, without modification,
     13  1.8.4.2  nathanw  *    this list of conditions, and the following disclaimer.
     14  1.8.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.8.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     16  1.8.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     17  1.8.4.2  nathanw  * 3. The name of the author may not be used to endorse or promote products
     18  1.8.4.2  nathanw  *    derived from this software without specific prior written permission.
     19  1.8.4.2  nathanw  *
     20  1.8.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     21  1.8.4.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  1.8.4.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  1.8.4.2  nathanw  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     24  1.8.4.2  nathanw  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  1.8.4.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  1.8.4.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  1.8.4.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  1.8.4.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  1.8.4.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  1.8.4.2  nathanw  * SUCH DAMAGE.
     31  1.8.4.2  nathanw  */
     32  1.8.4.2  nathanw 
     33  1.8.4.2  nathanw /*
     34  1.8.4.2  nathanw  * Autoconfiguration routines for the MCBUS system
     35  1.8.4.2  nathanw  * bus found on AlphaServer 4100 systems.
     36  1.8.4.2  nathanw  */
     37  1.8.4.2  nathanw 
     38  1.8.4.2  nathanw #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     39  1.8.4.2  nathanw 
     40  1.8.4.2  nathanw __KERNEL_RCSID(0, "$NetBSD: mcbus.c,v 1.8.4.2 2002/10/18 02:34:17 nathanw Exp $");
     41  1.8.4.2  nathanw 
     42  1.8.4.2  nathanw #include <sys/param.h>
     43  1.8.4.2  nathanw #include <sys/systm.h>
     44  1.8.4.2  nathanw #include <sys/device.h>
     45  1.8.4.2  nathanw #include <sys/malloc.h>
     46  1.8.4.2  nathanw 
     47  1.8.4.2  nathanw #include <machine/autoconf.h>
     48  1.8.4.2  nathanw #include <machine/rpb.h>
     49  1.8.4.2  nathanw #include <machine/pte.h>
     50  1.8.4.2  nathanw 
     51  1.8.4.2  nathanw #include <alpha/mcbus/mcbusreg.h>
     52  1.8.4.2  nathanw #include <alpha/mcbus/mcbusvar.h>
     53  1.8.4.2  nathanw 
     54  1.8.4.2  nathanw #include <alpha/pci/mcpciareg.h>
     55  1.8.4.2  nathanw 
     56  1.8.4.2  nathanw #include "locators.h"
     57  1.8.4.2  nathanw 
     58  1.8.4.2  nathanw #define KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
     59  1.8.4.2  nathanw #define	MCPCIA_EXISTS(mid, gid)	\
     60  1.8.4.2  nathanw 	(!badaddr((void *)KV(MCPCIA_BRIDGE_ADDR(gid, mid)), sizeof (u_int32_t)))
     61  1.8.4.2  nathanw 
     62  1.8.4.2  nathanw extern struct cfdriver mcbus_cd;
     63  1.8.4.2  nathanw 
     64  1.8.4.2  nathanw struct mcbus_cpu_busdep mcbus_primary;
     65  1.8.4.2  nathanw 
     66  1.8.4.2  nathanw static int	mcbusmatch __P((struct device *, struct cfdata *, void *));
     67  1.8.4.2  nathanw static void	mcbusattach __P((struct device *, struct device *, void *));
     68  1.8.4.2  nathanw static int	mcbusprint __P((void *, const char *));
     69  1.8.4.2  nathanw static int	mcbussbm __P((struct device *, struct cfdata *, void *));
     70  1.8.4.2  nathanw static char	*mcbus_node_type_str __P((u_int8_t));
     71  1.8.4.2  nathanw 
     72  1.8.4.2  nathanw typedef struct {
     73  1.8.4.2  nathanw 	struct device	mcbus_dev;
     74  1.8.4.2  nathanw 	u_int8_t	mcbus_types[MCBUS_MID_MAX];
     75  1.8.4.2  nathanw } mcbus_softc_t;
     76  1.8.4.2  nathanw 
     77  1.8.4.2  nathanw CFATTACH_DECL(mcbus, sizeof (mcbus_softc_t),
     78  1.8.4.2  nathanw     mcbusmatch, mcbusattach, NULL, NULL);
     79  1.8.4.2  nathanw 
     80  1.8.4.2  nathanw /*
     81  1.8.4.2  nathanw  * Tru64 UNIX (formerly Digital UNIX (formerly DEC OSF/1)) probes for MCPCIAs
     82  1.8.4.2  nathanw  * in the following order:
     83  1.8.4.2  nathanw  *
     84  1.8.4.2  nathanw  *	5, 4, 7, 6
     85  1.8.4.2  nathanw  *
     86  1.8.4.2  nathanw  * This is so that the built-in CD-ROM on the internal 53c810 is always
     87  1.8.4.2  nathanw  * dka500.  We probe them in the same order, for consistency.
     88  1.8.4.2  nathanw  */
     89  1.8.4.2  nathanw const int mcbus_mcpcia_probe_order[] = { 5, 4, 7, 6 };
     90  1.8.4.2  nathanw 
     91  1.8.4.2  nathanw extern void mcpcia_config_cleanup __P((void));
     92  1.8.4.2  nathanw 
     93  1.8.4.2  nathanw static int
     94  1.8.4.2  nathanw mcbusprint(aux, cp)
     95  1.8.4.2  nathanw 	void *aux;
     96  1.8.4.2  nathanw 	const char *cp;
     97  1.8.4.2  nathanw {
     98  1.8.4.2  nathanw 	struct mcbus_dev_attach_args *tap = aux;
     99  1.8.4.2  nathanw 	printf(" mid %d: %s", tap->ma_mid, mcbus_node_type_str(tap->ma_type));
    100  1.8.4.2  nathanw 	return (UNCONF);
    101  1.8.4.2  nathanw }
    102  1.8.4.2  nathanw 
    103  1.8.4.2  nathanw static int
    104  1.8.4.2  nathanw mcbussbm(parent, cf, aux)
    105  1.8.4.2  nathanw 	struct device *parent;
    106  1.8.4.2  nathanw 	struct cfdata *cf;
    107  1.8.4.2  nathanw 	void *aux;
    108  1.8.4.2  nathanw {
    109  1.8.4.2  nathanw 	struct mcbus_dev_attach_args *tap = aux;
    110  1.8.4.2  nathanw 	if (tap->ma_name != mcbus_cd.cd_name)
    111  1.8.4.2  nathanw 		return (0);
    112  1.8.4.2  nathanw 	if (cf->cf_loc[MCBUSCF_MID] != MCBUSCF_MID_DEFAULT &&
    113  1.8.4.2  nathanw 	    cf->cf_loc[MCBUSCF_MID] != tap->ma_mid)
    114  1.8.4.2  nathanw 		return (0);
    115  1.8.4.2  nathanw 	return (config_match(parent, cf, aux));
    116  1.8.4.2  nathanw }
    117  1.8.4.2  nathanw 
    118  1.8.4.2  nathanw static int
    119  1.8.4.2  nathanw mcbusmatch(parent, cf, aux)
    120  1.8.4.2  nathanw 	struct device *parent;
    121  1.8.4.2  nathanw 	struct cfdata *cf;
    122  1.8.4.2  nathanw 	void *aux;
    123  1.8.4.2  nathanw {
    124  1.8.4.2  nathanw 	struct mainbus_attach_args *ma = aux;
    125  1.8.4.2  nathanw 
    126  1.8.4.2  nathanw 	/* Make sure we're looking for a MCBUS. */
    127  1.8.4.2  nathanw 	if (strcmp(ma->ma_name, mcbus_cd.cd_name) != 0)
    128  1.8.4.2  nathanw 		return (0);
    129  1.8.4.2  nathanw 
    130  1.8.4.2  nathanw 	/*
    131  1.8.4.2  nathanw 	 * Only available on 4100 processor type platforms.
    132  1.8.4.2  nathanw 	 */
    133  1.8.4.2  nathanw 	if (cputype != ST_DEC_4100)
    134  1.8.4.2  nathanw 		return (0);
    135  1.8.4.2  nathanw 	return (1);
    136  1.8.4.2  nathanw }
    137  1.8.4.2  nathanw 
    138  1.8.4.2  nathanw static void
    139  1.8.4.2  nathanw mcbusattach(parent, self, aux)
    140  1.8.4.2  nathanw 	struct device *parent;
    141  1.8.4.2  nathanw 	struct device *self;
    142  1.8.4.2  nathanw 	void *aux;
    143  1.8.4.2  nathanw {
    144  1.8.4.2  nathanw 	static const char * const bcs[CPU_BCacheMask + 1] = {
    145  1.8.4.2  nathanw 		"No", "1MB", "2MB", "4MB",
    146  1.8.4.2  nathanw 	};
    147  1.8.4.2  nathanw 	struct mcbus_dev_attach_args ta;
    148  1.8.4.2  nathanw 	mcbus_softc_t *mbp = (mcbus_softc_t *)self;
    149  1.8.4.2  nathanw 	int i, mid;
    150  1.8.4.2  nathanw 
    151  1.8.4.2  nathanw 	printf(": %s BCache\n", mcbus_primary.mcbus_valid ?
    152  1.8.4.2  nathanw 	    bcs[mcbus_primary.mcbus_bcache] : "Unknown");
    153  1.8.4.2  nathanw 
    154  1.8.4.2  nathanw 	mbp->mcbus_types[0] = MCBUS_TYPE_RES;
    155  1.8.4.2  nathanw 	for (mid = 1; mid <= MCBUS_MID_MAX; ++mid)
    156  1.8.4.2  nathanw 		mbp->mcbus_types[mid] = MCBUS_TYPE_UNK;
    157  1.8.4.2  nathanw 
    158  1.8.4.2  nathanw 	/*
    159  1.8.4.2  nathanw 	 * Find and "configure" memory.
    160  1.8.4.2  nathanw 	 */
    161  1.8.4.2  nathanw 	ta.ma_name = mcbus_cd.cd_name;
    162  1.8.4.2  nathanw 
    163  1.8.4.2  nathanw 	/*
    164  1.8.4.2  nathanw 	 * XXX If we ever support more than one MCBUS, we'll
    165  1.8.4.2  nathanw 	 * XXX have to probe for them, and map them to unit
    166  1.8.4.2  nathanw 	 * XXX numbers.
    167  1.8.4.2  nathanw 	 */
    168  1.8.4.2  nathanw 	ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
    169  1.8.4.2  nathanw 	ta.ma_mid = 1;
    170  1.8.4.2  nathanw 	ta.ma_type = MCBUS_TYPE_MEM;
    171  1.8.4.2  nathanw 	mbp->mcbus_types[1] = MCBUS_TYPE_MEM;
    172  1.8.4.2  nathanw 	(void) config_found_sm(self, &ta, mcbusprint, mcbussbm);
    173  1.8.4.2  nathanw 
    174  1.8.4.2  nathanw 	/*
    175  1.8.4.2  nathanw 	 * Now find PCI busses.
    176  1.8.4.2  nathanw 	 */
    177  1.8.4.2  nathanw 	for (i = 0; i < MCPCIA_PER_MCBUS; i++) {
    178  1.8.4.2  nathanw 		mid = mcbus_mcpcia_probe_order[i];
    179  1.8.4.2  nathanw 		ta.ma_name = mcbus_cd.cd_name;
    180  1.8.4.2  nathanw 		/*
    181  1.8.4.2  nathanw 		 * XXX If we ever support more than one MCBUS, we'll
    182  1.8.4.2  nathanw 		 * XXX have to probe for them, and map them to unit
    183  1.8.4.2  nathanw 		 * XXX numbers.
    184  1.8.4.2  nathanw 		 */
    185  1.8.4.2  nathanw 		ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
    186  1.8.4.2  nathanw 		ta.ma_mid = mid;
    187  1.8.4.2  nathanw 		ta.ma_type = MCBUS_TYPE_PCI;
    188  1.8.4.2  nathanw 		if (MCPCIA_EXISTS(ta.ma_mid, ta.ma_gid))
    189  1.8.4.2  nathanw 			(void) config_found_sm(self, &ta, mcbusprint, mcbussbm);
    190  1.8.4.2  nathanw 	}
    191  1.8.4.2  nathanw 
    192  1.8.4.2  nathanw #if 0
    193  1.8.4.2  nathanw 	/*
    194  1.8.4.2  nathanw 	 * Deal with hooking CPU instances to MCBUS module ids.
    195  1.8.4.2  nathanw 	 *
    196  1.8.4.2  nathanw 	 * Note that we do this here because it's the read of
    197  1.8.4.2  nathanw 	 * stupid MCPCIA WHOAMI register that can get us the
    198  1.8.4.2  nathanw 	 * module ID and type of the configuring CPU.
    199  1.8.4.2  nathanw 	 */
    200  1.8.4.2  nathanw 
    201  1.8.4.2  nathanw 	if (mcbus_primary.mcbus_valid) {
    202  1.8.4.2  nathanw 		mid = mcbus_primary.mcbus_cpu_mid;
    203  1.8.4.2  nathanw 		printf("%s mid %d: %s %s\n", self->dv_xname,
    204  1.8.4.2  nathanw 		    mid, mcbus_node_type_str(MCBUS_TYPE_CPU),
    205  1.8.4.2  nathanw 		    bcs[mcbus_primary.mcbus_bcache & 0x7]);
    206  1.8.4.2  nathanw 		ta.ma_name = mcbus_cd.cd_name;
    207  1.8.4.2  nathanw 		/*
    208  1.8.4.2  nathanw 		 * XXX If we ever support more than one MCBUS, we'll
    209  1.8.4.2  nathanw 		 * XXX have to probe for them, and map them to unit
    210  1.8.4.2  nathanw 		 * XXX numbers.
    211  1.8.4.2  nathanw 		 */
    212  1.8.4.2  nathanw 		ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
    213  1.8.4.2  nathanw 		ta.ma_mid = mid;
    214  1.8.4.2  nathanw 		ta.ma_type = MCBUS_TYPE_CPU;
    215  1.8.4.2  nathanw 		mbp->mcbus_types[mid] = MCBUS_TYPE_CPU;
    216  1.8.4.2  nathanw 		(void) config_found_sm(self, &ta, mcbusprint, mcbussbm);
    217  1.8.4.2  nathanw 	}
    218  1.8.4.2  nathanw #endif
    219  1.8.4.2  nathanw 
    220  1.8.4.2  nathanw 	/*
    221  1.8.4.2  nathanw 	 * Now clean up after configuring everything.
    222  1.8.4.2  nathanw 	 *
    223  1.8.4.2  nathanw 	 * This is an unfortunate layering violation- but
    224  1.8.4.2  nathanw 	 * we can't enable interrupts until *all* probing
    225  1.8.4.2  nathanw 	 * is done, but the code and knowledge to clean
    226  1.8.4.2  nathanw 	 * up after probing and to enable interrupts is
    227  1.8.4.2  nathanw 	 * down in the MCPCIA layer.
    228  1.8.4.2  nathanw 	 */
    229  1.8.4.2  nathanw 	mcpcia_config_cleanup();
    230  1.8.4.2  nathanw }
    231  1.8.4.2  nathanw 
    232  1.8.4.2  nathanw static char *
    233  1.8.4.2  nathanw mcbus_node_type_str(type)
    234  1.8.4.2  nathanw 	u_int8_t type;
    235  1.8.4.2  nathanw {
    236  1.8.4.2  nathanw 	switch (type) {
    237  1.8.4.2  nathanw 	case MCBUS_TYPE_RES:
    238  1.8.4.2  nathanw 		panic ("RESERVED TYPE IN MCBUS_NODE_TYPE_STR");
    239  1.8.4.2  nathanw 		break;
    240  1.8.4.2  nathanw 	case MCBUS_TYPE_UNK:
    241  1.8.4.2  nathanw 		panic ("UNKNOWN TYPE IN MCBUS_NODE_TYPE_STR");
    242  1.8.4.2  nathanw 		break;
    243  1.8.4.2  nathanw 	case MCBUS_TYPE_MEM:
    244  1.8.4.2  nathanw 		return ("Memory");
    245  1.8.4.2  nathanw 	case MCBUS_TYPE_CPU:
    246  1.8.4.2  nathanw 		return ("CPU");
    247  1.8.4.2  nathanw 	case MCBUS_TYPE_PCI:
    248  1.8.4.2  nathanw 		return ("PCI Bridge");
    249  1.8.4.2  nathanw 	default:
    250  1.8.4.2  nathanw 		panic("REALLY UNKNWON (%x) TYPE IN MCBUS_NODE_TYPE_STR", type);
    251  1.8.4.2  nathanw 		break;
    252  1.8.4.2  nathanw 	}
    253  1.8.4.2  nathanw }
    254