Home | History | Annotate | Line # | Download | only in pci
cia.c revision 1.21
      1 /* $NetBSD: cia.c,v 1.21 1997/06/06 23:54:25 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 <machine/options.h>		/* Config options headers */
     31 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     32 
     33 __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.21 1997/06/06 23:54:25 thorpej Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/kernel.h>
     38 #include <sys/malloc.h>
     39 #include <sys/device.h>
     40 #include <vm/vm.h>
     41 
     42 #include <machine/autoconf.h>
     43 #include <machine/rpb.h>
     44 
     45 #include <dev/isa/isareg.h>
     46 #include <dev/isa/isavar.h>
     47 
     48 #include <dev/pci/pcireg.h>
     49 #include <dev/pci/pcivar.h>
     50 #include <alpha/pci/ciareg.h>
     51 #include <alpha/pci/ciavar.h>
     52 #ifdef DEC_KN20AA
     53 #include <alpha/pci/pci_kn20aa.h>
     54 #endif
     55 #ifdef DEC_EB164
     56 #include <alpha/pci/pci_eb164.h>
     57 #endif
     58 
     59 int	ciamatch __P((struct device *, struct cfdata *, void *));
     60 void	ciaattach __P((struct device *, struct device *, void *));
     61 
     62 struct cfattach cia_ca = {
     63 	sizeof(struct cia_softc), ciamatch, ciaattach,
     64 };
     65 
     66 struct cfdriver cia_cd = {
     67 	NULL, "cia", DV_DULL,
     68 };
     69 
     70 static int	ciaprint __P((void *, const char *pnp));
     71 
     72 /* There can be only one. */
     73 int ciafound;
     74 struct cia_config cia_configuration;
     75 
     76 int
     77 ciamatch(parent, match, aux)
     78 	struct device *parent;
     79 	struct cfdata *match;
     80 	void *aux;
     81 {
     82 	struct confargs *ca = aux;
     83 
     84 	/* Make sure that we're looking for a CIA. */
     85 	if (strcmp(ca->ca_name, cia_cd.cd_name) != 0)
     86 		return (0);
     87 
     88 	if (ciafound)
     89 		return (0);
     90 
     91 	return (1);
     92 }
     93 
     94 /*
     95  * Set up the chipset's function pointers.
     96  */
     97 void
     98 cia_init(ccp, mallocsafe)
     99 	struct cia_config *ccp;
    100 	int mallocsafe;
    101 {
    102 
    103 	ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
    104 	ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
    105 
    106 	if (!ccp->cc_initted) {
    107 		/* don't do these twice since they set up extents */
    108 		ccp->cc_iot = cia_bus_io_init(ccp);
    109 		ccp->cc_memt = cia_bus_mem_init(ccp);
    110 	}
    111 	ccp->cc_mallocsafe = mallocsafe;
    112 
    113 	cia_pci_init(&ccp->cc_pc, ccp);
    114 
    115 	cia_dma_init(ccp);
    116 
    117 	ccp->cc_initted = 1;
    118 }
    119 
    120 void
    121 ciaattach(parent, self, aux)
    122 	struct device *parent, *self;
    123 	void *aux;
    124 {
    125 	struct cia_softc *sc = (struct cia_softc *)self;
    126 	struct cia_config *ccp;
    127 	struct pcibus_attach_args pba;
    128 
    129 	/* note that we've attached the chipset; can't have 2 CIAs. */
    130 	ciafound = 1;
    131 
    132 	/*
    133 	 * set up the chipset's info; done once at console init time
    134 	 * (maybe), but we must do it here as well to take care of things
    135 	 * that need to use memory allocation.
    136 	 */
    137 	ccp = sc->sc_ccp = &cia_configuration;
    138 	cia_init(ccp, 1);
    139 
    140 	/* XXX print chipset information */
    141 	printf("\n");
    142 
    143 	switch (hwrpb->rpb_type) {
    144 #ifdef DEC_KN20AA
    145 	case ST_DEC_KN20AA:
    146 		pci_kn20aa_pickintr(ccp);
    147 #ifdef EVCNT_COUNTERS
    148 		evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
    149 #endif
    150 		break;
    151 #endif
    152 
    153 #ifdef DEC_EB164
    154 	case ST_EB164:
    155 		pci_eb164_pickintr(ccp);
    156 #ifdef EVCNT_COUNTERS
    157 		evcnt_attach(self, "intr", &eb164_intr_evcnt);
    158 #endif
    159 		break;
    160 #endif
    161 
    162 	default:
    163 		panic("ciaattach: shouldn't be here, really...");
    164 	}
    165 
    166 	pba.pba_busname = "pci";
    167 	pba.pba_iot = ccp->cc_iot;
    168 	pba.pba_memt = ccp->cc_memt;
    169 	pba.pba_dmat = &ccp->cc_dmat_direct;
    170 	pba.pba_pc = &ccp->cc_pc;
    171 	pba.pba_bus = 0;
    172 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    173 	config_found(self, &pba, ciaprint);
    174 }
    175 
    176 static int
    177 ciaprint(aux, pnp)
    178 	void *aux;
    179 	const char *pnp;
    180 {
    181 	register struct pcibus_attach_args *pba = aux;
    182 
    183 	/* only PCIs can attach to CIAs; easy. */
    184 	if (pnp)
    185 		printf("%s at %s", pba->pba_busname, pnp);
    186 	printf(" bus %d", pba->pba_bus);
    187 	return (UNCONF);
    188 }
    189