]> git.proxmox.com Git - mirror_qemu.git/blame - hw/versatile_pci.c
hw/arm11mpcore: Clean up to avoid using sysbus_mmio_init_cb2
[mirror_qemu.git] / hw / versatile_pci.c
CommitLineData
5fafdf24 1/*
502a5395
PB
2 * ARM Versatile/PB PCI host controller
3 *
0027b06d 4 * Copyright (c) 2006-2009 CodeSourcery.
502a5395
PB
5 * Written by Paul Brook
6 *
8e31bf38 7 * This code is licensed under the LGPL.
502a5395
PB
8 */
9
0027b06d 10#include "sysbus.h"
87ecb68b 11#include "pci.h"
b6243d99 12#include "pci_host.h"
1e39101c 13#include "exec-memory.h"
0027b06d
PB
14
15typedef struct {
16 SysBusDevice busdev;
17 qemu_irq irq[4];
18 int realview;
45de094e
AK
19 MemoryRegion mem_config;
20 MemoryRegion mem_config2;
21 MemoryRegion isa;
0027b06d 22} PCIVPBState;
502a5395 23
c227f099 24static inline uint32_t vpb_pci_config_addr(target_phys_addr_t addr)
502a5395 25{
80b3ada7 26 return addr & 0xffffff;
502a5395
PB
27}
28
45de094e
AK
29static void pci_vpb_config_write(void *opaque, target_phys_addr_t addr,
30 uint64_t val, unsigned size)
502a5395 31{
45de094e 32 pci_data_write(opaque, vpb_pci_config_addr(addr), val, size);
502a5395
PB
33}
34
45de094e
AK
35static uint64_t pci_vpb_config_read(void *opaque, target_phys_addr_t addr,
36 unsigned size)
502a5395
PB
37{
38 uint32_t val;
45de094e 39 val = pci_data_read(opaque, vpb_pci_config_addr(addr), size);
502a5395
PB
40 return val;
41}
42
45de094e
AK
43static const MemoryRegionOps pci_vpb_config_ops = {
44 .read = pci_vpb_config_read,
45 .write = pci_vpb_config_write,
46 .endianness = DEVICE_NATIVE_ENDIAN,
502a5395
PB
47};
48
d2b59317
PB
49static int pci_vpb_map_irq(PCIDevice *d, int irq_num)
50{
51 return irq_num;
52}
53
5d4e84c8 54static void pci_vpb_set_irq(void *opaque, int irq_num, int level)
502a5395 55{
5d4e84c8
JQ
56 qemu_irq *pic = opaque;
57
97aff481 58 qemu_set_irq(pic[irq_num], level);
502a5395
PB
59}
60
45de094e 61
c227f099 62static void pci_vpb_map(SysBusDevice *dev, target_phys_addr_t base)
502a5395 63{
0027b06d
PB
64 PCIVPBState *s = (PCIVPBState *)dev;
65 /* Selfconfig area. */
45de094e
AK
66 memory_region_add_subregion(get_system_memory(), base + 0x01000000,
67 &s->mem_config);
68 /* Normal config area. */
69 memory_region_add_subregion(get_system_memory(), base + 0x02000000,
70 &s->mem_config2);
71
72 if (s->realview) {
73 /* IO memory area. */
74 memory_region_add_subregion(get_system_memory(), base + 0x03000000,
75 &s->isa);
76 }
77}
78
79static void pci_vpb_unmap(SysBusDevice *dev, target_phys_addr_t base)
80{
81 PCIVPBState *s = (PCIVPBState *)dev;
82 /* Selfconfig area. */
83 memory_region_del_subregion(get_system_memory(), &s->mem_config);
0027b06d 84 /* Normal config area. */
45de094e 85 memory_region_del_subregion(get_system_memory(), &s->mem_config2);
0027b06d
PB
86
87 if (s->realview) {
88 /* IO memory area. */
45de094e 89 memory_region_del_subregion(get_system_memory(), &s->isa);
0027b06d
PB
90 }
91}
92
81a322d4 93static int pci_vpb_init(SysBusDevice *dev)
0027b06d
PB
94{
95 PCIVPBState *s = FROM_SYSBUS(PCIVPBState, dev);
96 PCIBus *bus;
97aff481 97 int i;
e69954b9 98
97aff481 99 for (i = 0; i < 4; i++) {
0027b06d 100 sysbus_init_irq(dev, &s->irq[i]);
e69954b9 101 }
02e2da45
PB
102 bus = pci_register_bus(&dev->qdev, "pci",
103 pci_vpb_set_irq, pci_vpb_map_irq, s->irq,
aee97b84 104 get_system_memory(), get_system_io(),
520128bd 105 PCI_DEVFN(11, 0), 4);
0027b06d 106
502a5395
PB
107 /* ??? Register memory space. */
108
45de094e
AK
109 memory_region_init_io(&s->mem_config, &pci_vpb_config_ops, bus,
110 "pci-vpb-selfconfig", 0x1000000);
111 memory_region_init_io(&s->mem_config2, &pci_vpb_config_ops, bus,
112 "pci-vpb-config", 0x1000000);
113 if (s->realview) {
114 isa_mmio_setup(&s->isa, 0x0100000);
115 }
116
117 sysbus_init_mmio_cb2(dev, pci_vpb_map, pci_vpb_unmap);
e69954b9 118
0027b06d 119 pci_create_simple(bus, -1, "versatile_pci_host");
81a322d4 120 return 0;
0027b06d 121}
e69954b9 122
81a322d4 123static int pci_realview_init(SysBusDevice *dev)
0027b06d
PB
124{
125 PCIVPBState *s = FROM_SYSBUS(PCIVPBState, dev);
126 s->realview = 1;
81a322d4 127 return pci_vpb_init(dev);
0027b06d 128}
502a5395 129
81a322d4 130static int versatile_pci_host_init(PCIDevice *d)
0027b06d 131{
a408b1de
MT
132 pci_set_word(d->config + PCI_STATUS,
133 PCI_STATUS_66MHZ | PCI_STATUS_DEVSEL_MEDIUM);
01764fe0 134 pci_set_byte(d->config + PCI_LATENCY_TIMER, 0x10);
81a322d4 135 return 0;
0027b06d 136}
502a5395 137
0aab0d3a
GH
138static PCIDeviceInfo versatile_pci_host_info = {
139 .qdev.name = "versatile_pci_host",
140 .qdev.size = sizeof(PCIDevice),
141 .init = versatile_pci_host_init,
56fe6408
IY
142 .vendor_id = PCI_VENDOR_ID_XILINX,
143 /* Both boards have the same device ID. Oh well. */
144 .device_id = PCI_DEVICE_ID_XILINX_XC2VP30,
145 .class_id = PCI_CLASS_PROCESSOR_CO,
0aab0d3a
GH
146};
147
0027b06d
PB
148static void versatile_pci_register_devices(void)
149{
150 sysbus_register_dev("versatile_pci", sizeof(PCIVPBState), pci_vpb_init);
151 sysbus_register_dev("realview_pci", sizeof(PCIVPBState),
152 pci_realview_init);
0aab0d3a 153 pci_qdev_register(&versatile_pci_host_info);
502a5395 154}
0027b06d
PB
155
156device_init(versatile_pci_register_devices)