Statistics
| Branch: | Revision:

root / hw / xen_platform.c @ bc927e48

History | View | Annotate | Download (11.8 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 7aa8cbb9 Anthony PERARD
static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
87 679f4f8b Stefano Stabellini
{
88 bd4982a6 Anthony PERARD
    /* We have to ignore passthrough devices */
89 679f4f8b Stefano Stabellini
    if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
90 bd4982a6 Anthony PERARD
            PCI_CLASS_NETWORK_ETHERNET
91 bd4982a6 Anthony PERARD
            && strcmp(d->name, "xen-pci-passthrough") != 0) {
92 4accd107 Anthony PERARD
        qdev_free(&d->qdev);
93 679f4f8b Stefano Stabellini
    }
94 679f4f8b Stefano Stabellini
}
95 679f4f8b Stefano Stabellini
96 679f4f8b Stefano Stabellini
static void pci_unplug_nics(PCIBus *bus)
97 679f4f8b Stefano Stabellini
{
98 7aa8cbb9 Anthony PERARD
    pci_for_each_device(bus, 0, unplug_nic, NULL);
99 679f4f8b Stefano Stabellini
}
100 679f4f8b Stefano Stabellini
101 7aa8cbb9 Anthony PERARD
static void unplug_disks(PCIBus *b, PCIDevice *d, void *o)
102 679f4f8b Stefano Stabellini
{
103 bd4982a6 Anthony PERARD
    /* We have to ignore passthrough devices */
104 679f4f8b Stefano Stabellini
    if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
105 bd4982a6 Anthony PERARD
            PCI_CLASS_STORAGE_IDE
106 bd4982a6 Anthony PERARD
            && strcmp(d->name, "xen-pci-passthrough") != 0) {
107 56f9107e Luiz Capitulino
        qdev_unplug(&(d->qdev), NULL);
108 679f4f8b Stefano Stabellini
    }
109 679f4f8b Stefano Stabellini
}
110 679f4f8b Stefano Stabellini
111 679f4f8b Stefano Stabellini
static void pci_unplug_disks(PCIBus *bus)
112 679f4f8b Stefano Stabellini
{
113 7aa8cbb9 Anthony PERARD
    pci_for_each_device(bus, 0, unplug_disks, NULL);
114 679f4f8b Stefano Stabellini
}
115 01195b73 Steven Smith
116 01195b73 Steven Smith
static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
117 01195b73 Steven Smith
{
118 01195b73 Steven Smith
    PCIXenPlatformState *s = opaque;
119 01195b73 Steven Smith
120 e7b48c97 Anthony PERARD
    switch (addr) {
121 01195b73 Steven Smith
    case 0:
122 01195b73 Steven Smith
        /* Unplug devices.  Value is a bitmask of which devices to
123 01195b73 Steven Smith
           unplug, with bit 0 the IDE devices, bit 1 the network
124 01195b73 Steven Smith
           devices, and bit 2 the non-primary-master IDE devices. */
125 679f4f8b Stefano Stabellini
        if (val & UNPLUG_ALL_IDE_DISKS) {
126 679f4f8b Stefano Stabellini
            DPRINTF("unplug disks\n");
127 922453bc Stefan Hajnoczi
            bdrv_drain_all();
128 679f4f8b Stefano Stabellini
            bdrv_flush_all();
129 679f4f8b Stefano Stabellini
            pci_unplug_disks(s->pci_dev.bus);
130 679f4f8b Stefano Stabellini
        }
131 679f4f8b Stefano Stabellini
        if (val & UNPLUG_ALL_NICS) {
132 679f4f8b Stefano Stabellini
            DPRINTF("unplug nics\n");
133 679f4f8b Stefano Stabellini
            pci_unplug_nics(s->pci_dev.bus);
134 679f4f8b Stefano Stabellini
        }
135 679f4f8b Stefano Stabellini
        if (val & UNPLUG_AUX_IDE_DISKS) {
136 679f4f8b Stefano Stabellini
            DPRINTF("unplug auxiliary disks not supported\n");
137 679f4f8b Stefano Stabellini
        }
138 01195b73 Steven Smith
        break;
139 01195b73 Steven Smith
    case 2:
140 01195b73 Steven Smith
        switch (val) {
141 01195b73 Steven Smith
        case 1:
142 01195b73 Steven Smith
            DPRINTF("Citrix Windows PV drivers loaded in guest\n");
143 01195b73 Steven Smith
            break;
144 01195b73 Steven Smith
        case 0:
145 01195b73 Steven Smith
            DPRINTF("Guest claimed to be running PV product 0?\n");
146 01195b73 Steven Smith
            break;
147 01195b73 Steven Smith
        default:
148 01195b73 Steven Smith
            DPRINTF("Unknown PV product %d loaded in guest\n", val);
149 01195b73 Steven Smith
            break;
150 01195b73 Steven Smith
        }
151 01195b73 Steven Smith
        s->driver_product_version = val;
152 01195b73 Steven Smith
        break;
153 01195b73 Steven Smith
    }
154 01195b73 Steven Smith
}
155 01195b73 Steven Smith
156 01195b73 Steven Smith
static void platform_fixed_ioport_writel(void *opaque, uint32_t addr,
157 01195b73 Steven Smith
                                         uint32_t val)
