Received: by 10.192.165.148 with SMTP id m20csp3413702imm; Sun, 29 Apr 2018 22:51:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpFLBlP/mPP8Q2VX9F8j6XQ08ToONG1hAKNWINFaq/4eBCB4oY2Suv+Bhaj+K1HNIBTYhPk X-Received: by 2002:a17:902:7d8b:: with SMTP id a11-v6mr11283550plm.291.1525067489891; Sun, 29 Apr 2018 22:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525067489; cv=none; d=google.com; s=arc-20160816; b=kMn6h7Z93ttDKPIrLjPqOS8/Bz/+7CySJ/kcTjZF8/AVY2EEg2MYzvb7ycnjLl3Vej nzBet6JF24CN5vXVvPVQS4AYDucXStIJbANOJKa0Z29N9o9JBmphbtffndG9wm0Ovcqp t8k7lgongaPpLEZWOU85Xxne//8CAT4WSW2ZLQDtsJ/E3miT8G2KoJx1zm32AliAFlFv IHqJFNJF78iTvnvVOAvcPYkh3RcFpZ8tawayDTe4if6pr8UtBhsvdDNJe4ma3XLTvBEf nimjfyQUMLPGXVgCgQrPcyRDLAtwl4h3y0CG6iBLKJYmJP7vctIh15FL3FEgrfevBuMz TMew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from :arc-authentication-results; bh=k3OMr2QfuHMbabntJULzYRR3dmt3TOFjK3HLZkJCC6s=; b=ZzzWKhG0bB0gVGrmRb5SS8K2NM1yRJolnaYozWAkG0drqFnMeNhgyRI/dTGbuVjeC0 OubtYYs63/lO3DsX9wM7ljTF77OvisSYyPrztuTQzcwWTJMj/jLBA2m3tTO573RYc3W2 WBckOjYzsuUsUwU6QJAE6GZliw3q+z3zAV06vnJHPVWDTJy5vWTqF6+Z57p/KM4pv75N K33DD917KH7l/NGLGHwtNXGYJ/Cxm7kSLv1VtZ+fKT3DN45dBCztvRxozdFMBi1vt6nF chIe0rCPRBDhKNcc9sHs2flGXNBm37JRHRi7GRvKxtoztrpq2c4S8wGKItDjfY9LLgiA DJwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o30-v6si6979134pli.64.2018.04.29.22.51.16; Sun, 29 Apr 2018 22:51:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752269AbeD3Fu3 (ORCPT + 99 others); Mon, 30 Apr 2018 01:50:29 -0400 Received: from david.siemens.de ([192.35.17.14]:41496 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751778AbeD3FtQ (ORCPT ); Mon, 30 Apr 2018 01:49:16 -0400 Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w3U5mmLU013618 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Apr 2018 07:48:48 +0200 Received: from md1f2u6c.ww002.siemens.net ([167.87.54.87]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id w3U5mj6w003250; Mon, 30 Apr 2018 07:48:47 +0200 From: Jan Kiszka To: Bjorn Helgaas , Linux Kernel Mailing List , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 06/10] PCI: Introduce devm_of_pci_get_host_bridge_resources() Date: Mon, 30 Apr 2018 07:48:40 +0200 Message-Id: <215a020abbafc599bda18463db6818fcb0d198c7.1525067324.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kiszka of_pci_get_host_bridge_resources() allocates the resource structures it fills dynamically, but none of its callers care to release them so far. Rather than requiring everyone to do this explicitly, introduce a managed version of that service. This differs API-wise only in taking a reference to the associated device, rather than to the device tree node. As of_pci_get_host_bridge_resources() is an exported interface, we cannot simply drop it at this point. After converting all in-tree users to the new API, we will phase out the unmanaged one. Signed-off-by: Jan Kiszka --- drivers/pci/of.c | 28 ++++++++++++++++++++++++++++ include/linux/of_pci.h | 10 ++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 8f6cbf13e18d..f16b343d3b85 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -378,6 +378,34 @@ int of_pci_get_host_bridge_resources(struct device_node *dev_node, bus_max, resources, io_base); } EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources); + +/** + * of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI host + * bridge resources from DT + * @dev: host bridge device + * @busno: bus number associated with the bridge root bus + * @bus_max: maximum number of buses for this bridge + * @resources: list where the range of resources will be added after DT parsing + * @io_base: pointer to a variable that will contain on return the physical + * address for the start of the I/O range. Can be NULL if the caller doesn't + * expect I/O ranges to be present in the device tree. + * + * This function will parse the "ranges" property of a PCI host bridge device + * node and setup the resource mapping based on its content. It is expected + * that the property conforms with the Power ePAPR document. + * + * It returns zero if the range parsing has been successful or a standard error + * value if it failed. + */ +int devm_of_pci_get_host_bridge_resources(struct device *dev, + unsigned char busno, unsigned char bus_max, + struct list_head *resources, resource_size_t *io_base) +{ + return __of_pci_get_host_bridge_resources(dev, dev->of_node, busno, + bus_max, resources, io_base); +} +EXPORT_SYMBOL_GPL(devm_of_pci_get_host_bridge_resources); + #endif /* CONFIG_OF_ADDRESS */ /** diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h index 74eec1943ad2..08b8f02426a5 100644 --- a/include/linux/of_pci.h +++ b/include/linux/of_pci.h @@ -74,6 +74,9 @@ of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin) int of_pci_get_host_bridge_resources(struct device_node *dev_node, unsigned char busno, unsigned char bus_max, struct list_head *resources, resource_size_t *io_base); +int devm_of_pci_get_host_bridge_resources(struct device *dev, + unsigned char busno, unsigned char bus_max, + struct list_head *resources, resource_size_t *io_base); #else static inline int of_pci_get_host_bridge_resources(struct device_node *dev_node, unsigned char busno, unsigned char bus_max, @@ -81,6 +84,13 @@ static inline int of_pci_get_host_bridge_resources(struct device_node *dev_node, { return -EINVAL; } + +static inline int devm_of_pci_get_host_bridge_resources(struct device *dev, + unsigned char busno, unsigned char bus_max, + struct list_head *resources, resource_size_t *io_base) +{ + return -EINVAL; +} #endif #endif -- 2.13.6