2009-08-28 15:28:13 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:03 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/hw.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/i386/pc.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/pci/pci.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/isa/isa.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2009-08-28 15:28:13 +02:00
|
|
|
|
|
|
|
PCIDevice *piix4_dev;
|
|
|
|
|
2010-12-02 16:26:56 +01:00
|
|
|
typedef struct PIIX4State {
|
|
|
|
PCIDevice dev;
|
|
|
|
} PIIX4State;
|
|
|
|
|
2015-05-13 02:43:24 +02:00
|
|
|
#define TYPE_PIIX4_PCI_DEVICE "PIIX4"
|
|
|
|
#define PIIX4_PCI_DEVICE(obj) \
|
|
|
|
OBJECT_CHECK(PIIX4State, (obj), TYPE_PIIX4_PCI_DEVICE)
|
|
|
|
|
2009-08-28 15:28:13 +02:00
|
|
|
static void piix4_reset(void *opaque)
|
|
|
|
{
|
2010-12-02 16:26:56 +01:00
|
|
|
PIIX4State *d = opaque;
|
|
|
|
uint8_t *pci_conf = d->dev.config;
|
2009-08-28 15:28:13 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-02 16:59:33 +01:00
|
|
|
static const VMStateDescription vmstate_piix4 = {
|
|
|
|
.name = "PIIX4",
|
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-04-16 15:32:32 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2010-12-02 16:59:33 +01:00
|
|
|
VMSTATE_PCI_DEVICE(dev, PIIX4State),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2009-08-28 15:28:13 +02:00
|
|
|
|
2015-01-19 15:52:30 +01:00
|
|
|
static void piix4_realize(PCIDevice *dev, Error **errp)
|
2009-08-28 15:28:13 +02:00
|
|
|
{
|
2015-05-13 02:43:24 +02:00
|
|
|
PIIX4State *d = PIIX4_PCI_DEVICE(dev);
|
2009-08-28 15:28:13 +02:00
|
|
|
|
isa: Clean up error handling around isa_bus_new()
We can have at most one ISA bus. If you try to create another one,
isa_bus_new() complains to stderr and returns null.
isa_bus_new() is called in two contexts, machine's init() and device's
realize() methods. Since complaining to stderr is not proper in the
latter context, convert isa_bus_new() to Error.
Machine's init():
* mips_jazz_init(), called from the init() methods of machines
"magnum" and "pica"
* mips_r4k_init(), the init() method of machine "mips"
* pc_init1() called from the init() methods of non-q35 PC machines
* typhoon_init(), called from clipper_init(), the init() method of
machine "clipper"
These callers always create the first ISA bus, hence isa_bus_new()
can't fail. Simply pass &error_abort.
Device's realize():
* i82378_realize(), of PCI device "i82378"
* ich9_lpc_realize(), of PCI device "ICH9-LPC"
* pci_ebus_realize(), of PCI device "ebus"
* piix3_realize(), of PCI device "pci-piix3", abstract parent of
"PIIX3" and "PIIX3-xen"
* piix4_realize(), of PCI device "PIIX4"
* vt82c686b_realize(), of PCI device "VT82C686B"
Propagate the error. Note that these devices are typically created
only by machine init() methods with qdev_init_nofail() or similar. If
we screwed up and created an ISA bus before that call, we now give up
right away. Before, we'd hobble on, and typically die in
isa_bus_irqs(). Similar if someone finds a way to hot-plug one of
these critters.
Cc: Richard Henderson <rth@twiddle.net>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "Hervé Poussineau" <hpoussin@reactos.org>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <1450370121-5768-11-git-send-email-armbru@redhat.com>
2015-12-17 17:35:18 +01:00
|
|
|
if (!isa_bus_new(DEVICE(d), pci_address_space(dev),
|
|
|
|
pci_address_space_io(dev), errp)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-12-02 16:26:56 +01:00
|
|
|
piix4_dev = &d->dev;
|
2009-08-28 15:28:13 +02:00
|
|
|
qemu_register_reset(piix4_reset, d);
|
|
|
|
}
|
|
|
|
|
2011-12-15 22:09:58 +01:00
|
|
|
int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn)
|
2009-08-28 15:28:13 +02:00
|
|
|
{
|
|
|
|
PCIDevice *d;
|
|
|
|
|
2010-06-23 09:15:31 +02:00
|
|
|
d = pci_create_simple_multifunction(bus, devfn, true, "PIIX4");
|
2013-06-07 14:11:07 +02:00
|
|
|
*isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(d), "isa.0"));
|
2009-08-28 15:28:13 +02:00
|
|
|
return d->devfn;
|
|
|
|
}
|
|
|
|
|
2011-12-04 19:22:06 +01:00
|
|
|
static void piix4_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 19:22:06 +01:00
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
|
2015-01-19 15:52:30 +01:00
|
|
|
k->realize = piix4_realize;
|
2011-12-04 19:22:06 +01:00
|
|
|
k->vendor_id = PCI_VENDOR_ID_INTEL;
|
|
|
|
k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
|
|
|
|
k->class_id = PCI_CLASS_BRIDGE_ISA;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "ISA bridge";
|
|
|
|
dc->vmsd = &vmstate_piix4;
|
2013-11-28 17:27:00 +01:00
|
|
|
/*
|
|
|
|
* Reason: part of PIIX4 southbridge, needs to be wired up,
|
|
|
|
* e.g. by mips_malta_init()
|
|
|
|
*/
|
2017-05-03 22:35:44 +02:00
|
|
|
dc->user_creatable = false;
|
2014-02-05 16:36:48 +01:00
|
|
|
dc->hotpluggable = false;
|
2011-12-04 19:22:06 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo piix4_info = {
|
2015-05-13 02:43:24 +02:00
|
|
|
.name = TYPE_PIIX4_PCI_DEVICE,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(PIIX4State),
|
|
|
|
.class_init = piix4_class_init,
|
2017-09-27 21:56:34 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2009-08-28 15:28:13 +02:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void piix4_register_types(void)
|
2009-08-28 15:28:13 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&piix4_info);
|
2009-08-28 15:28:13 +02:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(piix4_register_types)
|