~ubuntu-branches/ubuntu/vivid/qemu-linaro/vivid

« back to all changes in this revision

Viewing changes to hw/acpi_piix4.c

  • Committer: Ricardo Salveti de Araujo
  • Date: 2012-09-20 18:39:31 UTC
  • mfrom: (12922.1.2 qemu-linaro)
  • Revision ID: ricardo.salveti@linaro.org-20120920183931-sp3cg6kpdl8dmwo9
* New upstream release.
  - support emulated systems with more than 2G of memory. (LP: #1030588)
* Drop powerpc-missing-include.patch - merged upstream.
* Update debian/control:
  - drop perl build dependency.
  - add libfdt-dev build dependency.
* Update debian/qemu-keymaps.install file.
* Update debian/rules:
  - update QEMU_CPU for ARM architecture: armv4l -> armv7l.
  - update conf_audio_drv: default to PulseAudio since PA is the default on
    Ubuntu.
  - enable KVM on ARM architecture.
  - enable flat device tree support (--enable-fdt). (LP: #1030594)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "sysemu.h"
28
28
#include "range.h"
29
29
#include "ioport.h"
 
30
#include "fw_cfg.h"
30
31
 
31
32
//#define DEBUG
32
33
 
40
41
 
41
42
#define GPE_BASE 0xafe0
42
43
#define GPE_LEN 4
43
 
#define PCI_BASE 0xae00
 
44
#define PCI_UP_BASE 0xae00
 
45
#define PCI_DOWN_BASE 0xae04
44
46
#define PCI_EJ_BASE 0xae08
45
47
#define PCI_RMV_BASE 0xae0c
46
48
 
47
49
#define PIIX4_PCI_HOTPLUG_STATUS 2
48
50
 
49
51
struct pci_status {
50
 
    uint32_t up;
 
52
    uint32_t up; /* deprecated, maintained for migration compatibility */
51
53
    uint32_t down;
52
54
};
53
55
 
69
71
    /* for pci hotplug */
70
72
    struct pci_status pci0_status;
71
73
    uint32_t pci0_hotplug_enable;
 
74
    uint32_t pci0_slot_device_present;
 
75
 
 
76
    uint8_t disable_s3;
 
77
    uint8_t disable_s4;
 
78
    uint8_t s4_val;
72
79
} PIIX4PMState;
73
80
 
74
81
static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s);
121
128
        pm_update_sci(s);
122
129
        break;
123
130
    case 0x04:
124
 
        acpi_pm1_cnt_write(&s->ar, val);
 
131
        acpi_pm1_cnt_write(&s->ar, val, s->s4_val);
125
132
        break;
126
133
    default:
127
134
        break;
204
211
        pm_io_space_update((PIIX4PMState *)d);
205
212
}
206
213
 
 
214
static void vmstate_pci_status_pre_save(void *opaque)
 
215
{
 
216
    struct pci_status *pci0_status = opaque;
 
217
    PIIX4PMState *s = container_of(pci0_status, PIIX4PMState, pci0_status);
 
218
 
 
219
    /* We no longer track up, so build a safe value for migrating
 
220
     * to a version that still does... of course these might get lost
 
221
     * by an old buggy implementation, but we try. */
 
222
    pci0_status->up = s->pci0_slot_device_present & s->pci0_hotplug_enable;
 
223
}
 
224
 
207
225
static int vmstate_acpi_post_load(void *opaque, int version_id)
208
226
{
209
227
    PIIX4PMState *s = opaque;
240
258
    .version_id = 1,
241
259
    .minimum_version_id = 1,
242
260
    .minimum_version_id_old = 1,
 
261
    .pre_save = vmstate_pci_status_pre_save,
243
262
    .fields      = (VMStateField []) {
244
263
        VMSTATE_UINT32(up, struct pci_status),
245
264
        VMSTATE_UINT32(down, struct pci_status),
268
287
    }
269
288
};
270
289
 
 
290
static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
 
291
{
 
292
    BusChild *kid, *next;
 
293
    BusState *bus = qdev_get_parent_bus(&s->dev.qdev);
 
294
    int slot = ffs(slots) - 1;
 
295
    bool slot_free = true;
 
296
 
 
297
    /* Mark request as complete */
 
298
    s->pci0_status.down &= ~(1U << slot);
 
299
 
 
300
    QTAILQ_FOREACH_SAFE(kid, &bus->children, sibling, next) {
 
301
        DeviceState *qdev = kid->child;
 
302
        PCIDevice *dev = PCI_DEVICE(qdev);
 
303
        PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
 
304
        if (PCI_SLOT(dev->devfn) == slot) {
 
305
            if (pc->no_hotplug) {
 
306
                slot_free = false;
 
307
            } else {
 
308
                object_unparent(OBJECT(dev));
 
309
                qdev_free(qdev);
 
310
            }
 
311
        }
 
312
    }
 
313
    if (slot_free) {
 
314
        s->pci0_slot_device_present &= ~(1U << slot);
 
315
    }
 
316
}
 
