From patchwork Tue Jul 2 14:03:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 256430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 792E52C0097 for ; Wed, 3 Jul 2013 00:20:17 +1000 (EST) Received: from localhost ([::1]:56295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu1RG-0001db-F2 for incoming@patchwork.ozlabs.org; Tue, 02 Jul 2013 10:20:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu1Qr-0001cu-T3 for qemu-devel@nongnu.org; Tue, 02 Jul 2013 10:20:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uu1BD-0000mv-UR for qemu-devel@nongnu.org; Tue, 02 Jul 2013 10:04:05 -0400 Received: from smtp.citrix.com ([66.165.176.89]:54534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu1BD-0000mD-K6 for qemu-devel@nongnu.org; Tue, 02 Jul 2013 10:03:39 -0400 X-IronPort-AV: E=Sophos;i="4.87,980,1363132800"; d="scan'208";a="34688696" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/AES128-SHA; 02 Jul 2013 14:03:18 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.2.342.4; Tue, 2 Jul 2013 10:03:18 -0400 Received: from york.uk.xensource.com ([10.80.228.45] helo=york.uk.xensource.com.) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1Uu1Ar-0002o5-Si; Tue, 02 Jul 2013 15:03:17 +0100 From: Paul Durrant To: , Date: Tue, 2 Jul 2013 15:03:13 +0100 Message-ID: <1372773793-9343-1-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: Paul Durrant Subject: [Qemu-devel] [PATCH] Citrix PV Bus device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch introduces a new PCI device which will act as the binding point for Citrix branded PV drivers for Xen. The intention is that Citrix Windows PV drivers will be available on Windows Update and thus using the existing Xen platform PCI device as an anchor point is not desirable as that device has been ubiquitous in HVM guests for a long time and thus existing HVM guests running Windows would start automatically downloading drivers from Windows Update when this may not be desired by either the host or guest admin. This device therefore acts as an opt-in for those wishing to deploy Citrix PV drivers. Signed-off-by: Paul Durrant --- hw/i386/Makefile.objs | 1 + hw/i386/citrix_pv_bus.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci_ids.h | 7 ++- trace-events | 4 ++ 4 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 hw/i386/citrix_pv_bus.c diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 205d22e..8e28831 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -4,3 +4,4 @@ obj-y += pc.o pc_piix.o pc_q35.o obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o obj-y += kvmvapic.o +obj-y += citrix_pv_bus.o diff --git a/hw/i386/citrix_pv_bus.c b/hw/i386/citrix_pv_bus.c new file mode 100644 index 0000000..c17cfa6 --- /dev/null +++ b/hw/i386/citrix_pv_bus.c @@ -0,0 +1,126 @@ +/* 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. + */ + +#include "hw/hw.h" +#include "hw/pci/pci.h" +#include "trace.h" + +#define TYPE_CITRIX_PV_BUS_DEVICE "citrix-pv" + +#define CITRIX_PV_BUS_DEVICE(obj) \ + OBJECT_CHECK(CitrixPVBusDevice, (obj), TYPE_CITRIX_PV_BUS_DEVICE) + +typedef struct CitrixPVBusDevice { + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + uint8_t revision; + uint32_t size; + MemoryRegion mmio; +} CitrixPVBusDevice; + +static uint64_t citrix_pv_bus_mmio_read(void *opaque, hwaddr addr, + unsigned size) +{ + trace_citrix_pv_bus_mmio_read(addr); + + return ~(uint64_t)0; +} + +static void citrix_pv_bus_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + trace_citrix_pv_bus_mmio_write(addr); +} + +static const MemoryRegionOps citrix_pv_bus_mmio_ops = { + .read = &citrix_pv_bus_mmio_read, + .write = &citrix_pv_bus_mmio_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static int citrix_pv_bus_init(PCIDevice *pci_dev) +{ + CitrixPVBusDevice *d = CITRIX_PV_BUS_DEVICE(pci_dev); + uint8_t *pci_conf; + + pci_conf = pci_dev->config; + + pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_MEMORY); + pci_set_byte(pci_conf + PCI_REVISION_ID, d->revision); + + pci_config_set_prog_interface(pci_conf, 0); + + pci_conf[PCI_INTERRUPT_PIN] = 1; + + memory_region_init_io(&d->mmio, &citrix_pv_bus_mmio_ops, d, + "citrix-bus-mmio", d->size); + + pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, + &d->mmio); + + return 0; +} + +static Property citrix_pv_bus_props[] = { + DEFINE_PROP_UINT8("revision", CitrixPVBusDevice, revision, 0x01), + DEFINE_PROP_UINT32("size", CitrixPVBusDevice, size, 0x400000), + DEFINE_PROP_END_OF_LIST() +}; + +static void citrix_pv_bus_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->init = citrix_pv_bus_init; + k->vendor_id = PCI_VENDOR_ID_CITRIX; + k->device_id = PCI_DEVICE_ID_CITRIX_PV_BUS; + k->class_id = PCI_CLASS_SYSTEM_OTHER; + k->subsystem_vendor_id = PCI_VENDOR_ID_CITRIX; + k->subsystem_id = PCI_DEVICE_ID_CITRIX_PV_BUS; + dc->desc = "Citrix PV Bus"; + dc->props = citrix_pv_bus_props; +} + +static const TypeInfo citrix_pv_bus_type_info = { + .name = TYPE_CITRIX_PV_BUS_DEVICE, + .parent = TYPE_PCI_DEVICE, + .instance_size = sizeof(CitrixPVBusDevice), + .class_init = citrix_pv_bus_class_init, +}; + +static void citrix_pv_bus_register_types(void) +{ + type_register_static(&citrix_pv_bus_type_info); +} + +type_init(citrix_pv_bus_register_types) diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index d8dc2f1..95b236f 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -142,8 +142,11 @@ #define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0 -#define PCI_VENDOR_ID_XEN 0x5853 -#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001 +#define PCI_VENDOR_ID_CITRIX 0x5853 +#define PCI_DEVICE_ID_CITRIX_PV_BUS 0x0002 + +#define PCI_VENDOR_ID_XEN (PCI_VENDOR_ID_CITRIX) +#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001 #define PCI_VENDOR_ID_NEC 0x1033 #define PCI_DEVICE_ID_NEC_UPD720200 0x0194 diff --git a/trace-events b/trace-events index c5f1ccb..63052b9 100644 --- a/trace-events +++ b/trace-events @@ -1161,3 +1161,7 @@ kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d" # qom/object.c object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)" object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)" + +# hw/i386/citrix_pv_bus.c +citrix_pv_bus_mmio_read(uint64_t addr) "WARNING: read from Citrix PV MMIO space (address %"PRIx64")" +citrix_pv_bus_mmio_write(uint64_t addr) "WARNING: write to Citrix PV MMIO space (address %"PRIx64")"