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