pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Ultrasparc APB PCI host |
| 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 | 80b3ada | 2006-09-24 17:01:44 +0000 | [diff] [blame] | 24 | |
blueswir1 | a94fd95 | 2009-01-09 20:53:30 +0000 | [diff] [blame] | 25 | /* XXX This file and most of its contents are somewhat misnamed. The |
pbrook | 80b3ada | 2006-09-24 17:01:44 +0000 | [diff] [blame] | 26 | Ultrasparc PCI host is called the PCI Bus Module (PBM). The APB is |
| 27 | the secondary PCI bridge. */ |
| 28 | |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 29 | #include "sysbus.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 30 | #include "pci.h" |
Isaku Yamahata | 4f5e19e | 2009-10-30 21:21:06 +0900 | [diff] [blame] | 31 | #include "pci_host.h" |
Isaku Yamahata | 783753f | 2010-07-13 13:01:39 +0900 | [diff] [blame] | 32 | #include "pci_bridge.h" |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 33 | #include "pci_internals.h" |
Michael S. Tsirkin | 18e08a5 | 2009-11-11 14:59:56 +0200 | [diff] [blame] | 34 | #include "apb_pci.h" |
Markus Armbruster | 666daa6 | 2010-06-02 18:48:27 +0200 | [diff] [blame] | 35 | #include "sysemu.h" |
Avi Kivity | 1e39101 | 2011-07-26 14:26:19 +0300 | [diff] [blame] | 36 | #include "exec-memory.h" |
blueswir1 | a94fd95 | 2009-01-09 20:53:30 +0000 | [diff] [blame] | 37 | |
| 38 | /* debug APB */ |
| 39 | //#define DEBUG_APB |
| 40 | |
| 41 | #ifdef DEBUG_APB |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 42 | #define APB_DPRINTF(fmt, ...) \ |
| 43 | do { printf("APB: " fmt , ## __VA_ARGS__); } while (0) |
blueswir1 | a94fd95 | 2009-01-09 20:53:30 +0000 | [diff] [blame] | 44 | #else |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 45 | #define APB_DPRINTF(fmt, ...) |
blueswir1 | a94fd95 | 2009-01-09 20:53:30 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
Blue Swirl | 930f3fe | 2009-10-13 18:56:27 +0000 | [diff] [blame] | 48 | /* |
| 49 | * Chipset docs: |
| 50 | * PBM: "UltraSPARC IIi User's Manual", |
| 51 | * http://www.sun.com/processors/manuals/805-0087.pdf |
| 52 | * |
| 53 | * APB: "Advanced PCI Bridge (APB) User's Manual", |
| 54 | * http://www.sun.com/processors/manuals/805-1251.pdf |
| 55 | */ |
| 56 | |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 57 | #define PBM_PCI_IMR_MASK 0x7fffffff |
| 58 | #define PBM_PCI_IMR_ENABLED 0x80000000 |
| 59 | |
| 60 | #define POR (1 << 31) |
| 61 | #define SOFT_POR (1 << 30) |
| 62 | #define SOFT_XIR (1 << 29) |
| 63 | #define BTN_POR (1 << 28) |
| 64 | #define BTN_XIR (1 << 27) |
| 65 | #define RESET_MASK 0xf8000000 |
| 66 | #define RESET_WCMASK 0x98000000 |
| 67 | #define RESET_WMASK 0x60000000 |
| 68 | |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 69 | typedef struct APBState { |
| 70 | SysBusDevice busdev; |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 71 | PCIBus *bus; |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 72 | MemoryRegion apb_config; |
| 73 | MemoryRegion pci_config; |
Blue Swirl | f69539b | 2011-09-03 16:38:02 +0000 | [diff] [blame] | 74 | MemoryRegion pci_mmio; |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 75 | MemoryRegion pci_ioport; |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 76 | uint32_t iommu[4]; |
| 77 | uint32_t pci_control[16]; |
| 78 | uint32_t pci_irq_map[8]; |
| 79 | uint32_t obio_irq_map[32]; |
| 80 | qemu_irq pci_irqs[32]; |
| 81 | uint32_t reset_control; |
Blue Swirl | 9c0afd0 | 2010-05-12 19:27:23 +0000 | [diff] [blame] | 82 | unsigned int nr_resets; |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 83 | } APBState; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 84 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 85 | static void apb_config_writel (void *opaque, target_phys_addr_t addr, |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 86 | uint64_t val, unsigned size) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 87 | { |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 88 | APBState *s = opaque; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 89 | |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 90 | APB_DPRINTF("%s: addr " TARGET_FMT_lx " val %x\n", __func__, addr, val); |
| 91 | |
| 92 | switch (addr & 0xffff) { |
| 93 | case 0x30 ... 0x4f: /* DMA error registers */ |
| 94 | /* XXX: not implemented yet */ |
| 95 | break; |
| 96 | case 0x200 ... 0x20b: /* IOMMU */ |
| 97 | s->iommu[(addr & 0xf) >> 2] = val; |
| 98 | break; |
| 99 | case 0x20c ... 0x3ff: /* IOMMU flush */ |
| 100 | break; |
| 101 | case 0xc00 ... 0xc3f: /* PCI interrupt control */ |
| 102 | if (addr & 4) { |
| 103 | s->pci_irq_map[(addr & 0x3f) >> 3] &= PBM_PCI_IMR_MASK; |
| 104 | s->pci_irq_map[(addr & 0x3f) >> 3] |= val & ~PBM_PCI_IMR_MASK; |
| 105 | } |
| 106 | break; |
| 107 | case 0x2000 ... 0x202f: /* PCI control */ |
| 108 | s->pci_control[(addr & 0x3f) >> 2] = val; |
| 109 | break; |
| 110 | case 0xf020 ... 0xf027: /* Reset control */ |
| 111 | if (addr & 4) { |
| 112 | val &= RESET_MASK; |
| 113 | s->reset_control &= ~(val & RESET_WCMASK); |
| 114 | s->reset_control |= val & RESET_WMASK; |
| 115 | if (val & SOFT_POR) { |
Blue Swirl | 9c0afd0 | 2010-05-12 19:27:23 +0000 | [diff] [blame] | 116 | s->nr_resets = 0; |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 117 | qemu_system_reset_request(); |
| 118 | } else if (val & SOFT_XIR) { |
| 119 | qemu_system_reset_request(); |
| 120 | } |
| 121 | } |
| 122 | break; |
| 123 | case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */ |
| 124 | case 0xa400 ... 0xa67f: /* IOMMU diagnostics */ |
| 125 | case 0xa800 ... 0xa80f: /* Interrupt diagnostics */ |
| 126 | case 0xf000 ... 0xf01f: /* FFB config, memory control */ |
| 127 | /* we don't care */ |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 128 | default: |
blueswir1 | f930d07 | 2007-10-06 11:28:21 +0000 | [diff] [blame] | 129 | break; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 133 | static uint64_t apb_config_readl (void *opaque, |
| 134 | target_phys_addr_t addr, unsigned size) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 135 | { |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 136 | APBState *s = opaque; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 137 | uint32_t val; |
| 138 | |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 139 | switch (addr & 0xffff) { |
| 140 | case 0x30 ... 0x4f: /* DMA error registers */ |
| 141 | val = 0; |
| 142 | /* XXX: not implemented yet */ |
| 143 | break; |
| 144 | case 0x200 ... 0x20b: /* IOMMU */ |
| 145 | val = s->iommu[(addr & 0xf) >> 2]; |
| 146 | break; |
| 147 | case 0x20c ... 0x3ff: /* IOMMU flush */ |
| 148 | val = 0; |
| 149 | break; |
| 150 | case 0xc00 ... 0xc3f: /* PCI interrupt control */ |
| 151 | if (addr & 4) { |
| 152 | val = s->pci_irq_map[(addr & 0x3f) >> 3]; |
| 153 | } else { |
| 154 | val = 0; |
| 155 | } |
| 156 | break; |
| 157 | case 0x2000 ... 0x202f: /* PCI control */ |
| 158 | val = s->pci_control[(addr & 0x3f) >> 2]; |
| 159 | break; |
| 160 | case 0xf020 ... 0xf027: /* Reset control */ |
| 161 | if (addr & 4) { |
| 162 | val = s->reset_control; |
| 163 | } else { |
| 164 | val = 0; |
| 165 | } |
| 166 | break; |
| 167 | case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */ |
| 168 | case 0xa400 ... 0xa67f: /* IOMMU diagnostics */ |
| 169 | case 0xa800 ... 0xa80f: /* Interrupt diagnostics */ |
| 170 | case 0xf000 ... 0xf01f: /* FFB config, memory control */ |
| 171 | /* we don't care */ |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 172 | default: |
blueswir1 | f930d07 | 2007-10-06 11:28:21 +0000 | [diff] [blame] | 173 | val = 0; |
| 174 | break; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 175 | } |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 176 | APB_DPRINTF("%s: addr " TARGET_FMT_lx " -> %x\n", __func__, addr, val); |
| 177 | |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 178 | return val; |
| 179 | } |
| 180 | |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 181 | static const MemoryRegionOps apb_config_ops = { |
| 182 | .read = apb_config_readl, |
| 183 | .write = apb_config_writel, |
| 184 | .endianness = DEVICE_NATIVE_ENDIAN, |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 187 | static void apb_pci_config_write(void *opaque, target_phys_addr_t addr, |
| 188 | uint64_t val, unsigned size) |
Blue Swirl | 5a5d4a7 | 2010-01-11 21:20:53 +0000 | [diff] [blame] | 189 | { |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 190 | APBState *s = opaque; |
Michael S. Tsirkin | 63e6f31 | 2010-02-22 12:38:25 +0200 | [diff] [blame] | 191 | |
| 192 | val = qemu_bswap_len(val, size); |
Blue Swirl | 5a5d4a7 | 2010-01-11 21:20:53 +0000 | [diff] [blame] | 193 | APB_DPRINTF("%s: addr " TARGET_FMT_lx " val %x\n", __func__, addr, val); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 194 | pci_data_write(s->bus, addr, val, size); |
Blue Swirl | 5a5d4a7 | 2010-01-11 21:20:53 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 197 | static uint64_t apb_pci_config_read(void *opaque, target_phys_addr_t addr, |
| 198 | unsigned size) |
Blue Swirl | 5a5d4a7 | 2010-01-11 21:20:53 +0000 | [diff] [blame] | 199 | { |
| 200 | uint32_t ret; |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 201 | APBState *s = opaque; |
Blue Swirl | 5a5d4a7 | 2010-01-11 21:20:53 +0000 | [diff] [blame] | 202 | |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 203 | ret = pci_data_read(s->bus, addr, size); |
Michael S. Tsirkin | 63e6f31 | 2010-02-22 12:38:25 +0200 | [diff] [blame] | 204 | ret = qemu_bswap_len(ret, size); |
Blue Swirl | 5a5d4a7 | 2010-01-11 21:20:53 +0000 | [diff] [blame] | 205 | APB_DPRINTF("%s: addr " TARGET_FMT_lx " -> %x\n", __func__, addr, ret); |
| 206 | return ret; |
| 207 | } |
| 208 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 209 | static void pci_apb_iowriteb (void *opaque, target_phys_addr_t addr, |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 210 | uint32_t val) |
| 211 | { |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 212 | cpu_outb(addr & IOPORTS_MASK, val); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 215 | static void pci_apb_iowritew (void *opaque, target_phys_addr_t addr, |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 216 | uint32_t val) |
| 217 | { |
Blue Swirl | a4d5f62 | 2010-01-29 18:15:21 +0000 | [diff] [blame] | 218 | cpu_outw(addr & IOPORTS_MASK, bswap16(val)); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 221 | static void pci_apb_iowritel (void *opaque, target_phys_addr_t addr, |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 222 | uint32_t val) |
| 223 | { |
Blue Swirl | a4d5f62 | 2010-01-29 18:15:21 +0000 | [diff] [blame] | 224 | cpu_outl(addr & IOPORTS_MASK, bswap32(val)); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 227 | static uint32_t pci_apb_ioreadb (void *opaque, target_phys_addr_t addr) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 228 | { |
| 229 | uint32_t val; |
| 230 | |
Blue Swirl | afcea8c | 2009-09-20 16:05:47 +0000 | [diff] [blame] | 231 | val = cpu_inb(addr & IOPORTS_MASK); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 232 | return val; |
| 233 | } |
| 234 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 235 | static uint32_t pci_apb_ioreadw (void *opaque, target_phys_addr_t addr) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 236 | { |
| 237 | uint32_t val; |
| 238 | |
Blue Swirl | a4d5f62 | 2010-01-29 18:15:21 +0000 | [diff] [blame] | 239 | val = bswap16(cpu_inw(addr & IOPORTS_MASK)); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 240 | return val; |
| 241 | } |
| 242 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 243 | static uint32_t pci_apb_ioreadl (void *opaque, target_phys_addr_t addr) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 244 | { |
| 245 | uint32_t val; |
| 246 | |
Blue Swirl | a4d5f62 | 2010-01-29 18:15:21 +0000 | [diff] [blame] | 247 | val = bswap32(cpu_inl(addr & IOPORTS_MASK)); |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 248 | return val; |
| 249 | } |
| 250 | |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 251 | static const MemoryRegionOps pci_ioport_ops = { |
| 252 | .old_mmio = { |
| 253 | .read = { pci_apb_ioreadb, pci_apb_ioreadw, pci_apb_ioreadl }, |
| 254 | .write = { pci_apb_iowriteb, pci_apb_iowritew, pci_apb_iowritel, }, |
| 255 | }, |
| 256 | .endianness = DEVICE_NATIVE_ENDIAN, |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 257 | }; |
| 258 | |
pbrook | 80b3ada | 2006-09-24 17:01:44 +0000 | [diff] [blame] | 259 | /* The APB host has an IRQ line for each IRQ line of each slot. */ |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 260 | static int pci_apb_map_irq(PCIDevice *pci_dev, int irq_num) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 261 | { |
pbrook | 80b3ada | 2006-09-24 17:01:44 +0000 | [diff] [blame] | 262 | return ((pci_dev->devfn & 0x18) >> 1) + irq_num; |
| 263 | } |
| 264 | |
| 265 | static int pci_pbm_map_irq(PCIDevice *pci_dev, int irq_num) |
| 266 | { |
| 267 | int bus_offset; |
| 268 | if (pci_dev->devfn & 1) |
| 269 | bus_offset = 16; |
| 270 | else |
| 271 | bus_offset = 0; |
| 272 | return bus_offset + irq_num; |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Juan Quintela | 5d4e84c | 2009-08-28 15:28:17 +0200 | [diff] [blame] | 275 | static void pci_apb_set_irq(void *opaque, int irq_num, int level) |
pbrook | d2b5931 | 2006-09-24 00:16:34 +0000 | [diff] [blame] | 276 | { |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 277 | APBState *s = opaque; |
Juan Quintela | 5d4e84c | 2009-08-28 15:28:17 +0200 | [diff] [blame] | 278 | |
pbrook | 80b3ada | 2006-09-24 17:01:44 +0000 | [diff] [blame] | 279 | /* PCI IRQ map onto the first 32 INO. */ |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 280 | if (irq_num < 32) { |
| 281 | if (s->pci_irq_map[irq_num >> 2] & PBM_PCI_IMR_ENABLED) { |
| 282 | APB_DPRINTF("%s: set irq %d level %d\n", __func__, irq_num, level); |
| 283 | qemu_set_irq(s->pci_irqs[irq_num], level); |
| 284 | } else { |
| 285 | APB_DPRINTF("%s: not enabled: lower irq %d\n", __func__, irq_num); |
| 286 | qemu_irq_lower(s->pci_irqs[irq_num]); |
| 287 | } |
| 288 | } |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 291 | static int apb_pci_bridge_initfn(PCIDevice *dev) |
Michael S. Tsirkin | d631873 | 2009-11-11 14:33:54 +0200 | [diff] [blame] | 292 | { |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 293 | int rc; |
| 294 | |
| 295 | rc = pci_bridge_initfn(dev); |
| 296 | if (rc < 0) { |
| 297 | return rc; |
| 298 | } |
| 299 | |
Michael S. Tsirkin | d631873 | 2009-11-11 14:33:54 +0200 | [diff] [blame] | 300 | /* |
| 301 | * command register: |
| 302 | * According to PCI bridge spec, after reset |
| 303 | * bus master bit is off |
| 304 | * memory space enable bit is off |
| 305 | * According to manual (805-1251.pdf). |
| 306 | * the reset value should be zero unless the boot pin is tied high |
| 307 | * (which is true) and thus it should be PCI_COMMAND_MEMORY. |
| 308 | */ |
| 309 | pci_set_word(dev->config + PCI_COMMAND, |
Blue Swirl | 9fe52c7 | 2010-02-14 08:27:19 +0000 | [diff] [blame] | 310 | PCI_COMMAND_MEMORY); |
| 311 | pci_set_word(dev->config + PCI_STATUS, |
| 312 | PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ | |
| 313 | PCI_STATUS_DEVSEL_MEDIUM); |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 314 | return 0; |
Michael S. Tsirkin | d631873 | 2009-11-11 14:33:54 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 317 | PCIBus *pci_apb_init(target_phys_addr_t special_base, |
| 318 | target_phys_addr_t mem_base, |
blueswir1 | c190ea0 | 2009-01-10 11:33:32 +0000 | [diff] [blame] | 319 | qemu_irq *pic, PCIBus **bus2, PCIBus **bus3) |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 320 | { |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 321 | DeviceState *dev; |
| 322 | SysBusDevice *s; |
| 323 | APBState *d; |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 324 | unsigned int i; |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 325 | PCIDevice *pci_dev; |
| 326 | PCIBridge *br; |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 327 | |
| 328 | /* Ultrasparc PBM main bus */ |
| 329 | dev = qdev_create(NULL, "pbm"); |
Markus Armbruster | e23a1b3 | 2009-10-07 01:15:58 +0200 | [diff] [blame] | 330 | qdev_init_nofail(dev); |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 331 | s = sysbus_from_qdev(dev); |
| 332 | /* apb_config */ |
Blue Swirl | bae7b51 | 2010-01-10 18:25:48 +0000 | [diff] [blame] | 333 | sysbus_mmio_map(s, 0, special_base); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 334 | /* PCI configuration space */ |
| 335 | sysbus_mmio_map(s, 1, special_base + 0x1000000ULL); |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 336 | /* pci_ioport */ |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 337 | sysbus_mmio_map(s, 2, special_base + 0x2000000ULL); |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 338 | d = FROM_SYSBUS(APBState, s); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 339 | |
Blue Swirl | f69539b | 2011-09-03 16:38:02 +0000 | [diff] [blame] | 340 | memory_region_init(&d->pci_mmio, "pci-mmio", 0x100000000ULL); |
| 341 | memory_region_add_subregion(get_system_memory(), mem_base, &d->pci_mmio); |
| 342 | |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 343 | d->bus = pci_register_bus(&d->busdev.qdev, "pci", |
Blue Swirl | f69539b | 2011-09-03 16:38:02 +0000 | [diff] [blame] | 344 | pci_apb_set_irq, pci_pbm_map_irq, d, |
| 345 | &d->pci_mmio, |
| 346 | get_system_io(), |
| 347 | 0, 32); |
Blue Swirl | f6b6f1b | 2009-12-27 20:52:39 +0000 | [diff] [blame] | 348 | |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 349 | for (i = 0; i < 32; i++) { |
| 350 | sysbus_connect_irq(s, i, pic[i]); |
| 351 | } |
| 352 | |
Anthony Liguori | 7309335 | 2012-01-25 13:37:36 -0600 | [diff] [blame] | 353 | pci_create_simple(d->bus, 0, "pbm-pci"); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 354 | |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 355 | /* APB secondary busses */ |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 356 | pci_dev = pci_create_multifunction(d->bus, PCI_DEVFN(1, 0), true, |
| 357 | "pbm-bridge"); |
| 358 | br = DO_UPCAST(PCIBridge, dev, pci_dev); |
| 359 | pci_bridge_map_irq(br, "Advanced PCI Bus secondary bridge 1", |
| 360 | pci_apb_map_irq); |
| 361 | qdev_init_nofail(&pci_dev->qdev); |
| 362 | *bus2 = pci_bridge_get_sec_bus(br); |
Michael S. Tsirkin | d631873 | 2009-11-11 14:33:54 +0200 | [diff] [blame] | 363 | |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 364 | pci_dev = pci_create_multifunction(d->bus, PCI_DEVFN(1, 1), true, |
| 365 | "pbm-bridge"); |
| 366 | br = DO_UPCAST(PCIBridge, dev, pci_dev); |
| 367 | pci_bridge_map_irq(br, "Advanced PCI Bus secondary bridge 2", |
| 368 | pci_apb_map_irq); |
| 369 | qdev_init_nofail(&pci_dev->qdev); |
| 370 | *bus3 = pci_bridge_get_sec_bus(br); |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 371 | |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 372 | return d->bus; |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 375 | static void pci_pbm_reset(DeviceState *d) |
| 376 | { |
| 377 | unsigned int i; |
| 378 | APBState *s = container_of(d, APBState, busdev.qdev); |
| 379 | |
| 380 | for (i = 0; i < 8; i++) { |
| 381 | s->pci_irq_map[i] &= PBM_PCI_IMR_MASK; |
| 382 | } |
| 383 | |
Blue Swirl | 9c0afd0 | 2010-05-12 19:27:23 +0000 | [diff] [blame] | 384 | if (s->nr_resets++ == 0) { |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 385 | /* Power on reset */ |
| 386 | s->reset_control = POR; |
| 387 | } |
| 388 | } |
| 389 | |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 390 | static const MemoryRegionOps pci_config_ops = { |
| 391 | .read = apb_pci_config_read, |
| 392 | .write = apb_pci_config_write, |
| 393 | .endianness = DEVICE_NATIVE_ENDIAN, |
| 394 | }; |
| 395 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 396 | static int pci_pbm_init_device(SysBusDevice *dev) |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 397 | { |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 398 | APBState *s; |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 399 | unsigned int i; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 400 | |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 401 | s = FROM_SYSBUS(APBState, dev); |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 402 | for (i = 0; i < 8; i++) { |
| 403 | s->pci_irq_map[i] = (0x1f << 6) | (i << 2); |
| 404 | } |
| 405 | for (i = 0; i < 32; i++) { |
| 406 | sysbus_init_irq(dev, &s->pci_irqs[i]); |
| 407 | } |
| 408 | |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 409 | /* apb_config */ |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 410 | memory_region_init_io(&s->apb_config, &apb_config_ops, s, "apb-config", |
| 411 | 0x10000); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 412 | /* at region 0 */ |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 413 | sysbus_init_mmio(dev, &s->apb_config); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 414 | |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 415 | memory_region_init_io(&s->pci_config, &pci_config_ops, s, "apb-pci-config", |
| 416 | 0x1000000); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 417 | /* at region 1 */ |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 418 | sysbus_init_mmio(dev, &s->pci_config); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 419 | |
| 420 | /* pci_ioport */ |
Avi Kivity | 3812ed0 | 2011-08-15 17:17:15 +0300 | [diff] [blame] | 421 | memory_region_init_io(&s->pci_ioport, &pci_ioport_ops, s, |
| 422 | "apb-pci-ioport", 0x10000); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 423 | /* at region 2 */ |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 424 | sysbus_init_mmio(dev, &s->pci_ioport); |
Igor V. Kovalenko | d63baf9 | 2010-05-25 16:09:03 +0400 | [diff] [blame] | 425 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 426 | return 0; |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 427 | } |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 428 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 429 | static int pbm_pci_host_init(PCIDevice *d) |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 430 | { |
Blue Swirl | 9fe52c7 | 2010-02-14 08:27:19 +0000 | [diff] [blame] | 431 | pci_set_word(d->config + PCI_COMMAND, |
| 432 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
| 433 | pci_set_word(d->config + PCI_STATUS, |
| 434 | PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ | |
| 435 | PCI_STATUS_DEVSEL_MEDIUM); |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 436 | return 0; |
pbrook | 502a539 | 2006-05-13 16:11:23 +0000 | [diff] [blame] | 437 | } |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 438 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 439 | static void pbm_pci_host_class_init(ObjectClass *klass, void *data) |
| 440 | { |
| 441 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 442 | |
| 443 | k->init = pbm_pci_host_init; |
| 444 | k->vendor_id = PCI_VENDOR_ID_SUN; |
| 445 | k->device_id = PCI_DEVICE_ID_SUN_SABRE; |
| 446 | k->class_id = PCI_CLASS_BRIDGE_HOST; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 447 | } |
| 448 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 449 | static TypeInfo pbm_pci_host_info = { |
| 450 | .name = "pbm-pci", |
| 451 | .parent = TYPE_PCI_DEVICE, |
| 452 | .instance_size = sizeof(PCIDevice), |
| 453 | .class_init = pbm_pci_host_class_init, |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 454 | }; |
| 455 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 456 | static void pbm_host_class_init(ObjectClass *klass, void *data) |
| 457 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 458 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 459 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
| 460 | |
| 461 | k->init = pci_pbm_init_device; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 462 | dc->reset = pci_pbm_reset; |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 463 | } |
| 464 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 465 | static TypeInfo pbm_host_info = { |
| 466 | .name = "pbm", |
| 467 | .parent = TYPE_SYS_BUS_DEVICE, |
| 468 | .instance_size = sizeof(APBState), |
| 469 | .class_init = pbm_host_class_init, |
Blue Swirl | 95819af | 2010-01-30 19:48:12 +0000 | [diff] [blame] | 470 | }; |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 471 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 472 | static void pbm_pci_bridge_class_init(ObjectClass *klass, void *data) |
| 473 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 474 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 475 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 476 | |
| 477 | k->init = apb_pci_bridge_initfn; |
| 478 | k->exit = pci_bridge_exitfn; |
| 479 | k->vendor_id = PCI_VENDOR_ID_SUN; |
| 480 | k->device_id = PCI_DEVICE_ID_SUN_SIMBA; |
| 481 | k->revision = 0x11; |
| 482 | k->config_write = pci_bridge_write_config; |
| 483 | k->is_bridge = 1; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 484 | dc->reset = pci_bridge_reset; |
| 485 | dc->vmsd = &vmstate_pci_device; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 486 | } |
| 487 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 488 | static TypeInfo pbm_pci_bridge_info = { |
| 489 | .name = "pbm-bridge", |
| 490 | .parent = TYPE_PCI_DEVICE, |
| 491 | .instance_size = sizeof(PCIBridge), |
| 492 | .class_init = pbm_pci_bridge_class_init, |
Isaku Yamahata | 68f7999 | 2010-07-13 13:01:42 +0900 | [diff] [blame] | 493 | }; |
| 494 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 495 | static void pbm_register_types(void) |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 496 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 497 | type_register_static(&pbm_host_info); |
| 498 | type_register_static(&pbm_pci_host_info); |
| 499 | type_register_static(&pbm_pci_bridge_info); |
Blue Swirl | 72f44c8 | 2009-07-21 08:36:37 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 502 | type_init(pbm_register_types) |