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: 8326241 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A59DC9F38B for ; Tue, 16 Feb 2016 13:58:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AAC8620268 for ; Tue, 16 Feb 2016 13:58:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A98DE20263 for ; Tue, 16 Feb 2016 13:58:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVg7g-0005FX-Ta; Tue, 16 Feb 2016 13:57:00 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aVg5G-0002DH-F1 for linux-arm-kernel@lists.infradead.org; Tue, 16 Feb 2016 13:54:32 +0000 Received: by mail-wm0-x229.google.com with SMTP id b205so111065664wmb.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=dYiSfxys4i+gimnl/f58proUjK0bNNJt9dhZKdMRV4lf5f88Yd0qAzdEpt60xNEBDk AoRa/rmi5oGU+RImauMTaWgcoolDoh+17ldrxcrlqFUQbGht/ExwfFOFauS3+EJ42IRi W8fYYFtCv3PIvC1nu4ZgROUfaopGnqQTJeeRTw5ABISmVqbCNKjP+vvErQR9HYmHhs9+ pFzbvIATc5hC0QqAPeRytaGL9bCYGQcJJstM2/EHYzM8XXnquO+lny8q6XOt8lDU7vYZ 7+MDz0kAxVwrI0TNOZfUNgaJltvvpxxRW3SMMlMoxmTmOqHT/1o1V961IY2tHXSlJMQQ QTYw== X-Gm-Message-State: AG10YOTzlCDgVzNqSn6LyP1bNghpk7wdkRpdc1ufpz7u1vQqreHLK6NsJOIdMrBxm4PMmQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160216_055430_767237_EBF521F6 X-CRM114-Status: GOOD ( 14.20 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , jcm@redhat.com, linaro-acpi@lists.linaro.org, linux-pci@vger.kernel.org, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, robert.richter@caviumnetworks.com, Yinghai Lu , Suravee.Suthikulpanit@amd.com, msalter@redhat.com, wangyijing@huawei.com, mw@semihalf.com, Bjorn Helgaas , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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);