ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1 | /* |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 2 | * ARM Versatile/PB PCI host controller |
| 3 | * |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 4 | * Copyright (c) 2006-2009 CodeSourcery. |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 5 | * Written by Paul Brook |
| 6 | * |
Matthew Fernandez | 8e31bf3 | 2011-06-26 12:21:35 +1000 | [diff] [blame] | 7 | * This code is licensed under the LGPL. |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 10 | #include "sysbus.h" |
Michael S. Tsirkin | a2cb15b | 2012-12-12 14:24:50 +0200 | [diff] [blame] | 11 | #include "pci/pci.h" |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 12 | #include "pci/pci_bus.h" |
Michael S. Tsirkin | a2cb15b | 2012-12-12 14:24:50 +0200 | [diff] [blame] | 13 | #include "pci/pci_host.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 14 | #include "exec/address-spaces.h" |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 15 | |
| 16 | typedef struct { |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 17 | PCIHostState parent_obj; |
| 18 | |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 19 | qemu_irq irq[4]; |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 20 | MemoryRegion mem_config; |
| 21 | MemoryRegion mem_config2; |
Peter Maydell | 042f088 | 2013-03-01 17:35:36 +0000 | [diff] [blame] | 22 | MemoryRegion pci_io_space; |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 23 | PCIBus pci_bus; |
| 24 | PCIDevice pci_dev; |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 25 | } PCIVPBState; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 26 | |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 27 | #define TYPE_VERSATILE_PCI "versatile_pci" |
| 28 | #define PCI_VPB(obj) \ |
| 29 | OBJECT_CHECK(PCIVPBState, (obj), TYPE_VERSATILE_PCI) |
| 30 | |
| 31 | #define TYPE_VERSATILE_PCI_HOST "versatile_pci_host" |
| 32 | #define PCI_VPB_HOST(obj) \ |
| 33 | OBJECT_CHECK(PCIDevice), (obj), TYPE_VERSATILE_PCIHOST) |
| 34 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 35 | static inline uint32_t vpb_pci_config_addr(hwaddr addr) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 36 | { |
pbrook | 80b3ada | 2006-09-24 17:01:44 +0000 | [diff] [blame] | 37 | return addr & 0xffffff; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 40 | static void pci_vpb_config_write(void *opaque, hwaddr addr, |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 41 | uint64_t val, unsigned size) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 42 | { |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 43 | pci_data_write(opaque, vpb_pci_config_addr(addr), val, size); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 46 | static uint64_t pci_vpb_config_read(void *opaque, hwaddr addr, |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 47 | unsigned size) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 48 | { |
| 49 | uint32_t val; |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 50 | val = pci_data_read(opaque, vpb_pci_config_addr(addr), size); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 51 | return val; |
| 52 | } |
| 53 | |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 54 | static const MemoryRegionOps pci_vpb_config_ops = { |
| 55 | .read = pci_vpb_config_read, |
| 56 | .write = pci_vpb_config_write, |
| 57 | .endianness = DEVICE_NATIVE_ENDIAN, |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 60 | static int pci_vpb_map_irq(PCIDevice *d, int irq_num) |
| 61 | { |
Peter Maydell | 7e8ce1b | 2013-03-01 18:03:12 +0000 | [diff] [blame] | 62 | /* Slot to IRQ mapping for RealView Platform Baseboard 926 backplane |
| 63 | * name slot IntA IntB IntC IntD |
| 64 | * A 31 IRQ28 IRQ29 IRQ30 IRQ27 |
| 65 | * B 30 IRQ27 IRQ28 IRQ29 IRQ30 |
| 66 | * C 29 IRQ30 IRQ27 IRQ28 IRQ29 |
| 67 | * Slot C is for the host bridge; A and B the peripherals. |
| 68 | * Our output irqs 0..3 correspond to the baseboard's 27..30. |
| 69 | */ |
| 70 | return (PCI_SLOT(d->devfn) + irq_num - 2) % PCI_NUM_PINS; |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Juan Quintela | 5d4e84c | 2009-08-28 15:28:17 +0200 | [diff] [blame] | 73 | static void pci_vpb_set_irq(void *opaque, int irq_num, int level) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 74 | { |
Juan Quintela | 5d4e84c | 2009-08-28 15:28:17 +0200 | [diff] [blame] | 75 | qemu_irq *pic = opaque; |
| 76 | |
Paul Brook | 97aff48 | 2009-05-14 22:35:07 +0100 | [diff] [blame] | 77 | qemu_set_irq(pic[irq_num], level); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 80 | static void pci_vpb_init(Object *obj) |
| 81 | { |
| 82 | PCIHostState *h = PCI_HOST_BRIDGE(obj); |
| 83 | PCIVPBState *s = PCI_VPB(obj); |
| 84 | |
Peter Maydell | 042f088 | 2013-03-01 17:35:36 +0000 | [diff] [blame] | 85 | // XXX size of region? |
| 86 | memory_region_init(&s->pci_io_space, "pci_io", 0x100000); |
| 87 | |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 88 | pci_bus_new_inplace(&s->pci_bus, DEVICE(obj), "pci", |
Peter Maydell | 042f088 | 2013-03-01 17:35:36 +0000 | [diff] [blame] | 89 | get_system_memory(), &s->pci_io_space, |
Peter Maydell | 7e8ce1b | 2013-03-01 18:03:12 +0000 | [diff] [blame] | 90 | PCI_DEVFN(29, 0)); |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 91 | h->bus = &s->pci_bus; |
| 92 | |
| 93 | object_initialize(&s->pci_dev, TYPE_VERSATILE_PCI_HOST); |
| 94 | qdev_set_parent_bus(DEVICE(&s->pci_dev), BUS(&s->pci_bus)); |
Peter Maydell | 7e8ce1b | 2013-03-01 18:03:12 +0000 | [diff] [blame] | 95 | object_property_set_int(OBJECT(&s->pci_dev), PCI_DEVFN(29, 0), "addr", |
| 96 | NULL); |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 99 | static void pci_vpb_realize(DeviceState *dev, Error **errp) |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 100 | { |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 101 | PCIVPBState *s = PCI_VPB(dev); |
| 102 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 103 | int i; |
| 104 | |
| 105 | for (i = 0; i < 4; i++) { |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 106 | sysbus_init_irq(sbd, &s->irq[i]); |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 107 | } |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 108 | |
| 109 | pci_bus_irqs(&s->pci_bus, pci_vpb_set_irq, pci_vpb_map_irq, s->irq, 4); |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 110 | |
| 111 | /* ??? Register memory space. */ |
| 112 | |
Peter Maydell | 7d6e771 | 2011-09-01 18:36:53 +0100 | [diff] [blame] | 113 | /* Our memory regions are: |
| 114 | * 0 : PCI self config window |
| 115 | * 1 : PCI config window |
Peter Maydell | 720667a | 2013-03-01 13:57:45 +0000 | [diff] [blame] | 116 | * 2 : PCI IO window |
Peter Maydell | 7d6e771 | 2011-09-01 18:36:53 +0100 | [diff] [blame] | 117 | */ |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 118 | memory_region_init_io(&s->mem_config, &pci_vpb_config_ops, &s->pci_bus, |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 119 | "pci-vpb-selfconfig", 0x1000000); |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 120 | sysbus_init_mmio(sbd, &s->mem_config); |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 121 | memory_region_init_io(&s->mem_config2, &pci_vpb_config_ops, &s->pci_bus, |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 122 | "pci-vpb-config", 0x1000000); |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 123 | sysbus_init_mmio(sbd, &s->mem_config2); |
Peter Maydell | 042f088 | 2013-03-01 17:35:36 +0000 | [diff] [blame] | 124 | |
| 125 | sysbus_init_mmio(sbd, &s->pci_io_space); |
Avi Kivity | 45de094 | 2011-08-15 17:17:32 +0300 | [diff] [blame] | 126 | |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 127 | /* TODO Remove once realize propagates to child devices. */ |
| 128 | object_property_set_bool(OBJECT(&s->pci_dev), true, "realized", errp); |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 131 | static int versatile_pci_host_init(PCIDevice *d) |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 132 | { |
Michael S. Tsirkin | a408b1d | 2010-02-08 23:36:02 +0200 | [diff] [blame] | 133 | pci_set_word(d->config + PCI_STATUS, |
| 134 | PCI_STATUS_66MHZ | PCI_STATUS_DEVSEL_MEDIUM); |
Michael S. Tsirkin | 01764fe | 2010-02-08 23:33:33 +0200 | [diff] [blame] | 135 | pci_set_byte(d->config + PCI_LATENCY_TIMER, 0x10); |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 136 | return 0; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 137 | } |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 138 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 139 | static void versatile_pci_host_class_init(ObjectClass *klass, void *data) |
| 140 | { |
| 141 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 142 | |
| 143 | k->init = versatile_pci_host_init; |
| 144 | k->vendor_id = PCI_VENDOR_ID_XILINX; |
| 145 | k->device_id = PCI_DEVICE_ID_XILINX_XC2VP30; |
| 146 | k->class_id = PCI_CLASS_PROCESSOR_CO; |
| 147 | } |
| 148 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 149 | static const TypeInfo versatile_pci_host_info = { |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 150 | .name = TYPE_VERSATILE_PCI_HOST, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 151 | .parent = TYPE_PCI_DEVICE, |
| 152 | .instance_size = sizeof(PCIDevice), |
| 153 | .class_init = versatile_pci_host_class_init, |
Gerd Hoffmann | 0aab0d3 | 2009-06-30 14:12:07 +0200 | [diff] [blame] | 154 | }; |
| 155 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 156 | static void pci_vpb_class_init(ObjectClass *klass, void *data) |
| 157 | { |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 158 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 159 | |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 160 | dc->realize = pci_vpb_realize; |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 161 | } |
| 162 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 163 | static const TypeInfo pci_vpb_info = { |
Peter Maydell | 8bea7cb | 2013-03-01 14:42:54 +0000 | [diff] [blame] | 164 | .name = TYPE_VERSATILE_PCI, |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 165 | .parent = TYPE_PCI_HOST_BRIDGE, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 166 | .instance_size = sizeof(PCIVPBState), |
Peter Maydell | 833a26d | 2013-03-01 15:52:59 +0000 | [diff] [blame] | 167 | .instance_init = pci_vpb_init, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 168 | .class_init = pci_vpb_class_init, |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 169 | }; |
| 170 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 171 | static void versatile_pci_register_types(void) |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 172 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 173 | type_register_static(&pci_vpb_info); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 174 | type_register_static(&versatile_pci_host_info); |
Paul Brook | 0027b06 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 177 | type_init(versatile_pci_register_types) |