Home | History | Annotate | Line # | Download | only in pci
tsc.c revision 1.2
      1 /* $NetBSD: tsc.c,v 1.2 1999/11/04 19:15:23 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 by Ross Harvey.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Ross Harvey.
     17  * 4. The name of Ross Harvey 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 ROSS HARVEY ``AS IS'' AND ANY EXPRESS
     21  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
     23  * ARE DISCLAIMED.  IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
     24  * 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 #include "opt_dec_6600.h"
     35 
     36 #include <sys/cdefs.h>
     37 
     38 __KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.2 1999/11/04 19:15:23 thorpej Exp $");
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/device.h>
     43 #include <sys/malloc.h>
     44 
     45 #include <machine/autoconf.h>
     46 #include <machine/rpb.h>
     47 
     48 #include <dev/isa/isareg.h>
     49 #include <dev/isa/isavar.h>
     50 #include <dev/pci/pcireg.h>
     51 #include <dev/pci/pcivar.h>
     52 #include <alpha/pci/tsreg.h>
     53 #include <alpha/pci/tsvar.h>
     54 
     55 #ifdef DEC_6600
     56 #include <alpha/pci/pci_6600.h>
     57 #endif
     58 
     59 #define tsc() { Generate ctags(1) key. }
     60 
     61 int	tscmatch __P((struct device *, struct cfdata *, void *));
     62 void	tscattach __P((struct device *, struct device *, void *));
     63 
     64 struct cfattach tsc_ca = {
     65 	sizeof(struct tsc_softc), tscmatch, tscattach,
     66 };
     67 
     68 extern struct cfdriver tsc_cd;
     69 
     70 struct tsp_config tsp_configuration[2];
     71 
     72 static int tscprint __P((void *, const char *pnp));
     73 
     74 int	tspmatch __P((struct device *, struct cfdata *, void *));
     75 void	tspattach __P((struct device *, struct device *, void *));
     76 
     77 struct cfattach tsp_ca = {
     78 	sizeof(struct tsp_softc), tspmatch, tspattach,
     79 };
     80 
     81 extern struct cfdriver tsp_cd;
     82 
     83 static int tspprint __P((void *, const char *pnp));
     84 
     85 /* There can be only one */
     86 
     87 static int tscfound;
     88 
     89 int
     90 tscmatch(parent, match, aux)
     91 	struct device *parent;
     92 	struct cfdata *match;
     93 	void *aux;
     94 {
     95 	struct mainbus_attach_args *ma = aux;
     96 
     97 	return cputype == ST_DEC_6600
     98 	    && strcmp(ma->ma_name, tsc_cd.cd_name) == 0
     99 	    && !tscfound;
    100 }
    101 
    102 void tscattach(parent, self, aux)
    103 	struct device *parent, *self;
    104 	void *aux;
    105 {
    106 	int i;
    107 	int nbus;
    108 	u_int64_t csc, aar;
    109 	struct tsp_attach_args tsp;
    110 	struct mainbus_attach_args *ma = aux;
    111 
    112 	tscfound = 1;
    113 
    114 	csc = LDQP(TS_C_CSC);
    115 
    116 	nbus = 1 + (CSC_BC(csc) >= 2);
    117 	printf(": 21272 Core Logic Chipset, Cchip rev %d\n"
    118 		"%s%d: %c Dchips, %d memory bus%s of %d bytes\n",
    119 		(int)MISC_REV(LDQP(TS_C_MISC)),
    120 		ma->ma_name, ma->ma_slot, "2448"[CSC_BC(csc)],
    121 		nbus, nbus > 1 ? "es" : "", 16 + 16 * ((csc & CSC_AW) != 0));
    122 	printf("%s%d: arrays present: ", ma->ma_name, ma->ma_slot);
    123 	for(i = 0; i < 4; ++i) {
    124 		aar = LDQP(TS_C_AAR0 + i * TS_STEP);
    125 		printf("%s%dMB%s", i ? ", " : "", (8 << AAR_ASIZ(aar)) & ~0xf,
    126 		    aar & AAR_SPLIT ? " (split)" : "");
    127 	}
    128 	printf(", Dchip 0 rev %d\n", (int)LDQP(TS_D_DREV) & 0xf);
    129 
    130 	bzero(&tsp, sizeof tsp);
    131 	tsp.tsp_name = "tsp";
    132 	config_found(self, &tsp, NULL);
    133 
    134 	if(LDQP(TS_C_CSC) & CSC_P1P) {
    135 		++tsp.tsp_slot;
    136 		config_found(self, &tsp, tscprint);
    137 	}
    138 }
    139 
    140 static int
    141 tscprint(aux, p)
    142 	void *aux;
    143 	const char *p;
    144 {
    145 	register struct tsp_attach_args *tsp = aux;
    146 
    147 	if(p)
    148 		printf("%s%d at %s", tsp->tsp_name, tsp->tsp_slot, p);
    149 	return UNCONF;
    150 }
    151 
    152 #define tsp() { Generate ctags(1) key. }
    153 
    154 int
    155 tspmatch(parent, match, aux)
    156 	struct device *parent;
    157 	struct cfdata *match;
    158 	void *aux;
    159 {
    160 	struct tsp_attach_args *t = aux;
    161 
    162 	return  cputype == ST_DEC_6600
    163 	    && strcmp(t->tsp_name, tsp_cd.cd_name) == 0;
    164 }
    165 
    166 void tspattach(parent, self, aux)
    167 	struct device *parent, *self;
    168 	void *aux;
    169 {
    170 	struct pcibus_attach_args pba;
    171 	struct tsp_attach_args *t = aux;
    172 	struct tsp_config *pcp;
    173 
    174 	printf("\n");
    175 	pcp = tsp_init(1, t->tsp_slot);
    176 	tsp_dma_init(pcp);
    177 	pci_6600_pickintr(pcp);
    178 	pba.pba_busname = "pci";
    179 	pba.pba_iot = &pcp->pc_iot;
    180 	pba.pba_memt = &pcp->pc_memt;
    181 	pba.pba_dmat =
    182 	    alphabus_dma_get_tag(&pcp->pc_dmat_direct, ALPHA_BUS_PCI);
    183 	pba.pba_pc = &pcp->pc_pc;
    184 	pba.pba_bus = 0;
    185 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    186 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    187 	config_found(self, &pba, tspprint);
    188 }
    189 
    190 struct tsp_config *
    191 tsp_init(mallocsafe, n)
    192 	int mallocsafe;
    193 	int n;	/* Pchip number */
    194 {
    195 	struct tsp_config *pcp;
    196 
    197 	KASSERT((n | 1) == 1);
    198 	pcp = &tsp_configuration[n];
    199 	pcp->pc_pslot = n;
    200 	pcp->pc_iobase = TS_Pn(n, 0);
    201 	pcp->pc_csr = S_PAGE(TS_Pn(n, P_CSRBASE));
    202 	if (!pcp->pc_initted) {
    203 		tsp_bus_io_init(&pcp->pc_iot, pcp);
    204 		tsp_bus_mem_init(&pcp->pc_memt, pcp);
    205 	}
    206 	pcp->pc_mallocsafe = mallocsafe;
    207 	tsp_pci_init(&pcp->pc_pc, pcp);
    208 	pcp->pc_initted = 1;
    209 	return pcp;
    210 }
    211 
    212 static int
    213 tspprint(aux, p)
    214 	void *aux;
    215 	const char *p;
    216 {
    217 	register struct pcibus_attach_args *pci = aux;
    218 
    219 	if(p)
    220 		printf("%s at %s", pci->pba_busname, p);
    221 	printf(" bus %d", pci->pba_bus);
    222 	return UNCONF;
    223 }
    224