158 01195b73 Steven Smith
{
159 e7b48c97 Anthony PERARD
    switch (addr) {
160 01195b73 Steven Smith
    case 0:
161 01195b73 Steven Smith
        /* PV driver version */
162 01195b73 Steven Smith
        break;
163 01195b73 Steven Smith
    }
164 01195b73 Steven Smith
}
165 01195b73 Steven Smith
166 01195b73 Steven Smith
static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
167 01195b73 Steven Smith
{
168 01195b73 Steven Smith
    PCIXenPlatformState *s = opaque;
169 01195b73 Steven Smith
170 e7b48c97 Anthony PERARD
    switch (addr) {
171 01195b73 Steven Smith
    case 0: /* Platform flags */ {
172 01195b73 Steven Smith
        hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ?
173 01195b73 Steven Smith
            HVMMEM_ram_ro : HVMMEM_ram_rw;
174 01195b73 Steven Smith
        if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type, 0xc0, 0x40)) {
175 01195b73 Steven Smith
            DPRINTF("unable to change ro/rw state of ROM memory area!\n");
176 01195b73 Steven Smith
        } else {
177 01195b73 Steven Smith
            s->flags = val & PFFLAG_ROM_LOCK;
178 01195b73 Steven Smith
            DPRINTF("changed ro/rw state of ROM memory area. now is %s state.\n",
179 01195b73 Steven Smith
                    (mem_type == HVMMEM_ram_ro ? "ro":"rw"));
180 01195b73 Steven Smith
        }
181 01195b73 Steven Smith
        break;
182 01195b73 Steven Smith
    }
183 01195b73 Steven Smith
    case 2:
184 01195b73 Steven Smith
        log_writeb(s, val);
185 01195b73 Steven Smith
        break;
186 01195b73 Steven Smith
    }
187 01195b73 Steven Smith
}
188 01195b73 Steven Smith
189 01195b73 Steven Smith
static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
190 01195b73 Steven Smith
{
191 01195b73 Steven Smith
    PCIXenPlatformState *s = opaque;
192 01195b73 Steven Smith
193 e7b48c97 Anthony PERARD
    switch (addr) {
194 01195b73 Steven Smith
    case 0:
195 01195b73 Steven Smith
        if (s->drivers_blacklisted) {
196 01195b73 Steven Smith
            /* The drivers will recognise this magic number and refuse
197 01195b73 Steven Smith
             * to do anything. */
198 01195b73 Steven Smith
            return 0xd249;
199 01195b73 Steven Smith
        } else {
200 01195b73 Steven Smith
            /* Magic value so that you can identify the interface. */
201 01195b73 Steven Smith
            return 0x49d2;
202 01195b73 Steven Smith
        }
203 01195b73 Steven Smith
    default:
204 01195b73 Steven Smith
        return 0xffff;
205 01195b73 Steven Smith
    }
206 01195b73 Steven Smith
}
207 01195b73 Steven Smith
208 01195b73 Steven Smith
static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
209 01195b73 Steven Smith
{
210 01195b73 Steven Smith
    PCIXenPlatformState *s = opaque;
211 01195b73 Steven Smith
212 e7b48c97 Anthony PERARD
    switch (addr) {
213 01195b73 Steven Smith
    case 0:
214 01195b73 Steven Smith
        /* Platform flags */
215 01195b73 Steven Smith
        return s->flags;
216 01195b73 Steven Smith
    case 2:
217 01195b73 Steven Smith
        /* Version number */
218 01195b73 Steven Smith
        return 1;
219 01195b73 Steven Smith
    default:
220 01195b73 Steven Smith
        return 0xff;
221 01195b73 Steven Smith
    }
222 01195b73 Steven Smith
}
223 01195b73 Steven Smith
224 01195b73 Steven Smith
static void platform_fixed_ioport_reset(void *opaque)
225 01195b73 Steven Smith
{
226 01195b73 Steven Smith
    PCIXenPlatformState *s = opaque;
227 01195b73 Steven Smith
228 e7b48c97 Anthony PERARD
    platform_fixed_ioport_writeb(s, 0, 0);
229 01195b73 Steven Smith
}
230 01195b73 Steven Smith
231 626c7a17 Alexander Graf
static uint64_t platform_fixed_ioport_read(void *opaque,
232 626c7a17 Alexander Graf
                                           hwaddr addr,
233 626c7a17 Alexander Graf
                                           unsigned size)
