schizo.c revision 1.1 1 1.1 mrg /* $OpenBSD: schizo.c,v 1.55 2008/08/18 20:29:37 brad Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 2002 Jason L. Wright (jason (at) thought.net)
5 1.1 mrg * Copyright (c) 2003 Henric Jungheim
6 1.1 mrg * All rights reserved.
7 1.1 mrg *
8 1.1 mrg * Redistribution and use in source and binary forms, with or without
9 1.1 mrg * modification, are permitted provided that the following conditions
10 1.1 mrg * are met:
11 1.1 mrg * 1. Redistributions of source code must retain the above copyright
12 1.1 mrg * notice, this list of conditions and the following disclaimer.
13 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 mrg * notice, this list of conditions and the following disclaimer in the
15 1.1 mrg * documentation and/or other materials provided with the distribution.
16 1.1 mrg *
17 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.1 mrg * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 1.1 mrg * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 1.1 mrg * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 1.1 mrg * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.1 mrg * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 mrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 1.1 mrg * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 1.1 mrg * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1 mrg * POSSIBILITY OF SUCH DAMAGE.
28 1.1 mrg */
29 1.1 mrg
30 1.1 mrg #include <sys/param.h>
31 1.1 mrg #include <sys/device.h>
32 1.1 mrg #include <sys/errno.h>
33 1.1 mrg #include <sys/extent.h>
34 1.1 mrg #include <sys/malloc.h>
35 1.1 mrg #include <sys/systm.h>
36 1.1 mrg #include <sys/time.h>
37 1.1 mrg #include <sys/reboot.h>
38 1.1 mrg
39 1.1 mrg #define _SPARC_BUS_DMA_PRIVATE
40 1.1 mrg #include <machine/bus.h>
41 1.1 mrg #include <machine/autoconf.h>
42 1.1 mrg #include <machine/psl.h>
43 1.1 mrg
44 1.1 mrg #include <dev/pci/pcivar.h>
45 1.1 mrg #include <dev/pci/pcireg.h>
46 1.1 mrg
47 1.1 mrg #include <sparc64/dev/iommureg.h>
48 1.1 mrg #include <sparc64/dev/iommuvar.h>
49 1.1 mrg #include <sparc64/dev/schizoreg.h>
50 1.1 mrg #include <sparc64/dev/schizovar.h>
51 1.1 mrg #include <sparc64/sparc64/cache.h>
52 1.1 mrg
53 1.1 mrg #ifdef DEBUG
54 1.1 mrg #define SDB_PROM 0x01
55 1.1 mrg #define SDB_BUSMAP 0x02
56 1.1 mrg #define SDB_INTR 0x04
57 1.1 mrg #define SDB_CONF 0x08
58 1.1 mrg int schizo_debug = ~0;
59 1.1 mrg #define DPRINTF(l, s) do { if (schizo_debug & l) printf s; } while (0)
60 1.1 mrg #else
61 1.1 mrg #define DPRINTF(l, s)
62 1.1 mrg #endif
63 1.1 mrg
64 1.1 mrg extern struct sparc_pci_chipset _sparc_pci_chipset;
65 1.1 mrg
66 1.1 mrg int schizo_match(struct device *, void *, void *);
67 1.1 mrg void schizo_attach(struct device *, struct device *, void *);
68 1.1 mrg void schizo_init(struct schizo_softc *, int);
69 1.1 mrg void schizo_init_iommu(struct schizo_softc *, struct schizo_pbm *);
70 1.1 mrg int schizo_print(void *, const char *);
71 1.1 mrg
72 1.1 mrg void schizo_set_intr(struct schizo_softc *, struct schizo_pbm *, int,
73 1.1 mrg int (*handler)(void *), void *, int, char *);
74 1.1 mrg int schizo_ue(void *);
75 1.1 mrg int schizo_ce(void *);
76 1.1 mrg int schizo_safari_error(void *);
77 1.1 mrg int schizo_pci_error(void *);
78 1.1 mrg
79 1.1 mrg pci_chipset_tag_t schizo_alloc_chipset(struct schizo_pbm *, int,
80 1.1 mrg pci_chipset_tag_t);
81 1.1 mrg bus_space_tag_t schizo_alloc_mem_tag(struct schizo_pbm *);
82 1.1 mrg bus_space_tag_t schizo_alloc_io_tag(struct schizo_pbm *);
83 1.1 mrg bus_space_tag_t schizo_alloc_config_tag(struct schizo_pbm *);
84 1.1 mrg bus_space_tag_t schizo_alloc_bus_tag(struct schizo_pbm *, const char *,
85 1.1 mrg int, int, int);
86 1.1 mrg bus_dma_tag_t schizo_alloc_dma_tag(struct schizo_pbm *);
87 1.1 mrg
88 1.1 mrg pcireg_t schizo_conf_read(pci_chipset_tag_t, pcitag_t, int);
89 1.1 mrg void schizo_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
90 1.1 mrg
91 1.1 mrg int schizo_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
92 1.1 mrg int schizo_bus_map(bus_space_tag_t, bus_space_tag_t, bus_addr_t,
93 1.1 mrg bus_size_t, int, bus_space_handle_t *);
94 1.1 mrg paddr_t schizo_bus_mmap(bus_space_tag_t, bus_space_tag_t, bus_addr_t, off_t,
95 1.1 mrg int, int);
96 1.1 mrg bus_addr_t schizo_bus_addr(bus_space_tag_t, bus_space_tag_t,
97 1.1 mrg bus_space_handle_t);
98 1.1 mrg void *schizo_intr_establish(bus_space_tag_t, bus_space_tag_t, int, int, int,
99 1.1 mrg int (*)(void *), void *, const char *);
100 1.1 mrg
101 1.1 mrg int schizo_dmamap_create(bus_dma_tag_t, bus_dma_tag_t, bus_size_t, int,
102 1.1 mrg bus_size_t, bus_size_t, int, bus_dmamap_t *);
103 1.1 mrg
104 1.1 mrg int
105 1.1 mrg schizo_match(struct device *parent, void *match, void *aux)
106 1.1 mrg {
107 1.1 mrg struct mainbus_attach_args *ma = aux;
108 1.1 mrg char *str;
109 1.1 mrg
110 1.1 mrg if (strcmp(ma->ma_name, "pci") != 0)
111 1.1 mrg return (0);
112 1.1 mrg
113 1.1 mrg str = getpropstring(ma->ma_node, "model");
114 1.1 mrg if (strcmp(str, "schizo") == 0)
115 1.1 mrg return (1);
116 1.1 mrg
117 1.1 mrg str = getpropstring(ma->ma_node, "compatible");
118 1.1 mrg if (strcmp(str, "pci108e,8001") == 0)
119 1.1 mrg return (1);
120 1.1 mrg if (strcmp(str, "pci108e,8002") == 0) /* XMITS */
121 1.1 mrg return (1);
122 1.1 mrg if (strcmp(str, "pci108e,a801") == 0) /* Tomatillo */
123 1.1 mrg return (1);
124 1.1 mrg
125 1.1 mrg return (0);
126 1.1 mrg }
127 1.1 mrg
128 1.1 mrg void
129 1.1 mrg schizo_attach(struct device *parent, struct device *self, void *aux)
130 1.1 mrg {
131 1.1 mrg struct schizo_softc *sc = (struct schizo_softc *)self;
132 1.1 mrg struct mainbus_attach_args *ma = aux;
133 1.1 mrg int busa;
134 1.1 mrg char *str;
135 1.1 mrg
136 1.1 mrg str = getpropstring(ma->ma_node, "compatible");
137 1.1 mrg if (strcmp(str, "pci108e,a801") == 0)
138 1.1 mrg sc->sc_tomatillo = 1;
139 1.1 mrg
140 1.1 mrg sc->sc_node = ma->ma_node;
141 1.1 mrg sc->sc_dmat = ma->ma_dmatag;
142 1.1 mrg sc->sc_bust = ma->ma_bustag;
143 1.1 mrg sc->sc_ctrl = ma->ma_reg[1].ur_paddr - 0x10000UL;
144 1.1 mrg sc->sc_ign = INTIGN(ma->ma_upaid << INTMAP_IGN_SHIFT);
145 1.1 mrg
146 1.1 mrg if ((ma->ma_reg[0].ur_paddr & 0x00700000) == 0x00600000)
147 1.1 mrg busa = 1;
148 1.1 mrg else
149 1.1 mrg busa = 0;
150 1.1 mrg
151 1.1 mrg if (bus_space_map(sc->sc_bust, sc->sc_ctrl,
152 1.1 mrg sizeof(struct schizo_regs), 0, &sc->sc_ctrlh)) {
153 1.1 mrg printf(": failed to map registers\n");
154 1.1 mrg return;
155 1.1 mrg }
156 1.1 mrg
157 1.1 mrg /* enable schizo ecc error interrupts */
158 1.1 mrg schizo_write(sc, SCZ_ECCCTRL, schizo_read(sc, SCZ_ECCCTRL) |
159 1.1 mrg SCZ_ECCCTRL_EE_INTEN | SCZ_ECCCTRL_UE_INTEN |
160 1.1 mrg SCZ_ECCCTRL_CE_INTEN);
161 1.1 mrg
162 1.1 mrg schizo_init(sc, busa);
163 1.1 mrg }
164 1.1 mrg
165 1.1 mrg void
166 1.1 mrg schizo_init(struct schizo_softc *sc, int busa)
167 1.1 mrg {
168 1.1 mrg struct schizo_pbm *pbm;
169 1.1 mrg struct pcibus_attach_args pba;
170 1.1 mrg int *busranges = NULL, nranges;
171 1.1 mrg u_int64_t match, reg;
172 1.1 mrg
173 1.1 mrg pbm = malloc(sizeof(*pbm), M_DEVBUF, M_NOWAIT | M_ZERO);
174 1.1 mrg if (pbm == NULL)
175 1.1 mrg panic("schizo: can't alloc schizo pbm");
176 1.1 mrg
177 1.1 mrg pbm->sp_sc = sc;
178 1.1 mrg pbm->sp_bus_a = busa;
179 1.1 mrg pbm->sp_regt = sc->sc_bust;
180 1.1 mrg
181 1.1 mrg if (getprop(sc->sc_node, "ranges", sizeof(struct schizo_range),
182 1.1 mrg &pbm->sp_nrange, (void **)&pbm->sp_range))
183 1.1 mrg panic("schizo: can't get ranges");
184 1.1 mrg
185 1.1 mrg if (getprop(sc->sc_node, "bus-range", sizeof(int), &nranges,
186 1.1 mrg (void **)&busranges))
187 1.1 mrg panic("schizo: can't get bus-range");
188 1.1 mrg
189 1.1 mrg printf(": \"%s\", version %d, ign %x, bus %c %d to %d\n",
190 1.1 mrg sc->sc_tomatillo ? "Tomatillo" : "Schizo",
191 1.1 mrg getpropint(sc->sc_node, "version#", 0), sc->sc_ign,
192 1.1 mrg busa ? 'A' : 'B', busranges[0], busranges[1]);
193 1.1 mrg
194 1.1 mrg if (bus_space_subregion(pbm->sp_regt, sc->sc_ctrlh,
195 1.1 mrg busa ? offsetof(struct schizo_regs, pbm_a) :
196 1.1 mrg offsetof(struct schizo_regs, pbm_b),
197 1.1 mrg sizeof(struct schizo_pbm_regs),
198 1.1 mrg &pbm->sp_regh)) {
199 1.1 mrg panic("schizo: unable to create PBM handle");
200 1.1 mrg }
201 1.1 mrg
202 1.1 mrg printf("%s: ", sc->sc_dv.dv_xname);
203 1.1 mrg schizo_init_iommu(sc, pbm);
204 1.1 mrg
205 1.1 mrg match = schizo_read(sc, busa ? SCZ_PCIA_IO_MATCH : SCZ_PCIB_IO_MATCH);
206 1.1 mrg pbm->sp_confpaddr = match & ~0x8000000000000000UL;
207 1.1 mrg
208 1.1 mrg pbm->sp_memt = schizo_alloc_mem_tag(pbm);
209 1.1 mrg pbm->sp_iot = schizo_alloc_io_tag(pbm);
210 1.1 mrg pbm->sp_cfgt = schizo_alloc_config_tag(pbm);
211 1.1 mrg pbm->sp_dmat = schizo_alloc_dma_tag(pbm);
212 1.1 mrg
213 1.1 mrg if (bus_space_map(pbm->sp_cfgt, 0, 0x1000000, 0, &pbm->sp_cfgh))
214 1.1 mrg panic("schizo: could not map config space");
215 1.1 mrg
216 1.1 mrg pbm->sp_pc = schizo_alloc_chipset(pbm, sc->sc_node,
217 1.1 mrg &_sparc_pci_chipset);
218 1.1 mrg
219 1.1 mrg pbm->sp_pc->bustag = pbm->sp_cfgt;
220 1.1 mrg pbm->sp_pc->bushandle = pbm->sp_cfgh;
221 1.1 mrg
222 1.1 mrg pba.pba_busname = "pci";
223 1.1 mrg pba.pba_domain = pci_ndomains++;
224 1.1 mrg pba.pba_bus = busranges[0];
225 1.1 mrg pba.pba_bridgetag = NULL;
226 1.1 mrg pba.pba_pc = pbm->sp_pc;
227 1.1 mrg #if 0
228 1.1 mrg pba.pba_flags = pbm->sp_flags;
229 1.1 mrg #endif
230 1.1 mrg pba.pba_dmat = pbm->sp_dmat;
231 1.1 mrg pba.pba_memt = pbm->sp_memt;
232 1.1 mrg pba.pba_iot = pbm->sp_iot;
233 1.1 mrg pba.pba_pc->conf_read = schizo_conf_read;
234 1.1 mrg pba.pba_pc->conf_write = schizo_conf_write;
235 1.1 mrg pba.pba_pc->intr_map = schizo_intr_map;
236 1.1 mrg
237 1.1 mrg free(busranges, M_DEVBUF);
238 1.1 mrg
239 1.1 mrg schizo_pbm_write(pbm, SCZ_PCI_INTR_RETRY, 5);
240 1.1 mrg
241 1.1 mrg /* clear out the bus errors */
242 1.1 mrg schizo_pbm_write(pbm, SCZ_PCI_CTRL, schizo_pbm_read(pbm, SCZ_PCI_CTRL));
243 1.1 mrg schizo_pbm_write(pbm, SCZ_PCI_AFSR, schizo_pbm_read(pbm, SCZ_PCI_AFSR));
244 1.1 mrg schizo_cfg_write(pbm, PCI_COMMAND_STATUS_REG,
245 1.1 mrg schizo_cfg_read(pbm, PCI_COMMAND_STATUS_REG));
246 1.1 mrg
247 1.1 mrg reg = schizo_pbm_read(pbm, SCZ_PCI_CTRL);
248 1.1 mrg /* enable/disable error interrupts and arbiter */
249 1.1 mrg reg |= SCZ_PCICTRL_EEN | SCZ_PCICTRL_MMU_INT | SCZ_PCICTRL_ARB;
250 1.1 mrg reg &= ~SCZ_PCICTRL_SBH_INT;
251 1.1 mrg schizo_pbm_write(pbm, SCZ_PCI_CTRL, reg);
252 1.1 mrg
253 1.1 mrg reg = schizo_pbm_read(pbm, SCZ_PCI_DIAG);
254 1.1 mrg reg &= ~(SCZ_PCIDIAG_D_RTRYARB | SCZ_PCIDIAG_D_RETRY |
255 1.1 mrg SCZ_PCIDIAG_D_INTSYNC);
256 1.1 mrg schizo_pbm_write(pbm, SCZ_PCI_DIAG, reg);
257 1.1 mrg
258 1.1 mrg if (busa)
259 1.1 mrg schizo_set_intr(sc, pbm, PIL_HIGH, schizo_pci_error,
260 1.1 mrg pbm, SCZ_PCIERR_A_INO, "pci_a");
261 1.1 mrg else
262 1.1 mrg schizo_set_intr(sc, pbm, PIL_HIGH, schizo_pci_error,
263 1.1 mrg pbm, SCZ_PCIERR_B_INO, "pci_b");
264 1.1 mrg
265 1.1 mrg /* double mapped */
266 1.1 mrg schizo_set_intr(sc, pbm, PIL_HIGH, schizo_ue, sc, SCZ_UE_INO,
267 1.1 mrg "ue");
268 1.1 mrg schizo_set_intr(sc, pbm, PIL_HIGH, schizo_ce, sc, SCZ_CE_INO,
269 1.1 mrg "ce");
270 1.1 mrg schizo_set_intr(sc, pbm, PIL_HIGH, schizo_safari_error, sc,
271 1.1 mrg SCZ_SERR_INO, "safari");
272 1.1 mrg
273 1.1 mrg config_found(&sc->sc_dv, &pba, schizo_print);
274 1.1 mrg }
275 1.1 mrg
276 1.1 mrg int
277 1.1 mrg schizo_ue(void *vsc)
278 1.1 mrg {
279 1.1 mrg struct schizo_softc *sc = vsc;
280 1.1 mrg
281 1.1 mrg panic("%s: uncorrectable error", sc->sc_dv.dv_xname);
282 1.1 mrg return (1);
283 1.1 mrg }
284 1.1 mrg
285 1.1 mrg int
286 1.1 mrg schizo_ce(void *vsc)
287 1.1 mrg {
288 1.1 mrg struct schizo_softc *sc = vsc;
289 1.1 mrg
290 1.1 mrg panic("%s: correctable error", sc->sc_dv.dv_xname);
291 1.1 mrg return (1);
292 1.1 mrg }
293 1.1 mrg
294 1.1 mrg int
295 1.1 mrg schizo_pci_error(void *vpbm)
296 1.1 mrg {
297 1.1 mrg struct schizo_pbm *sp = vpbm;
298 1.1 mrg struct schizo_softc *sc = sp->sp_sc;
299 1.1 mrg u_int64_t afsr, afar, ctrl;
300 1.1 mrg u_int32_t csr;
301 1.1 mrg
302 1.1 mrg afsr = schizo_pbm_read(sp, SCZ_PCI_AFSR);
303 1.1 mrg afar = schizo_pbm_read(sp, SCZ_PCI_AFAR);
304 1.1 mrg ctrl = schizo_pbm_read(sp, SCZ_PCI_CTRL);
305 1.1 mrg csr = schizo_cfg_read(sp, PCI_COMMAND_STATUS_REG);
306 1.1 mrg
307 1.1 mrg printf("%s: pci bus %c error\n", sc->sc_dv.dv_xname,
308 1.1 mrg sp->sp_bus_a ? 'A' : 'B');
309 1.1 mrg
310 1.1 mrg printf("PCIAFSR=%lb\n", afsr, SCZ_PCIAFSR_BITS);
311 1.1 mrg printf("PCIAFAR=%lx\n", afar);
312 1.1 mrg printf("PCICTRL=%lb\n", ctrl, SCZ_PCICTRL_BITS);
313 1.1 mrg printf("PCICSR=%b\n", csr, PCI_COMMAND_STATUS_BITS);
314 1.1 mrg
315 1.1 mrg if (ctrl & SCZ_PCICTRL_MMU_ERR) {
316 1.1 mrg u_int32_t ctrl, tfar;
317 1.1 mrg
318 1.1 mrg ctrl = schizo_pbm_read(sp, SCZ_PCI_IOMMU_CTRL);
319 1.1 mrg printf("IOMMUCTRL=%lx\n", ctrl);
320 1.1 mrg
321 1.1 mrg if ((ctrl & TOM_IOMMU_ERR) == 0)
322 1.1 mrg goto clear_error;
323 1.1 mrg
324 1.1 mrg if (sc->sc_tomatillo) {
325 1.1 mrg tfar = schizo_pbm_read(sp, TOM_PCI_IOMMU_TFAR);
326 1.1 mrg printf("IOMMUTFAR=%lx\n", tfar);
327 1.1 mrg }
328 1.1 mrg
329 1.1 mrg /* These are non-fatal if target abort was signalled. */
330 1.1 mrg if ((ctrl & TOM_IOMMU_ERR_MASK) == TOM_IOMMU_INV_ERR ||
331 1.1 mrg ctrl & TOM_IOMMU_ILLTSBTBW_ERR ||
332 1.1 mrg ctrl & TOM_IOMMU_BADVA_ERR) {
333 1.1 mrg if (csr & PCI_STATUS_TARGET_TARGET_ABORT) {
334 1.1 mrg schizo_pbm_write(sp, SCZ_PCI_IOMMU_CTRL, ctrl);
335 1.1 mrg goto clear_error;
336 1.1 mrg }
337 1.1 mrg }
338 1.1 mrg }
339 1.1 mrg
340 1.1 mrg panic("%s: fatal", sc->sc_dv.dv_xname);
341 1.1 mrg
342 1.1 mrg clear_error:
343 1.1 mrg schizo_cfg_write(sp, PCI_COMMAND_STATUS_REG, csr);
344 1.1 mrg schizo_pbm_write(sp, SCZ_PCI_CTRL, ctrl);
345 1.1 mrg schizo_pbm_write(sp, SCZ_PCI_AFSR, afsr);
346 1.1 mrg return (1);
347 1.1 mrg }
348 1.1 mrg
349 1.1 mrg int
350 1.1 mrg schizo_safari_error(void *vsc)
351 1.1 mrg {
352 1.1 mrg struct schizo_softc *sc = vsc;
353 1.1 mrg
354 1.1 mrg printf("%s: safari error\n", sc->sc_dv.dv_xname);
355 1.1 mrg
356 1.1 mrg printf("ERRLOG=%lx\n", schizo_read(sc, SCZ_SAFARI_ERRLOG));
357 1.1 mrg printf("UE_AFSR=%lx\n", schizo_read(sc, SCZ_UE_AFSR));
358 1.1 mrg printf("UE_AFAR=%lx\n", schizo_read(sc, SCZ_UE_AFAR));
359 1.1 mrg printf("CE_AFSR=%lx\n", schizo_read(sc, SCZ_CE_AFSR));
360 1.1 mrg printf("CE_AFAR=%lx\n", schizo_read(sc, SCZ_CE_AFAR));
361 1.1 mrg
362 1.1 mrg panic("%s: fatal", sc->sc_dv.dv_xname);
363 1.1 mrg return (1);
364 1.1 mrg }
365 1.1 mrg
366 1.1 mrg void
367 1.1 mrg schizo_init_iommu(struct schizo_softc *sc, struct schizo_pbm *pbm)
368 1.1 mrg {
369 1.1 mrg struct iommu_state *is = &pbm->sp_is;
370 1.1 mrg int *vdma = NULL, nitem, tsbsize = 7;
371 1.1 mrg u_int32_t iobase = -1;
372 1.1 mrg vaddr_t va;
373 1.1 mrg char *name;
374 1.1 mrg
375 1.1 mrg va = (vaddr_t)pbm->sp_flush[0x40];
376 1.1 mrg
377 1.1 mrg is->is_bustag = pbm->sp_regt;
378 1.1 mrg
379 1.1 mrg if (bus_space_subregion(is->is_bustag, pbm->sp_regh,
380 1.1 mrg offsetof(struct schizo_pbm_regs, iommu),
381 1.1 mrg sizeof(struct iommureg), &is->is_iommu)) {
382 1.1 mrg panic("schizo: unable to create iommu handle");
383 1.1 mrg }
384 1.1 mrg
385 1.1 mrg is->is_sb[0] = &pbm->sp_sb;
386 1.1 mrg is->is_sb[0]->sb_bustag = is->is_bustag;
387 1.1 mrg is->is_sb[0]->sb_flush = (void *)(va & ~0x3f);
388 1.1 mrg
389 1.1 mrg if (bus_space_subregion(is->is_bustag, pbm->sp_regh,
390 1.1 mrg offsetof(struct schizo_pbm_regs, strbuf),
391 1.1 mrg sizeof(struct iommu_strbuf), &is->is_sb[0]->sb_sb)) {
392 1.1 mrg panic("schizo: unable to create streaming buffer handle");
393 1.1 mrg is->is_sb[0]->sb_flush = NULL;
394 1.1 mrg }
395 1.1 mrg
396 1.1 mrg #if 1
397 1.1 mrg /* XXX disable the streaming buffers for now */
398 1.1 mrg bus_space_write_8(is->is_bustag, is->is_sb[0]->sb_sb,
399 1.1 mrg STRBUFREG(strbuf_ctl),
400 1.1 mrg bus_space_read_8(is->is_bustag, is->is_sb[0]->sb_sb,
401 1.1 mrg STRBUFREG(strbuf_ctl)) & ~STRBUF_EN);
402 1.1 mrg is->is_sb[0]->sb_flush = NULL;
403 1.1 mrg #endif
404 1.1 mrg
405 1.1 mrg name = (char *)malloc(32, M_DEVBUF, M_NOWAIT);
406 1.1 mrg if (name == NULL)
407 1.1 mrg panic("couldn't malloc iommu name");
408 1.1 mrg snprintf(name, 32, "%s dvma", sc->sc_dv.dv_xname);
409 1.1 mrg
410 1.1 mrg /*
411 1.1 mrg * Separate the men from the boys. If the `virtual-dma'
412 1.1 mrg * property exists, use it.
413 1.1 mrg */
414 1.1 mrg if (!getprop(sc->sc_node, "virtual-dma", sizeof(vdma), &nitem,
415 1.1 mrg (void **)&vdma)) {
416 1.1 mrg /* Damn. Gotta use these values. */
417 1.1 mrg iobase = vdma[0];
418 1.1 mrg #define TSBCASE(x) case 1 << ((x) + 23): tsbsize = (x); break
419 1.1 mrg switch (vdma[1]) {
420 1.1 mrg TSBCASE(1); TSBCASE(2); TSBCASE(3);
421 1.1 mrg TSBCASE(4); TSBCASE(5); TSBCASE(6);
422 1.1 mrg default:
423 1.1 mrg printf("bogus tsb size %x, using 7\n", vdma[1]);
424 1.1 mrg TSBCASE(7);
425 1.1 mrg }
426 1.1 mrg #undef TSBCASE
427 1.1 mrg DPRINTF(SDB_BUSMAP, ("schizo_iommu_init: iobase=0x%x\n", iobase));
428 1.1 mrg free(vdma, M_DEVBUF);
429 1.1 mrg } else {
430 1.1 mrg DPRINTF(SDB_BUSMAP, ("schizo_iommu_init: getprop failed, "
431 1.1 mrg "using iobase=0x%x, tsbsize=%d\n", iobase, tsbsize));
432 1.1 mrg }
433 1.1 mrg
434 1.1 mrg iommu_init(name, is, tsbsize, iobase);
435 1.1 mrg }
436 1.1 mrg
437 1.1 mrg int
438 1.1 mrg schizo_print(void *aux, const char *p)
439 1.1 mrg {
440 1.1 mrg if (p == NULL)
441 1.1 mrg return (UNCONF);
442 1.1 mrg return (QUIET);
443 1.1 mrg }
444 1.1 mrg
445 1.1 mrg pcireg_t
446 1.1 mrg schizo_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
447 1.1 mrg {
448 1.1 mrg return (bus_space_read_4(pc->bustag, pc->bushandle,
449 1.1 mrg PCITAG_OFFSET(tag) + reg));
450 1.1 mrg }
451 1.1 mrg
452 1.1 mrg void
453 1.1 mrg schizo_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
454 1.1 mrg {
455 1.1 mrg bus_space_write_4(pc->bustag, pc->bushandle,
456 1.1 mrg PCITAG_OFFSET(tag) + reg, data);
457 1.1 mrg }
458 1.1 mrg
459 1.1 mrg /*
460 1.1 mrg * Bus-specific interrupt mapping
461 1.1 mrg */
462 1.1 mrg int
463 1.1 mrg schizo_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
464 1.1 mrg {
465 1.1 mrg struct schizo_pbm *sp = pa->pa_pc->cookie;
466 1.1 mrg struct schizo_softc *sc = sp->sp_sc;
467 1.1 mrg u_int dev;
468 1.1 mrg
469 1.1 mrg if (*ihp != (pci_intr_handle_t)-1) {
470 1.1 mrg *ihp |= sc->sc_ign;
471 1.1 mrg return (0);
472 1.1 mrg }
473 1.1 mrg
474 1.1 mrg /*
475 1.1 mrg * We didn't find a PROM mapping for this interrupt. Try to
476 1.1 mrg * construct one ourselves based on the swizzled interrupt pin
477 1.1 mrg * and the interrupt mapping for PCI slots documented in the
478 1.1 mrg * UltraSPARC-IIi User's Manual.
479 1.1 mrg */
480 1.1 mrg
481 1.1 mrg if (pa->pa_intrpin == 0)
482 1.1 mrg return (-1);
483 1.1 mrg
484 1.1 mrg /*
485 1.1 mrg * This deserves some documentation. Should anyone
486 1.1 mrg * have anything official looking, please speak up.
487 1.1 mrg */
488 1.1 mrg dev = pa->pa_device - 1;
489 1.1 mrg
490 1.1 mrg *ihp = (pa->pa_intrpin - 1) & INTMAP_PCIINT;
491 1.1 mrg *ihp |= (dev << 2) & INTMAP_PCISLOT;
492 1.1 mrg *ihp |= sc->sc_ign;
493 1.1 mrg
494 1.1 mrg return (0);
495 1.1 mrg }
496 1.1 mrg
497 1.1 mrg void
498 1.1 mrg schizo_set_intr(struct schizo_softc *sc, struct schizo_pbm *pbm, int ipl,
499 1.1 mrg int (*handler)(void *), void *arg, int ino, char *what)
500 1.1 mrg {
501 1.1 mrg struct intrhand *ih;
502 1.1 mrg volatile u_int64_t *map, *clr;
503 1.1 mrg struct schizo_pbm_regs *pbmreg;
504 1.1 mrg char *name;
505 1.1 mrg int nlen;
506 1.1 mrg
507 1.1 mrg pbmreg = bus_space_vaddr(pbm->sp_regt, pbm->sp_regh);
508 1.1 mrg map = &pbmreg->imap[ino];
509 1.1 mrg clr = &pbmreg->iclr[ino];
510 1.1 mrg ino |= sc->sc_ign;
511 1.1 mrg
512 1.1 mrg nlen = strlen(sc->sc_dv.dv_xname) + 1 + strlen(what) + 1;
513 1.1 mrg name = malloc(nlen, M_DEVBUF, M_WAITOK);
514 1.1 mrg snprintf(name, nlen, "%s:%s", sc->sc_dv.dv_xname, what);
515 1.1 mrg
516 1.1 mrg ih = bus_intr_allocate(pbm->sp_regt, handler, arg, ino, ipl,
517 1.1 mrg map, clr, name);
518 1.1 mrg if (ih == NULL) {
519 1.1 mrg printf("set_intr failed...\n");
520 1.1 mrg free(name, M_DEVBUF);
521 1.1 mrg return;
522 1.1 mrg }
523 1.1 mrg
524 1.1 mrg intr_establish(ih->ih_pil, ih);
525 1.1 mrg }
526 1.1 mrg
527 1.1 mrg bus_space_tag_t
528 1.1 mrg schizo_alloc_mem_tag(struct schizo_pbm *sp)
529 1.1 mrg {
530 1.1 mrg return (schizo_alloc_bus_tag(sp, "mem",
531 1.1 mrg 0x02, /* 32-bit mem space (where's the #define???) */
532 1.1 mrg ASI_PRIMARY, ASI_PRIMARY_LITTLE));
533 1.1 mrg }
534 1.1 mrg
535 1.1 mrg bus_space_tag_t
536 1.1 mrg schizo_alloc_io_tag(struct schizo_pbm *sp)
537 1.1 mrg {
538 1.1 mrg return (schizo_alloc_bus_tag(sp, "io",
539 1.1 mrg 0x01, /* IO space (where's the #define???) */
540 1.1 mrg ASI_PHYS_NON_CACHED_LITTLE, ASI_PHYS_NON_CACHED));
541 1.1 mrg }
542 1.1 mrg
543 1.1 mrg bus_space_tag_t
544 1.1 mrg schizo_alloc_config_tag(struct schizo_pbm *sp)
545 1.1 mrg {
546 1.1 mrg return (schizo_alloc_bus_tag(sp, "cfg",
547 1.1 mrg 0x00, /* Config space (where's the #define???) */
548 1.1 mrg ASI_PHYS_NON_CACHED_LITTLE, ASI_PHYS_NON_CACHED));
549 1.1 mrg }
550 1.1 mrg
551 1.1 mrg bus_space_tag_t
552 1.1 mrg schizo_alloc_bus_tag(struct schizo_pbm *pbm, const char *name, int ss,
553 1.1 mrg int asi, int sasi)
554 1.1 mrg {
555 1.1 mrg struct schizo_softc *sc = pbm->sp_sc;
556 1.1 mrg struct sparc_bus_space_tag *bt;
557 1.1 mrg
558 1.1 mrg bt = malloc(sizeof(*bt), M_DEVBUF, M_NOWAIT | M_ZERO);
559 1.1 mrg if (bt == NULL)
560 1.1 mrg panic("schizo: could not allocate bus tag");
561 1.1 mrg
562 1.1 mrg snprintf(bt->name, sizeof(bt->name), "%s-pbm_%s(%d/%2.2x)",
563 1.1 mrg sc->sc_dv.dv_xname, name, ss, asi);
564 1.1 mrg
565 1.1 mrg bt->cookie = pbm;
566 1.1 mrg bt->parent = sc->sc_bust;
567 1.1 mrg bt->default_type = ss;
568 1.1 mrg bt->asi = asi;
569 1.1 mrg bt->sasi = sasi;
570 1.1 mrg bt->sparc_bus_map = schizo_bus_map;
571 1.1 mrg bt->sparc_bus_mmap = schizo_bus_mmap;
572 1.1 mrg bt->sparc_bus_addr = schizo_bus_addr;
573 1.1 mrg bt->sparc_intr_establish = schizo_intr_establish;
574 1.1 mrg return (bt);
575 1.1 mrg }
576 1.1 mrg
577 1.1 mrg bus_dma_tag_t
578 1.1 mrg schizo_alloc_dma_tag(struct schizo_pbm *pbm)
579 1.1 mrg {
580 1.1 mrg struct schizo_softc *sc = pbm->sp_sc;
581 1.1 mrg bus_dma_tag_t dt, pdt = sc->sc_dmat;
582 1.1 mrg
583 1.1 mrg dt = malloc(sizeof(*dt), M_DEVBUF, M_NOWAIT | M_ZERO);
584 1.1 mrg if (dt == NULL)
585 1.1 mrg panic("schizo: could not alloc dma tag");
586 1.1 mrg
587 1.1 mrg dt->_cookie = pbm;
588 1.1 mrg dt->_parent = pdt;
589 1.1 mrg dt->_dmamap_create = schizo_dmamap_create;
590 1.1 mrg dt->_dmamap_destroy = iommu_dvmamap_destroy;
591 1.1 mrg dt->_dmamap_load = iommu_dvmamap_load;
592 1.1 mrg dt->_dmamap_load_raw = iommu_dvmamap_load_raw;
593 1.1 mrg dt->_dmamap_unload = iommu_dvmamap_unload;
594 1.1 mrg dt->_dmamap_sync = iommu_dvmamap_sync;
595 1.1 mrg dt->_dmamem_alloc = iommu_dvmamem_alloc;
596 1.1 mrg dt->_dmamem_free = iommu_dvmamem_free;
597 1.1 mrg dt->_dmamem_map = iommu_dvmamem_map;
598 1.1 mrg dt->_dmamem_unmap = iommu_dvmamem_unmap;
599 1.1 mrg return (dt);
600 1.1 mrg }
601 1.1 mrg
602 1.1 mrg pci_chipset_tag_t
603 1.1 mrg schizo_alloc_chipset(struct schizo_pbm *pbm, int node, pci_chipset_tag_t pc)
604 1.1 mrg {
605 1.1 mrg pci_chipset_tag_t npc;
606 1.1 mrg
607 1.1 mrg npc = malloc(sizeof *npc, M_DEVBUF, M_NOWAIT);
608 1.1 mrg if (npc == NULL)
609 1.1 mrg panic("schizo: could not allocate pci_chipset_tag_t");
610 1.1 mrg memcpy(npc, pc, sizeof *pc);
611 1.1 mrg npc->cookie = pbm;
612 1.1 mrg npc->rootnode = node;
613 1.1 mrg return (npc);
614 1.1 mrg }
615 1.1 mrg
616 1.1 mrg int
617 1.1 mrg schizo_dmamap_create(bus_dma_tag_t t, bus_dma_tag_t t0, bus_size_t size,
618 1.1 mrg int nsegments, bus_size_t maxsegsz, bus_size_t boundary, int flags,
619 1.1 mrg bus_dmamap_t *dmamp)
620 1.1 mrg {
621 1.1 mrg struct schizo_pbm *sp = t->_cookie;
622 1.1 mrg
623 1.1 mrg return (iommu_dvmamap_create(t, t0, &sp->sp_sb, size, nsegments,
624 1.1 mrg maxsegsz, boundary, flags, dmamp));
625 1.1 mrg }
626 1.1 mrg
627 1.1 mrg int
628 1.1 mrg schizo_bus_map(bus_space_tag_t t, bus_space_tag_t t0, bus_addr_t offset,
629 1.1 mrg bus_size_t size, int flags, bus_space_handle_t *hp)
630 1.1 mrg {
631 1.1 mrg struct schizo_pbm *pbm = t->cookie;
632 1.1 mrg int i, ss;
633 1.1 mrg
634 1.1 mrg DPRINTF(SDB_BUSMAP, ("schizo_bus_map: type %d off %qx sz %qx flags %d",
635 1.1 mrg t->default_type,
636 1.1 mrg (unsigned long long)offset,
637 1.1 mrg (unsigned long long)size,
638 1.1 mrg flags));
639 1.1 mrg
640 1.1 mrg ss = t->default_type;
641 1.1 mrg DPRINTF(SDB_BUSMAP, (" cspace %d", ss));
642 1.1 mrg
643 1.1 mrg if (t->parent == 0 || t->parent->sparc_bus_map == 0) {
644 1.1 mrg printf("\nschizo_bus_map: invalid parent");
645 1.1 mrg return (EINVAL);
646 1.1 mrg }
647 1.1 mrg
648 1.1 mrg if (flags & BUS_SPACE_MAP_PROMADDRESS) {
649 1.1 mrg return ((*t->parent->sparc_bus_map)
650 1.1 mrg (t, t0, offset, size, flags, hp));
651 1.1 mrg }
652 1.1 mrg
653 1.1 mrg for (i = 0; i < pbm->sp_nrange; i++) {
654 1.1 mrg bus_addr_t paddr;
655 1.1 mrg
656 1.1 mrg if (((pbm->sp_range[i].cspace >> 24) & 0x03) != ss)
657 1.1 mrg continue;
658 1.1 mrg
659 1.1 mrg paddr = pbm->sp_range[i].phys_lo + offset;
660 1.1 mrg paddr |= ((bus_addr_t)pbm->sp_range[i].phys_hi) << 32;
661 1.1 mrg return ((*t->parent->sparc_bus_map)
662 1.1 mrg (t, t0, paddr, size, flags, hp));
663 1.1 mrg }
664 1.1 mrg
665 1.1 mrg return (EINVAL);
666 1.1 mrg }
667 1.1 mrg
668 1.1 mrg paddr_t
669 1.1 mrg schizo_bus_mmap(bus_space_tag_t t, bus_space_tag_t t0, bus_addr_t paddr,
670 1.1 mrg off_t off, int prot, int flags)
671 1.1 mrg {
672 1.1 mrg bus_addr_t offset = paddr;
673 1.1 mrg struct schizo_pbm *pbm = t->cookie;
674 1.1 mrg int i, ss;
675 1.1 mrg
676 1.1 mrg ss = t->default_type;
677 1.1 mrg
678 1.1 mrg DPRINTF(SDB_BUSMAP, ("schizo_bus_mmap: prot %d flags %d pa %qx\n",
679 1.1 mrg prot, flags, (unsigned long long)paddr));
680 1.1 mrg
681 1.1 mrg if (t->parent == 0 || t->parent->sparc_bus_mmap == 0) {
682 1.1 mrg printf("\nschizo_bus_mmap: invalid parent");
683 1.1 mrg return (-1);
684 1.1 mrg }
685 1.1 mrg
686 1.1 mrg for (i = 0; i < pbm->sp_nrange; i++) {
687 1.1 mrg bus_addr_t paddr;
688 1.1 mrg
689 1.1 mrg if (((pbm->sp_range[i].cspace >> 24) & 0x03) != ss)
690 1.1 mrg continue;
691 1.1 mrg
692 1.1 mrg paddr = pbm->sp_range[i].phys_lo + offset;
693 1.1 mrg paddr |= ((bus_addr_t)pbm->sp_range[i].phys_hi<<32);
694 1.1 mrg return ((*t->parent->sparc_bus_mmap)
695 1.1 mrg (t, t0, paddr, off, prot, flags));
696 1.1 mrg }
697 1.1 mrg
698 1.1 mrg return (-1);
699 1.1 mrg }
700 1.1 mrg
701 1.1 mrg bus_addr_t
702 1.1 mrg schizo_bus_addr(bus_space_tag_t t, bus_space_tag_t t0, bus_space_handle_t h)
703 1.1 mrg {
704 1.1 mrg struct schizo_pbm *pbm = t->cookie;
705 1.1 mrg bus_addr_t addr;
706 1.1 mrg int i, ss;
707 1.1 mrg
708 1.1 mrg ss = t->default_type;
709 1.1 mrg
710 1.1 mrg if (t->parent == 0 || t->parent->sparc_bus_addr == 0) {
711 1.1 mrg printf("\nschizo_bus_addr: invalid parent");
712 1.1 mrg return (-1);
713 1.1 mrg }
714 1.1 mrg
715 1.1 mrg t = t->parent;
716 1.1 mrg
717 1.1 mrg addr = ((*t->sparc_bus_addr)(t, t0, h));
718 1.1 mrg if (addr == -1)
719 1.1 mrg return (-1);
720 1.1 mrg
721 1.1 mrg for (i = 0; i < pbm->sp_nrange; i++) {
722 1.1 mrg if (((pbm->sp_range[i].cspace >> 24) & 0x03) != ss)
723 1.1 mrg continue;
724 1.1 mrg
725 1.1 mrg return (BUS_ADDR_PADDR(addr) - pbm->sp_range[i].phys_lo);
726 1.1 mrg }
727 1.1 mrg
728 1.1 mrg return (-1);
729 1.1 mrg }
730 1.1 mrg
731 1.1 mrg void *
732 1.1 mrg schizo_intr_establish(bus_space_tag_t t, bus_space_tag_t t0, int ihandle,
733 1.1 mrg int level, int flags, int (*handler)(void *), void *arg, const char *what)
734 1.1 mrg {
735 1.1 mrg struct schizo_pbm *pbm = t->cookie;
736 1.1 mrg struct intrhand *ih = NULL;
737 1.1 mrg volatile u_int64_t *intrmapptr = NULL, *intrclrptr = NULL;
738 1.1 mrg int ino;
739 1.1 mrg long vec = INTVEC(ihandle);
740 1.1 mrg
741 1.1 mrg vec = INTVEC(ihandle);
742 1.1 mrg ino = INTINO(vec);
743 1.1 mrg
744 1.1 mrg if (level == IPL_NONE)
745 1.1 mrg level = INTLEV(vec);
746 1.1 mrg if (level == IPL_NONE) {
747 1.1 mrg printf(": no IPL, setting IPL 2.\n");
748 1.1 mrg level = 2;
749 1.1 mrg }
750 1.1 mrg
751 1.1 mrg if ((flags & BUS_INTR_ESTABLISH_SOFTINTR) == 0) {
752 1.1 mrg struct schizo_pbm_regs *pbmreg;
753 1.1 mrg
754 1.1 mrg pbmreg = bus_space_vaddr(pbm->sp_regt, pbm->sp_regh);
755 1.1 mrg intrmapptr = &pbmreg->imap[ino];
756 1.1 mrg intrclrptr = &pbmreg->iclr[ino];
757 1.1 mrg if (INTIGN(vec) == 0)
758 1.1 mrg ino |= (*intrmapptr) & INTMAP_IGN;
759 1.1 mrg else
760 1.1 mrg ino |= vec & INTMAP_IGN;
761 1.1 mrg }
762 1.1 mrg
763 1.1 mrg ih = bus_intr_allocate(t0, handler, arg, ino, level, intrmapptr,
764 1.1 mrg intrclrptr, what);
765 1.1 mrg if (ih == NULL)
766 1.1 mrg return (NULL);
767 1.1 mrg
768 1.1 mrg intr_establish(ih->ih_pil, ih);
769 1.1 mrg
770 1.1 mrg if (intrmapptr != NULL) {
771 1.1 mrg u_int64_t intrmap;
772 1.1 mrg
773 1.1 mrg intrmap = *intrmapptr;
774 1.1 mrg intrmap |= INTMAP_V;
775 1.1 mrg *intrmapptr = intrmap;
776 1.1 mrg intrmap = *intrmapptr;
777 1.1 mrg ih->ih_number |= intrmap & INTMAP_INR;
778 1.1 mrg }
779 1.1 mrg
780 1.1 mrg return (ih);
781 1.1 mrg }
782 1.1 mrg
783 1.1 mrg const struct cfattach schizo_ca = {
784 1.1 mrg sizeof(struct schizo_softc), schizo_match, schizo_attach
785 1.1 mrg };
786 1.1 mrg
787 1.1 mrg struct cfdriver schizo_cd = {
788 1.1 mrg NULL, "schizo", DV_DULL
789 1.1 mrg };
790