Statistics
| Branch: | Revision:

root / hw / pc_piix.c @ d8ee0384

History | View | Annotate | Download (18.2 kB)

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 "pci_ids.h"
32
#include "usb.h"
33
#include "net.h"
34
#include "boards.h"
35
#include "ide.h"
36
#include "kvm.h"
37
#include "kvm/clock.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
#include "cpu.h"
47
#ifdef CONFIG_XEN
48
#  include <xen/hvm/hvm_info_table.h>
49
#endif
50

    
51
#define MAX_IDE_BUS 2
52

    
53
static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
54
static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
55
static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
56

    
57
/* PC hardware initialisation */
58
static void pc_init1(MemoryRegion *system_memory,
59
                     MemoryRegion *system_io,
60
                     ram_addr_t ram_size,
61
                     const char *boot_device,
62
                     const char *kernel_filename,
63
                     const char *kernel_cmdline,
64
                     const char *initrd_filename,
65
                     const char *cpu_model,
66
                     int pci_enabled,
67
                     int kvmclock_enabled)
68
{
69
    int i;
70
    ram_addr_t below_4g_mem_size, above_4g_mem_size;
71
    PCIBus *pci_bus;
72
    ISABus *isa_bus;
73
    PCII440FXState *i440fx_state;
74
    int piix3_devfn = -1;
75
    qemu_irq *cpu_irq;
76
    qemu_irq *gsi;
77
    qemu_irq *i8259;
78
    qemu_irq *smi_irq;
79
    GSIState *gsi_state;
80
    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
81
    BusState *idebus[MAX_IDE_BUS];
82
    ISADevice *rtc_state;
83
    ISADevice *floppy;
84
    MemoryRegion *ram_memory;
85
    MemoryRegion *pci_memory;
86
    MemoryRegion *rom_memory;
87
    void *fw_cfg = NULL;
88

    
89
    pc_cpus_init(cpu_model);
90

    
91
    if (kvmclock_enabled) {
92
        kvmclock_create();
93
    }
94

    
95
    if (ram_size >= 0xe0000000 ) {
96
        above_4g_mem_size = ram_size - 0xe0000000;
97
        below_4g_mem_size = 0xe0000000;
98
    } else {
99
        above_4g_mem_size = 0;
100
        below_4g_mem_size = ram_size;
101
    }
102

    
103
    if (pci_enabled) {
104
        pci_memory = g_new(MemoryRegion, 1);
105
        memory_region_init(pci_memory, "pci", INT64_MAX);
106
        rom_memory = pci_memory;
107
    } else {
108
        pci_memory = NULL;
109
        rom_memory = system_memory;
110
    }
111

    
112
    /* allocate ram and load rom/bios */
113
    if (!xen_enabled()) {
114
        fw_cfg = pc_memory_init(system_memory,
115
                       kernel_filename, kernel_cmdline, initrd_filename,
116
                       below_4g_mem_size, above_4g_mem_size,
117
                       rom_memory, &ram_memory);
118
    }
119

    
120
    gsi_state = g_malloc0(sizeof(*gsi_state));
121
    if (kvm_irqchip_in_kernel()) {
122
        kvm_pc_setup_irq_routing(pci_enabled);
123
        gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
124
                                 GSI_NUM_PINS);
125
    } else {
126
        gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
127
    }
128

    
129
    if (pci_enabled) {
130
        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
131
                              system_memory, system_io, ram_size,
132
                              below_4g_mem_size,
133
                              0x100000000ULL - below_4g_mem_size,
134
                              0x100000000ULL + above_4g_mem_size,
135
                              (sizeof(hwaddr) == 4
136
                               ? 0
137
                               : ((uint64_t)1 << 62)),
138
                              pci_memory, ram_memory);
139
    } else {
140
        pci_bus = NULL;
141
        i440fx_state = NULL;
142
        isa_bus = isa_bus_new(NULL, system_io);
143
        no_hpet = 1;
144
    }
145
    isa_bus_irqs(isa_bus, gsi);
146

    
147
    if (kvm_irqchip_in_kernel()) {
148
        i8259 = kvm_i8259_init(isa_bus);
149
    } else if (xen_enabled()) {
150
        i8259 = xen_interrupt_controller_init();
151
    } else {
152
        cpu_irq = pc_allocate_cpu_irq();
153
        i8259 = i8259_init(isa_bus, cpu_irq[0]);
154
    }