234 626c7a17 Alexander Graf
{
235 626c7a17 Alexander Graf
    switch (size) {
236 626c7a17 Alexander Graf
    case 1:
237 626c7a17 Alexander Graf
        return platform_fixed_ioport_readb(opaque, addr);
238 626c7a17 Alexander Graf
    case 2:
239 626c7a17 Alexander Graf
        return platform_fixed_ioport_readw(opaque, addr);
240 626c7a17 Alexander Graf
    default:
241 626c7a17 Alexander Graf
        return -1;
242 626c7a17 Alexander Graf
    }
243 626c7a17 Alexander Graf
}
244 626c7a17 Alexander Graf
245 626c7a17 Alexander Graf
static void platform_fixed_ioport_write(void *opaque, hwaddr addr,
246 626c7a17 Alexander Graf
247 626c7a17 Alexander Graf
                                        uint64_t val, unsigned size)
248 626c7a17 Alexander Graf
{
249 626c7a17 Alexander Graf
    switch (size) {
250 626c7a17 Alexander Graf
    case 1:
251 626c7a17 Alexander Graf
        platform_fixed_ioport_writeb(opaque, addr, val);
252 626c7a17 Alexander Graf
        break;
253 626c7a17 Alexander Graf
    case 2:
254 626c7a17 Alexander Graf
        platform_fixed_ioport_writew(opaque, addr, val);
255 626c7a17 Alexander Graf
        break;
256 626c7a17 Alexander Graf
    case 4:
257 626c7a17 Alexander Graf
        platform_fixed_ioport_writel(opaque, addr, val);
258 626c7a17 Alexander Graf
        break;
259 626c7a17 Alexander Graf
    }
260 626c7a17 Alexander Graf
}
261 626c7a17 Alexander Graf
262 de00982e Avi Kivity
263 de00982e Avi Kivity
static const MemoryRegionOps platform_fixed_io_ops = {
264 626c7a17 Alexander Graf
    .read = platform_fixed_ioport_read,
265 626c7a17 Alexander Graf
    .write = platform_fixed_ioport_write,
266 626c7a17 Alexander Graf
    .impl = {
267 626c7a17 Alexander Graf
        .min_access_size = 1,
268 626c7a17 Alexander Graf
        .max_access_size = 4,
269 626c7a17 Alexander Graf
    },
270 626c7a17 Alexander Graf
    .endianness = DEVICE_LITTLE_ENDIAN,
271 de00982e Avi Kivity
};
272 de00982e Avi Kivity
273 01195b73 Steven Smith
static void platform_fixed_ioport_init(PCIXenPlatformState* s)
274 01195b73 Steven Smith
{
275 de00982e Avi Kivity
    memory_region_init_io(&s->fixed_io, &platform_fixed_io_ops, s,
276 de00982e Avi Kivity
                          "xen-fixed", 16);
277 de00982e Avi Kivity
    memory_region_add_subregion(get_system_io(), XEN_PLATFORM_IOPORT,
278 de00982e Avi Kivity
                                &s->fixed_io);
279 01195b73 Steven Smith
}
280 01195b73 Steven Smith
281 01195b73 Steven Smith
/* Xen Platform PCI Device */
282 01195b73 Steven Smith
283 01195b73 Steven Smith
static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr)
284 01195b73 Steven Smith
{
285 01195b73 Steven Smith
    if (addr == 0) {
286 e7b48c97 Anthony PERARD
        return platform_fixed_ioport_readb(opaque, 0);
287 01195b73 Steven Smith
    } else {
288 01195b73 Steven Smith
        return ~0u;
289 01195b73 Steven Smith
    }
290 01195b73 Steven Smith
}
291 01195b73 Steven Smith
292 01195b73 Steven Smith
static void xen_platform_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
293 01195b73 Steven Smith
{
294 01195b73 Steven Smith
    PCIXenPlatformState *s = opaque;
295 01195b73 Steven Smith
296 01195b73 Steven Smith
    switch (addr) {
297 01195b73 Steven Smith
    case 0: /* Platform flags */
298 e7b48c97 Anthony PERARD
        platform_fixed_ioport_writeb(opaque, 0, val);
299 01195b73 Steven Smith
        break;
300 01195b73 Steven Smith
    case 8:
301 01195b73 Steven Smith
        log_writeb(s, val);
302 01195b73 Steven Smith
        break;
303 01195b73 Steven Smith
    default:
304 01195b73 Steven Smith
        break;
305 01195b73 Steven Smith
    }
306 01195b73 Steven Smith
}
307 01195b73 Steven Smith
308 de00982e Avi Kivity
static MemoryRegionPortio xen_pci_portio[] = {
309 de00982e Avi Kivity
    { 0, 0x100, 1, .read = xen_platform_ioport_readb, },
310 de00982e Avi Kivity
    { 0, 0x100, 1, .write = xen_platform_ioport_writeb, },
311 de00982e Avi Kivity
    PORTIO_END_OF_LIST()
312 de00982e Avi Kivity
};
313 de00982e Avi Kivity
314 de00982e Avi Kivity
static const MemoryRegionOps xen_pci_io_ops = {
315 de00982e Avi Kivity
    .old_portio = xen_pci_portio,
316 de00982e Avi Kivity
};
317 01195b73 Steven Smith
318 de00982e Avi Kivity
static void platform_ioport_bar_setup(PCIXenPlatformState *d)
319 de00982e Avi Kivity
{
320 de00982e Avi Kivity
    memory_region_init_io(&d->bar, &xen_pci_io_ops, d, "xen-pci", 0x100);
321 01195b73 Steven Smith
}
322 01195b73 Steven Smith
323 a8170e5e Avi Kivity
static uint64_t platform_mmio_read(void *opaque, hwaddr addr,
324 de00982e Avi Kivity
                                   unsigned size)
