]> Git Repo - qemu.git/blob - hw/pc_piix.c
soc_dma: drop soc_dma_port_add_mem_ram()
[qemu.git] / hw / pc_piix.c
1 /*
2  * QEMU PC System Emulator
3  *
4  * Copyright (c) 2003-2004 Fabrice Bellard
5  *
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  */
24
25 #include <glib.h>
26
27 #include "hw.h"
28 #include "pc.h"
29 #include "apic.h"
30 #include "pci.h"
31 #include "usb-uhci.h"
32 #include "usb-ohci.h"
33 #include "net.h"
34 #include "boards.h"
35 #include "ide.h"
36 #include "kvm.h"
37 #include "kvmclock.h"
38 #include "sysemu.h"
39 #include "sysbus.h"
40 #include "arch_init.h"
41 #include "blockdev.h"
42 #include "smbus.h"
43 #include "xen.h"
44 #include "memory.h"
45 #include "exec-memory.h"
46 #ifdef CONFIG_XEN
47 #  include <xen/hvm/hvm_info_table.h>
48 #endif
49
50 #define MAX_IDE_BUS 2
51
52 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
53 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
54 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
55
56 static void ioapic_init(IsaIrqState *isa_irq_state)
57 {
58     DeviceState *dev;
59     SysBusDevice *d;
60     unsigned int i;
61
62     dev = qdev_create(NULL, "ioapic");
63     qdev_init_nofail(dev);
64     d = sysbus_from_qdev(dev);
65     sysbus_mmio_map(d, 0, 0xfec00000);
66
67     for (i = 0; i < IOAPIC_NUM_PINS; i++) {
68         isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
69     }
70 }
71
72 /* PC hardware initialisation */
73 static void pc_init1(MemoryRegion *system_memory,
74                      MemoryRegion *system_io,
75                      ram_addr_t ram_size,
76                      const char *boot_device,
77                      const char *kernel_filename,
78                      const char *kernel_cmdline,
79                      const char *initrd_filename,
80                      const char *cpu_model,
81                      int pci_enabled,
82                      int kvmclock_enabled)
83 {
84     int i;
85     ram_addr_t below_4g_mem_size, above_4g_mem_size;
86     PCIBus *pci_bus;
87     PCII440FXState *i440fx_state;
88     int piix3_devfn = -1;
89     qemu_irq *cpu_irq;
90     qemu_irq *isa_irq;
91     qemu_irq *i8259;
92     qemu_irq *cmos_s3;
93     qemu_irq *smi_irq;
94     IsaIrqState *isa_irq_state;
95     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
96     BusState *idebus[MAX_IDE_BUS];
97     ISADevice *rtc_state;
98     MemoryRegion *ram_memory;
99     MemoryRegion *pci_memory;
100
101     pc_cpus_init(cpu_model);
102
103     if (kvmclock_enabled) {
104         kvmclock_create();
105     }
106
107     if (ram_size >= 0xe0000000 ) {
108         above_4g_mem_size = ram_size - 0xe0000000;
109         below_4g_mem_size = 0xe0000000;
110     } else {
111         above_4g_mem_size = 0;
112         below_4g_mem_size = ram_size;
113     }
114
115     pci_memory = g_new(MemoryRegion, 1);
116     memory_region_init(pci_memory, "pci", INT64_MAX);
117
118     /* allocate ram and load rom/bios */
119     if (!xen_enabled()) {
120         pc_memory_init(system_memory,
121                        kernel_filename, kernel_cmdline, initrd_filename,
122                        below_4g_mem_size, above_4g_mem_size,
123                        pci_memory, &ram_memory);
124     }
125
126     if (!xen_enabled()) {
127         cpu_irq = pc_allocate_cpu_irq();
128         i8259 = i8259_init(cpu_irq[0]);
129     } else {
130         i8259 = xen_interrupt_controller_init();
131     }
132     isa_irq_state = g_malloc0(sizeof(*isa_irq_state));
133     isa_irq_state->i8259 = i8259;
134     if (pci_enabled) {
135         ioapic_init(isa_irq_state);
136     }
137     isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
138
139     if (pci_enabled) {
140         pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq,
141                               system_memory, system_io, ram_size,
142                               below_4g_mem_size,
143                               0x100000000ULL - below_4g_mem_size,
144                               0x100000000ULL + above_4g_mem_size,
145                               (sizeof(target_phys_addr_t) == 4
146                                ? 0
147                                : ((uint64_t)1 << 62)),
148                               pci_memory, ram_memory);
149     } else {
150         pci_bus = NULL;
151         i440fx_state = NULL;
152         isa_bus_new(NULL);
153     }
154     isa_bus_irqs(isa_irq);
155
156     pc_register_ferr_irq(isa_get_irq(13));
157
158     pc_vga_init(pci_enabled? pci_bus: NULL);
159
160     if (xen_enabled()) {
161         pci_create_simple(pci_bus, -1, "xen-platform");
162     }
163
164     /* init basic PC hardware */
165     pc_basic_device_init(isa_irq, &rtc_state, xen_enabled());
166
167     for(i = 0; i < nb_nics; i++) {
168         NICInfo *nd = &nd_table[i];
169
170         if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
171             pc_init_ne2k_isa(nd);
172         else
173             pci_nic_init_nofail(nd, "e1000", NULL);
174     }
175
176     ide_drive_get(hd, MAX_IDE_BUS);
177     if (pci_enabled) {
178         PCIDevice *dev;
179         if (xen_enabled()) {
180             dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
181         } else {
182             dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
183         }
184         idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
185         idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
186     } else {
187         for(i = 0; i < MAX_IDE_BUS; i++) {
188             ISADevice *dev;
189             dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
190                                hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
191             idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
192         }
193     }
194
195     audio_init(isa_irq, pci_enabled ? pci_bus : NULL);
196
197     pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
198                  idebus[0], idebus[1], rtc_state);
199
200     if (pci_enabled && usb_enabled) {
201         usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
202     }
203
204     if (pci_enabled && acpi_enabled) {
205         i2c_bus *smbus;
206
207         if (!xen_enabled()) {
208             cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
209         } else {
210             cmos_s3 = qemu_allocate_irqs(xen_cmos_set_s3_resume, rtc_state, 1);
211         }
212         smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
213         /* TODO: Populate SPD eeprom data.  */
214         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
215                               isa_get_irq(9), *cmos_s3, *smi_irq,
216                               kvm_enabled());
217         smbus_eeprom_init(smbus, 8, NULL, 0);
218     }
219
220     if (pci_enabled) {
221         pc_pci_device_init(pci_bus);
222     }
223 }
224
225 static void pc_init_pci(ram_addr_t ram_size,
226                         const char *boot_device,
227                         const char *kernel_filename,
228                         const char *kernel_cmdline,
229                         const char *initrd_filename,
230                         const char *cpu_model)
231 {
232     pc_init1(get_system_memory(),
233              get_system_io(),
234              ram_size, boot_device,
235              kernel_filename, kernel_cmdline,
236              initrd_filename, cpu_model, 1, 1);
237 }
238
239 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
240                                     const char *boot_device,
241                                     const char *kernel_filename,
242                                     const char *kernel_cmdline,
243                                     const char *initrd_filename,
244                                     const char *cpu_model)
245 {
246     pc_init1(get_system_memory(),
247              get_system_io(),
248              ram_size, boot_device,
249              kernel_filename, kernel_cmdline,
250              initrd_filename, cpu_model, 1, 0);
251 }
252
253 static void pc_init_isa(ram_addr_t ram_size,
254                         const char *boot_device,
255                         const char *kernel_filename,
256                         const char *kernel_cmdline,
257                         const char *initrd_filename,
258                         const char *cpu_model)
259 {
260     if (cpu_model == NULL)
261         cpu_model = "486";
262     pc_init1(get_system_memory(),
263              get_system_io(),
264              ram_size, boot_device,
265              kernel_filename, kernel_cmdline,
266              initrd_filename, cpu_model, 0, 1);
267 }
268
269 #ifdef CONFIG_XEN
270 static void pc_xen_hvm_init(ram_addr_t ram_size,
271                             const char *boot_device,
272                             const char *kernel_filename,
273                             const char *kernel_cmdline,
274                             const char *initrd_filename,
275                             const char *cpu_model)
276 {
277     if (xen_hvm_init() != 0) {
278         hw_error("xen hardware virtual machine initialisation failed");
279     }
280     pc_init_pci_no_kvmclock(ram_size, boot_device,
281                             kernel_filename, kernel_cmdline,
282                             initrd_filename, cpu_model);
283     xen_vcpu_init();
284 }
285 #endif
286
287 static QEMUMachine pc_machine = {
288     .name = "pc-0.14",
289     .alias = "pc",
290     .desc = "Standard PC",
291     .init = pc_init_pci,
292     .max_cpus = 255,
293     .is_default = 1,
294 };
295
296 static QEMUMachine pc_machine_v0_13 = {
297     .name = "pc-0.13",
298     .desc = "Standard PC",
299     .init = pc_init_pci_no_kvmclock,
300     .max_cpus = 255,
301     .compat_props = (GlobalProperty[]) {
302         {
303             .driver   = "virtio-9p-pci",
304             .property = "vectors",
305             .value    = stringify(0),
306         },{
307             .driver   = "VGA",
308             .property = "rombar",
309             .value    = stringify(0),
310         },{
311             .driver   = "vmware-svga",
312             .property = "rombar",
313             .value    = stringify(0),
314         },{
315             .driver   = "PCI",
316             .property = "command_serr_enable",
317             .value    = "off",
318         },{
319             .driver   = "virtio-blk-pci",
320             .property = "event_idx",
321             .value    = "off",
322         },{
323             .driver   = "virtio-serial-pci",
324             .property = "event_idx",
325             .value    = "off",
326         },{
327             .driver   = "virtio-net-pci",
328             .property = "event_idx",
329             .value    = "off",
330         },
331         { /* end of list */ }
332     },
333 };
334
335 static QEMUMachine pc_machine_v0_12 = {
336     .name = "pc-0.12",
337     .desc = "Standard PC",
338     .init = pc_init_pci_no_kvmclock,
339     .max_cpus = 255,
340     .compat_props = (GlobalProperty[]) {
341         {
342             .driver   = "virtio-serial-pci",
343             .property = "max_ports",
344             .value    = stringify(1),
345         },{
346             .driver   = "virtio-serial-pci",
347             .property = "vectors",
348             .value    = stringify(0),
349         },{
350             .driver   = "VGA",
351             .property = "rombar",
352             .value    = stringify(0),
353         },{
354             .driver   = "vmware-svga",
355             .property = "rombar",
356             .value    = stringify(0),
357         },{
358             .driver   = "PCI",
359             .property = "command_serr_enable",
360             .value    = "off",
361         },{
362             .driver   = "virtio-blk-pci",
363             .property = "event_idx",
364             .value    = "off",
365         },{
366             .driver   = "virtio-serial-pci",
367             .property = "event_idx",
368             .value    = "off",
369         },{
370             .driver   = "virtio-net-pci",
371             .property = "event_idx",
372             .value    = "off",
373         },
374         { /* end of list */ }
375     }
376 };
377
378 static QEMUMachine pc_machine_v0_11 = {
379     .name = "pc-0.11",
380     .desc = "Standard PC, qemu 0.11",
381     .init = pc_init_pci_no_kvmclock,
382     .max_cpus = 255,
383     .compat_props = (GlobalProperty[]) {
384         {
385             .driver   = "virtio-blk-pci",
386             .property = "vectors",
387             .value    = stringify(0),
388         },{
389             .driver   = "virtio-serial-pci",
390             .property = "max_ports",
391             .value    = stringify(1),
392         },{
393             .driver   = "virtio-serial-pci",
394             .property = "vectors",
395             .value    = stringify(0),
396         },{
397             .driver   = "ide-drive",
398             .property = "ver",
399             .value    = "0.11",
400         },{
401             .driver   = "scsi-disk",
402             .property = "ver",
403             .value    = "0.11",
404         },{
405             .driver   = "PCI",
406             .property = "rombar",
407             .value    = stringify(0),
408         },{
409             .driver   = "PCI",
410             .property = "command_serr_enable",
411             .value    = "off",
412         },{
413             .driver   = "virtio-blk-pci",
414             .property = "event_idx",
415             .value    = "off",
416         },{
417             .driver   = "virtio-serial-pci",
418             .property = "event_idx",
419             .value    = "off",
420         },{
421             .driver   = "virtio-net-pci",
422             .property = "event_idx",
423             .value    = "off",
424         },
425         { /* end of list */ }
426     }
427 };
428
429 static QEMUMachine pc_machine_v0_10 = {
430     .name = "pc-0.10",
431     .desc = "Standard PC, qemu 0.10",
432     .init = pc_init_pci_no_kvmclock,
433     .max_cpus = 255,
434     .compat_props = (GlobalProperty[]) {
435         {
436             .driver   = "virtio-blk-pci",
437             .property = "class",
438             .value    = stringify(PCI_CLASS_STORAGE_OTHER),
439         },{
440             .driver   = "virtio-serial-pci",
441             .property = "class",
442             .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
443         },{
444             .driver   = "virtio-serial-pci",
445             .property = "max_ports",
446             .value    = stringify(1),
447         },{
448             .driver   = "virtio-serial-pci",
449             .property = "vectors",
450             .value    = stringify(0),
451         },{
452             .driver   = "virtio-net-pci",
453             .property = "vectors",
454             .value    = stringify(0),
455         },{
456             .driver   = "virtio-blk-pci",
457             .property = "vectors",
458             .value    = stringify(0),
459         },{
460             .driver   = "ide-drive",
461             .property = "ver",
462             .value    = "0.10",
463         },{
464             .driver   = "scsi-disk",
465             .property = "ver",
466             .value    = "0.10",
467         },{
468             .driver   = "PCI",
469             .property = "rombar",
470             .value    = stringify(0),
471         },{
472             .driver   = "PCI",
473             .property = "command_serr_enable",
474             .value    = "off",
475         },{
476             .driver   = "virtio-blk-pci",
477             .property = "event_idx",
478             .value    = "off",
479         },{
480             .driver   = "virtio-serial-pci",
481             .property = "event_idx",
482             .value    = "off",
483         },{
484             .driver   = "virtio-net-pci",
485             .property = "event_idx",
486             .value    = "off",
487         },
488         { /* end of list */ }
489     },
490 };
491
492 static QEMUMachine isapc_machine = {
493     .name = "isapc",
494     .desc = "ISA-only PC",
495     .init = pc_init_isa,
496     .max_cpus = 1,
497 };
498
499 #ifdef CONFIG_XEN
500 static QEMUMachine xenfv_machine = {
501     .name = "xenfv",
502     .desc = "Xen Fully-virtualized PC",
503     .init = pc_xen_hvm_init,
504     .max_cpus = HVM_MAX_VCPUS,
505     .default_machine_opts = "accel=xen",
506 };
507 #endif
508
509 static void pc_machine_init(void)
510 {
511     qemu_register_machine(&pc_machine);
512     qemu_register_machine(&pc_machine_v0_13);
513     qemu_register_machine(&pc_machine_v0_12);
514     qemu_register_machine(&pc_machine_v0_11);
515     qemu_register_machine(&pc_machine_v0_10);
516     qemu_register_machine(&isapc_machine);
517 #ifdef CONFIG_XEN
518     qemu_register_machine(&xenfv_machine);
519 #endif
520 }
521
522 machine_init(pc_machine_init);
This page took 0.053152 seconds and 4 git commands to generate.