155

    
156
    for (i = 0; i < ISA_NUM_IRQS; i++) {
157
        gsi_state->i8259_irq[i] = i8259[i];
158
    }
159
    if (pci_enabled) {
160
        ioapic_init_gsi(gsi_state, "i440fx");
161
    }
162

    
163
    pc_register_ferr_irq(gsi[13]);
164

    
165
    pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
166
    if (xen_enabled()) {
167
        pci_create_simple(pci_bus, -1, "xen-platform");
168
    }
169

    
170
    /* init basic PC hardware */
171
    pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());
172

    
173
    pc_nic_init(isa_bus, pci_bus);
174

    
175
    ide_drive_get(hd, MAX_IDE_BUS);
176
    if (pci_enabled) {
177
        PCIDevice *dev;
178
        if (xen_enabled()) {
179
            dev = pci_piix3_xen_ide_init(pci_bus, hd, piix3_devfn + 1);
180
        } else {
181
            dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
182
        }
183
        idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
184
        idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
185
    } else {
186
        for(i = 0; i < MAX_IDE_BUS; i++) {
187
            ISADevice *dev;
188
            dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
189
                               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_bus, pci_enabled ? pci_bus : NULL);
196

    
197
    pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
198
                 floppy, idebus[0], idebus[1], rtc_state);
199

    
200
    if (pci_enabled && usb_enabled(false)) {
201
        pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
202
    }
203

    
204
    if (pci_enabled && acpi_enabled) {
205
        i2c_bus *smbus;
206

    
207
        smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
208
        /* TODO: Populate SPD eeprom data.  */
209
        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
210
                              gsi[9], *smi_irq,
211
                              kvm_enabled(), fw_cfg);
212
        smbus_eeprom_init(smbus, 8, NULL, 0);
213
    }
214

    
215
    if (pci_enabled) {
216
        pc_pci_device_init(pci_bus);
217
    }
218
}
219

    
220
static void pc_init_pci(QEMUMachineInitArgs *args)
221
{
222
    ram_addr_t ram_size = args->ram_size;
223
    const char *cpu_model = args->cpu_model;
224
    const char *kernel_filename = args->kernel_filename;
225
    const char *kernel_cmdline = args->kernel_cmdline;
226
    const char *initrd_filename = args->initrd_filename;
227
    const char *boot_device = args->boot_device;
228
    pc_init1(get_system_memory(),
229
             get_system_io(),
230
             ram_size, boot_device,
231
             kernel_filename, kernel_cmdline,
232
             initrd_filename, cpu_model, 1, 1);
233
}
234

    
235
static void pc_init_pci_1_3(QEMUMachineInitArgs *args)
236
{
237
    enable_kvm_pv_eoi();
238
    pc_init_pci(args);
239
}
240

    
241
static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args)
242
{
243
    ram_addr_t ram_size = args->ram_size;
244
    const char *cpu_model = args->cpu_model;
245
    const char *kernel_filename = args->kernel_filename;
246
    const char *kernel_cmdline = args->kernel_cmdline;
247
    const char *initrd_filename = args->initrd_filename;
248
    const char *boot_device = args->boot_device;
249
    pc_init1(get_system_memory(),
250
             get_system_io(),
251
             ram_size, boot_device,
252
             kernel_filename, kernel_cmdline,
253
             initrd_filename, cpu_model, 1, 0);
254
}
255

    
256
static void pc_init_isa(QEMUMachineInitArgs *args)
257
{
258
    ram_addr_t ram_size = args->ram_size;
259
    const char *cpu_model = args->cpu_model;
260
    const char *kernel_filename = args->kernel_filename;
261
    const char *kernel_cmdline = args->kernel_cmdline;
262
    const char *initrd_filename = args->initrd_filename;
263
    const char *boot_device = args->boot_device;
264
    if (cpu_model == NULL)
265
        cpu_model = "486";
266
    pc_init1(get_system_memory(),
267
             get_system_io(),
268
             ram_size, boot_device,
269
             kernel_filename, kernel_cmdline,
270
             initrd_filename, cpu_model, 0, 1);
271
}
272

    
273
#ifdef CONFIG_XEN
274
static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
275
{
276
    if (xen_hvm_init() != 0) {
277
        hw_error("xen hardware virtual machine initialisation failed");
278
    }
279
    pc_init_pci_no_kvmclock(args);
280
    xen_vcpu_init();
281
}
282
#endif
283

    
284
static QEMUMachine pc_machine_v1_3 = {
285
    .name = "pc-1.3",
286
    .alias = "pc",
287
    .desc = "Standard PC",
288
    .init = pc_init_pci_1_3,
289
    .max_cpus = 255,
290
    .is_default = 1,
291
};
292

    
293
#define PC_COMPAT_1_2 \
294
        {\
295
            .driver   = "nec-usb-xhci",\
296
            .property = "msi",\
297
            .value    = "off",\
298
        },{\
299
            .driver   = "nec-usb-xhci",\
300
            .property = "msix",\
301
            .value    = "off",\
302
        },{\
303
            .driver   = "ivshmem",\
304
            .property = "use64",\
305
            .value    = "0",\
306
        },{\
307
            .driver   = "qxl",\
308
            .property = "revision",\
309
            .value    = stringify(3),\
310
        },{\
311
            .driver   = "qxl-vga",\
312
            .property = "revision",\
313
            .value    = stringify(3),\
314
        },{\
315
            .driver   = "VGA",\
316
            .property = "mmio",\
317
            .value    = "off",\
318
        }
