From patchwork Thu Jun 20 17:01:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2757361 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CB3829F39E for ; Thu, 20 Jun 2013 17:02:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85CBA20421 for ; Thu, 20 Jun 2013 17:02:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2825220413 for ; Thu, 20 Jun 2013 17:02:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965190Ab3FTRBo (ORCPT ); Thu, 20 Jun 2013 13:01:44 -0400 Received: from mail-pb0-f49.google.com ([209.85.160.49]:51085 "EHLO mail-pb0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030293Ab3FTRBl (ORCPT ); Thu, 20 Jun 2013 13:01:41 -0400 Received: by mail-pb0-f49.google.com with SMTP id jt11so6392435pbb.22 for ; Thu, 20 Jun 2013 10:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=yU0usUQ35ZUrW9F/DINCU9XxvW+BmLnkJZdLEtZislM=; b=eHBGuEwiXYwr225ls41jCCOMDp0juJeKoU+bjTN72C2YO+jSOEXpsfKTMTBln+dpnk s4EiLJTAKMhpkZ2r6OSxPhhyn265m4uHemHSyJkBvrScx4nf9Wx+ddVPN42/vcIydyhI OpcGXg61xEcZcxUUk9LkJIHIUTwnHIabNFZWBhWlQt7FPndjzyXAcBPEBD1yzB+eyHUe EUObeKtWe5SSY+xFwQ/vygS20dDPcI8pgnMxWbrwLHhw4Q4Jg/XaS22LJJNNOFdNLzX2 cNFr3WcvLZEh3eUt+1XTBrEGL209OyM01E7r+wOP50JMlZkDoUW8KTt+cDAqP3SXAY5C MBFg== X-Received: by 10.66.221.2 with SMTP id qa2mr12264525pac.188.1371747700979; Thu, 20 Jun 2013 10:01:40 -0700 (PDT) Received: from localhost.localdomain ([120.196.98.106]) by mx.google.com with ESMTPSA id vz8sm1512876pac.20.2013.06.20.10.01.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Jun 2013 10:01:40 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Konrad Rzeszutek Wilk , Jeremy Fitzhardinge Cc: liuj97@gmail.com, Jiang Liu , Yijing Wang , xen-devel@lists.xensource.com, virtualization@lists.linux-foundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] PCI, xen-pcifront: use new PCI interfaces to simplify implementation Date: Fri, 21 Jun 2013 01:01:04 +0800 Message-Id: <1371747665-12768-3-git-send-email-liuj97@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1371747665-12768-1-git-send-email-liuj97@gmail.com> References: <1371747665-12768-1-git-send-email-liuj97@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jiang Liu Use new PCI interfaces to simplify xen-pcifront implementation: 1) Use pci_create_root_bus() instead of pci_scan_bus_parented() because pci_scan_bus_parented() will be marked as __deprecated. This also gets rid of a duplicated call to pci_bus_start_devices(). 2) Use pci_stop_and_remove_root_bus() instead of open-coded private implementation. 3) Use pci_set_host_bridge_release() to release data structures associated with PCI root buses. Signed-off-by: Jiang Liu Cc: Konrad Rzeszutek Wilk Cc: Jeremy Fitzhardinge Cc: xen-devel@lists.xensource.com Cc: virtualization@lists.linux-foundation.org Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/xen-pcifront.c | 70 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index 966abc6..1b01960 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -25,11 +25,6 @@ #define INVALID_GRANT_REF (0) #define INVALID_EVTCHN (-1) -struct pci_bus_entry { - struct list_head list; - struct pci_bus *bus; -}; - #define _PDEVB_op_active (0) #define PDEVB_op_active (1 << (_PDEVB_op_active)) @@ -47,12 +42,12 @@ struct pcifront_device { struct xen_pci_sharedinfo *sh_info; struct work_struct op_work; unsigned long flags; - }; struct pcifront_sd { int domain; struct pcifront_device *pdev; + struct resource busn_res; }; static inline struct pcifront_device * @@ -67,6 +62,12 @@ static inline void pcifront_init_sd(struct pcifront_sd *sd, { sd->domain = domain; sd->pdev = pdev; + + /* Xen pci-backend doesn't export P2P bridges */ + sd->busn_res.start = bus; + sd->busn_res.end = bus; + sd->busn_res.flags = IORESOURCE_BUS; + sd->busn_res.name = "PCI busn"; } static DEFINE_SPINLOCK(pcifront_dev_lock); @@ -441,12 +442,19 @@ static int pcifront_scan_bus(struct pcifront_device *pdev, return 0; } +static void pcifront_release_sd(struct pci_host_bridge *bridge) +{ + struct pcifront_sd *sd = bridge->release_data; + + kfree(sd); +} + static int pcifront_scan_root(struct pcifront_device *pdev, unsigned int domain, unsigned int bus) { struct pci_bus *b; struct pcifront_sd *sd = NULL; - struct pci_bus_entry *bus_entry = NULL; + LIST_HEAD(resources); int err = 0; #ifndef CONFIG_PCI_DOMAINS @@ -463,16 +471,18 @@ static int pcifront_scan_root(struct pcifront_device *pdev, dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n", domain, bus); - bus_entry = kmalloc(sizeof(*bus_entry), GFP_KERNEL); - sd = kmalloc(sizeof(*sd), GFP_KERNEL); - if (!bus_entry || !sd) { + sd = kzalloc(sizeof(*sd), GFP_KERNEL); + if (!sd) { err = -ENOMEM; goto err_out; } pcifront_init_sd(sd, domain, bus, pdev); - b = pci_scan_bus_parented(&pdev->xdev->dev, bus, - &pcifront_bus_ops, sd); + pci_add_resource(&resources, &ioport_resource); + pci_add_resource(&resources, &iomem_resource); + pci_add_resource(&resources, &sd->busn_res); + b = pci_create_root_bus(&pdev->xdev->dev, bus, &pcifront_bus_ops, + sd, &resources); if (!b) { dev_err(&pdev->xdev->dev, "Error creating PCI Frontend Bus!\n"); @@ -480,9 +490,8 @@ static int pcifront_scan_root(struct pcifront_device *pdev, goto err_out; } - bus_entry->bus = b; - - list_add(&bus_entry->list, &pdev->root_buses); + pci_set_host_bridge_release(to_pci_host_bridge(b->bridge), + pcifront_release_sd, sd); /* pci_scan_bus_parented skips devices which do not have a have * devfn==0. The pcifront_scan_bus enumerates all devfn. */ @@ -497,7 +506,6 @@ static int pcifront_scan_root(struct pcifront_device *pdev, return err; err_out: - kfree(bus_entry); kfree(sd); return err; @@ -538,35 +546,17 @@ static int pcifront_rescan_root(struct pcifront_device *pdev, return err; } -static void free_root_bus_devs(struct pci_bus *bus) -{ - struct pci_dev *dev; - - while (!list_empty(&bus->devices)) { - dev = container_of(bus->devices.next, struct pci_dev, - bus_list); - dev_dbg(&dev->dev, "removing device\n"); - pci_stop_and_remove_bus_device(dev); - } -} - static void pcifront_free_roots(struct pcifront_device *pdev) { - struct pci_bus_entry *bus_entry, *t; + struct pcifront_sd *sd; + struct pci_bus *bus, *temp; dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n"); - list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) { - list_del(&bus_entry->list); - - free_root_bus_devs(bus_entry->bus); - - kfree(bus_entry->bus->sysdata); - - device_unregister(bus_entry->bus->bridge); - pci_remove_bus(bus_entry->bus); - - kfree(bus_entry); + list_for_each_entry_safe(bus, temp, &pci_root_buses, node) { + sd = bus->sysdata; + if (sd->pdev == pdev) + pci_stop_and_remove_root_bus(bus); } }