xen: Set running state in xenstore.
[qemu/wangdongxu.git] / hw / pc_piix.c
blob62cdf71daa94b2557370e8e7dd837ef4661b4f0a
1 /*
2 * QEMU PC System Emulator
4 * Copyright (c) 2003-2004 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
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 #ifdef CONFIG_XEN
43 # include <xen/hvm/hvm_info_table.h>
44 #endif
46 #define MAX_IDE_BUS 2
48 static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
49 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
50 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
52 static void ioapic_init(IsaIrqState *isa_irq_state)
54 DeviceState *dev;
55 SysBusDevice *d;
56 unsigned int i;
58 dev = qdev_create(NULL, "ioapic");
59 qdev_init_nofail(dev);
60 d = sysbus_from_qdev(dev);
61 sysbus_mmio_map(d, 0, 0xfec00000);
63 for (i = 0; i < IOAPIC_NUM_PINS; i++) {
64 isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
68 /* PC hardware initialisation */
69 static void pc_init1(ram_addr_t ram_size,
70 const char *boot_device,
71 const char *kernel_filename,
72 const char *kernel_cmdline,
73 const char *initrd_filename,
74 const char *cpu_model,
75 int pci_enabled,
76 int kvmclock_enabled)
78 int i;
79 ram_addr_t below_4g_mem_size, above_4g_mem_size;
80 PCIBus *pci_bus;
81 PCII440FXState *i440fx_state;
82 int piix3_devfn = -1;
83 qemu_irq *cpu_irq;
84 qemu_irq *isa_irq;
85 qemu_irq *i8259;
86 qemu_irq *cmos_s3;
87 qemu_irq *smi_irq;
88 IsaIrqState *isa_irq_state;
89 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
90 BusState *idebus[MAX_IDE_BUS];
91 ISADevice *rtc_state;
93 pc_cpus_init(cpu_model);
95 if (kvmclock_enabled) {
96 kvmclock_create();
99 if (ram_size >= 0xe0000000 ) {
100 above_4g_mem_size = ram_size - 0xe0000000;
101 below_4g_mem_size = 0xe0000000;
102 } else {
103 above_4g_mem_size = 0;
104 below_4g_mem_size = ram_size;
107 /* allocate ram and load rom/bios */
108 if (!xen_enabled()) {
109 pc_memory_init(kernel_filename, kernel_cmdline, initrd_filename,
110 below_4g_mem_size, above_4g_mem_size);
113 if (!xen_enabled()) {
114 cpu_irq = pc_allocate_cpu_irq();
115 i8259 = i8259_init(cpu_irq[0]);
116 } else {
117 i8259 = xen_interrupt_controller_init();
119 isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
120 isa_irq_state->i8259 = i8259;
121 if (pci_enabled) {
122 ioapic_init(isa_irq_state);
124 isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
126 if (pci_enabled) {
127 if (!xen_enabled()) {
128 pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
129 } else {
130 pci_bus = i440fx_xen_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
132 } else {
133 pci_bus = NULL;
134 i440fx_state = NULL;
135 isa_bus_new(NULL);
137 isa_bus_irqs(isa_irq);
139 pc_register_ferr_irq(isa_get_irq(13));
141 pc_vga_init(pci_enabled? pci_bus: NULL);
143 /* init basic PC hardware */
144 pc_basic_device_init(isa_irq, &rtc_state, xen_enabled());
146 for(i = 0; i < nb_nics; i++) {
147 NICInfo *nd = &nd_table[i];
149 if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
150 pc_init_ne2k_isa(nd);
151 else
152 pci_nic_init_nofail(nd, "e1000", NULL);
155 ide_drive_get(hd, MAX_IDE_BUS);
156 if (pci_enabled) {
157 PCIDevice *dev;
158 dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
159 idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
160 idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
161 } else {
162 for(i = 0; i < MAX_IDE_BUS; i++) {
163 ISADevice *dev;
164 dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
165 hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
166 idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
170 audio_init(isa_irq, pci_enabled ? pci_bus : NULL);
172 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
173 idebus[0], idebus[1], rtc_state);
175 if (pci_enabled && usb_enabled) {
176 usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
179 if (pci_enabled && acpi_enabled) {
180 i2c_bus *smbus;
182 cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
183 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
184 /* TODO: Populate SPD eeprom data. */
185 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
186 isa_get_irq(9), *cmos_s3, *smi_irq,
187 kvm_enabled());
188 smbus_eeprom_init(smbus, 8, NULL, 0);
191 if (i440fx_state) {
192 i440fx_init_memory_mappings(i440fx_state);
195 if (pci_enabled) {
196 pc_pci_device_init(pci_bus);
200 static void pc_init_pci(ram_addr_t ram_size,
201 const char *boot_device,
202 const char *kernel_filename,
203 const char *kernel_cmdline,
204 const char *initrd_filename,
205 const char *cpu_model)
207 pc_init1(ram_size, boot_device,
208 kernel_filename, kernel_cmdline,
209 initrd_filename, cpu_model, 1, 1);
212 static void pc_init_pci_no_kvmclock(ram_addr_t ram_size,
213 const char *boot_device,
214 const char *kernel_filename,
215 const char *kernel_cmdline,
216 const char *initrd_filename,
217 const char *cpu_model)
219 pc_init1(ram_size, boot_device,
220 kernel_filename, kernel_cmdline,
221 initrd_filename, cpu_model, 1, 0);
224 static void pc_init_isa(ram_addr_t ram_size,
225 const char *boot_device,
226 const char *kernel_filename,
227 const char *kernel_cmdline,
228 const char *initrd_filename,
229 const char *cpu_model)
231 if (cpu_model == NULL)
232 cpu_model = "486";
233 pc_init1(ram_size, boot_device,
234 kernel_filename, kernel_cmdline,
235 initrd_filename, cpu_model, 0, 1);
238 #ifdef CONFIG_XEN
239 static void pc_xen_hvm_init(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)
246 if (xen_hvm_init() != 0) {
247 hw_error("xen hardware virtual machine initialisation failed");
249 pc_init_pci_no_kvmclock(ram_size, boot_device,
250 kernel_filename, kernel_cmdline,
251 initrd_filename, cpu_model);
252 xen_vcpu_init();
254 #endif
256 static QEMUMachine pc_machine = {
257 .name = "pc-0.14",
258 .alias = "pc",
259 .desc = "Standard PC",
260 .init = pc_init_pci,
261 .max_cpus = 255,
262 .is_default = 1,
265 static QEMUMachine pc_machine_v0_13 = {
266 .name = "pc-0.13",
267 .desc = "Standard PC",
268 .init = pc_init_pci_no_kvmclock,
269 .max_cpus = 255,
270 .compat_props = (GlobalProperty[]) {
272 .driver = "virtio-9p-pci",
273 .property = "vectors",
274 .value = stringify(0),
276 .driver = "VGA",
277 .property = "rombar",
278 .value = stringify(0),
280 .driver = "vmware-svga",
281 .property = "rombar",
282 .value = stringify(0),
284 .driver = "PCI",
285 .property = "command_serr_enable",
286 .value = "off",
288 { /* end of list */ }
292 static QEMUMachine pc_machine_v0_12 = {
293 .name = "pc-0.12",
294 .desc = "Standard PC",
295 .init = pc_init_pci_no_kvmclock,
296 .max_cpus = 255,
297 .compat_props = (GlobalProperty[]) {
299 .driver = "virtio-serial-pci",
300 .property = "max_ports",
301 .value = stringify(1),
303 .driver = "virtio-serial-pci",
304 .property = "vectors",
305 .value = stringify(0),
307 .driver = "VGA",
308 .property = "rombar",
309 .value = stringify(0),
311 .driver = "vmware-svga",
312 .property = "rombar",
313 .value = stringify(0),
315 .driver = "PCI",
316 .property = "command_serr_enable",
317 .value = "off",
319 { /* end of list */ }
323 static QEMUMachine pc_machine_v0_11 = {
324 .name = "pc-0.11",
325 .desc = "Standard PC, qemu 0.11",
326 .init = pc_init_pci_no_kvmclock,
327 .max_cpus = 255,
328 .compat_props = (GlobalProperty[]) {
330 .driver = "virtio-blk-pci",
331 .property = "vectors",
332 .value = stringify(0),
334 .driver = "virtio-serial-pci",
335 .property = "max_ports",
336 .value = stringify(1),
338 .driver = "virtio-serial-pci",
339 .property = "vectors",
340 .value = stringify(0),
342 .driver = "ide-drive",
343 .property = "ver",
344 .value = "0.11",
346 .driver = "scsi-disk",
347 .property = "ver",
348 .value = "0.11",
350 .driver = "PCI",
351 .property = "rombar",
352 .value = stringify(0),
354 .driver = "PCI",
355 .property = "command_serr_enable",
356 .value = "off",
358 { /* end of list */ }
362 static QEMUMachine pc_machine_v0_10 = {
363 .name = "pc-0.10",
364 .desc = "Standard PC, qemu 0.10",
365 .init = pc_init_pci_no_kvmclock,
366 .max_cpus = 255,
367 .compat_props = (GlobalProperty[]) {
369 .driver = "virtio-blk-pci",
370 .property = "class",
371 .value = stringify(PCI_CLASS_STORAGE_OTHER),
373 .driver = "virtio-serial-pci",
374 .property = "class",
375 .value = stringify(PCI_CLASS_DISPLAY_OTHER),
377 .driver = "virtio-serial-pci",
378 .property = "max_ports",
379 .value = stringify(1),
381 .driver = "virtio-serial-pci",
382 .property = "vectors",
383 .value = stringify(0),
385 .driver = "virtio-net-pci",
386 .property = "vectors",
387 .value = stringify(0),
389 .driver = "virtio-blk-pci",
390 .property = "vectors",
391 .value = stringify(0),
393 .driver = "ide-drive",
394 .property = "ver",
395 .value = "0.10",
397 .driver = "scsi-disk",
398 .property = "ver",
399 .value = "0.10",
401 .driver = "PCI",
402 .property = "rombar",
403 .value = stringify(0),
405 .driver = "PCI",
406 .property = "command_serr_enable",
407 .value = "off",
409 { /* end of list */ }
413 static QEMUMachine isapc_machine = {
414 .name = "isapc",
415 .desc = "ISA-only PC",
416 .init = pc_init_isa,
417 .max_cpus = 1,
420 #ifdef CONFIG_XEN
421 static QEMUMachine xenfv_machine = {
422 .name = "xenfv",
423 .desc = "Xen Fully-virtualized PC",
424 .init = pc_xen_hvm_init,
425 .max_cpus = HVM_MAX_VCPUS,
426 .default_machine_opts = "accel=xen",
428 #endif
430 static void pc_machine_init(void)
432 qemu_register_machine(&pc_machine);
433 qemu_register_machine(&pc_machine_v0_13);
434 qemu_register_machine(&pc_machine_v0_12);
435 qemu_register_machine(&pc_machine_v0_11);
436 qemu_register_machine(&pc_machine_v0_10);
437 qemu_register_machine(&isapc_machine);
438 #ifdef CONFIG_XEN
439 qemu_register_machine(&xenfv_machine);
440 #endif
443 machine_init(pc_machine_init);