2010-12-25 08:01:41 +03:00
|
|
|
/*
|
|
|
|
* QEMU Intel i82378 emulation (PCI to ISA bridge)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2011 Hervé Poussineau
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/i386/pc.h"
|
|
|
|
#include "hw/timer/i8254.h"
|
|
|
|
#include "hw/audio/pcspk.h"
|
2010-12-25 08:01:41 +03:00
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
#define TYPE_I82378 "i82378"
|
|
|
|
#define I82378(obj) \
|
|
|
|
OBJECT_CHECK(I82378State, (obj), TYPE_I82378)
|
2010-12-25 08:01:41 +03:00
|
|
|
|
|
|
|
typedef struct I82378State {
|
2013-07-24 01:16:46 +04:00
|
|
|
PCIDevice parent_obj;
|
|
|
|
|
2010-12-25 08:01:41 +03:00
|
|
|
qemu_irq out[2];
|
|
|
|
qemu_irq *i8259;
|
|
|
|
MemoryRegion io;
|
|
|
|
} I82378State;
|
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
static const VMStateDescription vmstate_i82378 = {
|
2010-12-25 08:01:41 +03:00
|
|
|
.name = "pci-i82378",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
2013-07-24 01:16:46 +04:00
|
|
|
VMSTATE_PCI_DEVICE(parent_obj, I82378State),
|
2010-12-25 08:01:41 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void i82378_request_out0_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
I82378State *s = opaque;
|
|
|
|
qemu_set_irq(s->out[0], level);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i82378_request_pic_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
DeviceState *dev = opaque;
|
2013-07-24 01:16:46 +04:00
|
|
|
I82378State *s = I82378(dev);
|
2010-12-25 08:01:41 +03:00
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
qemu_set_irq(s->i8259[irq], level);
|
2010-12-25 08:01:41 +03:00
|
|
|
}
|
|
|
|
|
2015-01-19 17:52:30 +03:00
|
|
|
static void i82378_realize(PCIDevice *pci, Error **errp)
|
2010-12-25 08:01:41 +03:00
|
|
|
{
|
2013-07-24 01:16:46 +04:00
|
|
|
DeviceState *dev = DEVICE(pci);
|
|
|
|
I82378State *s = I82378(dev);
|
|
|
|
uint8_t *pci_conf;
|
|
|
|
ISABus *isabus;
|
2012-03-17 18:39:41 +04:00
|
|
|
ISADevice *isa;
|
2010-12-25 08:01:41 +03:00
|
|
|
qemu_irq *out0_irq;
|
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
pci_conf = pci->config;
|
|
|
|
pci_set_word(pci_conf + PCI_COMMAND,
|
|
|
|
PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
|
|
|
|
pci_set_word(pci_conf + PCI_STATUS,
|
|
|
|
PCI_STATUS_DEVSEL_MEDIUM);
|
|
|
|
|
|
|
|
pci_config_set_interrupt_pin(pci_conf, 1); /* interrupt pin 0 */
|
|
|
|
|
2015-02-01 11:12:50 +03:00
|
|
|
isabus = isa_bus_new(dev, get_system_memory(),
|
|
|
|
pci_address_space_io(pci));
|
2013-07-24 01:16:46 +04:00
|
|
|
|
2010-12-25 08:01:41 +03:00
|
|
|
/* This device has:
|
|
|
|
2 82C59 (irq)
|
|
|
|
1 82C54 (pit)
|
|
|
|
2 82C37 (dma)
|
|
|
|
NMI
|
|
|
|
Utility Bus Support Registers
|
|
|
|
|
|
|
|
All devices accept byte access only, except timer
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Workaround the fact that i8259 is not qdev'ified... */
|
|
|
|
out0_irq = qemu_allocate_irqs(i82378_request_out0_irq, s, 1);
|
|
|
|
|
|
|
|
/* 2 82C59 (irq) */
|
|
|
|
s->i8259 = i8259_init(isabus, *out0_irq);
|
|
|
|
isa_bus_irqs(isabus, s->i8259);
|
|
|
|
|
|
|
|
/* 1 82C54 (pit) */
|
2013-07-24 01:16:46 +04:00
|
|
|
isa = pit_init(isabus, 0x40, 0, NULL);
|
2010-12-25 08:01:41 +03:00
|
|
|
|
|
|
|
/* speaker */
|
2013-07-24 01:16:46 +04:00
|
|
|
pcspk_init(isabus, isa);
|
2010-12-25 08:01:41 +03:00
|
|
|
|
|
|
|
/* 2 82C37 (dma) */
|
2012-03-17 18:39:41 +04:00
|
|
|
isa = isa_create_simple(isabus, "i82374");
|
2013-06-07 15:49:13 +04:00
|
|
|
qdev_connect_gpio_out(DEVICE(isa), 0, s->out[1]);
|
2010-12-25 08:01:41 +03:00
|
|
|
|
|
|
|
/* timer */
|
|
|
|
isa_create_simple(isabus, "mc146818rtc");
|
|
|
|
}
|
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
static void i82378_init(Object *obj)
|
2010-12-25 08:01:41 +03:00
|
|
|
{
|
2013-07-24 01:16:46 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
I82378State *s = I82378(obj);
|
2010-12-25 08:01:41 +03:00
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
qdev_init_gpio_out(dev, s->out, 2);
|
|
|
|
qdev_init_gpio_in(dev, i82378_request_pic_irq, 16);
|
2010-12-25 08:01:41 +03:00
|
|
|
}
|
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
static void i82378_class_init(ObjectClass *klass, void *data)
|
2011-12-04 22:22:06 +04:00
|
|
|
{
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 22:22:06 +04:00
|
|
|
|
2015-01-19 17:52:30 +03:00
|
|
|
k->realize = i82378_realize;
|
2011-12-04 22:22:06 +04:00
|
|
|
k->vendor_id = PCI_VENDOR_ID_INTEL;
|
|
|
|
k->device_id = PCI_DEVICE_ID_INTEL_82378;
|
|
|
|
k->revision = 0x03;
|
|
|
|
k->class_id = PCI_CLASS_BRIDGE_ISA;
|
2013-07-24 01:16:46 +04:00
|
|
|
dc->vmsd = &vmstate_i82378;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2011-12-04 22:22:06 +04:00
|
|
|
}
|
|
|
|
|
2013-07-24 01:16:46 +04:00
|
|
|
static const TypeInfo i82378_type_info = {
|
|
|
|
.name = TYPE_I82378,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
2013-07-24 01:16:46 +04:00
|
|
|
.instance_size = sizeof(I82378State),
|
|
|
|
.instance_init = i82378_init,
|
|
|
|
.class_init = i82378_class_init,
|
2010-12-25 08:01:41 +03:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void i82378_register_types(void)
|
2010-12-25 08:01:41 +03:00
|
|
|
{
|
2013-07-24 01:16:46 +04:00
|
|
|
type_register_static(&i82378_type_info);
|
2010-12-25 08:01:41 +03:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(i82378_register_types)
|