cia.c revision 1.1 1 1.1 cgd /* $NetBSD: cia.c,v 1.1 1995/11/23 02:37:24 cgd Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.1 cgd * Copyright (c) 1995 Carnegie-Mellon University.
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Author: Chris G. Demetriou
8 1.1 cgd *
9 1.1 cgd * Permission to use, copy, modify and distribute this software and
10 1.1 cgd * its documentation is hereby granted, provided that both the copyright
11 1.1 cgd * notice and this permission notice appear in all copies of the
12 1.1 cgd * software, derivative works or modified versions, and any portions
13 1.1 cgd * thereof, and that both notices appear in supporting documentation.
14 1.1 cgd *
15 1.1 cgd * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 cgd * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 cgd *
19 1.1 cgd * Carnegie Mellon requests users of this software to return to
20 1.1 cgd *
21 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 cgd * School of Computer Science
23 1.1 cgd * Carnegie Mellon University
24 1.1 cgd * Pittsburgh PA 15213-3890
25 1.1 cgd *
26 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
27 1.1 cgd * rights to redistribute these changes.
28 1.1 cgd */
29 1.1 cgd
30 1.1 cgd #include <sys/param.h>
31 1.1 cgd #include <sys/systm.h>
32 1.1 cgd #include <sys/kernel.h>
33 1.1 cgd #include <sys/malloc.h>
34 1.1 cgd #include <sys/device.h>
35 1.1 cgd #include <vm/vm.h>
36 1.1 cgd
37 1.1 cgd #include <machine/autoconf.h>
38 1.1 cgd #include <machine/rpb.h>
39 1.1 cgd
40 1.1 cgd #include <dev/isa/isareg.h>
41 1.1 cgd #include <dev/isa/isavar.h>
42 1.1 cgd
43 1.1 cgd #include <dev/pci/pcireg.h>
44 1.1 cgd #include <dev/pci/pcivar.h>
45 1.1 cgd #include <alpha/pci/ciareg.h>
46 1.1 cgd #include <alpha/pci/ciavar.h>
47 1.1 cgd #if defined(DEC_KN20AA)
48 1.1 cgd #include <alpha/pci/pci_kn20aa.h>
49 1.1 cgd #endif
50 1.1 cgd
51 1.1 cgd int ciamatch __P((struct device *, void *, void *));
52 1.1 cgd void ciaattach __P((struct device *, struct device *, void *));
53 1.1 cgd
54 1.1 cgd struct cfdriver ciacd = {
55 1.1 cgd NULL, "cia", ciamatch, ciaattach, DV_DULL,
56 1.1 cgd sizeof(struct cia_softc)
57 1.1 cgd };
58 1.1 cgd
59 1.1 cgd static int ciaprint __P((void *, char *pnp));
60 1.1 cgd
61 1.1 cgd #define REGVAL(r) (*(int32_t *)phystok0seg(r))
62 1.1 cgd
63 1.1 cgd /* There can be only one. */
64 1.1 cgd int ciafound;
65 1.1 cgd struct cia_config cia_configuration;
66 1.1 cgd
67 1.1 cgd int
68 1.1 cgd ciamatch(parent, match, aux)
69 1.1 cgd struct device *parent;
70 1.1 cgd void *match, *aux;
71 1.1 cgd {
72 1.1 cgd struct cfdata *cf = match;
73 1.1 cgd struct confargs *ca = aux;
74 1.1 cgd
75 1.1 cgd /* Make sure that we're looking for a CIA. */
76 1.1 cgd if (strcmp(ca->ca_name, ciacd.cd_name) != 0)
77 1.1 cgd return (0);
78 1.1 cgd
79 1.1 cgd if (ciafound)
80 1.1 cgd return (0);
81 1.1 cgd
82 1.1 cgd return (1);
83 1.1 cgd }
84 1.1 cgd
85 1.1 cgd /*
86 1.1 cgd * Set up the chipset's function pointers.
87 1.1 cgd */
88 1.1 cgd void
89 1.1 cgd cia_init(ccp)
90 1.1 cgd struct cia_config *ccp;
91 1.1 cgd {
92 1.1 cgd
93 1.1 cgd /*
94 1.1 cgd * Can't set up SGMAP data here; can be called before malloc().
95 1.1 cgd */
96 1.1 cgd
97 1.1 cgd ccp->cc_conffns = &cia_conf_fns;
98 1.1 cgd ccp->cc_confarg = ccp;
99 1.1 cgd ccp->cc_dmafns = &cia_dma_fns;
100 1.1 cgd ccp->cc_dmaarg = ccp;
101 1.1 cgd /* Interrupt routines set up in 'attach' */
102 1.1 cgd ccp->cc_memfns = &cia_mem_fns;
103 1.1 cgd ccp->cc_memarg = ccp;
104 1.1 cgd ccp->cc_piofns = &cia_pio_fns;
105 1.1 cgd ccp->cc_pioarg = ccp;
106 1.1 cgd }
107 1.1 cgd
108 1.1 cgd void
109 1.1 cgd ciaattach(parent, self, aux)
110 1.1 cgd struct device *parent, *self;
111 1.1 cgd void *aux;
112 1.1 cgd {
113 1.1 cgd struct confargs *ca = aux;
114 1.1 cgd struct cia_softc *sc = (struct cia_softc *)self;
115 1.1 cgd struct cia_config *ccp;
116 1.1 cgd struct pci_attach_args pa;
117 1.1 cgd
118 1.1 cgd /* note that we've attached the chipset; can't have 2 CIAs. */
119 1.1 cgd ciafound = 1;
120 1.1 cgd
121 1.1 cgd /*
122 1.1 cgd * set up the chipset's info; done once at console init time
123 1.1 cgd * (maybe), but doesn't hurt to do twice.
124 1.1 cgd */
125 1.1 cgd ccp = sc->sc_ccp = &cia_configuration;
126 1.1 cgd cia_init(ccp);
127 1.1 cgd
128 1.1 cgd /* XXX print chipset information */
129 1.1 cgd printf("\n");
130 1.1 cgd
131 1.1 cgd switch (hwrpb->rpb_type) {
132 1.1 cgd #if defined(DEC_KN20AA)
133 1.1 cgd case ST_DEC_KN20AA:
134 1.1 cgd pci_kn20aa_pickintr(ccp->cc_conffns, ccp->cc_confarg,
135 1.1 cgd ccp->cc_piofns, ccp->cc_pioarg,
136 1.1 cgd &ccp->cc_intrfns, &ccp->cc_intrarg);
137 1.1 cgd #ifdef EVCNT_COUNTERS
138 1.1 cgd evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
139 1.1 cgd #endif
140 1.1 cgd break;
141 1.1 cgd #endif
142 1.1 cgd default:
143 1.1 cgd panic("ciaattach: shouldn't be here, really...");
144 1.1 cgd }
145 1.1 cgd
146 1.1 cgd pa.pa_bus = 0;
147 1.1 cgd pa.pa_maxdev = 32;
148 1.1 cgd pa.pa_burstlog2 = 8;
149 1.1 cgd
150 1.1 cgd pa.pa_conffns = ccp->cc_conffns;
151 1.1 cgd pa.pa_confarg = ccp->cc_confarg;
152 1.1 cgd pa.pa_dmafns = ccp->cc_dmafns;
153 1.1 cgd pa.pa_dmaarg = ccp->cc_dmaarg;
154 1.1 cgd pa.pa_intrfns = ccp->cc_intrfns;
155 1.1 cgd pa.pa_intrarg = ccp->cc_intrarg;
156 1.1 cgd pa.pa_memfns = ccp->cc_memfns;
157 1.1 cgd pa.pa_memarg = ccp->cc_memarg;
158 1.1 cgd pa.pa_piofns = ccp->cc_piofns;
159 1.1 cgd pa.pa_pioarg = ccp->cc_pioarg;
160 1.1 cgd
161 1.1 cgd config_found(self, &pa, ciaprint);
162 1.1 cgd }
163 1.1 cgd
164 1.1 cgd static int
165 1.1 cgd ciaprint(aux, pnp)
166 1.1 cgd void *aux;
167 1.1 cgd char *pnp;
168 1.1 cgd {
169 1.1 cgd register struct pci_attach_args *pa = aux;
170 1.1 cgd
171 1.1 cgd /* only PCIs can attach to CIAs; easy. */
172 1.1 cgd if (pnp)
173 1.1 cgd printf("pci at %s", pnp);
174 1.1 cgd printf(" bus %d", pa->pa_bus);
175 1.1 cgd return (UNCONF);
176 1.1 cgd }
177