317
 
271
318
static void piix4_update_hotplug(PIIX4PMState *s)
272
319
{
273
320
    PCIDevice *dev = &s->dev;
274
321
    BusState *bus = qdev_get_parent_bus(&dev->qdev);
275
 
    DeviceState *qdev, *next;
 
322
    BusChild *kid, *next;
 
323
 
 
324
    /* Execute any pending removes during reset */
 
325
    while (s->pci0_status.down) {
 
326
        acpi_piix_eject_slot(s, s->pci0_status.down);
 
327
    }
276
328
 
277
329
    s->pci0_hotplug_enable = ~0;
 
330
    s->pci0_slot_device_present = 0;
278
331
 
279
 
    QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
 
332
    QTAILQ_FOREACH_SAFE(kid, &bus->children, sibling, next) {
 
333
        DeviceState *qdev = kid->child;
280
334
        PCIDevice *pdev = PCI_DEVICE(qdev);
281
335
        PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pdev);
282
336
        int slot = PCI_SLOT(pdev->devfn);
283
337
 
284
338
        if (pc->no_hotplug) {
285
 
            s->pci0_hotplug_enable &= ~(1 << slot);
 
339
            s->pci0_hotplug_enable &= ~(1U << slot);
286
340
        }
 
341
 
 
342
        s->pci0_slot_device_present |= (1U << slot);
287
343
    }
288
344
}
289
345
 
373
429
 
374
430
i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
375
431
                       qemu_irq sci_irq, qemu_irq smi_irq,
376
 
                       int kvm_enabled)
 
432
                       int kvm_enabled, void *fw_cfg)
377
433
{
378
434
    PCIDevice *dev;
379
435
    PIIX4PMState *s;
389
445
 
390
446
    qdev_init_nofail(&dev->qdev);
391
447
 
 
448
    if (fw_cfg) {
 
449
        uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
 
450
        suspend[3] = 1 | ((!s->disable_s3) << 7);
 
451
        suspend[4] = s->s4_val | ((!s->disable_s4) << 7);
 
452
 
 
453
        fw_cfg_add_file(fw_cfg, "etc/system-states", g_memdup(suspend, 6), 6);
 
454
    }
 
455
 
392
456
    return s->smb.smbus;
393
457
}
394
458
 
395
459
static Property piix4_pm_properties[] = {
396
460
    DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
 
461
    DEFINE_PROP_UINT8("disable_s3", PIIX4PMState, disable_s3, 0),
 
462
    DEFINE_PROP_UINT8("disable_s4", PIIX4PMState, disable_s4, 0),
 
463
    DEFINE_PROP_UINT8("s4_val", PIIX4PMState, s4_val, 2),
397
464
    DEFINE_PROP_END_OF_LIST(),
398
465
};
399
466
 
448
515
    PIIX4_DPRINTF("gpe write %x <== %d\n", addr, val);
449
516
}
450
517
 
451
 
static uint32_t pcihotplug_read(void *opaque, uint32_t addr)
452
 
{
453
 
    uint32_t val = 0;
454
 
    struct pci_status *g = opaque;
455
 
    switch (addr) {
456
 
        case PCI_BASE:
457
 
            val = g->up;
458
 
            break;
459
 
        case PCI_BASE + 4:
460
 
            val = g->down;
461
 
            break;
462
 
        default:
463
 
            break;
464
 
    }
465
 
 
466
 
    PIIX4_DPRINTF("pcihotplug read %x == %x\n", addr, val);
467
 
    return val;
468
 
}
469
 
 
470
 
static void pcihotplug_write(void *opaque, uint32_t addr, uint32_t val)
471
 
{
472
 
    struct pci_status *g = opaque;
473
 
    switch (addr) {
474
 
        case PCI_BASE:
475
 
            g->up = val;
476
 
            break;
477
 
        case PCI_BASE + 4:
478
 
            g->down = val;
479
 
            break;
480
 
   }
481
 
 
482
 
    PIIX4_DPRINTF("pcihotplug write %x <== %d\n", addr, val);
483
 
}
484
 
 
485
 
static uint32_t pciej_read(void *opaque, uint32_t addr)
486
 
