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