~ubuntu-branches/debian/jessie/qemu/jessie

« back to all changes in this revision

Viewing changes to hw/piix_pci.c

  • Committer: Package Import Robot
  • Author(s): Vagrant Cascadian
  • Date: 2011-10-03 12:29:18 UTC
  • mfrom: (1.2.13) (10.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20111003122918-zc4kv6epchrbgdta
Tags: 0.15.0+dfsg-1
* New upstream version.
* Install new qemu-system, qemu-user and qemu-user-static variants: 
  lm32, microblazeel, s390x, unicore32
* Patch from upstream to set QEMU_INCLUDES before QEMU_CFLAGS.
* Update debian/watch to check http://qemu.org/download.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "isa.h"
30
30
#include "sysbus.h"
31
31
#include "range.h"
 
32
#include "xen.h"
32
33
 
33
34
/*
34
35
 * I440FX chipset data sheet.
37
38
 
38
39
typedef PCIHostState I440FXState;
39
40
 
 
41
#define PIIX_NUM_PIC_IRQS       16      /* i8259 * 2 */
 
42
#define PIIX_NUM_PIRQS          4ULL    /* PIRQ[A-D] */
 
43
#define XEN_PIIX_NUM_PIRQS      128ULL
 
44
#define PIIX_PIRQC              0x60
 
45
 
40
46
typedef struct PIIX3State {
41
47
    PCIDevice dev;
42
 
    int pci_irq_levels[4];
 
48
 
 
49
    /*
 
50
     * bitmap to track pic levels.
 
51
     * The pic level is the logical OR of all the PCI irqs mapped to it
 
52
     * So one PIC level is tracked by PIIX_NUM_PIRQS bits.
 
53
     *
 
54
     * PIRQ is mapped to PIC pins, we track it by
 
55
     * PIIX_NUM_PIRQS * PIIX_NUM_PIC_IRQS = 64 bits with
 
56
     * pic_irq * PIIX_NUM_PIRQS + pirq
 
57
     */
 
58
#if PIIX_NUM_PIC_IRQS * PIIX_NUM_PIRQS > 64
 
59
#error "unable to encode pic state in 64bit in pic_levels."
 
60
#endif
 
61
    uint64_t pic_levels;
 
62
 
43
63
    qemu_irq *pic;
 
64
 
 
65
    /* This member isn't used. Just for save/load compatibility */
 
66
    int32_t pci_irq_levels_vmstate[PIIX_NUM_PIRQS];
44
67
} PIIX3State;
45
68
 
46
69
struct PCII440FXState {
55
78
#define I440FX_PAM_SIZE 7
56
79
#define I440FX_SMRAM    0x72
57
80
 
58
 
static void piix3_set_irq(void *opaque, int irq_num, int level);
 
81
static void piix3_set_irq(void *opaque, int pirq, int level);
 
82
static void piix3_write_config_xen(PCIDevice *dev,
 
83
                               uint32_t address, uint32_t val, int len);
59
84
 
60
85
/* return the global irq number corresponding to a given device irq
61
86
   pin. We could also use the bus number to have a more precise
62
87
   mapping. */
63
 
static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
 
88
static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
64
89
{
65
90
    int slot_addend;
66
91
    slot_addend = (pci_dev->devfn >> 3) - 1;
67
 
    return (irq_num + slot_addend) & 3;
 
92
    return (pci_intx + slot_addend) & 3;
68
93
}
69
94
 
70
95
static void update_pam(PCII440FXState *d, uint32_t start, uint32_t end, int r)
162
187
    i440fx_update_memory_mappings(d);
163
188
    qemu_get_8s(f, &d->smm_enabled);
164
189
 
165
 
    if (version_id == 2)
166
 
        for (i = 0; i < 4; i++)
167
 
            d->piix3->pci_irq_levels[i] = qemu_get_be32(f);
 
190
    if (version_id == 2) {
 
191
        for (i = 0; i < PIIX_NUM_PIRQS; i++) {
 
192
            qemu_get_be32(f); /* dummy load for compatibility */
 
193
        }
 
194
    }
168
195
 
169
196
    return 0;
170
197
}
205
232
{
206
233
    PCII440FXState *d = DO_UPCAST(PCII440FXState, dev, dev);
207
234
 
208
 
    pci_config_set_vendor_id(d->dev.config, PCI_VENDOR_ID_INTEL);
209
 
    pci_config_set_device_id(d->dev.config, PCI_DEVICE_ID_INTEL_82441);
210
 
    d->dev.config[0x08] = 0x02; // revision
211
 
    pci_config_set_class(d->dev.config, PCI_CLASS_BRIDGE_HOST);
212
 
 
213
235
    d->dev.config[I440FX_SMRAM] = 0x02;
214
236
 
215
237
    cpu_smm_register(&i440fx_set_smm, d);
216
238
    return 0;
217
239
}
218
240
 
219
 
PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size)
 
