2013-07-29 14:58:01 +04:00
|
|
|
/* Copyright (c) Citrix Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
* that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
* materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:03 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2013-07-29 14:58:01 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2013-07-29 14:58:01 +04:00
|
|
|
#include "trace.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2013-07-29 14:58:01 +04:00
|
|
|
|
|
|
|
#define TYPE_XEN_PV_DEVICE "xen-pvdevice"
|
|
|
|
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(XenPVDevice, XEN_PV_DEVICE)
|
2013-07-29 14:58:01 +04:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XenPVDevice {
|
2013-07-29 14:58:01 +04:00
|
|
|
/*< private >*/
|
|
|
|
PCIDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
uint16_t vendor_id;
|
|
|
|
uint16_t device_id;
|
|
|
|
uint8_t revision;
|
|
|
|
uint32_t size;
|
|
|
|
MemoryRegion mmio;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2013-07-29 14:58:01 +04:00
|
|
|
|
|
|
|
static uint64_t xen_pv_mmio_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
trace_xen_pv_mmio_read(addr);
|
|
|
|
|
|
|
|
return ~(uint64_t)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_pv_mmio_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
trace_xen_pv_mmio_write(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps xen_pv_mmio_ops = {
|
|
|
|
.read = &xen_pv_mmio_read,
|
|
|
|
.write = &xen_pv_mmio_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2018-03-14 02:14:54 +03:00
|
|
|
static const VMStateDescription vmstate_xen_pvdevice = {
|
|
|
|
.name = "xen-pvdevice",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_PCI_DEVICE(parent_obj, XenPVDevice),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-22 05:43:16 +03:00
|
|
|
static void xen_pv_realize(PCIDevice *pci_dev, Error **errp)
|
2013-07-29 14:58:01 +04:00
|
|
|
{
|
|
|
|
XenPVDevice *d = XEN_PV_DEVICE(pci_dev);
|
|
|
|
uint8_t *pci_conf;
|
|
|
|
|
2013-11-13 19:25:07 +04:00
|
|
|
/* device-id property must always be supplied */
|
2015-12-22 05:43:16 +03:00
|
|
|
if (d->device_id == 0xffff) {
|
|
|
|
error_setg(errp, "Device ID invalid, it must always be supplied");
|
|
|
|
return;
|
|
|
|
}
|
2013-11-13 19:25:07 +04:00
|
|
|
|
2013-07-29 14:58:01 +04:00
|
|
|
pci_conf = pci_dev->config;
|
|
|
|
|
|
|
|
pci_set_word(pci_conf + PCI_VENDOR_ID, d->vendor_id);
|
|
|
|
pci_set_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID, d->vendor_id);
|
|
|
|
pci_set_word(pci_conf + PCI_DEVICE_ID, d->device_id);
|
|
|
|
pci_set_word(pci_conf + PCI_SUBSYSTEM_ID, d->device_id);
|
|
|
|
pci_set_byte(pci_conf + PCI_REVISION_ID, d->revision);
|
|
|
|
|
|
|
|
pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_MEMORY);
|
|
|
|
|
|
|
|
pci_config_set_prog_interface(pci_conf, 0);
|
|
|
|
|
|
|
|
pci_conf[PCI_INTERRUPT_PIN] = 1;
|
|
|
|
|
|
|
|
memory_region_init_io(&d->mmio, NULL, &xen_pv_mmio_ops, d,
|
|
|
|
"mmio", d->size);
|
|
|
|
|
|
|
|
pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
|
|
|
|
&d->mmio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property xen_pv_props[] = {
|
|
|
|
DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_ID_XEN),
|
2013-11-13 19:25:07 +04:00
|
|
|
DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, 0xffff),
|
2013-07-29 14:58:01 +04:00
|
|
|
DEFINE_PROP_UINT8("revision", XenPVDevice, revision, 0x01),
|
|
|
|
DEFINE_PROP_UINT32("size", XenPVDevice, size, 0x400000),
|
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xen_pv_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
|
2015-12-22 05:43:16 +03:00
|
|
|
k->realize = xen_pv_realize;
|
2013-07-29 14:58:01 +04:00
|
|
|
k->class_id = PCI_CLASS_SYSTEM_OTHER;
|
|
|
|
dc->desc = "Xen PV Device";
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, xen_pv_props);
|
2018-03-14 02:14:54 +03:00
|
|
|
dc->vmsd = &vmstate_xen_pvdevice;
|
2013-07-29 14:58:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo xen_pv_type_info = {
|
|
|
|
.name = TYPE_XEN_PV_DEVICE,
|
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(XenPVDevice),
|
|
|
|
.class_init = xen_pv_class_init,
|
2017-09-27 22:56:34 +03:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2013-07-29 14:58:01 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void xen_pv_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&xen_pv_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(xen_pv_register_types)
|