]> Git Repo - qemu.git/blame - hw/i386/xen/xen_pvdevice.c
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-4.2-pull-request...
[qemu.git] / hw / i386 / xen / xen_pvdevice.c
CommitLineData
8fbab3b6
PD
1/* Copyright (c) Citrix Systems Inc.
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms,
5 * with or without modification, are permitted provided
6 * that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the
10 * following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the
13 * following disclaimer in the documentation and/or other
14 * materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
17 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
b6a0aa05 32#include "qemu/osdep.h"
da34e65c 33#include "qapi/error.h"
0b8fa32f 34#include "qemu/module.h"
8fbab3b6 35#include "hw/pci/pci.h"
a27bd6c7 36#include "hw/qdev-properties.h"
d6454270 37#include "migration/vmstate.h"
8fbab3b6
PD
38#include "trace.h"
39
40#define TYPE_XEN_PV_DEVICE "xen-pvdevice"
41
42#define XEN_PV_DEVICE(obj) \
43 OBJECT_CHECK(XenPVDevice, (obj), TYPE_XEN_PV_DEVICE)
44
45typedef struct XenPVDevice {
46 /*< private >*/
47 PCIDevice parent_obj;
48 /*< public >*/
49 uint16_t vendor_id;
50 uint16_t device_id;
51 uint8_t revision;
52 uint32_t size;
53 MemoryRegion mmio;
54} XenPVDevice;
55
56static uint64_t xen_pv_mmio_read(void *opaque, hwaddr addr,
57 unsigned size)
58{
59 trace_xen_pv_mmio_read(addr);
60
61 return ~(uint64_t)0;
62}
63
64static void xen_pv_mmio_write(void *opaque, hwaddr addr,
65 uint64_t val, unsigned size)
66{
67 trace_xen_pv_mmio_write(addr);
68}
69
70static const MemoryRegionOps xen_pv_mmio_ops = {
71 .read = &xen_pv_mmio_read,
72 .write = &xen_pv_mmio_write,
73 .endianness = DEVICE_LITTLE_ENDIAN,
74};
75
1dd6af73
ID
76static const VMStateDescription vmstate_xen_pvdevice = {
77 .name = "xen-pvdevice",
78 .version_id = 1,
79 .minimum_version_id = 1,
80 .fields = (VMStateField[]) {
81 VMSTATE_PCI_DEVICE(parent_obj, XenPVDevice),
82 VMSTATE_END_OF_LIST()
83 }
84};
85
c6b14aed 86static void xen_pv_realize(PCIDevice *pci_dev, Error **errp)
8fbab3b6
PD
87{
88 XenPVDevice *d = XEN_PV_DEVICE(pci_dev);
89 uint8_t *pci_conf;
90
539891a8 91 /* device-id property must always be supplied */
c6b14aed
C
92 if (d->device_id == 0xffff) {
93 error_setg(errp, "Device ID invalid, it must always be supplied");
94 return;
95 }
539891a8 96
8fbab3b6
PD
97 pci_conf = pci_dev->config;
98
99 pci_set_word(pci_conf + PCI_VENDOR_ID, d->vendor_id);
100 pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, d->vendor_id);
101 pci_set_word(pci_conf + PCI_DEVICE_ID, d->device_id);
102 pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, d->device_id);
103 pci_set_byte(pci_conf + PCI_REVISION_ID, d->revision);
104
105 pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_MEMORY);
106
107 pci_config_set_prog_interface(pci_conf, 0);
108
109 pci_conf[PCI_INTERRUPT_PIN] = 1;
110
111 memory_region_init_io(&d->mmio, NULL, &xen_pv_mmio_ops, d,
112 "mmio", d->size);
113
114 pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
115 &d->mmio);
8fbab3b6
PD
116}
117
118static Property xen_pv_props[] = {
119 DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_ID_XEN),
539891a8 120 DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, 0xffff),
8fbab3b6
PD
121 DEFINE_PROP_UINT8("revision", XenPVDevice, revision, 0x01),
122 DEFINE_PROP_UINT32("size", XenPVDevice, size, 0x400000),
123 DEFINE_PROP_END_OF_LIST()
124};
125
126static void xen_pv_class_init(ObjectClass *klass, void *data)
127{
128 DeviceClass *dc = DEVICE_CLASS(klass);
129 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
130
c6b14aed 131 k->realize = xen_pv_realize;
8fbab3b6
PD
132 k->class_id = PCI_CLASS_SYSTEM_OTHER;
133 dc->desc = "Xen PV Device";
134 dc->props = xen_pv_props;
1dd6af73 135 dc->vmsd = &vmstate_xen_pvdevice;
8fbab3b6
PD
136}
137
138static const TypeInfo xen_pv_type_info = {
139 .name = TYPE_XEN_PV_DEVICE,
140 .parent = TYPE_PCI_DEVICE,
141 .instance_size = sizeof(XenPVDevice),
142 .class_init = xen_pv_class_init,
fd3b02c8
EH
143 .interfaces = (InterfaceInfo[]) {
144 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
145 { },
146 },
8fbab3b6
PD
147};
148
149static void xen_pv_register_types(void)
150{
151 type_register_static(&xen_pv_type_info);
152}
153
154type_init(xen_pv_register_types)
This page took 0.265023 seconds and 4 git commands to generate.