1 /* $NetBSD: schizo.c,v 1.11 2009/12/30 20:20:56 nakayama Exp $ */
2 /* $OpenBSD: schizo.c,v 1.55 2008/08/18 20:29:37 brad Exp $ */
5 * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
6 * Copyright (c) 2003 Henric Jungheim
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/param.h>
32 #include <sys/device.h>
33 #include <sys/errno.h>
34 #include <sys/extent.h>
35 #include <sys/malloc.h>
36 #include <sys/systm.h>
38 #include <sys/reboot.h>
40 #define _SPARC_BUS_DMA_PRIVATE
41 #include <machine/bus.h>
42 #include <machine/autoconf.h>
43 #include <machine/psl.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pcireg.h>
48 #include <sparc64/dev/iommureg.h>
49 #include <sparc64/dev/iommuvar.h>
50 #include <sparc64/dev/schizoreg.h>
51 #include <sparc64/dev/schizovar.h>
52 #include <sparc64/sparc64/cache.h>
56 #define SDB_BUSMAP 0x02
58 #define SDB_INTMAP 0x08
60 int schizo_debug
= 0x0;
61 #define DPRINTF(l, s) do { if (schizo_debug & l) printf s; } while (0)
66 extern struct sparc_pci_chipset _sparc_pci_chipset
;
68 static int schizo_match(struct device
*, struct cfdata
*, void *);
69 static void schizo_attach(struct device
*, struct device
*, void *);
70 static int schizo_print(void *aux
, const char *p
);
72 CFATTACH_DECL(schizo
, sizeof(struct schizo_softc
),
73 schizo_match
, schizo_attach
, NULL
, NULL
);
75 void schizo_init(struct schizo_softc
*);
76 void schizo_init_iommu(struct schizo_softc
*, struct schizo_pbm
*);
78 void schizo_set_intr(struct schizo_softc
*, struct schizo_pbm
*, int,
79 int (*handler
)(void *), void *, int, const char *);
80 int schizo_ue(void *);
81 int schizo_ce(void *);
82 int schizo_safari_error(void *);
83 int schizo_pci_error(void *);
85 pci_chipset_tag_t
schizo_alloc_chipset(struct schizo_pbm
*, int,
87 bus_space_tag_t
schizo_alloc_mem_tag(struct schizo_pbm
*);
88 bus_space_tag_t
schizo_alloc_io_tag(struct schizo_pbm
*);
89 bus_space_tag_t
schizo_alloc_config_tag(struct schizo_pbm
*);
90 bus_space_tag_t
schizo_alloc_bus_tag(struct schizo_pbm
*, const char *,
92 bus_dma_tag_t
schizo_alloc_dma_tag(struct schizo_pbm
*);
94 pcireg_t
schizo_conf_read(pci_chipset_tag_t
, pcitag_t
, int);
95 void schizo_conf_write(pci_chipset_tag_t
, pcitag_t
, int, pcireg_t
);
97 int schizo_bus_map(bus_space_tag_t t
, bus_addr_t offset
, bus_size_t size
,
98 int flags
, vaddr_t unused
, bus_space_handle_t
*hp
);
99 static paddr_t
schizo_bus_mmap(bus_space_tag_t t
, bus_addr_t paddr
,
100 off_t off
, int prot
, int flags
);
101 static void *schizo_intr_establish(bus_space_tag_t
, int, int, int (*)(void *),
102 void *, void(*)(void));
103 static int schizo_pci_intr_map(struct pci_attach_args
*, pci_intr_handle_t
*);
104 static void *schizo_pci_intr_establish(pci_chipset_tag_t
, pci_intr_handle_t
,
105 int, int (*)(void *), void *);
106 static int schizo_pci_find_ino(struct pci_attach_args
*, pci_intr_handle_t
*);
107 static int schizo_dmamap_create(bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
108 bus_size_t
, int, bus_dmamap_t
*);
111 schizo_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
113 struct mainbus_attach_args
*ma
= aux
;
116 if (strcmp(ma
->ma_name
, "pci") != 0)
119 str
= prom_getpropstring(ma
->ma_node
, "model");
120 if (strcmp(str
, "schizo") == 0)
123 str
= prom_getpropstring(ma
->ma_node
, "compatible");
124 if (strcmp(str
, "pci108e,8001") == 0)
126 if (strcmp(str
, "pci108e,8002") == 0) /* XMITS */
128 if (strcmp(str
, "pci108e,a801") == 0) /* Tomatillo */
135 schizo_attach(struct device
*parent
, struct device
*self
, void *aux
)
137 struct schizo_softc
*sc
= (struct schizo_softc
*)self
;
138 struct mainbus_attach_args
*ma
= aux
;
142 printf(": addr %lx", ma
->ma_reg
[0].ur_paddr
);
143 str
= prom_getpropstring(ma
->ma_node
, "compatible");
144 if (strcmp(str
, "pci108e,a801") == 0)
145 sc
->sc_tomatillo
= 1;
147 sc
->sc_node
= ma
->ma_node
;
148 sc
->sc_dmat
= ma
->ma_dmatag
;
149 sc
->sc_bustag
= ma
->ma_bustag
;
150 sc
->sc_ctrl
= ma
->ma_reg
[1].ur_paddr
- 0x10000UL
;
151 sc
->sc_reg0
= ma
->ma_reg
[0];
153 if (bus_space_map(sc
->sc_bustag
, sc
->sc_ctrl
,
154 sizeof(struct schizo_regs
), 0,
156 printf(": failed to map registers\n");
160 sc
->sc_ign
= INTIGN(ma
->ma_upaid
<< INTMAP_IGN_SHIFT
);
162 /* enable schizo ecc error interrupts */
163 eccctrl
= schizo_read(sc
, SCZ_ECCCTRL
);
164 eccctrl
|= SCZ_ECCCTRL_EE_INTEN
|
165 SCZ_ECCCTRL_UE_INTEN
|
166 SCZ_ECCCTRL_CE_INTEN
;
167 schizo_write(sc
, SCZ_ECCCTRL
, eccctrl
);
173 schizo_init(struct schizo_softc
*sc
)
175 struct schizo_pbm
*pbm
;
176 struct pcibus_attach_args pba
;
177 int *busranges
= NULL
, nranges
;
178 u_int64_t
/*match,*/ reg
;
180 pbm
= malloc(sizeof(*pbm
), M_DEVBUF
, M_NOWAIT
| M_ZERO
);
182 panic("schizo: can't alloc schizo pbm");
185 pbm
->sp_regt
= sc
->sc_bustag
;
187 if ((sc
->sc_reg0
.ur_paddr
& 0x00700000) == 0x00600000)
192 if (prom_getprop(sc
->sc_node
, "ranges", sizeof(struct schizo_range
),
193 &pbm
->sp_nrange
, (void **)&pbm
->sp_range
))
194 panic("schizo: can't get ranges");
196 if (prom_getprop(sc
->sc_node
, "bus-range", sizeof(int), &nranges
,
197 (void **)&busranges
))
198 panic("schizo: can't get bus-range");
200 printf(": \"%s\", version %d, ign %x, bus %c %d to %d\n",
201 sc
->sc_tomatillo
? "Tomatillo" : "Schizo",
202 prom_getpropint(sc
->sc_node
, "version#", 0), sc
->sc_ign
,
203 pbm
->sp_bus_a
? 'A' : 'B', busranges
[0], busranges
[1]);
205 if (bus_space_subregion(pbm
->sp_regt
, sc
->sc_ctrlh
,
206 pbm
->sp_bus_a
? offsetof(struct schizo_regs
, pbm_a
) :
207 offsetof(struct schizo_regs
, pbm_b
),
208 sizeof(struct schizo_pbm_regs
),
210 panic("schizo: unable to create PBM handle");
213 printf("%s: ", sc
->sc_dv
.dv_xname
);
214 schizo_init_iommu(sc
, pbm
);
216 pbm
->sp_memt
= schizo_alloc_mem_tag(pbm
);
217 pbm
->sp_iot
= schizo_alloc_io_tag(pbm
);
218 pbm
->sp_cfgt
= schizo_alloc_config_tag(pbm
);
219 pbm
->sp_dmat
= schizo_alloc_dma_tag(pbm
);
220 pbm
->sp_flags
= (pbm
->sp_memt
? PCI_FLAGS_MEM_ENABLED
: 0) |
221 (pbm
->sp_iot
? PCI_FLAGS_IO_ENABLED
: 0);
223 if (bus_space_map(pbm
->sp_cfgt
, 0, 0x1000000, 0, &pbm
->sp_cfgh
))
224 panic("schizo: could not map config space");
226 pbm
->sp_pc
= schizo_alloc_chipset(pbm
, sc
->sc_node
,
227 &_sparc_pci_chipset
);
228 pbm
->sp_pc
->spc_busmax
= busranges
[1];
229 pbm
->sp_pc
->spc_busnode
= malloc(sizeof(*pbm
->sp_pc
->spc_busnode
),
230 M_DEVBUF
, M_NOWAIT
| M_ZERO
);
231 if (pbm
->sp_pc
->spc_busnode
== NULL
)
232 panic("schizo: malloc busnode");
234 pba
.pba_bus
= busranges
[0];
235 pba
.pba_bridgetag
= NULL
;
236 pba
.pba_pc
= pbm
->sp_pc
;
237 pba
.pba_flags
= pbm
->sp_flags
;
238 pba
.pba_dmat
= pbm
->sp_dmat
;
239 pba
.pba_dmat64
= NULL
; /* XXX */
240 pba
.pba_memt
= pbm
->sp_memt
;
241 pba
.pba_iot
= pbm
->sp_iot
;
243 free(busranges
, M_DEVBUF
);
245 schizo_pbm_write(pbm
, SCZ_PCI_INTR_RETRY
, 5);
247 /* clear out the bus errors */
248 schizo_pbm_write(pbm
, SCZ_PCI_CTRL
, schizo_pbm_read(pbm
, SCZ_PCI_CTRL
));
249 schizo_pbm_write(pbm
, SCZ_PCI_AFSR
, schizo_pbm_read(pbm
, SCZ_PCI_AFSR
));
250 schizo_cfg_write(pbm
, PCI_COMMAND_STATUS_REG
,
251 schizo_cfg_read(pbm
, PCI_COMMAND_STATUS_REG
));
253 reg
= schizo_pbm_read(pbm
, SCZ_PCI_CTRL
);
254 /* enable/disable error interrupts and arbiter */
255 reg
|= SCZ_PCICTRL_EEN
| SCZ_PCICTRL_MMU_INT
| SCZ_PCICTRL_ARB
;
256 reg
&= ~SCZ_PCICTRL_SBH_INT
;
257 schizo_pbm_write(pbm
, SCZ_PCI_CTRL
, reg
);
259 reg
= schizo_pbm_read(pbm
, SCZ_PCI_DIAG
);
260 reg
&= ~(SCZ_PCIDIAG_D_RTRYARB
| SCZ_PCIDIAG_D_RETRY
|
261 SCZ_PCIDIAG_D_INTSYNC
);
262 schizo_pbm_write(pbm
, SCZ_PCI_DIAG
, reg
);
265 schizo_set_intr(sc
, pbm
, PIL_HIGH
, schizo_pci_error
,
266 pbm
, SCZ_PCIERR_A_INO
, "pci_a");
268 schizo_set_intr(sc
, pbm
, PIL_HIGH
, schizo_pci_error
,
269 pbm
, SCZ_PCIERR_B_INO
, "pci_b");
272 schizo_set_intr(sc
, pbm
, PIL_HIGH
, schizo_ue
, sc
, SCZ_UE_INO
,
274 schizo_set_intr(sc
, pbm
, PIL_HIGH
, schizo_ce
, sc
, SCZ_CE_INO
,
276 schizo_set_intr(sc
, pbm
, PIL_HIGH
, schizo_safari_error
, sc
,
277 SCZ_SERR_INO
, "safari");
279 config_found(&sc
->sc_dv
, &pba
, schizo_print
);
285 struct schizo_softc
*sc
= vsc
;
287 panic("%s: uncorrectable error", sc
->sc_dv
.dv_xname
);
294 struct schizo_softc
*sc
= vsc
;
296 panic("%s: correctable error", sc
->sc_dv
.dv_xname
);
301 schizo_pci_error(void *vpbm
)
303 struct schizo_pbm
*sp
= vpbm
;
304 struct schizo_softc
*sc
= sp
->sp_sc
;
305 u_int64_t afsr
, afar
, ctrl
, tfar
;
309 afsr
= schizo_pbm_read(sp
, SCZ_PCI_AFSR
);
310 afar
= schizo_pbm_read(sp
, SCZ_PCI_AFAR
);
311 ctrl
= schizo_pbm_read(sp
, SCZ_PCI_CTRL
);
312 csr
= schizo_cfg_read(sp
, PCI_COMMAND_STATUS_REG
);
314 printf("%s: pci bus %c error\n", sc
->sc_dv
.dv_xname
,
315 sp
->sp_bus_a
? 'A' : 'B');
317 snprintb(bits
, sizeof(bits
), SCZ_PCIAFSR_BITS
, afsr
);
318 printf("PCIAFSR=%s\n", bits
);
319 printf("PCIAFAR=%lx\n", afar
);
320 snprintb(bits
, sizeof(bits
), SCZ_PCICTRL_BITS
, ctrl
);
321 printf("PCICTRL=%s\n", bits
);
322 #ifdef PCI_COMMAND_STATUS_BITS
323 snprintb(bits
, sizeof(bits
), PCI_COMMAND_STATUS_BITS
, csr
);
324 printf("PCICSR=%s\n", bits
);
327 if (ctrl
& SCZ_PCICTRL_MMU_ERR
) {
328 ctrl
= schizo_pbm_read(sp
, SCZ_PCI_IOMMU_CTRL
);
329 printf("IOMMUCTRL=%lx\n", ctrl
);
331 if ((ctrl
& TOM_IOMMU_ERR
) == 0)
334 if (sc
->sc_tomatillo
) {
335 tfar
= schizo_pbm_read(sp
, TOM_PCI_IOMMU_TFAR
);
336 printf("IOMMUTFAR=%lx\n", tfar
);
339 /* These are non-fatal if target abort was signalled. */
340 if ((ctrl
& TOM_IOMMU_ERR_MASK
) == TOM_IOMMU_INV_ERR
||
341 ctrl
& TOM_IOMMU_ILLTSBTBW_ERR
||
342 ctrl
& TOM_IOMMU_BADVA_ERR
) {
343 if (csr
& PCI_STATUS_TARGET_TARGET_ABORT
) {
344 schizo_pbm_write(sp
, SCZ_PCI_IOMMU_CTRL
, ctrl
);
350 panic("%s: fatal", sc
->sc_dv
.dv_xname
);
353 schizo_cfg_write(sp
, PCI_COMMAND_STATUS_REG
, csr
);
354 schizo_pbm_write(sp
, SCZ_PCI_CTRL
, ctrl
);
355 schizo_pbm_write(sp
, SCZ_PCI_AFSR
, afsr
);
360 schizo_safari_error(void *vsc
)
362 struct schizo_softc
*sc
= vsc
;
364 printf("%s: safari error\n", sc
->sc_dv
.dv_xname
);
366 printf("ERRLOG=%lx\n", schizo_read(sc
, SCZ_SAFARI_ERRLOG
));
367 printf("UE_AFSR=%lx\n", schizo_read(sc
, SCZ_UE_AFSR
));
368 printf("UE_AFAR=%lx\n", schizo_read(sc
, SCZ_UE_AFAR
));
369 printf("CE_AFSR=%lx\n", schizo_read(sc
, SCZ_CE_AFSR
));
370 printf("CE_AFAR=%lx\n", schizo_read(sc
, SCZ_CE_AFAR
));
372 panic("%s: fatal", sc
->sc_dv
.dv_xname
);
377 schizo_init_iommu(struct schizo_softc
*sc
, struct schizo_pbm
*pbm
)
379 struct iommu_state
*is
= &pbm
->sp_is
;
380 int *vdma
= NULL
, nitem
, tsbsize
= 7;
381 u_int32_t iobase
= -1;
385 va
= (vaddr_t
)pbm
->sp_flush
[0x40];
387 /* punch in our copies */
388 is
->is_bustag
= pbm
->sp_regt
;
389 if (bus_space_subregion(is
->is_bustag
, pbm
->sp_regh
,
390 offsetof(struct schizo_pbm_regs
, iommu
),
391 sizeof(struct schizo_iommureg
), &is
->is_iommu
)) {
392 printf("schizo: unable to create streaming buffer handle\n");
393 is
->is_sb
[0]->sb_flush
= NULL
;
396 /* initialize our strbuf_ctl */
397 is
->is_sb
[0] = &pbm
->sp_sb
;
398 pbm
->sp_sb
.sb_is
= is
;
399 is
->is_sb
[0]->sb_flush
= (void *)(va
& ~0x3f);
401 if (bus_space_subregion(is
->is_bustag
, pbm
->sp_regh
,
402 offsetof(struct schizo_pbm_regs
, strbuf
),
403 sizeof(struct iommu_strbuf
), &is
->is_sb
[0]->sb_sb
)) {
406 name
= (char *)malloc(32, M_DEVBUF
, M_NOWAIT
);
408 panic("couldn't malloc iommu name");
409 snprintf(name
, 32, "%s dvma", sc
->sc_dv
.dv_xname
);
412 * Separate the men from the boys. If the `virtual-dma'
413 * property exists, use it.
415 if (!prom_getprop(sc
->sc_node
, "virtual-dma", sizeof(vdma
), &nitem
,
417 /* Damn. Gotta use these values. */
419 #define TSBCASE(x) case 1 << ((x) + 23): tsbsize = (x); break
421 TSBCASE(1); TSBCASE(2); TSBCASE(3);
422 TSBCASE(4); TSBCASE(5); TSBCASE(6);
424 printf("bogus tsb size %x, using 7\n", vdma
[1]);
428 DPRINTF(SDB_BUSMAP
, ("schizo_init_iommu: iobase=0x%x\n", iobase
));
429 free(vdma
, M_DEVBUF
);
431 DPRINTF(SDB_BUSMAP
, ("schizo_init_iommu: getprop failed, "
432 "using iobase=0x%x, tsbsize=%d\n", iobase
, tsbsize
));
435 iommu_init(name
, is
, tsbsize
, iobase
);
439 schizo_print(void *aux
, const char *p
)
448 schizo_conf_read(pci_chipset_tag_t pc
, pcitag_t tag
, int reg
)
450 struct schizo_pbm
*sp
= pc
->cookie
;
451 pcireg_t val
= (pcireg_t
)~0;
453 DPRINTF(SDB_CONF
, ("%s: tag %lx reg %x ", __func__
, (long)tag
, reg
));
454 if (PCITAG_NODE(tag
) != -1)
455 val
= bus_space_read_4(sp
->sp_cfgt
, sp
->sp_cfgh
,
456 PCITAG_OFFSET(tag
) + reg
);
457 DPRINTF(SDB_CONF
, (" returning %08x\n", (u_int
)val
));
462 schizo_conf_write(pci_chipset_tag_t pc
, pcitag_t tag
, int reg
, pcireg_t data
)
464 struct schizo_pbm
*sp
= pc
->cookie
;
466 DPRINTF(SDB_CONF
, ("%s: tag %lx; reg %x; data %x", __func__
,
467 (long)tag
, reg
, (int)data
));
469 /* If we don't know it, just punt it. */
470 if (PCITAG_NODE(tag
) == -1) {
471 DPRINTF(SDB_CONF
, (" .. bad addr\n"));
475 bus_space_write_4(sp
->sp_cfgt
, sp
->sp_cfgh
,
476 PCITAG_OFFSET(tag
) + reg
, data
);
477 DPRINTF(SDB_CONF
, (" .. done\n"));
481 schizo_set_intr(struct schizo_softc
*sc
, struct schizo_pbm
*pbm
, int ipl
,
482 int (*handler
)(void *), void *arg
, int ino
, const char *what
)
485 u_int64_t mapoff
, clroff
;
487 DPRINTF(SDB_INTR
, ("%s: ino %x ign %x fn %p arg %p", __func__
,
488 ino
, sc
->sc_ign
, handler
, arg
));
490 mapoff
= offsetof(struct schizo_pbm_regs
, imap
[ino
]);
491 clroff
= offsetof(struct schizo_pbm_regs
, iclr
[ino
]);
494 DPRINTF(SDB_INTR
, (" mapoff %lx clroff %lx\n", mapoff
, clroff
));
496 ih
= (struct intrhand
*)
497 malloc(sizeof(struct intrhand
), M_DEVBUF
, M_NOWAIT
);
501 ih
->ih_map
= (uint64_t *)((char *)sc
->sc_reg0
.ur_paddr
+ mapoff
);
502 ih
->ih_clr
= (uint64_t *)((char *)sc
->sc_reg0
.ur_paddr
+ clroff
);
503 ih
->ih_fun
= handler
;
504 ih
->ih_pil
= (1<<ipl
);
505 ih
->ih_number
= INTVEC(schizo_pbm_read(pbm
, mapoff
));
506 intr_establish(ipl
, ipl
!= IPL_VM
, ih
);
508 schizo_pbm_write(pbm
, mapoff
,
509 ih
->ih_number
| INTMAP_V
| (CPU_UPAID
<< INTMAP_TID_SHIFT
));
513 schizo_alloc_mem_tag(struct schizo_pbm
*sp
)
515 return (schizo_alloc_bus_tag(sp
, "mem",
516 PCI_MEMORY_BUS_SPACE
));
520 schizo_alloc_io_tag(struct schizo_pbm
*sp
)
522 return (schizo_alloc_bus_tag(sp
, "io",
527 schizo_alloc_config_tag(struct schizo_pbm
*sp
)
529 return (schizo_alloc_bus_tag(sp
, "cfg",
530 PCI_CONFIG_BUS_SPACE
));
534 schizo_alloc_bus_tag(struct schizo_pbm
*pbm
, const char *name
, int type
)
536 struct schizo_softc
*sc
= pbm
->sp_sc
;
539 bt
= (bus_space_tag_t
) malloc(sizeof(struct sparc_bus_space_tag
),
540 M_DEVBUF
, M_NOWAIT
| M_ZERO
);
542 panic("schizo: could not allocate bus tag");
545 bt
->parent
= sc
->sc_bustag
;
547 bt
->sparc_bus_map
= schizo_bus_map
;
548 bt
->sparc_bus_mmap
= schizo_bus_mmap
;
549 bt
->sparc_intr_establish
= schizo_intr_establish
;
554 schizo_alloc_dma_tag(struct schizo_pbm
*pbm
)
556 struct schizo_softc
*sc
= pbm
->sp_sc
;
557 bus_dma_tag_t dt
, pdt
= sc
->sc_dmat
;
559 dt
= malloc(sizeof(*dt
), M_DEVBUF
, M_NOWAIT
| M_ZERO
);
561 panic("schizo: could not alloc dma tag");
565 #define PCOPY(x) dt->x = pdt->x
566 dt
->_dmamap_create
= schizo_dmamap_create
;
567 PCOPY(_dmamap_destroy
);
568 dt
->_dmamap_load
= iommu_dvmamap_load
;
569 PCOPY(_dmamap_load_mbuf
);
570 PCOPY(_dmamap_load_uio
);
571 dt
->_dmamap_load_raw
= iommu_dvmamap_load_raw
;
572 dt
->_dmamap_unload
= iommu_dvmamap_unload
;
573 dt
->_dmamap_sync
= iommu_dvmamap_sync
;
574 dt
->_dmamem_alloc
= iommu_dvmamem_alloc
;
575 dt
->_dmamem_free
= iommu_dvmamem_free
;
576 dt
->_dmamem_map
= iommu_dvmamem_map
;
577 dt
->_dmamem_unmap
= iommu_dvmamem_unmap
;
584 schizo_alloc_chipset(struct schizo_pbm
*pbm
, int node
, pci_chipset_tag_t pc
)
586 pci_chipset_tag_t npc
;
588 npc
= malloc(sizeof *npc
, M_DEVBUF
, M_NOWAIT
);
590 panic("schizo: could not allocate pci_chipset_tag_t");
591 memcpy(npc
, pc
, sizeof *pc
);
593 npc
->rootnode
= node
;
594 npc
->spc_conf_read
= schizo_conf_read
;
595 npc
->spc_conf_write
= schizo_conf_write
;
596 npc
->spc_intr_map
= schizo_pci_intr_map
;
597 npc
->spc_intr_establish
= schizo_pci_intr_establish
;
598 npc
->spc_find_ino
= schizo_pci_find_ino
;
603 schizo_dmamap_create(bus_dma_tag_t t
, bus_size_t size
,
604 int nsegments
, bus_size_t maxsegsz
, bus_size_t boundary
, int flags
,
607 struct schizo_pbm
*pbm
= t
->_cookie
;
610 error
= bus_dmamap_create(t
->_parent
, size
, nsegments
, maxsegsz
,
611 boundary
, flags
, dmamp
);
613 (*dmamp
)->_dm_cookie
= &pbm
->sp_sb
;
617 static struct schizo_range
*
618 get_schizorange(struct schizo_pbm
*pbm
, int ss
)
622 for (i
= 0; i
< pbm
->sp_nrange
; i
++) {
623 if (((pbm
->sp_range
[i
].cspace
>> 24) & 0x03) == ss
)
624 return (&pbm
->sp_range
[i
]);
631 schizo_bus_map(bus_space_tag_t t
, bus_addr_t offset
, bus_size_t size
,
632 int flags
, vaddr_t unused
, bus_space_handle_t
*hp
)
635 struct schizo_pbm
*pbm
= t
->cookie
;
636 struct schizo_softc
*sc
= pbm
->sp_sc
;
637 struct schizo_range
*sr
;
640 DPRINTF(SDB_BUSMAP
, ("schizo_bus_map: type %d off %qx sz %qx flags %d",
642 (unsigned long long)offset
,
643 (unsigned long long)size
,
646 ss
= sparc_pci_childspace(t
->type
);
647 DPRINTF(SDB_BUSMAP
, (" cspace %d\n", ss
));
649 sr
= get_schizorange(pbm
, ss
);
651 paddr
= BUS_ADDR(sr
->phys_hi
, sr
->phys_lo
+ offset
);
652 DPRINTF(SDB_BUSMAP
, ("%s: mapping paddr "
653 "space %lx offset %lx paddr %qx\n",
654 __func__
, (long)ss
, (long)offset
,
655 (unsigned long long)paddr
));
656 return ((*sc
->sc_bustag
->sparc_bus_map
)(t
, paddr
, size
,
659 DPRINTF(SDB_BUSMAP
, ("%s: FAILED\n", __func__
));
664 schizo_bus_mmap(bus_space_tag_t t
, bus_addr_t paddr
, off_t off
, int prot
,
667 bus_addr_t offset
= paddr
;
668 struct schizo_pbm
*pbm
= t
->cookie
;
669 struct schizo_softc
*sc
= pbm
->sp_sc
;
670 struct schizo_range
*sr
;
673 ss
= sparc_pci_childspace(t
->type
);
675 DPRINTF(SDB_BUSMAP
, ("schizo_bus_mmap: prot %d flags %d pa %qx\n",
676 prot
, flags
, (unsigned long long)paddr
));
678 sr
= get_schizorange(pbm
, ss
);
680 paddr
= BUS_ADDR(sr
->phys_hi
, sr
->phys_lo
+ offset
);
681 DPRINTF(SDB_BUSMAP
, ("%s: mapping paddr "
682 "space %lx offset %lx paddr %qx\n",
683 __func__
, (long)ss
, (long)offset
,
684 (unsigned long long)paddr
));
685 return (bus_space_mmap(sc
->sc_bustag
, paddr
, off
,
688 DPRINTF(SDB_BUSMAP
, ("%s: FAILED\n", __func__
));
693 * Set the IGN for this schizo into the handle.
696 schizo_pci_intr_map(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
698 struct schizo_pbm
*pbm
= pa
->pa_pc
->cookie
;
699 struct schizo_softc
*sc
= pbm
->sp_sc
;
702 DPRINTF(SDB_INTMAP
, ("returning IGN adjusted to %x\n", *ihp
));
707 schizo_intr_establish(bus_space_tag_t t
, int ihandle
, int level
,
708 int (*handler
)(void *), void *arg
, void (*fastvec
)(void) /* ignored */)
710 struct schizo_pbm
*pbm
= t
->cookie
;
711 struct schizo_softc
*sc
= pbm
->sp_sc
;
712 struct intrhand
*ih
= NULL
;
713 uint64_t mapoff
, clroff
;
714 volatile uint64_t *intrmapptr
= NULL
, *intrclrptr
= NULL
;
718 vec
= INTVEC(ihandle
);
721 ih
= malloc(sizeof *ih
, M_DEVBUF
, M_NOWAIT
);
725 DPRINTF(SDB_INTR
, ("\n%s: ihandle %d level %d fn %p arg %p\n", __func__
,
726 ihandle
, level
, handler
, arg
));
728 if (level
== IPL_NONE
)
730 if (level
== IPL_NONE
) {
731 printf(": no IPL, setting IPL 2.\n");
735 mapoff
= offsetof(struct schizo_pbm_regs
, imap
[ino
]);
736 clroff
= offsetof(struct schizo_pbm_regs
, iclr
[ino
]);
738 DPRINTF(SDB_INTR
, ("%s: intr %x: %p mapoff %lx clroff %lx\n",
739 __func__
, ino
, intrlev
[ino
], mapoff
, clroff
));
741 intrmapptr
= (uint64_t *)((char *)sc
->sc_reg0
.ur_paddr
+ mapoff
);
742 intrclrptr
= (uint64_t *)((char *)sc
->sc_reg0
.ur_paddr
+ clroff
);
744 if (INTIGN(vec
) == 0)
745 ino
|= schizo_pbm_read(pbm
, mapoff
) & INTMAP_IGN
;
747 ino
|= vec
& INTMAP_IGN
;
749 /* Register the map and clear intr registers */
750 ih
->ih_map
= intrmapptr
;
751 ih
->ih_clr
= intrclrptr
;
753 ih
->ih_fun
= handler
;
759 "; installing handler %p arg %p with inr %x pil %u\n",
760 handler
, arg
, ino
, (u_int
)ih
->ih_pil
));
762 intr_establish(ih
->ih_pil
, level
!= IPL_VM
, ih
);
765 * Enable the interrupt now we have the handler installed.
766 * Read the current value as we can't change it besides the
767 * valid bit so so make sure only this bit is changed.
772 imap
= schizo_pbm_read(pbm
, mapoff
);
773 DPRINTF(SDB_INTR
, ("; read intrmap = %016qx",
774 (unsigned long long)imap
));
776 DPRINTF(SDB_INTR
, ("; addr of intrmapptr = %p", intrmapptr
));
777 DPRINTF(SDB_INTR
, ("; writing intrmap = %016qx\n",
778 (unsigned long long)imap
));
779 schizo_pbm_write(pbm
, mapoff
, imap
);
780 imap
= schizo_pbm_read(pbm
, mapoff
);
781 DPRINTF(SDB_INTR
, ("; reread intrmap = %016qx",
782 (unsigned long long)imap
));
783 ih
->ih_number
|= imap
& INTMAP_INR
;
786 /* set state to IDLE */
787 schizo_pbm_write(pbm
, clroff
, 0);
794 schizo_pci_intr_establish(pci_chipset_tag_t pc
, pci_intr_handle_t ih
, int level
,
795 int (*func
)(void *), void *arg
)
798 struct schizo_pbm
*pbm
= (struct schizo_pbm
*)pc
->cookie
;
800 DPRINTF(SDB_INTR
, ("%s: ih %lx; level %d", __func__
, (u_long
)ih
, level
));
801 cookie
= bus_intr_establish(pbm
->sp_memt
, ih
, level
, func
, arg
);
803 DPRINTF(SDB_INTR
, ("; returning handle %p\n", cookie
));
808 schizo_pci_find_ino(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
811 struct schizo_pbm
*pbm
= pa
->pa_pc
->cookie
;
812 struct schizo_softc
*sc
= pbm
->sp_sc
;
818 DPRINTF(SDB_INTMAP
, ("pci_find_ino: pa_tag: node %x, %d:%d:%d\n",
819 PCITAG_NODE(pa
->pa_tag
), (int)PCITAG_BUS(pa
->pa_tag
),
820 (int)PCITAG_DEV(pa
->pa_tag
),
821 (int)PCITAG_FUN(pa
->pa_tag
)));
823 ("pci_find_ino: intrswiz %d, intrpin %d, intrline %d, rawintrpin %d\n",
824 pa
->pa_intrswiz
, pa
->pa_intrpin
, pa
->pa_intrline
, pa
->pa_rawintrpin
));
825 DPRINTF(SDB_INTMAP
, ("pci_find_ino: pa_intrtag: node %x, %d:%d:%d\n",
826 PCITAG_NODE(pa
->pa_intrtag
),
827 (int)PCITAG_BUS(pa
->pa_intrtag
),
828 (int)PCITAG_DEV(pa
->pa_intrtag
),
829 (int)PCITAG_FUN(pa
->pa_intrtag
)));
832 bus
= (pp
->pp_id
== PSYCHO_PBM_B
);
834 * If we are on a ppb, use the devno on the underlying bus when forming
837 if (pa
->pa_intrswiz
!= 0 && PCITAG_NODE(pa
->pa_intrtag
) != 0)
838 dev
= PCITAG_DEV(pa
->pa_intrtag
);
843 if (sc
->sc_mode
== PSYCHO_MODE_PSYCHO
&&
844 pp
->pp_id
== PSYCHO_PBM_B
)
847 pin
= pa
->pa_intrpin
- 1;
848 DPRINTF(SDB_INTMAP
, ("pci_find_ino: mode %d, pbm %d, dev %d, pin %d\n",
849 sc
->sc_mode
, pp
->pp_id
, dev
, pin
));
851 *ihp
= sc
->sc_ign
| ((bus
<< 4) & INTMAP_PCIBUS
) |
852 ((dev
<< 2) & INTMAP_PCISLOT
) | (pin
& INTMAP_PCIINT
);