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 "qemu/osdep.h"
31 #include "hw/sysbus.h"
32 #include "hw/pci/pci.h"
33 #include "hw/pci/pci_host.h"
34 #include "hw/pci/pci_bridge.h"
35 #include "hw/pci/pci_bus.h"
36 #include "hw/pci-host/apb.h"
37 #include "sysemu/sysemu.h"
38 #include "exec/address-spaces.h"
45 #define APB_DPRINTF(fmt, ...) \
46 do { printf("APB: " fmt , ## __VA_ARGS__); } while (0)
48 #define APB_DPRINTF(fmt, ...)
55 #define IOMMU_DPRINTF(fmt, ...) \
56 do { printf("IOMMU: " fmt , ## __VA_ARGS__); } while (0)
58 #define IOMMU_DPRINTF(fmt, ...)
63 * PBM: "UltraSPARC IIi User's Manual",
64 * http://www.sun.com/processors/manuals/805-0087.pdf
66 * APB: "Advanced PCI Bridge (APB) User's Manual",
67 * http://www.sun.com/processors/manuals/805-1251.pdf
70 #define PBM_PCI_IMR_MASK 0x7fffffff
71 #define PBM_PCI_IMR_ENABLED 0x80000000
73 #define POR (1U << 31)
74 #define SOFT_POR (1U << 30)
75 #define SOFT_XIR (1U << 29)
76 #define BTN_POR (1U << 28)
77 #define BTN_XIR (1U << 27)
78 #define RESET_MASK 0xf8000000
79 #define RESET_WCMASK 0x98000000
80 #define RESET_WMASK 0x60000000
83 #define NO_IRQ_REQUEST (MAX_IVEC + 1)
85 #define IOMMU_PAGE_SIZE_8K (1ULL << 13)
86 #define IOMMU_PAGE_MASK_8K (~(IOMMU_PAGE_SIZE_8K - 1))
87 #define IOMMU_PAGE_SIZE_64K (1ULL << 16)
88 #define IOMMU_PAGE_MASK_64K (~(IOMMU_PAGE_SIZE_64K - 1))
92 #define IOMMU_CTRL 0x0
93 #define IOMMU_CTRL_TBW_SIZE (1ULL << 2)
94 #define IOMMU_CTRL_MMU_EN (1ULL)
96 #define IOMMU_CTRL_TSB_SHIFT 16
98 #define IOMMU_BASE 0x8
99 #define IOMMU_FLUSH 0x10
101 #define IOMMU_TTE_DATA_V (1ULL << 63)
102 #define IOMMU_TTE_DATA_SIZE (1ULL << 61)
103 #define IOMMU_TTE_DATA_W (1ULL << 1)
105 #define IOMMU_TTE_PHYS_MASK_8K 0x1ffffffe000ULL
106 #define IOMMU_TTE_PHYS_MASK_64K 0x1ffffff8000ULL
108 #define IOMMU_TSB_8K_OFFSET_MASK_8M 0x00000000007fe000ULL
109 #define IOMMU_TSB_8K_OFFSET_MASK_16M 0x0000000000ffe000ULL
110 #define IOMMU_TSB_8K_OFFSET_MASK_32M 0x0000000001ffe000ULL
111 #define IOMMU_TSB_8K_OFFSET_MASK_64M 0x0000000003ffe000ULL
112 #define IOMMU_TSB_8K_OFFSET_MASK_128M 0x0000000007ffe000ULL
113 #define IOMMU_TSB_8K_OFFSET_MASK_256M 0x000000000fffe000ULL
114 #define IOMMU_TSB_8K_OFFSET_MASK_512M 0x000000001fffe000ULL
115 #define IOMMU_TSB_8K_OFFSET_MASK_1G 0x000000003fffe000ULL
117 #define IOMMU_TSB_64K_OFFSET_MASK_64M 0x0000000003ff0000ULL
118 #define IOMMU_TSB_64K_OFFSET_MASK_128M 0x0000000007ff0000ULL
119 #define IOMMU_TSB_64K_OFFSET_MASK_256M 0x000000000fff0000ULL
120 #define IOMMU_TSB_64K_OFFSET_MASK_512M 0x000000001fff0000ULL
121 #define IOMMU_TSB_64K_OFFSET_MASK_1G 0x000000003fff0000ULL
122 #define IOMMU_TSB_64K_OFFSET_MASK_2G 0x000000007fff0000ULL
124 typedef struct IOMMUState {
125 AddressSpace iommu_as;
126 IOMMUMemoryRegion iommu;
128 uint64_t regs[IOMMU_NREGS];
131 #define TYPE_APB "pbm"
133 #define APB_DEVICE(obj) \
134 OBJECT_CHECK(APBState, (obj), TYPE_APB)
136 #define TYPE_APB_IOMMU_MEMORY_REGION "pbm-iommu-memory-region"
138 typedef struct APBState {
139 PCIHostState parent_obj;
141 MemoryRegion apb_config;
142 MemoryRegion pci_config;
143 MemoryRegion pci_mmio;
144 MemoryRegion pci_ioport;
147 uint32_t pci_control[16];
148 uint32_t pci_irq_map[8];
149 uint32_t pci_err_irq_map[4];
150 uint32_t obio_irq_map[32];
153 unsigned int irq_request;
154 uint32_t reset_control;
155 unsigned int nr_resets;
158 static inline void pbm_set_request(APBState *s, unsigned int irq_num)
160 APB_DPRINTF("%s: request irq %d\n", __func__, irq_num);
162 s->irq_request = irq_num;
163 qemu_set_irq(s->ivec_irqs[irq_num], 1);
166 static inline void pbm_check_irqs(APBState *s)
171 /* Previous request is not acknowledged, resubmit */
172 if (s->irq_request != NO_IRQ_REQUEST) {
173 pbm_set_request(s, s->irq_request);
176 /* no request pending */
177 if (s->pci_irq_in == 0ULL) {
180 for (i = 0; i < 32; i++) {
181 if (s->pci_irq_in & (1ULL << i)) {
182 if (s->pci_irq_map[i >> 2] & PBM_PCI_IMR_ENABLED) {
183 pbm_set_request(s, i);
188 for (i = 32; i < 64; i++) {
189 if (s->pci_irq_in & (1ULL << i)) {
190 if (s->obio_irq_map[i - 32] & PBM_PCI_IMR_ENABLED) {
191 pbm_set_request(s, i);
198 static inline void pbm_clear_request(APBState *s, unsigned int irq_num)
200 APB_DPRINTF("%s: clear request irq %d\n", __func__, irq_num);
201 qemu_set_irq(s->ivec_irqs[irq_num], 0);
202 s->irq_request = NO_IRQ_REQUEST;
205 static AddressSpace *pbm_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
207 IOMMUState *is = opaque;
209 return &is->iommu_as;
212 /* Called from RCU critical section */
213 static IOMMUTLBEntry pbm_translate_iommu(IOMMUMemoryRegion *iommu, hwaddr addr,
214 IOMMUAccessFlags flag)
216 IOMMUState *is = container_of(iommu, IOMMUState, iommu);
217 hwaddr baseaddr, offset;
220 IOMMUTLBEntry ret = {
221 .target_as = &address_space_memory,
223 .translated_addr = 0,
224 .addr_mask = ~(hwaddr)0,
228 if (!(is->regs[IOMMU_CTRL >> 3] & IOMMU_CTRL_MMU_EN)) {
229 /* IOMMU disabled, passthrough using standard 8K page */
230 ret.iova = addr & IOMMU_PAGE_MASK_8K;
231 ret.translated_addr = addr;
232 ret.addr_mask = IOMMU_PAGE_MASK_8K;
238 baseaddr = is->regs[IOMMU_BASE >> 3];
239 tsbsize = (is->regs[IOMMU_CTRL >> 3] >> IOMMU_CTRL_TSB_SHIFT) & 0x7;
241 if (is->regs[IOMMU_CTRL >> 3] & IOMMU_CTRL_TBW_SIZE) {
245 offset = (addr & IOMMU_TSB_64K_OFFSET_MASK_64M) >> 13;
248 offset = (addr & IOMMU_TSB_64K_OFFSET_MASK_128M) >> 13;
251 offset = (addr & IOMMU_TSB_64K_OFFSET_MASK_256M) >> 13;
254 offset = (addr & IOMMU_TSB_64K_OFFSET_MASK_512M) >> 13;
257 offset = (addr & IOMMU_TSB_64K_OFFSET_MASK_1G) >> 13;
260 offset = (addr & IOMMU_TSB_64K_OFFSET_MASK_2G) >> 13;
263 /* Not implemented, error */
270 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_8M) >> 10;
273 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_16M) >> 10;
276 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_32M) >> 10;
279 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_64M) >> 10;
282 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_128M) >> 10;
285 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_256M) >> 10;
288 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_512M) >> 10;
291 offset = (addr & IOMMU_TSB_8K_OFFSET_MASK_1G) >> 10;
296 tte = address_space_ldq_be(&address_space_memory, baseaddr + offset,
297 MEMTXATTRS_UNSPECIFIED, NULL);
299 if (!(tte & IOMMU_TTE_DATA_V)) {
300 /* Invalid mapping */
304 if (tte & IOMMU_TTE_DATA_W) {
312 if (tte & IOMMU_TTE_DATA_SIZE) {
314 ret.iova = addr & IOMMU_PAGE_MASK_64K;
315 ret.translated_addr = tte & IOMMU_TTE_PHYS_MASK_64K;
316 ret.addr_mask = (IOMMU_PAGE_SIZE_64K - 1);
319 ret.iova = addr & IOMMU_PAGE_MASK_8K;
320 ret.translated_addr = tte & IOMMU_TTE_PHYS_MASK_8K;
321 ret.addr_mask = (IOMMU_PAGE_SIZE_8K - 1);
327 static void iommu_config_write(void *opaque, hwaddr addr,
328 uint64_t val, unsigned size)
330 IOMMUState *is = opaque;
332 IOMMU_DPRINTF("IOMMU config write: 0x%" HWADDR_PRIx " val: %" PRIx64
333 " size: %d\n", addr, val, size);
338 is->regs[IOMMU_CTRL >> 3] &= 0xffffffffULL;
339 is->regs[IOMMU_CTRL >> 3] |= val << 32;
341 is->regs[IOMMU_CTRL >> 3] = val;
344 case IOMMU_CTRL + 0x4:
345 is->regs[IOMMU_CTRL >> 3] &= 0xffffffff00000000ULL;
346 is->regs[IOMMU_CTRL >> 3] |= val & 0xffffffffULL;
350 is->regs[IOMMU_BASE >> 3] &= 0xffffffffULL;
351 is->regs[IOMMU_BASE >> 3] |= val << 32;
353 is->regs[IOMMU_BASE >> 3] = val;
356 case IOMMU_BASE + 0x4:
357 is->regs[IOMMU_BASE >> 3] &= 0xffffffff00000000ULL;
358 is->regs[IOMMU_BASE >> 3] |= val & 0xffffffffULL;
361 case IOMMU_FLUSH + 0x4:
364 qemu_log_mask(LOG_UNIMP,
365 "apb iommu: Unimplemented register write "
366 "reg 0x%" HWADDR_PRIx " size 0x%x value 0x%" PRIx64 "\n",
372 static uint64_t iommu_config_read(void *opaque, hwaddr addr, unsigned size)
374 IOMMUState *is = opaque;
380 val = is->regs[IOMMU_CTRL >> 3] >> 32;
382 val = is->regs[IOMMU_CTRL >> 3];
385 case IOMMU_CTRL + 0x4:
386 val = is->regs[IOMMU_CTRL >> 3] & 0xffffffffULL;
390 val = is->regs[IOMMU_BASE >> 3] >> 32;
392 val = is->regs[IOMMU_BASE >> 3];
395 case IOMMU_BASE + 0x4:
396 val = is->regs[IOMMU_BASE >> 3] & 0xffffffffULL;
399 case IOMMU_FLUSH + 0x4:
403 qemu_log_mask(LOG_UNIMP,
404 "apb iommu: Unimplemented register read "
405 "reg 0x%" HWADDR_PRIx " size 0x%x\n",
411 IOMMU_DPRINTF("IOMMU config read: 0x%" HWADDR_PRIx " val: %" PRIx64
412 " size: %d\n", addr, val, size);
417 static void apb_config_writel (void *opaque, hwaddr addr,
418 uint64_t val, unsigned size)
420 APBState *s = opaque;
421 IOMMUState *is = &s->iommu;
423 APB_DPRINTF("%s: addr " TARGET_FMT_plx " val %" PRIx64 "\n", __func__, addr, val);
425 switch (addr & 0xffff) {
426 case 0x30 ... 0x4f: /* DMA error registers */
427 /* XXX: not implemented yet */
429 case 0x200 ... 0x217: /* IOMMU */
430 iommu_config_write(is, (addr & 0x1f), val, size);
432 case 0xc00 ... 0xc3f: /* PCI interrupt control */
434 unsigned int ino = (addr & 0x3f) >> 3;
435 s->pci_irq_map[ino] &= PBM_PCI_IMR_MASK;
436 s->pci_irq_map[ino] |= val & ~PBM_PCI_IMR_MASK;
437 if ((s->irq_request == ino) && !(val & ~PBM_PCI_IMR_MASK)) {
438 pbm_clear_request(s, ino);
443 case 0x1000 ... 0x107f: /* OBIO interrupt control */
445 unsigned int ino = ((addr & 0xff) >> 3);
446 s->obio_irq_map[ino] &= PBM_PCI_IMR_MASK;
447 s->obio_irq_map[ino] |= val & ~PBM_PCI_IMR_MASK;
448 if ((s->irq_request == (ino | 0x20))
449 && !(val & ~PBM_PCI_IMR_MASK)) {
450 pbm_clear_request(s, ino | 0x20);
455 case 0x1400 ... 0x14ff: /* PCI interrupt clear */
457 unsigned int ino = (addr & 0xff) >> 5;
458 if ((s->irq_request / 4) == ino) {
459 pbm_clear_request(s, s->irq_request);
464 case 0x1800 ... 0x1860: /* OBIO interrupt clear */
466 unsigned int ino = ((addr & 0xff) >> 3) | 0x20;
467 if (s->irq_request == ino) {
468 pbm_clear_request(s, ino);
473 case 0x2000 ... 0x202f: /* PCI control */
474 s->pci_control[(addr & 0x3f) >> 2] = val;
476 case 0xf020 ... 0xf027: /* Reset control */
479 s->reset_control &= ~(val & RESET_WCMASK);
480 s->reset_control |= val & RESET_WMASK;
481 if (val & SOFT_POR) {
483 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
484 } else if (val & SOFT_XIR) {
485 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
489 case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */
490 case 0xa400 ... 0xa67f: /* IOMMU diagnostics */
491 case 0xa800 ... 0xa80f: /* Interrupt diagnostics */
492 case 0xf000 ... 0xf01f: /* FFB config, memory control */
499 static uint64_t apb_config_readl (void *opaque,
500 hwaddr addr, unsigned size)
502 APBState *s = opaque;
503 IOMMUState *is = &s->iommu;
506 switch (addr & 0xffff) {
507 case 0x30 ... 0x4f: /* DMA error registers */
509 /* XXX: not implemented yet */
511 case 0x200 ... 0x217: /* IOMMU */
512 val = iommu_config_read(is, (addr & 0x1f), size);
514 case 0xc00 ... 0xc3f: /* PCI interrupt control */
516 val = s->pci_irq_map[(addr & 0x3f) >> 3];
521 case 0x1000 ... 0x107f: /* OBIO interrupt control */
523 val = s->obio_irq_map[(addr & 0xff) >> 3];
528 case 0x1080 ... 0x108f: /* PCI bus error */
530 val = s->pci_err_irq_map[(addr & 0xf) >> 3];
535 case 0x2000 ... 0x202f: /* PCI control */
536 val = s->pci_control[(addr & 0x3f) >> 2];
538 case 0xf020 ... 0xf027: /* Reset control */
540 val = s->reset_control;
545 case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */
546 case 0xa400 ... 0xa67f: /* IOMMU diagnostics */
547 case 0xa800 ... 0xa80f: /* Interrupt diagnostics */
548 case 0xf000 ... 0xf01f: /* FFB config, memory control */
554 APB_DPRINTF("%s: addr " TARGET_FMT_plx " -> %x\n", __func__, addr, val);
559 static const MemoryRegionOps apb_config_ops = {
560 .read = apb_config_readl,
561 .write = apb_config_writel,
562 .endianness = DEVICE_NATIVE_ENDIAN,
565 static void apb_pci_config_write(void *opaque, hwaddr addr,
566 uint64_t val, unsigned size)
568 APBState *s = opaque;
569 PCIHostState *phb = PCI_HOST_BRIDGE(s);
571 val = qemu_bswap_len(val, size);
572 APB_DPRINTF("%s: addr " TARGET_FMT_plx " val %" PRIx64 "\n", __func__, addr, val);
573 pci_data_write(phb->bus, addr, val, size);
576 static uint64_t apb_pci_config_read(void *opaque, hwaddr addr,
580 APBState *s = opaque;
581 PCIHostState *phb = PCI_HOST_BRIDGE(s);
583 ret = pci_data_read(phb->bus, addr, size);
584 ret = qemu_bswap_len(ret, size);
585 APB_DPRINTF("%s: addr " TARGET_FMT_plx " -> %x\n", __func__, addr, ret);
589 /* The APB host has an IRQ line for each IRQ line of each slot. */
590 static int pci_apb_map_irq(PCIDevice *pci_dev, int irq_num)
592 return ((pci_dev->devfn & 0x18) >> 1) + irq_num;
595 static int pci_pbm_map_irq(PCIDevice *pci_dev, int irq_num)
598 if (pci_dev->devfn & 1)
602 return (bus_offset + (PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f;
605 static void pci_apb_set_irq(void *opaque, int irq_num, int level)
607 APBState *s = opaque;
609 APB_DPRINTF("%s: set irq_in %d level %d\n", __func__, irq_num, level);
610 /* PCI IRQ map onto the first 32 INO. */
613 s->pci_irq_in |= 1ULL << irq_num;
614 if (s->pci_irq_map[irq_num >> 2] & PBM_PCI_IMR_ENABLED) {
615 pbm_set_request(s, irq_num);
618 s->pci_irq_in &= ~(1ULL << irq_num);
621 /* OBIO IRQ map onto the next 32 INO. */
623 APB_DPRINTF("%s: set irq %d level %d\n", __func__, irq_num, level);
624 s->pci_irq_in |= 1ULL << irq_num;
625 if ((s->irq_request == NO_IRQ_REQUEST)
626 && (s->obio_irq_map[irq_num - 32] & PBM_PCI_IMR_ENABLED)) {
627 pbm_set_request(s, irq_num);
630 s->pci_irq_in &= ~(1ULL << irq_num);
635 static void apb_pci_bridge_realize(PCIDevice *dev, Error **errp)
637 pci_bridge_initfn(dev, TYPE_PCI_BUS);
641 * According to PCI bridge spec, after reset
642 * bus master bit is off
643 * memory space enable bit is off
644 * According to manual (805-1251.pdf).
645 * the reset value should be zero unless the boot pin is tied high
646 * (which is true) and thus it should be PCI_COMMAND_MEMORY.
648 pci_set_word(dev->config + PCI_COMMAND,
650 pci_set_word(dev->config + PCI_STATUS,
651 PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
652 PCI_STATUS_DEVSEL_MEDIUM);
655 PCIBus *pci_apb_init(hwaddr special_base,
657 qemu_irq *ivec_irqs, PCIBus **bus2, PCIBus **bus3,
668 /* Ultrasparc PBM main bus */
669 dev = qdev_create(NULL, TYPE_APB);
671 phb = PCI_HOST_BRIDGE(dev);
672 phb->bus = pci_register_bus(DEVICE(phb), "pci",
673 pci_apb_set_irq, pci_pbm_map_irq, d,
676 0, 32, TYPE_PCI_BUS);
677 qdev_init_nofail(dev);
678 s = SYS_BUS_DEVICE(dev);
680 sysbus_mmio_map(s, 0, special_base);
681 /* PCI configuration space */
682 sysbus_mmio_map(s, 1, special_base + 0x1000000ULL);
684 sysbus_mmio_map(s, 2, special_base + 0x2000000ULL);
686 memory_region_init(&d->pci_mmio, OBJECT(s), "pci-mmio", 0x100000000ULL);
687 memory_region_add_subregion(get_system_memory(), mem_base, &d->pci_mmio);
689 *pbm_irqs = d->pbm_irqs;
690 d->ivec_irqs = ivec_irqs;
692 pci_create_simple(phb->bus, 0, "pbm-pci");
696 memset(is, 0, sizeof(IOMMUState));
698 memory_region_init_iommu(&is->iommu, sizeof(is->iommu),
699 TYPE_APB_IOMMU_MEMORY_REGION, OBJECT(dev),
700 "iommu-apb", UINT64_MAX);
701 address_space_init(&is->iommu_as, MEMORY_REGION(&is->iommu), "pbm-as");
702 pci_setup_iommu(phb->bus, pbm_pci_dma_iommu, is);
704 /* APB secondary busses */
705 pci_dev = pci_create_multifunction(phb->bus, PCI_DEVFN(1, 0), true,
707 br = PCI_BRIDGE(pci_dev);
708 pci_bridge_map_irq(br, "Advanced PCI Bus secondary bridge 1",
710 qdev_init_nofail(&pci_dev->qdev);
711 *bus2 = pci_bridge_get_sec_bus(br);
713 pci_dev = pci_create_multifunction(phb->bus, PCI_DEVFN(1, 1), true,
715 br = PCI_BRIDGE(pci_dev);
716 pci_bridge_map_irq(br, "Advanced PCI Bus secondary bridge 2",
718 qdev_init_nofail(&pci_dev->qdev);
719 *bus3 = pci_bridge_get_sec_bus(br);
724 static void pci_pbm_reset(DeviceState *d)
727 APBState *s = APB_DEVICE(d);
729 for (i = 0; i < 8; i++) {
730 s->pci_irq_map[i] &= PBM_PCI_IMR_MASK;
732 for (i = 0; i < 32; i++) {
733 s->obio_irq_map[i] &= PBM_PCI_IMR_MASK;
736 s->irq_request = NO_IRQ_REQUEST;
737 s->pci_irq_in = 0ULL;
739 if (s->nr_resets++ == 0) {
741 s->reset_control = POR;
745 static const MemoryRegionOps pci_config_ops = {
746 .read = apb_pci_config_read,
747 .write = apb_pci_config_write,
748 .endianness = DEVICE_NATIVE_ENDIAN,
751 static int pci_pbm_init_device(SysBusDevice *dev)
757 for (i = 0; i < 8; i++) {
758 s->pci_irq_map[i] = (0x1f << 6) | (i << 2);
760 for (i = 0; i < 2; i++) {
761 s->pci_err_irq_map[i] = (0x1f << 6) | 0x30;
763 for (i = 0; i < 32; i++) {
764 s->obio_irq_map[i] = ((0x1f << 6) | 0x20) + i;
766 s->pbm_irqs = qemu_allocate_irqs(pci_apb_set_irq, s, MAX_IVEC);
767 s->irq_request = NO_IRQ_REQUEST;
768 s->pci_irq_in = 0ULL;
771 memory_region_init_io(&s->apb_config, OBJECT(s), &apb_config_ops, s,
772 "apb-config", 0x10000);
774 sysbus_init_mmio(dev, &s->apb_config);
776 memory_region_init_io(&s->pci_config, OBJECT(s), &pci_config_ops, s,
777 "apb-pci-config", 0x1000000);
779 sysbus_init_mmio(dev, &s->pci_config);
782 memory_region_init_alias(&s->pci_ioport, OBJECT(s), "apb-pci-ioport",
783 get_system_io(), 0, 0x10000);
785 sysbus_init_mmio(dev, &s->pci_ioport);
790 static void pbm_pci_host_realize(PCIDevice *d, Error **errp)
792 pci_set_word(d->config + PCI_COMMAND,
793 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
794 pci_set_word(d->config + PCI_STATUS,
795 PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
796 PCI_STATUS_DEVSEL_MEDIUM);
799 static void pbm_pci_host_class_init(ObjectClass *klass, void *data)
801 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
802 DeviceClass *dc = DEVICE_CLASS(klass);
804 k->realize = pbm_pci_host_realize;
805 k->vendor_id = PCI_VENDOR_ID_SUN;
806 k->device_id = PCI_DEVICE_ID_SUN_SABRE;
807 k->class_id = PCI_CLASS_BRIDGE_HOST;
809 * PCI-facing part of the host bridge, not usable without the
810 * host-facing part, which can't be device_add'ed, yet.
812 dc->user_creatable = false;
815 static const TypeInfo pbm_pci_host_info = {
817 .parent = TYPE_PCI_DEVICE,
818 .instance_size = sizeof(PCIDevice),
819 .class_init = pbm_pci_host_class_init,
822 static void pbm_host_class_init(ObjectClass *klass, void *data)
824 DeviceClass *dc = DEVICE_CLASS(klass);
825 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
827 k->init = pci_pbm_init_device;
828 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
829 dc->reset = pci_pbm_reset;
832 static const TypeInfo pbm_host_info = {
834 .parent = TYPE_PCI_HOST_BRIDGE,
835 .instance_size = sizeof(APBState),
836 .class_init = pbm_host_class_init,
839 static void pbm_pci_bridge_class_init(ObjectClass *klass, void *data)
841 DeviceClass *dc = DEVICE_CLASS(klass);
842 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
844 k->realize = apb_pci_bridge_realize;
845 k->exit = pci_bridge_exitfn;
846 k->vendor_id = PCI_VENDOR_ID_SUN;
847 k->device_id = PCI_DEVICE_ID_SUN_SIMBA;
849 k->config_write = pci_bridge_write_config;
851 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
852 dc->reset = pci_bridge_reset;
853 dc->vmsd = &vmstate_pci_device;
856 static const TypeInfo pbm_pci_bridge_info = {
857 .name = "pbm-bridge",
858 .parent = TYPE_PCI_BRIDGE,
859 .class_init = pbm_pci_bridge_class_init,
862 static void pbm_iommu_memory_region_class_init(ObjectClass *klass, void *data)
864 IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass);
866 imrc->translate = pbm_translate_iommu;
869 static const TypeInfo pbm_iommu_memory_region_info = {
870 .parent = TYPE_IOMMU_MEMORY_REGION,
871 .name = TYPE_APB_IOMMU_MEMORY_REGION,
872 .class_init = pbm_iommu_memory_region_class_init,
875 static void pbm_register_types(void)
877 type_register_static(&pbm_host_info);
878 type_register_static(&pbm_pci_host_info);
879 type_register_static(&pbm_pci_bridge_info);
880 type_register_static(&pbm_iommu_memory_region_info);
883 type_init(pbm_register_types)