Home | History | Annotate | Line # | Download | only in pci
cia.c revision 1.27
      1 /* $NetBSD: cia.c,v 1.27 1997/09/17 01:34:18 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include "opt_dec_eb164.h"
     31 #include "opt_dec_kn20aa.h"
     32 
     33 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34 
     35 __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.27 1997/09/17 01:34:18 thorpej Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/malloc.h>
     41 #include <sys/device.h>
     42 #include <vm/vm.h>
     43 
     44 #include <machine/autoconf.h>
     45 #include <machine/rpb.h>
     46 
     47 #include <dev/isa/isareg.h>
     48 #include <dev/isa/isavar.h>
     49 
     50 #include <dev/pci/pcireg.h>
     51 #include <dev/pci/pcivar.h>
     52 #include <alpha/pci/ciareg.h>
     53 #include <alpha/pci/ciavar.h>
     54 #ifdef DEC_KN20AA
     55 #include <alpha/pci/pci_kn20aa.h>
     56 #endif
     57 #ifdef DEC_EB164
     58 #include <alpha/pci/pci_eb164.h>
     59 #endif
     60 
     61 int	ciamatch __P((struct device *, struct cfdata *, void *));
     62 void	ciaattach __P((struct device *, struct device *, void *));
     63 
     64 struct cfattach cia_ca = {
     65 	sizeof(struct cia_softc), ciamatch, ciaattach,
     66 };
     67 
     68 struct cfdriver cia_cd = {
     69 	NULL, "cia", DV_DULL,
     70 };
     71 
     72 static int	ciaprint __P((void *, const char *pnp));
     73 
     74 /* There can be only one. */
     75 int ciafound;
     76 struct cia_config cia_configuration;
     77 
     78 int
     79 ciamatch(parent, match, aux)
     80 	struct device *parent;
     81 	struct cfdata *match;
     82 	void *aux;
     83 {
     84 	struct confargs *ca = aux;
     85 
     86 	/* Make sure that we're looking for a CIA. */
     87 	if (strcmp(ca->ca_name, cia_cd.cd_name) != 0)
     88 		return (0);
     89 
     90 	if (ciafound)
     91 		return (0);
     92 
     93 	return (1);
     94 }
     95 
     96 /*
     97  * Set up the chipset's function pointers.
     98  */
     99 void
    100 cia_init(ccp, mallocsafe)
    101 	struct cia_config *ccp;
    102 	int mallocsafe;
    103 {
    104 
    105 	ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
    106 	ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
    107 	ccp->cc_rev = REGVAL(CIA_CSR_REV);
    108 
    109 	/*
    110 	 * Revisions >= 2 have the CNFG register.
    111 	 */
    112 	if (ccp->cc_rev >= 2)
    113 		ccp->cc_cnfg = REGVAL(CIA_CSR_CNFG);
    114 	else
    115 		ccp->cc_cnfg = 0;
    116 
    117 	if (!ccp->cc_initted) {
    118 		/* don't do these twice since they set up extents */
    119 		cia_swiz_bus_io_init(&ccp->cc_iot, ccp);
    120 		cia_swiz_bus_mem_init(&ccp->cc_memt, ccp);
    121 	}
    122 	ccp->cc_mallocsafe = mallocsafe;
    123 
    124 	cia_pci_init(&ccp->cc_pc, ccp);
    125 
    126 	cia_dma_init(ccp);
    127 
    128 	ccp->cc_initted = 1;
    129 }
    130 
    131 void
    132 ciaattach(parent, self, aux)
    133 	struct device *parent, *self;
    134 	void *aux;
    135 {
    136 	struct cia_softc *sc = (struct cia_softc *)self;
    137 	struct cia_config *ccp;
    138 	struct pcibus_attach_args pba;
    139 
    140 	/* note that we've attached the chipset; can't have 2 CIAs. */
    141 	ciafound = 1;
    142 
    143 	/*
    144 	 * set up the chipset's info; done once at console init time
    145 	 * (maybe), but we must do it here as well to take care of things
    146 	 * that need to use memory allocation.
    147 	 */
    148 	ccp = sc->sc_ccp = &cia_configuration;
    149 	cia_init(ccp, 1);
    150 
    151 	printf(": DECchip 21171/21172 Core Logic chipset rev. %d\n",
    152 	    ccp->cc_rev);
    153 
    154 	/*
    155 	 * XXX Should we print any more?  We only care about BWX right now.
    156 	 */
    157 	if (ccp->cc_cnfg & CNFG_BWEN)
    158 		printf("%s: EV56 BWX enabled\n", self->dv_xname);
    159 
    160 	switch (hwrpb->rpb_type) {
    161 #ifdef DEC_KN20AA
    162 	case ST_DEC_KN20AA:
    163 		pci_kn20aa_pickintr(ccp);
    164 #ifdef EVCNT_COUNTERS
    165 		evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
    166 #endif
    167 		break;
    168 #endif
    169 
    170 #ifdef DEC_EB164
    171 	case ST_EB164:
    172 		pci_eb164_pickintr(ccp);
    173 #ifdef EVCNT_COUNTERS
    174 		evcnt_attach(self, "intr", &eb164_intr_evcnt);
    175 #endif
    176 		break;
    177 #endif
    178 
    179 	default:
    180 		panic("ciaattach: shouldn't be here, really...");
    181 	}
    182 
    183 	pba.pba_busname = "pci";
    184 	pba.pba_iot = &ccp->cc_iot;
    185 	pba.pba_memt = &ccp->cc_memt;
    186 	pba.pba_dmat = &ccp->cc_dmat_direct;
    187 	pba.pba_pc = &ccp->cc_pc;
    188 	pba.pba_bus = 0;
    189 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    190 	config_found(self, &pba, ciaprint);
    191 }
    192 
    193 static int
    194 ciaprint(aux, pnp)
    195 	void *aux;
    196 	const char *pnp;
    197 {
    198 	register struct pcibus_attach_args *pba = aux;
    199 
    200 	/* only PCIs can attach to CIAs; easy. */
    201 	if (pnp)
    202 		printf("%s at %s", pba->pba_busname, pnp);
    203 	printf(" bus %d", pba->pba_bus);
    204 	return (UNCONF);
    205 }
    206