pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Uninorth PCI host (for all Mac99 and newer machines) |
| 3 | * |
| 4 | * Copyright (c) 2006 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 24 | #include "hw.h" |
| 25 | #include "ppc_mac.h" |
| 26 | #include "pci.h" |
Isaku Yamahata | 4f5e19e | 2009-10-30 21:21:06 +0900 | [diff] [blame] | 27 | #include "pci_host.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 28 | |
blueswir1 | f390238 | 2009-02-05 20:22:07 +0000 | [diff] [blame] | 29 | /* debug UniNorth */ |
| 30 | //#define DEBUG_UNIN |
| 31 | |
| 32 | #ifdef DEBUG_UNIN |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 33 | #define UNIN_DPRINTF(fmt, ...) \ |
| 34 | do { printf("UNIN: " fmt , ## __VA_ARGS__); } while (0) |
blueswir1 | f390238 | 2009-02-05 20:22:07 +0000 | [diff] [blame] | 35 | #else |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 36 | #define UNIN_DPRINTF(fmt, ...) |
blueswir1 | f390238 | 2009-02-05 20:22:07 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
Alexander Graf | fa0be69 | 2010-02-09 17:37:04 +0100 | [diff] [blame] | 39 | static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e }; |
| 40 | |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 41 | typedef struct UNINState { |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 42 | PCIHostState host_state; |
Blue Swirl | 46f3069 | 2011-09-17 20:30:50 +0000 | [diff] [blame] | 43 | MemoryRegion pci_mmio; |
| 44 | MemoryRegion pci_hole; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 45 | } UNINState; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 46 | |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 47 | static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 48 | { |
Alexander Graf | fa0be69 | 2010-02-09 17:37:04 +0100 | [diff] [blame] | 49 | int retval; |
| 50 | int devfn = pci_dev->devfn & 0x00FFFFFF; |
| 51 | |
| 52 | retval = (((devfn >> 11) & 0x1F) + irq_num) & 3; |
| 53 | |
| 54 | return retval; |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Juan Quintela | 5d4e84c | 2009-08-28 15:28:17 +0200 | [diff] [blame] | 57 | static void pci_unin_set_irq(void *opaque, int irq_num, int level) |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 58 | { |
Juan Quintela | 5d4e84c | 2009-08-28 15:28:17 +0200 | [diff] [blame] | 59 | qemu_irq *pic = opaque; |
| 60 | |
Alexander Graf | fa0be69 | 2010-02-09 17:37:04 +0100 | [diff] [blame] | 61 | UNIN_DPRINTF("%s: setting INT %d = %d\n", __func__, |
| 62 | unin_irq_line[irq_num], level); |
| 63 | qemu_set_irq(pic[unin_irq_line[irq_num]], level); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Alexander Graf | d86f0e3 | 2010-02-09 17:37:01 +0100 | [diff] [blame] | 66 | static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr) |
| 67 | { |
| 68 | uint32_t retval; |
| 69 | |
| 70 | if (reg & (1u << 31)) { |
| 71 | /* XXX OpenBIOS compatibility hack */ |
| 72 | retval = reg | (addr & 3); |
| 73 | } else if (reg & 1) { |
| 74 | /* CFA1 style */ |
| 75 | retval = (reg & ~7u) | (addr & 7); |
| 76 | } else { |
| 77 | uint32_t slot, func; |
| 78 | |
| 79 | /* Grab CFA0 style values */ |
| 80 | slot = ffs(reg & 0xfffff800) - 1; |
| 81 | func = (reg >> 8) & 7; |
| 82 | |
| 83 | /* ... and then convert them to x86 format */ |
| 84 | /* config pointer */ |
| 85 | retval = (reg & (0xff - 7)) | (addr & 7); |
| 86 | /* slot */ |
| 87 | retval |= slot << 11; |
| 88 | /* fn */ |
| 89 | retval |= func << 8; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | UNIN_DPRINTF("Converted config space accessor %08x/%08x -> %08x\n", |
| 94 | reg, addr, retval); |
| 95 | |
| 96 | return retval; |
| 97 | } |
| 98 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 99 | static void unin_data_write(void *opaque, target_phys_addr_t addr, |
| 100 | uint64_t val, unsigned len) |
Alexander Graf | d86f0e3 | 2010-02-09 17:37:01 +0100 | [diff] [blame] | 101 | { |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 102 | UNINState *s = opaque; |
| 103 | UNIN_DPRINTF("write addr %" TARGET_FMT_plx " len %d val %"PRIx64"\n", |
| 104 | addr, len, val); |
Alexander Graf | d86f0e3 | 2010-02-09 17:37:01 +0100 | [diff] [blame] | 105 | pci_data_write(s->host_state.bus, |
| 106 | unin_get_config_reg(s->host_state.config_reg, addr), |
| 107 | val, len); |
| 108 | } |
| 109 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 110 | static uint64_t unin_data_read(void *opaque, target_phys_addr_t addr, |
| 111 | unsigned len) |
Alexander Graf | d86f0e3 | 2010-02-09 17:37:01 +0100 | [diff] [blame] | 112 | { |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 113 | UNINState *s = opaque; |
Alexander Graf | d86f0e3 | 2010-02-09 17:37:01 +0100 | [diff] [blame] | 114 | uint32_t val; |
| 115 | |
| 116 | val = pci_data_read(s->host_state.bus, |
| 117 | unin_get_config_reg(s->host_state.config_reg, addr), |
| 118 | len); |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 119 | UNIN_DPRINTF("read addr %" TARGET_FMT_plx " len %d val %x\n", |
| 120 | addr, len, val); |
Alexander Graf | d86f0e3 | 2010-02-09 17:37:01 +0100 | [diff] [blame] | 121 | return val; |
| 122 | } |
| 123 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 124 | static const MemoryRegionOps unin_data_ops = { |
| 125 | .read = unin_data_read, |
| 126 | .write = unin_data_write, |
| 127 | .endianness = DEVICE_LITTLE_ENDIAN, |
| 128 | }; |
| 129 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 130 | static int pci_unin_main_init_device(SysBusDevice *dev) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 131 | { |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 132 | PCIHostState *h; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 133 | UNINState *s; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 134 | |
| 135 | /* Use values found on a real PowerMac */ |
| 136 | /* Uninorth main bus */ |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 137 | h = FROM_SYSBUS(PCIHostState, dev); |
| 138 | s = DO_UPCAST(UNINState, host_state, h); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 139 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 140 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
| 141 | &s->host_state, "pci-conf-idx", 0x1000); |
| 142 | memory_region_init_io(&s->host_state.data_mem, &unin_data_ops, s, |
| 143 | "pci-conf-data", 0x1000); |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 144 | sysbus_init_mmio(dev, &s->host_state.conf_mem); |
| 145 | sysbus_init_mmio(dev, &s->host_state.data_mem); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 146 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 147 | return 0; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 150 | |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 151 | static int pci_u3_agp_init_device(SysBusDevice *dev) |
| 152 | { |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 153 | PCIHostState *h; |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 154 | UNINState *s; |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 155 | |
| 156 | /* Uninorth U3 AGP bus */ |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 157 | h = FROM_SYSBUS(PCIHostState, dev); |
| 158 | s = DO_UPCAST(UNINState, host_state, h); |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 159 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 160 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
| 161 | &s->host_state, "pci-conf-idx", 0x1000); |
| 162 | memory_region_init_io(&s->host_state.data_mem, &unin_data_ops, s, |
| 163 | "pci-conf-data", 0x1000); |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 164 | sysbus_init_mmio(dev, &s->host_state.conf_mem); |
| 165 | sysbus_init_mmio(dev, &s->host_state.data_mem); |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 166 | |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 170 | static int pci_unin_agp_init_device(SysBusDevice *dev) |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 171 | { |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 172 | PCIHostState *h; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 173 | UNINState *s; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 174 | |
| 175 | /* Uninorth AGP bus */ |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 176 | h = FROM_SYSBUS(PCIHostState, dev); |
| 177 | s = DO_UPCAST(UNINState, host_state, h); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 178 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 179 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
| 180 | &s->host_state, "pci-conf-idx", 0x1000); |
| 181 | memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops, |
| 182 | &s->host_state, "pci-conf-data", 0x1000); |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 183 | sysbus_init_mmio(dev, &s->host_state.conf_mem); |
| 184 | sysbus_init_mmio(dev, &s->host_state.data_mem); |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 185 | return 0; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 188 | static int pci_unin_internal_init_device(SysBusDevice *dev) |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 189 | { |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 190 | PCIHostState *h; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 191 | UNINState *s; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 192 | |
| 193 | /* Uninorth internal bus */ |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 194 | h = FROM_SYSBUS(PCIHostState, dev); |
| 195 | s = DO_UPCAST(UNINState, host_state, h); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 196 | |
Avi Kivity | d0ed807 | 2011-07-24 17:47:18 +0300 | [diff] [blame] | 197 | memory_region_init_io(&s->host_state.conf_mem, &pci_host_conf_le_ops, |
| 198 | &s->host_state, "pci-conf-idx", 0x1000); |
| 199 | memory_region_init_io(&s->host_state.data_mem, &pci_host_data_le_ops, |
| 200 | &s->host_state, "pci-conf-data", 0x1000); |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 201 | sysbus_init_mmio(dev, &s->host_state.conf_mem); |
| 202 | sysbus_init_mmio(dev, &s->host_state.data_mem); |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 203 | return 0; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Avi Kivity | aee97b8 | 2011-08-08 16:09:04 +0300 | [diff] [blame] | 206 | PCIBus *pci_pmac_init(qemu_irq *pic, |
| 207 | MemoryRegion *address_space_mem, |
| 208 | MemoryRegion *address_space_io) |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 209 | { |
| 210 | DeviceState *dev; |
| 211 | SysBusDevice *s; |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 212 | PCIHostState *h; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 213 | UNINState *d; |
| 214 | |
| 215 | /* Use values found on a real PowerMac */ |
| 216 | /* Uninorth main bus */ |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 217 | dev = qdev_create(NULL, "uni-north-pci-pcihost"); |
Markus Armbruster | e23a1b3 | 2009-10-07 01:15:58 +0200 | [diff] [blame] | 218 | qdev_init_nofail(dev); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 219 | s = sysbus_from_qdev(dev); |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 220 | h = FROM_SYSBUS(PCIHostState, s); |
| 221 | d = DO_UPCAST(UNINState, host_state, h); |
Blue Swirl | 46f3069 | 2011-09-17 20:30:50 +0000 | [diff] [blame] | 222 | memory_region_init(&d->pci_mmio, "pci-mmio", 0x100000000ULL); |
| 223 | memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio, |
| 224 | 0x80000000ULL, 0x70000000ULL); |
| 225 | memory_region_add_subregion(address_space_mem, 0x80000000ULL, |
| 226 | &d->pci_hole); |
| 227 | |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 228 | d->host_state.bus = pci_register_bus(dev, "pci", |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 229 | pci_unin_set_irq, pci_unin_map_irq, |
Avi Kivity | aee97b8 | 2011-08-08 16:09:04 +0300 | [diff] [blame] | 230 | pic, |
Blue Swirl | 46f3069 | 2011-09-17 20:30:50 +0000 | [diff] [blame] | 231 | &d->pci_mmio, |
Avi Kivity | aee97b8 | 2011-08-08 16:09:04 +0300 | [diff] [blame] | 232 | address_space_io, |
Avi Kivity | 1e39101 | 2011-07-26 14:26:19 +0300 | [diff] [blame] | 233 | PCI_DEVFN(11, 0), 4); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 234 | |
Blue Swirl | 6039874 | 2009-11-15 14:30:56 +0000 | [diff] [blame] | 235 | #if 0 |
Isaku Yamahata | 520128b | 2010-06-23 16:15:25 +0900 | [diff] [blame] | 236 | pci_create_simple(d->host_state.bus, PCI_DEVFN(11, 0), "uni-north"); |
Blue Swirl | 6039874 | 2009-11-15 14:30:56 +0000 | [diff] [blame] | 237 | #endif |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 238 | |
| 239 | sysbus_mmio_map(s, 0, 0xf2800000); |
| 240 | sysbus_mmio_map(s, 1, 0xf2c00000); |
| 241 | |
| 242 | /* DEC 21154 bridge */ |
| 243 | #if 0 |
| 244 | /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */ |
Isaku Yamahata | 520128b | 2010-06-23 16:15:25 +0900 | [diff] [blame] | 245 | pci_create_simple(d->host_state.bus, PCI_DEVFN(12, 0), "dec-21154"); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 246 | #endif |
| 247 | |
| 248 | /* Uninorth AGP bus */ |
Isaku Yamahata | 520128b | 2010-06-23 16:15:25 +0900 | [diff] [blame] | 249 | pci_create_simple(d->host_state.bus, PCI_DEVFN(11, 0), "uni-north-agp"); |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 250 | dev = qdev_create(NULL, "uni-north-agp-pcihost"); |
Blue Swirl | d27d06f | 2009-11-15 17:42:17 +0000 | [diff] [blame] | 251 | qdev_init_nofail(dev); |
| 252 | s = sysbus_from_qdev(dev); |
| 253 | sysbus_mmio_map(s, 0, 0xf0800000); |
| 254 | sysbus_mmio_map(s, 1, 0xf0c00000); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 255 | |
| 256 | /* Uninorth internal bus */ |
| 257 | #if 0 |
| 258 | /* XXX: not needed for now */ |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 259 | pci_create_simple(d->host_state.bus, PCI_DEVFN(14, 0), |
| 260 | "uni-north-internal-pci"); |
| 261 | dev = qdev_create(NULL, "uni-north-internal-pci-pcihost"); |
Blue Swirl | d27d06f | 2009-11-15 17:42:17 +0000 | [diff] [blame] | 262 | qdev_init_nofail(dev); |
| 263 | s = sysbus_from_qdev(dev); |
| 264 | sysbus_mmio_map(s, 0, 0xf4800000); |
| 265 | sysbus_mmio_map(s, 1, 0xf4c00000); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 266 | #endif |
| 267 | |
| 268 | return d->host_state.bus; |
| 269 | } |
| 270 | |
Avi Kivity | aee97b8 | 2011-08-08 16:09:04 +0300 | [diff] [blame] | 271 | PCIBus *pci_pmac_u3_init(qemu_irq *pic, |
| 272 | MemoryRegion *address_space_mem, |
| 273 | MemoryRegion *address_space_io) |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 274 | { |
| 275 | DeviceState *dev; |
| 276 | SysBusDevice *s; |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 277 | PCIHostState *h; |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 278 | UNINState *d; |
| 279 | |
| 280 | /* Uninorth AGP bus */ |
| 281 | |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 282 | dev = qdev_create(NULL, "u3-agp-pcihost"); |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 283 | qdev_init_nofail(dev); |
| 284 | s = sysbus_from_qdev(dev); |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 285 | h = FROM_SYSBUS(PCIHostState, s); |
| 286 | d = DO_UPCAST(UNINState, host_state, h); |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 287 | |
Blue Swirl | 46f3069 | 2011-09-17 20:30:50 +0000 | [diff] [blame] | 288 | memory_region_init(&d->pci_mmio, "pci-mmio", 0x100000000ULL); |
| 289 | memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio, |
| 290 | 0x80000000ULL, 0x70000000ULL); |
| 291 | memory_region_add_subregion(address_space_mem, 0x80000000ULL, |
| 292 | &d->pci_hole); |
| 293 | |
Andreas Färber | ff452ac | 2012-01-19 07:40:17 +0000 | [diff] [blame] | 294 | d->host_state.bus = pci_register_bus(dev, "pci", |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 295 | pci_unin_set_irq, pci_unin_map_irq, |
Avi Kivity | aee97b8 | 2011-08-08 16:09:04 +0300 | [diff] [blame] | 296 | pic, |
Blue Swirl | 46f3069 | 2011-09-17 20:30:50 +0000 | [diff] [blame] | 297 | &d->pci_mmio, |
Avi Kivity | aee97b8 | 2011-08-08 16:09:04 +0300 | [diff] [blame] | 298 | address_space_io, |
Avi Kivity | 1e39101 | 2011-07-26 14:26:19 +0300 | [diff] [blame] | 299 | PCI_DEVFN(11, 0), 4); |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 300 | |
| 301 | sysbus_mmio_map(s, 0, 0xf0800000); |
| 302 | sysbus_mmio_map(s, 1, 0xf0c00000); |
| 303 | |
| 304 | pci_create_simple(d->host_state.bus, 11 << 3, "u3-agp"); |
| 305 | |
| 306 | return d->host_state.bus; |
| 307 | } |
| 308 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 309 | static int unin_main_pci_host_init(PCIDevice *d) |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 310 | { |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 311 | d->config[0x0C] = 0x08; // cache_line_size |
| 312 | d->config[0x0D] = 0x10; // latency_timer |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 313 | d->config[0x34] = 0x00; // capabilities_pointer |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 314 | return 0; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 315 | } |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 316 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 317 | static int unin_agp_pci_host_init(PCIDevice *d) |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 318 | { |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 319 | d->config[0x0C] = 0x08; // cache_line_size |
| 320 | d->config[0x0D] = 0x10; // latency_timer |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 321 | // d->config[0x34] = 0x80; // capabilities_pointer |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 322 | return 0; |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 323 | } |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 324 | |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 325 | static int u3_agp_pci_host_init(PCIDevice *d) |
| 326 | { |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 327 | /* cache line size */ |
| 328 | d->config[0x0C] = 0x08; |
| 329 | /* latency timer */ |
| 330 | d->config[0x0D] = 0x10; |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 334 | static int unin_internal_pci_host_init(PCIDevice *d) |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 335 | { |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 336 | d->config[0x0C] = 0x08; // cache_line_size |
| 337 | d->config[0x0D] = 0x10; // latency_timer |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 338 | d->config[0x34] = 0x00; // capabilities_pointer |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 339 | return 0; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 340 | } |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 341 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 342 | static void unin_main_pci_host_class_init(ObjectClass *klass, void *data) |
| 343 | { |
| 344 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 345 | |
| 346 | k->init = unin_main_pci_host_init; |
| 347 | k->vendor_id = PCI_VENDOR_ID_APPLE; |
| 348 | k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI; |
| 349 | k->revision = 0x00; |
| 350 | k->class_id = PCI_CLASS_BRIDGE_HOST; |
| 351 | } |
| 352 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 353 | static const TypeInfo unin_main_pci_host_info = { |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 354 | .name = "uni-north-pci", |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 355 | .parent = TYPE_PCI_DEVICE, |
| 356 | .instance_size = sizeof(PCIDevice), |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 357 | .class_init = unin_main_pci_host_class_init, |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 358 | }; |
| 359 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 360 | static void u3_agp_pci_host_class_init(ObjectClass *klass, void *data) |
| 361 | { |
| 362 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 363 | |
| 364 | k->init = u3_agp_pci_host_init; |
| 365 | k->vendor_id = PCI_VENDOR_ID_APPLE; |
| 366 | k->device_id = PCI_DEVICE_ID_APPLE_U3_AGP; |
| 367 | k->revision = 0x00; |
| 368 | k->class_id = PCI_CLASS_BRIDGE_HOST; |
| 369 | } |
| 370 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 371 | static const TypeInfo u3_agp_pci_host_info = { |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 372 | .name = "u3-agp", |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 373 | .parent = TYPE_PCI_DEVICE, |
| 374 | .instance_size = sizeof(PCIDevice), |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 375 | .class_init = u3_agp_pci_host_class_init, |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 376 | }; |
| 377 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 378 | static void unin_agp_pci_host_class_init(ObjectClass *klass, void *data) |
| 379 | { |
| 380 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 381 | |
| 382 | k->init = unin_agp_pci_host_init; |
| 383 | k->vendor_id = PCI_VENDOR_ID_APPLE; |
| 384 | k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP; |
| 385 | k->revision = 0x00; |
| 386 | k->class_id = PCI_CLASS_BRIDGE_HOST; |
| 387 | } |
| 388 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 389 | static const TypeInfo unin_agp_pci_host_info = { |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 390 | .name = "uni-north-agp", |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 391 | .parent = TYPE_PCI_DEVICE, |
| 392 | .instance_size = sizeof(PCIDevice), |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 393 | .class_init = unin_agp_pci_host_class_init, |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 394 | }; |
| 395 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 396 | static void unin_internal_pci_host_class_init(ObjectClass *klass, void *data) |
| 397 | { |
| 398 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 399 | |
| 400 | k->init = unin_internal_pci_host_init; |
| 401 | k->vendor_id = PCI_VENDOR_ID_APPLE; |
| 402 | k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_I_PCI; |
| 403 | k->revision = 0x00; |
| 404 | k->class_id = PCI_CLASS_BRIDGE_HOST; |
| 405 | } |
| 406 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 407 | static const TypeInfo unin_internal_pci_host_info = { |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 408 | .name = "uni-north-internal-pci", |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 409 | .parent = TYPE_PCI_DEVICE, |
| 410 | .instance_size = sizeof(PCIDevice), |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 411 | .class_init = unin_internal_pci_host_class_init, |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 412 | }; |
| 413 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 414 | static void pci_unin_main_class_init(ObjectClass *klass, void *data) |
| 415 | { |
| 416 | SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); |
| 417 | |
| 418 | sbc->init = pci_unin_main_init_device; |
| 419 | } |
| 420 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 421 | static const TypeInfo pci_unin_main_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 422 | .name = "uni-north-pci-pcihost", |
| 423 | .parent = TYPE_SYS_BUS_DEVICE, |
| 424 | .instance_size = sizeof(UNINState), |
| 425 | .class_init = pci_unin_main_class_init, |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 426 | }; |
| 427 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 428 | static void pci_u3_agp_class_init(ObjectClass *klass, void *data) |
| 429 | { |
| 430 | SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); |
| 431 | |
| 432 | sbc->init = pci_u3_agp_init_device; |
| 433 | } |
| 434 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 435 | static const TypeInfo pci_u3_agp_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 436 | .name = "u3-agp-pcihost", |
| 437 | .parent = TYPE_SYS_BUS_DEVICE, |
| 438 | .instance_size = sizeof(UNINState), |
| 439 | .class_init = pci_u3_agp_class_init, |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 440 | }; |
| 441 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 442 | static void pci_unin_agp_class_init(ObjectClass *klass, void *data) |
| 443 | { |
| 444 | SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); |
| 445 | |
| 446 | sbc->init = pci_unin_agp_init_device; |
| 447 | } |
| 448 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 449 | static const TypeInfo pci_unin_agp_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 450 | .name = "uni-north-agp-pcihost", |
| 451 | .parent = TYPE_SYS_BUS_DEVICE, |
| 452 | .instance_size = sizeof(UNINState), |
| 453 | .class_init = pci_unin_agp_class_init, |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 454 | }; |
| 455 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 456 | static void pci_unin_internal_class_init(ObjectClass *klass, void *data) |
| 457 | { |
| 458 | SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); |
| 459 | |
| 460 | sbc->init = pci_unin_internal_init_device; |
| 461 | } |
| 462 | |
Andreas Färber | 4240abf | 2012-08-20 19:07:56 +0200 | [diff] [blame^] | 463 | static const TypeInfo pci_unin_internal_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 464 | .name = "uni-north-internal-pci-pcihost", |
| 465 | .parent = TYPE_SYS_BUS_DEVICE, |
| 466 | .instance_size = sizeof(UNINState), |
| 467 | .class_init = pci_unin_internal_class_init, |
Andreas Färber | 70f9c98 | 2012-01-19 07:40:16 +0000 | [diff] [blame] | 468 | }; |
| 469 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 470 | static void unin_register_types(void) |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 471 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 472 | type_register_static(&unin_main_pci_host_info); |
| 473 | type_register_static(&u3_agp_pci_host_info); |
| 474 | type_register_static(&unin_agp_pci_host_info); |
| 475 | type_register_static(&unin_internal_pci_host_info); |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 476 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 477 | type_register_static(&pci_unin_main_info); |
| 478 | type_register_static(&pci_u3_agp_info); |
| 479 | type_register_static(&pci_unin_agp_info); |
| 480 | type_register_static(&pci_unin_internal_info); |
Blue Swirl | 2e29bd0 | 2009-07-31 20:23:28 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 483 | type_init(unin_register_types) |