]>
Commit | Line | Data |
---|---|---|
502a5395 | 1 | /* |
9b301794 | 2 | * QEMU Ultrasparc Sabre PCI host (PBM) |
502a5395 PB |
3 | * |
4 | * Copyright (c) 2006 Fabrice Bellard | |
9625036d | 5 | * Copyright (c) 2012,2013 Artyom Tarasenko |
9b301794 | 6 | * Copyright (c) 2018 Mark Cave-Ayland |
5fafdf24 | 7 | * |
502a5395 PB |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
24 | * THE SOFTWARE. | |
25 | */ | |
80b3ada7 | 26 | |
97d5408f | 27 | #include "qemu/osdep.h" |
83c9f4ca PB |
28 | #include "hw/sysbus.h" |
29 | #include "hw/pci/pci.h" | |
30 | #include "hw/pci/pci_host.h" | |
a27bd6c7 | 31 | #include "hw/qdev-properties.h" |
83c9f4ca PB |
32 | #include "hw/pci/pci_bridge.h" |
33 | #include "hw/pci/pci_bus.h" | |
64552b6b | 34 | #include "hw/irq.h" |
ffd9589e | 35 | #include "hw/pci-bridge/simba.h" |
9b301794 | 36 | #include "hw/pci-host/sabre.h" |
9307d06d | 37 | #include "qapi/error.h" |
03dd024f | 38 | #include "qemu/log.h" |
0b8fa32f | 39 | #include "qemu/module.h" |
54d31236 | 40 | #include "sysemu/runstate.h" |
bfec08b5 | 41 | #include "trace.h" |
a94fd955 | 42 | |
930f3fe1 BS |
43 | /* |
44 | * Chipset docs: | |
45 | * PBM: "UltraSPARC IIi User's Manual", | |
c092bfe5 | 46 | * https://web.archive.org/web/20030403110020/http://www.sun.com/processors/manuals/805-0087.pdf |
930f3fe1 BS |
47 | */ |
48 | ||
95819af0 BS |
49 | #define PBM_PCI_IMR_MASK 0x7fffffff |
50 | #define PBM_PCI_IMR_ENABLED 0x80000000 | |
51 | ||
af23906d PM |
52 | #define POR (1U << 31) |
53 | #define SOFT_POR (1U << 30) | |
54 | #define SOFT_XIR (1U << 29) | |
55 | #define BTN_POR (1U << 28) | |
56 | #define BTN_XIR (1U << 27) | |
95819af0 BS |
57 | #define RESET_MASK 0xf8000000 |
58 | #define RESET_WCMASK 0x98000000 | |
59 | #define RESET_WMASK 0x60000000 | |
60 | ||
9625036d | 61 | #define NO_IRQ_REQUEST (MAX_IVEC + 1) |
361dea40 | 62 | |
b14dcaf4 | 63 | static inline void sabre_set_request(SabreState *s, unsigned int irq_num) |
9625036d | 64 | { |
bfec08b5 | 65 | trace_sabre_set_request(irq_num); |
9625036d AT |
66 | s->irq_request = irq_num; |
67 | qemu_set_irq(s->ivec_irqs[irq_num], 1); | |
68 | } | |
69 | ||
b14dcaf4 | 70 | static inline void sabre_check_irqs(SabreState *s) |
9625036d | 71 | { |
9625036d AT |
72 | unsigned int i; |
73 | ||
74 | /* Previous request is not acknowledged, resubmit */ | |
75 | if (s->irq_request != NO_IRQ_REQUEST) { | |
fe984c7d | 76 | sabre_set_request(s, s->irq_request); |
9625036d AT |
77 | return; |
78 | } | |
79 | /* no request pending */ | |
80 | if (s->pci_irq_in == 0ULL) { | |
81 | return; | |
82 | } | |
83 | for (i = 0; i < 32; i++) { | |
84 | if (s->pci_irq_in & (1ULL << i)) { | |
85 | if (s->pci_irq_map[i >> 2] & PBM_PCI_IMR_ENABLED) { | |
fe984c7d | 86 | sabre_set_request(s, i); |
9625036d AT |
87 | return; |
88 | } | |
89 | } | |
90 | } | |
91 | for (i = 32; i < 64; i++) { | |
92 | if (s->pci_irq_in & (1ULL << i)) { | |
93 | if (s->obio_irq_map[i - 32] & PBM_PCI_IMR_ENABLED) { | |
fe984c7d | 94 | sabre_set_request(s, i); |
9625036d AT |
95 | break; |
96 | } | |
97 | } | |
98 | } | |
99 | } | |
100 | ||
b14dcaf4 | 101 | static inline void sabre_clear_request(SabreState *s, unsigned int irq_num) |
9625036d | 102 | { |
bfec08b5 | 103 | trace_sabre_clear_request(irq_num); |
9625036d AT |
104 | qemu_set_irq(s->ivec_irqs[irq_num], 0); |
105 | s->irq_request = NO_IRQ_REQUEST; | |
106 | } | |
94d19914 | 107 | |
fe984c7d | 108 | static AddressSpace *sabre_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn) |
ae74bbe7 MCA |
109 | { |
110 | IOMMUState *is = opaque; | |
111 | ||
112 | return &is->iommu_as; | |
113 | } | |
114 | ||
fe984c7d | 115 | static void sabre_config_write(void *opaque, hwaddr addr, |
3812ed0b | 116 | uint64_t val, unsigned size) |
502a5395 | 117 | { |
b14dcaf4 | 118 | SabreState *s = opaque; |
95819af0 | 119 | |
bfec08b5 | 120 | trace_sabre_config_write(addr, val); |
95819af0 | 121 | |
a0376c03 | 122 | switch (addr) { |
95819af0 BS |
123 | case 0x30 ... 0x4f: /* DMA error registers */ |
124 | /* XXX: not implemented yet */ | |
125 | break; | |
95819af0 BS |
126 | case 0xc00 ... 0xc3f: /* PCI interrupt control */ |
127 | if (addr & 4) { | |
9625036d AT |
128 | unsigned int ino = (addr & 0x3f) >> 3; |
129 | s->pci_irq_map[ino] &= PBM_PCI_IMR_MASK; | |
130 | s->pci_irq_map[ino] |= val & ~PBM_PCI_IMR_MASK; | |
131 | if ((s->irq_request == ino) && !(val & ~PBM_PCI_IMR_MASK)) { | |
fe984c7d | 132 | sabre_clear_request(s, ino); |
9625036d | 133 | } |
fe984c7d | 134 | sabre_check_irqs(s); |
95819af0 BS |
135 | } |
136 | break; | |
de739df8 | 137 | case 0x1000 ... 0x107f: /* OBIO interrupt control */ |
361dea40 | 138 | if (addr & 4) { |
9625036d AT |
139 | unsigned int ino = ((addr & 0xff) >> 3); |
140 | s->obio_irq_map[ino] &= PBM_PCI_IMR_MASK; | |
141 | s->obio_irq_map[ino] |= val & ~PBM_PCI_IMR_MASK; | |
142 | if ((s->irq_request == (ino | 0x20)) | |
143 | && !(val & ~PBM_PCI_IMR_MASK)) { | |
fe984c7d | 144 | sabre_clear_request(s, ino | 0x20); |
9625036d | 145 | } |
fe984c7d | 146 | sabre_check_irqs(s); |
361dea40 BS |
147 | } |
148 | break; | |
9625036d | 149 | case 0x1400 ... 0x14ff: /* PCI interrupt clear */ |
94d19914 | 150 | if (addr & 4) { |
9625036d AT |
151 | unsigned int ino = (addr & 0xff) >> 5; |
152 | if ((s->irq_request / 4) == ino) { | |
fe984c7d MCA |
153 | sabre_clear_request(s, s->irq_request); |
154 | sabre_check_irqs(s); | |
9625036d | 155 | } |
94d19914 AT |
156 | } |
157 | break; | |
158 | case 0x1800 ... 0x1860: /* OBIO interrupt clear */ | |
159 | if (addr & 4) { | |
9625036d AT |
160 | unsigned int ino = ((addr & 0xff) >> 3) | 0x20; |
161 | if (s->irq_request == ino) { | |
fe984c7d MCA |
162 | sabre_clear_request(s, ino); |
163 | sabre_check_irqs(s); | |
9625036d | 164 | } |
94d19914 AT |
165 | } |
166 | break; | |
95819af0 BS |
167 | case 0x2000 ... 0x202f: /* PCI control */ |
168 | s->pci_control[(addr & 0x3f) >> 2] = val; | |
169 | break; | |
170 | case 0xf020 ... 0xf027: /* Reset control */ | |
171 | if (addr & 4) { | |
172 | val &= RESET_MASK; | |
173 | s->reset_control &= ~(val & RESET_WCMASK); | |
174 | s->reset_control |= val & RESET_WMASK; | |
175 | if (val & SOFT_POR) { | |
9c0afd0e | 176 | s->nr_resets = 0; |
cf83f140 | 177 | qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); |
95819af0 | 178 | } else if (val & SOFT_XIR) { |
cf83f140 | 179 | qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); |
95819af0 BS |
180 | } |
181 | } | |
182 | break; | |
183 | case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */ | |
184 | case 0xa400 ... 0xa67f: /* IOMMU diagnostics */ | |
185 | case 0xa800 ... 0xa80f: /* Interrupt diagnostics */ | |
186 | case 0xf000 ... 0xf01f: /* FFB config, memory control */ | |
187 | /* we don't care */ | |
502a5395 | 188 | default: |
f930d07e | 189 | break; |
502a5395 PB |
190 | } |
191 | } | |
192 | ||
fe984c7d | 193 | static uint64_t sabre_config_read(void *opaque, |
a8170e5e | 194 | hwaddr addr, unsigned size) |
502a5395 | 195 | { |
b14dcaf4 | 196 | SabreState *s = opaque; |
0980307e | 197 | uint32_t val = 0; |
502a5395 | 198 | |
a0376c03 | 199 | switch (addr) { |
95819af0 | 200 | case 0x30 ... 0x4f: /* DMA error registers */ |
95819af0 BS |
201 | /* XXX: not implemented yet */ |
202 | break; | |
95819af0 BS |
203 | case 0xc00 ... 0xc3f: /* PCI interrupt control */ |
204 | if (addr & 4) { | |
205 | val = s->pci_irq_map[(addr & 0x3f) >> 3]; | |
95819af0 BS |
206 | } |
207 | break; | |
de739df8 | 208 | case 0x1000 ... 0x107f: /* OBIO interrupt control */ |
361dea40 BS |
209 | if (addr & 4) { |
210 | val = s->obio_irq_map[(addr & 0xff) >> 3]; | |
361dea40 BS |
211 | } |
212 | break; | |
de739df8 MCA |
213 | case 0x1080 ... 0x108f: /* PCI bus error */ |
214 | if (addr & 4) { | |
215 | val = s->pci_err_irq_map[(addr & 0xf) >> 3]; | |
de739df8 MCA |
216 | } |
217 | break; | |
95819af0 BS |
218 | case 0x2000 ... 0x202f: /* PCI control */ |
219 | val = s->pci_control[(addr & 0x3f) >> 2]; | |
220 | break; | |
221 | case 0xf020 ... 0xf027: /* Reset control */ | |
222 | if (addr & 4) { | |
223 | val = s->reset_control; | |
95819af0 BS |
224 | } |
225 | break; | |
226 | case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */ | |
227 | case 0xa400 ... 0xa67f: /* IOMMU diagnostics */ | |
228 | case 0xa800 ... 0xa80f: /* Interrupt diagnostics */ | |
229 | case 0xf000 ... 0xf01f: /* FFB config, memory control */ | |
230 | /* we don't care */ | |
502a5395 | 231 | default: |
f930d07e | 232 | break; |
502a5395 | 233 | } |
bfec08b5 | 234 | trace_sabre_config_read(addr, val); |
95819af0 | 235 | |
502a5395 PB |
236 | return val; |
237 | } | |
238 | ||
fe984c7d MCA |
239 | static const MemoryRegionOps sabre_config_ops = { |
240 | .read = sabre_config_read, | |
241 | .write = sabre_config_write, | |
b2f9005a | 242 | .endianness = DEVICE_BIG_ENDIAN, |
502a5395 PB |
243 | }; |
244 | ||
fe984c7d MCA |
245 | static void sabre_pci_config_write(void *opaque, hwaddr addr, |
246 | uint64_t val, unsigned size) | |
5a5d4a76 | 247 | { |
b14dcaf4 | 248 | SabreState *s = opaque; |
2b8fbcd8 | 249 | PCIHostState *phb = PCI_HOST_BRIDGE(s); |
63e6f31d | 250 | |
bfec08b5 | 251 | trace_sabre_pci_config_write(addr, val); |
2b8fbcd8 | 252 | pci_data_write(phb->bus, addr, val, size); |
5a5d4a76 BS |
253 | } |
254 | ||
fe984c7d MCA |
255 | static uint64_t sabre_pci_config_read(void *opaque, hwaddr addr, |
256 | unsigned size) | |
5a5d4a76 BS |
257 | { |
258 | uint32_t ret; | |
b14dcaf4 | 259 | SabreState *s = opaque; |
2b8fbcd8 | 260 | PCIHostState *phb = PCI_HOST_BRIDGE(s); |
5a5d4a76 | 261 | |
2b8fbcd8 | 262 | ret = pci_data_read(phb->bus, addr, size); |
bfec08b5 | 263 | trace_sabre_pci_config_read(addr, ret); |
5a5d4a76 BS |
264 | return ret; |
265 | } | |
266 | ||
fe984c7d MCA |
267 | /* The sabre host has an IRQ line for each IRQ line of each slot. */ |
268 | static int pci_sabre_map_irq(PCIDevice *pci_dev, int irq_num) | |
502a5395 | 269 | { |
6864fa38 MCA |
270 | /* Return the irq as swizzled by the PBM */ |
271 | return irq_num; | |
80b3ada7 PB |
272 | } |
273 | ||
90302ada | 274 | static int pci_simbaA_map_irq(PCIDevice *pci_dev, int irq_num) |
80b3ada7 | 275 | { |
d9e4d682 MCA |
276 | /* The on-board devices have fixed (legacy) OBIO intnos */ |
277 | switch (PCI_SLOT(pci_dev->devfn)) { | |
278 | case 1: | |
279 | /* Onboard NIC */ | |
a5546222 | 280 | return OBIO_NIC_IRQ; |
d9e4d682 MCA |
281 | case 3: |
282 | /* Onboard IDE */ | |
a5546222 | 283 | return OBIO_HDD_IRQ; |
d9e4d682 MCA |
284 | default: |
285 | /* Normal intno, fall through */ | |
286 | break; | |
6864fa38 | 287 | } |
6864fa38 | 288 | |
d9e4d682 MCA |
289 | return ((PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f; |
290 | } | |
6864fa38 | 291 | |
90302ada | 292 | static int pci_simbaB_map_irq(PCIDevice *pci_dev, int irq_num) |
d9e4d682 MCA |
293 | { |
294 | return (0x10 + (PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f; | |
d2b59317 PB |
295 | } |
296 | ||
fe984c7d | 297 | static void pci_sabre_set_irq(void *opaque, int irq_num, int level) |
d2b59317 | 298 | { |
b14dcaf4 | 299 | SabreState *s = opaque; |
5d4e84c8 | 300 | |
bfec08b5 MCA |
301 | trace_sabre_pci_set_irq(irq_num, level); |
302 | ||
80b3ada7 | 303 | /* PCI IRQ map onto the first 32 INO. */ |
95819af0 | 304 | if (irq_num < 32) { |
9625036d AT |
305 | if (level) { |
306 | s->pci_irq_in |= 1ULL << irq_num; | |
307 | if (s->pci_irq_map[irq_num >> 2] & PBM_PCI_IMR_ENABLED) { | |
fe984c7d | 308 | sabre_set_request(s, irq_num); |
9625036d | 309 | } |
361dea40 | 310 | } else { |
9625036d | 311 | s->pci_irq_in &= ~(1ULL << irq_num); |
361dea40 BS |
312 | } |
313 | } else { | |
9625036d AT |
314 | /* OBIO IRQ map onto the next 32 INO. */ |
315 | if (level) { | |
bfec08b5 | 316 | trace_sabre_pci_set_obio_irq(irq_num, level); |
9625036d AT |
317 | s->pci_irq_in |= 1ULL << irq_num; |
318 | if ((s->irq_request == NO_IRQ_REQUEST) | |
319 | && (s->obio_irq_map[irq_num - 32] & PBM_PCI_IMR_ENABLED)) { | |
fe984c7d | 320 | sabre_set_request(s, irq_num); |
9625036d | 321 | } |
95819af0 | 322 | } else { |
9625036d | 323 | s->pci_irq_in &= ~(1ULL << irq_num); |
95819af0 BS |
324 | } |
325 | } | |
502a5395 PB |
326 | } |
327 | ||
fe984c7d | 328 | static void sabre_reset(DeviceState *d) |
72f44c8c | 329 | { |
5b07883c | 330 | SabreState *s = SABRE(d); |
33c5eb02 MCA |
331 | PCIDevice *pci_dev; |
332 | unsigned int i; | |
333 | uint16_t cmd; | |
72f44c8c | 334 | |
95819af0 BS |
335 | for (i = 0; i < 8; i++) { |
336 | s->pci_irq_map[i] &= PBM_PCI_IMR_MASK; | |
337 | } | |
d1d80055 AT |
338 | for (i = 0; i < 32; i++) { |
339 | s->obio_irq_map[i] &= PBM_PCI_IMR_MASK; | |
340 | } | |
95819af0 | 341 | |
9625036d AT |
342 | s->irq_request = NO_IRQ_REQUEST; |
343 | s->pci_irq_in = 0ULL; | |
344 | ||
9c0afd0e | 345 | if (s->nr_resets++ == 0) { |
95819af0 BS |
346 | /* Power on reset */ |
347 | s->reset_control = POR; | |
348 | } | |
33c5eb02 MCA |
349 | |
350 | /* As this is the busA PCI bridge which contains the on-board devices | |
351 | * attached to the ebus, ensure that we initially allow IO transactions | |
352 | * so that we get the early serial console until OpenBIOS can properly | |
353 | * configure the PCI bridge itself */ | |
354 | pci_dev = PCI_DEVICE(s->bridgeA); | |
355 | cmd = pci_get_word(pci_dev->config + PCI_COMMAND); | |
356 | pci_set_word(pci_dev->config + PCI_COMMAND, cmd | PCI_COMMAND_IO); | |
357 | pci_bridge_update_mappings(PCI_BRIDGE(pci_dev)); | |
95819af0 BS |
358 | } |
359 | ||
3812ed0b | 360 | static const MemoryRegionOps pci_config_ops = { |
fe984c7d MCA |
361 | .read = sabre_pci_config_read, |
362 | .write = sabre_pci_config_write, | |
b2f9005a | 363 | .endianness = DEVICE_LITTLE_ENDIAN, |
3812ed0b AK |
364 | }; |
365 | ||
fe984c7d | 366 | static void sabre_realize(DeviceState *dev, Error **errp) |
95819af0 | 367 | { |
5b07883c | 368 | SabreState *s = SABRE(dev); |
cacd0580 | 369 | PCIHostState *phb = PCI_HOST_BRIDGE(dev); |
68f79994 | 370 | PCIDevice *pci_dev; |
502a5395 | 371 | |
cacd0580 MCA |
372 | memory_region_init(&s->pci_mmio, OBJECT(s), "pci-mmio", 0x100000000ULL); |
373 | memory_region_add_subregion(get_system_memory(), s->mem_base, | |
374 | &s->pci_mmio); | |
375 | ||
acc95bc8 | 376 | phb->bus = pci_register_root_bus(dev, "pci", |
fe984c7d | 377 | pci_sabre_set_irq, pci_sabre_map_irq, s, |
acc95bc8 MT |
378 | &s->pci_mmio, |
379 | &s->pci_ioport, | |
ef905eff | 380 | 0, 0x40, TYPE_PCI_BUS); |
f69539b1 | 381 | |
8fb28035 | 382 | pci_create_simple(phb->bus, 0, TYPE_SABRE_PCI_DEVICE); |
d63baf92 | 383 | |
fe984c7d | 384 | /* IOMMU */ |
9b301794 | 385 | memory_region_add_subregion_overlap(&s->sabre_config, 0x200, |
aea5b071 | 386 | sysbus_mmio_get_region(SYS_BUS_DEVICE(s->iommu), 0), 1); |
fe984c7d | 387 | pci_setup_iommu(phb->bus, sabre_pci_dma_iommu, s->iommu); |
ae74bbe7 | 388 | |
72f44c8c | 389 | /* APB secondary busses */ |
c925f40a | 390 | pci_dev = pci_new_multifunction(PCI_DEVFN(1, 0), TYPE_SIMBA_PCI_BRIDGE); |
cacd0580 | 391 | s->bridgeB = PCI_BRIDGE(pci_dev); |
90302ada | 392 | pci_bridge_map_irq(s->bridgeB, "pciB", pci_simbaB_map_irq); |
9307d06d | 393 | pci_realize_and_unref(pci_dev, phb->bus, &error_fatal); |
68f79994 | 394 | |
c925f40a | 395 | pci_dev = pci_new_multifunction(PCI_DEVFN(1, 1), TYPE_SIMBA_PCI_BRIDGE); |
cacd0580 | 396 | s->bridgeA = PCI_BRIDGE(pci_dev); |
90302ada | 397 | pci_bridge_map_irq(s->bridgeA, "pciA", pci_simbaA_map_irq); |
9307d06d | 398 | pci_realize_and_unref(pci_dev, phb->bus, &error_fatal); |
95819af0 BS |
399 | } |
400 | ||
fe984c7d | 401 | static void sabre_init(Object *obj) |
95819af0 | 402 | { |
5b07883c | 403 | SabreState *s = SABRE(obj); |
cacd0580 | 404 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
95819af0 | 405 | unsigned int i; |
72f44c8c | 406 | |
95819af0 BS |
407 | for (i = 0; i < 8; i++) { |
408 | s->pci_irq_map[i] = (0x1f << 6) | (i << 2); | |
409 | } | |
de739df8 MCA |
410 | for (i = 0; i < 2; i++) { |
411 | s->pci_err_irq_map[i] = (0x1f << 6) | 0x30; | |
412 | } | |
d1d80055 AT |
413 | for (i = 0; i < 32; i++) { |
414 | s->obio_irq_map[i] = ((0x1f << 6) | 0x20) + i; | |
415 | } | |
fe984c7d | 416 | qdev_init_gpio_in_named(DEVICE(s), pci_sabre_set_irq, "pbm-irq", MAX_IVEC); |
2a4d6af5 | 417 | qdev_init_gpio_out_named(DEVICE(s), s->ivec_irqs, "ivec-irq", MAX_IVEC); |
9625036d AT |
418 | s->irq_request = NO_IRQ_REQUEST; |
419 | s->pci_irq_in = 0ULL; | |
95819af0 | 420 | |
aea5b071 MCA |
421 | /* IOMMU */ |
422 | object_property_add_link(obj, "iommu", TYPE_SUN4U_IOMMU, | |
423 | (Object **) &s->iommu, | |
424 | qdev_prop_allow_set_link_before_realize, | |
d2623129 | 425 | 0); |
aea5b071 | 426 | |
9b301794 MCA |
427 | /* sabre_config */ |
428 | memory_region_init_io(&s->sabre_config, OBJECT(s), &sabre_config_ops, s, | |
429 | "sabre-config", 0x10000); | |
d63baf92 | 430 | /* at region 0 */ |
9b301794 | 431 | sysbus_init_mmio(sbd, &s->sabre_config); |
d63baf92 | 432 | |
40c5dce9 | 433 | memory_region_init_io(&s->pci_config, OBJECT(s), &pci_config_ops, s, |
9b301794 | 434 | "sabre-pci-config", 0x1000000); |
d63baf92 | 435 | /* at region 1 */ |
b26f4419 | 436 | sysbus_init_mmio(sbd, &s->pci_config); |
d63baf92 IK |
437 | |
438 | /* pci_ioport */ | |
9b301794 MCA |
439 | memory_region_init(&s->pci_ioport, OBJECT(s), "sabre-pci-ioport", |
440 | 0x1000000); | |
6864fa38 | 441 | |
d63baf92 | 442 | /* at region 2 */ |
b26f4419 | 443 | sysbus_init_mmio(sbd, &s->pci_ioport); |
72f44c8c | 444 | } |
502a5395 | 445 | |
5560c58a | 446 | static void sabre_pci_realize(PCIDevice *d, Error **errp) |
72f44c8c | 447 | { |
9fe52c7f BS |
448 | pci_set_word(d->config + PCI_COMMAND, |
449 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); | |
450 | pci_set_word(d->config + PCI_STATUS, | |
451 | PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ | | |
452 | PCI_STATUS_DEVSEL_MEDIUM); | |
72f44c8c | 453 | } |
80b3ada7 | 454 | |
5560c58a | 455 | static void sabre_pci_class_init(ObjectClass *klass, void *data) |
40021f08 AL |
456 | { |
457 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); | |
08c58f92 | 458 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 | 459 | |
5560c58a | 460 | k->realize = sabre_pci_realize; |
40021f08 AL |
461 | k->vendor_id = PCI_VENDOR_ID_SUN; |
462 | k->device_id = PCI_DEVICE_ID_SUN_SABRE; | |
463 | k->class_id = PCI_CLASS_BRIDGE_HOST; | |
08c58f92 MA |
464 | /* |
465 | * PCI-facing part of the host bridge, not usable without the | |
466 | * host-facing part, which can't be device_add'ed, yet. | |
467 | */ | |
e90f2a8c | 468 | dc->user_creatable = false; |
40021f08 AL |
469 | } |
470 | ||
5560c58a | 471 | static const TypeInfo sabre_pci_info = { |
8fb28035 | 472 | .name = TYPE_SABRE_PCI_DEVICE, |
39bffca2 | 473 | .parent = TYPE_PCI_DEVICE, |
8fb28035 | 474 | .instance_size = sizeof(SabrePCIState), |
5560c58a | 475 | .class_init = sabre_pci_class_init, |
fd3b02c8 EH |
476 | .interfaces = (InterfaceInfo[]) { |
477 | { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | |
478 | { }, | |
479 | }, | |
72f44c8c BS |
480 | }; |
481 | ||
09af820e MCA |
482 | static char *sabre_ofw_unit_address(const SysBusDevice *dev) |
483 | { | |
5b07883c | 484 | SabreState *s = SABRE(dev); |
09af820e MCA |
485 | |
486 | return g_strdup_printf("%x,%x", | |
487 | (uint32_t)((s->special_base >> 32) & 0xffffffff), | |
488 | (uint32_t)(s->special_base & 0xffffffff)); | |
489 | } | |
490 | ||
fe984c7d | 491 | static Property sabre_properties[] = { |
b14dcaf4 MCA |
492 | DEFINE_PROP_UINT64("special-base", SabreState, special_base, 0), |
493 | DEFINE_PROP_UINT64("mem-base", SabreState, mem_base, 0), | |
cacd0580 MCA |
494 | DEFINE_PROP_END_OF_LIST(), |
495 | }; | |
496 | ||
fe984c7d | 497 | static void sabre_class_init(ObjectClass *klass, void *data) |
999e12bb | 498 | { |
39bffca2 | 499 | DeviceClass *dc = DEVICE_CLASS(klass); |
09af820e | 500 | SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); |
999e12bb | 501 | |
fe984c7d MCA |
502 | dc->realize = sabre_realize; |
503 | dc->reset = sabre_reset; | |
4f67d30b | 504 | device_class_set_props(dc, sabre_properties); |
b26f4419 | 505 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
09af820e MCA |
506 | dc->fw_name = "pci"; |
507 | sbc->explicit_ofw_unit_address = sabre_ofw_unit_address; | |
999e12bb AL |
508 | } |
509 | ||
fe984c7d | 510 | static const TypeInfo sabre_info = { |
b14dcaf4 | 511 | .name = TYPE_SABRE, |
2b8fbcd8 | 512 | .parent = TYPE_PCI_HOST_BRIDGE, |
b14dcaf4 | 513 | .instance_size = sizeof(SabreState), |
fe984c7d MCA |
514 | .instance_init = sabre_init, |
515 | .class_init = sabre_class_init, | |
95819af0 | 516 | }; |
68f79994 | 517 | |
fe984c7d | 518 | static void sabre_register_types(void) |
72f44c8c | 519 | { |
fe984c7d | 520 | type_register_static(&sabre_info); |
5560c58a | 521 | type_register_static(&sabre_pci_info); |
502a5395 | 522 | } |
72f44c8c | 523 | |
fe984c7d | 524 | type_init(sabre_register_types) |