root / hw / xen_platform.c @ 416343b1
History | View | Annotate | Download (11 kB)
1 | 01195b73 | Steven Smith | /*
|
---|---|---|---|
2 | 01195b73 | Steven Smith | * XEN platform pci device, formerly known as the event channel device
|
3 | 01195b73 | Steven Smith | *
|
4 | 01195b73 | Steven Smith | * Copyright (c) 2003-2004 Intel Corp.
|
5 | 01195b73 | Steven Smith | * Copyright (c) 2006 XenSource
|
6 | 01195b73 | Steven Smith | *
|
7 | 01195b73 | Steven Smith | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | 01195b73 | Steven Smith | * of this software and associated documentation files (the "Software"), to deal
|
9 | 01195b73 | Steven Smith | * in the Software without restriction, including without limitation the rights
|
10 | 01195b73 | Steven Smith | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | 01195b73 | Steven Smith | * copies of the Software, and to permit persons to whom the Software is
|
12 | 01195b73 | Steven Smith | * furnished to do so, subject to the following conditions:
|
13 | 01195b73 | Steven Smith | *
|
14 | 01195b73 | Steven Smith | * The above copyright notice and this permission notice shall be included in
|
15 | 01195b73 | Steven Smith | * all copies or substantial portions of the Software.
|
16 | 01195b73 | Steven Smith | *
|
17 | 01195b73 | Steven Smith | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | 01195b73 | Steven Smith | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | 01195b73 | Steven Smith | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | 01195b73 | Steven Smith | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | 01195b73 | Steven Smith | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | 01195b73 | Steven Smith | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | 01195b73 | Steven Smith | * THE SOFTWARE.
|
24 | 01195b73 | Steven Smith | */
|
25 | 01195b73 | Steven Smith | |
26 | 01195b73 | Steven Smith | #include <assert.h> |
27 | 01195b73 | Steven Smith | |
28 | 01195b73 | Steven Smith | #include "hw.h" |
29 | 01195b73 | Steven Smith | #include "pc.h" |
30 | 01195b73 | Steven Smith | #include "pci.h" |
31 | 01195b73 | Steven Smith | #include "irq.h" |
32 | 01195b73 | Steven Smith | #include "xen_common.h" |
33 | 01195b73 | Steven Smith | #include "net.h" |
34 | 01195b73 | Steven Smith | #include "xen_backend.h" |
35 | 01195b73 | Steven Smith | #include "trace.h" |
36 | de00982e | Avi Kivity | #include "exec-memory.h" |
37 | 01195b73 | Steven Smith | |
38 | 01195b73 | Steven Smith | #include <xenguest.h> |
39 | 01195b73 | Steven Smith | |
40 | 01195b73 | Steven Smith | //#define DEBUG_PLATFORM
|
41 | 01195b73 | Steven Smith | |
42 | 01195b73 | Steven Smith | #ifdef DEBUG_PLATFORM
|
43 | 01195b73 | Steven Smith | #define DPRINTF(fmt, ...) do { \ |
44 | 01195b73 | Steven Smith | fprintf(stderr, "xen_platform: " fmt, ## __VA_ARGS__); \ |
45 | 01195b73 | Steven Smith | } while (0) |
46 | 01195b73 | Steven Smith | #else
|
47 | 01195b73 | Steven Smith | #define DPRINTF(fmt, ...) do { } while (0) |
48 | 01195b73 | Steven Smith | #endif
|
49 | 01195b73 | Steven Smith | |
50 | 01195b73 | Steven Smith | #define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */ |
51 | 01195b73 | Steven Smith | |
52 | 01195b73 | Steven Smith | typedef struct PCIXenPlatformState { |
53 | 01195b73 | Steven Smith | PCIDevice pci_dev; |
54 | de00982e | Avi Kivity | MemoryRegion fixed_io; |
55 | de00982e | Avi Kivity | MemoryRegion bar; |
56 | de00982e | Avi Kivity | MemoryRegion mmio_bar; |
57 | 01195b73 | Steven Smith | uint8_t flags; /* used only for version_id == 2 */
|
58 | 01195b73 | Steven Smith | int drivers_blacklisted;
|
59 | 01195b73 | Steven Smith | uint16_t driver_product_version; |
60 | 01195b73 | Steven Smith | |
61 | 01195b73 | Steven Smith | /* Log from guest drivers */
|
62 | 01195b73 | Steven Smith | char log_buffer[4096]; |
63 | 01195b73 | Steven Smith | int log_buffer_off;
|
64 | 01195b73 | Steven Smith | } PCIXenPlatformState; |
65 | 01195b73 | Steven Smith | |
66 | 01195b73 | Steven Smith | #define XEN_PLATFORM_IOPORT 0x10 |
67 | 01195b73 | Steven Smith | |
68 | 01195b73 | Steven Smith | /* Send bytes to syslog */
|
69 | 01195b73 | Steven Smith | static void log_writeb(PCIXenPlatformState *s, char val) |
70 | 01195b73 | Steven Smith | { |
71 | 01195b73 | Steven Smith | if (val == '\n' || s->log_buffer_off == sizeof(s->log_buffer) - 1) { |
72 | 01195b73 | Steven Smith | /* Flush buffer */
|
73 | 01195b73 | Steven Smith | s->log_buffer[s->log_buffer_off] = 0;
|
74 | 01195b73 | Steven Smith | trace_xen_platform_log(s->log_buffer); |
75 | 01195b73 | Steven Smith | s->log_buffer_off = 0;
|
76 | 01195b73 | Steven Smith | } else {
|
77 | 01195b73 | Steven Smith | s->log_buffer[s->log_buffer_off++] = val; |
78 | 01195b73 | Steven Smith | } |
79 | 01195b73 | Steven Smith | } |
80 | 01195b73 | Steven Smith | |
81 | 01195b73 | Steven Smith | /* Xen Platform, Fixed IOPort */
|
82 | 679f4f8b | Stefano Stabellini | #define UNPLUG_ALL_IDE_DISKS 1 |
83 | 679f4f8b | Stefano Stabellini | #define UNPLUG_ALL_NICS 2 |
84 | 679f4f8b | Stefano Stabellini | #define UNPLUG_AUX_IDE_DISKS 4 |
85 | 679f4f8b | Stefano Stabellini | |
86 | 679f4f8b | Stefano Stabellini | static void unplug_nic(PCIBus *b, PCIDevice *d) |
87 | 679f4f8b | Stefano Stabellini | { |
88 | 679f4f8b | Stefano Stabellini | if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
|
89 | 679f4f8b | Stefano Stabellini | PCI_CLASS_NETWORK_ETHERNET) { |
90 | 679f4f8b | Stefano Stabellini | qdev_unplug(&(d->qdev)); |
91 | 679f4f8b | Stefano Stabellini | } |
92 | 679f4f8b | Stefano Stabellini | } |
93 | 679f4f8b | Stefano Stabellini | |
94 | 679f4f8b | Stefano Stabellini | static void pci_unplug_nics(PCIBus *bus) |
95 | 679f4f8b | Stefano Stabellini | { |
96 | 679f4f8b | Stefano Stabellini | pci_for_each_device(bus, 0, unplug_nic);
|
97 | 679f4f8b | Stefano Stabellini | } |
98 | 679f4f8b | Stefano Stabellini | |
99 | 679f4f8b | Stefano Stabellini | static void unplug_disks(PCIBus *b, PCIDevice *d) |
100 | 679f4f8b | Stefano Stabellini | { |
101 | 679f4f8b | Stefano Stabellini | if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
|
102 | 679f4f8b | Stefano Stabellini | PCI_CLASS_STORAGE_IDE) { |
103 | 679f4f8b | Stefano Stabellini | qdev_unplug(&(d->qdev)); |
104 | 679f4f8b | Stefano Stabellini | } |
105 | 679f4f8b | Stefano Stabellini | } |
106 | 679f4f8b | Stefano Stabellini | |
107 | 679f4f8b | Stefano Stabellini | static void pci_unplug_disks(PCIBus *bus) |
108 | 679f4f8b | Stefano Stabellini | { |
109 | 679f4f8b | Stefano Stabellini | pci_for_each_device(bus, 0, unplug_disks);
|
110 | 679f4f8b | Stefano Stabellini | } |
111 | 01195b73 | Steven Smith | |
112 | 01195b73 | Steven Smith | static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val) |
113 | 01195b73 | Steven Smith | { |
114 | 01195b73 | Steven Smith | PCIXenPlatformState *s = opaque; |
115 | 01195b73 | Steven Smith | |
116 | 01195b73 | Steven Smith | switch (addr - XEN_PLATFORM_IOPORT) {
|
117 | 01195b73 | Steven Smith | case 0: |
118 | 01195b73 | Steven Smith | /* Unplug devices. Value is a bitmask of which devices to
|
119 | 01195b73 | Steven Smith | unplug, with bit 0 the IDE devices, bit 1 the network
|
120 | 01195b73 | Steven Smith | devices, and bit 2 the non-primary-master IDE devices. */
|
121 | 679f4f8b | Stefano Stabellini | if (val & UNPLUG_ALL_IDE_DISKS) {
|
122 | 679f4f8b | Stefano Stabellini | DPRINTF("unplug disks\n");
|
123 | 679f4f8b | Stefano Stabellini | qemu_aio_flush(); |
124 | 679f4f8b | Stefano Stabellini | bdrv_flush_all(); |
125 | 679f4f8b | Stefano Stabellini | pci_unplug_disks(s->pci_dev.bus); |
126 | 679f4f8b | Stefano Stabellini | } |
127 | 679f4f8b | Stefano Stabellini | if (val & UNPLUG_ALL_NICS) {
|
128 | 679f4f8b | Stefano Stabellini | DPRINTF("unplug nics\n");
|
129 | 679f4f8b | Stefano Stabellini | pci_unplug_nics(s->pci_dev.bus); |
130 | 679f4f8b | Stefano Stabellini | } |
131 | 679f4f8b | Stefano Stabellini | if (val & UNPLUG_AUX_IDE_DISKS) {
|
132 | 679f4f8b | Stefano Stabellini | DPRINTF("unplug auxiliary disks not supported\n");
|
133 | 679f4f8b | Stefano Stabellini | } |
134 | 01195b73 | Steven Smith | break;
|
135 | 01195b73 | Steven Smith | case 2: |
136 | 01195b73 | Steven Smith | switch (val) {
|
137 | 01195b73 | Steven Smith | case 1: |
138 | 01195b73 | Steven Smith | DPRINTF("Citrix Windows PV drivers loaded in guest\n");
|
139 | 01195b73 | Steven Smith | break;
|
140 | 01195b73 | Steven Smith | case 0: |
141 | 01195b73 | Steven Smith | DPRINTF("Guest claimed to be running PV product 0?\n");
|
142 | 01195b73 | Steven Smith | break;
|
143 | 01195b73 | Steven Smith | default:
|
144 | 01195b73 | Steven Smith | DPRINTF("Unknown PV product %d loaded in guest\n", val);
|
145 | 01195b73 | Steven Smith | break;
|
146 | 01195b73 | Steven Smith | } |
147 | 01195b73 | Steven Smith | s->driver_product_version = val; |
148 | 01195b73 | Steven Smith | break;
|
149 | 01195b73 | Steven Smith | } |
150 | 01195b73 | Steven Smith | } |
151 | 01195b73 | Steven Smith | |
152 | 01195b73 | Steven Smith | static void platform_fixed_ioport_writel(void *opaque, uint32_t addr, |
153 | 01195b73 | Steven Smith | uint32_t val) |
154 | 01195b73 | Steven Smith | { |
155 | 01195b73 | Steven Smith | switch (addr - XEN_PLATFORM_IOPORT) {
|
156 | 01195b73 | Steven Smith | case 0: |
157 | 01195b73 | Steven Smith | /* PV driver version */
|
158 | 01195b73 | Steven Smith | break;
|
159 | 01195b73 | Steven Smith | } |
160 | 01195b73 | Steven Smith | } |
161 | 01195b73 | Steven Smith | |
162 | 01195b73 | Steven Smith | static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) |
163 | 01195b73 | Steven Smith | { |
164 | 01195b73 | Steven Smith | PCIXenPlatformState *s = opaque; |
165 | 01195b73 | Steven Smith | |
166 | 01195b73 | Steven Smith | switch (addr - XEN_PLATFORM_IOPORT) {
|
167 | 01195b73 | Steven Smith | case 0: /* Platform flags */ { |
168 | 01195b73 | Steven Smith | hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ? |
169 | 01195b73 | Steven Smith | HVMMEM_ram_ro : HVMMEM_ram_rw; |
170 | 01195b73 | Steven Smith | if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type, 0xc0, 0x40)) { |
171 | 01195b73 | Steven Smith | DPRINTF("unable to change ro/rw state of ROM memory area!\n");
|
172 | 01195b73 | Steven Smith | } else {
|
173 | 01195b73 | Steven Smith | s->flags = val & PFFLAG_ROM_LOCK; |
174 | 01195b73 | Steven Smith | DPRINTF("changed ro/rw state of ROM memory area. now is %s state.\n",
|
175 | 01195b73 | Steven Smith | (mem_type == HVMMEM_ram_ro ? "ro":"rw")); |
176 | 01195b73 | Steven Smith | } |
177 | 01195b73 | Steven Smith | break;
|
178 | 01195b73 | Steven Smith | } |
179 | 01195b73 | Steven Smith | case 2: |
180 | 01195b73 | Steven Smith | log_writeb(s, val); |
181 | 01195b73 | Steven Smith | break;
|
182 | 01195b73 | Steven Smith | } |
183 | 01195b73 | Steven Smith | } |
184 | 01195b73 | Steven Smith | |
185 | 01195b73 | Steven Smith | static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr) |
186 | 01195b73 | Steven Smith | { |
187 | 01195b73 | Steven Smith | PCIXenPlatformState *s = opaque; |
188 | 01195b73 | Steven Smith | |
189 | 01195b73 | Steven Smith | switch (addr - XEN_PLATFORM_IOPORT) {
|
190 | 01195b73 | Steven Smith | case 0: |
191 | 01195b73 | Steven Smith | if (s->drivers_blacklisted) {
|
192 | 01195b73 | Steven Smith | /* The drivers will recognise this magic number and refuse
|
193 | 01195b73 | Steven Smith | * to do anything. */
|
194 | 01195b73 | Steven Smith | return 0xd249; |
195 | 01195b73 | Steven Smith | } else {
|
196 | 01195b73 | Steven Smith | /* Magic value so that you can identify the interface. */
|
197 | 01195b73 | Steven Smith | return 0x49d2; |
198 | 01195b73 | Steven Smith | } |
199 | 01195b73 | Steven Smith | default:
|
200 | 01195b73 | Steven Smith | return 0xffff; |
201 | 01195b73 | Steven Smith | } |
202 | 01195b73 | Steven Smith | } |
203 | 01195b73 | Steven Smith | |
204 | 01195b73 | Steven Smith | static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr) |
205 | 01195b73 | Steven Smith | { |
206 | 01195b73 | Steven Smith | PCIXenPlatformState *s = opaque; |
207 | 01195b73 | Steven Smith | |
208 | 01195b73 | Steven Smith | switch (addr - XEN_PLATFORM_IOPORT) {
|
209 | 01195b73 | Steven Smith | case 0: |
210 | 01195b73 | Steven Smith | /* Platform flags */
|
211 | 01195b73 | Steven Smith | return s->flags;
|
212 | 01195b73 | Steven Smith | case 2: |
213 | 01195b73 | Steven Smith | /* Version number */
|
214 | 01195b73 | Steven Smith | return 1; |
215 | 01195b73 | Steven Smith | default:
|
216 | 01195b73 | Steven Smith | return 0xff; |
217 | 01195b73 | Steven Smith | } |
218 | 01195b73 | Steven Smith | } |
219 | 01195b73 | Steven Smith | |
220 | 01195b73 | Steven Smith | static void platform_fixed_ioport_reset(void *opaque) |
221 | 01195b73 | Steven Smith | { |
222 | 01195b73 | Steven Smith | PCIXenPlatformState *s = opaque; |
223 | 01195b73 | Steven Smith | |
224 | 01195b73 | Steven Smith | platform_fixed_ioport_writeb(s, XEN_PLATFORM_IOPORT, 0);
|
225 | 01195b73 | Steven Smith | } |
226 | 01195b73 | Steven Smith | |
227 | de00982e | Avi Kivity | const MemoryRegionPortio xen_platform_ioport[] = {
|
228 | de00982e | Avi Kivity | { 0, 16, 4, .write = platform_fixed_ioport_writel, }, |
229 | de00982e | Avi Kivity | { 0, 16, 2, .write = platform_fixed_ioport_writew, }, |
230 | de00982e | Avi Kivity | { 0, 16, 1, .write = platform_fixed_ioport_writeb, }, |
231 | de00982e | Avi Kivity | { 0, 16, 2, .read = platform_fixed_ioport_readw, }, |
232 | de00982e | Avi Kivity | { 0, 16, 1, .read = platform_fixed_ioport_readb, }, |
233 | de00982e | Avi Kivity | PORTIO_END_OF_LIST() |
234 | de00982e | Avi Kivity | }; |
235 | de00982e | Avi Kivity | |
236 | de00982e | Avi Kivity | static const MemoryRegionOps platform_fixed_io_ops = { |
237 | de00982e | Avi Kivity | .old_portio = xen_platform_ioport, |
238 | de00982e | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
239 | de00982e | Avi Kivity | }; |
240 | de00982e | Avi Kivity | |
241 | 01195b73 | Steven Smith | static void platform_fixed_ioport_init(PCIXenPlatformState* s) |
242 | 01195b73 | Steven Smith | { |
243 | de00982e | Avi Kivity | memory_region_init_io(&s->fixed_io, &platform_fixed_io_ops, s, |
244 | de00982e | Avi Kivity | "xen-fixed", 16); |
245 | de00982e | Avi Kivity | memory_region_add_subregion(get_system_io(), XEN_PLATFORM_IOPORT, |
246 | de00982e | Avi Kivity | &s->fixed_io); |
247 | 01195b73 | Steven Smith | } |
248 | 01195b73 | Steven Smith | |
249 | 01195b73 | Steven Smith | /* Xen Platform PCI Device */
|
250 | 01195b73 | Steven Smith | |
251 | 01195b73 | Steven Smith | static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr) |
252 | 01195b73 | Steven Smith | { |
253 | 01195b73 | Steven Smith | if (addr == 0) { |
254 | 01195b73 | Steven Smith | return platform_fixed_ioport_readb(opaque, XEN_PLATFORM_IOPORT);
|
255 | 01195b73 | Steven Smith | } else {
|
256 | 01195b73 | Steven Smith | return ~0u; |
257 | 01195b73 | Steven Smith | } |
258 | 01195b73 | Steven Smith | } |
259 | 01195b73 | Steven Smith | |
260 | 01195b73 | Steven Smith | static void xen_platform_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) |
261 | 01195b73 | Steven Smith | { |
262 | 01195b73 | Steven Smith | PCIXenPlatformState *s = opaque; |
263 | 01195b73 | Steven Smith | |
264 | 01195b73 | Steven Smith | switch (addr) {
|
265 | 01195b73 | Steven Smith | case 0: /* Platform flags */ |
266 | 01195b73 | Steven Smith | platform_fixed_ioport_writeb(opaque, XEN_PLATFORM_IOPORT, val); |
267 | 01195b73 | Steven Smith | break;
|
268 | 01195b73 | Steven Smith | case 8: |
269 | 01195b73 | Steven Smith | log_writeb(s, val); |
270 | 01195b73 | Steven Smith | break;
|
271 | 01195b73 | Steven Smith | default:
|
272 | 01195b73 | Steven Smith | break;
|
273 | 01195b73 | Steven Smith | } |
274 | 01195b73 | Steven Smith | } |
275 | 01195b73 | Steven Smith | |
276 | de00982e | Avi Kivity | static MemoryRegionPortio xen_pci_portio[] = {
|
277 | de00982e | Avi Kivity | { 0, 0x100, 1, .read = xen_platform_ioport_readb, }, |
278 | de00982e | Avi Kivity | { 0, 0x100, 1, .write = xen_platform_ioport_writeb, }, |
279 | de00982e | Avi Kivity | PORTIO_END_OF_LIST() |
280 | de00982e | Avi Kivity | }; |
281 | de00982e | Avi Kivity | |
282 | de00982e | Avi Kivity | static const MemoryRegionOps xen_pci_io_ops = { |
283 | de00982e | Avi Kivity | .old_portio = xen_pci_portio, |
284 | de00982e | Avi Kivity | }; |
285 | 01195b73 | Steven Smith | |
286 | de00982e | Avi Kivity | static void platform_ioport_bar_setup(PCIXenPlatformState *d) |
287 | de00982e | Avi Kivity | { |
288 | de00982e | Avi Kivity | memory_region_init_io(&d->bar, &xen_pci_io_ops, d, "xen-pci", 0x100); |
289 | 01195b73 | Steven Smith | } |
290 | 01195b73 | Steven Smith | |
291 | de00982e | Avi Kivity | static uint64_t platform_mmio_read(void *opaque, target_phys_addr_t addr, |
292 | de00982e | Avi Kivity | unsigned size)
|
293 | 01195b73 | Steven Smith | { |
294 | 01195b73 | Steven Smith | DPRINTF("Warning: attempted read from physical address "
|
295 | 01195b73 | Steven Smith | "0x" TARGET_FMT_plx " in xen platform mmio space\n", addr); |
296 | 01195b73 | Steven Smith | |
297 | 01195b73 | Steven Smith | return 0; |
298 | 01195b73 | Steven Smith | } |
299 | 01195b73 | Steven Smith | |
300 | de00982e | Avi Kivity | static void platform_mmio_write(void *opaque, target_phys_addr_t addr, |
301 | de00982e | Avi Kivity | uint64_t val, unsigned size)
|
302 | 01195b73 | Steven Smith | { |
303 | de00982e | Avi Kivity | DPRINTF("Warning: attempted write of 0x%"PRIx64" to physical " |
304 | 01195b73 | Steven Smith | "address 0x" TARGET_FMT_plx " in xen platform mmio space\n", |
305 | 01195b73 | Steven Smith | val, addr); |
306 | 01195b73 | Steven Smith | } |
307 | 01195b73 | Steven Smith | |
308 | de00982e | Avi Kivity | static const MemoryRegionOps platform_mmio_handler = { |
309 | 01195b73 | Steven Smith | .read = &platform_mmio_read, |
310 | 01195b73 | Steven Smith | .write = &platform_mmio_write, |
311 | de00982e | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
312 | 01195b73 | Steven Smith | }; |
313 | 01195b73 | Steven Smith | |
314 | de00982e | Avi Kivity | static void platform_mmio_setup(PCIXenPlatformState *d) |
315 | 01195b73 | Steven Smith | { |
316 | de00982e | Avi Kivity | memory_region_init_io(&d->mmio_bar, &platform_mmio_handler, d, |
317 | de00982e | Avi Kivity | "xen-mmio", 0x1000000); |
318 | 01195b73 | Steven Smith | } |
319 | 01195b73 | Steven Smith | |
320 | 01195b73 | Steven Smith | static int xen_platform_post_load(void *opaque, int version_id) |
321 | 01195b73 | Steven Smith | { |
322 | 01195b73 | Steven Smith | PCIXenPlatformState *s = opaque; |
323 | 01195b73 | Steven Smith | |
324 | 01195b73 | Steven Smith | platform_fixed_ioport_writeb(s, XEN_PLATFORM_IOPORT, s->flags); |
325 | 01195b73 | Steven Smith | |
326 | 01195b73 | Steven Smith | return 0; |
327 | 01195b73 | Steven Smith | } |
328 | 01195b73 | Steven Smith | |
329 | 01195b73 | Steven Smith | static const VMStateDescription vmstate_xen_platform = { |
330 | 01195b73 | Steven Smith | .name = "platform",
|
331 | 01195b73 | Steven Smith | .version_id = 4,
|
332 | 01195b73 | Steven Smith | .minimum_version_id = 4,
|
333 | 01195b73 | Steven Smith | .minimum_version_id_old = 4,
|
334 | 01195b73 | Steven Smith | .post_load = xen_platform_post_load, |
335 | 01195b73 | Steven Smith | .fields = (VMStateField []) { |
336 | 01195b73 | Steven Smith | VMSTATE_PCI_DEVICE(pci_dev, PCIXenPlatformState), |
337 | 01195b73 | Steven Smith | VMSTATE_UINT8(flags, PCIXenPlatformState), |
338 | 01195b73 | Steven Smith | VMSTATE_END_OF_LIST() |
339 | 01195b73 | Steven Smith | } |
340 | 01195b73 | Steven Smith | }; |
341 | 01195b73 | Steven Smith | |
342 | 01195b73 | Steven Smith | static int xen_platform_initfn(PCIDevice *dev) |
343 | 01195b73 | Steven Smith | { |
344 | 01195b73 | Steven Smith | PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, dev); |
345 | 01195b73 | Steven Smith | uint8_t *pci_conf; |
346 | 01195b73 | Steven Smith | |
347 | 01195b73 | Steven Smith | pci_conf = d->pci_dev.config; |
348 | 01195b73 | Steven Smith | |
349 | 01195b73 | Steven Smith | pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
350 | 01195b73 | Steven Smith | |
351 | 01195b73 | Steven Smith | pci_config_set_prog_interface(pci_conf, 0);
|
352 | 01195b73 | Steven Smith | |
353 | 01195b73 | Steven Smith | pci_conf[PCI_INTERRUPT_PIN] = 1;
|
354 | 01195b73 | Steven Smith | |
355 | de00982e | Avi Kivity | platform_ioport_bar_setup(d); |
356 | e824b2cc | Avi Kivity | pci_register_bar(&d->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->bar);
|
357 | 01195b73 | Steven Smith | |
358 | 01195b73 | Steven Smith | /* reserve 16MB mmio address for share memory*/
|
359 | de00982e | Avi Kivity | platform_mmio_setup(d); |
360 | e824b2cc | Avi Kivity | pci_register_bar(&d->pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
|
361 | e824b2cc | Avi Kivity | &d->mmio_bar); |
362 | 01195b73 | Steven Smith | |
363 | 01195b73 | Steven Smith | platform_fixed_ioport_init(d); |
364 | 01195b73 | Steven Smith | |
365 | 01195b73 | Steven Smith | return 0; |
366 | 01195b73 | Steven Smith | } |
367 | 01195b73 | Steven Smith | |
368 | 01195b73 | Steven Smith | static void platform_reset(DeviceState *dev) |
369 | 01195b73 | Steven Smith | { |
370 | 01195b73 | Steven Smith | PCIXenPlatformState *s = DO_UPCAST(PCIXenPlatformState, pci_dev.qdev, dev); |
371 | 01195b73 | Steven Smith | |
372 | 01195b73 | Steven Smith | platform_fixed_ioport_reset(s); |
373 | 01195b73 | Steven Smith | } |
374 | 01195b73 | Steven Smith | |
375 | 01195b73 | Steven Smith | static PCIDeviceInfo xen_platform_info = {
|
376 | 01195b73 | Steven Smith | .init = xen_platform_initfn, |
377 | 01195b73 | Steven Smith | .qdev.name = "xen-platform",
|
378 | 01195b73 | Steven Smith | .qdev.desc = "XEN platform pci device",
|
379 | 01195b73 | Steven Smith | .qdev.size = sizeof(PCIXenPlatformState),
|
380 | 01195b73 | Steven Smith | .qdev.vmsd = &vmstate_xen_platform, |
381 | 01195b73 | Steven Smith | .qdev.reset = platform_reset, |
382 | 0d2b962d | Michael S. Tsirkin | |
383 | 0d2b962d | Michael S. Tsirkin | .vendor_id = PCI_VENDOR_ID_XEN, |
384 | 0d2b962d | Michael S. Tsirkin | .device_id = PCI_DEVICE_ID_XEN_PLATFORM, |
385 | 0d2b962d | Michael S. Tsirkin | .class_id = PCI_CLASS_OTHERS << 8 | 0x80, |
386 | 0d2b962d | Michael S. Tsirkin | .subsystem_vendor_id = PCI_VENDOR_ID_XEN, |
387 | 0d2b962d | Michael S. Tsirkin | .subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM, |
388 | 0d2b962d | Michael S. Tsirkin | .revision = 1,
|
389 | 01195b73 | Steven Smith | }; |
390 | 01195b73 | Steven Smith | |
391 | 01195b73 | Steven Smith | static void xen_platform_register(void) |
392 | 01195b73 | Steven Smith | { |
393 | 01195b73 | Steven Smith | pci_qdev_register(&xen_platform_info); |
394 | 01195b73 | Steven Smith | } |
395 | 01195b73 | Steven Smith | |
396 | 01195b73 | Steven Smith | device_init(xen_platform_register); |