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
38 qemu_irq
*ioapic_irq_hack
;
42 static const int ide_iobase
[MAX_IDE_BUS
] = { 0x1f0, 0x170 };
43 static const int ide_iobase2
[MAX_IDE_BUS
] = { 0x3f6, 0x376 };
44 static const int ide_irq
[MAX_IDE_BUS
] = { 14, 15 };
46 const char *global_cpu_model
; /* cpu hotadd */
48 static void ioapic_init(IsaIrqState
*isa_irq_state
)
54 dev
= qdev_create(NULL
, "ioapic");
55 qdev_init_nofail(dev
);
56 d
= sysbus_from_qdev(dev
);
57 sysbus_mmio_map(d
, 0, 0xfec00000);
59 for (i
= 0; i
< IOAPIC_NUM_PINS
; i
++) {
60 isa_irq_state
->ioapic
[i
] = qdev_get_gpio_in(dev
, i
);
64 /* PC hardware initialisation */
65 static void pc_init1(ram_addr_t ram_size
,
66 const char *boot_device
,
67 const char *kernel_filename
,
68 const char *kernel_cmdline
,
69 const char *initrd_filename
,
70 const char *cpu_model
,
74 ram_addr_t below_4g_mem_size
, above_4g_mem_size
;
76 PCII440FXState
*i440fx_state
;
83 IsaIrqState
*isa_irq_state
;
84 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
85 FDCtrl
*floppy_controller
;
88 global_cpu_model
= cpu_model
;
90 pc_cpus_init(cpu_model
);
94 /* allocate ram and load rom/bios */
95 pc_memory_init(ram_size
, kernel_filename
, kernel_cmdline
, initrd_filename
,
96 &below_4g_mem_size
, &above_4g_mem_size
);
98 cpu_irq
= pc_allocate_cpu_irq();
99 #ifdef KVM_CAP_IRQCHIP
100 if (kvm_enabled() && kvm_irqchip_in_kernel()) {
101 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
103 ioapic_init(isa_irq_state
);
105 isa_irq
= i8259
= kvm_i8259_init(cpu_irq
[0]);
106 ioapic_irq_hack
= isa_irq
;
110 i8259
= i8259_init(cpu_irq
[0]);
111 isa_irq_state
= qemu_mallocz(sizeof(*isa_irq_state
));
112 isa_irq_state
->i8259
= i8259
;
114 ioapic_init(isa_irq_state
);
116 isa_irq
= qemu_allocate_irqs(isa_irq_handler
, isa_irq_state
, 24);
120 pci_bus
= i440fx_init(&i440fx_state
, &piix3_devfn
, isa_irq
, ram_size
);
125 isa_bus_irqs(isa_irq
);
127 pc_register_ferr_irq(isa_reserve_irq(13));
128 cpu_irq
= pc_allocate_cpu_irq();
130 pc_vga_init(pci_enabled
? pci_bus
: NULL
);
132 /* init basic PC hardware */
133 pc_basic_device_init(isa_irq
, &floppy_controller
, &rtc_state
);
135 for(i
= 0; i
< nb_nics
; i
++) {
136 NICInfo
*nd
= &nd_table
[i
];
138 if (!pci_enabled
|| (nd
->model
&& strcmp(nd
->model
, "ne2k_isa") == 0))
139 pc_init_ne2k_isa(nd
);
141 pci_nic_init_nofail(nd
, "rtl8139", NULL
);
144 if (drive_get_max_bus(IF_IDE
) >= MAX_IDE_BUS
) {
145 fprintf(stderr
, "qemu: too many IDE bus\n");
149 for(i
= 0; i
< MAX_IDE_BUS
* MAX_IDE_DEVS
; i
++) {
150 hd
[i
] = drive_get(IF_IDE
, i
/ MAX_IDE_DEVS
, i
% MAX_IDE_DEVS
);
154 pci_piix3_ide_init(pci_bus
, hd
, piix3_devfn
+ 1);
156 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
157 isa_ide_init(ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
158 hd
[MAX_IDE_DEVS
* i
], hd
[MAX_IDE_DEVS
* i
+ 1]);
162 pc_audio_init(pci_enabled
? pci_bus
: NULL
, isa_irq
);
164 pc_cmos_init(below_4g_mem_size
, above_4g_mem_size
, boot_device
, hd
,
165 floppy_controller
, rtc_state
);
167 if (pci_enabled
&& usb_enabled
) {
168 usb_uhci_piix3_init(pci_bus
, piix3_devfn
+ 2);
171 if (pci_enabled
&& acpi_enabled
) {
172 uint8_t *eeprom_buf
= qemu_mallocz(8 * 256); /* XXX: make this persistent */
175 cmos_s3
= qemu_allocate_irqs(pc_cmos_set_s3_resume
, rtc_state
, 1);
176 smi_irq
= qemu_allocate_irqs(pc_acpi_smi_interrupt
, first_cpu
, 1);
177 /* TODO: Populate SPD eeprom data. */
178 smbus
= piix4_pm_init(pci_bus
, piix3_devfn
+ 3, 0xb100,
179 isa_reserve_irq(9), *cmos_s3
, *smi_irq
,
181 for (i
= 0; i
< 8; i
++) {
183 eeprom
= qdev_create((BusState
*)smbus
, "smbus-eeprom");
184 qdev_prop_set_uint8(eeprom
, "address", 0x50 + i
);
185 qdev_prop_set_ptr(eeprom
, "data", eeprom_buf
+ (i
* 256));
186 qdev_init_nofail(eeprom
);
191 i440fx_init_memory_mappings(i440fx_state
);
195 pc_pci_device_init(pci_bus
);
199 static void pc_init_pci(ram_addr_t ram_size
,
200 const char *boot_device
,
201 const char *kernel_filename
,
202 const char *kernel_cmdline
,
203 const char *initrd_filename
,
204 const char *cpu_model
)
206 pc_init1(ram_size
, boot_device
,
207 kernel_filename
, kernel_cmdline
,
208 initrd_filename
, cpu_model
, 1);
211 static void pc_init_isa(ram_addr_t ram_size
,
212 const char *boot_device
,
213 const char *kernel_filename
,
214 const char *kernel_cmdline
,
215 const char *initrd_filename
,
216 const char *cpu_model
)
218 if (cpu_model
== NULL
)
220 pc_init1(ram_size
, boot_device
,
221 kernel_filename
, kernel_cmdline
,
222 initrd_filename
, cpu_model
, 0);
225 static QEMUMachine pc_machine
= {
228 .desc
= "Standard PC",
234 static QEMUMachine pc_machine_v0_12
= {
236 .desc
= "Standard PC",
239 .compat_props
= (GlobalProperty
[]) {
241 .driver
= "virtio-serial-pci",
242 .property
= "max_nr_ports",
243 .value
= stringify(1),
245 .driver
= "virtio-serial-pci",
246 .property
= "vectors",
247 .value
= stringify(0),
249 { /* end of list */ }
253 static QEMUMachine pc_machine_v0_11
= {
255 .desc
= "Standard PC, qemu 0.11",
258 .compat_props
= (GlobalProperty
[]) {
260 .driver
= "virtio-blk-pci",
261 .property
= "vectors",
262 .value
= stringify(0),
264 .driver
= "virtio-serial-pci",
265 .property
= "max_nr_ports",
266 .value
= stringify(1),
268 .driver
= "virtio-serial-pci",
269 .property
= "vectors",
270 .value
= stringify(0),
272 .driver
= "ide-drive",
276 .driver
= "scsi-disk",
281 .property
= "rombar",
282 .value
= stringify(0),
284 { /* end of list */ }
288 static QEMUMachine pc_machine_v0_10
= {
290 .desc
= "Standard PC, qemu 0.10",
293 .compat_props
= (GlobalProperty
[]) {
295 .driver
= "virtio-blk-pci",
297 .value
= stringify(PCI_CLASS_STORAGE_OTHER
),
299 .driver
= "virtio-serial-pci",
301 .value
= stringify(PCI_CLASS_DISPLAY_OTHER
),
303 .driver
= "virtio-serial-pci",
304 .property
= "max_nr_ports",
305 .value
= stringify(1),
307 .driver
= "virtio-serial-pci",
308 .property
= "vectors",
309 .value
= stringify(0),
311 .driver
= "virtio-net-pci",
312 .property
= "vectors",
313 .value
= stringify(0),
315 .driver
= "virtio-blk-pci",
316 .property
= "vectors",
317 .value
= stringify(0),
319 .driver
= "ide-drive",
323 .driver
= "scsi-disk",
328 .property
= "rombar",
329 .value
= stringify(0),
331 { /* end of list */ }
335 static QEMUMachine isapc_machine
= {
337 .desc
= "ISA-only PC",
342 static void pc_machine_init(void)
344 qemu_register_machine(&pc_machine
);
345 qemu_register_machine(&pc_machine_v0_12
);
346 qemu_register_machine(&pc_machine_v0_11
);
347 qemu_register_machine(&pc_machine_v0_10
);
348 qemu_register_machine(&isapc_machine
);
351 machine_init(pc_machine_init
);