root / hw / piix_pci.c @ b31442c3
History | View | Annotate | Download (12.1 kB)
1 | 502a5395 | pbrook | /*
|
---|---|---|---|
2 | 502a5395 | pbrook | * QEMU i440FX/PIIX3 PCI Bridge Emulation
|
3 | 502a5395 | pbrook | *
|
4 | 502a5395 | pbrook | * Copyright (c) 2006 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 502a5395 | pbrook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 502a5395 | pbrook | * of this software and associated documentation files (the "Software"), to deal
|
8 | 502a5395 | pbrook | * in the Software without restriction, including without limitation the rights
|
9 | 502a5395 | pbrook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 502a5395 | pbrook | * copies of the Software, and to permit persons to whom the Software is
|
11 | 502a5395 | pbrook | * furnished to do so, subject to the following conditions:
|
12 | 502a5395 | pbrook | *
|
13 | 502a5395 | pbrook | * The above copyright notice and this permission notice shall be included in
|
14 | 502a5395 | pbrook | * all copies or substantial portions of the Software.
|
15 | 502a5395 | pbrook | *
|
16 | 502a5395 | pbrook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 502a5395 | pbrook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 502a5395 | pbrook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 502a5395 | pbrook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 502a5395 | pbrook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 502a5395 | pbrook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 502a5395 | pbrook | * THE SOFTWARE.
|
23 | 502a5395 | pbrook | */
|
24 | 502a5395 | pbrook | |
25 | 87ecb68b | pbrook | #include "hw.h" |
26 | 87ecb68b | pbrook | #include "pc.h" |
27 | 87ecb68b | pbrook | #include "pci.h" |
28 | f75247f1 | Gerd Hoffmann | #include "isa.h" |
29 | 8a14daa5 | Gerd Hoffmann | #include "sysbus.h" |
30 | 87ecb68b | pbrook | |
31 | 502a5395 | pbrook | typedef uint32_t pci_addr_t;
|
32 | 502a5395 | pbrook | #include "pci_host.h" |
33 | 502a5395 | pbrook | |
34 | 502a5395 | pbrook | typedef PCIHostState I440FXState;
|
35 | 502a5395 | pbrook | |
36 | 502a5395 | pbrook | static void i440fx_addr_writel(void* opaque, uint32_t addr, uint32_t val) |
37 | 502a5395 | pbrook | { |
38 | 502a5395 | pbrook | I440FXState *s = opaque; |
39 | 502a5395 | pbrook | s->config_reg = val; |
40 | 502a5395 | pbrook | } |
41 | 502a5395 | pbrook | |
42 | 502a5395 | pbrook | static uint32_t i440fx_addr_readl(void* opaque, uint32_t addr) |
43 | 502a5395 | pbrook | { |
44 | 502a5395 | pbrook | I440FXState *s = opaque; |
45 | 502a5395 | pbrook | return s->config_reg;
|
46 | 502a5395 | pbrook | } |
47 | 502a5395 | pbrook | |
48 | d537cf6c | pbrook | static void piix3_set_irq(qemu_irq *pic, int irq_num, int level); |
49 | d2b59317 | pbrook | |
50 | d2b59317 | pbrook | /* return the global irq number corresponding to a given device irq
|
51 | d2b59317 | pbrook | pin. We could also use the bus number to have a more precise
|
52 | d2b59317 | pbrook | mapping. */
|
53 | d2b59317 | pbrook | static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num) |
54 | d2b59317 | pbrook | { |
55 | d2b59317 | pbrook | int slot_addend;
|
56 | d2b59317 | pbrook | slot_addend = (pci_dev->devfn >> 3) - 1; |
57 | d2b59317 | pbrook | return (irq_num + slot_addend) & 3; |
58 | d2b59317 | pbrook | } |
59 | 502a5395 | pbrook | |
60 | 00f82b8a | aurel32 | static target_phys_addr_t isa_page_descs[384 / 4]; |
61 | ee0ea1d0 | bellard | static uint8_t smm_enabled;
|
62 | 52fc1d83 | balrog | static int pci_irq_levels[4]; |
63 | ee0ea1d0 | bellard | |
64 | 84631fd7 | bellard | static void update_pam(PCIDevice *d, uint32_t start, uint32_t end, int r) |
65 | 84631fd7 | bellard | { |
66 | 84631fd7 | bellard | uint32_t addr; |
67 | 84631fd7 | bellard | |
68 | 84631fd7 | bellard | // printf("ISA mapping %08x-0x%08x: %d\n", start, end, r);
|
69 | 84631fd7 | bellard | switch(r) {
|
70 | 84631fd7 | bellard | case 3: |
71 | 84631fd7 | bellard | /* RAM */
|
72 | 5fafdf24 | ths | cpu_register_physical_memory(start, end - start, |
73 | 84631fd7 | bellard | start); |
74 | 84631fd7 | bellard | break;
|
75 | 84631fd7 | bellard | case 1: |
76 | 84631fd7 | bellard | /* ROM (XXX: not quite correct) */
|
77 | 5fafdf24 | ths | cpu_register_physical_memory(start, end - start, |
78 | 84631fd7 | bellard | start | IO_MEM_ROM); |
79 | 84631fd7 | bellard | break;
|
80 | 84631fd7 | bellard | case 2: |
81 | 84631fd7 | bellard | case 0: |
82 | 84631fd7 | bellard | /* XXX: should distinguish read/write cases */
|
83 | 84631fd7 | bellard | for(addr = start; addr < end; addr += 4096) { |
84 | 5fafdf24 | ths | cpu_register_physical_memory(addr, 4096,
|
85 | 84631fd7 | bellard | isa_page_descs[(addr - 0xa0000) >> 12]); |
86 | 84631fd7 | bellard | } |
87 | 84631fd7 | bellard | break;
|
88 | 84631fd7 | bellard | } |
89 | 84631fd7 | bellard | } |
90 | ee0ea1d0 | bellard | |
91 | ee0ea1d0 | bellard | static void i440fx_update_memory_mappings(PCIDevice *d) |
92 | ee0ea1d0 | bellard | { |
93 | ee0ea1d0 | bellard | int i, r;
|
94 | 84631fd7 | bellard | uint32_t smram, addr; |
95 | 84631fd7 | bellard | |
96 | 84631fd7 | bellard | update_pam(d, 0xf0000, 0x100000, (d->config[0x59] >> 4) & 3); |
97 | 84631fd7 | bellard | for(i = 0; i < 12; i++) { |
98 | 84631fd7 | bellard | r = (d->config[(i >> 1) + 0x5a] >> ((i & 1) * 4)) & 3; |
99 | 84631fd7 | bellard | update_pam(d, 0xc0000 + 0x4000 * i, 0xc0000 + 0x4000 * (i + 1), r); |
100 | ee0ea1d0 | bellard | } |
101 | 84631fd7 | bellard | smram = d->config[0x72];
|
102 | 84631fd7 | bellard | if ((smm_enabled && (smram & 0x08)) || (smram & 0x40)) { |
103 | 84631fd7 | bellard | cpu_register_physical_memory(0xa0000, 0x20000, 0xa0000); |
104 | 84631fd7 | bellard | } else {
|
105 | 84631fd7 | bellard | for(addr = 0xa0000; addr < 0xc0000; addr += 4096) { |
106 | 5fafdf24 | ths | cpu_register_physical_memory(addr, 4096,
|
107 | 84631fd7 | bellard | isa_page_descs[(addr - 0xa0000) >> 12]); |
108 | ee0ea1d0 | bellard | } |
109 | ee0ea1d0 | bellard | } |
110 | ee0ea1d0 | bellard | } |
111 | ee0ea1d0 | bellard | |
112 | ee0ea1d0 | bellard | void i440fx_set_smm(PCIDevice *d, int val) |
113 | ee0ea1d0 | bellard | { |
114 | ee0ea1d0 | bellard | val = (val != 0);
|
115 | ee0ea1d0 | bellard | if (smm_enabled != val) {
|
116 | ee0ea1d0 | bellard | smm_enabled = val; |
117 | ee0ea1d0 | bellard | i440fx_update_memory_mappings(d); |
118 | ee0ea1d0 | bellard | } |
119 | ee0ea1d0 | bellard | } |
120 | ee0ea1d0 | bellard | |
121 | ee0ea1d0 | bellard | |
122 | ee0ea1d0 | bellard | /* XXX: suppress when better memory API. We make the assumption that
|
123 | ee0ea1d0 | bellard | no device (in particular the VGA) changes the memory mappings in
|
124 | ee0ea1d0 | bellard | the 0xa0000-0x100000 range */
|
125 | ee0ea1d0 | bellard | void i440fx_init_memory_mappings(PCIDevice *d)
|
126 | ee0ea1d0 | bellard | { |
127 | ee0ea1d0 | bellard | int i;
|
128 | ee0ea1d0 | bellard | for(i = 0; i < 96; i++) { |
129 | ee0ea1d0 | bellard | isa_page_descs[i] = cpu_get_physical_page_desc(0xa0000 + i * 0x1000); |
130 | ee0ea1d0 | bellard | } |
131 | ee0ea1d0 | bellard | } |
132 | ee0ea1d0 | bellard | |
133 | 5fafdf24 | ths | static void i440fx_write_config(PCIDevice *d, |
134 | ee0ea1d0 | bellard | uint32_t address, uint32_t val, int len)
|
135 | ee0ea1d0 | bellard | { |
136 | ee0ea1d0 | bellard | /* XXX: implement SMRAM.D_LOCK */
|
137 | ee0ea1d0 | bellard | pci_default_write_config(d, address, val, len); |
138 | 84631fd7 | bellard | if ((address >= 0x59 && address <= 0x5f) || address == 0x72) |
139 | ee0ea1d0 | bellard | i440fx_update_memory_mappings(d); |
140 | ee0ea1d0 | bellard | } |
141 | ee0ea1d0 | bellard | |
142 | ee0ea1d0 | bellard | static void i440fx_save(QEMUFile* f, void *opaque) |
143 | ee0ea1d0 | bellard | { |
144 | ee0ea1d0 | bellard | PCIDevice *d = opaque; |
145 | 52fc1d83 | balrog | int i;
|
146 | 52fc1d83 | balrog | |
147 | ee0ea1d0 | bellard | pci_device_save(d, f); |
148 | ee0ea1d0 | bellard | qemu_put_8s(f, &smm_enabled); |
149 | 52fc1d83 | balrog | |
150 | 52fc1d83 | balrog | for (i = 0; i < 4; i++) |
151 | 52fc1d83 | balrog | qemu_put_be32(f, pci_irq_levels[i]); |
152 | ee0ea1d0 | bellard | } |
153 | ee0ea1d0 | bellard | |
154 | ee0ea1d0 | bellard | static int i440fx_load(QEMUFile* f, void *opaque, int version_id) |
155 | ee0ea1d0 | bellard | { |
156 | ee0ea1d0 | bellard | PCIDevice *d = opaque; |
157 | 52fc1d83 | balrog | int ret, i;
|
158 | ee0ea1d0 | bellard | |
159 | 52fc1d83 | balrog | if (version_id > 2) |
160 | ee0ea1d0 | bellard | return -EINVAL;
|
161 | ee0ea1d0 | bellard | ret = pci_device_load(d, f); |
162 | ee0ea1d0 | bellard | if (ret < 0) |
163 | ee0ea1d0 | bellard | return ret;
|
164 | ee0ea1d0 | bellard | i440fx_update_memory_mappings(d); |
165 | ee0ea1d0 | bellard | qemu_get_8s(f, &smm_enabled); |
166 | 52fc1d83 | balrog | |
167 | 52fc1d83 | balrog | if (version_id >= 2) |
168 | 52fc1d83 | balrog | for (i = 0; i < 4; i++) |
169 | 52fc1d83 | balrog | pci_irq_levels[i] = qemu_get_be32(f); |
170 | 52fc1d83 | balrog | |
171 | ee0ea1d0 | bellard | return 0; |
172 | ee0ea1d0 | bellard | } |
173 | ee0ea1d0 | bellard | |
174 | 8a14daa5 | Gerd Hoffmann | static void i440fx_pcihost_initfn(SysBusDevice *dev) |
175 | 502a5395 | pbrook | { |
176 | 8a14daa5 | Gerd Hoffmann | I440FXState *s = FROM_SYSBUS(I440FXState, dev); |
177 | 502a5395 | pbrook | |
178 | 502a5395 | pbrook | register_ioport_write(0xcf8, 4, 4, i440fx_addr_writel, s); |
179 | 502a5395 | pbrook | register_ioport_read(0xcf8, 4, 4, i440fx_addr_readl, s); |
180 | 502a5395 | pbrook | |
181 | 502a5395 | pbrook | register_ioport_write(0xcfc, 4, 1, pci_host_data_writeb, s); |
182 | 502a5395 | pbrook | register_ioport_write(0xcfc, 4, 2, pci_host_data_writew, s); |
183 | 502a5395 | pbrook | register_ioport_write(0xcfc, 4, 4, pci_host_data_writel, s); |
184 | 502a5395 | pbrook | register_ioport_read(0xcfc, 4, 1, pci_host_data_readb, s); |
185 | 502a5395 | pbrook | register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s); |
186 | 502a5395 | pbrook | register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s); |
187 | 8a14daa5 | Gerd Hoffmann | } |
188 | 502a5395 | pbrook | |
189 | 8a14daa5 | Gerd Hoffmann | static void i440fx_initfn(PCIDevice *d) |
190 | 8a14daa5 | Gerd Hoffmann | { |
191 | deb54399 | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_INTEL); |
192 | deb54399 | aliguori | pci_config_set_device_id(d->config, PCI_DEVICE_ID_INTEL_82441); |
193 | 502a5395 | pbrook | d->config[0x08] = 0x02; // revision |
194 | 173a543b | blueswir1 | pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); |
195 | 6407f373 | Isaku Yamahata | d->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
196 | ee0ea1d0 | bellard | |
197 | 84631fd7 | bellard | d->config[0x72] = 0x02; /* SMRAM */ |
198 | ee0ea1d0 | bellard | |
199 | 52fc1d83 | balrog | register_savevm("I440FX", 0, 2, i440fx_save, i440fx_load, d); |
200 | 8a14daa5 | Gerd Hoffmann | } |
201 | 8a14daa5 | Gerd Hoffmann | |
202 | 8a14daa5 | Gerd Hoffmann | PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic) |
203 | 8a14daa5 | Gerd Hoffmann | { |
204 | 8a14daa5 | Gerd Hoffmann | DeviceState *dev; |
205 | 8a14daa5 | Gerd Hoffmann | PCIBus *b; |
206 | 8a14daa5 | Gerd Hoffmann | PCIDevice *d; |
207 | 8a14daa5 | Gerd Hoffmann | I440FXState *s; |
208 | 8a14daa5 | Gerd Hoffmann | |
209 | 8a14daa5 | Gerd Hoffmann | dev = qdev_create(NULL, "i440FX-pcihost"); |
210 | 8a14daa5 | Gerd Hoffmann | s = FROM_SYSBUS(I440FXState, sysbus_from_qdev(dev)); |
211 | 8a14daa5 | Gerd Hoffmann | b = pci_register_bus(&s->busdev.qdev, "pci.0",
|
212 | 8a14daa5 | Gerd Hoffmann | piix3_set_irq, pci_slot_get_pirq, pic, 0, 4); |
213 | 8a14daa5 | Gerd Hoffmann | s->bus = b; |
214 | 8a14daa5 | Gerd Hoffmann | qdev_init(dev); |
215 | 8a14daa5 | Gerd Hoffmann | |
216 | 8a14daa5 | Gerd Hoffmann | d = pci_create_simple(b, 0, "i440FX"); |
217 | ee0ea1d0 | bellard | *pi440fx_state = d; |
218 | 8a14daa5 | Gerd Hoffmann | |
219 | 502a5395 | pbrook | return b;
|
220 | 502a5395 | pbrook | } |
221 | 502a5395 | pbrook | |
222 | 502a5395 | pbrook | /* PIIX3 PCI to ISA bridge */
|
223 | 502a5395 | pbrook | |
224 | b1d8e52e | blueswir1 | static PCIDevice *piix3_dev;
|
225 | 5c2b87e3 | ths | PCIDevice *piix4_dev; |
226 | 502a5395 | pbrook | |
227 | d537cf6c | pbrook | static void piix3_set_irq(qemu_irq *pic, int irq_num, int level) |
228 | 502a5395 | pbrook | { |
229 | d2b59317 | pbrook | int i, pic_irq, pic_level;
|
230 | 502a5395 | pbrook | |
231 | d2b59317 | pbrook | pci_irq_levels[irq_num] = level; |
232 | 502a5395 | pbrook | |
233 | 502a5395 | pbrook | /* now we change the pic irq level according to the piix irq mappings */
|
234 | 502a5395 | pbrook | /* XXX: optimize */
|
235 | 502a5395 | pbrook | pic_irq = piix3_dev->config[0x60 + irq_num];
|
236 | 502a5395 | pbrook | if (pic_irq < 16) { |
237 | d2b59317 | pbrook | /* The pic level is the logical OR of all the PCI irqs mapped
|
238 | 502a5395 | pbrook | to it */
|
239 | 502a5395 | pbrook | pic_level = 0;
|
240 | d2b59317 | pbrook | for (i = 0; i < 4; i++) { |
241 | d2b59317 | pbrook | if (pic_irq == piix3_dev->config[0x60 + i]) |
242 | d2b59317 | pbrook | pic_level |= pci_irq_levels[i]; |
243 | d2b59317 | pbrook | } |
244 | d537cf6c | pbrook | qemu_set_irq(pic[pic_irq], pic_level); |
245 | 502a5395 | pbrook | } |
246 | 502a5395 | pbrook | } |
247 | 502a5395 | pbrook | |
248 | 15a1956a | Gleb Natapov | static void piix3_reset(void *opaque) |
249 | 502a5395 | pbrook | { |
250 | 15a1956a | Gleb Natapov | PCIDevice *d = opaque; |
251 | 502a5395 | pbrook | uint8_t *pci_conf = d->config; |
252 | 502a5395 | pbrook | |
253 | 502a5395 | pbrook | pci_conf[0x04] = 0x07; // master, memory and I/O |
254 | 502a5395 | pbrook | pci_conf[0x05] = 0x00; |
255 | 502a5395 | pbrook | pci_conf[0x06] = 0x00; |
256 | 502a5395 | pbrook | pci_conf[0x07] = 0x02; // PCI_status_devsel_medium |
257 | 502a5395 | pbrook | pci_conf[0x4c] = 0x4d; |
258 | 502a5395 | pbrook | pci_conf[0x4e] = 0x03; |
259 | 502a5395 | pbrook | pci_conf[0x4f] = 0x00; |
260 | 502a5395 | pbrook | pci_conf[0x60] = 0x80; |
261 | 477afee3 | aurel32 | pci_conf[0x61] = 0x80; |
262 | 477afee3 | aurel32 | pci_conf[0x62] = 0x80; |
263 | 477afee3 | aurel32 | pci_conf[0x63] = 0x80; |
264 | 502a5395 | pbrook | pci_conf[0x69] = 0x02; |
265 | 502a5395 | pbrook | pci_conf[0x70] = 0x80; |
266 | 502a5395 | pbrook | pci_conf[0x76] = 0x0c; |
267 | 502a5395 | pbrook | pci_conf[0x77] = 0x0c; |
268 | 502a5395 | pbrook | pci_conf[0x78] = 0x02; |
269 | 502a5395 | pbrook | pci_conf[0x79] = 0x00; |
270 | 502a5395 | pbrook | pci_conf[0x80] = 0x00; |
271 | 502a5395 | pbrook | pci_conf[0x82] = 0x00; |
272 | 502a5395 | pbrook | pci_conf[0xa0] = 0x08; |
273 | 502a5395 | pbrook | pci_conf[0xa2] = 0x00; |
274 | 502a5395 | pbrook | pci_conf[0xa3] = 0x00; |
275 | 502a5395 | pbrook | pci_conf[0xa4] = 0x00; |
276 | 502a5395 | pbrook | pci_conf[0xa5] = 0x00; |
277 | 502a5395 | pbrook | pci_conf[0xa6] = 0x00; |
278 | 502a5395 | pbrook | pci_conf[0xa7] = 0x00; |
279 | 502a5395 | pbrook | pci_conf[0xa8] = 0x0f; |
280 | 502a5395 | pbrook | pci_conf[0xaa] = 0x00; |
281 | 502a5395 | pbrook | pci_conf[0xab] = 0x00; |
282 | 502a5395 | pbrook | pci_conf[0xac] = 0x00; |
283 | 502a5395 | pbrook | pci_conf[0xae] = 0x00; |
284 | 15a1956a | Gleb Natapov | |
285 | 15a1956a | Gleb Natapov | memset(pci_irq_levels, 0, sizeof(pci_irq_levels)); |
286 | 502a5395 | pbrook | } |
287 | 502a5395 | pbrook | |
288 | eae6bcbf | Blue Swirl | static void piix4_reset(void *opaque) |
289 | 5c2b87e3 | ths | { |
290 | eae6bcbf | Blue Swirl | PCIDevice *d = opaque; |
291 | 5c2b87e3 | ths | uint8_t *pci_conf = d->config; |
292 | 5c2b87e3 | ths | |
293 | 5c2b87e3 | ths | pci_conf[0x04] = 0x07; // master, memory and I/O |
294 | 5c2b87e3 | ths | pci_conf[0x05] = 0x00; |
295 | 5c2b87e3 | ths | pci_conf[0x06] = 0x00; |
296 | 5c2b87e3 | ths | pci_conf[0x07] = 0x02; // PCI_status_devsel_medium |
297 | 5c2b87e3 | ths | pci_conf[0x4c] = 0x4d; |
298 | 5c2b87e3 | ths | pci_conf[0x4e] = 0x03; |
299 | 5c2b87e3 | ths | pci_conf[0x4f] = 0x00; |
300 | 5c2b87e3 | ths | pci_conf[0x60] = 0x0a; // PCI A -> IRQ 10 |
301 | 5c2b87e3 | ths | pci_conf[0x61] = 0x0a; // PCI B -> IRQ 10 |
302 | 5c2b87e3 | ths | pci_conf[0x62] = 0x0b; // PCI C -> IRQ 11 |
303 | 5c2b87e3 | ths | pci_conf[0x63] = 0x0b; // PCI D -> IRQ 11 |
304 | 5c2b87e3 | ths | pci_conf[0x69] = 0x02; |
305 | 5c2b87e3 | ths | pci_conf[0x70] = 0x80; |
306 | 5c2b87e3 | ths | pci_conf[0x76] = 0x0c; |
307 | 5c2b87e3 | ths | pci_conf[0x77] = 0x0c; |
308 | 5c2b87e3 | ths | pci_conf[0x78] = 0x02; |
309 | 5c2b87e3 | ths | pci_conf[0x79] = 0x00; |
310 | 5c2b87e3 | ths | pci_conf[0x80] = 0x00; |
311 | 5c2b87e3 | ths | pci_conf[0x82] = 0x00; |
312 | 5c2b87e3 | ths | pci_conf[0xa0] = 0x08; |
313 | 5c2b87e3 | ths | pci_conf[0xa2] = 0x00; |
314 | 5c2b87e3 | ths | pci_conf[0xa3] = 0x00; |
315 | 5c2b87e3 | ths | pci_conf[0xa4] = 0x00; |
316 | 5c2b87e3 | ths | pci_conf[0xa5] = 0x00; |
317 | 5c2b87e3 | ths | pci_conf[0xa6] = 0x00; |
318 | 5c2b87e3 | ths | pci_conf[0xa7] = 0x00; |
319 | 5c2b87e3 | ths | pci_conf[0xa8] = 0x0f; |
320 | 5c2b87e3 | ths | pci_conf[0xaa] = 0x00; |
321 | 5c2b87e3 | ths | pci_conf[0xab] = 0x00; |
322 | 5c2b87e3 | ths | pci_conf[0xac] = 0x00; |
323 | 5c2b87e3 | ths | pci_conf[0xae] = 0x00; |
324 | eae6bcbf | Blue Swirl | |
325 | eae6bcbf | Blue Swirl | memset(pci_irq_levels, 0, sizeof(pci_irq_levels)); |
326 | 5c2b87e3 | ths | } |
327 | 5c2b87e3 | ths | |
328 | 1941d19c | bellard | static void piix_save(QEMUFile* f, void *opaque) |
329 | 1941d19c | bellard | { |
330 | 1941d19c | bellard | PCIDevice *d = opaque; |
331 | 1941d19c | bellard | pci_device_save(d, f); |
332 | 1941d19c | bellard | } |
333 | 1941d19c | bellard | |
334 | 1941d19c | bellard | static int piix_load(QEMUFile* f, void *opaque, int version_id) |
335 | 1941d19c | bellard | { |
336 | 1941d19c | bellard | PCIDevice *d = opaque; |
337 | 1941d19c | bellard | if (version_id != 2) |
338 | 1941d19c | bellard | return -EINVAL;
|
339 | 1941d19c | bellard | return pci_device_load(d, f);
|
340 | 1941d19c | bellard | } |
341 | 1941d19c | bellard | |
342 | 8a14daa5 | Gerd Hoffmann | static void piix3_initfn(PCIDevice *d) |
343 | 502a5395 | pbrook | { |
344 | 502a5395 | pbrook | uint8_t *pci_conf; |
345 | 502a5395 | pbrook | |
346 | f75247f1 | Gerd Hoffmann | isa_bus_new(&d->qdev); |
347 | 1941d19c | bellard | register_savevm("PIIX3", 0, 2, piix_save, piix_load, d); |
348 | 502a5395 | pbrook | |
349 | 502a5395 | pbrook | pci_conf = d->config; |
350 | deb54399 | aliguori | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL); |
351 | deb54399 | aliguori | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_0); // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
|
352 | 173a543b | blueswir1 | pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA); |
353 | 6407f373 | Isaku Yamahata | pci_conf[PCI_HEADER_TYPE] = |
354 | 6407f373 | Isaku Yamahata | PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
|
355 | 502a5395 | pbrook | |
356 | 8a14daa5 | Gerd Hoffmann | piix3_dev = d; |
357 | 502a5395 | pbrook | piix3_reset(d); |
358 | a08d4367 | Jan Kiszka | qemu_register_reset(piix3_reset, d); |
359 | 502a5395 | pbrook | } |
360 | 5c2b87e3 | ths | |
361 | 8a14daa5 | Gerd Hoffmann | static void piix4_initfn(PCIDevice *d) |
362 | 5c2b87e3 | ths | { |
363 | 5c2b87e3 | ths | uint8_t *pci_conf; |
364 | 5c2b87e3 | ths | |
365 | 5c2b87e3 | ths | register_savevm("PIIX4", 0, 2, piix_save, piix_load, d); |
366 | 5c2b87e3 | ths | |
367 | 5c2b87e3 | ths | pci_conf = d->config; |
368 | deb54399 | aliguori | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL); |
369 | deb54399 | aliguori | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_0); // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
|
370 | 173a543b | blueswir1 | pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA); |
371 | 6407f373 | Isaku Yamahata | pci_conf[PCI_HEADER_TYPE] = |
372 | 6407f373 | Isaku Yamahata | PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
|
373 | 6407f373 | Isaku Yamahata | |
374 | 8a14daa5 | Gerd Hoffmann | piix4_dev = d; |
375 | 5c2b87e3 | ths | piix4_reset(d); |
376 | a08d4367 | Jan Kiszka | qemu_register_reset(piix4_reset, d); |
377 | 8a14daa5 | Gerd Hoffmann | } |
378 | 8a14daa5 | Gerd Hoffmann | |
379 | 8a14daa5 | Gerd Hoffmann | int piix3_init(PCIBus *bus, int devfn) |
380 | 8a14daa5 | Gerd Hoffmann | { |
381 | 8a14daa5 | Gerd Hoffmann | PCIDevice *d; |
382 | 8a14daa5 | Gerd Hoffmann | |
383 | 8a14daa5 | Gerd Hoffmann | d = pci_create_simple(bus, devfn, "PIIX3");
|
384 | 5c2b87e3 | ths | return d->devfn;
|
385 | 5c2b87e3 | ths | } |
386 | 8a14daa5 | Gerd Hoffmann | |
387 | 8a14daa5 | Gerd Hoffmann | int piix4_init(PCIBus *bus, int devfn) |
388 | 8a14daa5 | Gerd Hoffmann | { |
389 | 8a14daa5 | Gerd Hoffmann | PCIDevice *d; |
390 | 8a14daa5 | Gerd Hoffmann | |
391 | 8a14daa5 | Gerd Hoffmann | d = pci_create_simple(bus, devfn, "PIIX4");
|
392 | 8a14daa5 | Gerd Hoffmann | return d->devfn;
|
393 | 8a14daa5 | Gerd Hoffmann | } |
394 | 8a14daa5 | Gerd Hoffmann | |
395 | 8a14daa5 | Gerd Hoffmann | static PCIDeviceInfo i440fx_info[] = {
|
396 | 8a14daa5 | Gerd Hoffmann | { |
397 | 8a14daa5 | Gerd Hoffmann | .qdev.name = "i440FX",
|
398 | 8a14daa5 | Gerd Hoffmann | .qdev.desc = "Host bridge",
|
399 | 8a14daa5 | Gerd Hoffmann | .qdev.size = sizeof(PCIDevice),
|
400 | 8a14daa5 | Gerd Hoffmann | .qdev.no_user = 1,
|
401 | 8a14daa5 | Gerd Hoffmann | .init = i440fx_initfn, |
402 | 8a14daa5 | Gerd Hoffmann | .config_write = i440fx_write_config, |
403 | 8a14daa5 | Gerd Hoffmann | },{ |
404 | 8a14daa5 | Gerd Hoffmann | .qdev.name = "PIIX3",
|
405 | 8a14daa5 | Gerd Hoffmann | .qdev.desc = "ISA bridge",
|
406 | 8a14daa5 | Gerd Hoffmann | .qdev.size = sizeof(PCIDevice),
|
407 | 8a14daa5 | Gerd Hoffmann | .qdev.no_user = 1,
|
408 | 8a14daa5 | Gerd Hoffmann | .init = piix3_initfn, |
409 | 8a14daa5 | Gerd Hoffmann | },{ |
410 | 8a14daa5 | Gerd Hoffmann | .qdev.name = "PIIX4",
|
411 | 8a14daa5 | Gerd Hoffmann | .qdev.desc = "ISA bridge",
|
412 | 8a14daa5 | Gerd Hoffmann | .qdev.size = sizeof(PCIDevice),
|
413 | 8a14daa5 | Gerd Hoffmann | .qdev.no_user = 1,
|
414 | 8a14daa5 | Gerd Hoffmann | .init = piix4_initfn, |
415 | 8a14daa5 | Gerd Hoffmann | },{ |
416 | 8a14daa5 | Gerd Hoffmann | /* end of list */
|
417 | 8a14daa5 | Gerd Hoffmann | } |
418 | 8a14daa5 | Gerd Hoffmann | }; |
419 | 8a14daa5 | Gerd Hoffmann | |
420 | 8a14daa5 | Gerd Hoffmann | static SysBusDeviceInfo i440fx_pcihost_info = {
|
421 | 8a14daa5 | Gerd Hoffmann | .init = i440fx_pcihost_initfn, |
422 | 8a14daa5 | Gerd Hoffmann | .qdev.name = "i440FX-pcihost",
|
423 | 8a14daa5 | Gerd Hoffmann | .qdev.size = sizeof(I440FXState),
|
424 | 8a14daa5 | Gerd Hoffmann | .qdev.no_user = 1,
|
425 | 8a14daa5 | Gerd Hoffmann | }; |
426 | 8a14daa5 | Gerd Hoffmann | |
427 | 8a14daa5 | Gerd Hoffmann | static void i440fx_register(void) |
428 | 8a14daa5 | Gerd Hoffmann | { |
429 | 8a14daa5 | Gerd Hoffmann | sysbus_register_withprop(&i440fx_pcihost_info); |
430 | 8a14daa5 | Gerd Hoffmann | pci_qdev_register_many(i440fx_info); |
431 | 8a14daa5 | Gerd Hoffmann | } |
432 | 8a14daa5 | Gerd Hoffmann | device_init(i440fx_register); |