Home | History | Annotate | Line # | Download | only in tlsb
tlsb.c revision 1.12
      1 /* $NetBSD: tlsb.c,v 1.12 1998/07/08 01:03:41 mjacob Exp $ */
      2 /*
      3  * Copyright (c) 1997 by Matthew Jacob
      4  * NASA AMES Research Center.
      5  * All rights reserved.
      6  *
      7  * Based in part upon a prototype version by Jason Thorpe
      8  * Copyright (c) 1996 by Jason Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice immediately at the beginning of the file, without modification,
     15  *    this list of conditions, and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * Autoconfiguration and support routines for the TurboLaser System Bus
     37  * found on AlphaServer 8200 and 8400 systems.
     38  */
     39 
     40 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     41 
     42 __KERNEL_RCSID(0, "$NetBSD: tlsb.c,v 1.12 1998/07/08 01:03:41 mjacob Exp $");
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/device.h>
     47 #include <sys/malloc.h>
     48 
     49 #include <machine/autoconf.h>
     50 #include <machine/rpb.h>
     51 #include <machine/pte.h>
     52 
     53 #include <alpha/tlsb/tlsbreg.h>
     54 #include <alpha/tlsb/tlsbvar.h>
     55 
     56 #include "locators.h"
     57 
     58 extern int	cputype;
     59 
     60 #define KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
     61 
     62 static int	tlsbmatch __P((struct device *, struct cfdata *, void *));
     63 static void	tlsbattach __P((struct device *, struct device *, void *));
     64 
     65 struct cfattach tlsb_ca = {
     66 	sizeof (struct device), tlsbmatch, tlsbattach
     67 };
     68 
     69 extern struct cfdriver tlsb_cd;
     70 
     71 static int	tlsbprint __P((void *, const char *));
     72 static int	tlsbsubmatch __P((struct device *, struct cfdata *, void *));
     73 static char	*tlsb_node_type_str __P((u_int32_t));
     74 
     75 /*
     76  * There can be only one TurboLaser, and we'll overload it
     77  * with a bitmap of found turbo laser nodes. Note that
     78  * these are just the actual hard TL node IDS that we
     79  * discover here, not the virtual IDs that get assigned
     80  * to CPUs. During TLSB specific error handling we
     81  * only need to know which actual TLSB slots have boards
     82  * in them (irrespective of how many CPUs they have).
     83  */
     84 int	tlsb_found;
     85 
     86 static int
     87 tlsbprint(aux, pnp)
     88 	void *aux;
     89 	const char *pnp;
     90 {
     91 	struct tlsb_dev_attach_args *tap = aux;
     92 
     93 	if (pnp)
     94 		printf("%s at %s node %d", tlsb_node_type_str(tap->ta_dtype),
     95 		    pnp, tap->ta_node);
     96 	else
     97 		printf(" node %d: %s", tap->ta_node,
     98 		    tlsb_node_type_str(tap->ta_dtype));
     99 
    100 	return (UNCONF);
    101 }
    102 
    103 static int
    104 tlsbsubmatch(parent, cf, aux)
    105 	struct device *parent;
    106 	struct cfdata *cf;
    107 	void *aux;
    108 {
    109 	struct tlsb_dev_attach_args *tap = aux;
    110 
    111 	if (cf->cf_loc[TLSBCF_NODE] != TLSBCF_NODE_DEFAULT &&
    112 	    cf->cf_loc[TLSBCF_NODE] != tap->ta_node)
    113 		return (0);
    114 
    115 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    116 }
    117 
    118 static int
    119 tlsbmatch(parent, cf, aux)
    120 	struct device *parent;
    121 	struct cfdata *cf;
    122 	void *aux;
    123 {
    124 	struct mainbus_attach_args *ma = aux;
    125 
    126 	/* Make sure we're looking for a TurboLaser. */
    127 	if (strcmp(ma->ma_name, tlsb_cd.cd_name) != 0)
    128 		return (0);
    129 
    130 	/*
    131 	 * Only one instance of TurboLaser allowed,
    132 	 * and only available on 21000 processor type
    133 	 * platforms.
    134 	 */
    135 	if ((cputype != ST_DEC_21000) || tlsb_found)
    136 		return (0);
    137 
    138 	return (1);
    139 }
    140 
    141 static void
    142 tlsbattach(parent, self, aux)
    143 	struct device *parent;
    144 	struct device *self;
    145 	void *aux;
    146 {
    147 	extern struct cfdriver cpu_cd;
    148 	struct tlsb_dev_attach_args ta;
    149 	u_int32_t tldev;
    150 	u_int8_t vid;
    151 	int node;
    152 	struct cfdriver *cfd = &cpu_cd;
    153 
    154 	printf("\n");
    155 
    156 	/*
    157 	 * Attempt to find all devices on the bus, including
    158 	 * CPUs, memory modules, and I/O modules.
    159 	 */
    160 
    161 	/*
    162 	 * Sigh. I would like to just start off nicely,
    163 	 * but I need to treat I/O modules differently-
    164 	 * The highest priority I/O node has to be in
    165 	 * node #8, and I want to find it *first*, since
    166 	 * it will have the primary disks (most likely)
    167 	 * on it.
    168 	 */
    169 	for (node = 0; node <= TLSB_NODE_MAX; ++node) {
    170 		/*
    171 		 * Check for invalid address.  This may not really
    172 		 * be necessary, but what the heck...
    173 		 */
    174 		if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
    175 			continue;
    176 		tldev = TLSB_GET_NODEREG(node, TLDEV);
    177 		if (tldev == 0) {
    178 			/* Nothing at this node. */
    179 			continue;
    180 		}
    181 		/*
    182 		 * Store up that we found something at this node.
    183 		 * We do this so that we don't have to do something
    184 		 * silly at fault time like try a 'baddadr'...
    185 		 */
    186 		tlsb_found |= (1 << node);
    187 		if (TLDEV_ISIOPORT(tldev))
    188 			continue;	/* not interested right now */
    189 		ta.ta_node = node;
    190 		ta.ta_dtype = TLDEV_DTYPE(tldev);
    191 		ta.ta_swrev = TLDEV_SWREV(tldev);
    192 		ta.ta_hwrev = TLDEV_HWREV(tldev);
    193 
    194 		/*
    195 		 * Deal with hooking CPU instances to TurboLaser nodes.
    196 		 */
    197 		if (TLDEV_ISCPU(tldev)) {
    198 			printf("%s node %d: %s", self->dv_xname,
    199 			    node, tlsb_node_type_str(tldev));
    200 
    201 			/*
    202 			 * Hook in the first CPU unit.
    203 			 */
    204 			vid = (TLSB_GET_NODEREG(node, TLVID) &
    205 			    TLVID_VIDA_MASK) >> TLVID_VIDA_SHIFT;
    206 			printf(", VID %d -> %s", vid, cfd->cd_name);
    207 			printf("\n");
    208 			TLSB_PUT_NODEREG(node, TLCPUMASK, (1<<vid));
    209 		}
    210 		/*
    211 		 * Attach any  children nodes, including a CPU's GBus
    212 		 */
    213 		config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
    214 	}
    215 	/*
    216 	 * *Now* search for I/O nodes (in descending order)
    217 	 */
    218 	while (--node > 0) {
    219 		if (badaddr(TLSB_NODE_REG_ADDR(node, TLDEV), sizeof(u_int32_t)))
    220 			continue;
    221 		tldev = TLSB_GET_NODEREG(node, TLDEV);
    222 		if (tldev == 0) {
    223 			continue;
    224 		}
    225 		if (TLDEV_ISIOPORT(tldev)) {
    226 			ta.ta_node = node;
    227 			ta.ta_dtype = TLDEV_DTYPE(tldev);
    228 			ta.ta_swrev = TLDEV_SWREV(tldev);
    229 			ta.ta_hwrev = TLDEV_HWREV(tldev);
    230 			config_found_sm(self, &ta, tlsbprint, tlsbsubmatch);
    231 		}
    232 	}
    233 }
    234 
    235 static char *
    236 tlsb_node_type_str(dtype)
    237 	u_int32_t dtype;
    238 {
    239 	static char	tlsb_line[64];
    240 
    241 	switch (dtype & TLDEV_DTYPE_MASK) {
    242 	case TLDEV_DTYPE_KFTHA:
    243 		return ("KFTHA I/O interface");
    244 
    245 	case TLDEV_DTYPE_KFTIA:
    246 		return ("KFTIA I/O interface");
    247 
    248 	case TLDEV_DTYPE_MS7CC:
    249 		return ("MS7CC Memory Module");
    250 
    251 	case TLDEV_DTYPE_SCPU4:
    252 		return ("Single CPU, 4MB cache");
    253 
    254 	case TLDEV_DTYPE_SCPU16:
    255 		return ("Single CPU, 16MB cache");
    256 
    257 	case TLDEV_DTYPE_DCPU4:
    258 		return ("Dual CPU, 4MB cache");
    259 
    260 	case TLDEV_DTYPE_DCPU16:
    261 		return ("Dual CPU, 16MB cache");
    262 
    263 	default:
    264 		bzero(tlsb_line, sizeof(tlsb_line));
    265 		sprintf(tlsb_line, "unknown, dtype 0x%x", dtype);
    266 		return (tlsb_line);
    267 	}
    268 	/* NOTREACHED */
    269 }
    270