2 * QEMU Intel i82378 emulation (PCI to ISA bridge)
4 * Copyright (c) 2010-2011 Hervé Poussineau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "hw/pci/pci.h"
21 #include "hw/i386/pc.h"
22 #include "hw/timer/i8254.h"
23 #include "hw/audio/pcspk.h"
25 #define TYPE_I82378 "i82378"
27 OBJECT_CHECK(I82378State, (obj), TYPE_I82378)
29 typedef struct I82378State
{
37 static const VMStateDescription vmstate_i82378
= {
40 .minimum_version_id
= 0,
41 .fields
= (VMStateField
[]) {
42 VMSTATE_PCI_DEVICE(parent_obj
, I82378State
),
47 static void i82378_request_out0_irq(void *opaque
, int irq
, int level
)
49 I82378State
*s
= opaque
;
50 qemu_set_irq(s
->out
[0], level
);
53 static void i82378_request_pic_irq(void *opaque
, int irq
, int level
)
55 DeviceState
*dev
= opaque
;
56 I82378State
*s
= I82378(dev
);
58 qemu_set_irq(s
->i8259
[irq
], level
);
61 static void i82378_realize(PCIDevice
*pci
, Error
**errp
)
63 DeviceState
*dev
= DEVICE(pci
);
64 I82378State
*s
= I82378(dev
);
69 pci_conf
= pci
->config
;
70 pci_set_word(pci_conf
+ PCI_COMMAND
,
71 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
);
72 pci_set_word(pci_conf
+ PCI_STATUS
,
73 PCI_STATUS_DEVSEL_MEDIUM
);
75 pci_config_set_interrupt_pin(pci_conf
, 1); /* interrupt pin 0 */
77 isabus
= isa_bus_new(dev
, get_system_memory(),
78 pci_address_space_io(pci
));
85 Utility Bus Support Registers
87 All devices accept byte access only, except timer
91 s
->i8259
= i8259_init(isabus
,
92 qemu_allocate_irq(i82378_request_out0_irq
, s
, 0));
93 isa_bus_irqs(isabus
, s
->i8259
);
96 isa
= pit_init(isabus
, 0x40, 0, NULL
);
99 pcspk_init(isabus
, isa
);
102 isa
= isa_create_simple(isabus
, "i82374");
105 isa_create_simple(isabus
, "mc146818rtc");
108 static void i82378_init(Object
*obj
)
110 DeviceState
*dev
= DEVICE(obj
);
111 I82378State
*s
= I82378(obj
);
113 qdev_init_gpio_out(dev
, s
->out
, 1);
114 qdev_init_gpio_in(dev
, i82378_request_pic_irq
, 16);
117 static void i82378_class_init(ObjectClass
*klass
, void *data
)
119 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
120 DeviceClass
*dc
= DEVICE_CLASS(klass
);
122 k
->realize
= i82378_realize
;
123 k
->vendor_id
= PCI_VENDOR_ID_INTEL
;
124 k
->device_id
= PCI_DEVICE_ID_INTEL_82378
;
126 k
->class_id
= PCI_CLASS_BRIDGE_ISA
;
127 dc
->vmsd
= &vmstate_i82378
;
128 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
131 static const TypeInfo i82378_type_info
= {
133 .parent
= TYPE_PCI_DEVICE
,
134 .instance_size
= sizeof(I82378State
),
135 .instance_init
= i82378_init
,
136 .class_init
= i82378_class_init
,
139 static void i82378_register_types(void)
141 type_register_static(&i82378_type_info
);
144 type_init(i82378_register_types
)