xref: /openbmc/qemu/hw/isa/i82378.c (revision 8fa3b702)
1 /*
2  * QEMU Intel i82378 emulation (PCI to ISA bridge)
3  *
4  * Copyright (c) 2010-2011 Hervé Poussineau
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 
20 #include "qemu/osdep.h"
21 #include "hw/pci/pci.h"
22 #include "hw/irq.h"
23 #include "hw/intc/i8259.h"
24 #include "hw/timer/i8254.h"
25 #include "migration/vmstate.h"
26 #include "hw/audio/pcspk.h"
27 #include "qom/object.h"
28 
29 #define TYPE_I82378 "i82378"
30 typedef struct I82378State I82378State;
31 DECLARE_INSTANCE_CHECKER(I82378State, I82378,
32                          TYPE_I82378)
33 
34 struct I82378State {
35     PCIDevice parent_obj;
36 
37     qemu_irq out[2];
38     qemu_irq *i8259;
39     MemoryRegion io;
40 };
41 
42 static const VMStateDescription vmstate_i82378 = {
43     .name = "pci-i82378",
44     .version_id = 0,
45     .minimum_version_id = 0,
46     .fields = (VMStateField[]) {
47         VMSTATE_PCI_DEVICE(parent_obj, I82378State),
48         VMSTATE_END_OF_LIST()
49     },
50 };
51 
52 static void i82378_request_out0_irq(void *opaque, int irq, int level)
53 {
54     I82378State *s = opaque;
55     qemu_set_irq(s->out[0], level);
56 }
57 
58 static void i82378_request_pic_irq(void *opaque, int irq, int level)
59 {
60     DeviceState *dev = opaque;
61     I82378State *s = I82378(dev);
62 
63     qemu_set_irq(s->i8259[irq], level);
64 }
65 
66 static void i82378_realize(PCIDevice *pci, Error **errp)
67 {
68     DeviceState *dev = DEVICE(pci);
69     I82378State *s = I82378(dev);
70     uint8_t *pci_conf;
71     ISABus *isabus;
72     ISADevice *pit;
73 
74     pci_conf = pci->config;
75     pci_set_word(pci_conf + PCI_COMMAND,
76                  PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
77     pci_set_word(pci_conf + PCI_STATUS,
78                  PCI_STATUS_DEVSEL_MEDIUM);
79 
80     pci_config_set_interrupt_pin(pci_conf, 1); /* interrupt pin 0 */
81 
82     isabus = isa_bus_new(dev, get_system_memory(),
83                          pci_address_space_io(pci), errp);
84     if (!isabus) {
85         return;
86     }
87 
88     /* This device has:
89        2 82C59 (irq)
90        1 82C54 (pit)
91        2 82C37 (dma)
92        NMI
93        Utility Bus Support Registers
94 
95        All devices accept byte access only, except timer
96      */
97 
98     /* 2 82C59 (irq) */
99     s->i8259 = i8259_init(isabus,
100                           qemu_allocate_irq(i82378_request_out0_irq, s, 0));
101     isa_bus_irqs(isabus, s->i8259);
102 
103     /* 1 82C54 (pit) */
104     pit = i8254_pit_init(isabus, 0x40, 0, NULL);
105 
106     /* speaker */
107     pcspk_init(isa_new(TYPE_PC_SPEAKER), isabus, pit);
108 
109     /* 2 82C37 (dma) */
110     isa_create_simple(isabus, "i82374");
111 }
112 
113 static void i82378_init(Object *obj)
114 {
115     DeviceState *dev = DEVICE(obj);
116     I82378State *s = I82378(obj);
117 
118     qdev_init_gpio_out(dev, s->out, 1);
119     qdev_init_gpio_in(dev, i82378_request_pic_irq, 16);
120 }
121 
122 static void i82378_class_init(ObjectClass *klass, void *data)
123 {
124     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
125     DeviceClass *dc = DEVICE_CLASS(klass);
126 
127     k->realize = i82378_realize;
128     k->vendor_id = PCI_VENDOR_ID_INTEL;
129     k->device_id = PCI_DEVICE_ID_INTEL_82378;
130     k->revision = 0x03;
131     k->class_id = PCI_CLASS_BRIDGE_ISA;
132     dc->vmsd = &vmstate_i82378;
133     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
134 }
135 
136 static const TypeInfo i82378_type_info = {
137     .name = TYPE_I82378,
138     .parent = TYPE_PCI_DEVICE,
139     .instance_size = sizeof(I82378State),
140     .instance_init = i82378_init,
141     .class_init = i82378_class_init,
142     .interfaces = (InterfaceInfo[]) {
143         { INTERFACE_CONVENTIONAL_PCI_DEVICE },
144         { },
145     },
146 };
147 
148 static void i82378_register_types(void)
149 {
150     type_register_static(&i82378_type_info);
151 }
152 
153 type_init(i82378_register_types)
154