From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UwC7f-0006Ep-IY for qemu-devel@nongnu.org; Mon, 08 Jul 2013 10:09:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UwC7P-0007zo-E6 for qemu-devel@nongnu.org; Mon, 08 Jul 2013 10:08:59 -0400 Received: from mail-oa0-f53.google.com ([209.85.219.53]:64862) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UwC7P-0007zO-6U for qemu-devel@nongnu.org; Mon, 08 Jul 2013 10:08:43 -0400 Received: by mail-oa0-f53.google.com with SMTP id k14so6246252oag.40 for ; Mon, 08 Jul 2013 07:08:42 -0700 (PDT) From: Anthony Liguori In-Reply-To: <1372930249-22916-1-git-send-email-paul.durrant@citrix.com> References: <1372930249-22916-1-git-send-email-paul.durrant@citrix.com> Date: Mon, 08 Jul 2013 09:08:40 -0500 Message-ID: <87k3l1400n.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v5] Xen PV Device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paul Durrant , qemu-devel@nongnu.org, xen-devel@lists.xen.org Cc: Stefano Stabellini Paul Durrant writes: > Introduces a new Xen PV PCI device which will act as a binding point for > PV drivers for Xen. > The device has parameterized vendor-id, device-id and revision to allow to > be configured as a binding point for any vendor's PV drivers. > > Signed-off-by: Paul Durrant > Cc: Stefano Stabellini > Reviewed-by: Andreas F=C3=A4rber Reviewed-by: Anthony Liguori Regards, Anthony Liguori > --- > > V5: > - Addresses comments from Andreas F=C3=A4rber > > V4: > - Renamed from 'Citrix PV Bus' to 'Xen PV Device' > - Paramaterized vendor-id and device-id as requested by Stefano Stabellini > > V3: > - Addresses comments from Anthony Liguori and Peter Maydell > > V2: > - Addresses comments from Andreas Farber and Paolo Bonzini > > hw/xen/Makefile.objs | 1 + > hw/xen/xen_pvdevice.c | 131 ++++++++++++++++++++++++++++++++++++++++= ++++++ > include/hw/pci/pci_ids.h | 5 +- > trace-events | 4 ++ > 4 files changed, 139 insertions(+), 2 deletions(-) > create mode 100644 hw/xen/xen_pvdevice.c > > diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs > index 2017560..cd2df6a 100644 > --- a/hw/xen/Makefile.objs > +++ b/hw/xen/Makefile.objs > @@ -1,5 +1,6 @@ > # xen backend driver support > common-obj-$(CONFIG_XEN_BACKEND) +=3D xen_backend.o xen_devconfig.o > +common-obj-y +=3D xen_pvdevice.o >=20=20 > obj-$(CONFIG_XEN_I386) +=3D xen_platform.o xen_apic.o > obj-$(CONFIG_XEN_PCI_PASSTHROUGH) +=3D xen-host-pci-device.o > diff --git a/hw/xen/xen_pvdevice.c b/hw/xen/xen_pvdevice.c > new file mode 100644 > index 0000000..93dfab2 > --- /dev/null > +++ b/hw/xen/xen_pvdevice.c > @@ -0,0 +1,131 @@ > +/* Copyright (c) Citrix Systems Inc. > + * All rights reserved. > + *=20 > + * Redistribution and use in source and binary forms,=20 > + * with or without modification, are permitted provided=20 > + * that the following conditions are met: > + *=20 > + * * Redistributions of source code must retain the above=20 > + * copyright notice, this list of conditions and the=20 > + * following disclaimer. > + * * Redistributions in binary form must reproduce the above=20 > + * copyright notice, this list of conditions and the=20 > + * following disclaimer in the documentation and/or other=20 > + * materials provided with the distribution. > + *=20 > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND=20 > + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,=20 > + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF=20 > + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE=20 > + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR=20 > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=20 > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,=20 > + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR=20 > + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS=20 > + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,=20 > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING=20 > + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE=20 > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF=20 > + * SUCH DAMAGE. > + */ > + > +#include "hw/hw.h" > +#include "hw/pci/pci.h" > +#include "trace.h" > + > +#define TYPE_XEN_PV_DEVICE "xen-pvdevice" > + > +#define XEN_PV_DEVICE(obj) \ > + OBJECT_CHECK(XenPVDevice, (obj), TYPE_XEN_PV_DEVICE) > + > +typedef struct XenPVDevice { > + /*< private >*/ > + PCIDevice parent_obj; > + /*< public >*/ > + uint16_t vendor_id; > + uint16_t device_id; > + uint8_t revision; > + uint32_t size; > + MemoryRegion mmio; > +} XenPVDevice; > + > +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 =3D { > + .read =3D &xen_pv_mmio_read, > + .write =3D &xen_pv_mmio_write, > + .endianness =3D DEVICE_LITTLE_ENDIAN, > +}; > + > +static int xen_pv_init(PCIDevice *pci_dev) > +{ > + XenPVDevice *d =3D XEN_PV_DEVICE(pci_dev); > + uint8_t *pci_conf; > + > + pci_conf =3D 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] =3D 1; > + > + memory_region_init_io(&d->mmio, &xen_pv_mmio_ops, d, > + "mmio", d->size); > + > + pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, > + &d->mmio); > + > + return 0; > +} > + > +static Property xen_pv_props[] =3D { > + DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_I= D_XEN), > + DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, PCI_DEVICE_I= D_XEN_PVDEVICE), > + 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 =3D DEVICE_CLASS(klass); > + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); > + > + k->init =3D xen_pv_init; > + k->class_id =3D PCI_CLASS_SYSTEM_OTHER; > + dc->desc =3D "Xen PV Device"; > + dc->props =3D xen_pv_props; > +} > + > +static const TypeInfo xen_pv_type_info =3D { > + .name =3D TYPE_XEN_PV_DEVICE, > + .parent =3D TYPE_PCI_DEVICE, > + .instance_size =3D sizeof(XenPVDevice), > + .class_init =3D xen_pv_class_init, > +}; > + > +static void xen_pv_register_types(void) > +{ > + type_register_static(&xen_pv_type_info); > +} > + > +type_init(xen_pv_register_types) > diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h > index d8dc2f1..263bca3 100644 > --- a/include/hw/pci/pci_ids.h > +++ b/include/hw/pci/pci_ids.h > @@ -142,8 +142,9 @@ >=20=20 > #define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0 >=20=20 > -#define PCI_VENDOR_ID_XEN 0x5853 > -#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001 > +#define PCI_VENDOR_ID_XEN 0x5853 > +#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001 > +#define PCI_DEVICE_ID_XEN_PVDEVICE 0x0002 >=20=20 > #define PCI_VENDOR_ID_NEC 0x1033 > #define PCI_DEVICE_ID_NEC_UPD720200 0x0194 > diff --git a/trace-events b/trace-events > index c5f1ccb..0445853 100644 > --- a/trace-events > +++ b/trace-events > @@ -1161,3 +1161,7 @@ kvm_run_exit(int cpu_index, uint32_t reason) "cpu_i= ndex %d, reason %d" > # qom/object.c > object_dynamic_cast_assert(const char *type, const char *target, const c= har *file, int line, const char *func) "%s->%s (%s:%d:%s)" > object_class_dynamic_cast_assert(const char *type, const char *target, c= onst char *file, int line, const char *func) "%s->%s (%s:%d:%s)" > + > +# hw/xen/xen_pvdevice.c > +xen_pv_mmio_read(uint64_t addr) "WARNING: read from Xen PV Device MMIO s= pace (address %"PRIx64")" > +xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO s= pace (address %"PRIx64")" > --=20 > 1.7.10.4