{
487
 
    PIIX4_DPRINTF("pciej read %x\n", addr);
 
518
static uint32_t pci_up_read(void *opaque, uint32_t addr)
 
519
{
 
520
    PIIX4PMState *s = opaque;
 
521
    uint32_t val;
 
522
 
 
523
    /* Manufacture an "up" value to cause a device check on any hotplug
 
524
     * slot with a device.  Extra device checks are harmless. */
 
525
    val = s->pci0_slot_device_present & s->pci0_hotplug_enable;
 
526
 
 
527
    PIIX4_DPRINTF("pci_up_read %x\n", val);
 
528
    return val;
 
529
}
 
530
 
 
531
static uint32_t pci_down_read(void *opaque, uint32_t addr)
 
532
{
 
533
    PIIX4PMState *s = opaque;
 
534
    uint32_t val = s->pci0_status.down;
 
535
 
 
536
    PIIX4_DPRINTF("pci_down_read %x\n", val);
 
537
    return val;
 
538
}
 
539
 
 
540
static uint32_t pci_features_read(void *opaque, uint32_t addr)
 
541
{
 
542
    /* No feature defined yet */
 
543
    PIIX4_DPRINTF("pci_features_read %x\n", 0);
488
544
    return 0;
489
545
}
490
546
 
491
547
static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
492
548
{
493
 
    BusState *bus = opaque;
494
 
    DeviceState *qdev, *next;
495
 
    int slot = ffs(val) - 1;
496
 
 
497
 
    QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
498
 
        PCIDevice *dev = PCI_DEVICE(qdev);
499
 
        PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
500
 
        if (PCI_SLOT(dev->devfn) == slot && !pc->no_hotplug) {
501
 
            qdev_free(qdev);
502
 
        }
503
 
    }
504
 
 
 
549
    acpi_piix_eject_slot(opaque, val);
505
550
 
506
551
    PIIX4_DPRINTF("pciej write %x <== %d\n", addr, val);
507
552
}
513
558
    return s->pci0_hotplug_enable;
514
559
}
515
560
 
516
 
static void pcirmv_write(void *opaque, uint32_t addr, uint32_t val)
517
 
{
518
 
    return;
519
 
}
520
 
 
521
561
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
522
562
                                PCIHotplugState state);
523
563
 
524
564
static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
525
565
{
526
 
    struct pci_status *pci0_status = &s->pci0_status;
527
566
 
528
567
    register_ioport_write(GPE_BASE, GPE_LEN, 1, gpe_writeb, s);
529
568
    register_ioport_read(GPE_BASE, GPE_LEN, 1,  gpe_readb, s);
530
569
    acpi_gpe_blk(&s->ar, GPE_BASE);
531
570
 
532
 
    register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, pci0_status);
533
 
    register_ioport_read(PCI_BASE, 8, 4,  pcihotplug_read, pci0_status);
534
 
 
535
 
    register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, bus);
536
 
    register_ioport_read(PCI_EJ_BASE, 4, 4,  pciej_read, bus);
537
 
 
538
 
    register_ioport_write(PCI_RMV_BASE, 4, 4, pcirmv_write, s);
 
571
    register_ioport_read(PCI_UP_BASE, 4, 4, pci_up_read, s);
 
572
    register_ioport_read(PCI_DOWN_BASE, 4, 4, pci_down_read, s);
 
573
 
 
574
    register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, s);
 
575
    register_ioport_read(PCI_EJ_BASE, 4, 4,  pci_features_read, s);
 
576
 
539
577
    register_ioport_read(PCI_RMV_BASE, 4, 4,  pcirmv_read, s);
540
578
 
541
579
    pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev);
544
582
static void enable_device(PIIX4PMState *s, int slot)
545
583
{
546
584
    s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
547
 
    s->pci0_status.up |= (1 << slot);
 
585
    s->pci0_slot_device_present |= (1U << slot);
548
586
}
549
587
 
550
588
static void disable_device(PIIX4PMState *s, int slot)
551
589
{
552
590
    s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
553
 
    s->pci0_status.down |= (1 << slot);
 
591
    s->pci0_status.down |= (1U << slot);
554
592
}
555
593
 
556
594
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
564
602
     * it is present on boot, no hotplug event is necessary. We do send an
565
603
     * event when the device is disabled later. */
566
604
    if (state == PCI_COLDPLUG_ENABLED) {
 
605
        s->pci0_slot_device_present |= (1U << slot);
567
606
        return 0;
568
607
    }
569
608
 
570
 
    s->pci0_status.up = 0;
571
 
    s->pci0_status.down = 0;
572
609
    if (state == PCI_HOTPLUG_ENABLED) {
573
610
        enable_device(s, slot);
574
611
    } else {