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