319

    
320
static QEMUMachine pc_machine_v1_2 = {
321
    .name = "pc-1.2",
322
    .desc = "Standard PC",
323
    .init = pc_init_pci,
324
    .max_cpus = 255,
325
    .compat_props = (GlobalProperty[]) {
326
        PC_COMPAT_1_2,
327
        { /* end of list */ }
328
    },
329
};
330

    
331
#define PC_COMPAT_1_1 \
332
        PC_COMPAT_1_2,\
333
        {\
334
            .driver   = "virtio-scsi-pci",\
335
            .property = "hotplug",\
336
            .value    = "off",\
337
        },{\
338
            .driver   = "virtio-scsi-pci",\
339
            .property = "param_change",\
340
            .value    = "off",\
341
        },{\
342
            .driver   = "VGA",\
343
            .property = "vgamem_mb",\
344
            .value    = stringify(8),\
345
        },{\
346
            .driver   = "vmware-svga",\
347
            .property = "vgamem_mb",\
348
            .value    = stringify(8),\
349
        },{\
350
            .driver   = "qxl-vga",\
351
            .property = "vgamem_mb",\
352
            .value    = stringify(8),\
353
        },{\
354
            .driver   = "qxl",\
355
            .property = "vgamem_mb",\
356
            .value    = stringify(8),\
357
        },{\
358
            .driver   = "virtio-blk-pci",\
359
            .property = "config-wce",\
360
            .value    = "off",\
361
        }
362

    
363
static QEMUMachine pc_machine_v1_1 = {
364
    .name = "pc-1.1",
365
    .desc = "Standard PC",
366
    .init = pc_init_pci,
367
    .max_cpus = 255,
368
    .compat_props = (GlobalProperty[]) {
369
        PC_COMPAT_1_1,
370
        { /* end of list */ }
371
    },
372
};
373

    
374
#define PC_COMPAT_1_0 \
375
        PC_COMPAT_1_1,\
376
        {\
377
            .driver   = "pc-sysfw",\
378
            .property = "rom_only",\
379
            .value    = stringify(1),\
380
        }, {\
381
            .driver   = "isa-fdc",\
382
            .property = "check_media_rate",\
383
            .value    = "off",\
384
        }, {\
385
            .driver   = "virtio-balloon-pci",\
386
            .property = "class",\
387
            .value    = stringify(PCI_CLASS_MEMORY_RAM),\
388
        },{\
389
            .driver   = "apic",\
390
            .property = "vapic",\
391
            .value    = "off",\
392
        },{\
393
            .driver   = TYPE_USB_DEVICE,\
394
            .property = "full-path",\
395
            .value    = "no",\
396
        }