241
static PCIBus *i440fx_common_init(const char *device_name,
 
242
                                  PCII440FXState **pi440fx_state,
 
243
                                  int *piix3_devfn,
 
244
                                  qemu_irq *pic, ram_addr_t ram_size)
220
245
{
221
246
    DeviceState *dev;
222
247
    PCIBus *b;
230
255
    s->bus = b;
231
256
    qdev_init_nofail(dev);
232
257
 
233
 
    d = pci_create_simple(b, 0, "i440FX");
 
258
    d = pci_create_simple(b, 0, device_name);
234
259
    *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
235
260
 
236
 
    piix3 = DO_UPCAST(PIIX3State, dev,
237
 
                      pci_create_simple_multifunction(b, -1, true, "PIIX3"));
 
261
    /* Xen supports additional interrupt routes from the PCI devices to
 
262
     * the IOAPIC: the four pins of each PCI device on the bus are also
 
263
     * connected to the IOAPIC directly.
 
264
     * These additional routes can be discovered through ACPI. */
 
265
    if (xen_enabled()) {
 
266
        piix3 = DO_UPCAST(PIIX3State, dev,
 
267
                pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
 
268
        pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
 
269
                piix3, XEN_PIIX_NUM_PIRQS);
 
270
    } else {
 
271
        piix3 = DO_UPCAST(PIIX3State, dev,
 
272
                pci_create_simple_multifunction(b, -1, true, "PIIX3"));
 
273
        pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
 
274
                PIIX_NUM_PIRQS);
 
275
    }
238
276
    piix3->pic = pic;
239
 
    pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, 4);
 
277
 
240
278
    (*pi440fx_state)->piix3 = piix3;
241
279
 
242
280
    *piix3_devfn = piix3->dev.devfn;
249
287
    return b;
250
288
}
251
289
 
 
290
PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
 
291
                    qemu_irq *pic, ram_addr_t ram_size)
 
292
{
 
293
    PCIBus *b;
 
294
 
 
295
    b = i440fx_common_init("i440FX", pi440fx_state, piix3_devfn, pic, ram_size);
 
296
    return b;
 
297
}
 
298
 
252
299
/* PIIX3 PCI to ISA bridge */
253
 
 
254
 
static void piix3_set_irq(void *opaque, int irq_num, int level)
255
 
