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