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
39 qemu_irq
*ioapic_irq_hack
;
43 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
44 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
45 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
47 const char *global_cpu_model
; /* cpu hotadd */
49 static void ioapic_init(IsaIrqState
*isa_irq_state
)
55 dev
= qdev_create(NULL
, "ioapic");
56 qdev_init_nofail(dev
);
57 d
= sysbus_from_qdev(dev
);
58 sysbus_mmio_map(d
, 0, 0xfec00000);
60 for (i
= 0; i
< IOAPIC_NUM_PINS
; i
++) {
61 isa_irq_state
->ioapic
[i
] = qdev_get_gpio_in(dev
, i
);
65 /* PC hardware initialisation */
66 static void pc_init1(ram_addr_t ram_size
,
67 const char *boot_device
,
68 const char *kernel_filename
,
69 const char *kernel_cmdline
,
70 const char *initrd_filename
,
71 const char *cpu_model
,
75 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
77 PCII440FXState
*i440fx_state
;
84 IsaIrqState
*isa_irq_state
;
85 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
86 FDCtrl
*floppy_controller
;
87 BusState
*idebus
[MAX_IDE_BUS
];
90 global_cpu_model
= cpu_model
;
92 pc_cpus_init(cpu_model
);
96 /* allocate ram and load rom/bios */
97 pc_memory_init(ram_size
, kernel_filename
, kernel_cmdline
, initrd_filename
,
98 &below_4g_mem_size
, &above_4g_mem_size
);
100 cpu_irq
= pc_allocate_cpu_irq();
101 #ifdef KVM_CAP_IRQCHIP
102 if (kvm_enabled() && kvm_irqchip_in_kernel()) {
103 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
105 ioapic_init(isa_irq_state
);
107 isa_irq
= i8259
= kvm_i8259_init(cpu_irq
[0]);
108 ioapic_irq_hack
= isa_irq
;
112 i8259
= i8259_init(cpu_irq
[0]);
113 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
114 isa_irq_state
->i8259
= i8259
;
116 ioapic_init(isa_irq_state
);
118 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, isa_irq_state
, 24);
122 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, isa_irq
, ram_size
);
128 isa_bus_irqs(isa_irq
);
130 pc_register_ferr_irq(isa_reserve_irq(13));
131 cpu_irq
= pc_allocate_cpu_irq();
133 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
135 /* init basic PC hardware */
136 pc_basic_device_init(isa_irq
, &floppy_controller
, &rtc_state
);
138 for(i
= 0; i
< nb_nics
; i
++) {
139 NICInfo
*nd
= &nd_table
[i
];
141 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
142 pc_init_ne2k_isa(nd
);
144 pci_nic_init_nofail(nd
, "rtl8139", NULL
);
147 if (drive_get_max_bus(IF_IDE
) >= MAX_IDE_BUS
) {
148 fprintf(stderr
, "qemu: too many IDE bus\n");
152 for(i
= 0; i
< MAX_IDE_BUS
* MAX_IDE_DEVS
; i
++) {
153 hd
[i
] = drive_get(IF_IDE
, i
/ MAX_IDE_DEVS
, i
% MAX_IDE_DEVS
);
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");
162 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
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 pc_audio_init(pci_enabled
? pci_bus
: NULL
, isa_irq
);
172 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
,
173 idebus
[0], idebus
[1], floppy_controller
, 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 uint8_t *eeprom_buf
= qemu_mallocz(8 * 256); /* XXX: make this persistent */
183 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
184 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
185 /* TODO: Populate SPD eeprom data. */
186 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
187 isa_reserve_irq(9), *cmos_s3
, *smi_irq
,
189 for (i
= 0; i
< 8; i
++) {
191 eeprom
= qdev_create((BusState
*)smbus
, "smbus-eeprom");
192 qdev_prop_set_uint8(eeprom
, "address", 0x50 + i
);
193 qdev_prop_set_ptr(eeprom
, "data", eeprom_buf
+ (i
* 256));
194 qdev_init_nofail(eeprom
);
199 i440fx_init_memory_mappings(i440fx_state
);
203 pc_pci_device_init(pci_bus
);
207 static void pc_init_pci(ram_addr_t ram_size
,
208 const char *boot_device
,
209 const char *kernel_filename
,
210 const char *kernel_cmdline
,
211 const char *initrd_filename
,
212 const char *cpu_model
)
214 pc_init1(ram_size
, boot_device
,
215 kernel_filename
, kernel_cmdline
,
216 initrd_filename
, cpu_model
, 1);
219 static void pc_init_isa(ram_addr_t ram_size
,
220 const char *boot_device
,
221 const char *kernel_filename
,
222 const char *kernel_cmdline
,
223 const char *initrd_filename
,
224 const char *cpu_model
)
226 if (cpu_model
== NULL
)
228 pc_init1(ram_size
, boot_device
,
229 kernel_filename
, kernel_cmdline
,
230 initrd_filename
, cpu_model
, 0);
233 static QEMUMachine pc_machine
= {
236 .desc
= "Standard PC",
242 static QEMUMachine pc_machine_v0_12
= {
244 .desc
= "Standard PC",
247 .compat_props
= (GlobalProperty
[]) {
249 .driver
= "virtio-serial-pci",
250 .property
= "max_ports",
251 .value
= stringify(1),
253 .driver
= "virtio-serial-pci",
254 .property
= "vectors",
255 .value
= stringify(0),
257 { /* end of list */ }
261 static QEMUMachine pc_machine_v0_11
= {
263 .desc
= "Standard PC, qemu 0.11",
266 .compat_props
= (GlobalProperty
[]) {
268 .driver
= "virtio-blk-pci",
269 .property
= "vectors",
270 .value
= stringify(0),
272 .driver
= "virtio-serial-pci",
273 .property
= "max_ports",
274 .value
= stringify(1),
276 .driver
= "virtio-serial-pci",
277 .property
= "vectors",
278 .value
= stringify(0),
280 .driver
= "ide-drive",
284 .driver
= "scsi-disk",
289 .property
= "rombar",
290 .value
= stringify(0),
292 { /* end of list */ }
296 static QEMUMachine pc_machine_v0_10
= {
298 .desc
= "Standard PC, qemu 0.10",
301 .compat_props
= (GlobalProperty
[]) {
303 .driver
= "virtio-blk-pci",
305 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
307 .driver
= "virtio-serial-pci",
309 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
311 .driver
= "virtio-serial-pci",
312 .property
= "max_ports",
313 .value
= stringify(1),
315 .driver
= "virtio-serial-pci",
316 .property
= "vectors",
317 .value
= stringify(0),
319 .driver
= "virtio-net-pci",
320 .property
= "vectors",
321 .value
= stringify(0),
323 .driver
= "virtio-blk-pci",
324 .property
= "vectors",
325 .value
= stringify(0),
327 .driver
= "ide-drive",
331 .driver
= "scsi-disk",
336 .property
= "rombar",
337 .value
= stringify(0),
339 { /* end of list */ }
343 static QEMUMachine isapc_machine
= {
345 .desc
= "ISA-only PC",
350 static void pc_machine_init(void)
352 qemu_register_machine(&pc_machine
);
353 qemu_register_machine(&pc_machine_v0_12
);
354 qemu_register_machine(&pc_machine_v0_11
);
355 qemu_register_machine(&pc_machine_v0_10
);
356 qemu_register_machine(&isapc_machine
);
359 machine_init(pc_machine_init
);