Home | History | Annotate | Line # | Download | only in pci
tsc.c revision 1.19.18.1
      1  1.19.18.1     rmind /* $NetBSD: tsc.c,v 1.19.18.1 2014/05/18 17:44:53 rmind Exp $ */
      2        1.1      ross 
      3        1.1      ross /*-
      4        1.1      ross  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
      5        1.1      ross  *
      6        1.1      ross  * Redistribution and use in source and binary forms, with or without
      7        1.1      ross  * modification, are permitted provided that the following conditions
      8        1.1      ross  * are met:
      9        1.1      ross  * 1. Redistributions of source code must retain the above copyright
     10        1.1      ross  *    notice, this list of conditions and the following disclaimer.
     11        1.1      ross  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1      ross  *    notice, this list of conditions and the following disclaimer in the
     13        1.1      ross  *    documentation and/or other materials provided with the distribution.
     14        1.1      ross  * 3. All advertising materials mentioning features or use of this software
     15        1.1      ross  *    must display the following acknowledgement:
     16        1.1      ross  *	This product includes software developed by Ross Harvey.
     17        1.1      ross  * 4. The name of Ross Harvey may not be used to endorse or promote products
     18        1.1      ross  *    derived from this software without specific prior written permission.
     19        1.1      ross  *
     20        1.1      ross  * THIS SOFTWARE IS PROVIDED BY ROSS HARVEY ``AS IS'' AND ANY EXPRESS
     21        1.1      ross  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22        1.1      ross  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
     23        1.1      ross  * ARE DISCLAIMED.  IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
     24        1.1      ross  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25        1.1      ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26        1.1      ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27        1.1      ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28        1.1      ross  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29        1.1      ross  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30        1.1      ross  * SUCH DAMAGE.
     31        1.1      ross  *
     32        1.1      ross  */
     33        1.1      ross 
     34        1.1      ross #include "opt_dec_6600.h"
     35        1.1      ross 
     36        1.1      ross #include <sys/cdefs.h>
     37        1.1      ross 
     38  1.19.18.1     rmind __KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.19.18.1 2014/05/18 17:44:53 rmind Exp $");
     39        1.1      ross 
     40        1.1      ross #include <sys/param.h>
     41        1.1      ross #include <sys/systm.h>
     42        1.1      ross #include <sys/device.h>
     43        1.1      ross #include <sys/malloc.h>
     44        1.1      ross 
     45        1.1      ross #include <machine/autoconf.h>
     46        1.1      ross #include <machine/rpb.h>
     47        1.3   thorpej #include <machine/sysarch.h>
     48        1.1      ross 
     49        1.1      ross #include <dev/isa/isareg.h>
     50        1.1      ross #include <dev/isa/isavar.h>
     51        1.1      ross #include <dev/pci/pcireg.h>
     52        1.1      ross #include <dev/pci/pcivar.h>
     53        1.1      ross #include <alpha/pci/tsreg.h>
     54        1.1      ross #include <alpha/pci/tsvar.h>
     55        1.1      ross 
     56  1.19.18.1     rmind #include "tsciic.h"
     57  1.19.18.1     rmind 
     58        1.1      ross #ifdef DEC_6600
     59        1.1      ross #include <alpha/pci/pci_6600.h>
     60        1.1      ross #endif
     61        1.1      ross 
     62        1.1      ross #define tsc() { Generate ctags(1) key. }
     63        1.1      ross 
     64       1.17  jakllsch static int tscmatch(device_t, cfdata_t, void *);
     65       1.17  jakllsch static void tscattach(device_t, device_t, void *);
     66        1.1      ross 
     67       1.17  jakllsch CFATTACH_DECL_NEW(tsc, 0, tscmatch, tscattach, NULL, NULL);
     68        1.1      ross 
     69        1.1      ross extern struct cfdriver tsc_cd;
     70        1.1      ross 
     71  1.19.18.1     rmind struct tsp_config tsp_configuration[4];
     72        1.1      ross 
     73       1.14       dsl static int tscprint(void *, const char *pnp);
     74        1.1      ross 
     75       1.17  jakllsch static int tspmatch(device_t, cfdata_t, void *);
     76       1.17  jakllsch static void tspattach(device_t, device_t, void *);
     77        1.1      ross 
     78       1.17  jakllsch CFATTACH_DECL_NEW(tsp, 0, tspmatch, tspattach, NULL, NULL);
     79        1.1      ross 
     80        1.1      ross extern struct cfdriver tsp_cd;
     81        1.1      ross 
     82       1.14       dsl static int tsp_bus_get_window(int, int,
     83       1.14       dsl 	struct alpha_bus_space_translation *);
     84        1.3   thorpej 
     85  1.19.18.1     rmind static int tsciicprint(void *, const char *pnp);
     86  1.19.18.1     rmind 
     87  1.19.18.1     rmind static int tsciicmatch(device_t, cfdata_t, void *);
     88  1.19.18.1     rmind static void tsciicattach(device_t, device_t, void *);
     89  1.19.18.1     rmind 
     90  1.19.18.1     rmind CFATTACH_DECL_NEW(tsciic, sizeof(struct tsciic_softc), tsciicmatch,
     91  1.19.18.1     rmind     tsciicattach, NULL, NULL);
     92  1.19.18.1     rmind 
     93  1.19.18.1     rmind #if NTSCIIC
     94  1.19.18.1     rmind extern struct cfdriver tsciic_cd;
     95  1.19.18.1     rmind #endif
     96  1.19.18.1     rmind 
     97        1.1      ross /* There can be only one */
     98        1.3   thorpej static int tscfound;
     99        1.1      ross 
    100        1.3   thorpej /* Which hose is the display console connected to? */
    101        1.3   thorpej int tsp_console_hose;
    102        1.1      ross 
    103       1.17  jakllsch static int
    104       1.17  jakllsch tscmatch(device_t parent, cfdata_t match, void *aux)
    105        1.1      ross {
    106        1.1      ross 	struct mainbus_attach_args *ma = aux;
    107        1.1      ross 
    108  1.19.18.1     rmind 	switch (cputype) {
    109  1.19.18.1     rmind 	case ST_DEC_6600:
    110  1.19.18.1     rmind 	case ST_DEC_TITAN:
    111  1.19.18.1     rmind 		return strcmp(ma->ma_name, tsc_cd.cd_name) == 0 && !tscfound;
    112  1.19.18.1     rmind 	default:
    113  1.19.18.1     rmind 		return 0;
    114  1.19.18.1     rmind 	}
    115        1.1      ross }
    116        1.1      ross 
    117       1.17  jakllsch static void
    118       1.17  jakllsch tscattach(device_t parent, device_t self, void * aux)
    119        1.1      ross {
    120        1.1      ross 	int i;
    121        1.1      ross 	int nbus;
    122       1.17  jakllsch 	uint64_t csc, aar;
    123        1.1      ross 	struct tsp_attach_args tsp;
    124  1.19.18.1     rmind 	struct tsciic_attach_args tsciic;
    125        1.1      ross 	struct mainbus_attach_args *ma = aux;
    126  1.19.18.1     rmind 	int titan = cputype == ST_DEC_TITAN;
    127        1.1      ross 
    128        1.1      ross 	tscfound = 1;
    129        1.1      ross 
    130        1.1      ross 	csc = LDQP(TS_C_CSC);
    131        1.1      ross 
    132        1.1      ross 	nbus = 1 + (CSC_BC(csc) >= 2);
    133  1.19.18.1     rmind 	printf(": 2127%c Core Logic Chipset, Cchip rev %d\n"
    134        1.1      ross 		"%s%d: %c Dchips, %d memory bus%s of %d bytes\n",
    135  1.19.18.1     rmind 		titan ? '4' : '2', (int)MISC_REV(LDQP(TS_C_MISC)),
    136        1.1      ross 		ma->ma_name, ma->ma_slot, "2448"[CSC_BC(csc)],
    137        1.1      ross 		nbus, nbus > 1 ? "es" : "", 16 + 16 * ((csc & CSC_AW) != 0));
    138        1.1      ross 	printf("%s%d: arrays present: ", ma->ma_name, ma->ma_slot);
    139  1.19.18.1     rmind 	for (i = 0; i < 4; ++i) {
    140        1.1      ross 		aar = LDQP(TS_C_AAR0 + i * TS_STEP);
    141        1.1      ross 		printf("%s%dMB%s", i ? ", " : "", (8 << AAR_ASIZ(aar)) & ~0xf,
    142        1.1      ross 		    aar & AAR_SPLIT ? " (split)" : "");
    143        1.1      ross 	}
    144        1.1      ross 	printf(", Dchip 0 rev %d\n", (int)LDQP(TS_D_DREV) & 0xf);
    145        1.1      ross 
    146        1.6   thorpej 	memset(&tsp, 0, sizeof tsp);
    147        1.1      ross 	tsp.tsp_name = "tsp";
    148  1.19.18.1     rmind 	tsp.tsp_slot = 0;
    149  1.19.18.1     rmind 
    150  1.19.18.1     rmind 	config_found(self, &tsp, tscprint);
    151  1.19.18.1     rmind 	if (titan) {
    152  1.19.18.1     rmind 		tsp.tsp_slot += 2;
    153  1.19.18.1     rmind 		config_found(self, &tsp, tscprint);
    154  1.19.18.1     rmind 	}
    155        1.1      ross 
    156  1.19.18.1     rmind 	if (csc & CSC_P1P) {
    157  1.19.18.1     rmind 		tsp.tsp_slot = 1;
    158        1.1      ross 		config_found(self, &tsp, tscprint);
    159  1.19.18.1     rmind 		if (titan) {
    160  1.19.18.1     rmind 			tsp.tsp_slot += 2;
    161  1.19.18.1     rmind 			config_found(self, &tsp, tscprint);
    162  1.19.18.1     rmind 		}
    163        1.1      ross 	}
    164  1.19.18.1     rmind 
    165  1.19.18.1     rmind 	memset(&tsciic, 0, sizeof tsciic);
    166  1.19.18.1     rmind 	tsciic.tsciic_name = "tsciic";
    167  1.19.18.1     rmind 
    168  1.19.18.1     rmind 	config_found(self, &tsciic, tsciicprint);
    169        1.1      ross }
    170        1.1      ross 
    171        1.1      ross static int
    172       1.15       dsl tscprint(void *aux, const char *p)
    173        1.1      ross {
    174  1.19.18.1     rmind 	struct tsp_attach_args *tsp = aux;
    175        1.1      ross 
    176  1.19.18.1     rmind 	if (p)
    177       1.10   thorpej 		aprint_normal("%s%d at %s", tsp->tsp_name, tsp->tsp_slot, p);
    178        1.1      ross 	return UNCONF;
    179        1.1      ross }
    180        1.1      ross 
    181  1.19.18.1     rmind static int
    182  1.19.18.1     rmind tsciicprint(void *aux, const char *p)
    183  1.19.18.1     rmind {
    184  1.19.18.1     rmind 	struct tsciic_attach_args *tsciic = aux;
    185  1.19.18.1     rmind 
    186  1.19.18.1     rmind 	if (p)
    187  1.19.18.1     rmind 		aprint_normal("%s at %s\n", tsciic->tsciic_name, p);
    188  1.19.18.1     rmind 	else
    189  1.19.18.1     rmind 		aprint_normal("\n");
    190  1.19.18.1     rmind 	return UNCONF;
    191  1.19.18.1     rmind }
    192  1.19.18.1     rmind 
    193        1.1      ross #define tsp() { Generate ctags(1) key. }
    194        1.1      ross 
    195       1.17  jakllsch static int
    196       1.17  jakllsch tspmatch(device_t parent, cfdata_t match, void *aux)
    197        1.1      ross {
    198        1.1      ross 	struct tsp_attach_args *t = aux;
    199        1.1      ross 
    200  1.19.18.1     rmind 	switch (cputype) {
    201  1.19.18.1     rmind 	case ST_DEC_6600:
    202  1.19.18.1     rmind 	case ST_DEC_TITAN:
    203  1.19.18.1     rmind 		return strcmp(t->tsp_name, tsp_cd.cd_name) == 0;
    204  1.19.18.1     rmind 	default:
    205  1.19.18.1     rmind 		return 0;
    206  1.19.18.1     rmind 	}
    207        1.1      ross }
    208        1.1      ross 
    209       1.17  jakllsch static void
    210       1.17  jakllsch tspattach(device_t parent, device_t self, void *aux)
    211        1.1      ross {
    212        1.1      ross 	struct pcibus_attach_args pba;
    213        1.1      ross 	struct tsp_attach_args *t = aux;
    214        1.1      ross 	struct tsp_config *pcp;
    215        1.1      ross 
    216        1.1      ross 	printf("\n");
    217        1.1      ross 	pcp = tsp_init(1, t->tsp_slot);
    218        1.5   thorpej 
    219        1.1      ross 	tsp_dma_init(pcp);
    220  1.19.18.1     rmind 
    221        1.5   thorpej 	/*
    222        1.5   thorpej 	 * Do PCI memory initialization that needs to be deferred until
    223        1.5   thorpej 	 * malloc is safe.  On the Tsunami, we need to do this after
    224        1.5   thorpej 	 * DMA is initialized, as well.
    225        1.5   thorpej 	 */
    226        1.5   thorpej 	tsp_bus_mem_init2(&pcp->pc_memt, pcp);
    227        1.5   thorpej 
    228        1.1      ross 	pci_6600_pickintr(pcp);
    229        1.5   thorpej 
    230        1.1      ross 	pba.pba_iot = &pcp->pc_iot;
    231        1.1      ross 	pba.pba_memt = &pcp->pc_memt;
    232        1.1      ross 	pba.pba_dmat =
    233        1.1      ross 	    alphabus_dma_get_tag(&pcp->pc_dmat_direct, ALPHA_BUS_PCI);
    234       1.11      fvdl 	pba.pba_dmat64 = NULL;
    235        1.1      ross 	pba.pba_pc = &pcp->pc_pc;
    236        1.1      ross 	pba.pba_bus = 0;
    237        1.7   thorpej 	pba.pba_bridgetag = NULL;
    238       1.19    dyoung 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
    239        1.2   thorpej 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    240       1.12  drochner 	config_found_ia(self, "pcibus", &pba, pcibusprint);
    241        1.1      ross }
    242        1.1      ross 
    243        1.1      ross struct tsp_config *
    244       1.16       dsl tsp_init(int mallocsafe, int n)
    245       1.16       dsl 	/* n:	 Pchip number */
    246        1.1      ross {
    247        1.1      ross 	struct tsp_config *pcp;
    248  1.19.18.1     rmind 	int titan = cputype == ST_DEC_TITAN;
    249        1.1      ross 
    250  1.19.18.1     rmind 	KASSERT(n >= 0 && n < __arraycount(tsp_configuration));
    251        1.1      ross 	pcp = &tsp_configuration[n];
    252        1.1      ross 	pcp->pc_pslot = n;
    253        1.1      ross 	pcp->pc_iobase = TS_Pn(n, 0);
    254  1.19.18.1     rmind 	pcp->pc_csr = S_PAGE(TS_Pn(n & 1, P_CSRBASE));
    255  1.19.18.1     rmind 	if (n & 2) {
    256  1.19.18.1     rmind 		/* `A' port of PA Chip */
    257  1.19.18.1     rmind 		pcp->pc_csr++;
    258  1.19.18.1     rmind 	}
    259  1.19.18.1     rmind 	if (titan) {
    260  1.19.18.1     rmind 		/* same address on G and A ports */
    261  1.19.18.1     rmind 		pcp->pc_tlbia = &pcp->pc_csr->port.g.tsp_tlbia.tsg_r;
    262  1.19.18.1     rmind 	} else {
    263  1.19.18.1     rmind 		pcp->pc_tlbia = &pcp->pc_csr->port.p.tsp_tlbia.tsg_r;
    264  1.19.18.1     rmind 	}
    265  1.19.18.1     rmind 
    266        1.1      ross 	if (!pcp->pc_initted) {
    267        1.1      ross 		tsp_bus_io_init(&pcp->pc_iot, pcp);
    268        1.1      ross 		tsp_bus_mem_init(&pcp->pc_memt, pcp);
    269        1.3   thorpej 
    270        1.3   thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
    271        1.3   thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
    272        1.3   thorpej 
    273        1.3   thorpej 		alpha_bus_get_window = tsp_bus_get_window;
    274        1.1      ross 	}
    275        1.1      ross 	pcp->pc_mallocsafe = mallocsafe;
    276        1.1      ross 	tsp_pci_init(&pcp->pc_pc, pcp);
    277        1.1      ross 	pcp->pc_initted = 1;
    278        1.1      ross 	return pcp;
    279        1.1      ross }
    280        1.1      ross 
    281        1.1      ross static int
    282       1.17  jakllsch tsp_bus_get_window(int type, int window,
    283       1.17  jakllsch     struct alpha_bus_space_translation *abst)
    284        1.3   thorpej {
    285        1.3   thorpej 	struct tsp_config *tsp = &tsp_configuration[tsp_console_hose];
    286        1.3   thorpej 	bus_space_tag_t st;
    287        1.4   thorpej 	int error;
    288        1.3   thorpej 
    289        1.3   thorpej 	switch (type) {
    290        1.3   thorpej 	case ALPHA_BUS_TYPE_PCI_IO:
    291        1.3   thorpej 		st = &tsp->pc_iot;
    292        1.3   thorpej 		break;
    293        1.3   thorpej 
    294        1.3   thorpej 	case ALPHA_BUS_TYPE_PCI_MEM:
    295        1.3   thorpej 		st = &tsp->pc_memt;
    296        1.3   thorpej 		break;
    297        1.3   thorpej 
    298        1.3   thorpej 	default:
    299        1.3   thorpej 		panic("tsp_bus_get_window");
    300        1.3   thorpej 	}
    301        1.3   thorpej 
    302        1.4   thorpej 	error = alpha_bus_space_get_window(st, window, abst);
    303        1.4   thorpej 	if (error)
    304  1.19.18.1     rmind 		return error;
    305        1.4   thorpej 
    306        1.4   thorpej 	abst->abst_sys_start = TS_PHYSADDR(abst->abst_sys_start);
    307        1.4   thorpej 	abst->abst_sys_end = TS_PHYSADDR(abst->abst_sys_end);
    308        1.4   thorpej 
    309  1.19.18.1     rmind 	return 0;
    310  1.19.18.1     rmind }
    311  1.19.18.1     rmind 
    312  1.19.18.1     rmind #define tsciic() { Generate ctags(1) key. }
    313  1.19.18.1     rmind 
    314  1.19.18.1     rmind static int
    315  1.19.18.1     rmind tsciicmatch(device_t parent, cfdata_t match, void *aux)
    316  1.19.18.1     rmind {
    317  1.19.18.1     rmind #if NTSCIIC
    318  1.19.18.1     rmind 	struct tsciic_attach_args *t = aux;
    319  1.19.18.1     rmind #endif
    320  1.19.18.1     rmind 
    321  1.19.18.1     rmind 	switch (cputype) {
    322  1.19.18.1     rmind 	case ST_DEC_6600:
    323  1.19.18.1     rmind 	case ST_DEC_TITAN:
    324  1.19.18.1     rmind #if NTSCIIC
    325  1.19.18.1     rmind 		return strcmp(t->tsciic_name, tsciic_cd.cd_name) == 0;
    326  1.19.18.1     rmind #endif
    327  1.19.18.1     rmind 	default:
    328  1.19.18.1     rmind 		return 0;
    329  1.19.18.1     rmind 	}
    330  1.19.18.1     rmind }
    331  1.19.18.1     rmind 
    332  1.19.18.1     rmind static void
    333  1.19.18.1     rmind tsciicattach(device_t parent, device_t self, void *aux)
    334  1.19.18.1     rmind {
    335  1.19.18.1     rmind #if NTSCIIC
    336  1.19.18.1     rmind 	tsciic_init(self);
    337  1.19.18.1     rmind #endif
    338        1.1      ross }
    339       1.18      hans 
    340       1.18      hans void
    341       1.18      hans tsc_print_dir(unsigned int indent, unsigned long dir)
    342       1.18      hans {
    343       1.18      hans 	char buf[60];
    344       1.18      hans 
    345       1.18      hans 	snprintb(buf, 60,
    346       1.18      hans 		 "\177\20"
    347       1.18      hans 		 "b\77Internal Cchip asynchronous error\0"
    348       1.18      hans 		 "b\76Pchip 0 error\0"
    349       1.18      hans 		 "b\75Pchip 1 error\0"
    350       1.18      hans 		 "b\74Pchip 2 error\0"
    351       1.18      hans 		 "b\73Pchip 3 error\0",
    352       1.18      hans 		 dir);
    353       1.18      hans 	IPRINTF(indent, "DIR = %s\n", buf);
    354       1.18      hans }
    355       1.18      hans 
    356       1.18      hans void
    357       1.18      hans tsc_print_misc(unsigned int indent, unsigned long misc)
    358       1.18      hans {
    359       1.18      hans 	unsigned long tmp = MISC_NXM_SRC(misc);
    360       1.18      hans 
    361       1.18      hans 	if (!MISC_NXM(misc))
    362       1.18      hans 		return;
    363       1.18      hans 
    364       1.18      hans 	IPRINTF(indent, "NXM address detected\n");
    365       1.18      hans 	IPRINTF(indent, "NXM source         = %s %lu\n",
    366       1.18      hans 		tmp <= 3 ? "CPU" : "Pchip", tmp <= 3 ? tmp : tmp - 4);
    367       1.18      hans }
    368