397

    
398
static QEMUMachine pc_machine_v1_0 = {
399
    .name = "pc-1.0",
400
    .desc = "Standard PC",
401
    .init = pc_init_pci,
402
    .max_cpus = 255,
403
    .compat_props = (GlobalProperty[]) {
404
        PC_COMPAT_1_0,
405
        { /* end of list */ }
406
    },
407
    .hw_version = "1.0",
408
};
409

    
410
#define PC_COMPAT_0_15 \
411
        PC_COMPAT_1_0
412

    
413
static QEMUMachine pc_machine_v0_15 = {
414
    .name = "pc-0.15",
415
    .desc = "Standard PC",
416
    .init = pc_init_pci,
417
    .max_cpus = 255,
418
    .compat_props = (GlobalProperty[]) {
419
        PC_COMPAT_0_15,
420
        { /* end of list */ }
421
    },
422
    .hw_version = "0.15",
423
};
424

    
425
#define PC_COMPAT_0_14 \
426
        PC_COMPAT_0_15,\
427
        {\
428
            .driver   = "virtio-blk-pci",\
429
            .property = "event_idx",\
430
            .value    = "off",\
431
        },{\
432
            .driver   = "virtio-serial-pci",\
433
            .property = "event_idx",\
434
            .value    = "off",\
435
        },{\
436
            .driver   = "virtio-net-pci",\
437
            .property = "event_idx",\
438
            .value    = "off",\
439
        },{\
440
            .driver   = "virtio-balloon-pci",\
441
            .property = "event_idx",\
442
            .value    = "off",\
443
        }
444

    
445
static QEMUMachine pc_machine_v0_14 = {
446
    .name = "pc-0.14",
447
    .desc = "Standard PC",
448
    .init = pc_init_pci,
449
    .max_cpus = 255,
450
    .compat_props = (GlobalProperty[]) {
451
        PC_COMPAT_0_14, 
452
        {
453
            .driver   = "qxl",
454
            .property = "revision",
455
            .value    = stringify(2),
456
        },{
457
            .driver   = "qxl-vga",
458
            .property = "revision",
459
            .value    = stringify(2),
460
        },
461
        { /* end of list */ }
462
    },
463
    .hw_version = "0.14",
464
};
465

    
466
#define PC_COMPAT_0_13 \
467
        PC_COMPAT_0_14,\
468
        {\
469
            .driver   = TYPE_PCI_DEVICE,\
470
            .property = "command_serr_enable",\
471
            .value    = "off",\
472
        },{\
473
            .driver   = "AC97",\
474
            .property = "use_broken_id",\
475
            .value    = stringify(1),\
476
        }
477

    
478
static QEMUMachine pc_machine_v0_13 = {
479
    .name = "pc-0.13",
480
    .desc = "Standard PC",
481
    .init = pc_init_pci_no_kvmclock,
482
    .max_cpus = 255,
483
    .compat_props = (GlobalProperty[]) {
484
        PC_COMPAT_0_13,
485
        {
486
            .driver   = "virtio-9p-pci",
487
            .property = "vectors",
488
            .value    = stringify(0),
489
        },{
490
            .driver   = "VGA",
491
            .property = "rombar",
492
            .value    = stringify(0),
493
        },{
494
            .driver   = "vmware-svga",
495
            .property = "rombar",
496
            .value    = stringify(0),
497
        },
498
        { /* end of list */ }
499
    },
500
    .hw_version = "0.13",
501
};
502

    
503
#define PC_COMPAT_0_12 \
504
        PC_COMPAT_0_13,\
505
        {\
506
            .driver   = "virtio-serial-pci",\
507
            .property = "max_ports",\
508
            .value    = stringify(1),\
509
        },{\
510
            .driver   = "virtio-serial-pci",\
511
            .property = "vectors",\
512
            .value    = stringify(0),\
513
        }
514

    
515
static QEMUMachine pc_machine_v0_12 = {
516
    .name = "pc-0.12",
517
    .desc = "Standard PC",
518
    .init = pc_init_pci_no_kvmclock,
519
    .max_cpus = 255,
520
    .compat_props = (GlobalProperty[]) {
521
        PC_COMPAT_0_12,
522
        {
523
            .driver   = "VGA",
524
            .property = "rombar",
525
            .value    = stringify(0),
526
        },{
527
            .driver   = "vmware-svga",
528
            .property = "rombar",
529
            .value    = stringify(0),
530
        },
531
        { /* end of list */ }
532
    },
533
    .hw_version = "0.12",
534
};
535

    
536
#define PC_COMPAT_0_11 \
537
        PC_COMPAT_0_12,\
538
        {\
539
            .driver   = "virtio-blk-pci",\
540
            .property = "vectors",\
541
            .value    = stringify(0),\
542
        },{\
543
            .driver   = TYPE_PCI_DEVICE,\
544
            .property = "rombar",\
545
            .value    = stringify(0),\
546
        }
547

    
548
static QEMUMachine pc_machine_v0_11 = {
549
    .name = "pc-0.11",
550
    .desc = "Standard PC, qemu 0.11",
551
    .init = pc_init_pci_no_kvmclock,
552
    .max_cpus = 255,
553
    .compat_props = (GlobalProperty[]) {
554
        PC_COMPAT_0_11,
555
        {
556
            .driver   = "ide-drive",
557
            .property = "ver",
558
            .value    = "0.11",
559
        },{
560
            .driver   = "scsi-disk",
561
            .property = "ver",
562
            .value    = "0.11",
563
        },
564
        { /* end of list */ }
565
    },
566
    .hw_version = "0.11",
567
};
568

    
569
static QEMUMachine pc_machine_v0_10 = {
570
    .name = "pc-0.10",
571
    .desc = "Standard PC, qemu 0.10",
572
    .init = pc_init_pci_no_kvmclock,
573
    .max_cpus = 255,
574
    .compat_props = (GlobalProperty[]) {
575
        PC_COMPAT_0_11,
576
        {
577
            .driver   = "virtio-blk-pci",
578
            .property = "class",
579
            .value    = stringify(PCI_CLASS_STORAGE_OTHER),
580
        },{
581
            .driver   = "virtio-serial-pci",
582
            .property = "class",
583
            .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
584
        },{
585
            .driver   = "virtio-net-pci",
586
            .property = "vectors",
587
            .value    = stringify(0),
588
        },{
589
            .driver   = "ide-drive",
590
            .property = "ver",
591
            .value    = "0.10",
592
        },{
593
            .driver   = "scsi-disk",
594
            .property = "ver",
595
            .value    = "0.10",
596
        },
597
        { /* end of list */ }
598
    },
599
    .hw_version = "0.10",
600
};
601

    
602
static QEMUMachine isapc_machine = {
603
    .name = "isapc",
604
    .desc = "ISA-only PC",
605
    .init = pc_init_isa,
606
    .max_cpus = 1,
607
    .compat_props = (GlobalProperty[]) {
608
        {
609
            .driver   = "pc-sysfw",
610
            .property = "rom_only",
611
            .value    = stringify(1),
612
        },
613
        { /* end of list */ }
614
    },
615
};
616

    
617
#ifdef CONFIG_XEN
618
static QEMUMachine xenfv_machine = {
619
    .name = "xenfv",
620
    .desc = "Xen Fully-virtualized PC",
621
    .init = pc_xen_hvm_init,
622
    .max_cpus = HVM_MAX_VCPUS,
623
    .default_machine_opts = "accel=xen",
624
};
625
#endif
626

    
627
static void pc_machine_init(void)
628
{
629
    qemu_register_machine(&pc_machine_v1_3);
630
    qemu_register_machine(&pc_machine_v1_2);
631
    qemu_register_machine(&pc_machine_v1_1);
632
    qemu_register_machine(&pc_machine_v1_0);
633
    qemu_register_machine(&pc_machine_v0_15);
634
    qemu_register_machine(&pc_machine_v0_14);
635
    qemu_register_machine(&pc_machine_v0_13);
636
    qemu_register_machine(&pc_machine_v0_12);
637
    qemu_register_machine(&pc_machine_v0_11);
638
    qemu_register_machine(&pc_machine_v0_10);
639
    qemu_register_machine(&isapc_machine);
640
#ifdef CONFIG_XEN
641
    qemu_register_machine(&xenfv_machine);
642
#endif
643
}
644

    
645
machine_init(pc_machine_init);