dwlpx.c revision 1.13 1 1.13 thorpej /* $NetBSD: dwlpx.c,v 1.13 1998/01/12 10:21:12 thorpej Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.2 cgd * Copyright (c) 1997 by Matthew Jacob
5 1.1 cgd * NASA AMES Research Center.
6 1.1 cgd * All rights reserved.
7 1.1 cgd *
8 1.1 cgd * Redistribution and use in source and binary forms, with or without
9 1.1 cgd * modification, are permitted provided that the following conditions
10 1.1 cgd * are met:
11 1.1 cgd * 1. Redistributions of source code must retain the above copyright
12 1.1 cgd * notice immediately at the beginning of the file, without modification,
13 1.1 cgd * this list of conditions, and the following disclaimer.
14 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 cgd * notice, this list of conditions and the following disclaimer in the
16 1.1 cgd * documentation and/or other materials provided with the distribution.
17 1.1 cgd * 3. The name of the author may not be used to endorse or promote products
18 1.1 cgd * derived from this software without specific prior written permission.
19 1.1 cgd *
20 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 1.1 cgd * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1 cgd * SUCH DAMAGE.
31 1.1 cgd */
32 1.3 cgd
33 1.4 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
34 1.4 cgd
35 1.13 thorpej __KERNEL_RCSID(0, "$NetBSD: dwlpx.c,v 1.13 1998/01/12 10:21:12 thorpej Exp $");
36 1.1 cgd
37 1.1 cgd #include <sys/param.h>
38 1.1 cgd #include <sys/systm.h>
39 1.1 cgd #include <sys/kernel.h>
40 1.1 cgd #include <sys/device.h>
41 1.1 cgd #include <vm/vm.h>
42 1.1 cgd
43 1.1 cgd #include <machine/autoconf.h>
44 1.1 cgd #include <dev/pci/pcireg.h>
45 1.1 cgd #include <dev/pci/pcivar.h>
46 1.1 cgd #include <alpha/tlsb/tlsbreg.h>
47 1.1 cgd #include <alpha/tlsb/kftxxvar.h>
48 1.1 cgd #include <alpha/tlsb/kftxxreg.h>
49 1.1 cgd #include <alpha/pci/dwlpxreg.h>
50 1.1 cgd #include <alpha/pci/dwlpxvar.h>
51 1.1 cgd #include <alpha/pci/pci_kn8ae.h>
52 1.1 cgd
53 1.1 cgd #include <alpha/include/pmap.old.h>
54 1.1 cgd
55 1.1 cgd #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
56 1.1 cgd
57 1.1 cgd static int dwlpxmatch __P((struct device *, struct cfdata *, void *));
58 1.1 cgd static void dwlpxattach __P((struct device *, struct device *, void *));
59 1.13 thorpej
60 1.1 cgd struct cfattach dwlpx_ca = {
61 1.1 cgd sizeof(struct dwlpx_softc), dwlpxmatch, dwlpxattach
62 1.1 cgd };
63 1.1 cgd
64 1.13 thorpej extern struct cfdriver dwlpx_cd;
65 1.1 cgd
66 1.1 cgd static int dwlpxprint __P((void *, const char *));
67 1.1 cgd
68 1.1 cgd static int
69 1.1 cgd dwlpxprint(aux, pnp)
70 1.1 cgd void *aux;
71 1.1 cgd const char *pnp;
72 1.1 cgd {
73 1.1 cgd register struct pcibus_attach_args *pba = aux;
74 1.1 cgd /* only PCIs can attach to DWLPX's; easy. */
75 1.1 cgd if (pnp)
76 1.1 cgd printf("%s at %s", pba->pba_busname, pnp);
77 1.1 cgd printf(" bus %d", pba->pba_bus);
78 1.1 cgd return (UNCONF);
79 1.1 cgd }
80 1.1 cgd
81 1.1 cgd static int
82 1.1 cgd dwlpxmatch(parent, cf, aux)
83 1.1 cgd struct device *parent;
84 1.1 cgd struct cfdata *cf;
85 1.1 cgd void *aux;
86 1.1 cgd {
87 1.1 cgd struct kft_dev_attach_args *ka = aux;
88 1.1 cgd
89 1.1 cgd if (strcmp(ka->ka_name, dwlpx_cd.cd_name) != 0)
90 1.1 cgd return (0);
91 1.1 cgd return (1);
92 1.1 cgd }
93 1.1 cgd
94 1.1 cgd static void
95 1.1 cgd dwlpxattach(parent, self, aux)
96 1.1 cgd struct device *parent;
97 1.1 cgd struct device *self;
98 1.1 cgd void *aux;
99 1.1 cgd {
100 1.1 cgd static int once = 0;
101 1.1 cgd struct dwlpx_softc *sc = (struct dwlpx_softc *)self;
102 1.8 thorpej struct dwlpx_config *ccp = &sc->dwlpx_cc;
103 1.1 cgd struct kft_dev_attach_args *ka = aux;
104 1.1 cgd struct pcibus_attach_args pba;
105 1.8 thorpej u_int32_t pcia_present;
106 1.1 cgd
107 1.1 cgd sc->dwlpx_node = ka->ka_node;
108 1.1 cgd sc->dwlpx_dtype = ka->ka_dtype;
109 1.1 cgd sc->dwlpx_hosenum = ka->ka_hosenum;
110 1.1 cgd /*
111 1.1 cgd * On reads, you get a fault if you read a nonexisted HPC.
112 1.1 cgd * The internal KFTIA hose (hose 0) has only 2 HPCs.
113 1.1 cgd */
114 1.1 cgd sc->dwlpx_nhpc = NHPC;
115 1.1 cgd if (sc->dwlpx_hosenum == 0) {
116 1.1 cgd if (TLDEV_DTYPE(sc->dwlpx_dtype) == TLDEV_DTYPE_KFTIA) {
117 1.1 cgd sc->dwlpx_nhpc = NHPC - 1;
118 1.1 cgd }
119 1.1 cgd }
120 1.1 cgd
121 1.1 cgd dwlpx_init(sc);
122 1.8 thorpej
123 1.8 thorpej /* XXX Need to detect DWLPA vs. DWLPB here. */
124 1.8 thorpej pcia_present = REGVAL(PCIA_PRESENT + ccp->cc_sysbase);
125 1.8 thorpej
126 1.8 thorpej printf(": PCIA rev. %d, STD I/O %spresent\n",
127 1.8 thorpej (pcia_present >> PCIA_PRESENT_REVSHIFT) & PCIA_PRESENT_REVMASK,
128 1.8 thorpej (pcia_present & PCIA_PRESENT_STDIO) == 0 ? "not " : "");
129 1.8 thorpej
130 1.8 thorpej #if 0
131 1.8 thorpej {
132 1.8 thorpej int hpc, slot, slotval;
133 1.8 thorpej const char *str;
134 1.8 thorpej
135 1.8 thorpej for (hpc = 0; hpc < sc->dwlpx_nhpc; hpc++) {
136 1.8 thorpej for (slot = 0; slot < 4; slot++) {
137 1.8 thorpej slotval = (pcia_present >>
138 1.8 thorpej PCIA_PRESENT_SLOTSHIFT(hpc, slot)) &
139 1.8 thorpej PCIA_PRESENT_SLOT_MASK;
140 1.8 thorpej if (slotval == PCIA_PRESENT_SLOT_NONE)
141 1.8 thorpej continue;
142 1.8 thorpej switch (slotval) {
143 1.8 thorpej case PCIA_PRESENT_SLOT_25W:
144 1.8 thorpej str = "25";
145 1.8 thorpej break;
146 1.8 thorpej case PCIA_PRESENT_SLOT_15W:
147 1.8 thorpej str = "15";
148 1.8 thorpej break;
149 1.8 thorpej case PCIA_PRESENT_SLOW_7W:
150 1.8 thorpej default: /* XXX gcc */
151 1.8 thorpej str = "7.5";
152 1.8 thorpej break;
153 1.8 thorpej }
154 1.8 thorpej printf("%s: hpc %d slot %d: %s watt module\n",
155 1.8 thorpej sc->dwlpx_dev.dv_xname, hpc, slot, str);
156 1.8 thorpej }
157 1.8 thorpej }
158 1.8 thorpej }
159 1.8 thorpej #endif
160 1.8 thorpej
161 1.1 cgd if (once == 0) {
162 1.1 cgd /*
163 1.1 cgd * Set up interrupts
164 1.1 cgd */
165 1.1 cgd pci_kn8ae_pickintr(&sc->dwlpx_cc, 1);
166 1.1 cgd #ifdef EVCNT_COUNTERS
167 1.1 cgd evcnt_attach(self, "intr", kn8ae_intr_evcnt);
168 1.1 cgd #endif
169 1.1 cgd once++;
170 1.1 cgd } else {
171 1.1 cgd pci_kn8ae_pickintr(&sc->dwlpx_cc, 0);
172 1.1 cgd }
173 1.1 cgd
174 1.1 cgd /*
175 1.1 cgd * Attach PCI bus
176 1.1 cgd */
177 1.1 cgd pba.pba_busname = "pci";
178 1.11 thorpej pba.pba_iot = &sc->dwlpx_cc.cc_iot;
179 1.11 thorpej pba.pba_memt = &sc->dwlpx_cc.cc_memt;
180 1.6 thorpej pba.pba_dmat = /* start with direct, may change... */
181 1.6 thorpej alphabus_dma_get_tag(&sc->dwlpx_cc.cc_dmat_direct, ALPHA_BUS_PCI);
182 1.1 cgd pba.pba_pc = &sc->dwlpx_cc.cc_pc;
183 1.1 cgd pba.pba_bus = 0;
184 1.5 cgd pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
185 1.1 cgd config_found(self, &pba, dwlpxprint);
186 1.1 cgd }
187 1.1 cgd
188 1.1 cgd void
189 1.1 cgd dwlpx_init(sc)
190 1.1 cgd struct dwlpx_softc *sc;
191 1.1 cgd {
192 1.1 cgd int i;
193 1.1 cgd struct dwlpx_config *ccp = &sc->dwlpx_cc;
194 1.1 cgd
195 1.1 cgd if (ccp->cc_initted == 0) {
196 1.10 thorpej dwlpx_bus_io_init(&ccp->cc_iot, ccp);
197 1.10 thorpej dwlpx_bus_mem_init(&ccp->cc_memt, ccp);
198 1.1 cgd }
199 1.1 cgd dwlpx_pci_init(&ccp->cc_pc, ccp);
200 1.1 cgd ccp->cc_sc = sc;
201 1.1 cgd
202 1.1 cgd /*
203 1.1 cgd * Establish a precalculated base for convenience's sake.
204 1.1 cgd */
205 1.1 cgd ccp->cc_sysbase =
206 1.1 cgd (((unsigned long)(sc->dwlpx_node - 4)) << 36) |
207 1.1 cgd (((unsigned long) sc->dwlpx_hosenum) << 34) |
208 1.1 cgd (1LL << 39);
209 1.1 cgd
210 1.1 cgd /*
211 1.6 thorpej * Set up DMA stuff for this DWLPX.
212 1.1 cgd */
213 1.6 thorpej dwlpx_dma_init(ccp);
214 1.1 cgd
215 1.1 cgd /*
216 1.1 cgd * Set up interrupt stuff for this DWLPX.
217 1.1 cgd *
218 1.1 cgd * Note that all PCI interrupt pins are disabled at this time.
219 1.1 cgd *
220 1.1 cgd * Do this even for all HPCs- even for the nonexistent
221 1.1 cgd * one on hose zero of a KFTIA.
222 1.1 cgd */
223 1.1 cgd for (i = 0; i < NHPC; i++) {
224 1.1 cgd REGVAL(PCIA_IMASK(i) + ccp->cc_sysbase) = DWLPX_IMASK_DFLT;
225 1.1 cgd REGVAL(PCIA_ERRVEC(i) + ccp->cc_sysbase) =
226 1.1 cgd DWLPX_ERRVEC((sc->dwlpx_node - 4), sc->dwlpx_hosenum);
227 1.1 cgd }
228 1.1 cgd for (i = 0; i < DWLPX_MAXDEV; i++) {
229 1.1 cgd u_int16_t vec;
230 1.1 cgd int ss, hpc;
231 1.1 cgd
232 1.1 cgd vec = DWLPX_MVEC((sc->dwlpx_node - 4), sc->dwlpx_hosenum, i);
233 1.1 cgd ss = i;
234 1.1 cgd if (i < 4) {
235 1.1 cgd hpc = 0;
236 1.1 cgd } else if (i < 8) {
237 1.1 cgd ss -= 4;
238 1.1 cgd hpc = 1;
239 1.1 cgd } else {
240 1.1 cgd ss -= 8;
241 1.1 cgd hpc = 2;
242 1.1 cgd }
243 1.1 cgd REGVAL(PCIA_DEVVEC(hpc, ss, 1) + ccp->cc_sysbase) = vec;
244 1.1 cgd REGVAL(PCIA_DEVVEC(hpc, ss, 2) + ccp->cc_sysbase) = vec;
245 1.1 cgd REGVAL(PCIA_DEVVEC(hpc, ss, 3) + ccp->cc_sysbase) = vec;
246 1.1 cgd REGVAL(PCIA_DEVVEC(hpc, ss, 4) + ccp->cc_sysbase) = vec;
247 1.1 cgd }
248 1.1 cgd /*
249 1.1 cgd * Establish HAE values, as well as make sure of sanity elsewhere.
250 1.1 cgd */
251 1.1 cgd for (i = 0; i < sc->dwlpx_nhpc; i++) {
252 1.1 cgd u_int32_t ctl = REGVAL(PCIA_CTL(i) + ccp->cc_sysbase);
253 1.1 cgd ctl &= 0x0fffffff;
254 1.9 mjacob ctl &= ~(PCIA_CTL_MHAE(0x1f) | PCIA_CTL_IHAE(0x1f));
255 1.9 mjacob /*
256 1.9 mjacob * I originally also had it or'ing in 3, which makes no sense.
257 1.9 mjacob */
258 1.9 mjacob
259 1.9 mjacob ctl |= PCIA_CTL_RMMENA | PCIA_CTL_RMMARB;
260 1.9 mjacob
261 1.9 mjacob /*
262 1.9 mjacob * Only valid if we're attached to a KFTIA or a KTHA.
263 1.9 mjacob */
264 1.9 mjacob ctl |= PCIA_CTL_3UP;
265 1.9 mjacob
266 1.9 mjacob ctl |= PCIA_CTL_CUTENA;
267 1.9 mjacob
268 1.1 cgd REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) = ctl;
269 1.1 cgd }
270 1.1 cgd ccp->cc_initted = 1;
271 1.1 cgd }
272