From patchwork Thu Jan 6 14:14:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 77717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AFBD5B70A9 for ; Fri, 7 Jan 2011 01:22:38 +1100 (EST) Received: from localhost ([127.0.0.1]:49616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Paqgp-00044r-9E for incoming@patchwork.ozlabs.org; Thu, 06 Jan 2011 09:19:43 -0500 Received: from [140.186.70.92] (port=47538 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Paqc5-0002Gd-Lf for qemu-devel@nongnu.org; Thu, 06 Jan 2011 09:14:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Paqc0-0000cI-IV for qemu-devel@nongnu.org; Thu, 06 Jan 2011 09:14:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:18069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Paqc0-0000bc-Ay for qemu-devel@nongnu.org; Thu, 06 Jan 2011 09:14:44 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p06EEhOS020938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Jan 2011 09:14:43 -0500 Received: from rincewind.home.kraxel.org (vpn1-4-139.ams2.redhat.com [10.36.4.139]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p06EEgwT022083; Thu, 6 Jan 2011 09:14:42 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 2C1F8400F9; Thu, 6 Jan 2011 15:14:40 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 6 Jan 2011 15:14:37 +0100 Message-Id: <1294323280-21692-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1294323280-21692-1-git-send-email-kraxel@redhat.com> References: <1294323280-21692-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v2 1/4] pci: allow devices being tagged as not hotpluggable. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds a field to PCIDeviceInfo to tag devices as being not hotpluggable. Any attempt to plug-in or -out such a device will throw an error. Signed-off-by: Gerd Hoffmann Acked-by: Michael S. Tsirkin --- hw/pci.c | 10 ++++++++++ hw/pci.h | 3 +++ qerror.c | 4 ++++ qerror.h | 3 +++ 4 files changed, 20 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index ef00d20..a4ae3b2 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1620,6 +1620,11 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base) info->is_bridge); if (pci_dev == NULL) return -1; + if (qdev->hotplugged && info->no_hotplug) { + qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name); + do_pci_unregister_device(pci_dev); + return -1; + } rc = info->init(pci_dev); if (rc != 0) { do_pci_unregister_device(pci_dev); @@ -1652,7 +1657,12 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base) static int pci_unplug_device(DeviceState *qdev) { PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev); + PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev); + if (info->no_hotplug) { + qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name); + return -1; + } return dev->bus->hotplug(dev->bus->hotplug_qdev, dev, PCI_HOTPLUG_DISABLED); } diff --git a/hw/pci.h b/hw/pci.h index 17744dc..6b4bd3e 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -434,6 +434,9 @@ typedef struct { /* pcie stuff */ int is_express; /* is this device pci express? */ + /* device isn't hot-pluggable */ + int no_hotplug; + /* rom bar */ const char *romfile; } PCIDeviceInfo; diff --git a/qerror.c b/qerror.c index ac2cdaf..9d0cdeb 100644 --- a/qerror.c +++ b/qerror.c @@ -101,6 +101,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device '%(device)' has no child bus", }, { + .error_fmt = QERR_DEVICE_NO_HOTPLUG, + .desc = "Device '%(device)' does not support hotplugging", + }, + { .error_fmt = QERR_DUPLICATE_ID, .desc = "Duplicate ID '%(id)' for %(object)", }, diff --git a/qerror.h b/qerror.h index 943a24b..b0f69da 100644 --- a/qerror.h +++ b/qerror.h @@ -90,6 +90,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_DEVICE_NO_BUS \ "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }" +#define QERR_DEVICE_NO_HOTPLUG \ + "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }" + #define QERR_DUPLICATE_ID \ "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }"