Home | History | Annotate | Line # | Download | only in pci
tsc.c revision 1.11.2.3
      1  1.11.2.3    skrll /* $NetBSD: tsc.c,v 1.11.2.3 2004/09/21 13:12:02 skrll 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.11.2.3    skrll __KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.11.2.3 2004/09/21 13:12:02 skrll 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.1     ross #ifdef DEC_6600
     57       1.1     ross #include <alpha/pci/pci_6600.h>
     58       1.1     ross #endif
     59       1.1     ross 
     60       1.1     ross #define tsc() { Generate ctags(1) key. }
     61       1.1     ross 
     62       1.1     ross int	tscmatch __P((struct device *, struct cfdata *, void *));
     63       1.1     ross void	tscattach __P((struct device *, struct device *, void *));
     64       1.1     ross 
     65       1.9  thorpej CFATTACH_DECL(tsc, sizeof(struct tsc_softc),
     66       1.9  thorpej     tscmatch, tscattach, NULL, NULL);
     67       1.1     ross 
     68       1.1     ross extern struct cfdriver tsc_cd;
     69       1.1     ross 
     70       1.1     ross struct tsp_config tsp_configuration[2];
     71       1.1     ross 
     72       1.1     ross static int tscprint __P((void *, const char *pnp));
     73       1.1     ross 
     74       1.1     ross int	tspmatch __P((struct device *, struct cfdata *, void *));
     75       1.1     ross void	tspattach __P((struct device *, struct device *, void *));
     76       1.1     ross 
     77       1.9  thorpej CFATTACH_DECL(tsp, sizeof(struct tsp_softc),
     78       1.9  thorpej     tspmatch, tspattach, NULL, NULL);
     79       1.1     ross 
     80       1.1     ross extern struct cfdriver tsp_cd;
     81       1.1     ross 
     82       1.3  thorpej static int tsp_bus_get_window __P((int, int,
     83       1.3  thorpej 	struct alpha_bus_space_translation *));
     84       1.3  thorpej 
     85       1.1     ross /* There can be only one */
     86       1.3  thorpej static int tscfound;
     87       1.1     ross 
     88       1.3  thorpej /* Which hose is the display console connected to? */
     89       1.3  thorpej int tsp_console_hose;
     90       1.1     ross 
     91       1.1     ross int
     92       1.1     ross tscmatch(parent, match, aux)
     93       1.1     ross 	struct device *parent;
     94       1.1     ross 	struct cfdata *match;
     95       1.1     ross 	void *aux;
     96       1.1     ross {
     97       1.1     ross 	struct mainbus_attach_args *ma = aux;
     98       1.1     ross 
     99       1.1     ross 	return cputype == ST_DEC_6600
    100       1.1     ross 	    && strcmp(ma->ma_name, tsc_cd.cd_name) == 0
    101       1.1     ross 	    && !tscfound;
    102       1.1     ross }
    103       1.1     ross 
    104       1.1     ross void tscattach(parent, self, aux)
    105       1.1     ross 	struct device *parent, *self;
    106       1.1     ross 	void *aux;
    107       1.1     ross {
    108       1.1     ross 	int i;
    109       1.1     ross 	int nbus;
    110       1.1     ross 	u_int64_t csc, aar;
    111       1.1     ross 	struct tsp_attach_args tsp;
    112       1.1     ross 	struct mainbus_attach_args *ma = aux;
    113       1.1     ross 
    114       1.1     ross 	tscfound = 1;
    115       1.1     ross 
    116       1.1     ross 	csc = LDQP(TS_C_CSC);
    117       1.1     ross 
    118       1.1     ross 	nbus = 1 + (CSC_BC(csc) >= 2);
    119       1.1     ross 	printf(": 21272 Core Logic Chipset, Cchip rev %d\n"
    120       1.1     ross 		"%s%d: %c Dchips, %d memory bus%s of %d bytes\n",
    121       1.1     ross 		(int)MISC_REV(LDQP(TS_C_MISC)),
    122       1.1     ross 		ma->ma_name, ma->ma_slot, "2448"[CSC_BC(csc)],
    123       1.1     ross 		nbus, nbus > 1 ? "es" : "", 16 + 16 * ((csc & CSC_AW) != 0));
    124       1.1     ross 	printf("%s%d: arrays present: ", ma->ma_name, ma->ma_slot);
    125       1.1     ross 	for(i = 0; i < 4; ++i) {
    126       1.1     ross 		aar = LDQP(TS_C_AAR0 + i * TS_STEP);
    127       1.1     ross 		printf("%s%dMB%s", i ? ", " : "", (8 << AAR_ASIZ(aar)) & ~0xf,
    128       1.1     ross 		    aar & AAR_SPLIT ? " (split)" : "");
    129       1.1     ross 	}
    130       1.1     ross 	printf(", Dchip 0 rev %d\n", (int)LDQP(TS_D_DREV) & 0xf);
    131       1.1     ross 
    132       1.6  thorpej 	memset(&tsp, 0, sizeof tsp);
    133       1.1     ross 	tsp.tsp_name = "tsp";
    134       1.1     ross 	config_found(self, &tsp, NULL);
    135       1.1     ross 
    136       1.1     ross 	if(LDQP(TS_C_CSC) & CSC_P1P) {
    137       1.1     ross 		++tsp.tsp_slot;
    138       1.1     ross 		config_found(self, &tsp, tscprint);
    139       1.1     ross 	}
    140       1.1     ross }
    141       1.1     ross 
    142       1.1     ross static int
    143       1.1     ross tscprint(aux, p)
    144       1.1     ross 	void *aux;
    145       1.1     ross 	const char *p;
    146       1.1     ross {
    147       1.1     ross 	register struct tsp_attach_args *tsp = aux;
    148       1.1     ross 
    149       1.1     ross 	if(p)
    150      1.10  thorpej 		aprint_normal("%s%d at %s", tsp->tsp_name, tsp->tsp_slot, p);
    151       1.1     ross 	return UNCONF;
    152       1.1     ross }
    153       1.1     ross 
    154       1.1     ross #define tsp() { Generate ctags(1) key. }
    155       1.1     ross 
    156       1.1     ross int
    157       1.1     ross tspmatch(parent, match, aux)
    158       1.1     ross 	struct device *parent;
    159       1.1     ross 	struct cfdata *match;
    160       1.1     ross 	void *aux;
    161       1.1     ross {
    162       1.1     ross 	struct tsp_attach_args *t = aux;
    163       1.1     ross 
    164       1.1     ross 	return  cputype == ST_DEC_6600
    165       1.1     ross 	    && strcmp(t->tsp_name, tsp_cd.cd_name) == 0;
    166       1.1     ross }
    167       1.1     ross 
    168       1.3  thorpej void
    169       1.3  thorpej tspattach(parent, self, aux)
    170       1.1     ross 	struct device *parent, *self;
    171       1.1     ross 	void *aux;
    172       1.1     ross {
    173       1.1     ross 	struct pcibus_attach_args pba;
    174       1.1     ross 	struct tsp_attach_args *t = aux;
    175       1.1     ross 	struct tsp_config *pcp;
    176       1.1     ross 
    177       1.1     ross 	printf("\n");
    178       1.1     ross 	pcp = tsp_init(1, t->tsp_slot);
    179       1.5  thorpej 
    180       1.1     ross 	tsp_dma_init(pcp);
    181       1.5  thorpej 
    182       1.5  thorpej 	/*
    183       1.5  thorpej 	 * Do PCI memory initialization that needs to be deferred until
    184       1.5  thorpej 	 * malloc is safe.  On the Tsunami, we need to do this after
    185       1.5  thorpej 	 * DMA is initialized, as well.
    186       1.5  thorpej 	 */
    187       1.5  thorpej 	tsp_bus_mem_init2(&pcp->pc_memt, pcp);
    188       1.5  thorpej 
    189       1.1     ross 	pci_6600_pickintr(pcp);
    190       1.5  thorpej 
    191       1.1     ross 	pba.pba_iot = &pcp->pc_iot;
    192       1.1     ross 	pba.pba_memt = &pcp->pc_memt;
    193       1.1     ross 	pba.pba_dmat =
    194       1.1     ross 	    alphabus_dma_get_tag(&pcp->pc_dmat_direct, ALPHA_BUS_PCI);
    195      1.11     fvdl 	pba.pba_dmat64 = NULL;
    196       1.1     ross 	pba.pba_pc = &pcp->pc_pc;
    197       1.1     ross 	pba.pba_bus = 0;
    198       1.7  thorpej 	pba.pba_bridgetag = NULL;
    199       1.2  thorpej 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    200       1.2  thorpej 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    201  1.11.2.1    skrll 	config_found_ia(self, "pcibus", &pba, pcibusprint);
    202       1.1     ross }
    203       1.1     ross 
    204       1.1     ross struct tsp_config *
    205       1.1     ross tsp_init(mallocsafe, n)
    206       1.1     ross 	int mallocsafe;
    207       1.1     ross 	int n;	/* Pchip number */
    208       1.1     ross {
    209       1.1     ross 	struct tsp_config *pcp;
    210       1.1     ross 
    211       1.1     ross 	KASSERT((n | 1) == 1);
    212       1.1     ross 	pcp = &tsp_configuration[n];
    213       1.1     ross 	pcp->pc_pslot = n;
    214       1.1     ross 	pcp->pc_iobase = TS_Pn(n, 0);
    215       1.1     ross 	pcp->pc_csr = S_PAGE(TS_Pn(n, P_CSRBASE));
    216       1.1     ross 	if (!pcp->pc_initted) {
    217       1.1     ross 		tsp_bus_io_init(&pcp->pc_iot, pcp);
    218       1.1     ross 		tsp_bus_mem_init(&pcp->pc_memt, pcp);
    219       1.3  thorpej 
    220       1.3  thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
    221       1.3  thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
    222       1.3  thorpej 
    223       1.3  thorpej 		alpha_bus_get_window = tsp_bus_get_window;
    224       1.1     ross 	}
    225       1.1     ross 	pcp->pc_mallocsafe = mallocsafe;
    226       1.1     ross 	tsp_pci_init(&pcp->pc_pc, pcp);
    227       1.1     ross 	pcp->pc_initted = 1;
    228       1.1     ross 	return pcp;
    229       1.1     ross }
    230       1.1     ross 
    231       1.1     ross static int
    232       1.3  thorpej tsp_bus_get_window(type, window, abst)
    233       1.3  thorpej 	int type, window;
    234       1.3  thorpej 	struct alpha_bus_space_translation *abst;
    235       1.3  thorpej {
    236       1.3  thorpej 	struct tsp_config *tsp = &tsp_configuration[tsp_console_hose];
    237       1.3  thorpej 	bus_space_tag_t st;
    238       1.4  thorpej 	int error;
    239       1.3  thorpej 
    240       1.3  thorpej 	switch (type) {
    241       1.3  thorpej 	case ALPHA_BUS_TYPE_PCI_IO:
    242       1.3  thorpej 		st = &tsp->pc_iot;
    243       1.3  thorpej 		break;
    244       1.3  thorpej 
    245       1.3  thorpej 	case ALPHA_BUS_TYPE_PCI_MEM:
    246       1.3  thorpej 		st = &tsp->pc_memt;
    247       1.3  thorpej 		break;
    248       1.3  thorpej 
    249       1.3  thorpej 	default:
    250       1.3  thorpej 		panic("tsp_bus_get_window");
    251       1.3  thorpej 	}
    252       1.3  thorpej 
    253       1.4  thorpej 	error = alpha_bus_space_get_window(st, window, abst);
    254       1.4  thorpej 	if (error)
    255       1.4  thorpej 		return (error);
    256       1.4  thorpej 
    257       1.4  thorpej 	abst->abst_sys_start = TS_PHYSADDR(abst->abst_sys_start);
    258       1.4  thorpej 	abst->abst_sys_end = TS_PHYSADDR(abst->abst_sys_end);
    259       1.4  thorpej 
    260       1.4  thorpej 	return (0);
    261       1.1     ross }
    262