From patchwork Tue Feb 16 13:53:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 8325961 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 10A60C02AA for ; Tue, 16 Feb 2016 13:56:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1CC2D20263 for ; Tue, 16 Feb 2016 13:56:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2C5020268 for ; Tue, 16 Feb 2016 13:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932551AbcBPNzZ (ORCPT ); Tue, 16 Feb 2016 08:55:25 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36699 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932559AbcBPNyP (ORCPT ); Tue, 16 Feb 2016 08:54:15 -0500 Received: by mail-wm0-f50.google.com with SMTP id g62so108510602wme.1 for ; Tue, 16 Feb 2016 05:54:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rlJnsSTNsgYGWt8et2kPwDs2Xu+OBkP7fQRbDBPDkxs=; b=AAuJ3Z4Mxzind3Z6e/iw6WPAzgUl5vyddHIGHhZIIYlO5onEQbTI5Bi12CSO73fhD2 hQPErOLN/OUklQSpJ1MfZuggkmaPT59S0T2NZ2xHGPQH1wbVJ/i5R8/3bB7yGbqEwVPz VZFHJjrfy6ENbfUekvjesKk6gLyU5gbd1SMJWs+1Iv8WfrHCA8z4WhAyVU+YNDikBEos x9/lOJ09lfufXQ5g28jnxFpprDSkVPANArbk0zCNY7zps7ySvdepquOIXzUIJTEYWTSC Bl1OmFjWqW9vE+45mOo999566XboZ35uK8j+lAd8BUL3OAIUuA52g1Ep5TFkn6foitke 66TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rlJnsSTNsgYGWt8et2kPwDs2Xu+OBkP7fQRbDBPDkxs=; b=DolRa/7OlZB+nv5igtheQYwWFYIBcoJK+o/vCzpiztGINsorH1y+SbBjTQJaEylGQS SCx9v5j/zUHLckIPv4mYDsuxazaHtKbLX2aqwRuQbDqTsR6fVYhjwkw59ZaSf0iKBRH7 0yl/yFnFlqvlvToUA+9ctGPPm/zQ2LIU9pWK6zcakD6HRZ4yxRmXp6E2Yi3b+M3dKSyc EmyffengnmO+sJrE8AczWz3f9oYnxllGKMAzGZR5zbi/Kcs64Yc3VsNbapq2anRp1ush k7gXVKYTb0/SA3qF7Z6jssHVEZKCiDNjWNguSmuNMlDQRFuYoeIoJa76EWBTllrG2MwH 5fdg== X-Gm-Message-State: AG10YOTm5xRShHHFlSi6kPI7dSNURxlptDYvo49dNnydI9znN8HB7KR4vNNFG02wclJhvg== X-Received: by 10.28.126.205 with SMTP id z196mr18265942wmc.44.1455630853778; Tue, 16 Feb 2016 05:54:13 -0800 (PST) Received: from tn-HP-4.semihalf.local ([80.82.22.190]) by smtp.gmail.com with ESMTPSA id q129sm20833462wmd.14.2016.02.16.05.54.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Feb 2016 05:54:12 -0800 (PST) From: Tomasz Nowicki To: helgaas@kernel.org, arnd@arndb.de, will.deacon@arm.com, catalin.marinas@arm.com, rafael@kernel.org, hanjun.guo@linaro.org, Lorenzo.Pieralisi@arm.com, okaya@codeaurora.org, jiang.liu@linux.intel.com, jchandra@broadcom.com, Stefano.Stabellini@eu.citrix.com Cc: robert.richter@caviumnetworks.com, mw@semihalf.com, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com, wangyijing@huawei.com, Suravee.Suthikulpanit@amd.com, msalter@redhat.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, jcm@redhat.com, Lorenzo Pieralisi , Bjorn Helgaas , Yinghai Lu Subject: [PATCH V5 11/15] drivers: pci: add generic code to claim bus resources Date: Tue, 16 Feb 2016 14:53:41 +0100 Message-Id: <1455630825-27253-12-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455630825-27253-1-git-send-email-tn@semihalf.com> References: <1455630825-27253-1-git-send-email-tn@semihalf.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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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: Lorenzo Pieralisi PCI core code contains a set of functions, eg: pci_assign_unassigned_bus_resources() that allow to assign the PCI resources for a given bus after enumeration. On systems where the PCI BARs are immutable (ie they must not and can not be assigned), PCI resources must be claimed in order to be validated and inserted in the PCI resources tree, but there is no generic PCI kernel function for that purpose and the resource claiming is implemented in an arch specific fashion which resulted in arches implementations that contain duplicated code. This patch, based on the ia64 resource claiming arch implementation, implements a set of functions in core PCI code that provides a PCI core interface for resources claiming for a given PCI bus hierarchy, paving the way for further resource claiming consolidation across architectures. Signed-off-by: Lorenzo Pieralisi Cc: Arnd Bergmann Cc: Bjorn Helgaas Cc: Yinghai Lu --- drivers/pci/setup-bus.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 64 insertions(+) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 7796d0a..c959398 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1424,6 +1424,69 @@ void pci_bus_assign_resources(const struct pci_bus *bus) } EXPORT_SYMBOL(pci_bus_assign_resources); +static void pci_claim_device_resources(struct pci_dev *dev) +{ + int i; + + for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) { + struct resource *r = &dev->resource[i]; + + if (!r->flags || r->parent) + continue; + + pci_claim_resource(dev, i); + } +} + +static void pci_claim_bridge_resources(struct pci_dev *dev) +{ + int i; + + for (i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) { + struct resource *r = &dev->resource[i]; + + if (!r->flags || r->parent) + continue; + + pci_claim_bridge_resource(dev, i); + } +} + +static void pci_bus_allocate_dev_resources(struct pci_bus *b) +{ + struct pci_dev *dev; + struct pci_bus *child; + + list_for_each_entry(dev, &b->devices, bus_list) { + pci_claim_device_resources(dev); + + child = dev->subordinate; + if (child) + pci_bus_allocate_dev_resources(child); + } +} + +static void pci_bus_allocate_resources(struct pci_bus *b) +{ + struct pci_bus *child; + + /* Depth-First Search on bus tree */ + if (b->self) { + pci_read_bridge_bases(b); + pci_claim_bridge_resources(b->self); + } + + list_for_each_entry(child, &b->children, node) + pci_bus_allocate_resources(child); +} + +void pci_bus_claim_resources(struct pci_bus *b) +{ + pci_bus_allocate_resources(b); + pci_bus_allocate_dev_resources(b); +} +EXPORT_SYMBOL(pci_bus_claim_resources); + static void __pci_bridge_assign_resources(const struct pci_dev *bridge, struct list_head *add_head, struct list_head *fail_head) diff --git a/include/linux/pci.h b/include/linux/pci.h index dac677c..6faf994 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1119,6 +1119,7 @@ ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */ resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx); void pci_bus_assign_resources(const struct pci_bus *bus); +void pci_bus_claim_resources(struct pci_bus *bus); void pci_bus_size_bridges(struct pci_bus *bus); int pci_claim_resource(struct pci_dev *, int); int pci_claim_bridge_resource(struct pci_dev *bridge, int i);