root / hw / versatile_pci.c @ 92f562ec
History | View | Annotate | Download (4.3 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | 502a5395 | pbrook | * ARM Versatile/PB PCI host controller
|
3 | 502a5395 | pbrook | *
|
4 | 0027b06d | Paul Brook | * Copyright (c) 2006-2009 CodeSourcery.
|
5 | 502a5395 | pbrook | * Written by Paul Brook
|
6 | 502a5395 | pbrook | *
|
7 | 8e31bf38 | Matthew Fernandez | * This code is licensed under the LGPL.
|
8 | 502a5395 | pbrook | */
|
9 | 502a5395 | pbrook | |
10 | 0027b06d | Paul Brook | #include "sysbus.h" |
11 | 87ecb68b | pbrook | #include "pci.h" |
12 | b6243d99 | Isaku Yamahata | #include "pci_host.h" |
13 | 1e39101c | Avi Kivity | #include "exec-memory.h" |
14 | 0027b06d | Paul Brook | |
15 | 0027b06d | Paul Brook | typedef struct { |
16 | 0027b06d | Paul Brook | SysBusDevice busdev; |
17 | 0027b06d | Paul Brook | qemu_irq irq[4];
|
18 | 0027b06d | Paul Brook | int realview;
|
19 | 0027b06d | Paul Brook | int mem_config;
|
20 | 0027b06d | Paul Brook | } PCIVPBState; |
21 | 502a5395 | pbrook | |
22 | c227f099 | Anthony Liguori | static inline uint32_t vpb_pci_config_addr(target_phys_addr_t addr) |
23 | 502a5395 | pbrook | { |
24 | 80b3ada7 | pbrook | return addr & 0xffffff; |
25 | 502a5395 | pbrook | } |
26 | 502a5395 | pbrook | |
27 | c227f099 | Anthony Liguori | static void pci_vpb_config_writeb (void *opaque, target_phys_addr_t addr, |
28 | 502a5395 | pbrook | uint32_t val) |
29 | 502a5395 | pbrook | { |
30 | 502a5395 | pbrook | pci_data_write(opaque, vpb_pci_config_addr (addr), val, 1);
|
31 | 502a5395 | pbrook | } |
32 | 502a5395 | pbrook | |
33 | c227f099 | Anthony Liguori | static void pci_vpb_config_writew (void *opaque, target_phys_addr_t addr, |
34 | 502a5395 | pbrook | uint32_t val) |
35 | 502a5395 | pbrook | { |
36 | 502a5395 | pbrook | pci_data_write(opaque, vpb_pci_config_addr (addr), val, 2);
|
37 | 502a5395 | pbrook | } |
38 | 502a5395 | pbrook | |
39 | c227f099 | Anthony Liguori | static void pci_vpb_config_writel (void *opaque, target_phys_addr_t addr, |
40 | 502a5395 | pbrook | uint32_t val) |
41 | 502a5395 | pbrook | { |
42 | 502a5395 | pbrook | pci_data_write(opaque, vpb_pci_config_addr (addr), val, 4);
|
43 | 502a5395 | pbrook | } |
44 | 502a5395 | pbrook | |
45 | c227f099 | Anthony Liguori | static uint32_t pci_vpb_config_readb (void *opaque, target_phys_addr_t addr) |
46 | 502a5395 | pbrook | { |
47 | 502a5395 | pbrook | uint32_t val; |
48 | 502a5395 | pbrook | val = pci_data_read(opaque, vpb_pci_config_addr (addr), 1);
|
49 | 502a5395 | pbrook | return val;
|
50 | 502a5395 | pbrook | } |
51 | 502a5395 | pbrook | |
52 | c227f099 | Anthony Liguori | static uint32_t pci_vpb_config_readw (void *opaque, target_phys_addr_t addr) |
53 | 502a5395 | pbrook | { |
54 | 502a5395 | pbrook | uint32_t val; |
55 | 502a5395 | pbrook | val = pci_data_read(opaque, vpb_pci_config_addr (addr), 2);
|
56 | 502a5395 | pbrook | return val;
|
57 | 502a5395 | pbrook | } |
58 | 502a5395 | pbrook | |
59 | c227f099 | Anthony Liguori | static uint32_t pci_vpb_config_readl (void *opaque, target_phys_addr_t addr) |
60 | 502a5395 | pbrook | { |
61 | 502a5395 | pbrook | uint32_t val; |
62 | 502a5395 | pbrook | val = pci_data_read(opaque, vpb_pci_config_addr (addr), 4);
|
63 | 502a5395 | pbrook | return val;
|
64 | 502a5395 | pbrook | } |
65 | 502a5395 | pbrook | |
66 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pci_vpb_config_write[] = { |
67 | 502a5395 | pbrook | &pci_vpb_config_writeb, |
68 | 502a5395 | pbrook | &pci_vpb_config_writew, |
69 | 502a5395 | pbrook | &pci_vpb_config_writel, |
70 | 502a5395 | pbrook | }; |
71 | 502a5395 | pbrook | |
72 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pci_vpb_config_read[] = { |
73 | 502a5395 | pbrook | &pci_vpb_config_readb, |
74 | 502a5395 | pbrook | &pci_vpb_config_readw, |
75 | 502a5395 | pbrook | &pci_vpb_config_readl, |
76 | 502a5395 | pbrook | }; |
77 | 502a5395 | pbrook | |
78 | d2b59317 | pbrook | static int pci_vpb_map_irq(PCIDevice *d, int irq_num) |
79 | d2b59317 | pbrook | { |
80 | d2b59317 | pbrook | return irq_num;
|
81 | d2b59317 | pbrook | } |
82 | d2b59317 | pbrook | |
83 | 5d4e84c8 | Juan Quintela | static void pci_vpb_set_irq(void *opaque, int irq_num, int level) |
84 | 502a5395 | pbrook | { |
85 | 5d4e84c8 | Juan Quintela | qemu_irq *pic = opaque; |
86 | 5d4e84c8 | Juan Quintela | |
87 | 97aff481 | Paul Brook | qemu_set_irq(pic[irq_num], level); |
88 | 502a5395 | pbrook | } |
89 | 502a5395 | pbrook | |
90 | c227f099 | Anthony Liguori | static void pci_vpb_map(SysBusDevice *dev, target_phys_addr_t base) |
91 | 502a5395 | pbrook | { |
92 | 0027b06d | Paul Brook | PCIVPBState *s = (PCIVPBState *)dev; |
93 | 0027b06d | Paul Brook | /* Selfconfig area. */
|
94 | 0027b06d | Paul Brook | cpu_register_physical_memory(base + 0x01000000, 0x1000000, s->mem_config); |
95 | 0027b06d | Paul Brook | /* Normal config area. */
|
96 | 0027b06d | Paul Brook | cpu_register_physical_memory(base + 0x02000000, 0x1000000, s->mem_config); |
97 | 0027b06d | Paul Brook | |
98 | 0027b06d | Paul Brook | if (s->realview) {
|
99 | 0027b06d | Paul Brook | /* IO memory area. */
|
100 | 968d683c | Alexander Graf | isa_mmio_init(base + 0x03000000, 0x00100000); |
101 | 0027b06d | Paul Brook | } |
102 | 0027b06d | Paul Brook | } |
103 | 0027b06d | Paul Brook | |
104 | 81a322d4 | Gerd Hoffmann | static int pci_vpb_init(SysBusDevice *dev) |
105 | 0027b06d | Paul Brook | { |
106 | 0027b06d | Paul Brook | PCIVPBState *s = FROM_SYSBUS(PCIVPBState, dev); |
107 | 0027b06d | Paul Brook | PCIBus *bus; |
108 | 97aff481 | Paul Brook | int i;
|
109 | e69954b9 | pbrook | |
110 | 97aff481 | Paul Brook | for (i = 0; i < 4; i++) { |
111 | 0027b06d | Paul Brook | sysbus_init_irq(dev, &s->irq[i]); |
112 | e69954b9 | pbrook | } |
113 | 02e2da45 | Paul Brook | bus = pci_register_bus(&dev->qdev, "pci",
|
114 | 02e2da45 | Paul Brook | pci_vpb_set_irq, pci_vpb_map_irq, s->irq, |
115 | aee97b84 | Avi Kivity | get_system_memory(), get_system_io(), |
116 | 520128bd | Isaku Yamahata | PCI_DEVFN(11, 0), 4); |
117 | 0027b06d | Paul Brook | |
118 | 502a5395 | pbrook | /* ??? Register memory space. */
|
119 | 502a5395 | pbrook | |
120 | 1eed09cb | Avi Kivity | s->mem_config = cpu_register_io_memory(pci_vpb_config_read, |
121 | 2507c12a | Alexander Graf | pci_vpb_config_write, bus, |
122 | 387c3e96 | Alexander Graf | DEVICE_LITTLE_ENDIAN); |
123 | 0027b06d | Paul Brook | sysbus_init_mmio_cb(dev, 0x04000000, pci_vpb_map);
|
124 | e69954b9 | pbrook | |
125 | 0027b06d | Paul Brook | pci_create_simple(bus, -1, "versatile_pci_host"); |
126 | 81a322d4 | Gerd Hoffmann | return 0; |
127 | 0027b06d | Paul Brook | } |
128 | e69954b9 | pbrook | |
129 | 81a322d4 | Gerd Hoffmann | static int pci_realview_init(SysBusDevice *dev) |
130 | 0027b06d | Paul Brook | { |
131 | 0027b06d | Paul Brook | PCIVPBState *s = FROM_SYSBUS(PCIVPBState, dev); |
132 | 0027b06d | Paul Brook | s->realview = 1;
|
133 | 81a322d4 | Gerd Hoffmann | return pci_vpb_init(dev);
|
134 | 0027b06d | Paul Brook | } |
135 | 502a5395 | pbrook | |
136 | 81a322d4 | Gerd Hoffmann | static int versatile_pci_host_init(PCIDevice *d) |
137 | 0027b06d | Paul Brook | { |
138 | a408b1de | Michael S. Tsirkin | pci_set_word(d->config + PCI_STATUS, |
139 | a408b1de | Michael S. Tsirkin | PCI_STATUS_66MHZ | PCI_STATUS_DEVSEL_MEDIUM); |
140 | 01764fe0 | Michael S. Tsirkin | pci_set_byte(d->config + PCI_LATENCY_TIMER, 0x10);
|
141 | 81a322d4 | Gerd Hoffmann | return 0; |
142 | 0027b06d | Paul Brook | } |
143 | 502a5395 | pbrook | |
144 | 0aab0d3a | Gerd Hoffmann | static PCIDeviceInfo versatile_pci_host_info = {
|
145 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "versatile_pci_host",
|
146 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(PCIDevice),
|
147 | 0aab0d3a | Gerd Hoffmann | .init = versatile_pci_host_init, |
148 | 56fe6408 | Isaku Yamahata | .vendor_id = PCI_VENDOR_ID_XILINX, |
149 | 56fe6408 | Isaku Yamahata | /* Both boards have the same device ID. Oh well. */
|
150 | 56fe6408 | Isaku Yamahata | .device_id = PCI_DEVICE_ID_XILINX_XC2VP30, |
151 | 56fe6408 | Isaku Yamahata | .class_id = PCI_CLASS_PROCESSOR_CO, |
152 | 0aab0d3a | Gerd Hoffmann | }; |
153 | 0aab0d3a | Gerd Hoffmann | |
154 | 0027b06d | Paul Brook | static void versatile_pci_register_devices(void) |
155 | 0027b06d | Paul Brook | { |
156 | 0027b06d | Paul Brook | sysbus_register_dev("versatile_pci", sizeof(PCIVPBState), pci_vpb_init); |
157 | 0027b06d | Paul Brook | sysbus_register_dev("realview_pci", sizeof(PCIVPBState), |
158 | 0027b06d | Paul Brook | pci_realview_init); |
159 | 0aab0d3a | Gerd Hoffmann | pci_qdev_register(&versatile_pci_host_info); |
160 | 502a5395 | pbrook | } |
161 | 0027b06d | Paul Brook | |
162 | 0027b06d | Paul Brook | device_init(versatile_pci_register_devices) |