]> git.proxmox.com Git - qemu.git/blame - hw/prep_pci.c
virtio-blk: hide VIRTIO_BLK_F_CONFIG_WCE from old machine types
[qemu.git] / hw / prep_pci.c
CommitLineData
502a5395
PB
1/*
2 * QEMU PREP PCI host
3 *
4 * Copyright (c) 2006 Fabrice Bellard
5fafdf24 5 *
502a5395
PB
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
87ecb68b
PB
25#include "hw.h"
26#include "pci.h"
502a5395 27#include "pci_host.h"
6c84ce0d 28#include "pc.h"
8ca8c7bc 29#include "exec-memory.h"
502a5395 30
8ca8c7bc
AF
31typedef struct PRePPCIState {
32 PCIHostState host_state;
6c84ce0d 33 MemoryRegion intack;
8ca8c7bc
AF
34 qemu_irq irq[4];
35} PREPPCIState;
502a5395 36
55526054
AF
37typedef struct RavenPCIState {
38 PCIDevice dev;
39} RavenPCIState;
40
c227f099 41static inline uint32_t PPC_PCIIO_config(target_phys_addr_t addr)
502a5395
PB
42{
43 int i;
44
45 for(i = 0; i < 11; i++) {
46 if ((addr & (1 << (11 + i))) != 0)
47 break;
48 }
49 return (addr & 0x7ff) | (i << 11);
50}
51
7e5610ff
AF
52static void ppc_pci_io_write(void *opaque, target_phys_addr_t addr,
53 uint64_t val, unsigned int size)
502a5395
PB
54{
55 PREPPCIState *s = opaque;
8ca8c7bc 56 pci_data_write(s->host_state.bus, PPC_PCIIO_config(addr), val, size);
502a5395
PB
57}
58
7e5610ff
AF
59static uint64_t ppc_pci_io_read(void *opaque, target_phys_addr_t addr,
60 unsigned int size)
502a5395
PB
61{
62 PREPPCIState *s = opaque;
8ca8c7bc 63 return pci_data_read(s->host_state.bus, PPC_PCIIO_config(addr), size);
502a5395
PB
64}
65
f81138ce 66static const MemoryRegionOps PPC_PCIIO_ops = {
7e5610ff
AF
67 .read = ppc_pci_io_read,
68 .write = ppc_pci_io_write,
9c95f183 69 .endianness = DEVICE_LITTLE_ENDIAN,
502a5395
PB
70};
71
6c84ce0d
HP
72static uint64_t ppc_intack_read(void *opaque, target_phys_addr_t addr,
73 unsigned int size)
74{
75 return pic_read_irq(isa_pic);
76}
77
78static const MemoryRegionOps PPC_intack_ops = {
79 .read = ppc_intack_read,
80 .valid = {
81 .max_access_size = 1,
82 },
83};
84
d2b59317 85static int prep_map_irq(PCIDevice *pci_dev, int irq_num)
502a5395 86{
80b3ada7 87 return (irq_num + (pci_dev->devfn >> 3)) & 1;
d2b59317
PB
88}
89
5d4e84c8 90static void prep_set_irq(void *opaque, int irq_num, int level)
d2b59317 91{
5d4e84c8
JQ
92 qemu_irq *pic = opaque;
93
8ca8c7bc 94 qemu_set_irq(pic[irq_num] , level);
502a5395
PB
95}
96
8ca8c7bc 97static int raven_pcihost_init(SysBusDevice *dev)
502a5395 98{
8ca8c7bc
AF
99 PCIHostState *h = FROM_SYSBUS(PCIHostState, dev);
100 PREPPCIState *s = DO_UPCAST(PREPPCIState, host_state, h);
101 MemoryRegion *address_space_mem = get_system_memory();
102 MemoryRegion *address_space_io = get_system_io();
103 PCIBus *bus;
104 int i;
105
106 for (i = 0; i < 4; i++) {
107 sysbus_init_irq(dev, &s->irq[i]);
108 }
502a5395 109
8ca8c7bc
AF
110 bus = pci_register_bus(&h->busdev.qdev, NULL,
111 prep_set_irq, prep_map_irq, s->irq,
112 address_space_mem, address_space_io, 0, 4);
113 h->bus = bus;
502a5395 114
8ca8c7bc 115 memory_region_init_io(&h->conf_mem, &pci_host_conf_be_ops, s,
d0ed8076 116 "pci-conf-idx", 1);
8ca8c7bc
AF
117 sysbus_add_io(dev, 0xcf8, &h->conf_mem);
118 sysbus_init_ioports(&h->busdev, 0xcf8, 1);
d0ed8076 119
8ca8c7bc 120 memory_region_init_io(&h->data_mem, &pci_host_data_be_ops, s,
d0ed8076 121 "pci-conf-data", 1);
8ca8c7bc
AF
122 sysbus_add_io(dev, 0xcfc, &h->data_mem);
123 sysbus_init_ioports(&h->busdev, 0xcfc, 1);
502a5395 124
8ca8c7bc
AF
125 memory_region_init_io(&h->mmcfg, &PPC_PCIIO_ops, s, "pciio", 0x00400000);
126 memory_region_add_subregion(address_space_mem, 0x80800000, &h->mmcfg);
502a5395 127
6c84ce0d
HP
128 memory_region_init_io(&s->intack, &PPC_intack_ops, s, "pci-intack", 1);
129 memory_region_add_subregion(address_space_mem, 0xbffffff0, &s->intack);
8ca8c7bc 130 pci_create_simple(bus, 0, "raven");
55526054 131
8ca8c7bc 132 return 0;
55526054
AF
133}
134
135static int raven_init(PCIDevice *d)
136{
502a5395
PB
137 d->config[0x0C] = 0x08; // cache_line_size
138 d->config[0x0D] = 0x10; // latency_timer
502a5395
PB
139 d->config[0x34] = 0x00; // capabilities_pointer
140
55526054 141 return 0;
502a5395 142}
55526054
AF
143
144static const VMStateDescription vmstate_raven = {
145 .name = "raven",
146 .version_id = 0,
147 .minimum_version_id = 0,
148 .fields = (VMStateField[]) {
149 VMSTATE_PCI_DEVICE(dev, RavenPCIState),
150 VMSTATE_END_OF_LIST()
151 },
152};
153
40021f08
AL
154static void raven_class_init(ObjectClass *klass, void *data)
155{
156 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
39bffca2 157 DeviceClass *dc = DEVICE_CLASS(klass);
40021f08
AL
158
159 k->init = raven_init;
160 k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
161 k->device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN;
162 k->revision = 0x00;
163 k->class_id = PCI_CLASS_BRIDGE_HOST;
39bffca2
AL
164 dc->desc = "PReP Host Bridge - Motorola Raven";
165 dc->vmsd = &vmstate_raven;
166 dc->no_user = 1;
40021f08
AL
167}
168
39bffca2 169static TypeInfo raven_info = {
40021f08 170 .name = "raven",
39bffca2
AL
171 .parent = TYPE_PCI_DEVICE,
172 .instance_size = sizeof(RavenPCIState),
40021f08 173 .class_init = raven_class_init,
55526054
AF
174};
175
999e12bb
AL
176static void raven_pcihost_class_init(ObjectClass *klass, void *data)
177{
178 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
39bffca2 179 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb
AL
180
181 k->init = raven_pcihost_init;
39bffca2
AL
182 dc->fw_name = "pci";
183 dc->no_user = 1;
999e12bb
AL
184}
185
39bffca2 186static TypeInfo raven_pcihost_info = {
999e12bb 187 .name = "raven-pcihost",
39bffca2
AL
188 .parent = TYPE_SYS_BUS_DEVICE,
189 .instance_size = sizeof(PREPPCIState),
999e12bb 190 .class_init = raven_pcihost_class_init,
8ca8c7bc
AF
191};
192
83f7d43a 193static void raven_register_types(void)
55526054 194{
39bffca2
AL
195 type_register_static(&raven_pcihost_info);
196 type_register_static(&raven_info);
55526054
AF
197}
198
83f7d43a 199type_init(raven_register_types)