325 01195b73 Steven Smith
{
326 01195b73 Steven Smith
    DPRINTF("Warning: attempted read from physical address "
327 01195b73 Steven Smith
            "0x" TARGET_FMT_plx " in xen platform mmio space\n", addr);
328 01195b73 Steven Smith
329 01195b73 Steven Smith
    return 0;
330 01195b73 Steven Smith
}
331 01195b73 Steven Smith
332 a8170e5e Avi Kivity
static void platform_mmio_write(void *opaque, hwaddr addr,
333 de00982e Avi Kivity
                                uint64_t val, unsigned size)
334 01195b73 Steven Smith
{
335 de00982e Avi Kivity
    DPRINTF("Warning: attempted write of 0x%"PRIx64" to physical "
336 01195b73 Steven Smith
            "address 0x" TARGET_FMT_plx " in xen platform mmio space\n",
337 01195b73 Steven Smith
            val, addr);
338 01195b73 Steven Smith
}
339 01195b73 Steven Smith
340 de00982e Avi Kivity
static const MemoryRegionOps platform_mmio_handler = {
341 01195b73 Steven Smith
    .read = &platform_mmio_read,
342 01195b73 Steven Smith
    .write = &platform_mmio_write,
343 de00982e Avi Kivity
    .endianness = DEVICE_NATIVE_ENDIAN,
344 01195b73 Steven Smith
};
345 01195b73 Steven Smith
346 de00982e Avi Kivity
static void platform_mmio_setup(PCIXenPlatformState *d)
347 01195b73 Steven Smith
{
348 de00982e Avi Kivity
    memory_region_init_io(&d->mmio_bar, &platform_mmio_handler, d,
349 de00982e Avi Kivity
                          "xen-mmio", 0x1000000);
350 01195b73 Steven Smith
}
351 01195b73 Steven Smith
352 01195b73 Steven Smith
static int xen_platform_post_load(void *opaque, int version_id)
353 01195b73 Steven Smith
{
354 01195b73 Steven Smith
    PCIXenPlatformState *s = opaque;
355 01195b73 Steven Smith
356 e7b48c97 Anthony PERARD
    platform_fixed_ioport_writeb(s, 0, s->flags);
357 01195b73 Steven Smith
358 01195b73 Steven Smith
    return 0;
359 01195b73 Steven Smith
}
360 01195b73 Steven Smith
361 01195b73 Steven Smith
static const VMStateDescription vmstate_xen_platform = {
362 01195b73 Steven Smith
    .name = "platform",
363 01195b73 Steven Smith
    .version_id = 4,
364 01195b73 Steven Smith
    .minimum_version_id = 4,
365 01195b73 Steven Smith
    .minimum_version_id_old = 4,
366 01195b73 Steven Smith
    .post_load = xen_platform_post_load,
367 01195b73 Steven Smith
    .fields = (VMStateField []) {
368 01195b73 Steven Smith
        VMSTATE_PCI_DEVICE(pci_dev, PCIXenPlatformState),
369 01195b73 Steven Smith
        VMSTATE_UINT8(flags, PCIXenPlatformState),
370 01195b73 Steven Smith
        VMSTATE_END_OF_LIST()
371 01195b73 Steven Smith
    }
372 01195b73 Steven Smith
};
373 01195b73 Steven Smith
374 01195b73 Steven Smith
static int xen_platform_initfn(PCIDevice *dev)
375 01195b73 Steven Smith
{
376 01195b73 Steven Smith
    PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, dev);
