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