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