377 01195b73 Steven Smith
    uint8_t *pci_conf;
378 01195b73 Steven Smith
379 01195b73 Steven Smith
    pci_conf = d->pci_dev.config;
380 01195b73 Steven Smith
381 01195b73 Steven Smith
    pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
382 01195b73 Steven Smith
383 01195b73 Steven Smith
    pci_config_set_prog_interface(pci_conf, 0);
384 01195b73 Steven Smith
385 01195b73 Steven Smith
    pci_conf[PCI_INTERRUPT_PIN] = 1;
386 01195b73 Steven Smith
387 de00982e Avi Kivity
    platform_ioport_bar_setup(d);
388 e824b2cc Avi Kivity
    pci_register_bar(&d->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->bar);
389 01195b73 Steven Smith
390 01195b73 Steven Smith
    /* reserve 16MB mmio address for share memory*/
391 de00982e Avi Kivity
    platform_mmio_setup(d);
392 e824b2cc Avi Kivity
    pci_register_bar(&d->pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
393 e824b2cc Avi Kivity
                     &d->mmio_bar);
394 01195b73 Steven Smith
395 01195b73 Steven Smith
    platform_fixed_ioport_init(d);
396 01195b73 Steven Smith
397 01195b73 Steven Smith
    return 0;
398 01195b73 Steven Smith
}
399 01195b73 Steven Smith
400 01195b73 Steven Smith
static void platform_reset(DeviceState *dev)
401 01195b73 Steven Smith
{
402 01195b73 Steven Smith
    PCIXenPlatformState *s = DO_UPCAST(PCIXenPlatformState, pci_dev.qdev, dev);
403 01195b73 Steven Smith
404 01195b73 Steven Smith
    platform_fixed_ioport_reset(s);
405 01195b73 Steven Smith
}
406 01195b73 Steven Smith
407 40021f08 Anthony Liguori
static void xen_platform_class_init(ObjectClass *klass, void *data)
408 40021f08 Anthony Liguori
{
409 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
410 40021f08 Anthony Liguori
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
411 40021f08 Anthony Liguori
412 40021f08 Anthony Liguori
    k->init = xen_platform_initfn;
413 40021f08 Anthony Liguori
    k->vendor_id = PCI_VENDOR_ID_XEN;
414 40021f08 Anthony Liguori
    k->device_id = PCI_DEVICE_ID_XEN_PLATFORM;
415 40021f08 Anthony Liguori
    k->class_id = PCI_CLASS_OTHERS << 8 | 0x80;
416 40021f08 Anthony Liguori
    k->subsystem_vendor_id = PCI_VENDOR_ID_XEN;
417 40021f08 Anthony Liguori
    k->subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM;
418 40021f08 Anthony Liguori
    k->revision = 1;
419 39bffca2 Anthony Liguori
    dc->desc = "XEN platform pci device";
420 39bffca2 Anthony Liguori
    dc->reset = platform_reset;
421 39bffca2 Anthony Liguori
    dc->vmsd = &vmstate_xen_platform;
422 40021f08 Anthony Liguori
}
423 40021f08 Anthony Liguori
424 39bffca2 Anthony Liguori
static TypeInfo xen_platform_info = {
425 39bffca2 Anthony Liguori
    .name          = "xen-platform",
426 39bffca2 Anthony Liguori
    .parent        = TYPE_PCI_DEVICE,
427 39bffca2 Anthony Liguori
    .instance_size = sizeof(PCIXenPlatformState),
428 39bffca2 Anthony Liguori
    .class_init    = xen_platform_class_init,
429 01195b73 Steven Smith
};
430 01195b73 Steven Smith
431 83f7d43a Andreas Färber
static void xen_platform_register_types(void)
432 01195b73 Steven Smith
{
433 39bffca2 Anthony Liguori
    type_register_static(&xen_platform_info);
434 01195b73 Steven Smith
}
435 01195b73 Steven Smith
436 83f7d43a Andreas Färber
type_init(xen_platform_register_types)