From patchwork Thu Feb 2 18:35:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9552915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A2468604A7 for ; Thu, 2 Feb 2017 18:38:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93C9328411 for ; Thu, 2 Feb 2017 18:38:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 886C0284A3; Thu, 2 Feb 2017 18:38:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 238D728425 for ; Thu, 2 Feb 2017 18:38:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZMEX-0003jP-JS; Thu, 02 Feb 2017 18:35:49 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZMEV-0003j1-Tq for xen-devel@lists.xenproject.org; Thu, 02 Feb 2017 18:35:48 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 14/F0-23854-30C73985; Thu, 02 Feb 2017 18:35:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsVybKJshy5TzeQ Ig7k/lC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oz+rr1MBdOFK2a/fMnawPifr4uRi0NIYCqj xKt931kgnB1MEls2XGfvYuTkYBMwlPj7ZBMbiC0iICZxevc0JpAiZoGTjBKXr0xmAkkIC1hLt H97AdbAIqAqcW/9akYQm1fATWLnr/NgNRICchInj01mBbE5BXwkFi94wAJiCwl4S3S0vWGHqM mQmNczhxXC9pJYdOMSlK0mcfXcJuYJjHwLGBlWMaoXpxaVpRbpmuslFWWmZ5TkJmbm6BoaGOv lphYXJ6an5iQmFesl5+duYgQGCgMQ7GBs/O50iFGSg0lJlHeK1uQIIb6k/JTKjMTijPii0pzU 4kOMMhwcShK8xlVAOcGi1PTUirTMHGDIwqQlOHiURHjngaR5iwsSc4sz0yFSpxgVpcR5zUESA iCJjNI8uDZYnFxilJUS5mUEOkSIpyC1KDezBFX+FaM4B6OSMG8HyBSezLwSuOmvgBYzAS3++X gSyOKSRISUVANjQ7td6LuAGNfEf9/SnqmvMtzG1T+xa5XXtLhFLFejI1YZXH33qW9h7dMZwgK 85/Y9W7SEkeHSjJJ86wiXPLXVulJOPP/fNz85JCLzUYmLZ3PNqXs7J7uf0jUP3hP0aSPzxukb XxUtEs6Lu3zxeeg2Xt0D+u/NGhh7Q4VXnKy+s2HVyZcx6q3iSizFGYmGWsxFxYkAEqj9Lo4CA AA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-7.tower-31.messagelabs.com!1486060545!76160430!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54919 invoked from network); 2 Feb 2017 18:35:46 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-7.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Feb 2017 18:35:46 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F3CB22024F; Thu, 2 Feb 2017 18:35:43 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (c-50-131-44-19.hsd1.ca.comcast.net [50.131.44.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CF6B6201C7; Thu, 2 Feb 2017 18:35:42 +0000 (UTC) From: Stefano Stabellini To: stefanha@gmail.com Date: Thu, 2 Feb 2017 10:35:37 -0800 Message-Id: <1486060541-29146-1-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP Cc: peter.maydell@linaro.org, sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [PULL 1/5] xen-platform: re-structure unplug_disks X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Durrant The current code is poorly structured and potentially leads to multiple config space reads when one is sufficient. Also the UNPLUG_ALL_IDE_DISKS flag is mis-named since it also results in SCSI disks being unplugged. This patch renames the flag and re-structures the code to be more efficient, and readable. Signed-off-by: Paul Durrant Reviewed-by: Stefano Stabellini --- hw/i386/xen/xen_platform.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 2e1e543..f50915f 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -88,7 +88,7 @@ static void log_writeb(PCIXenPlatformState *s, char val) } /* Xen Platform, Fixed IOPort */ -#define UNPLUG_ALL_IDE_DISKS 1 +#define UNPLUG_ALL_DISKS 1 #define UNPLUG_ALL_NICS 2 #define UNPLUG_AUX_IDE_DISKS 4 @@ -110,14 +110,21 @@ static void pci_unplug_nics(PCIBus *bus) 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) { + if (!strcmp(d->name, "xen-pci-passthrough")) { + return; + } + + switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) { + case PCI_CLASS_STORAGE_IDE: pci_piix3_xen_ide_unplug(DEVICE(d)); - } else if (pci_get_word(d->config + PCI_CLASS_DEVICE) == - PCI_CLASS_STORAGE_SCSI - && strcmp(d->name, "xen-pci-passthrough") != 0) { + break; + + case PCI_CLASS_STORAGE_SCSI: object_unparent(OBJECT(d)); + break; + + default: + break; } } @@ -134,9 +141,9 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v 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 + unplug, with bit 0 the disk devices, bit 1 the network devices, and bit 2 the non-primary-master IDE devices. */ - if (val & UNPLUG_ALL_IDE_DISKS) { + if (val & UNPLUG_ALL_DISKS) { DPRINTF("unplug disks\n"); pci_unplug_disks(pci_dev->bus); }