cia.c revision 1.2 1 /* $NetBSD: cia.c,v 1.2 1996/03/17 01:06:31 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995 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
51 int ciamatch __P((struct device *, void *, void *));
52 void ciaattach __P((struct device *, struct device *, void *));
53
54 struct cfattach cia_ca = {
55 sizeof(struct cia_softc), ciamatch, ciaattach
56 };
57
58 struct cfdriver cia_cd = {
59 NULL, "cia", DV_DULL
60 };
61
62 static int ciaprint __P((void *, char *pnp));
63
64 #define REGVAL(r) (*(int32_t *)phystok0seg(r))
65
66 /* There can be only one. */
67 int ciafound;
68 struct cia_config cia_configuration;
69
70 int
71 ciamatch(parent, match, aux)
72 struct device *parent;
73 void *match, *aux;
74 {
75 struct cfdata *cf = match;
76 struct confargs *ca = aux;
77
78 /* Make sure that we're looking for a CIA. */
79 if (strcmp(ca->ca_name, cia_cd.cd_name) != 0)
80 return (0);
81
82 if (ciafound)
83 return (0);
84
85 return (1);
86 }
87
88 /*
89 * Set up the chipset's function pointers.
90 */
91 void
92 cia_init(ccp)
93 struct cia_config *ccp;
94 {
95
96 /*
97 * Can't set up SGMAP data here; can be called before malloc().
98 */
99
100 ccp->cc_conffns = &cia_conf_fns;
101 ccp->cc_confarg = ccp;
102 ccp->cc_dmafns = &cia_dma_fns;
103 ccp->cc_dmaarg = ccp;
104 /* Interrupt routines set up in 'attach' */
105 ccp->cc_memfns = &cia_mem_fns;
106 ccp->cc_memarg = ccp;
107 ccp->cc_piofns = &cia_pio_fns;
108 ccp->cc_pioarg = ccp;
109 }
110
111 void
112 ciaattach(parent, self, aux)
113 struct device *parent, *self;
114 void *aux;
115 {
116 struct confargs *ca = aux;
117 struct cia_softc *sc = (struct cia_softc *)self;
118 struct cia_config *ccp;
119 struct pci_attach_args pa;
120
121 /* note that we've attached the chipset; can't have 2 CIAs. */
122 ciafound = 1;
123
124 /*
125 * set up the chipset's info; done once at console init time
126 * (maybe), but doesn't hurt to do twice.
127 */
128 ccp = sc->sc_ccp = &cia_configuration;
129 cia_init(ccp);
130
131 /* XXX print chipset information */
132 printf("\n");
133
134 switch (hwrpb->rpb_type) {
135 #if defined(DEC_KN20AA)
136 case ST_DEC_KN20AA:
137 pci_kn20aa_pickintr(ccp->cc_conffns, ccp->cc_confarg,
138 ccp->cc_piofns, ccp->cc_pioarg,
139 &ccp->cc_intrfns, &ccp->cc_intrarg);
140 #ifdef EVCNT_COUNTERS
141 evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
142 #endif
143 break;
144 #endif
145 default:
146 panic("ciaattach: shouldn't be here, really...");
147 }
148
149 pa.pa_bus = 0;
150 pa.pa_maxdev = 32;
151 pa.pa_burstlog2 = 8;
152
153 pa.pa_conffns = ccp->cc_conffns;
154 pa.pa_confarg = ccp->cc_confarg;
155 pa.pa_dmafns = ccp->cc_dmafns;
156 pa.pa_dmaarg = ccp->cc_dmaarg;
157 pa.pa_intrfns = ccp->cc_intrfns;
158 pa.pa_intrarg = ccp->cc_intrarg;
159 pa.pa_memfns = ccp->cc_memfns;
160 pa.pa_memarg = ccp->cc_memarg;
161 pa.pa_piofns = ccp->cc_piofns;
162 pa.pa_pioarg = ccp->cc_pioarg;
163
164 config_found(self, &pa, ciaprint);
165 }
166
167 static int
168 ciaprint(aux, pnp)
169 void *aux;
170 char *pnp;
171 {
172 register struct pci_attach_args *pa = aux;
173
174 /* only PCIs can attach to CIAs; easy. */
175 if (pnp)
176 printf("pci at %s", pnp);
177 printf(" bus %d", pa->pa_bus);
178 return (UNCONF);
179 }
180