From patchwork Fri Mar 31 07:52:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 77607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp395770vqo; Fri, 31 Mar 2023 01:06:16 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/Nurd6nf0916pls3I5yBFmEFnFpPC5715IPtjNl9NSTwVPsH1AK5wldxMtbBczZyAGHCq X-Received: by 2002:a62:1948:0:b0:627:f740:51f9 with SMTP id 69-20020a621948000000b00627f74051f9mr9259809pfz.3.1680249975987; Fri, 31 Mar 2023 01:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680249975; cv=none; d=google.com; s=arc-20160816; b=MT3xVBbn/HIElHNhfa0Q+bWzC8kkHVqqIxGeOo3cmrHsylyIeIZvJpgBqAJBBpLRaQ KjdTLNKj9H4tVRjTov9LN/u+I1EltXqZ39RIx/BQ9hyS27PTARqvRudyTMU7HhI1f3Ob CRIA/EMvNlg1ItlYonDANLK8Z75Id7q0pGB207AwmSaH7IbP3guZSzDwx97N1/BmlYHl VYo4ATM9+iVIg0XAtOd3vhP8eHmiXXJ4jAfVtlaFBnzvAc31t8nskYD4hBeol7W4VnCt 0RVblZhIfDc5PgzEVs54Ph4J8Qp5bewUWVFkhHL4yAdUweYmKY20kItJwXdVCr/TQUrn uD5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yMdH41meGqShd3bY+plNTdYl8PLyrMSSJDM+RDgcY5Q=; b=ijXakk0KB3m+aU8yRdwrrUS8nQbOGFjzDpx18EF6WBifYWsHbMbg4nKNjoX4B4ETxS B2r+mZ7hJxIuG1dl6erB6BwhtpqODFgwwkgsa8FthT4Pk+L1Meq1YiVNCTVWfc9046b/ s1vgUJvOhmONQ8sV3+Sm940gA7VLbhxNCQkmggjqAsyNetr9kYjRCfwIHFAQMrgGEmrd EOY5GhW71IUiot24MiDG6Sszs7AJAwwHwxQ/OP5zStzJDrKsYuNvrkx8UFRDG34jZaR1 ddwNYytc3JxsmGzN6WV9A6JuvvM+KMTBrXleltU2eFeZwJX8BBxpRBWWPcEA/yfBS4G+ 8vaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a63-20020a639042000000b0050f8d6d85fcsi1856912pge.303.2023.03.31.01.06.03; Fri, 31 Mar 2023 01:06:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231189AbjCaHxl (ORCPT + 99 others); Fri, 31 Mar 2023 03:53:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbjCaHxM (ORCPT ); Fri, 31 Mar 2023 03:53:12 -0400 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 425A911176 for ; Fri, 31 Mar 2023 00:52:38 -0700 (PDT) Received: from ramsan.of.borg ([84.195.187.55]) by albert.telenet-ops.be with bizsmtp id evsc290071C8whw06vsc8b; Fri, 31 Mar 2023 09:52:36 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1pi9Y6-00FTC0-I1; Fri, 31 Mar 2023 09:52:36 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1pi9Yp-008Ra0-Qw; Fri, 31 Mar 2023 09:52:35 +0200 From: Geert Uytterhoeven To: Rob Herring , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/3] of: address: Document return value of of_address_to_resource() Date: Fri, 31 Mar 2023 09:52:28 +0200 Message-Id: <61ffcb5e87511dfa21af169efd04806101c48b8a.1680248888.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.4 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761869799164290605?= X-GMAIL-MSGID: =?utf-8?q?1761869799164290605?= Add the missing return value documentation to the linuxdoc comment block for the of_address_to_resource() function. Signed-off-by: Geert Uytterhoeven --- drivers/of/address.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index 4c5c3b7ab99449f2..6312b10885e85864 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -882,6 +882,8 @@ static int __of_address_to_resource(struct device_node *dev, int index, int bar_ * @index: Index into the array * @r: Pointer to resource array * + * Returns -EINVAL if the range cannot be converted to resource. + * * Note that if your address is a PIO address, the conversion will fail if * the physical address can't be internally converted to an IO token with * pci_address_to_pio(), that is because it's either called too early or it From patchwork Fri Mar 31 07:52:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 77595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp391861vqo; Fri, 31 Mar 2023 00:59:19 -0700 (PDT) X-Google-Smtp-Source: AKy350b7OuI2EVjO2QivSM1KvRw7jAzVNGO8Pyp/qeHs/S9Ui2ORu6YABcuCMNEMa4n5QdS5ZYG5 X-Received: by 2002:a17:903:1250:b0:1a2:55ca:6669 with SMTP id u16-20020a170903125000b001a255ca6669mr20599017plh.33.1680249559540; Fri, 31 Mar 2023 00:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680249559; cv=none; d=google.com; s=arc-20160816; b=yx4Vi292Rh6i+hYmFe0yKlz0Vlc185aKeAfj9ncYdt41bPnfVzp11qt6sBOgwpF0S4 ShG8nA7fFJ6Lnfv+b0erMb8/yLVle/3UflnhEkOEH/d0TBMWbddY8+aN/Jv4Fnkt4iNA 67KBdCHWILm9roJtcA0OIbMidSPHS0Q0TsUeztfI6RIHcbwZ/8PXaf8Cd8ZndyrqzRzn d8Pd6cE40V9bhXjQH7YfQLZGKgyEmHHAnl1ZwcG2zmbOtScDweIsaydIBIhMyQJoPv0N CljbxBkqmAB2GoNf2DDSuHqqNOzqssvWke0wJ8ce6+lAVlJEEX9FgBT6BheT42GX150z 26/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7Ypl2IraqAUOWXlyl64Q9kUg2qObElv6iAX1PlhDYW8=; b=RAJnKUucPw/cxSQwij0UdkywoJJ8JwMVSHh9qHrL4Y9jDNdzPmbddq5kJKRqepRh5C ngGFK4rbGY/I7bnm042+cIy3sjY7wzQnh/f4qGiDA/xXio1NeP5HG2jbl2dLRoq3gKzr 1g1bpRr8G2iHatwrieGO9pwAVctb9thj+iA9K3X2ATjLOBl4C78ZFyIiLrX4KbrZXTxf xfWRVkI+Hoal7nda8PwtKE+SFG/dSe9QgJ/B8HfYkuWMdQflwWG6rO4p3b/wgEUlhZcQ RRhG1YRUg/hANK3o4Xs2rz8qtaGMB0P8JMM7d9CHle4JQzeb4U1QZwYQzu3enZccU8Pz dwDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lf5-20020a170902fb4500b001992f451a28si1505933plb.384.2023.03.31.00.59.07; Fri, 31 Mar 2023 00:59:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbjCaHxo (ORCPT + 99 others); Fri, 31 Mar 2023 03:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbjCaHxM (ORCPT ); Fri, 31 Mar 2023 03:53:12 -0400 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4342A1B350 for ; Fri, 31 Mar 2023 00:52:38 -0700 (PDT) Received: from ramsan.of.borg ([84.195.187.55]) by albert.telenet-ops.be with bizsmtp id evsc290061C8whw06vsc8a; Fri, 31 Mar 2023 09:52:36 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1pi9Y6-00FTC1-I1; Fri, 31 Mar 2023 09:52:36 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1pi9Yp-008Ra3-Sh; Fri, 31 Mar 2023 09:52:35 +0200 From: Geert Uytterhoeven To: Rob Herring , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/3] of: address: Fix documented return value of of_pci_range_to_resource() Date: Fri, 31 Mar 2023 09:52:29 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.4 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761869361858708901?= X-GMAIL-MSGID: =?utf-8?q?1761869361858708901?= of_pci_range_to_resource() returns a negative instead of a positive error code. Signed-off-by: Geert Uytterhoeven --- drivers/of/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 6312b10885e85864..bd965d104c83a1ac 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -216,7 +216,7 @@ EXPORT_SYMBOL_GPL(of_pci_address_to_resource); * @res: pointer to a valid resource that will be updated to * reflect the values contained in the range. * - * Returns EINVAL if the range cannot be converted to resource. + * Returns -EINVAL if the range cannot be converted to resource. * * Note that if the range is an IO range, the resource will be converted * using pci_address_to_pio() which can fail if it is called too early or From patchwork Fri Mar 31 07:52:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 77604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp395316vqo; Fri, 31 Mar 2023 01:05:25 -0700 (PDT) X-Google-Smtp-Source: AKy350Zi5XmhUfQhIf5DYI6iuEjQM0gHS4gs9twQpvurVzaEVKlU1lfpY+NOJtLjucyqUdV1tqON X-Received: by 2002:a62:8496:0:b0:627:f659:a771 with SMTP id k144-20020a628496000000b00627f659a771mr25930635pfd.12.1680249925022; Fri, 31 Mar 2023 01:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680249925; cv=none; d=google.com; s=arc-20160816; b=rcQA5oDFJB6n8KTPc5PTrp6HPpEB3Kkny1vw0Jse0GK9elwsNDKYM0NdBwaPhVkWoi C5EF7ebAcTZYfq9+P3beSKQtvGETaCTKXuvcQqSy/ud2irwYMRuWVoAwtdf72I1zKdCa PCpnEr3aY1w8A9rBHYQbFN7fxwoj9fU9fw7An7A5UkYyxsLuh278mRlyu3QJNZWPQXp8 ziOkL7yMKawSB7bTGHKms1K6cpXYttdzYS7oV6jp+VWh9s91x5QSdHCXdklOB4nfumZo UQLa9fMwAYNE9trDGB3RKjUqxmpAKCJLqcX4p6Fh68yr0KNmxbQlSFDY60T18/9M4j8z tFYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LuI3F16paXXw8E9wTjLyHAutoC8GagQYwnyWrGBkmVo=; b=Mgl+xr8byckx2ZIld8IGh9Mn/W2NA3486ZOvKlTaaDMnx7IxpgK4heYoDzpHvUo3hY yjVjfGPmwQtJH8uNq9ZH+FL7jzkU+j94oQiIhhCIZGzCR7Iz6VRtoSq1jPVd/4LZsyvL R/eEuzYHpOwiG3R0OlJx77d+OPMvy02pVbCiNyUsPgp8CU9KOQ5GQy/SZqNIGHuWPi35 yK488US1tF23lUhyE9e93G0jzYpycUtPBqXcBBZw5TGT+Ku4zNmIjKYs9+rXwQJg1UuZ csDkOwTDnDKJjSzQxWfkjhSDgF3MZBX+zLKhqKH47I3qZpoOV3tIDIPcnD+N3pHvNJZU tkkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h21-20020aa796d5000000b0062decde9849si127863pfq.137.2023.03.31.01.05.12; Fri, 31 Mar 2023 01:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbjCaHxq (ORCPT + 99 others); Fri, 31 Mar 2023 03:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbjCaHxN (ORCPT ); Fri, 31 Mar 2023 03:53:13 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42915191C1 for ; Fri, 31 Mar 2023 00:52:38 -0700 (PDT) Received: from ramsan.of.borg ([84.195.187.55]) by laurent.telenet-ops.be with bizsmtp id evsc290061C8whw01vsci5; Fri, 31 Mar 2023 09:52:36 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1pi9Y6-00FTC2-IG; Fri, 31 Mar 2023 09:52:36 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1pi9Yp-008Ra7-U0; Fri, 31 Mar 2023 09:52:35 +0200 From: Geert Uytterhoeven To: Rob Herring , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/3] of: address: Reshuffle to remove forward declarations Date: Fri, 31 Mar 2023 09:52:30 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.4 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_FILL_THIS_FORM_SHORT autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761869745172388031?= X-GMAIL-MSGID: =?utf-8?q?1761869745172388031?= Reshuffle the code to get rid of the forward declarations, which improves readability. Signed-off-by: Geert Uytterhoeven --- drivers/of/address.c | 271 +++++++++++++++++++++---------------------- 1 file changed, 133 insertions(+), 138 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index bd965d104c83a1ac..80b36dfdb69c24c8 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -24,11 +24,6 @@ #define OF_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS) #define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNT(na) && (ns) > 0) -static struct of_bus *of_match_bus(struct device_node *np); -static int __of_address_to_resource(struct device_node *dev, int index, - int bar_no, struct resource *r); -static bool of_mmio_is_nonposted(struct device_node *np); - /* Debug utility */ #ifdef DEBUG static void of_dump_addr(const char *s, const __be32 *addr, int na) @@ -198,17 +193,6 @@ static int of_bus_pci_translate(__be32 *addr, u64 offset, int na) } #endif /* CONFIG_PCI */ -int of_pci_address_to_resource(struct device_node *dev, int bar, - struct resource *r) -{ - - if (!IS_ENABLED(CONFIG_PCI)) - return -ENOSYS; - - return __of_address_to_resource(dev, -1, bar, r); -} -EXPORT_SYMBOL_GPL(of_pci_address_to_resource); - /* * of_pci_range_to_resource - Create a resource from an of_pci_range * @range: the PCI range that describes the resource @@ -837,128 +821,6 @@ static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr, return port; } -static int __of_address_to_resource(struct device_node *dev, int index, int bar_no, - struct resource *r) -{ - u64 taddr; - const __be32 *addrp; - u64 size; - unsigned int flags; - const char *name = NULL; - - addrp = __of_get_address(dev, index, bar_no, &size, &flags); - if (addrp == NULL) - return -EINVAL; - - /* Get optional "reg-names" property to add a name to a resource */ - if (index >= 0) - of_property_read_string_index(dev, "reg-names", index, &name); - - if (flags & IORESOURCE_MEM) - taddr = of_translate_address(dev, addrp); - else if (flags & IORESOURCE_IO) - taddr = of_translate_ioport(dev, addrp, size); - else - return -EINVAL; - - if (taddr == OF_BAD_ADDR) - return -EINVAL; - memset(r, 0, sizeof(struct resource)); - - if (of_mmio_is_nonposted(dev)) - flags |= IORESOURCE_MEM_NONPOSTED; - - r->start = taddr; - r->end = taddr + size - 1; - r->flags = flags; - r->name = name ? name : dev->full_name; - - return 0; -} - -/** - * of_address_to_resource - Translate device tree address and return as resource - * @dev: Caller's Device Node - * @index: Index into the array - * @r: Pointer to resource array - * - * Returns -EINVAL if the range cannot be converted to resource. - * - * Note that if your address is a PIO address, the conversion will fail if - * the physical address can't be internally converted to an IO token with - * pci_address_to_pio(), that is because it's either called too early or it - * can't be matched to any host bridge IO space - */ -int of_address_to_resource(struct device_node *dev, int index, - struct resource *r) -{ - return __of_address_to_resource(dev, index, -1, r); -} -EXPORT_SYMBOL_GPL(of_address_to_resource); - -/** - * of_iomap - Maps the memory mapped IO for a given device_node - * @np: the device whose io range will be mapped - * @index: index of the io range - * - * Returns a pointer to the mapped memory - */ -void __iomem *of_iomap(struct device_node *np, int index) -{ - struct resource res; - - if (of_address_to_resource(np, index, &res)) - return NULL; - - if (res.flags & IORESOURCE_MEM_NONPOSTED) - return ioremap_np(res.start, resource_size(&res)); - else - return ioremap(res.start, resource_size(&res)); -} -EXPORT_SYMBOL(of_iomap); - -/* - * of_io_request_and_map - Requests a resource and maps the memory mapped IO - * for a given device_node - * @device: the device whose io range will be mapped - * @index: index of the io range - * @name: name "override" for the memory region request or NULL - * - * Returns a pointer to the requested and mapped memory or an ERR_PTR() encoded - * error code on failure. Usage example: - * - * base = of_io_request_and_map(node, 0, "foo"); - * if (IS_ERR(base)) - * return PTR_ERR(base); - */ -void __iomem *of_io_request_and_map(struct device_node *np, int index, - const char *name) -{ - struct resource res; - void __iomem *mem; - - if (of_address_to_resource(np, index, &res)) - return IOMEM_ERR_PTR(-EINVAL); - - if (!name) - name = res.name; - if (!request_mem_region(res.start, resource_size(&res), name)) - return IOMEM_ERR_PTR(-EBUSY); - - if (res.flags & IORESOURCE_MEM_NONPOSTED) - mem = ioremap_np(res.start, resource_size(&res)); - else - mem = ioremap(res.start, resource_size(&res)); - - if (!mem) { - release_mem_region(res.start, resource_size(&res)); - return IOMEM_ERR_PTR(-ENOMEM); - } - - return mem; -} -EXPORT_SYMBOL(of_io_request_and_map); - #ifdef CONFIG_HAS_DMA /** * of_dma_get_range - Get DMA range info and put it into a map array @@ -1155,3 +1017,136 @@ static bool of_mmio_is_nonposted(struct device_node *np) of_node_put(parent); return nonposted; } + +static int __of_address_to_resource(struct device_node *dev, int index, int bar_no, + struct resource *r) +{ + u64 taddr; + const __be32 *addrp; + u64 size; + unsigned int flags; + const char *name = NULL; + + addrp = __of_get_address(dev, index, bar_no, &size, &flags); + if (addrp == NULL) + return -EINVAL; + + /* Get optional "reg-names" property to add a name to a resource */ + if (index >= 0) + of_property_read_string_index(dev, "reg-names", index, &name); + + if (flags & IORESOURCE_MEM) + taddr = of_translate_address(dev, addrp); + else if (flags & IORESOURCE_IO) + taddr = of_translate_ioport(dev, addrp, size); + else + return -EINVAL; + + if (taddr == OF_BAD_ADDR) + return -EINVAL; + memset(r, 0, sizeof(struct resource)); + + if (of_mmio_is_nonposted(dev)) + flags |= IORESOURCE_MEM_NONPOSTED; + + r->start = taddr; + r->end = taddr + size - 1; + r->flags = flags; + r->name = name ? name : dev->full_name; + + return 0; +} + +/** + * of_address_to_resource - Translate device tree address and return as resource + * @dev: Caller's Device Node + * @index: Index into the array + * @r: Pointer to resource array + * + * Returns -EINVAL if the range cannot be converted to resource. + * + * Note that if your address is a PIO address, the conversion will fail if + * the physical address can't be internally converted to an IO token with + * pci_address_to_pio(), that is because it's either called too early or it + * can't be matched to any host bridge IO space + */ +int of_address_to_resource(struct device_node *dev, int index, + struct resource *r) +{ + return __of_address_to_resource(dev, index, -1, r); +} +EXPORT_SYMBOL_GPL(of_address_to_resource); + +int of_pci_address_to_resource(struct device_node *dev, int bar, + struct resource *r) +{ + + if (!IS_ENABLED(CONFIG_PCI)) + return -ENOSYS; + + return __of_address_to_resource(dev, -1, bar, r); +} +EXPORT_SYMBOL_GPL(of_pci_address_to_resource); + +/** + * of_iomap - Maps the memory mapped IO for a given device_node + * @np: the device whose io range will be mapped + * @index: index of the io range + * + * Returns a pointer to the mapped memory + */ +void __iomem *of_iomap(struct device_node *np, int index) +{ + struct resource res; + + if (of_address_to_resource(np, index, &res)) + return NULL; + + if (res.flags & IORESOURCE_MEM_NONPOSTED) + return ioremap_np(res.start, resource_size(&res)); + else + return ioremap(res.start, resource_size(&res)); +} +EXPORT_SYMBOL(of_iomap); + +/* + * of_io_request_and_map - Requests a resource and maps the memory mapped IO + * for a given device_node + * @device: the device whose io range will be mapped + * @index: index of the io range + * @name: name "override" for the memory region request or NULL + * + * Returns a pointer to the requested and mapped memory or an ERR_PTR() encoded + * error code on failure. Usage example: + * + * base = of_io_request_and_map(node, 0, "foo"); + * if (IS_ERR(base)) + * return PTR_ERR(base); + */ +void __iomem *of_io_request_and_map(struct device_node *np, int index, + const char *name) +{ + struct resource res; + void __iomem *mem; + + if (of_address_to_resource(np, index, &res)) + return IOMEM_ERR_PTR(-EINVAL); + + if (!name) + name = res.name; + if (!request_mem_region(res.start, resource_size(&res), name)) + return IOMEM_ERR_PTR(-EBUSY); + + if (res.flags & IORESOURCE_MEM_NONPOSTED) + mem = ioremap_np(res.start, resource_size(&res)); + else + mem = ioremap(res.start, resource_size(&res)); + + if (!mem) { + release_mem_region(res.start, resource_size(&res)); + return IOMEM_ERR_PTR(-ENOMEM); + } + + return mem; +} +EXPORT_SYMBOL(of_io_request_and_map);