cia.c revision 1.15 1 /* $NetBSD: cia.c,v 1.15 1996/12/05 01:39:35 cgd 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/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/device.h>
35 #include <vm/vm.h>
36
37 #include <machine/autoconf.h>
38 #include <machine/rpb.h>
39
40 #include <dev/isa/isareg.h>
41 #include <dev/isa/isavar.h>
42
43 #include <dev/pci/pcireg.h>
44 #include <dev/pci/pcivar.h>
45 #include <alpha/pci/ciareg.h>
46 #include <alpha/pci/ciavar.h>
47 #if defined(DEC_KN20AA)
48 #include <alpha/pci/pci_kn20aa.h>
49 #endif
50 #if defined(DEC_EB164)
51 #include <alpha/pci/pci_eb164.h>
52 #endif
53
54 #ifdef __BROKEN_INDIRECT_CONFIG
55 int ciamatch __P((struct device *, void *, void *));
56 #else
57 int ciamatch __P((struct device *, struct cfdata *, void *));
58 #endif
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 #ifdef __BROKEN_INDIRECT_CONFIG
79 void *match;
80 #else
81 struct cfdata *match;
82 #endif
83 void *aux;
84 {
85 struct confargs *ca = aux;
86
87 /* Make sure that we're looking for a CIA. */
88 if (strcmp(ca->ca_name, cia_cd.cd_name) != 0)
89 return (0);
90
91 if (ciafound)
92 return (0);
93
94 return (1);
95 }
96
97 /*
98 * Set up the chipset's function pointers.
99 */
100 void
101 cia_init(ccp, mallocsafe)
102 struct cia_config *ccp;
103 int mallocsafe;
104 {
105
106 /*
107 * Can't set up SGMAP data here; can be called before malloc().
108 * XXX THIS COMMENT NO LONGER MAKES SENSE.
109 */
110
111 ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
112 ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
113
114 if (!ccp->cc_initted) {
115 /* don't do these twice since they set up extents */
116 ccp->cc_iot = cia_bus_io_init(ccp);
117 ccp->cc_memt = cia_bus_mem_init(ccp);
118 }
119 ccp->cc_mallocsafe = mallocsafe;
120
121 cia_pci_init(&ccp->cc_pc, ccp);
122
123 /* XXX XXX BEGIN XXX XXX */
124 { /* XXX */
125 extern vm_offset_t alpha_XXX_dmamap_or; /* XXX */
126 alpha_XXX_dmamap_or = 0x40000000; /* XXX */
127 } /* XXX */
128 /* XXX XXX END XXX XXX */
129
130 ccp->cc_initted = 1;
131 }
132
133 void
134 ciaattach(parent, self, aux)
135 struct device *parent, *self;
136 void *aux;
137 {
138 struct cia_softc *sc = (struct cia_softc *)self;
139 struct cia_config *ccp;
140 struct pcibus_attach_args pba;
141
142 /* note that we've attached the chipset; can't have 2 CIAs. */
143 ciafound = 1;
144
145 /*
146 * set up the chipset's info; done once at console init time
147 * (maybe), but doesn't hurt to do twice.
148 */
149 ccp = sc->sc_ccp = &cia_configuration;
150 cia_init(ccp, 1);
151
152 /* XXX print chipset information */
153 printf("\n");
154
155 switch (hwrpb->rpb_type) {
156 #if defined(DEC_KN20AA)
157 case ST_DEC_KN20AA:
158 pci_kn20aa_pickintr(ccp);
159 #ifdef EVCNT_COUNTERS
160 evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
161 #endif
162 break;
163 #endif
164
165 #if defined(DEC_EB164)
166 case ST_EB164:
167 pci_eb164_pickintr(ccp);
168 #ifdef EVCNT_COUNTERS
169 evcnt_attach(self, "intr", &eb164_intr_evcnt);
170 #endif
171 break;
172 #endif
173
174 default:
175 panic("ciaattach: shouldn't be here, really...");
176 }
177
178 pba.pba_busname = "pci";
179 pba.pba_iot = ccp->cc_iot;
180 pba.pba_memt = ccp->cc_memt;
181 pba.pba_pc = &ccp->cc_pc;
182 pba.pba_bus = 0;
183 config_found(self, &pba, ciaprint);
184 }
185
186 static int
187 ciaprint(aux, pnp)
188 void *aux;
189 const char *pnp;
190 {
191 register struct pcibus_attach_args *pba = aux;
192
193 /* only PCIs can attach to CIAs; easy. */
194 if (pnp)
195 printf("%s at %s", pba->pba_busname, pnp);
196 printf(" bus %d", pba->pba_bus);
197 return (UNCONF);
198 }
199