1 /* $NetBSD: psycho.c,v 1.99 2009/12/30 17:16:49 nakayama Exp $ */
4 * Copyright (c) 1999, 2000 Matthew R. Green
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Copyright (c) 2001, 2002 Eduardo E. Horvath
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. The name of the author may not be used to endorse or promote products
42 * derived from this software without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
48 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
49 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
51 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 #include <sys/cdefs.h>
58 __KERNEL_RCSID(0, "$NetBSD: psycho.c,v 1.99 2009/12/30 17:16:49 nakayama Exp $");
63 * Support for `psycho' and `psycho+' UPA to PCI bridge and
64 * UltraSPARC IIi and IIe `sabre' PCI controllers.
69 #define PDB_BUSMAP 0x02
71 #define PDB_INTMAP 0x08
73 int psycho_debug
= 0x0;
74 #define DPRINTF(l, s) do { if (psycho_debug & l) printf s; } while (0)
79 #include <sys/param.h>
80 #include <sys/device.h>
81 #include <sys/errno.h>
82 #include <sys/extent.h>
83 #include <sys/malloc.h>
84 #include <sys/systm.h>
86 #include <sys/reboot.h>
90 #define _SPARC_BUS_DMA_PRIVATE
91 #include <machine/bus.h>
92 #include <machine/autoconf.h>
93 #include <machine/psl.h>
95 #include <dev/pci/pcivar.h>
96 #include <dev/pci/pcireg.h>
97 #include <dev/sysmon/sysmon_taskq.h>
99 #include <sparc64/dev/iommureg.h>
100 #include <sparc64/dev/iommuvar.h>
101 #include <sparc64/dev/psychoreg.h>
102 #include <sparc64/dev/psychovar.h>
106 static pci_chipset_tag_t
psycho_alloc_chipset(struct psycho_pbm
*, int,
108 static struct extent
*psycho_alloc_extent(struct psycho_pbm
*, int, int,
110 static void psycho_get_bus_range(int, int *);
111 static void psycho_get_ranges(int, struct psycho_ranges
**, int *);
112 static void psycho_set_intr(struct psycho_softc
*, int, void *, uint64_t *,
115 /* chipset handlers */
116 static pcireg_t
psycho_pci_conf_read(pci_chipset_tag_t
, pcitag_t
, int);
117 static void psycho_pci_conf_write(pci_chipset_tag_t
, pcitag_t
, int,
119 static void *psycho_pci_intr_establish(pci_chipset_tag_t
,
121 int, int (*)(void *), void *);
122 static int psycho_pci_find_ino(struct pci_attach_args
*,
123 pci_intr_handle_t
*);
125 /* Interrupt handlers */
126 static int psycho_ue(void *);
127 static int psycho_ce(void *);
128 static int psycho_bus_a(void *);
129 static int psycho_bus_b(void *);
130 static int psycho_powerfail(void *);
131 static int psycho_wakeup(void *);
135 static void psycho_iommu_init(struct psycho_softc
*, int);
138 * bus space and bus DMA support for UltraSPARC `psycho'. note that most
139 * of the bus DMA support is provided by the iommu dvma controller.
141 static struct psycho_ranges
*get_psychorange(struct psycho_pbm
*, int);
143 static paddr_t
psycho_bus_mmap(bus_space_tag_t
, bus_addr_t
, off_t
, int, int);
144 static int _psycho_bus_map(bus_space_tag_t
, bus_addr_t
, bus_size_t
, int,
145 vaddr_t
, bus_space_handle_t
*);
146 static void *psycho_intr_establish(bus_space_tag_t
, int, int, int (*)(void *),
147 void *, void(*)(void));
149 static int psycho_dmamap_create(bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
150 bus_size_t
, int, bus_dmamap_t
*);
151 static void psycho_sabre_dmamap_sync(bus_dma_tag_t
, bus_dmamap_t
, bus_addr_t
,
154 /* base pci_chipset */
155 extern struct sparc_pci_chipset _sparc_pci_chipset
;
157 /* power button handlers */
158 static void psycho_register_power_button(struct psycho_softc
*sc
);
159 static void psycho_power_button_pressed(void *arg
);
164 static int psycho_match(struct device
*, struct cfdata
*, void *);
165 static void psycho_attach(struct device
*, struct device
*, void *);
166 static int psycho_print(void *aux
, const char *p
);
168 CFATTACH_DECL(psycho
, sizeof(struct psycho_softc
),
169 psycho_match
, psycho_attach
, NULL
, NULL
);
172 * "sabre" is the UltraSPARC IIi onboard UPA to PCI bridge. It manages a
173 * single PCI bus and does not have a streaming buffer. It often has an APB
174 * (advanced PCI bridge) connected to it, which was designed specifically for
175 * the IIi. The APB let's the IIi handle two independednt PCI buses, and
176 * appears as two "simba"'s underneath the sabre.
178 * "psycho" and "psycho+" is a dual UPA to PCI bridge. It sits on the UPA bus
179 * and manages two PCI buses. "psycho" has two 64-bit 33 MHz buses, while
180 * "psycho+" controls both a 64-bit 33 MHz and a 64-bit 66 MHz PCI bus. You
181 * will usually find a "psycho+" since I don't think the original "psycho"
182 * ever shipped, and if it did it would be in the U30.
184 * Each "psycho" PCI bus appears as a separate OFW node, but since they are
185 * both part of the same IC, they only have a single register space. As such,
186 * they need to be configured together, even though the autoconfiguration will
187 * attach them separately.
189 * On UltraIIi machines, "sabre" itself usually takes pci0, with "simba" often
190 * as pci1 and pci2, although they have been implemented with other PCI bus
191 * numbers on some machines.
193 * On UltraII machines, there can be any number of "psycho+" ICs, each
194 * providing two PCI buses.
197 * XXXX The psycho/sabre node has an `interrupts' attribute. They contain
198 * the values of the following interrupts in this order:
205 * We really should attach handlers for each.
209 #define ROM_PCI_NAME "pci"
211 struct psycho_names
{
215 { "SUNW,psycho", PSYCHO_MODE_PSYCHO
},
216 { "pci108e,8000", PSYCHO_MODE_PSYCHO
},
217 { "SUNW,sabre", PSYCHO_MODE_SABRE
},
218 { "pci108e,a000", PSYCHO_MODE_SABRE
},
219 { "pci108e,a001", PSYCHO_MODE_SABRE
},
224 psycho_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
226 struct mainbus_attach_args
*ma
= aux
;
227 char *model
= prom_getpropstring(ma
->ma_node
, "model");
230 /* match on a name of "pci" and a sabre or a psycho */
231 if (strcmp(ma
->ma_name
, ROM_PCI_NAME
) == 0) {
232 for (i
=0; psycho_names
[i
].p_name
; i
++)
233 if (strcmp(model
, psycho_names
[i
].p_name
) == 0)
236 model
= prom_getpropstring(ma
->ma_node
, "compatible");
237 for (i
=0; psycho_names
[i
].p_name
; i
++)
238 if (strcmp(model
, psycho_names
[i
].p_name
) == 0)
245 static void psycho_dump_intmap(struct psycho_softc
*sc
);
247 psycho_dump_intmap(struct psycho_softc
*sc
)
249 volatile uint64_t *intrmapptr
= NULL
;
251 printf("psycho_dump_intmap: OBIO\n");
253 for (intrmapptr
= &sc
->sc_regs
->scsi_int_map
;
254 intrmapptr
< &sc
->sc_regs
->ue_int_map
;
256 printf("%p: %llx\n", intrmapptr
,
257 (unsigned long long)*intrmapptr
);
259 printf("\tintmap:pci\n");
260 for (intrmapptr
= &sc
->sc_regs
->pcia_slot0_int
;
261 intrmapptr
<= &sc
->sc_regs
->pcib_slot3_int
;
263 printf("%p: %llx\n", intrmapptr
,
264 (unsigned long long)*intrmapptr
);
266 printf("\tintmap:ffb\n");
267 for (intrmapptr
= &sc
->sc_regs
->ffb0_int_map
;
268 intrmapptr
<= &sc
->sc_regs
->ffb1_int_map
;
270 printf("%p: %llx\n", intrmapptr
,
271 (unsigned long long)*intrmapptr
);
276 * SUNW,psycho initialisation ..
277 * - find the per-psycho registers
278 * - figure out the IGN.
279 * - find our partner psycho
280 * - configure ourselves
282 * - get interrupt-map and interrupt-map-mask
283 * - setup the chipsets.
284 * - if we're the first of the pair, initialise the IOMMU, otherwise
285 * just copy it's tags and addresses.
288 psycho_attach(struct device
*parent
, struct device
*self
, void *aux
)
290 struct psycho_softc
*sc
= (struct psycho_softc
*)self
;
291 struct psycho_softc
*osc
= NULL
;
292 struct psycho_pbm
*pp
;
293 struct pcibus_attach_args pba
;
294 struct mainbus_attach_args
*ma
= aux
;
295 struct psycho_ranges
*pr
;
296 prop_dictionary_t dict
;
297 bus_space_handle_t bh
;
298 uint64_t csr
, mem_base
;
299 int psycho_br
[2], n
, i
;
300 bus_space_handle_t pci_ctl
;
301 char *model
= prom_getpropstring(ma
->ma_node
, "model");
305 sc
->sc_node
= ma
->ma_node
;
306 sc
->sc_bustag
= ma
->ma_bustag
;
307 sc
->sc_dmatag
= ma
->ma_dmatag
;
310 * Identify the device.
312 for (i
=0; psycho_names
[i
].p_name
; i
++)
313 if (strcmp(model
, psycho_names
[i
].p_name
) == 0) {
314 sc
->sc_mode
= psycho_names
[i
].p_type
;
318 model
= prom_getpropstring(ma
->ma_node
, "compatible");
319 for (i
=0; psycho_names
[i
].p_name
; i
++)
320 if (strcmp(model
, psycho_names
[i
].p_name
) == 0) {
321 sc
->sc_mode
= psycho_names
[i
].p_type
;
325 panic("unknown psycho model %s", model
);
329 * The psycho gets three register banks:
330 * (0) per-PBM configuration and status registers
331 * (1) per-PBM PCI configuration space, containing only the
332 * PBM 256-byte PCI header
333 * (2) the shared psycho configuration registers (struct psychoreg)
336 /* Register layouts are different. stuupid. */
337 if (sc
->sc_mode
== PSYCHO_MODE_PSYCHO
) {
338 sc
->sc_basepaddr
= (paddr_t
)ma
->ma_reg
[2].ur_paddr
;
340 if (ma
->ma_naddress
> 2) {
341 sparc_promaddr_to_handle(sc
->sc_bustag
,
342 ma
->ma_address
[2], &sc
->sc_bh
);
343 sparc_promaddr_to_handle(sc
->sc_bustag
,
344 ma
->ma_address
[0], &pci_ctl
);
346 sc
->sc_regs
= (struct psychoreg
*)
347 bus_space_vaddr(sc
->sc_bustag
, sc
->sc_bh
);
348 } else if (ma
->ma_nreg
> 2) {
350 /* We need to map this in ourselves. */
351 if (bus_space_map(sc
->sc_bustag
,
352 ma
->ma_reg
[2].ur_paddr
,
353 ma
->ma_reg
[2].ur_len
, BUS_SPACE_MAP_LINEAR
,
355 panic("psycho_attach: cannot map regs");
356 sc
->sc_regs
= (struct psychoreg
*)
357 bus_space_vaddr(sc
->sc_bustag
, sc
->sc_bh
);
359 if (bus_space_map(sc
->sc_bustag
,
360 ma
->ma_reg
[0].ur_paddr
,
361 ma
->ma_reg
[0].ur_len
, BUS_SPACE_MAP_LINEAR
,
363 panic("psycho_attach: cannot map ctl");
365 panic("psycho_attach: %d not enough registers",
369 sc
->sc_basepaddr
= (paddr_t
)ma
->ma_reg
[0].ur_paddr
;
371 if (ma
->ma_naddress
) {
372 sparc_promaddr_to_handle(sc
->sc_bustag
,
373 ma
->ma_address
[0], &sc
->sc_bh
);
374 sc
->sc_regs
= (struct psychoreg
*)
375 bus_space_vaddr(sc
->sc_bustag
, sc
->sc_bh
);
376 bus_space_subregion(sc
->sc_bustag
, sc
->sc_bh
,
377 offsetof(struct psychoreg
, psy_pcictl
),
378 sizeof(struct pci_ctl
), &pci_ctl
);
379 } else if (ma
->ma_nreg
) {
381 /* We need to map this in ourselves. */
382 if (bus_space_map(sc
->sc_bustag
,
383 ma
->ma_reg
[0].ur_paddr
,
384 ma
->ma_reg
[0].ur_len
, BUS_SPACE_MAP_LINEAR
,
386 panic("psycho_attach: cannot map regs");
387 sc
->sc_regs
= (struct psychoreg
*)
388 bus_space_vaddr(sc
->sc_bustag
, sc
->sc_bh
);
390 bus_space_subregion(sc
->sc_bustag
, sc
->sc_bh
,
391 offsetof(struct psychoreg
, psy_pcictl
),
392 sizeof(struct pci_ctl
), &pci_ctl
);
394 panic("psycho_attach: %d not enough registers",
399 csr
= bus_space_read_8(sc
->sc_bustag
, sc
->sc_bh
,
400 offsetof(struct psychoreg
, psy_csr
));
401 sc
->sc_ign
= 0x7c0; /* APB IGN is always 0x7c */
402 if (sc
->sc_mode
== PSYCHO_MODE_PSYCHO
)
403 sc
->sc_ign
= PSYCHO_GCSR_IGN(csr
) << 6;
405 aprint_normal_dev(self
, "%s: impl %d, version %d: ign %x ",
406 model
, PSYCHO_GCSR_IMPL(csr
), PSYCHO_GCSR_VERS(csr
),
409 * Match other psycho's that are already configured against
410 * the base physical address. This will be the same for a
411 * pair of devices that share register space.
413 for (n
= 0; n
< psycho_cd
.cd_ndevs
; n
++) {
415 struct psycho_softc
*asc
= device_lookup_private(&psycho_cd
, n
);
417 if (asc
== NULL
|| asc
== sc
)
418 /* This entry is not there or it is me */
421 if (asc
->sc_basepaddr
!= sc
->sc_basepaddr
)
422 /* This is an unrelated psycho */
431 /* Oh, dear. OK, lets get started */
434 * Setup the PCI control register
436 csr
= bus_space_read_8(sc
->sc_bustag
, pci_ctl
,
437 offsetof(struct pci_ctl
, pci_csr
));
442 csr
&= ~(PCICTL_SERR
|
446 bus_space_write_8(sc
->sc_bustag
, pci_ctl
,
447 offsetof(struct pci_ctl
, pci_csr
), csr
);
451 * Allocate our psycho_pbm
453 pp
= sc
->sc_psycho_this
= malloc(sizeof *pp
, M_DEVBUF
,
456 panic("could not allocate psycho pbm");
460 /* grab the psycho ranges */
461 psycho_get_ranges(sc
->sc_node
, &pp
->pp_range
, &pp
->pp_nrange
);
463 /* get the bus-range for the psycho */
464 psycho_get_bus_range(sc
->sc_node
, psycho_br
);
466 pba
.pba_bus
= psycho_br
[0];
467 pba
.pba_bridgetag
= NULL
;
469 aprint_normal("bus range %u to %u", psycho_br
[0], psycho_br
[1]);
470 aprint_normal("; PCI bus %d", psycho_br
[0]);
472 pp
->pp_pcictl
= pci_ctl
;
474 /* allocate our tags */
475 pp
->pp_memt
= psycho_alloc_mem_tag(pp
);
476 pp
->pp_iot
= psycho_alloc_io_tag(pp
);
477 pp
->pp_dmat
= psycho_alloc_dma_tag(pp
);
478 pp
->pp_flags
= (pp
->pp_memt
? PCI_FLAGS_MEM_ENABLED
: 0) |
479 (pp
->pp_iot
? PCI_FLAGS_IO_ENABLED
: 0);
481 /* allocate a chipset for this */
482 pp
->pp_pc
= psycho_alloc_chipset(pp
, sc
->sc_node
, &_sparc_pci_chipset
);
483 pp
->pp_pc
->spc_busmax
= psycho_br
[1];
485 switch((ma
->ma_reg
[0].ur_paddr
) & 0xf000) {
487 pp
->pp_id
= PSYCHO_PBM_A
;
490 pp
->pp_id
= PSYCHO_PBM_B
;
496 /* allocate extents for free bus space */
497 pp
->pp_exmem
= psycho_alloc_extent(pp
, sc
->sc_node
, 0x02, "psycho mem");
498 pp
->pp_exio
= psycho_alloc_extent(pp
, sc
->sc_node
, 0x01, "psycho io");
501 if (psycho_debug
& PDB_INTR
)
502 psycho_dump_intmap(sc
);
506 * And finally, if we're a sabre or the first of a pair of psycho's to
507 * arrive here, start up the IOMMU and get a config space tag.
513 * Establish handlers for interesting interrupts....
515 * XXX We need to remember these and remove this to support
516 * hotplug on the UPA/FHC bus.
518 * XXX Not all controllers have these, but installing them
519 * is better than trying to sort through this mess.
521 psycho_set_intr(sc
, 15, psycho_ue
,
522 &sc
->sc_regs
->ue_int_map
,
523 &sc
->sc_regs
->ue_clr_int
);
524 psycho_set_intr(sc
, 1, psycho_ce
,
525 &sc
->sc_regs
->ce_int_map
,
526 &sc
->sc_regs
->ce_clr_int
);
527 psycho_set_intr(sc
, 15, psycho_bus_a
,
528 &sc
->sc_regs
->pciaerr_int_map
,
529 &sc
->sc_regs
->pciaerr_clr_int
);
530 psycho_set_intr(sc
, 15, psycho_powerfail
,
531 &sc
->sc_regs
->power_int_map
,
532 &sc
->sc_regs
->power_clr_int
);
533 psycho_register_power_button(sc
);
534 if (sc
->sc_mode
!= PSYCHO_MODE_SABRE
) {
535 /* sabre doesn't have these interrupts */
536 psycho_set_intr(sc
, 15, psycho_bus_b
,
537 &sc
->sc_regs
->pciberr_int_map
,
538 &sc
->sc_regs
->pciberr_clr_int
);
539 psycho_set_intr(sc
, 1, psycho_wakeup
,
540 &sc
->sc_regs
->pwrmgt_int_map
,
541 &sc
->sc_regs
->pwrmgt_clr_int
);
545 * Apparently a number of machines with psycho and psycho+
546 * controllers have interrupt latency issues. We'll try
547 * setting the interrupt retry timeout to 0xff which gives us
548 * a retry of 3-6 usec (which is what sysio is set to) for the
549 * moment, which seems to help alleviate this problem.
551 timeo
= sc
->sc_regs
->intr_retry_timer
;
554 printf("decreasing interrupt retry timeout "
555 "from %lx to 0xff\n", (long)timeo
);
557 sc
->sc_regs
->intr_retry_timer
= 0xff;
561 * Allocate bus node, this contains a prom node per bus.
563 pp
->pp_pc
->spc_busnode
=
564 malloc(sizeof(*pp
->pp_pc
->spc_busnode
), M_DEVBUF
,
566 if (pp
->pp_pc
->spc_busnode
== NULL
)
567 panic("psycho_attach: malloc busnode");
570 * Setup IOMMU and PCI configuration if we're the first
571 * of a pair of psycho's to arrive here.
573 * We should calculate a TSB size based on amount of RAM
574 * and number of bus controllers and number an type of
577 * For the moment, 32KB should be more than enough.
579 sc
->sc_is
= malloc(sizeof(struct iommu_state
),
581 if (sc
->sc_is
== NULL
)
582 panic("psycho_attach: malloc iommu_state");
584 /* Point the strbuf_ctl at the iommu_state */
585 pp
->pp_sb
.sb_is
= sc
->sc_is
;
587 sc
->sc_is
->is_sb
[0] = sc
->sc_is
->is_sb
[1] = NULL
;
588 if (prom_getproplen(sc
->sc_node
, "no-streaming-cache") < 0) {
589 struct strbuf_ctl
*sb
= &pp
->pp_sb
;
590 vaddr_t va
= (vaddr_t
)&pp
->pp_flush
[0x40];
593 * Initialize the strbuf_ctl.
595 * The flush sync buffer must be 64-byte aligned.
597 sb
->sb_flush
= (void *)(va
& ~0x3f);
599 bus_space_subregion(sc
->sc_bustag
, pci_ctl
,
600 offsetof(struct pci_ctl
, pci_strbuf
),
601 sizeof (struct iommu_strbuf
), &sb
->sb_sb
);
603 /* Point our iommu at the strbuf_ctl */
604 sc
->sc_is
->is_sb
[0] = sb
;
607 psycho_iommu_init(sc
, 2);
609 sc
->sc_configtag
= psycho_alloc_config_tag(sc
->sc_psycho_this
);
612 * XXX This is a really ugly hack because PCI config space
613 * is explicitly handled with unmapped accesses.
615 i
= sc
->sc_bustag
->type
;
616 sc
->sc_bustag
->type
= PCI_CONFIG_BUS_SPACE
;
617 if (bus_space_map(sc
->sc_bustag
, sc
->sc_basepaddr
+ 0x01000000,
619 panic("could not map psycho PCI configuration space");
620 sc
->sc_bustag
->type
= i
;
621 sc
->sc_configaddr
= bh
;
623 /* Share bus numbers with the pair of mine */
624 pp
->pp_pc
->spc_busnode
=
625 osc
->sc_psycho_this
->pp_pc
->spc_busnode
;
627 /* Just copy IOMMU state, config tag and address */
628 sc
->sc_is
= osc
->sc_is
;
629 sc
->sc_configtag
= osc
->sc_configtag
;
630 sc
->sc_configaddr
= osc
->sc_configaddr
;
632 /* Point the strbuf_ctl at the iommu_state */
633 pp
->pp_sb
.sb_is
= sc
->sc_is
;
635 if (prom_getproplen(sc
->sc_node
, "no-streaming-cache") < 0) {
636 struct strbuf_ctl
*sb
= &pp
->pp_sb
;
637 vaddr_t va
= (vaddr_t
)&pp
->pp_flush
[0x40];
640 * Initialize the strbuf_ctl.
642 * The flush sync buffer must be 64-byte aligned.
644 sb
->sb_flush
= (void *)(va
& ~0x3f);
646 bus_space_subregion(sc
->sc_bustag
, pci_ctl
,
647 offsetof(struct pci_ctl
, pci_strbuf
),
648 sizeof (struct iommu_strbuf
), &sb
->sb_sb
);
650 /* Point our iommu at the strbuf_ctl */
651 sc
->sc_is
->is_sb
[1] = sb
;
653 iommu_reset(sc
->sc_is
);
656 dict
= device_properties(self
);
657 pr
= get_psychorange(pp
, 2); /* memory range */
659 printf("memory range: %08x %08x\n", pr
->phys_hi
, pr
->phys_lo
);
661 mem_base
= ((uint64_t)pr
->phys_hi
) << 32 | pr
->phys_lo
;
662 prop_dictionary_set_uint64(dict
, "mem_base", mem_base
);
665 * attach the pci.. note we pass PCI A tags, etc., for the sabre here.
667 pba
.pba_flags
= sc
->sc_psycho_this
->pp_flags
;
668 pba
.pba_dmat
= sc
->sc_psycho_this
->pp_dmat
;
669 pba
.pba_dmat64
= NULL
;
670 pba
.pba_iot
= sc
->sc_psycho_this
->pp_iot
;
671 pba
.pba_memt
= sc
->sc_psycho_this
->pp_memt
;
672 pba
.pba_pc
= pp
->pp_pc
;
674 config_found_ia(self
, "pcibus", &pba
, psycho_print
);
678 psycho_print(void *aux
, const char *p
)
687 psycho_set_intr(struct psycho_softc
*sc
, int ipl
, void *handler
,
688 uint64_t *mapper
, uint64_t *clearer
)
692 ih
= (struct intrhand
*)malloc(sizeof(struct intrhand
),
696 ih
->ih_clr
= clearer
;
697 ih
->ih_fun
= handler
;
698 ih
->ih_pil
= (1<<ipl
);
699 ih
->ih_number
= INTVEC(*(ih
->ih_map
));
700 intr_establish(ipl
, ipl
!= IPL_VM
, ih
);
701 *(ih
->ih_map
) |= INTMAP_V
|(CPU_UPAID
<< INTMAP_TID_SHIFT
);
705 * power button handlers
708 psycho_register_power_button(struct psycho_softc
*sc
)
710 sysmon_task_queue_init();
712 sc
->sc_powerpressed
= 0;
713 sc
->sc_smcontext
= malloc(sizeof(struct sysmon_pswitch
), M_DEVBUF
, 0);
714 if (!sc
->sc_smcontext
) {
715 aprint_error_dev(&sc
->sc_dev
, "could not allocate power button context\n");
718 memset(sc
->sc_smcontext
, 0, sizeof(struct sysmon_pswitch
));
719 sc
->sc_smcontext
->smpsw_name
= device_xname(&sc
->sc_dev
);
720 sc
->sc_smcontext
->smpsw_type
= PSWITCH_TYPE_POWER
;
721 if (sysmon_pswitch_register(sc
->sc_smcontext
) != 0)
722 aprint_error_dev(&sc
->sc_dev
, "unable to register power button with sysmon\n");
726 psycho_power_button_pressed(void *arg
)
728 struct psycho_softc
*sc
= arg
;
730 sysmon_pswitch_event(sc
->sc_smcontext
, PSWITCH_EVENT_PRESSED
);
731 sc
->sc_powerpressed
= 0;
739 * allocate a PCI chipset tag and set it's cookie.
741 static pci_chipset_tag_t
742 psycho_alloc_chipset(struct psycho_pbm
*pp
, int node
, pci_chipset_tag_t pc
)
744 pci_chipset_tag_t npc
;
746 npc
= malloc(sizeof *npc
, M_DEVBUF
, M_NOWAIT
);
748 panic("could not allocate pci_chipset_tag_t");
749 memcpy(npc
, pc
, sizeof *pc
);
751 npc
->rootnode
= node
;
752 npc
->spc_conf_read
= psycho_pci_conf_read
;
753 npc
->spc_conf_write
= psycho_pci_conf_write
;
754 npc
->spc_intr_map
= NULL
;
755 npc
->spc_intr_establish
= psycho_pci_intr_establish
;
756 npc
->spc_find_ino
= psycho_pci_find_ino
;
762 * create extent for free bus space, then allocate assigned regions.
764 static struct extent
*
765 psycho_alloc_extent(struct psycho_pbm
*pp
, int node
, int ss
, const char *name
)
767 struct psycho_registers
*pa
= NULL
;
768 struct psycho_ranges
*pr
;
770 bus_addr_t baddr
, addr
;
771 bus_size_t bsize
, size
;
774 /* get bus space size */
775 pr
= get_psychorange(pp
, ss
);
777 printf("psycho_alloc_extent: get_psychorange failed\n");
781 bsize
= BUS_ADDR(pr
->size_hi
, pr
->size_lo
);
783 /* get available lists */
785 if (prom_getprop(node
, "available", sizeof(*pa
), &num
, &pa
)) {
786 printf("psycho_alloc_extent: no \"available\" property\n");
791 ex
= extent_create(name
, baddr
, bsize
- baddr
- 1, M_DEVBUF
, 0, 0,
794 printf("psycho_alloc_extent: extent_create failed\n");
798 /* allocate assigned regions */
799 for (i
= 0; i
< num
; i
++)
800 if (((pa
[i
].phys_hi
>> 24) & 0x03) == ss
) {
801 /* allocate bus space */
802 addr
= BUS_ADDR(pa
[i
].phys_mid
, pa
[i
].phys_lo
);
803 size
= BUS_ADDR(pa
[i
].size_hi
, pa
[i
].size_lo
);
804 if (extent_alloc_region(ex
, baddr
, addr
- baddr
,
806 printf("psycho_alloc_extent: "
807 "extent_alloc_region %" PRIx64
"-%"
808 PRIx64
" failed\n", baddr
, addr
);
815 /* allocate left region if available */
817 if (extent_alloc_region(ex
, baddr
, bsize
- baddr
, EX_NOWAIT
)) {
818 printf("psycho_alloc_extent: extent_alloc_region %"
819 PRIx64
"-%" PRIx64
" failed\n", baddr
, bsize
);
837 * grovel the OBP for various psycho properties
840 psycho_get_bus_range(int node
, int *brp
)
845 error
= prom_getprop(node
, "bus-range", sizeof(*brp
), &n
, &brp
);
847 panic("could not get psycho bus-range, error %d", error
);
849 panic("broken psycho bus-range");
850 DPRINTF(PDB_PROM
, ("psycho debug: got `bus-range' for node %08x: %u - %u\n",
851 node
, brp
[0], brp
[1]));
855 psycho_get_ranges(int node
, struct psycho_ranges
**rp
, int *np
)
858 if (prom_getprop(node
, "ranges", sizeof(**rp
), np
, rp
))
859 panic("could not get psycho ranges");
860 DPRINTF(PDB_PROM
, ("psycho debug: got `ranges' for node %08x: %d entries\n", node
, *np
));
864 * Interrupt handlers.
870 struct psycho_softc
*sc
= (struct psycho_softc
*)arg
;
871 struct psychoreg
*regs
= sc
->sc_regs
;
872 struct iommu_state
*is
= sc
->sc_is
;
873 uint64_t afsr
= regs
->psy_ue_afsr
;
874 uint64_t afar
= regs
->psy_ue_afar
;
875 psize_t size
= PAGE_SIZE
<< is
->is_tsbsize
;
879 * It's uncorrectable. Dump the regs and panic.
881 snprintb(bits
, sizeof(bits
), PSYCHO_UE_AFSR_BITS
, afsr
);
882 aprint_error_dev(&sc
->sc_dev
,
883 "uncorrectable DMA error AFAR %" PRIx64
" AFSR %s\n", afar
, bits
);
885 /* Sometimes the AFAR points to an IOTSB entry */
886 if (afar
>= is
->is_ptsb
&& afar
< is
->is_ptsb
+ size
) {
887 aprint_error_dev(&sc
->sc_dev
,
888 "IOVA %" PRIx64
" IOTTE %" PRIx64
"\n",
889 (afar
- is
->is_ptsb
) / sizeof(is
->is_tsb
[0]) * PAGE_SIZE
890 + is
->is_dvmabase
, ldxa(afar
, ASI_PHYS_CACHED
));
895 regs
->psy_ue_afar
= 0;
896 regs
->psy_ue_afsr
= 0;
903 struct psycho_softc
*sc
= (struct psycho_softc
*)arg
;
904 struct psychoreg
*regs
= sc
->sc_regs
;
907 * It's correctable. Dump the regs and continue.
909 aprint_error_dev(&sc
->sc_dev
,
910 "correctable DMA error AFAR %" PRIx64
" AFSR %" PRIx64
"\n",
911 regs
->psy_ce_afar
, regs
->psy_ce_afsr
);
916 psycho_bus_a(void *arg
)
918 struct psycho_softc
*sc
= (struct psycho_softc
*)arg
;
919 struct psychoreg
*regs
= sc
->sc_regs
;
922 * It's uncorrectable. Dump the regs and panic.
925 panic("%s: PCI bus A error AFAR %" PRIx64
" AFSR %" PRIx64
,
926 device_xname(&sc
->sc_dev
),
927 regs
->psy_pcictl
[0].pci_afar
, regs
->psy_pcictl
[0].pci_afsr
);
932 psycho_bus_b(void *arg
)
934 struct psycho_softc
*sc
= (struct psycho_softc
*)arg
;
935 struct psychoreg
*regs
= sc
->sc_regs
;
938 * It's uncorrectable. Dump the regs and panic.
941 panic("%s: PCI bus B error AFAR %" PRIx64
" AFSR %" PRIx64
,
942 device_xname(&sc
->sc_dev
),
943 regs
->psy_pcictl
[0].pci_afar
, regs
->psy_pcictl
[0].pci_afsr
);
948 psycho_powerfail(void *arg
)
950 struct psycho_softc
*sc
= (struct psycho_softc
*)arg
;
953 * We lost power. Queue a callback with thread context to
954 * handle all the real work.
956 if (sc
->sc_powerpressed
== 0 && sc
->sc_smcontext
!= NULL
) {
957 sc
->sc_powerpressed
= 1;
958 sysmon_task_queue_sched(0, psycho_power_button_pressed
, sc
);
964 int psycho_wakeup(void *arg
)
966 struct psycho_softc
*sc
= (struct psycho_softc
*)arg
;
969 * Gee, we don't really have a framework to deal with this
972 aprint_error_dev(&sc
->sc_dev
, "power management wakeup\n");
978 * initialise the IOMMU..
981 psycho_iommu_init(struct psycho_softc
*sc
, int tsbsize
)
984 struct iommu_state
*is
= sc
->sc_is
;
985 uint32_t iobase
= -1;
989 /* punch in our copies */
990 is
->is_bustag
= sc
->sc_bustag
;
991 bus_space_subregion(sc
->sc_bustag
, sc
->sc_bh
,
992 offsetof(struct psychoreg
, psy_iommu
),
993 sizeof (struct iommureg
),
997 * Separate the men from the boys. Get the `virtual-dma'
998 * property for sabre and use that to make sure the damn
1001 * We could query the `#virtual-dma-size-cells' and
1002 * `#virtual-dma-addr-cells' and DTRT, but I'm lazy.
1005 if (!prom_getprop(sc
->sc_node
, "virtual-dma", sizeof(vdma
), &nitem
,
1007 /* Damn. Gotta use these values. */
1009 #define TSBCASE(x) case 1<<((x)+23): tsbsize = (x); break
1011 TSBCASE(1); TSBCASE(2); TSBCASE(3);
1012 TSBCASE(4); TSBCASE(5); TSBCASE(6);
1014 printf("bogus tsb size %x, using 7\n", vdma
[1]);
1020 /* give us a nice name.. */
1021 name
= (char *)malloc(32, M_DEVBUF
, M_NOWAIT
);
1023 panic("couldn't malloc iommu name");
1024 snprintf(name
, 32, "%s dvma", device_xname(&sc
->sc_dev
));
1026 iommu_init(name
, is
, tsbsize
, iobase
);
1030 * below here is bus space and bus DMA support
1033 psycho_alloc_bus_tag(struct psycho_pbm
*pp
, int type
)
1035 struct psycho_softc
*sc
= pp
->pp_sc
;
1038 bt
= (bus_space_tag_t
) malloc(sizeof(struct sparc_bus_space_tag
),
1039 M_DEVBUF
, M_NOWAIT
| M_ZERO
);
1041 panic("could not allocate psycho bus tag");
1044 bt
->parent
= sc
->sc_bustag
;
1046 bt
->sparc_bus_map
= _psycho_bus_map
;
1047 bt
->sparc_bus_mmap
= psycho_bus_mmap
;
1048 bt
->sparc_intr_establish
= psycho_intr_establish
;
1053 psycho_alloc_dma_tag(struct psycho_pbm
*pp
)
1055 struct psycho_softc
*sc
= pp
->pp_sc
;
1056 bus_dma_tag_t dt
, pdt
= sc
->sc_dmatag
;
1058 dt
= (bus_dma_tag_t
)
1059 malloc(sizeof(struct sparc_bus_dma_tag
), M_DEVBUF
, M_NOWAIT
);
1061 panic("could not allocate psycho DMA tag");
1063 memset(dt
, 0, sizeof *dt
);
1066 #define PCOPY(x) dt->x = pdt->x
1067 dt
->_dmamap_create
= psycho_dmamap_create
;
1068 PCOPY(_dmamap_destroy
);
1069 dt
->_dmamap_load
= iommu_dvmamap_load
;
1070 PCOPY(_dmamap_load_mbuf
);
1071 PCOPY(_dmamap_load_uio
);
1072 dt
->_dmamap_load_raw
= iommu_dvmamap_load_raw
;
1073 dt
->_dmamap_unload
= iommu_dvmamap_unload
;
1074 if (sc
->sc_mode
== PSYCHO_MODE_SABRE
)
1075 dt
->_dmamap_sync
= psycho_sabre_dmamap_sync
;
1077 dt
->_dmamap_sync
= iommu_dvmamap_sync
;
1078 dt
->_dmamem_alloc
= iommu_dvmamem_alloc
;
1079 dt
->_dmamem_free
= iommu_dvmamem_free
;
1080 dt
->_dmamem_map
= iommu_dvmamem_map
;
1081 dt
->_dmamem_unmap
= iommu_dvmamem_unmap
;
1082 PCOPY(_dmamem_mmap
);
1088 * bus space support. <sparc64/dev/psychoreg.h> has a discussion about
1089 * PCI physical addresses.
1092 static struct psycho_ranges
*
1093 get_psychorange(struct psycho_pbm
*pp
, int ss
)
1097 for (i
= 0; i
< pp
->pp_nrange
; i
++) {
1098 if (((pp
->pp_range
[i
].cspace
>> 24) & 0x03) == ss
)
1099 return (&pp
->pp_range
[i
]);
1106 _psycho_bus_map(bus_space_tag_t t
, bus_addr_t offset
, bus_size_t size
,
1107 int flags
, vaddr_t unused
, bus_space_handle_t
*hp
)
1109 struct psycho_pbm
*pp
= t
->cookie
;
1110 struct psycho_softc
*sc
= pp
->pp_sc
;
1111 struct psycho_ranges
*pr
;
1116 ("_psycho_bus_map: type %d off %qx sz %qx flags %d",
1117 t
->type
, (unsigned long long)offset
,
1118 (unsigned long long)size
, flags
));
1120 ss
= sparc_pci_childspace(t
->type
);
1121 DPRINTF(PDB_BUSMAP
, (" cspace %d", ss
));
1123 pr
= get_psychorange(pp
, ss
);
1125 paddr
= BUS_ADDR(pr
->phys_hi
, pr
->phys_lo
+ offset
);
1126 DPRINTF(PDB_BUSMAP
, ("\n_psycho_bus_map: mapping paddr "
1127 "space %lx offset %lx paddr %qx\n",
1128 (long)ss
, (long)offset
,
1129 (unsigned long long)paddr
));
1130 return ((*sc
->sc_bustag
->sparc_bus_map
)(t
, paddr
, size
,
1133 DPRINTF(PDB_BUSMAP
, (" FAILED\n"));
1138 psycho_bus_mmap(bus_space_tag_t t
, bus_addr_t paddr
, off_t off
, int prot
,
1141 bus_addr_t offset
= paddr
;
1142 struct psycho_pbm
*pp
= t
->cookie
;
1143 struct psycho_softc
*sc
= pp
->pp_sc
;
1144 struct psycho_ranges
*pr
;
1147 ss
= sparc_pci_childspace(t
->type
);
1149 DPRINTF(PDB_BUSMAP
, ("_psycho_bus_mmap: prot %x flags %d pa %qx\n",
1150 prot
, flags
, (unsigned long long)paddr
));
1152 pr
= get_psychorange(pp
, ss
);
1154 paddr
= BUS_ADDR(pr
->phys_hi
, pr
->phys_lo
+ offset
);
1155 DPRINTF(PDB_BUSMAP
, ("\n_psycho_bus_mmap: mapping paddr "
1156 "space %lx offset %lx paddr %qx\n",
1157 (long)ss
, (long)offset
,
1158 (unsigned long long)paddr
));
1159 return (bus_space_mmap(sc
->sc_bustag
, paddr
, off
,
1167 * Get a PCI offset address from bus_space_handle_t.
1170 psycho_bus_offset(bus_space_tag_t t
, bus_space_handle_t
*hp
)
1172 struct psycho_pbm
*pp
= t
->cookie
;
1173 struct psycho_ranges
*pr
;
1174 bus_addr_t addr
, offset
;
1179 ss
= sparc_pci_childspace(t
->type
);
1180 DPRINTF(PDB_BUSMAP
, ("psycho_bus_offset: type %d addr %" PRIx64
1181 " cspace %d", t
->type
, addr
, ss
));
1183 pr
= get_psychorange(pp
, ss
);
1185 if (!PHYS_ASI(hp
->_asi
)) {
1186 va
= trunc_page((vaddr_t
)addr
);
1187 if (pmap_extract(pmap_kernel(), va
, &addr
) == FALSE
) {
1189 ("\n pmap_extract FAILED\n"));
1192 addr
+= hp
->_ptr
& PGOFSET
;
1194 offset
= BUS_ADDR_PADDR(addr
) - pr
->phys_lo
;
1195 DPRINTF(PDB_BUSMAP
, ("\npsycho_bus_offset: paddr %" PRIx64
1196 " offset %" PRIx64
"\n", addr
, offset
));
1199 DPRINTF(PDB_BUSMAP
, ("\n FAILED\n"));
1205 * install an interrupt handler for a PCI device
1208 psycho_intr_establish(bus_space_tag_t t
, int ihandle
, int level
,
1209 int (*handler
)(void *), void *arg
, void (*fastvec
)(void) /* ignored */)
1211 struct psycho_pbm
*pp
= t
->cookie
;
1212 struct psycho_softc
*sc
= pp
->pp_sc
;
1213 struct intrhand
*ih
;
1214 volatile uint64_t *intrmapptr
= NULL
, *intrclrptr
= NULL
;
1217 long vec
= INTVEC(ihandle
);
1219 ih
= (struct intrhand
*)
1220 malloc(sizeof(struct intrhand
), M_DEVBUF
, M_NOWAIT
);
1225 * Hunt through all the interrupt mapping regs to look for our
1228 * XXX We only compare INOs rather than IGNs since the firmware may
1229 * not provide the IGN and the IGN is constant for all device on that
1230 * PCI controller. This could cause problems for the FFB/external
1231 * interrupt which has a full vector that can be set arbitrarily.
1234 DPRINTF(PDB_INTR
, ("\npsycho_intr_establish: ihandle %x vec %lx", ihandle
, vec
));
1236 DPRINTF(PDB_INTR
, (" ino %x", ino
));
1238 /* If the device didn't ask for an IPL, use the one encoded. */
1239 if (level
== IPL_NONE
) level
= INTLEV(vec
);
1240 /* If it still has no level, print a warning and assign IPL 2 */
1241 if (level
== IPL_NONE
) {
1242 printf("ERROR: no IPL, setting IPL 2.\n");
1246 DPRINTF(PDB_INTR
, ("\npsycho: intr %lx: %p\nHunting for IRQ...\n",
1247 (long)ino
, intrlev
[ino
]));
1250 * First look for PCI interrupts, otherwise the PCI A slot 0
1251 * INTA# interrupt might match an unused non-PCI (obio)
1254 for (intrmapptr
= &sc
->sc_regs
->pcia_slot0_int
,
1255 intrclrptr
= &sc
->sc_regs
->pcia0_clr_int
[0];
1256 intrmapptr
<= &sc
->sc_regs
->pcib_slot3_int
;
1257 intrmapptr
++, intrclrptr
+= 4) {
1258 if (sc
->sc_mode
== PSYCHO_MODE_PSYCHO
&&
1259 (intrmapptr
== &sc
->sc_regs
->pcia_slot2_int
||
1260 intrmapptr
== &sc
->sc_regs
->pcia_slot3_int
))
1262 if (((*intrmapptr
^ vec
) & 0x3c) == 0) {
1263 intrclrptr
+= vec
& 0x3;
1268 /* Now hunt thru obio. */
1269 for (intrmapptr
= &sc
->sc_regs
->scsi_int_map
,
1270 intrclrptr
= &sc
->sc_regs
->scsi_clr_int
;
1271 intrmapptr
< &sc
->sc_regs
->ue_int_map
;
1272 intrmapptr
++, intrclrptr
++) {
1273 if (INTINO(*intrmapptr
) == ino
)
1277 /* Finally check the two FFB slots */
1278 intrclrptr
= NULL
; /* XXX? */
1279 for (intrmapptr
= &sc
->sc_regs
->ffb0_int_map
;
1280 intrmapptr
<= &sc
->sc_regs
->ffb1_int_map
;
1282 if (INTVEC(*intrmapptr
) == ino
)
1286 printf("Cannot find interrupt vector %lx\n", vec
);
1290 /* Register the map and clear intr registers */
1291 ih
->ih_map
= intrmapptr
;
1292 ih
->ih_clr
= intrclrptr
;
1294 ih
->ih_fun
= handler
;
1297 ih
->ih_number
= ino
| sc
->sc_ign
;
1300 "; installing handler %p arg %p with ino %u pil %u\n",
1301 handler
, arg
, (u_int
)ino
, (u_int
)ih
->ih_pil
));
1303 intr_establish(ih
->ih_pil
, level
!= IPL_VM
, ih
);
1306 * Enable the interrupt now we have the handler installed.
1307 * Read the current value as we can't change it besides the
1308 * valid bit so so make sure only this bit is changed.
1310 * XXXX --- we really should use bus_space for this.
1314 DPRINTF(PDB_INTR
, ("; read intrmap = %016qx",
1315 (unsigned long long)imap
));
1317 /* Enable the interrupt */
1318 imap
|= INTMAP_V
|(CPU_UPAID
<< INTMAP_TID_SHIFT
);
1319 DPRINTF(PDB_INTR
, ("; addr of intrmapptr = %p", intrmapptr
));
1320 DPRINTF(PDB_INTR
, ("; writing intrmap = %016qx\n",
1321 (unsigned long long)imap
));
1323 DPRINTF(PDB_INTR
, ("; reread intrmap = %016qx",
1324 (unsigned long long)(imap
= *intrmapptr
)));
1327 /* set state to IDLE */
1334 * per-controller driver calls
1337 /* assume we are mapped little-endian/side-effect */
1339 psycho_pci_conf_read(pci_chipset_tag_t pc
, pcitag_t tag
, int reg
)
1341 struct psycho_pbm
*pp
= pc
->cookie
;
1342 struct psycho_softc
*sc
= pp
->pp_sc
;
1343 pcireg_t val
= (pcireg_t
)~0;
1345 DPRINTF(PDB_CONF
, ("%s: tag %lx reg %x ", __func__
,
1347 if (PCITAG_NODE(tag
) != -1) {
1349 DPRINTF(PDB_CONF
, ("asi=%x addr=%qx (offset=%x) ...",
1350 sc
->sc_configaddr
._asi
,
1351 (long long)(sc
->sc_configaddr
._ptr
+
1352 PCITAG_OFFSET(tag
) + reg
),
1353 (int)PCITAG_OFFSET(tag
) + reg
));
1355 val
= bus_space_read_4(sc
->sc_configtag
, sc
->sc_configaddr
,
1356 PCITAG_OFFSET(tag
) + reg
);
1359 else DPRINTF(PDB_CONF
, ("%s: bogus pcitag %x\n", __func__
,
1360 (int)PCITAG_OFFSET(tag
)));
1362 DPRINTF(PDB_CONF
, (" returning %08x\n", (u_int
)val
));
1368 psycho_pci_conf_write(pci_chipset_tag_t pc
, pcitag_t tag
, int reg
, pcireg_t data
)
1370 struct psycho_pbm
*pp
= pc
->cookie
;
1371 struct psycho_softc
*sc
= pp
->pp_sc
;
1373 DPRINTF(PDB_CONF
, ("%s: tag %lx; reg %x; data %x; ", __func__
,
1374 (long)PCITAG_OFFSET(tag
), reg
, (int)data
));
1375 DPRINTF(PDB_CONF
, ("asi = %x; readaddr = %qx (offset = %x)\n",
1376 sc
->sc_configaddr
._asi
,
1377 (long long)(sc
->sc_configaddr
._ptr
+ PCITAG_OFFSET(tag
) + reg
),
1378 (int)PCITAG_OFFSET(tag
) + reg
));
1380 /* If we don't know it, just punt it. */
1381 if (PCITAG_NODE(tag
) == -1) {
1382 DPRINTF(PDB_CONF
, ("%s: bad addr", __func__
));
1386 bus_space_write_4(sc
->sc_configtag
, sc
->sc_configaddr
,
1387 PCITAG_OFFSET(tag
) + reg
, data
);
1391 psycho_pci_intr_establish(pci_chipset_tag_t pc
, pci_intr_handle_t ih
, int level
,
1392 int (*func
)(void *), void *arg
)
1395 struct psycho_pbm
*pp
= (struct psycho_pbm
*)pc
->cookie
;
1397 DPRINTF(PDB_INTR
, ("%s: ih %lx; level %d", __func__
, (u_long
)ih
, level
));
1398 cookie
= bus_intr_establish(pp
->pp_memt
, ih
, level
, func
, arg
);
1400 DPRINTF(PDB_INTR
, ("; returning handle %p\n", cookie
));
1405 psycho_pci_find_ino(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
1407 struct psycho_pbm
*pp
= pa
->pa_pc
->cookie
;
1408 struct psycho_softc
*sc
= pp
->pp_sc
;
1413 DPRINTF(PDB_INTMAP
, ("%s: pa_tag: node %x, %d:%d:%d\n", __func__
,
1414 PCITAG_NODE(pa
->pa_tag
), (int)PCITAG_BUS(pa
->pa_tag
),
1415 (int)PCITAG_DEV(pa
->pa_tag
),
1416 (int)PCITAG_FUN(pa
->pa_tag
)));
1418 ("%s: intrswiz %d, intrpin %d, intrline %d, rawintrpin %d\n", __func__
,
1419 pa
->pa_intrswiz
, pa
->pa_intrpin
, pa
->pa_intrline
, pa
->pa_rawintrpin
));
1420 DPRINTF(PDB_INTMAP
, ("%s: pa_intrtag: node %x, %d:%d:%d\n", __func__
,
1421 PCITAG_NODE(pa
->pa_intrtag
),
1422 (int)PCITAG_BUS(pa
->pa_intrtag
),
1423 (int)PCITAG_DEV(pa
->pa_intrtag
),
1424 (int)PCITAG_FUN(pa
->pa_intrtag
)));
1426 bus
= (pp
->pp_id
== PSYCHO_PBM_B
);
1428 * If we are on a ppb, use the devno on the underlying bus when forming
1431 if (pa
->pa_intrswiz
!= 0 && PCITAG_NODE(pa
->pa_intrtag
) != 0)
1432 dev
= PCITAG_DEV(pa
->pa_intrtag
);
1434 dev
= pa
->pa_device
;
1437 if (sc
->sc_mode
== PSYCHO_MODE_PSYCHO
&&
1438 pp
->pp_id
== PSYCHO_PBM_B
)
1441 pin
= pa
->pa_intrpin
- 1;
1442 DPRINTF(PDB_INTMAP
, ("%s: mode %d, pbm %d, dev %d, pin %d\n", __func__
,
1443 sc
->sc_mode
, pp
->pp_id
, dev
, pin
));
1445 *ihp
= sc
->sc_ign
| ((bus
<< 4) & INTMAP_PCIBUS
) |
1446 ((dev
<< 2) & INTMAP_PCISLOT
) | (pin
& INTMAP_PCIINT
);
1452 * hooks into the iommu dvma calls.
1455 psycho_dmamap_create(bus_dma_tag_t t
, bus_size_t size
, int nsegments
,
1456 bus_size_t maxsegsz
, bus_size_t boundary
, int flags
,
1457 bus_dmamap_t
*dmamp
)
1459 struct psycho_pbm
*pp
= (struct psycho_pbm
*)t
->_cookie
;
1462 error
= bus_dmamap_create(t
->_parent
, size
, nsegments
, maxsegsz
,
1463 boundary
, flags
, dmamp
);
1465 (*dmamp
)->_dm_cookie
= &pp
->pp_sb
;
1470 * UltraSPARC IIi and IIe have no streaming buffers, but have PCI DMA
1471 * Write Synchronization Register (see UltraSPARC-IIi User's Manual
1472 * section 19.3.0.5). So use it to synchronize with the DMA writes.
1475 psycho_sabre_dmamap_sync(bus_dma_tag_t t
, bus_dmamap_t map
, bus_addr_t offset
,
1476 bus_size_t len
, int ops
)
1478 struct psycho_pbm
*pp
= (struct psycho_pbm
*)t
->_cookie
;
1479 struct psycho_softc
*sc
= pp
->pp_sc
;
1481 if (ops
& BUS_DMASYNC_POSTREAD
)
1482 bus_space_read_8(sc
->sc_bustag
, sc
->sc_bh
,
1483 offsetof(struct psychoreg
, pci_dma_write_sync
));
1484 bus_dmamap_sync(t
->_parent
, map
, offset
, len
, ops
);