Home | History | Annotate | Line # | Download | only in mcbus
mcbus.c revision 1.23.2.1
      1 /* $NetBSD: mcbus.c,v 1.23.2.1 2021/08/01 22:42:01 thorpej 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.23.2.1 2021/08/01 22:42:01 thorpej Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 
     46 #include <machine/autoconf.h>
     47 #include <machine/rpb.h>
     48 #include <machine/pte.h>
     49 
     50 #include <alpha/mcbus/mcbusreg.h>
     51 #include <alpha/mcbus/mcbusvar.h>
     52 
     53 #include <alpha/pci/mcpciareg.h>
     54 
     55 #include "locators.h"
     56 
     57 #define KV(_addr)	((void *)ALPHA_PHYS_TO_K0SEG((_addr)))
     58 #define	MCPCIA_EXISTS(mid, gid)	\
     59 	(!badaddr((void *)KV(MCPCIA_BRIDGE_ADDR(gid, mid)), sizeof (uint32_t)))
     60 
     61 extern struct cfdriver mcbus_cd;
     62 
     63 struct mcbus_cpu_busdep mcbus_primary;
     64 
     65 static int	mcbusmatch(device_t, cfdata_t, void *);
     66 static void	mcbusattach(device_t, device_t, void *);
     67 static int	mcbusprint(void *, const char *);
     68 static const char *mcbus_node_type_str(uint8_t);
     69 
     70 typedef struct {
     71 	uint8_t	mcbus_types[MCBUS_MID_MAX];
     72 } mcbus_softc_t;
     73 
     74 CFATTACH_DECL_NEW(mcbus, sizeof (mcbus_softc_t),
     75     mcbusmatch, mcbusattach, NULL, NULL);
     76 
     77 /*
     78  * Tru64 UNIX (formerly Digital UNIX (formerly DEC OSF/1)) probes for MCPCIAs
     79  * in the following order:
     80  *
     81  *	5, 4, 7, 6
     82  *
     83  * This is so that the built-in CD-ROM on the internal 53c810 is always
     84  * dka500.  We probe them in the same order, for consistency.
     85  */
     86 const int mcbus_mcpcia_probe_order[] = { 5, 4, 7, 6 };
     87 
     88 extern void mcpcia_config_cleanup(void);
     89 
     90 static int
     91 mcbusprint(void *aux, const char *cp)
     92 {
     93 	struct mcbus_dev_attach_args *tap = aux;
     94 	aprint_normal(" mid %d: %s", tap->ma_mid,
     95 	    mcbus_node_type_str(tap->ma_type));
     96 	return (UNCONF);
     97 }
     98 
     99 static int
    100 mcbusmatch(device_t parent, cfdata_t cf, void *aux)
    101 {
    102 	struct mainbus_attach_args *ma = aux;
    103 
    104 	/* Make sure we're looking for a MCBUS. */
    105 	if (strcmp(ma->ma_name, mcbus_cd.cd_name) != 0)
    106 		return (0);
    107 
    108 	/*
    109 	 * Only available on 4100 processor type platforms.
    110 	 */
    111 	if (cputype != ST_DEC_4100)
    112 		return (0);
    113 	return (1);
    114 }
    115 
    116 static void
    117 mcbusattach(device_t parent, device_t self, void *aux)
    118 {
    119 	static const char * const bcs[CPU_BCacheMask + 1] = {
    120 		"No", "1MB", "2MB", "4MB",
    121 	};
    122 	struct mcbus_dev_attach_args ta;
    123 	mcbus_softc_t *mbp = device_private(self);
    124 	int i, mid;
    125 	int locs[MCBUSCF_NLOCS];
    126 
    127 	printf(": %s BCache\n", mcbus_primary.mcbus_valid ?
    128 	    bcs[mcbus_primary.mcbus_bcache] : "Unknown");
    129 
    130 	mbp->mcbus_types[0] = MCBUS_TYPE_RES;
    131 	for (mid = 1; mid < MCBUS_MID_MAX; ++mid)
    132 		mbp->mcbus_types[mid] = MCBUS_TYPE_UNK;
    133 
    134 	/*
    135 	 * Find and "configure" memory.
    136 	 */
    137 
    138 	/*
    139 	 * XXX If we ever support more than one MCBUS, we'll
    140 	 * XXX have to probe for them, and map them to unit
    141 	 * XXX numbers.
    142 	 */
    143 	ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
    144 	ta.ma_mid = 1;
    145 	ta.ma_type = MCBUS_TYPE_MEM;
    146 	mbp->mcbus_types[1] = MCBUS_TYPE_MEM;
    147 	locs[MCBUSCF_MID] = 1;
    148 	config_found(self, &ta, mcbusprint,
    149 	    CFARG_SUBMATCH, config_stdsubmatch,
    150 	    CFARG_LOCATORS, locs,
    151 	    CFARG_EOL);
    152 
    153 	/*
    154 	 * Now find PCI busses.
    155 	 */
    156 	for (i = 0; i < MCPCIA_PER_MCBUS; i++) {
    157 		mid = mcbus_mcpcia_probe_order[i];
    158 		/*
    159 		 * XXX If we ever support more than one MCBUS, we'll
    160 		 * XXX have to probe for them, and map them to unit
    161 		 * XXX numbers.
    162 		 */
    163 		ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
    164 		ta.ma_mid = mid;
    165 		ta.ma_type = MCBUS_TYPE_PCI;
    166 		locs[MCBUSCF_MID] = mid;
    167 		if (MCPCIA_EXISTS(ta.ma_mid, ta.ma_gid))
    168 			config_found(self, &ta, mcbusprint,
    169 			    CFARG_SUBMATCH, config_stdsubmatch,
    170 			    CFARG_LOCATORS, locs,
    171 			    CFARG_EOL);
    172 	}
    173 
    174 #if 0
    175 	/*
    176 	 * Deal with hooking CPU instances to MCBUS module ids.
    177 	 *
    178 	 * Note that we do this here because it's the read of
    179 	 * stupid MCPCIA WHOAMI register that can get us the
    180 	 * module ID and type of the configuring CPU.
    181 	 */
    182 
    183 	if (mcbus_primary.mcbus_valid) {
    184 		mid = mcbus_primary.mcbus_cpu_mid;
    185 		printf("%s mid %d: %s %s\n", device_xname(self),
    186 		    mid, mcbus_node_type_str(MCBUS_TYPE_CPU),
    187 		    bcs[mcbus_primary.mcbus_bcache & 0x7]);
    188 		/*
    189 		 * XXX If we ever support more than one MCBUS, we'll
    190 		 * XXX have to probe for them, and map them to unit
    191 		 * XXX numbers.
    192 		 */
    193 		ta.ma_gid = MCBUS_GID_FROM_INSTANCE(0);
    194 		ta.ma_mid = mid;
    195 		ta.ma_type = MCBUS_TYPE_CPU;
    196 		mbp->mcbus_types[mid] = MCBUS_TYPE_CPU;
    197 		locs[MCBUSCF_MID] = mid;
    198 		config_found(self, &ta, mcbusprint,
    199 		    CFARG_SUBMATCH, config_stdsubmatch,
    200 		    CFARG_LOCATORS, locs,
    201 		    CFARG_EOL);
    202 	}
    203 #endif
    204 
    205 	/*
    206 	 * Now clean up after configuring everything.
    207 	 *
    208 	 * This is an unfortunate layering violation- but
    209 	 * we can't enable interrupts until *all* probing
    210 	 * is done, but the code and knowledge to clean
    211 	 * up after probing and to enable interrupts is
    212 	 * down in the MCPCIA layer.
    213 	 */
    214 	mcpcia_config_cleanup();
    215 }
    216 
    217 static const char *
    218 mcbus_node_type_str(uint8_t type)
    219 {
    220 	switch (type) {
    221 	case MCBUS_TYPE_RES:
    222 		panic ("RESERVED TYPE IN MCBUS_NODE_TYPE_STR");
    223 		break;
    224 	case MCBUS_TYPE_UNK:
    225 		panic ("UNKNOWN TYPE IN MCBUS_NODE_TYPE_STR");
    226 		break;
    227 	case MCBUS_TYPE_MEM:
    228 		return ("Memory");
    229 	case MCBUS_TYPE_CPU:
    230 		return ("CPU");
    231 	case MCBUS_TYPE_PCI:
    232 		return ("PCI Bridge");
    233 	default:
    234 		panic("REALLY UNKNWON (%x) TYPE IN MCBUS_NODE_TYPE_STR", type);
    235 		break;
    236 	}
    237 }
    238