From patchwork Wed May 7 15:09:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 29792 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 94244202E4 for ; Wed, 7 May 2014 15:12:03 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id lx4sf5469283iec.7 for ; Wed, 07 May 2014 08:12:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=WWoWDm97e30hUoj0SBwJtVIIjLeKLJZmv+KJUtAT1ko=; b=TsPBDV+7qYiM2e9hpCWAe7+SWqQ/FLdQZPuRtZ3N6RhOjMYEXKckzxNAV5tvzlalED v4KGJFMVJll1pzXfO7fFSTnc1XKr+G1UsX4fP78PxN7EN6lqbMbB8d1VTjDvXfdO8ia0 cOiqzm5GfO6rrNakOzMisz8Zjr+9OoeeM3VfB31B/5URapo5nnp5cOuD8VTbkaLvzBLx YN85gsDV2wuiJE//Xhj14DK1SMHcA3vA+zM0Og+iPPk4x/Fw7HBfnzoe3EwZ6xJ3KBKc WFEESU6TUES7zqznmcWhQtH8b2eHfF70yj35g5wxmn8obzkZO0shWjiEbfyE/eHFGn8O av3A== X-Gm-Message-State: ALoCoQkCEsk8IC9cVXCwbXxyvgeksNP3nZTJvcnXyfY6WFe57BcMRzdn9BNHQiwot7fWGsXduz7a X-Received: by 10.42.229.194 with SMTP id jj2mr2756806icb.18.1399475522820; Wed, 07 May 2014 08:12:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.247 with SMTP id b110ls3413954qge.16.gmail; Wed, 07 May 2014 08:12:02 -0700 (PDT) X-Received: by 10.58.202.133 with SMTP id ki5mr38514015vec.19.1399475522574; Wed, 07 May 2014 08:12:02 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id qw5si2963440vcb.48.2014.05.07.08.12.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 08:12:02 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id pa12so1435181veb.26 for ; Wed, 07 May 2014 08:12:02 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr1247208vcd.45.1399475522436; Wed, 07 May 2014 08:12:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp317698vcb; Wed, 7 May 2014 08:12:00 -0700 (PDT) X-Received: by 10.221.37.1 with SMTP id tc1mr7164928vcb.32.1399475520904; Wed, 07 May 2014 08:12:00 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id tm8si2953309vdc.98.2014.05.07.08.12.00 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 07 May 2014 08:12:00 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wi3Ub-0004RY-IQ; Wed, 07 May 2014 15:10:45 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wi3UY-0004Ol-BB for xen-devel@lists.xensource.com; Wed, 07 May 2014 15:10:43 +0000 Received: from [193.109.254.147:64886] by server-15.bemta-14.messagelabs.com id D7/4F-15813-1FC4A635; Wed, 07 May 2014 15:10:41 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1399475436!3308595!4 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10903 invoked from network); 7 May 2014 15:10:40 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-4.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 7 May 2014 15:10:40 -0000 X-IronPort-AV: E=Sophos; i="4.97,1004,1389744000"; d="scan'208"; a="128639628" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 07 May 2014 15:10:36 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.3.181.6; Wed, 7 May 2014 11:10:34 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1Wi3UK-0004B3-P1; Wed, 07 May 2014 16:10:28 +0100 From: Stefano Stabellini To: Date: Wed, 7 May 2014 16:09:59 +0100 Message-ID: <1399475403-5408-4-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 Cc: olaf@aepfle.de, xen-devel@lists.xensource.com, Wei Liu , Stefano Stabellini , qemu-devel@nongnu.org, anthony@codemonkey.ws, Anthony.Perard@citrix.com, pbonzini@redhat.com Subject: [Xen-devel] [PULL 4/7] xen: move Xen HVM files under hw/i386/xen X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Wei Liu Signed-off-by: Wei Liu Signed-off-by: Stefano Stabellini --- hw/i386/Makefile.objs | 2 +- hw/i386/xen/Makefile.objs | 1 + hw/i386/xen/xen_apic.c | 97 ++++++++++ hw/i386/xen/xen_platform.c | 450 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/xen/xen_pvdevice.c | 135 +++++++++++++ hw/xen/Makefile.objs | 1 - hw/xen/xen_apic.c | 97 ---------- hw/xen/xen_platform.c | 450 -------------------------------------------- hw/xen/xen_pvdevice.c | 135 ------------- 9 files changed, 684 insertions(+), 684 deletions(-) create mode 100644 hw/i386/xen/Makefile.objs create mode 100644 hw/i386/xen/xen_apic.c create mode 100644 hw/i386/xen/xen_platform.c create mode 100644 hw/i386/xen/xen_pvdevice.c delete mode 100644 hw/xen/xen_apic.c delete mode 100644 hw/xen/xen_platform.c delete mode 100644 hw/xen/xen_pvdevice.c diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index f9899a3..f66c349 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -2,7 +2,7 @@ obj-$(CONFIG_KVM) += kvm/ obj-y += multiboot.o smbios.o obj-y += pc.o pc_piix.o pc_q35.o obj-y += pc_sysfw.o -obj-$(CONFIG_XEN) += ../xenpv/ +obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o obj-y += acpi-build.o diff --git a/hw/i386/xen/Makefile.objs b/hw/i386/xen/Makefile.objs new file mode 100644 index 0000000..801a68d --- /dev/null +++ b/hw/i386/xen/Makefile.objs @@ -0,0 +1 @@ +obj-y += xen_platform.o xen_apic.o xen_pvdevice.o diff --git a/hw/i386/xen/xen_apic.c b/hw/i386/xen/xen_apic.c new file mode 100644 index 0000000..63bb7f7 --- /dev/null +++ b/hw/i386/xen/xen_apic.c @@ -0,0 +1,97 @@ +/* + * Xen basic APIC support + * + * Copyright (c) 2012 Citrix + * + * Authors: + * Wei Liu + * + * This work is licensed under the terms of the GNU GPL version 2 or + * later. See the COPYING file in the top-level directory. + */ +#include "hw/i386/apic_internal.h" +#include "hw/pci/msi.h" +#include "hw/xen/xen.h" + +static uint64_t xen_apic_mem_read(void *opaque, hwaddr addr, + unsigned size) +{ + return ~(uint64_t)0; +} + +static void xen_apic_mem_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + if (size != sizeof(uint32_t)) { + fprintf(stderr, "Xen: APIC write data size = %d, invalid\n", size); + return; + } + + xen_hvm_inject_msi(addr, data); +} + +static const MemoryRegionOps xen_apic_io_ops = { + .read = xen_apic_mem_read, + .write = xen_apic_mem_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void xen_apic_realize(DeviceState *dev, Error **errp) +{ + APICCommonState *s = APIC_COMMON(dev); + + memory_region_init_io(&s->io_memory, OBJECT(s), &xen_apic_io_ops, s, + "xen-apic-msi", APIC_SPACE_SIZE); + +#if defined(CONFIG_XEN_CTRL_INTERFACE_VERSION) \ + && CONFIG_XEN_CTRL_INTERFACE_VERSION >= 420 + msi_supported = true; +#endif +} + +static void xen_apic_set_base(APICCommonState *s, uint64_t val) +{ +} + +static void xen_apic_set_tpr(APICCommonState *s, uint8_t val) +{ +} + +static uint8_t xen_apic_get_tpr(APICCommonState *s) +{ + return 0; +} + +static void xen_apic_vapic_base_update(APICCommonState *s) +{ +} + +static void xen_apic_external_nmi(APICCommonState *s) +{ +} + +static void xen_apic_class_init(ObjectClass *klass, void *data) +{ + APICCommonClass *k = APIC_COMMON_CLASS(klass); + + k->realize = xen_apic_realize; + k->set_base = xen_apic_set_base; + k->set_tpr = xen_apic_set_tpr; + k->get_tpr = xen_apic_get_tpr; + k->vapic_base_update = xen_apic_vapic_base_update; + k->external_nmi = xen_apic_external_nmi; +} + +static const TypeInfo xen_apic_info = { + .name = "xen-apic", + .parent = TYPE_APIC_COMMON, + .instance_size = sizeof(APICCommonState), + .class_init = xen_apic_class_init, +}; + +static void xen_apic_register_types(void) +{ + type_register_static(&xen_apic_info); +} + +type_init(xen_apic_register_types) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c new file mode 100644 index 0000000..1d9d0e9 --- /dev/null +++ b/hw/i386/xen/xen_platform.c @@ -0,0 +1,450 @@ +/* + * XEN platform pci device, formerly known as the event channel device + * + * Copyright (c) 2003-2004 Intel Corp. + * Copyright (c) 2006 XenSource + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "hw/ide.h" +#include "hw/pci/pci.h" +#include "hw/irq.h" +#include "hw/xen/xen_common.h" +#include "hw/xen/xen_backend.h" +#include "trace.h" +#include "exec/address-spaces.h" + +#include + +//#define DEBUG_PLATFORM + +#ifdef DEBUG_PLATFORM +#define DPRINTF(fmt, ...) do { \ + fprintf(stderr, "xen_platform: " fmt, ## __VA_ARGS__); \ +} while (0) +#else +#define DPRINTF(fmt, ...) do { } while (0) +#endif + +#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */ + +typedef struct PCIXenPlatformState { + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + + MemoryRegion fixed_io; + MemoryRegion bar; + MemoryRegion mmio_bar; + uint8_t flags; /* used only for version_id == 2 */ + int drivers_blacklisted; + uint16_t driver_product_version; + + /* Log from guest drivers */ + char log_buffer[4096]; + int log_buffer_off; +} PCIXenPlatformState; + +#define TYPE_XEN_PLATFORM "xen-platform" +#define XEN_PLATFORM(obj) \ + OBJECT_CHECK(PCIXenPlatformState, (obj), TYPE_XEN_PLATFORM) + +#define XEN_PLATFORM_IOPORT 0x10 + +/* Send bytes to syslog */ +static void log_writeb(PCIXenPlatformState *s, char val) +{ + if (val == '\n' || s->log_buffer_off == sizeof(s->log_buffer) - 1) { + /* Flush buffer */ + s->log_buffer[s->log_buffer_off] = 0; + trace_xen_platform_log(s->log_buffer); + s->log_buffer_off = 0; + } else { + s->log_buffer[s->log_buffer_off++] = val; + } +} + +/* Xen Platform, Fixed IOPort */ +#define UNPLUG_ALL_IDE_DISKS 1 +#define UNPLUG_ALL_NICS 2 +#define UNPLUG_AUX_IDE_DISKS 4 + +static void unplug_nic(PCIBus *b, PCIDevice *d, void *o) +{ + /* We have to ignore passthrough devices */ + if (pci_get_word(d->config + PCI_CLASS_DEVICE) == + PCI_CLASS_NETWORK_ETHERNET + && strcmp(d->name, "xen-pci-passthrough") != 0) { + object_unparent(OBJECT(d)); + } +} + +static void pci_unplug_nics(PCIBus *bus) +{ + pci_for_each_device(bus, 0, unplug_nic, NULL); +} + +static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) +{ + /* We have to ignore passthrough devices */ + if (pci_get_word(d->config + PCI_CLASS_DEVICE) == + PCI_CLASS_STORAGE_IDE + && strcmp(d->name, "xen-pci-passthrough") != 0) { + pci_piix3_xen_ide_unplug(DEVICE(d)); + } +} + +static void pci_unplug_disks(PCIBus *bus) +{ + pci_for_each_device(bus, 0, unplug_disks, NULL); +} + +static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val) +{ + PCIXenPlatformState *s = opaque; + + switch (addr) { + case 0: { + PCIDevice *pci_dev = PCI_DEVICE(s); + /* Unplug devices. Value is a bitmask of which devices to + unplug, with bit 0 the IDE devices, bit 1 the network + devices, and bit 2 the non-primary-master IDE devices. */ + if (val & UNPLUG_ALL_IDE_DISKS) { + DPRINTF("unplug disks\n"); + bdrv_drain_all(); + bdrv_flush_all(); + pci_unplug_disks(pci_dev->bus); + } + if (val & UNPLUG_ALL_NICS) { + DPRINTF("unplug nics\n"); + pci_unplug_nics(pci_dev->bus); + } + if (val & UNPLUG_AUX_IDE_DISKS) { + DPRINTF("unplug auxiliary disks not supported\n"); + } + break; + } + case 2: + switch (val) { + case 1: + DPRINTF("Citrix Windows PV drivers loaded in guest\n"); + break; + case 0: + DPRINTF("Guest claimed to be running PV product 0?\n"); + break; + default: + DPRINTF("Unknown PV product %d loaded in guest\n", val); + break; + } + s->driver_product_version = val; + break; + } +} + +static void platform_fixed_ioport_writel(void *opaque, uint32_t addr, + uint32_t val) +{ + switch (addr) { + case 0: + /* PV driver version */ + break; + } +} + +static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) +{ + PCIXenPlatformState *s = opaque; + + switch (addr) { + case 0: /* Platform flags */ { + hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ? + HVMMEM_ram_ro : HVMMEM_ram_rw; + if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type, 0xc0, 0x40)) { + DPRINTF("unable to change ro/rw state of ROM memory area!\n"); + } else { + s->flags = val & PFFLAG_ROM_LOCK; + DPRINTF("changed ro/rw state of ROM memory area. now is %s state.\n", + (mem_type == HVMMEM_ram_ro ? "ro":"rw")); + } + break; + } + case 2: + log_writeb(s, val); + break; + } +} + +static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr) +{ + PCIXenPlatformState *s = opaque; + + switch (addr) { + case 0: + if (s->drivers_blacklisted) { + /* The drivers will recognise this magic number and refuse + * to do anything. */ + return 0xd249; + } else { + /* Magic value so that you can identify the interface. */ + return 0x49d2; + } + default: + return 0xffff; + } +} + +static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr) +{ + PCIXenPlatformState *s = opaque; + + switch (addr) { + case 0: + /* Platform flags */ + return s->flags; + case 2: + /* Version number */ + return 1; + default: + return 0xff; + } +} + +static void platform_fixed_ioport_reset(void *opaque) +{ + PCIXenPlatformState *s = opaque; + + platform_fixed_ioport_writeb(s, 0, 0); +} + +static uint64_t platform_fixed_ioport_read(void *opaque, + hwaddr addr, + unsigned size) +{ + switch (size) { + case 1: + return platform_fixed_ioport_readb(opaque, addr); + case 2: + return platform_fixed_ioport_readw(opaque, addr); + default: + return -1; + } +} + +static void platform_fixed_ioport_write(void *opaque, hwaddr addr, + + uint64_t val, unsigned size) +{ + switch (size) { + case 1: + platform_fixed_ioport_writeb(opaque, addr, val); + break; + case 2: + platform_fixed_ioport_writew(opaque, addr, val); + break; + case 4: + platform_fixed_ioport_writel(opaque, addr, val); + break; + } +} + + +static const MemoryRegionOps platform_fixed_io_ops = { + .read = platform_fixed_ioport_read, + .write = platform_fixed_ioport_write, + .valid = { + .unaligned = true, + }, + .impl = { + .min_access_size = 1, + .max_access_size = 4, + .unaligned = true, + }, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static void platform_fixed_ioport_init(PCIXenPlatformState* s) +{ + memory_region_init_io(&s->fixed_io, OBJECT(s), &platform_fixed_io_ops, s, + "xen-fixed", 16); + memory_region_add_subregion(get_system_io(), XEN_PLATFORM_IOPORT, + &s->fixed_io); +} + +/* Xen Platform PCI Device */ + +static uint64_t xen_platform_ioport_readb(void *opaque, hwaddr addr, + unsigned int size) +{ + if (addr == 0) { + return platform_fixed_ioport_readb(opaque, 0); + } else { + return ~0u; + } +} + +static void xen_platform_ioport_writeb(void *opaque, hwaddr addr, + uint64_t val, unsigned int size) +{ + PCIXenPlatformState *s = opaque; + + switch (addr) { + case 0: /* Platform flags */ + platform_fixed_ioport_writeb(opaque, 0, (uint32_t)val); + break; + case 8: + log_writeb(s, (uint32_t)val); + break; + default: + break; + } +} + +static const MemoryRegionOps xen_pci_io_ops = { + .read = xen_platform_ioport_readb, + .write = xen_platform_ioport_writeb, + .impl.min_access_size = 1, + .impl.max_access_size = 1, +}; + +static void platform_ioport_bar_setup(PCIXenPlatformState *d) +{ + memory_region_init_io(&d->bar, OBJECT(d), &xen_pci_io_ops, d, + "xen-pci", 0x100); +} + +static uint64_t platform_mmio_read(void *opaque, hwaddr addr, + unsigned size) +{ + DPRINTF("Warning: attempted read from physical address " + "0x" TARGET_FMT_plx " in xen platform mmio space\n", addr); + + return 0; +} + +static void platform_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + DPRINTF("Warning: attempted write of 0x%"PRIx64" to physical " + "address 0x" TARGET_FMT_plx " in xen platform mmio space\n", + val, addr); +} + +static const MemoryRegionOps platform_mmio_handler = { + .read = &platform_mmio_read, + .write = &platform_mmio_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void platform_mmio_setup(PCIXenPlatformState *d) +{ + memory_region_init_io(&d->mmio_bar, OBJECT(d), &platform_mmio_handler, d, + "xen-mmio", 0x1000000); +} + +static int xen_platform_post_load(void *opaque, int version_id) +{ + PCIXenPlatformState *s = opaque; + + platform_fixed_ioport_writeb(s, 0, s->flags); + + return 0; +} + +static const VMStateDescription vmstate_xen_platform = { + .name = "platform", + .version_id = 4, + .minimum_version_id = 4, + .minimum_version_id_old = 4, + .post_load = xen_platform_post_load, + .fields = (VMStateField []) { + VMSTATE_PCI_DEVICE(parent_obj, PCIXenPlatformState), + VMSTATE_UINT8(flags, PCIXenPlatformState), + VMSTATE_END_OF_LIST() + } +}; + +static int xen_platform_initfn(PCIDevice *dev) +{ + PCIXenPlatformState *d = XEN_PLATFORM(dev); + uint8_t *pci_conf; + + pci_conf = dev->config; + + pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY); + + pci_config_set_prog_interface(pci_conf, 0); + + pci_conf[PCI_INTERRUPT_PIN] = 1; + + platform_ioport_bar_setup(d); + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->bar); + + /* reserve 16MB mmio address for share memory*/ + platform_mmio_setup(d); + pci_register_bar(dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, + &d->mmio_bar); + + platform_fixed_ioport_init(d); + + return 0; +} + +static void platform_reset(DeviceState *dev) +{ + PCIXenPlatformState *s = XEN_PLATFORM(dev); + + platform_fixed_ioport_reset(s); +} + +static void xen_platform_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->init = xen_platform_initfn; + k->vendor_id = PCI_VENDOR_ID_XEN; + k->device_id = PCI_DEVICE_ID_XEN_PLATFORM; + k->class_id = PCI_CLASS_OTHERS << 8 | 0x80; + k->subsystem_vendor_id = PCI_VENDOR_ID_XEN; + k->subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM; + k->revision = 1; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + dc->desc = "XEN platform pci device"; + dc->reset = platform_reset; + dc->vmsd = &vmstate_xen_platform; +} + +static const TypeInfo xen_platform_info = { + .name = TYPE_XEN_PLATFORM, + .parent = TYPE_PCI_DEVICE, + .instance_size = sizeof(PCIXenPlatformState), + .class_init = xen_platform_class_init, +}; + +static void xen_platform_register_types(void) +{ + type_register_static(&xen_platform_info); +} + +type_init(xen_platform_register_types) diff --git a/hw/i386/xen/xen_pvdevice.c b/hw/i386/xen/xen_pvdevice.c new file mode 100644 index 0000000..c218947 --- /dev/null +++ b/hw/i386/xen/xen_pvdevice.c @@ -0,0 +1,135 @@ +/* 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_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 = { + .read = &xen_pv_mmio_read, + .write = &xen_pv_mmio_write, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static int xen_pv_init(PCIDevice *pci_dev) +{ + XenPVDevice *d = XEN_PV_DEVICE(pci_dev); + uint8_t *pci_conf; + + /* device-id property must always be supplied */ + if (d->device_id == 0xffff) + return -1; + + 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); + + return 0; +} + +static Property xen_pv_props[] = { + DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_ID_XEN), + DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, 0xffff), + 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); + + k->init = xen_pv_init; + k->class_id = PCI_CLASS_SYSTEM_OTHER; + dc->desc = "Xen PV Device"; + dc->props = xen_pv_props; +} + +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, +}; + +static void xen_pv_register_types(void) +{ + type_register_static(&xen_pv_type_info); +} + +type_init(xen_pv_register_types) diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs index ce640c6..a0ca0aa 100644 --- a/hw/xen/Makefile.objs +++ b/hw/xen/Makefile.objs @@ -1,6 +1,5 @@ # xen backend driver support common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o -obj-$(CONFIG_XEN_I386) += xen_platform.o xen_apic.o xen_pvdevice.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o diff --git a/hw/xen/xen_apic.c b/hw/xen/xen_apic.c deleted file mode 100644 index 63bb7f7..0000000 --- a/hw/xen/xen_apic.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Xen basic APIC support - * - * Copyright (c) 2012 Citrix - * - * Authors: - * Wei Liu - * - * This work is licensed under the terms of the GNU GPL version 2 or - * later. See the COPYING file in the top-level directory. - */ -#include "hw/i386/apic_internal.h" -#include "hw/pci/msi.h" -#include "hw/xen/xen.h" - -static uint64_t xen_apic_mem_read(void *opaque, hwaddr addr, - unsigned size) -{ - return ~(uint64_t)0; -} - -static void xen_apic_mem_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) -{ - if (size != sizeof(uint32_t)) { - fprintf(stderr, "Xen: APIC write data size = %d, invalid\n", size); - return; - } - - xen_hvm_inject_msi(addr, data); -} - -static const MemoryRegionOps xen_apic_io_ops = { - .read = xen_apic_mem_read, - .write = xen_apic_mem_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void xen_apic_realize(DeviceState *dev, Error **errp) -{ - APICCommonState *s = APIC_COMMON(dev); - - memory_region_init_io(&s->io_memory, OBJECT(s), &xen_apic_io_ops, s, - "xen-apic-msi", APIC_SPACE_SIZE); - -#if defined(CONFIG_XEN_CTRL_INTERFACE_VERSION) \ - && CONFIG_XEN_CTRL_INTERFACE_VERSION >= 420 - msi_supported = true; -#endif -} - -static void xen_apic_set_base(APICCommonState *s, uint64_t val) -{ -} - -static void xen_apic_set_tpr(APICCommonState *s, uint8_t val) -{ -} - -static uint8_t xen_apic_get_tpr(APICCommonState *s) -{ - return 0; -} - -static void xen_apic_vapic_base_update(APICCommonState *s) -{ -} - -static void xen_apic_external_nmi(APICCommonState *s) -{ -} - -static void xen_apic_class_init(ObjectClass *klass, void *data) -{ - APICCommonClass *k = APIC_COMMON_CLASS(klass); - - k->realize = xen_apic_realize; - k->set_base = xen_apic_set_base; - k->set_tpr = xen_apic_set_tpr; - k->get_tpr = xen_apic_get_tpr; - k->vapic_base_update = xen_apic_vapic_base_update; - k->external_nmi = xen_apic_external_nmi; -} - -static const TypeInfo xen_apic_info = { - .name = "xen-apic", - .parent = TYPE_APIC_COMMON, - .instance_size = sizeof(APICCommonState), - .class_init = xen_apic_class_init, -}; - -static void xen_apic_register_types(void) -{ - type_register_static(&xen_apic_info); -} - -type_init(xen_apic_register_types) diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c deleted file mode 100644 index 1d9d0e9..0000000 --- a/hw/xen/xen_platform.c +++ /dev/null @@ -1,450 +0,0 @@ -/* - * XEN platform pci device, formerly known as the event channel device - * - * Copyright (c) 2003-2004 Intel Corp. - * Copyright (c) 2006 XenSource - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "hw/hw.h" -#include "hw/i386/pc.h" -#include "hw/ide.h" -#include "hw/pci/pci.h" -#include "hw/irq.h" -#include "hw/xen/xen_common.h" -#include "hw/xen/xen_backend.h" -#include "trace.h" -#include "exec/address-spaces.h" - -#include - -//#define DEBUG_PLATFORM - -#ifdef DEBUG_PLATFORM -#define DPRINTF(fmt, ...) do { \ - fprintf(stderr, "xen_platform: " fmt, ## __VA_ARGS__); \ -} while (0) -#else -#define DPRINTF(fmt, ...) do { } while (0) -#endif - -#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */ - -typedef struct PCIXenPlatformState { - /*< private >*/ - PCIDevice parent_obj; - /*< public >*/ - - MemoryRegion fixed_io; - MemoryRegion bar; - MemoryRegion mmio_bar; - uint8_t flags; /* used only for version_id == 2 */ - int drivers_blacklisted; - uint16_t driver_product_version; - - /* Log from guest drivers */ - char log_buffer[4096]; - int log_buffer_off; -} PCIXenPlatformState; - -#define TYPE_XEN_PLATFORM "xen-platform" -#define XEN_PLATFORM(obj) \ - OBJECT_CHECK(PCIXenPlatformState, (obj), TYPE_XEN_PLATFORM) - -#define XEN_PLATFORM_IOPORT 0x10 - -/* Send bytes to syslog */ -static void log_writeb(PCIXenPlatformState *s, char val) -{ - if (val == '\n' || s->log_buffer_off == sizeof(s->log_buffer) - 1) { - /* Flush buffer */ - s->log_buffer[s->log_buffer_off] = 0; - trace_xen_platform_log(s->log_buffer); - s->log_buffer_off = 0; - } else { - s->log_buffer[s->log_buffer_off++] = val; - } -} - -/* Xen Platform, Fixed IOPort */ -#define UNPLUG_ALL_IDE_DISKS 1 -#define UNPLUG_ALL_NICS 2 -#define UNPLUG_AUX_IDE_DISKS 4 - -static void unplug_nic(PCIBus *b, PCIDevice *d, void *o) -{ - /* We have to ignore passthrough devices */ - if (pci_get_word(d->config + PCI_CLASS_DEVICE) == - PCI_CLASS_NETWORK_ETHERNET - && strcmp(d->name, "xen-pci-passthrough") != 0) { - object_unparent(OBJECT(d)); - } -} - -static void pci_unplug_nics(PCIBus *bus) -{ - pci_for_each_device(bus, 0, unplug_nic, NULL); -} - -static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) -{ - /* We have to ignore passthrough devices */ - if (pci_get_word(d->config + PCI_CLASS_DEVICE) == - PCI_CLASS_STORAGE_IDE - && strcmp(d->name, "xen-pci-passthrough") != 0) { - pci_piix3_xen_ide_unplug(DEVICE(d)); - } -} - -static void pci_unplug_disks(PCIBus *bus) -{ - pci_for_each_device(bus, 0, unplug_disks, NULL); -} - -static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val) -{ - PCIXenPlatformState *s = opaque; - - switch (addr) { - case 0: { - PCIDevice *pci_dev = PCI_DEVICE(s); - /* Unplug devices. Value is a bitmask of which devices to - unplug, with bit 0 the IDE devices, bit 1 the network - devices, and bit 2 the non-primary-master IDE devices. */ - if (val & UNPLUG_ALL_IDE_DISKS) { - DPRINTF("unplug disks\n"); - bdrv_drain_all(); - bdrv_flush_all(); - pci_unplug_disks(pci_dev->bus); - } - if (val & UNPLUG_ALL_NICS) { - DPRINTF("unplug nics\n"); - pci_unplug_nics(pci_dev->bus); - } - if (val & UNPLUG_AUX_IDE_DISKS) { - DPRINTF("unplug auxiliary disks not supported\n"); - } - break; - } - case 2: - switch (val) { - case 1: - DPRINTF("Citrix Windows PV drivers loaded in guest\n"); - break; - case 0: - DPRINTF("Guest claimed to be running PV product 0?\n"); - break; - default: - DPRINTF("Unknown PV product %d loaded in guest\n", val); - break; - } - s->driver_product_version = val; - break; - } -} - -static void platform_fixed_ioport_writel(void *opaque, uint32_t addr, - uint32_t val) -{ - switch (addr) { - case 0: - /* PV driver version */ - break; - } -} - -static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) -{ - PCIXenPlatformState *s = opaque; - - switch (addr) { - case 0: /* Platform flags */ { - hvmmem_type_t mem_type = (val & PFFLAG_ROM_LOCK) ? - HVMMEM_ram_ro : HVMMEM_ram_rw; - if (xc_hvm_set_mem_type(xen_xc, xen_domid, mem_type, 0xc0, 0x40)) { - DPRINTF("unable to change ro/rw state of ROM memory area!\n"); - } else { - s->flags = val & PFFLAG_ROM_LOCK; - DPRINTF("changed ro/rw state of ROM memory area. now is %s state.\n", - (mem_type == HVMMEM_ram_ro ? "ro":"rw")); - } - break; - } - case 2: - log_writeb(s, val); - break; - } -} - -static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr) -{ - PCIXenPlatformState *s = opaque; - - switch (addr) { - case 0: - if (s->drivers_blacklisted) { - /* The drivers will recognise this magic number and refuse - * to do anything. */ - return 0xd249; - } else { - /* Magic value so that you can identify the interface. */ - return 0x49d2; - } - default: - return 0xffff; - } -} - -static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr) -{ - PCIXenPlatformState *s = opaque; - - switch (addr) { - case 0: - /* Platform flags */ - return s->flags; - case 2: - /* Version number */ - return 1; - default: - return 0xff; - } -} - -static void platform_fixed_ioport_reset(void *opaque) -{ - PCIXenPlatformState *s = opaque; - - platform_fixed_ioport_writeb(s, 0, 0); -} - -static uint64_t platform_fixed_ioport_read(void *opaque, - hwaddr addr, - unsigned size) -{ - switch (size) { - case 1: - return platform_fixed_ioport_readb(opaque, addr); - case 2: - return platform_fixed_ioport_readw(opaque, addr); - default: - return -1; - } -} - -static void platform_fixed_ioport_write(void *opaque, hwaddr addr, - - uint64_t val, unsigned size) -{ - switch (size) { - case 1: - platform_fixed_ioport_writeb(opaque, addr, val); - break; - case 2: - platform_fixed_ioport_writew(opaque, addr, val); - break; - case 4: - platform_fixed_ioport_writel(opaque, addr, val); - break; - } -} - - -static const MemoryRegionOps platform_fixed_io_ops = { - .read = platform_fixed_ioport_read, - .write = platform_fixed_ioport_write, - .valid = { - .unaligned = true, - }, - .impl = { - .min_access_size = 1, - .max_access_size = 4, - .unaligned = true, - }, - .endianness = DEVICE_LITTLE_ENDIAN, -}; - -static void platform_fixed_ioport_init(PCIXenPlatformState* s) -{ - memory_region_init_io(&s->fixed_io, OBJECT(s), &platform_fixed_io_ops, s, - "xen-fixed", 16); - memory_region_add_subregion(get_system_io(), XEN_PLATFORM_IOPORT, - &s->fixed_io); -} - -/* Xen Platform PCI Device */ - -static uint64_t xen_platform_ioport_readb(void *opaque, hwaddr addr, - unsigned int size) -{ - if (addr == 0) { - return platform_fixed_ioport_readb(opaque, 0); - } else { - return ~0u; - } -} - -static void xen_platform_ioport_writeb(void *opaque, hwaddr addr, - uint64_t val, unsigned int size) -{ - PCIXenPlatformState *s = opaque; - - switch (addr) { - case 0: /* Platform flags */ - platform_fixed_ioport_writeb(opaque, 0, (uint32_t)val); - break; - case 8: - log_writeb(s, (uint32_t)val); - break; - default: - break; - } -} - -static const MemoryRegionOps xen_pci_io_ops = { - .read = xen_platform_ioport_readb, - .write = xen_platform_ioport_writeb, - .impl.min_access_size = 1, - .impl.max_access_size = 1, -}; - -static void platform_ioport_bar_setup(PCIXenPlatformState *d) -{ - memory_region_init_io(&d->bar, OBJECT(d), &xen_pci_io_ops, d, - "xen-pci", 0x100); -} - -static uint64_t platform_mmio_read(void *opaque, hwaddr addr, - unsigned size) -{ - DPRINTF("Warning: attempted read from physical address " - "0x" TARGET_FMT_plx " in xen platform mmio space\n", addr); - - return 0; -} - -static void platform_mmio_write(void *opaque, hwaddr addr, - uint64_t val, unsigned size) -{ - DPRINTF("Warning: attempted write of 0x%"PRIx64" to physical " - "address 0x" TARGET_FMT_plx " in xen platform mmio space\n", - val, addr); -} - -static const MemoryRegionOps platform_mmio_handler = { - .read = &platform_mmio_read, - .write = &platform_mmio_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static void platform_mmio_setup(PCIXenPlatformState *d) -{ - memory_region_init_io(&d->mmio_bar, OBJECT(d), &platform_mmio_handler, d, - "xen-mmio", 0x1000000); -} - -static int xen_platform_post_load(void *opaque, int version_id) -{ - PCIXenPlatformState *s = opaque; - - platform_fixed_ioport_writeb(s, 0, s->flags); - - return 0; -} - -static const VMStateDescription vmstate_xen_platform = { - .name = "platform", - .version_id = 4, - .minimum_version_id = 4, - .minimum_version_id_old = 4, - .post_load = xen_platform_post_load, - .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(parent_obj, PCIXenPlatformState), - VMSTATE_UINT8(flags, PCIXenPlatformState), - VMSTATE_END_OF_LIST() - } -}; - -static int xen_platform_initfn(PCIDevice *dev) -{ - PCIXenPlatformState *d = XEN_PLATFORM(dev); - uint8_t *pci_conf; - - pci_conf = dev->config; - - pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY); - - pci_config_set_prog_interface(pci_conf, 0); - - pci_conf[PCI_INTERRUPT_PIN] = 1; - - platform_ioport_bar_setup(d); - pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->bar); - - /* reserve 16MB mmio address for share memory*/ - platform_mmio_setup(d); - pci_register_bar(dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, - &d->mmio_bar); - - platform_fixed_ioport_init(d); - - return 0; -} - -static void platform_reset(DeviceState *dev) -{ - PCIXenPlatformState *s = XEN_PLATFORM(dev); - - platform_fixed_ioport_reset(s); -} - -static void xen_platform_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - - k->init = xen_platform_initfn; - k->vendor_id = PCI_VENDOR_ID_XEN; - k->device_id = PCI_DEVICE_ID_XEN_PLATFORM; - k->class_id = PCI_CLASS_OTHERS << 8 | 0x80; - k->subsystem_vendor_id = PCI_VENDOR_ID_XEN; - k->subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM; - k->revision = 1; - set_bit(DEVICE_CATEGORY_MISC, dc->categories); - dc->desc = "XEN platform pci device"; - dc->reset = platform_reset; - dc->vmsd = &vmstate_xen_platform; -} - -static const TypeInfo xen_platform_info = { - .name = TYPE_XEN_PLATFORM, - .parent = TYPE_PCI_DEVICE, - .instance_size = sizeof(PCIXenPlatformState), - .class_init = xen_platform_class_init, -}; - -static void xen_platform_register_types(void) -{ - type_register_static(&xen_platform_info); -} - -type_init(xen_platform_register_types) diff --git a/hw/xen/xen_pvdevice.c b/hw/xen/xen_pvdevice.c deleted file mode 100644 index c218947..0000000 --- a/hw/xen/xen_pvdevice.c +++ /dev/null @@ -1,135 +0,0 @@ -/* 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_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 = { - .read = &xen_pv_mmio_read, - .write = &xen_pv_mmio_write, - .endianness = DEVICE_LITTLE_ENDIAN, -}; - -static int xen_pv_init(PCIDevice *pci_dev) -{ - XenPVDevice *d = XEN_PV_DEVICE(pci_dev); - uint8_t *pci_conf; - - /* device-id property must always be supplied */ - if (d->device_id == 0xffff) - return -1; - - 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); - - return 0; -} - -static Property xen_pv_props[] = { - DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_ID_XEN), - DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, 0xffff), - 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); - - k->init = xen_pv_init; - k->class_id = PCI_CLASS_SYSTEM_OTHER; - dc->desc = "Xen PV Device"; - dc->props = xen_pv_props; -} - -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, -}; - -static void xen_pv_register_types(void) -{ - type_register_static(&xen_pv_type_info); -} - -type_init(xen_pv_register_types)