2 * QEMU Ultrasparc APB PCI host
4 * Copyright (c) 2006 Fabrice Bellard
5 * Copyright (c) 2012,2013 Artyom Tarasenko
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 /* XXX This file and most of its contents are somewhat misnamed. The
27 Ultrasparc PCI host is called the PCI Bus Module (PBM). The APB is
28 the secondary PCI bridge. */
30 #include "hw/sysbus.h"
31 #include "hw/pci/pci.h"
32 #include "hw/pci/pci_host.h"
33 #include "hw/pci/pci_bridge.h"
34 #include "hw/pci/pci_bus.h"
35 #include "hw/pci-host/apb.h"
36 #include "sysemu/sysemu.h"
37 #include "exec/address-spaces.h"
43 #define APB_DPRINTF(fmt, ...) \
44 do { printf("APB: " fmt , ## __VA_ARGS__); } while (0)
46 #define APB_DPRINTF(fmt, ...)
53 #define IOMMU_DPRINTF(fmt, ...) \
54 do { printf("IOMMU: " fmt , ## __VA_ARGS__); } while (0)
56 #define IOMMU_DPRINTF(fmt, ...)
61 * PBM: "UltraSPARC IIi User's Manual",
62 * http://www.sun.com/processors/manuals/805-0087.pdf
64 * APB: "Advanced PCI Bridge (APB) User's Manual",
65 * http://www.sun.com/processors/manuals/805-1251.pdf
68 #define PBM_PCI_IMR_MASK 0x7fffffff
69 #define PBM_PCI_IMR_ENABLED 0x80000000
71 #define POR (1U << 31)
72 #define SOFT_POR (1U << 30)
73 #define SOFT_XIR (1U << 29)
74 #define BTN_POR (1U << 28)
75 #define BTN_XIR (1U << 27)
76 #define RESET_MASK 0xf8000000
77 #define RESET_WCMASK 0x98000000
78 #define RESET_WMASK 0x60000000
81 #define NO_IRQ_REQUEST (MAX_IVEC + 1)
83 #define IOMMU_PAGE_SIZE_8K (1ULL << 13)
84 #define IOMMU_PAGE_MASK_8K (~(IOMMU_PAGE_SIZE_8K - 1))
85 #define IOMMU_PAGE_SIZE_64K (1ULL << 16)
86 #define IOMMU_PAGE_MASK_64K (~(IOMMU_PAGE_SIZE_64K - 1))
90 #define IOMMU_CTRL 0x0
91 #define IOMMU_CTRL_TBW_SIZE (1ULL << 2)
92 #define IOMMU_CTRL_MMU_EN (1ULL)
94 #define IOMMU_CTRL_TSB_SHIFT 16
96 #define IOMMU_BASE 0x8
97 #define IOMMU_FLUSH 0x10
99 #define IOMMU_TTE_DATA_V (1ULL << 63)
100 #define IOMMU_TTE_DATA_SIZE (1ULL << 61)
101 #define IOMMU_TTE_DATA_W (1ULL << 1)
103 #define IOMMU_TTE_PHYS_MASK_8K 0x1ffffffe000ULL
104 #define IOMMU_TTE_PHYS_MASK_64K 0x1ffffff8000ULL
106 #define IOMMU_TSB_8K_OFFSET_MASK_8M 0x00000000007fe000ULL
107 #define IOMMU_TSB_8K_OFFSET_MASK_16M 0x0000000000ffe000ULL
108 #define IOMMU_TSB_8K_OFFSET_MASK_32M 0x0000000001ffe000ULL
109 #define IOMMU_TSB_8K_OFFSET_MASK_64M 0x0000000003ffe000ULL
110 #define IOMMU_TSB_8K_OFFSET_MASK_128M 0x0000000007ffe000ULL
111 #define IOMMU_TSB_8K_OFFSET_MASK_256M 0x000000000fffe000ULL
112 #define IOMMU_TSB_8K_OFFSET_MASK_512M 0x000000001fffe000ULL
113 #define IOMMU_TSB_8K_OFFSET_MASK_1G 0x000000003fffe000ULL
115 #define IOMMU_TSB_64K_OFFSET_MASK_64M 0x0000000003ff0000ULL
116 #define IOMMU_TSB_64K_OFFSET_MASK_128M 0x0000000007ff0000ULL
117 #define IOMMU_TSB_64K_OFFSET_MASK_256M 0x000000000fff0000ULL
118 #define IOMMU_TSB_64K_OFFSET_MASK_512M 0x000000001fff0000ULL
119 #define IOMMU_TSB_64K_OFFSET_MASK_1G 0x000000003fff0000ULL
120 #define IOMMU_TSB_64K_OFFSET_MASK_2G 0x000000007fff0000ULL
122 typedef struct IOMMUState
{
123 AddressSpace iommu_as
;
126 uint64_t regs
[IOMMU_NREGS
];
129 #define TYPE_APB "pbm"
131 #define APB_DEVICE(obj) \
132 OBJECT_CHECK(APBState, (obj), TYPE_APB)
134 typedef struct APBState
{
135 PCIHostState parent_obj
;
137 MemoryRegion apb_config
;
138 MemoryRegion pci_config
;
139 MemoryRegion pci_mmio
;
140 MemoryRegion pci_ioport
;
143 uint32_t pci_control
[16];
144 uint32_t pci_irq_map
[8];
145 uint32_t pci_err_irq_map
[4];
146 uint32_t obio_irq_map
[32];
149 unsigned int irq_request
;
150 uint32_t reset_control
;
151 unsigned int nr_resets
;
154 static inline void pbm_set_request(APBState
*s
, unsigned int irq_num
)
156 APB_DPRINTF("%s: request irq %d\n", __func__
, irq_num
);
158 s
->irq_request
= irq_num
;
159 qemu_set_irq(s
->ivec_irqs
[irq_num
], 1);
162 static inline void pbm_check_irqs(APBState
*s
)
167 /* Previous request is not acknowledged, resubmit */
168 if (s
->irq_request
!= NO_IRQ_REQUEST
) {
169 pbm_set_request(s
, s
->irq_request
);
172 /* no request pending */
173 if (s
->pci_irq_in
== 0ULL) {
176 for (i
= 0; i
< 32; i
++) {
177 if (s
->pci_irq_in
& (1ULL << i
)) {
178 if (s
->pci_irq_map
[i
>> 2] & PBM_PCI_IMR_ENABLED
) {
179 pbm_set_request(s
, i
);
184 for (i
= 32; i
< 64; i
++) {
185 if (s
->pci_irq_in
& (1ULL << i
)) {
186 if (s
->obio_irq_map
[i
- 32] & PBM_PCI_IMR_ENABLED
) {
187 pbm_set_request(s
, i
);
194 static inline void pbm_clear_request(APBState
*s
, unsigned int irq_num
)
196 APB_DPRINTF("%s: clear request irq %d\n", __func__
, irq_num
);
197 qemu_set_irq(s
->ivec_irqs
[irq_num
], 0);
198 s
->irq_request
= NO_IRQ_REQUEST
;
201 static AddressSpace
*pbm_pci_dma_iommu(PCIBus
*bus
, void *opaque
, int devfn
)
203 IOMMUState
*is
= opaque
;
205 return &is
->iommu_as
;
208 static IOMMUTLBEntry
pbm_translate_iommu(MemoryRegion
*iommu
, hwaddr addr
,
211 IOMMUState
*is
= container_of(iommu
, IOMMUState
, iommu
);
212 hwaddr baseaddr
, offset
;
215 IOMMUTLBEntry ret
= {
216 .target_as
= &address_space_memory
,
218 .translated_addr
= 0,
219 .addr_mask
= ~(hwaddr
)0,
223 if (!(is
->regs
[IOMMU_CTRL
>> 3] & IOMMU_CTRL_MMU_EN
)) {
224 /* IOMMU disabled, passthrough using standard 8K page */
225 ret
.iova
= addr
& IOMMU_PAGE_MASK_8K
;
226 ret
.translated_addr
= addr
;
227 ret
.addr_mask
= IOMMU_PAGE_MASK_8K
;
233 baseaddr
= is
->regs
[IOMMU_BASE
>> 3];
234 tsbsize
= (is
->regs
[IOMMU_CTRL
>> 3] >> IOMMU_CTRL_TSB_SHIFT
) & 0x7;
236 if (is
->regs
[IOMMU_CTRL
>> 3] & IOMMU_CTRL_TBW_SIZE
) {
240 offset
= (addr
& IOMMU_TSB_64K_OFFSET_MASK_64M
) >> 13;
243 offset
= (addr
& IOMMU_TSB_64K_OFFSET_MASK_128M
) >> 13;
246 offset
= (addr
& IOMMU_TSB_64K_OFFSET_MASK_256M
) >> 13;
249 offset
= (addr
& IOMMU_TSB_64K_OFFSET_MASK_512M
) >> 13;
252 offset
= (addr
& IOMMU_TSB_64K_OFFSET_MASK_1G
) >> 13;
255 offset
= (addr
& IOMMU_TSB_64K_OFFSET_MASK_2G
) >> 13;
258 /* Not implemented, error */
265 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_8M
) >> 10;
268 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_16M
) >> 10;
271 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_32M
) >> 10;
274 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_64M
) >> 10;
277 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_128M
) >> 10;
280 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_256M
) >> 10;
283 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_512M
) >> 10;
286 offset
= (addr
& IOMMU_TSB_8K_OFFSET_MASK_1G
) >> 10;
291 tte
= ldq_be_phys(&address_space_memory
, baseaddr
+ offset
);
293 if (!(tte
& IOMMU_TTE_DATA_V
)) {
294 /* Invalid mapping */
298 if (tte
& IOMMU_TTE_DATA_W
) {
306 if (tte
& IOMMU_TTE_DATA_SIZE
) {
308 ret
.iova
= addr
& IOMMU_PAGE_MASK_64K
;
309 ret
.translated_addr
= tte
& IOMMU_TTE_PHYS_MASK_64K
;
310 ret
.addr_mask
= (IOMMU_PAGE_SIZE_64K
- 1);
313 ret
.iova
= addr
& IOMMU_PAGE_MASK_8K
;
314 ret
.translated_addr
= tte
& IOMMU_TTE_PHYS_MASK_8K
;
315 ret
.addr_mask
= (IOMMU_PAGE_SIZE_8K
- 1);
321 static MemoryRegionIOMMUOps pbm_iommu_ops
= {
322 .translate
= pbm_translate_iommu
,
325 static void iommu_config_write(void *opaque
, hwaddr addr
,
326 uint64_t val
, unsigned size
)
328 IOMMUState
*is
= opaque
;
330 IOMMU_DPRINTF("IOMMU config write: 0x%" HWADDR_PRIx
" val: %" PRIx64
331 " size: %d\n", addr
, val
, size
);
336 is
->regs
[IOMMU_CTRL
>> 3] &= 0xffffffffULL
;
337 is
->regs
[IOMMU_CTRL
>> 3] |= val
<< 32;
339 is
->regs
[IOMMU_CTRL
>> 3] = val
;
342 case IOMMU_CTRL
+ 0x4:
343 is
->regs
[IOMMU_CTRL
>> 3] &= 0xffffffff00000000ULL
;
344 is
->regs
[IOMMU_CTRL
>> 3] |= val
& 0xffffffffULL
;
348 is
->regs
[IOMMU_BASE
>> 3] &= 0xffffffffULL
;
349 is
->regs
[IOMMU_BASE
>> 3] |= val
<< 32;
351 is
->regs
[IOMMU_BASE
>> 3] = val
;
354 case IOMMU_BASE
+ 0x4:
355 is
->regs
[IOMMU_BASE
>> 3] &= 0xffffffff00000000ULL
;
356 is
->regs
[IOMMU_BASE
>> 3] |= val
& 0xffffffffULL
;
359 case IOMMU_FLUSH
+ 0x4:
362 qemu_log_mask(LOG_UNIMP
,
363 "apb iommu: Unimplemented register write "
364 "reg 0x%" HWADDR_PRIx
" size 0x%x value 0x%" PRIx64
"\n",
370 static uint64_t iommu_config_read(void *opaque
, hwaddr addr
, unsigned size
)
372 IOMMUState
*is
= opaque
;
378 val
= is
->regs
[IOMMU_CTRL
>> 3] >> 32;
380 val
= is
->regs
[IOMMU_CTRL
>> 3];
383 case IOMMU_CTRL
+ 0x4:
384 val
= is
->regs
[IOMMU_CTRL
>> 3] & 0xffffffffULL
;
388 val
= is
->regs
[IOMMU_BASE
>> 3] >> 32;
390 val
= is
->regs
[IOMMU_BASE
>> 3];
393 case IOMMU_BASE
+ 0x4:
394 val
= is
->regs
[IOMMU_BASE
>> 3] & 0xffffffffULL
;
397 case IOMMU_FLUSH
+ 0x4:
401 qemu_log_mask(LOG_UNIMP
,
402 "apb iommu: Unimplemented register read "
403 "reg 0x%" HWADDR_PRIx
" size 0x%x\n",
409 IOMMU_DPRINTF("IOMMU config read: 0x%" HWADDR_PRIx
" val: %" PRIx64
410 " size: %d\n", addr
, val
, size
);
415 static void apb_config_writel (void *opaque
, hwaddr addr
,
416 uint64_t val
, unsigned size
)
418 APBState
*s
= opaque
;
419 IOMMUState
*is
= &s
->iommu
;
421 APB_DPRINTF("%s: addr " TARGET_FMT_plx
" val %" PRIx64
"\n", __func__
, addr
, val
);
423 switch (addr
& 0xffff) {
424 case 0x30 ... 0x4f: /* DMA error registers */
425 /* XXX: not implemented yet */
427 case 0x200 ... 0x217: /* IOMMU */
428 iommu_config_write(is
, (addr
& 0x1f), val
, size
);
430 case 0xc00 ... 0xc3f: /* PCI interrupt control */
432 unsigned int ino
= (addr
& 0x3f) >> 3;
433 s
->pci_irq_map
[ino
] &= PBM_PCI_IMR_MASK
;
434 s
->pci_irq_map
[ino
] |= val
& ~PBM_PCI_IMR_MASK
;
435 if ((s
->irq_request
== ino
) && !(val
& ~PBM_PCI_IMR_MASK
)) {
436 pbm_clear_request(s
, ino
);
441 case 0x1000 ... 0x107f: /* OBIO interrupt control */
443 unsigned int ino
= ((addr
& 0xff) >> 3);
444 s
->obio_irq_map
[ino
] &= PBM_PCI_IMR_MASK
;
445 s
->obio_irq_map
[ino
] |= val
& ~PBM_PCI_IMR_MASK
;
446 if ((s
->irq_request
== (ino
| 0x20))
447 && !(val
& ~PBM_PCI_IMR_MASK
)) {
448 pbm_clear_request(s
, ino
| 0x20);
453 case 0x1400 ... 0x14ff: /* PCI interrupt clear */
455 unsigned int ino
= (addr
& 0xff) >> 5;
456 if ((s
->irq_request
/ 4) == ino
) {
457 pbm_clear_request(s
, s
->irq_request
);
462 case 0x1800 ... 0x1860: /* OBIO interrupt clear */
464 unsigned int ino
= ((addr
& 0xff) >> 3) | 0x20;
465 if (s
->irq_request
== ino
) {
466 pbm_clear_request(s
, ino
);
471 case 0x2000 ... 0x202f: /* PCI control */
472 s
->pci_control
[(addr
& 0x3f) >> 2] = val
;
474 case 0xf020 ... 0xf027: /* Reset control */
477 s
->reset_control
&= ~(val
& RESET_WCMASK
);
478 s
->reset_control
|= val
& RESET_WMASK
;
479 if (val
& SOFT_POR
) {
481 qemu_system_reset_request();
482 } else if (val
& SOFT_XIR
) {
483 qemu_system_reset_request();
487 case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */
488 case 0xa400 ... 0xa67f: /* IOMMU diagnostics */
489 case 0xa800 ... 0xa80f: /* Interrupt diagnostics */
490 case 0xf000 ... 0xf01f: /* FFB config, memory control */
497 static uint64_t apb_config_readl (void *opaque
,
498 hwaddr addr
, unsigned size
)
500 APBState
*s
= opaque
;
501 IOMMUState
*is
= &s
->iommu
;
504 switch (addr
& 0xffff) {
505 case 0x30 ... 0x4f: /* DMA error registers */
507 /* XXX: not implemented yet */
509 case 0x200 ... 0x217: /* IOMMU */
510 val
= iommu_config_read(is
, (addr
& 0x1f), size
);
512 case 0xc00 ... 0xc3f: /* PCI interrupt control */
514 val
= s
->pci_irq_map
[(addr
& 0x3f) >> 3];
519 case 0x1000 ... 0x107f: /* OBIO interrupt control */
521 val
= s
->obio_irq_map
[(addr
& 0xff) >> 3];
526 case 0x1080 ... 0x108f: /* PCI bus error */
528 val
= s
->pci_err_irq_map
[(addr
& 0xf) >> 3];
533 case 0x2000 ... 0x202f: /* PCI control */
534 val
= s
->pci_control
[(addr
& 0x3f) >> 2];
536 case 0xf020 ... 0xf027: /* Reset control */
538 val
= s
->reset_control
;
543 case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */
544 case 0xa400 ... 0xa67f: /* IOMMU diagnostics */
545 case 0xa800 ... 0xa80f: /* Interrupt diagnostics */
546 case 0xf000 ... 0xf01f: /* FFB config, memory control */
552 APB_DPRINTF("%s: addr " TARGET_FMT_plx
" -> %x\n", __func__
, addr
, val
);
557 static const MemoryRegionOps apb_config_ops
= {
558 .read
= apb_config_readl
,
559 .write
= apb_config_writel
,
560 .endianness
= DEVICE_NATIVE_ENDIAN
,
563 static void apb_pci_config_write(void *opaque
, hwaddr addr
,
564 uint64_t val
, unsigned size
)
566 APBState
*s
= opaque
;
567 PCIHostState
*phb
= PCI_HOST_BRIDGE(s
);
569 val
= qemu_bswap_len(val
, size
);
570 APB_DPRINTF("%s: addr " TARGET_FMT_plx
" val %" PRIx64
"\n", __func__
, addr
, val
);
571 pci_data_write(phb
->bus
, addr
, val
, size
);
574 static uint64_t apb_pci_config_read(void *opaque
, hwaddr addr
,
578 APBState
*s
= opaque
;
579 PCIHostState
*phb
= PCI_HOST_BRIDGE(s
);
581 ret
= pci_data_read(phb
->bus
, addr
, size
);
582 ret
= qemu_bswap_len(ret
, size
);
583 APB_DPRINTF("%s: addr " TARGET_FMT_plx
" -> %x\n", __func__
, addr
, ret
);
587 /* The APB host has an IRQ line for each IRQ line of each slot. */
588 static int pci_apb_map_irq(PCIDevice
*pci_dev
, int irq_num
)
590 return ((pci_dev
->devfn
& 0x18) >> 1) + irq_num
;
593 static int pci_pbm_map_irq(PCIDevice
*pci_dev
, int irq_num
)
596 if (pci_dev
->devfn
& 1)
600 return (bus_offset
+ (PCI_SLOT(pci_dev
->devfn
) << 2) + irq_num
) & 0x1f;
603 static void pci_apb_set_irq(void *opaque
, int irq_num
, int level
)
605 APBState
*s
= opaque
;
607 APB_DPRINTF("%s: set irq_in %d level %d\n", __func__
, irq_num
, level
);
608 /* PCI IRQ map onto the first 32 INO. */
611 s
->pci_irq_in
|= 1ULL << irq_num
;
612 if (s
->pci_irq_map
[irq_num
>> 2] & PBM_PCI_IMR_ENABLED
) {
613 pbm_set_request(s
, irq_num
);
616 s
->pci_irq_in
&= ~(1ULL << irq_num
);
619 /* OBIO IRQ map onto the next 32 INO. */
621 APB_DPRINTF("%s: set irq %d level %d\n", __func__
, irq_num
, level
);
622 s
->pci_irq_in
|= 1ULL << irq_num
;
623 if ((s
->irq_request
== NO_IRQ_REQUEST
)
624 && (s
->obio_irq_map
[irq_num
- 32] & PBM_PCI_IMR_ENABLED
)) {
625 pbm_set_request(s
, irq_num
);
628 s
->pci_irq_in
&= ~(1ULL << irq_num
);
633 static int apb_pci_bridge_initfn(PCIDevice
*dev
)
637 rc
= pci_bridge_initfn(dev
, TYPE_PCI_BUS
);
644 * According to PCI bridge spec, after reset
645 * bus master bit is off
646 * memory space enable bit is off
647 * According to manual (805-1251.pdf).
648 * the reset value should be zero unless the boot pin is tied high
649 * (which is true) and thus it should be PCI_COMMAND_MEMORY.
651 pci_set_word(dev
->config
+ PCI_COMMAND
,
653 pci_set_word(dev
->config
+ PCI_STATUS
,
654 PCI_STATUS_FAST_BACK
| PCI_STATUS_66MHZ
|
655 PCI_STATUS_DEVSEL_MEDIUM
);
659 PCIBus
*pci_apb_init(hwaddr special_base
,
661 qemu_irq
*ivec_irqs
, PCIBus
**bus2
, PCIBus
**bus3
,
672 /* Ultrasparc PBM main bus */
673 dev
= qdev_create(NULL
, TYPE_APB
);
674 qdev_init_nofail(dev
);
675 s
= SYS_BUS_DEVICE(dev
);
677 sysbus_mmio_map(s
, 0, special_base
);
678 /* PCI configuration space */
679 sysbus_mmio_map(s
, 1, special_base
+ 0x1000000ULL
);
681 sysbus_mmio_map(s
, 2, special_base
+ 0x2000000ULL
);
684 memory_region_init(&d
->pci_mmio
, OBJECT(s
), "pci-mmio", 0x100000000ULL
);
685 memory_region_add_subregion(get_system_memory(), mem_base
, &d
->pci_mmio
);
687 phb
= PCI_HOST_BRIDGE(dev
);
688 phb
->bus
= pci_register_bus(DEVICE(phb
), "pci",
689 pci_apb_set_irq
, pci_pbm_map_irq
, d
,
692 0, 32, TYPE_PCI_BUS
);
694 *pbm_irqs
= d
->pbm_irqs
;
695 d
->ivec_irqs
= ivec_irqs
;
697 pci_create_simple(phb
->bus
, 0, "pbm-pci");
701 memset(is
, 0, sizeof(IOMMUState
));
703 memory_region_init_iommu(&is
->iommu
, OBJECT(dev
), &pbm_iommu_ops
,
704 "iommu-apb", UINT64_MAX
);
705 address_space_init(&is
->iommu_as
, &is
->iommu
, "pbm-as");
706 pci_setup_iommu(phb
->bus
, pbm_pci_dma_iommu
, is
);
708 /* APB secondary busses */
709 pci_dev
= pci_create_multifunction(phb
->bus
, PCI_DEVFN(1, 0), true,
711 br
= PCI_BRIDGE(pci_dev
);
712 pci_bridge_map_irq(br
, "Advanced PCI Bus secondary bridge 1",
714 qdev_init_nofail(&pci_dev
->qdev
);
715 *bus2
= pci_bridge_get_sec_bus(br
);
717 pci_dev
= pci_create_multifunction(phb
->bus
, PCI_DEVFN(1, 1), true,
719 br
= PCI_BRIDGE(pci_dev
);
720 pci_bridge_map_irq(br
, "Advanced PCI Bus secondary bridge 2",
722 qdev_init_nofail(&pci_dev
->qdev
);
723 *bus3
= pci_bridge_get_sec_bus(br
);
728 static void pci_pbm_reset(DeviceState
*d
)
731 APBState
*s
= APB_DEVICE(d
);
733 for (i
= 0; i
< 8; i
++) {
734 s
->pci_irq_map
[i
] &= PBM_PCI_IMR_MASK
;
736 for (i
= 0; i
< 32; i
++) {
737 s
->obio_irq_map
[i
] &= PBM_PCI_IMR_MASK
;
740 s
->irq_request
= NO_IRQ_REQUEST
;
741 s
->pci_irq_in
= 0ULL;
743 if (s
->nr_resets
++ == 0) {
745 s
->reset_control
= POR
;
749 static const MemoryRegionOps pci_config_ops
= {
750 .read
= apb_pci_config_read
,
751 .write
= apb_pci_config_write
,
752 .endianness
= DEVICE_NATIVE_ENDIAN
,
755 static int pci_pbm_init_device(SysBusDevice
*dev
)
761 for (i
= 0; i
< 8; i
++) {
762 s
->pci_irq_map
[i
] = (0x1f << 6) | (i
<< 2);
764 for (i
= 0; i
< 2; i
++) {
765 s
->pci_err_irq_map
[i
] = (0x1f << 6) | 0x30;
767 for (i
= 0; i
< 32; i
++) {
768 s
->obio_irq_map
[i
] = ((0x1f << 6) | 0x20) + i
;
770 s
->pbm_irqs
= qemu_allocate_irqs(pci_apb_set_irq
, s
, MAX_IVEC
);
771 s
->irq_request
= NO_IRQ_REQUEST
;
772 s
->pci_irq_in
= 0ULL;
775 memory_region_init_io(&s
->apb_config
, OBJECT(s
), &apb_config_ops
, s
,
776 "apb-config", 0x10000);
778 sysbus_init_mmio(dev
, &s
->apb_config
);
780 memory_region_init_io(&s
->pci_config
, OBJECT(s
), &pci_config_ops
, s
,
781 "apb-pci-config", 0x1000000);
783 sysbus_init_mmio(dev
, &s
->pci_config
);
786 memory_region_init_alias(&s
->pci_ioport
, OBJECT(s
), "apb-pci-ioport",
787 get_system_io(), 0, 0x10000);
789 sysbus_init_mmio(dev
, &s
->pci_ioport
);
794 static int pbm_pci_host_init(PCIDevice
*d
)
796 pci_set_word(d
->config
+ PCI_COMMAND
,
797 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
);
798 pci_set_word(d
->config
+ PCI_STATUS
,
799 PCI_STATUS_FAST_BACK
| PCI_STATUS_66MHZ
|
800 PCI_STATUS_DEVSEL_MEDIUM
);
804 static void pbm_pci_host_class_init(ObjectClass
*klass
, void *data
)
806 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
807 DeviceClass
*dc
= DEVICE_CLASS(klass
);
809 k
->init
= pbm_pci_host_init
;
810 k
->vendor_id
= PCI_VENDOR_ID_SUN
;
811 k
->device_id
= PCI_DEVICE_ID_SUN_SABRE
;
812 k
->class_id
= PCI_CLASS_BRIDGE_HOST
;
814 * PCI-facing part of the host bridge, not usable without the
815 * host-facing part, which can't be device_add'ed, yet.
817 dc
->cannot_instantiate_with_device_add_yet
= true;
820 static const TypeInfo pbm_pci_host_info
= {
822 .parent
= TYPE_PCI_DEVICE
,
823 .instance_size
= sizeof(PCIDevice
),
824 .class_init
= pbm_pci_host_class_init
,
827 static void pbm_host_class_init(ObjectClass
*klass
, void *data
)
829 DeviceClass
*dc
= DEVICE_CLASS(klass
);
830 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
832 k
->init
= pci_pbm_init_device
;
833 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
834 dc
->reset
= pci_pbm_reset
;
837 static const TypeInfo pbm_host_info
= {
839 .parent
= TYPE_PCI_HOST_BRIDGE
,
840 .instance_size
= sizeof(APBState
),
841 .class_init
= pbm_host_class_init
,
844 static void pbm_pci_bridge_class_init(ObjectClass
*klass
, void *data
)
846 DeviceClass
*dc
= DEVICE_CLASS(klass
);
847 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
849 k
->init
= apb_pci_bridge_initfn
;
850 k
->exit
= pci_bridge_exitfn
;
851 k
->vendor_id
= PCI_VENDOR_ID_SUN
;
852 k
->device_id
= PCI_DEVICE_ID_SUN_SIMBA
;
854 k
->config_write
= pci_bridge_write_config
;
856 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
857 dc
->reset
= pci_bridge_reset
;
858 dc
->vmsd
= &vmstate_pci_device
;
861 static const TypeInfo pbm_pci_bridge_info
= {
862 .name
= "pbm-bridge",
863 .parent
= TYPE_PCI_BRIDGE
,
864 .class_init
= pbm_pci_bridge_class_init
,
867 static void pbm_register_types(void)
869 type_register_static(&pbm_host_info
);
870 type_register_static(&pbm_pci_host_info
);
871 type_register_static(&pbm_pci_bridge_info
);
874 type_init(pbm_register_types
)