piix4.c 3.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * QEMU PIIX4 PCI Bridge Emulation
 *
 * Copyright (c) 2006 Fabrice Bellard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

25
#include "hw/hw.h"
P
Paolo Bonzini 已提交
26
#include "hw/i386/pc.h"
27
#include "hw/pci/pci.h"
P
Paolo Bonzini 已提交
28
#include "hw/isa/isa.h"
29
#include "hw/sysbus.h"
30 31 32

PCIDevice *piix4_dev;

J
Juan Quintela 已提交
33 34 35 36
typedef struct PIIX4State {
    PCIDevice dev;
} PIIX4State;

37 38
static void piix4_reset(void *opaque)
{
J
Juan Quintela 已提交
39 40
    PIIX4State *d = opaque;
    uint8_t *pci_conf = d->dev.config;
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

    pci_conf[0x04] = 0x07; // master, memory and I/O
    pci_conf[0x05] = 0x00;
    pci_conf[0x06] = 0x00;
    pci_conf[0x07] = 0x02; // PCI_status_devsel_medium
    pci_conf[0x4c] = 0x4d;
    pci_conf[0x4e] = 0x03;
    pci_conf[0x4f] = 0x00;
    pci_conf[0x60] = 0x0a; // PCI A -> IRQ 10
    pci_conf[0x61] = 0x0a; // PCI B -> IRQ 10
    pci_conf[0x62] = 0x0b; // PCI C -> IRQ 11
    pci_conf[0x63] = 0x0b; // PCI D -> IRQ 11
    pci_conf[0x69] = 0x02;
    pci_conf[0x70] = 0x80;
    pci_conf[0x76] = 0x0c;
    pci_conf[0x77] = 0x0c;
    pci_conf[0x78] = 0x02;
    pci_conf[0x79] = 0x00;
    pci_conf[0x80] = 0x00;
    pci_conf[0x82] = 0x00;
    pci_conf[0xa0] = 0x08;
    pci_conf[0xa2] = 0x00;
    pci_conf[0xa3] = 0x00;
    pci_conf[0xa4] = 0x00;
    pci_conf[0xa5] = 0x00;
    pci_conf[0xa6] = 0x00;
    pci_conf[0xa7] = 0x00;
    pci_conf[0xa8] = 0x0f;
    pci_conf[0xaa] = 0x00;
    pci_conf[0xab] = 0x00;
    pci_conf[0xac] = 0x00;
    pci_conf[0xae] = 0x00;
}

J
Juan Quintela 已提交
75 76 77 78 79 80 81 82 83 84
static const VMStateDescription vmstate_piix4 = {
    .name = "PIIX4",
    .version_id = 2,
    .minimum_version_id = 2,
    .minimum_version_id_old = 2,
    .fields      = (VMStateField[]) {
        VMSTATE_PCI_DEVICE(dev, PIIX4State),
        VMSTATE_END_OF_LIST()
    }
};
85

J
Juan Quintela 已提交
86
static int piix4_initfn(PCIDevice *dev)
87
{
J
Juan Quintela 已提交
88
    PIIX4State *d = DO_UPCAST(PIIX4State, dev, dev);
89

90
    isa_bus_new(&d->dev.qdev, pci_address_space_io(dev));
J
Juan Quintela 已提交
91
    piix4_dev = &d->dev;
92 93 94 95
    qemu_register_reset(piix4_reset, d);
    return 0;
}

96
int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn)
97 98 99
{
    PCIDevice *d;

100
    d = pci_create_simple_multifunction(bus, devfn, true, "PIIX4");
101
    *isa_bus = DO_UPCAST(ISABus, qbus, qdev_get_child_bus(&d->qdev, "isa.0"));
102 103 104
    return d->devfn;
}

105 106
static void piix4_class_init(ObjectClass *klass, void *data)
{
107
    DeviceClass *dc = DEVICE_CLASS(klass);
108 109 110 111 112 113 114
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

    k->no_hotplug = 1;
    k->init = piix4_initfn;
    k->vendor_id = PCI_VENDOR_ID_INTEL;
    k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
    k->class_id = PCI_CLASS_BRIDGE_ISA;
115 116 117
    dc->desc = "ISA bridge";
    dc->no_user = 1;
    dc->vmsd = &vmstate_piix4;
118 119
}

120
static const TypeInfo piix4_info = {
121 122 123 124
    .name          = "PIIX4",
    .parent        = TYPE_PCI_DEVICE,
    .instance_size = sizeof(PIIX4State),
    .class_init    = piix4_class_init,
125 126
};

A
Andreas Färber 已提交
127
static void piix4_register_types(void)
128
{
129
    type_register_static(&piix4_info);
130
}
A
Andreas Färber 已提交
131 132

type_init(piix4_register_types)