]> Git Repo - qemu.git/blame - hw/pci-host/prep.c
qdev: Replace no_user by cannot_instantiate_with_device_add_yet
[qemu.git] / hw / pci-host / prep.c
CommitLineData
502a5395
PB
1/*
2 * QEMU PREP PCI host
3 *
4 * Copyright (c) 2006 Fabrice Bellard
98aca3c8 5 * Copyright (c) 2011-2013 Andreas Färber
5fafdf24 6 *
502a5395
PB
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
83c9f4ca
PB
26#include "hw/hw.h"
27#include "hw/pci/pci.h"
28#include "hw/pci/pci_bus.h"
29#include "hw/pci/pci_host.h"
0d09e41a 30#include "hw/i386/pc.h"
022c62cb 31#include "exec/address-spaces.h"
502a5395 32
98aca3c8 33#define TYPE_RAVEN_PCI_DEVICE "raven"
03a6b667
AF
34#define TYPE_RAVEN_PCI_HOST_BRIDGE "raven-pcihost"
35
98aca3c8
AF
36#define RAVEN_PCI_DEVICE(obj) \
37 OBJECT_CHECK(RavenPCIState, (obj), TYPE_RAVEN_PCI_DEVICE)
38
39typedef struct RavenPCIState {
40 PCIDevice dev;
41} RavenPCIState;
42
03a6b667
AF
43#define RAVEN_PCI_HOST_BRIDGE(obj) \
44 OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE)
45
8ca8c7bc 46typedef struct PRePPCIState {
67c332fd 47 PCIHostState parent_obj;
03a6b667 48
6c84ce0d 49 MemoryRegion intack;
8ca8c7bc 50 qemu_irq irq[4];
98aca3c8
AF
51 PCIBus pci_bus;
52 RavenPCIState pci_dev;
8ca8c7bc 53} PREPPCIState;
502a5395 54
a8170e5e 55static inline uint32_t PPC_PCIIO_config(hwaddr addr)
502a5395
PB
56{
57 int i;
58
03a6b667
AF
59 for (i = 0; i < 11; i++) {
60 if ((addr & (1 << (11 + i))) != 0) {
502a5395 61 break;
03a6b667 62 }
502a5395
PB
63 }
64 return (addr & 0x7ff) | (i << 11);
65}
66
a8170e5e 67static void ppc_pci_io_write(void *opaque, hwaddr addr,
7e5610ff 68 uint64_t val, unsigned int size)
502a5395
PB
69{
70 PREPPCIState *s = opaque;
67c332fd
AF
71 PCIHostState *phb = PCI_HOST_BRIDGE(s);
72 pci_data_write(phb->bus, PPC_PCIIO_config(addr), val, size);
502a5395
PB
73}
74
a8170e5e 75static uint64_t ppc_pci_io_read(void *opaque, hwaddr addr,
7e5610ff 76 unsigned int size)
502a5395
PB
77{
78 PREPPCIState *s = opaque;
67c332fd
AF
79 PCIHostState *phb = PCI_HOST_BRIDGE(s);
80 return pci_data_read(phb->bus, PPC_PCIIO_config(addr), size);
502a5395
PB
81}
82
f81138ce 83static const MemoryRegionOps PPC_PCIIO_ops = {
7e5610ff
AF
84 .read = ppc_pci_io_read,
85 .write = ppc_pci_io_write,
9c95f183 86 .endianness = DEVICE_LITTLE_ENDIAN,
502a5395
PB
87};
88
a8170e5e 89static uint64_t ppc_intack_read(void *opaque, hwaddr addr,
6c84ce0d
HP
90 unsigned int size)
91{
92 return pic_read_irq(isa_pic);
93}
94
95static const MemoryRegionOps PPC_intack_ops = {
96 .read = ppc_intack_read,
97 .valid = {
98 .max_access_size = 1,
99 },
100};
101
d2b59317 102static int prep_map_irq(PCIDevice *pci_dev, int irq_num)
502a5395 103{
80b3ada7 104 return (irq_num + (pci_dev->devfn >> 3)) & 1;
d2b59317
PB
105}
106
5d4e84c8 107static void prep_set_irq(void *opaque, int irq_num, int level)
d2b59317 108{
5d4e84c8
JQ
109 qemu_irq *pic = opaque;
110
8ca8c7bc 111 qemu_set_irq(pic[irq_num] , level);
502a5395
PB
112}
113
8d5ce2e5 114static void raven_pcihost_realizefn(DeviceState *d, Error **errp)
502a5395 115{
8d5ce2e5 116 SysBusDevice *dev = SYS_BUS_DEVICE(d);
8558d942 117 PCIHostState *h = PCI_HOST_BRIDGE(dev);
03a6b667 118 PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(dev);
8ca8c7bc 119 MemoryRegion *address_space_mem = get_system_memory();
8ca8c7bc
AF
120 int i;
121
768d7e2c
HP
122 isa_mem_base = 0xc0000000;
123
8ca8c7bc
AF
124 for (i = 0; i < 4; i++) {
125 sysbus_init_irq(dev, &s->irq[i]);
126 }
502a5395 127
98aca3c8 128 pci_bus_irqs(&s->pci_bus, prep_set_irq, prep_map_irq, s->irq, 4);
502a5395 129
40c5dce9 130 memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_be_ops, s,
d0ed8076 131 "pci-conf-idx", 1);
8ca8c7bc
AF
132 sysbus_add_io(dev, 0xcf8, &h->conf_mem);
133 sysbus_init_ioports(&h->busdev, 0xcf8, 1);
d0ed8076 134
40c5dce9 135 memory_region_init_io(&h->data_mem, OBJECT(h), &pci_host_data_be_ops, s,
d0ed8076 136 "pci-conf-data", 1);
8ca8c7bc
AF
137 sysbus_add_io(dev, 0xcfc, &h->data_mem);
138 sysbus_init_ioports(&h->busdev, 0xcfc, 1);
502a5395 139
40c5dce9 140 memory_region_init_io(&h->mmcfg, OBJECT(s), &PPC_PCIIO_ops, s, "pciio", 0x00400000);
8ca8c7bc 141 memory_region_add_subregion(address_space_mem, 0x80800000, &h->mmcfg);
502a5395 142
40c5dce9 143 memory_region_init_io(&s->intack, OBJECT(s), &PPC_intack_ops, s, "pci-intack", 1);
6c84ce0d 144 memory_region_add_subregion(address_space_mem, 0xbffffff0, &s->intack);
55526054 145
98aca3c8 146 /* TODO Remove once realize propagates to child devices. */
8d5ce2e5 147 object_property_set_bool(OBJECT(&s->pci_dev), true, "realized", errp);
98aca3c8
AF
148}
149
150static void raven_pcihost_initfn(Object *obj)
151{
152 PCIHostState *h = PCI_HOST_BRIDGE(obj);
153 PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(obj);
154 MemoryRegion *address_space_mem = get_system_memory();
155 MemoryRegion *address_space_io = get_system_io();
156 DeviceState *pci_dev;
157
dd301ca6 158 pci_bus_new_inplace(&s->pci_bus, sizeof(s->pci_bus), DEVICE(obj), NULL,
60a0e443 159 address_space_mem, address_space_io, 0, TYPE_PCI_BUS);
98aca3c8
AF
160 h->bus = &s->pci_bus;
161
213f0c4f 162 object_initialize(&s->pci_dev, sizeof(s->pci_dev), TYPE_RAVEN_PCI_DEVICE);
98aca3c8
AF
163 pci_dev = DEVICE(&s->pci_dev);
164 qdev_set_parent_bus(pci_dev, BUS(&s->pci_bus));
165 object_property_set_int(OBJECT(&s->pci_dev), PCI_DEVFN(0, 0), "addr",
166 NULL);
167 qdev_prop_set_bit(pci_dev, "multifunction", false);
55526054
AF
168}
169
170static int raven_init(PCIDevice *d)
171{
502a5395
PB
172 d->config[0x0C] = 0x08; // cache_line_size
173 d->config[0x0D] = 0x10; // latency_timer
502a5395
PB
174 d->config[0x34] = 0x00; // capabilities_pointer
175
55526054 176 return 0;
502a5395 177}
55526054
AF
178
179static const VMStateDescription vmstate_raven = {
180 .name = "raven",
181 .version_id = 0,
182 .minimum_version_id = 0,
183 .fields = (VMStateField[]) {
184 VMSTATE_PCI_DEVICE(dev, RavenPCIState),
185 VMSTATE_END_OF_LIST()
186 },
187};
188
40021f08
AL
189static void raven_class_init(ObjectClass *klass, void *data)
190{
191 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
39bffca2 192 DeviceClass *dc = DEVICE_CLASS(klass);
40021f08
AL
193
194 k->init = raven_init;
195 k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
196 k->device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN;
197 k->revision = 0x00;
198 k->class_id = PCI_CLASS_BRIDGE_HOST;
39bffca2
AL
199 dc->desc = "PReP Host Bridge - Motorola Raven";
200 dc->vmsd = &vmstate_raven;
efec3dd6 201 dc->cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
40021f08
AL
202}
203
4240abff 204static const TypeInfo raven_info = {
98aca3c8 205 .name = TYPE_RAVEN_PCI_DEVICE,
39bffca2
AL
206 .parent = TYPE_PCI_DEVICE,
207 .instance_size = sizeof(RavenPCIState),
40021f08 208 .class_init = raven_class_init,
55526054
AF
209};
210
999e12bb
AL
211static void raven_pcihost_class_init(ObjectClass *klass, void *data)
212{
39bffca2 213 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 214
125ee0ed 215 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
8d5ce2e5 216 dc->realize = raven_pcihost_realizefn;
39bffca2 217 dc->fw_name = "pci";
efec3dd6 218 dc->cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
999e12bb
AL
219}
220
4240abff 221static const TypeInfo raven_pcihost_info = {
03a6b667 222 .name = TYPE_RAVEN_PCI_HOST_BRIDGE,
8558d942 223 .parent = TYPE_PCI_HOST_BRIDGE,
39bffca2 224 .instance_size = sizeof(PREPPCIState),
98aca3c8 225 .instance_init = raven_pcihost_initfn,
999e12bb 226 .class_init = raven_pcihost_class_init,
8ca8c7bc
AF
227};
228
83f7d43a 229static void raven_register_types(void)
55526054 230{
39bffca2
AL
231 type_register_static(&raven_pcihost_info);
232 type_register_static(&raven_info);
55526054
AF
233}
234
83f7d43a 235type_init(raven_register_types)
This page took 0.853747 seconds and 4 git commands to generate.