{
256
 
    int i, pic_irq, pic_level;
 
300
static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
 
301
{
 
302
    qemu_set_irq(piix3->pic[pic_irq],
 
303
                 !!(piix3->pic_levels &
 
304
                    (((1ULL << PIIX_NUM_PIRQS) - 1) <<
 
305
                     (pic_irq * PIIX_NUM_PIRQS))));
 
306
}
 
307
 
 
308
static void piix3_set_irq_level(PIIX3State *piix3, int pirq, int level)
 
309
{
 
310
    int pic_irq;
 
311
    uint64_t mask;
 
312
 
 
313
    pic_irq = piix3->dev.config[PIIX_PIRQC + pirq];
 
314
    if (pic_irq >= PIIX_NUM_PIC_IRQS) {
 
315
        return;
 
316
    }
 
317
 
 
318
    mask = 1ULL << ((pic_irq * PIIX_NUM_PIRQS) + pirq);
 
319
    piix3->pic_levels &= ~mask;
 
320
    piix3->pic_levels |= mask * !!level;
 
321
 
 
322
    piix3_set_irq_pic(piix3, pic_irq);
 
323
}
 
324
 
 
325
static void piix3_set_irq(void *opaque, int pirq, int level)
 
326
{
257
327
    PIIX3State *piix3 = opaque;
258
 
 
259
 
    piix3->pci_irq_levels[irq_num] = level;
260
 
 
261
 
    /* now we change the pic irq level according to the piix irq mappings */
262
 
    /* XXX: optimize */
263
 
    pic_irq = piix3->dev.config[0x60 + irq_num];
264
 
    if (pic_irq < 16) {
265
 
        /* The pic level is the logical OR of all the PCI irqs mapped
266
 
           to it */
267
 
        pic_level = 0;
268
 
        for (i = 0; i < 4; i++) {
269
 
            if (pic_irq == piix3->dev.config[0x60 + i])
270
 
                pic_level |= piix3->pci_irq_levels[i];
 
328
    piix3_set_irq_level(piix3, pirq, level);
 
329
}
 
330
 
 
331
/* irq routing is changed. so rebuild bitmap */
 
332
static void piix3_update_irq_levels(PIIX3State *piix3)
 
333
{
 
334
    int pirq;
 
335
 
 
336
    piix3->pic_levels = 0;
 
337
    for (pirq = 0; pirq < PIIX_NUM_PIRQS; pirq++) {
 
338
        piix3_set_irq_level(piix3, pirq,
 
339
                            pci_bus_get_irq_level(piix3->dev.bus, pirq));
 
340
    }
 
341
}
 
342
 
 
343
static void piix3_write_config(PCIDevice *dev,
 
344
                               uint32_t address, uint32_t val, int len)
 
345
{
 
346
    pci_default_write_config(dev, address, val, len);
 
347
    if (ranges_overlap(address, len, PIIX_PIRQC, 4)) {
 
348
        PIIX3State *piix3 = DO_UPCAST(PIIX3State, dev, dev);
 
349
        int pic_irq;
 
350
        piix3_update_irq_levels(piix3);
 
351
        for (pic_irq = 0; pic_irq < PIIX_NUM_PIC_IRQS; pic_irq++) {
 
352
            piix3_set_irq_pic(piix3, pic_irq);
271
353
        }
272
 
        qemu_set_irq(piix3->pic[pic_irq], pic_level);
273
354
    }
274
355
}
275
356
 
 
357
static void piix3_write_config_xen(PCIDevice *dev,
 
358
                               uint32_t address, uint32_t val, int len)
 
359
{
 
360
    xen_piix_pci_write_config_client(address, val, len);
 
361
    piix3_write_config(dev, address, val, len);
 
362
}
 
363
 
276
364
static void piix3_reset(void *opaque)
277
365
{
278
366
    PIIX3State *d = opaque;
310
398
    pci_conf[0xac] = 0x00;
311
399
    pci_conf[0xae] = 0x00;
312
400
 
313
 
    memset(d->pci_irq_levels, 0, sizeof(d->pci_irq_levels));
 
401
    d->pic_levels = 0;
 
402
}
 
403
 
 
404
static int piix3_post_load(void *opaque, int version_id)
 
405
{
 
406
    PIIX3State *piix3 = opaque;
 
407
    piix3_update_irq_levels(piix3);
 
408
    return 0;
 
409
}
 
410
 
 
411
static void piix3_pre_save(void *opaque)
 
412
{
 
413
    int i;
 
414
    PIIX3State *piix3 = opaque;
 
415
 
 
416
    for (i = 0; i < ARRAY_SIZE(piix3->pci_irq_levels_vmstate); i++) {
 
417
        piix3->pci_irq_levels_vmstate[i] =
 
418
            pci_bus_get_irq_level(piix3->dev.bus, i);
 
419
    }
314
420
}
315
421
 
316
422
static const VMStateDescription vmstate_piix3 = {
318
424
    .version_id = 3,
319
425
    .minimum_version_id = 2,
320
426
    .minimum_version_id_old = 2,
 
427
    .post_load = piix3_post_load,
 
428
    .pre_save = piix3_pre_save,
321
429
    .fields      = (VMStateField []) {
322
430
        VMSTATE_PCI_DEVICE(dev, PIIX3State),
323
 
        VMSTATE_INT32_ARRAY_V(pci_irq_levels, PIIX3State, 4, 3),
 
431
        VMSTATE_INT32_ARRAY_V(pci_irq_levels_vmstate, PIIX3State,
 
432
                              PIIX_NUM_PIRQS, 3),
324
433
        VMSTATE_END_OF_LIST()
325
434
    }
326
435
};
328
437
static int piix3_initfn(PCIDevice *dev)
329
438
{
330
439
    PIIX3State *d = DO_UPCAST(PIIX3State, dev, dev);
331
 
    uint8_t *pci_conf;
332
440
 
333
441
    isa_bus_new(&d->dev.qdev);
334
 
 
335
 
    pci_conf = d->dev.config;
336
 
    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
337
 
    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_0); // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
338
 
    pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
339
 
 
340
442
    qemu_register_reset(piix3_reset, d);
341
443
    return 0;
342
444
}
351
453
        .no_hotplug   = 1,
352
454
        .init         = i440fx_initfn,
353
455
        .config_write = i440fx_write_config,
 
456
        .vendor_id    = PCI_VENDOR_ID_INTEL,
 
457
        .device_id    = PCI_DEVICE_ID_INTEL_82441,
 
458
        .revision     = 0x02,
 
459
        .class_id     = PCI_CLASS_BRIDGE_HOST,
354
460
    },{
355
461
        .qdev.name    = "PIIX3",
356
462
        .qdev.desc    = "ISA bridge",
359
465
        .qdev.no_user = 1,
360
466
        .no_hotplug   = 1,
361
467
        .init         = piix3_initfn,
 
468
        .config_write = piix3_write_config,
 
469
        .vendor_id    = PCI_VENDOR_ID_INTEL,
 
470
        .device_id    = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
 
471
        .class_id     = PCI_CLASS_BRIDGE_ISA,
 
472
    },{
 
473
        .qdev.name    = "PIIX3-xen",
 
474
        .qdev.desc    = "ISA bridge",
 
475
        .qdev.size    = sizeof(PIIX3State),
 
476
        .qdev.vmsd    = &vmstate_piix3,
 
477
        .qdev.no_user = 1,
 
478
        .no_hotplug   = 1,
 
479
        .init         = piix3_initfn,
 
480
        .config_write = piix3_write_config_xen,
 
481
        .vendor_id    = PCI_VENDOR_ID_INTEL,
 
482
        .device_id    = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
 
483
        .class_id     = PCI_CLASS_BRIDGE_ISA,
362
484
    },{
363
485
        /* end of list */
364
486
    }