Statistics
| Branch: | Revision:

root / hw / xen_platform.c @ 0d09e41a

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