From patchwork Tue Mar 28 20:15:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 13191523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 017D4C77B6C for ; Tue, 28 Mar 2023 20:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3jPa3gYIj0xks39LR28NKdbijQT/g9+7lVWyM5vrNog=; b=YiqAJ1nvj+zmfA xxob2Ab7onqKPxEg4Y3d1mBoYUcGDdLO0xx9sCySxqyxPi+3mrez4MffoWUMAzf5vuu6ADyXo8hda S8JbvsCW6GmijGkLxG/c5YE8dWQejv/6YmMZdCuSr0CrsaTSrPwmEOhdtxpsxVG1gThg6dUGNfrEC lHW5XUwbi9FIua7kfK/d9DwPNfqlts0vX3utpPEKA/0m6cQd5le3hLItWvtgQE1UUsJ5x11YJichz ae3wF3JIVyjRLCiZrb+dLwv8CaQQKMem3YD0/cdjtk57Eq7G9VoK4K3kzyFcRncBS3/J5cgfwyIfp mMcFoLQ/L3G9hFzwxGOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phFk7-00Fl7t-13; Tue, 28 Mar 2023 20:16:31 +0000 Received: from mail-oi1-f175.google.com ([209.85.167.175]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phFju-00Fl27-2o for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2023 20:16:20 +0000 Received: by mail-oi1-f175.google.com with SMTP id r84so8656019oih.11 for ; Tue, 28 Mar 2023 13:16:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680034577; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VpsM8Gyt+E2oU3DAGA2Cy9raNlOEiWzk+fnJGTbZemI=; b=Fi8N94TG+5zf0Us5OCKV6O8JJ4Gb6Hp9gUlxCfAAEQmUtMvqmzFFEVqWsCm3zmr4gO ByOrkLOYzDxrX0SqAl5f3a7wZnHcukwKaKF9b0vA1bt3zNcOJxhpRSUSr+OOF8ZEk4lM CT/QC3OSrxke9x9JC1tmifpAgj2lwXPL+8RcYOmYqh+A2791IxKBiIJA+fukYzXZ+8yU CPDtR99RPnuEvpSMEOhHsooBtIJRWb29X1XYIgBzTXq7fk9qb2YeqhIb1RaMfKVQbOQb LQRg6e1O2jj3GKUfgLKYj6WUcpVUYjUKXL5SV6moIwInyTUkeVHx3GArZWEtak+zJ/cz O3KQ== X-Gm-Message-State: AO0yUKUpGlcpe0mh698G25+7KCfFUPX2hxqjDqjzFfVKJ61PepfoXySQ 0XyZkPFJ4OtQCuj/BWoKdQ== X-Google-Smtp-Source: AK7set9zxFcHUmej6FZI0b/r9kzi7HNM/sTT+QF7paaDfTXpKf0/Bz0qzrUkdUNA414JIRwtcEX/5g== X-Received: by 2002:a05:6808:de6:b0:387:1a46:8317 with SMTP id g38-20020a0568080de600b003871a468317mr7680846oic.13.1680034576781; Tue, 28 Mar 2023 13:16:16 -0700 (PDT) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id v7-20020a4aaec7000000b00529cc3986c8sm2696062oon.40.2023.03.28.13.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 13:16:16 -0700 (PDT) Received: (nullmailer pid 3993710 invoked by uid 1000); Tue, 28 Mar 2023 20:16:10 -0000 From: Rob Herring Date: Tue, 28 Mar 2023 15:15:56 -0500 Subject: [PATCH 1/5] of: unittest: Add bus address range parsing tests MIME-Version: 1.0 Message-Id: <20230328-dt-address-helpers-v1-1-e2456c3e77ab@kernel.org> References: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> In-Reply-To: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Stuart Yoder , Laurentiu Tudor , Benjamin Herrenschmidt Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org X-Mailer: b4 0.13-dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230328_131618_906275_F7D9E83C X-CRM114-Status: GOOD ( 16.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org While there are tests for "dma-ranges" helpers, "ranges" is missing any tests. It's the same underlying code, but for completeness add a test for "ranges" parsing iterators. This is in preparation to add some additional "ranges" helpers. Signed-off-by: Rob Herring --- drivers/of/unittest.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index b5a7a31d8bd2..1a45df1f354a 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1008,6 +1008,58 @@ static void __init of_unittest_pci_dma_ranges(void) of_node_put(np); } +static void __init of_unittest_bus_ranges(void) +{ + struct device_node *np; + struct of_range range; + struct of_range_parser parser; + int i = 0; + + np = of_find_node_by_path("/testcase-data/address-tests"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + if (of_range_parser_init(&parser, np)) { + pr_err("missing ranges property\n"); + return; + } + + /* + * Get the "ranges" from the device tree + */ + for_each_of_range(&parser, &range) { + unittest(range.flags == IORESOURCE_MEM, + "for_each_of_range wrong flags on node %pOF flags=%x (expected %x)\n", + np, range.flags, IORESOURCE_MEM); + if (!i) { + unittest(range.size == 0x40000000, + "for_each_of_range wrong size on node %pOF size=%llx\n", + np, range.size); + unittest(range.cpu_addr == 0x70000000, + "for_each_of_range wrong CPU addr (%llx) on node %pOF", + range.cpu_addr, np); + unittest(range.bus_addr == 0x70000000, + "for_each_of_range wrong bus addr (%llx) on node %pOF", + range.pci_addr, np); + } else { + unittest(range.size == 0x20000000, + "for_each_of_range wrong size on node %pOF size=%llx\n", + np, range.size); + unittest(range.cpu_addr == 0xd0000000, + "for_each_of_range wrong CPU addr (%llx) on node %pOF", + range.cpu_addr, np); + unittest(range.bus_addr == 0x00000000, + "for_each_of_range wrong bus addr (%llx) on node %pOF", + range.pci_addr, np); + } + i++; + } + + of_node_put(np); +} + static void __init of_unittest_parse_interrupts(void) { struct device_node *np; @@ -3644,6 +3696,7 @@ static int __init of_unittest(void) of_unittest_dma_get_max_cpu_address(); of_unittest_parse_dma_ranges(); of_unittest_pci_dma_ranges(); + of_unittest_bus_ranges(); of_unittest_match_node(); of_unittest_platform_populate(); of_unittest_overlay(); From patchwork Tue Mar 28 20:15:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 13191521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E5B7C77B60 for ; Tue, 28 Mar 2023 20:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dKOWCW3AXIwjIMP0S9XWGAEHTfb6UhYQPI26Gf7/Rho=; b=E0Wno3o9YAW0/I qDj+HAPA6mWB9+kISIymgDw9BV+4bLCrOqWHbuqoZE8IDZ/Kbgk944Eq8XpbtzsOizk4zryJYJpdm V9VjJlxSNLXJIW+W4jizwtw77R0xa+NhIVMjTg7iGfGkYIpEzF9RA8ZTWDvgsOihAVC5obw3T6dAf APP2KZQBvRDmJk6MFG70UheWosTXk8FBOUk0GOy30bbrZvwFA/hb3AVOuFqm+gOjGZn6UYlH4s+E6 6hLNUHKgm0qvIWh1yTFDeGV9Q3+IAO/bGFm7OtQL8T5HtDMygeAGaVV/L7ljol4boMXHmR+QNLlt2 2X3TT3tlX9P1CfPyTIjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phFk5-00Fl6Z-0j; Tue, 28 Mar 2023 20:16:29 +0000 Received: from mail-oa1-f48.google.com ([209.85.160.48]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phFjs-00Fl12-2a for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2023 20:16:18 +0000 Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-17aaa51a911so14014643fac.5 for ; Tue, 28 Mar 2023 13:16:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680034573; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WffwCkUrO2QFOwkwd1OwIoPn40+WgwuocFCo25EFRP4=; b=jKUbVtv2e1KFUdsK8llruNRK0FEew27NRweaiWJva336aVXzQNkUp52CqFIqYFISeV PJ6pX+KIUNPkN/AXrdFbVPI87HpEY3qSNrhOpR6yauMMlamfT0f3H68d8QmKP4USREn/ Qbj9hqT8tasTtIYT5wIk7ikqcjxR6mCfXrhMoTj81mEXADpXaVl6La4TD9P4qOFI2wLu 5Y3LGO5oO0Pe91fy0/ELKwXwuXpvD4FiHfeo/a3HFR69RUHJZOge5DRWmKz/0PfZkWDO komZzwTGiK1D7G6gk1gQjlsWDMJnK9YLw/WUkicBJw9BLePIOelFJu44UzNcgJ3cgKZw rMvw== X-Gm-Message-State: AAQBX9d68q9DL9lYQM5lSdvx+Lo6Hu7pFXm0Vxire0BijzBTy+ZUFiHW p234C5tW2GUnWcs/ktb2rQ== X-Google-Smtp-Source: AK7set9O95zUO5XPRjY3del1fKAHhbZzd1ayFyAZFIuT0LhS8F1687vY4wmshaSQMXVNhTAnL+nVzg== X-Received: by 2002:a05:6870:e40d:b0:169:dcba:1ec9 with SMTP id n13-20020a056870e40d00b00169dcba1ec9mr11894631oag.41.1680034573156; Tue, 28 Mar 2023 13:16:13 -0700 (PDT) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id m9-20020a9d6ac9000000b0069f153bb37asm8467384otq.62.2023.03.28.13.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 13:16:12 -0700 (PDT) Received: (nullmailer pid 3993719 invoked by uid 1000); Tue, 28 Mar 2023 20:16:10 -0000 From: Rob Herring Date: Tue, 28 Mar 2023 15:15:57 -0500 Subject: [PATCH 2/5] of/address: Add of_range_to_resource() helper MIME-Version: 1.0 Message-Id: <20230328-dt-address-helpers-v1-2-e2456c3e77ab@kernel.org> References: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> In-Reply-To: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Stuart Yoder , Laurentiu Tudor , Benjamin Herrenschmidt Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org X-Mailer: b4 0.13-dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230328_131616_833449_C7CAABEA X-CRM114-Status: GOOD ( 22.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A few users need to convert a specific "ranges" entry into a struct resource. Add a helper to similar to of_address_to_resource(). The existing of_pci_range_to_resource() helper isn't really PCI specific, so it can be used with the CONFIG_PCI check dropped. Signed-off-by: Rob Herring --- drivers/of/address.c | 31 ++++++++++++++++++++++++++++--- drivers/of/unittest.c | 16 +++++++++++++++- include/linux/of_address.h | 8 ++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 4c0b169ef9bf..b79f005834fc 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -229,9 +229,6 @@ int of_pci_range_to_resource(struct of_pci_range *range, res->parent = res->child = res->sibling = NULL; res->name = np->full_name; - if (!IS_ENABLED(CONFIG_PCI)) - return -ENOSYS; - if (res->flags & IORESOURCE_IO) { unsigned long port; err = pci_register_io_range(&np->fwnode, range->cpu_addr, @@ -263,6 +260,34 @@ int of_pci_range_to_resource(struct of_pci_range *range, } EXPORT_SYMBOL(of_pci_range_to_resource); +/* + * of_range_to_resource - Create a resource from a ranges entry + * @np: device node where the range belongs to + * @index: the 'ranges' index to convert to a resource + * @res: pointer to a valid resource that will be updated to + * reflect the values contained in the range. + * + * Returns ENOENT if the entry is not found or EINVAL if the range cannot be + * converted to resource. + */ +int of_range_to_resource(struct device_node *np, int index, struct resource *res) +{ + int ret, i = 0; + struct of_range_parser parser; + struct of_range range; + + ret = of_range_parser_init(&parser, np); + if (ret) + return ret; + + for_each_of_range(&parser, &range) + if (i++ == index) + return of_pci_range_to_resource(&range, np, res); + + return -ENOENT; +} +EXPORT_SYMBOL(of_range_to_resource); + /* * ISA bus specific translator */ diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1a45df1f354a..945288d5672f 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1013,7 +1013,8 @@ static void __init of_unittest_bus_ranges(void) struct device_node *np; struct of_range range; struct of_range_parser parser; - int i = 0; + struct resource res; + int ret, i = 0; np = of_find_node_by_path("/testcase-data/address-tests"); if (!np) { @@ -1026,6 +1027,19 @@ static void __init of_unittest_bus_ranges(void) return; } + ret = of_range_to_resource(np, 1, &res); + unittest(!ret, "of_range_to_resource returned error (%d) node %pOF\n", + ret, np); + unittest(resource_type(&res) == IORESOURCE_MEM, + "of_range_to_resource wrong resource type on node %pOF res=%pR\n", + np, &res); + unittest(res.start == 0xd0000000, + "of_range_to_resource wrong resource start address on node %pOF res=%pR\n", + np, &res); + unittest(resource_size(&res) == 0x20000000, + "of_range_to_resource wrong resource start address on node %pOF res=%pR\n", + np, &res); + /* * Get the "ranges" from the device tree */ diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 376671594746..1d005439f026 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -68,6 +68,8 @@ extern int of_pci_address_to_resource(struct device_node *dev, int bar, extern int of_pci_range_to_resource(struct of_pci_range *range, struct device_node *np, struct resource *res); +extern int of_range_to_resource(struct device_node *np, int index, + struct resource *res); extern bool of_dma_is_coherent(struct device_node *np); #else /* CONFIG_OF_ADDRESS */ static inline void __iomem *of_io_request_and_map(struct device_node *device, @@ -120,6 +122,12 @@ static inline int of_pci_range_to_resource(struct of_pci_range *range, return -ENOSYS; } +static inline int of_range_to_resource(struct device_node *np, int index, + struct resource *res) +{ + return -ENOSYS; +} + static inline bool of_dma_is_coherent(struct device_node *np) { return false; From patchwork Tue Mar 28 20:15:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 13191520 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8011C77B6D for ; Tue, 28 Mar 2023 20:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lPk0IpF6HqoXshNFKnqZ+IWzz07DdBk9Rfmb88gAOHA=; b=5GxmP/IXH4zoQ3 TtH8ZLfVbVb8AxhvlnnqOcQndQej+vI99lIPuNGD9sc4xkFIemBUibzpcUaHfz/DieqcWt+dFVEaV p4nwCTm2ihVUqzs2wt+bJPMjPL65Nl6szVnAvmRAtvfw3dYk9F4nu6JPbfoJxff2CFljyT8s25rKE Li9QnrBzFtXcP+V21rEqR5KhULimd7gRvI+/cRqRZ9lA66uv9NZRJn5M7xUX89SkvdVxZC0pq/Cak i7n9D74/pvcqysH6r5ZVolNko1ftBPnxe80+nTCKiit+zC9tRKt6KbUqqN/8DZfITb0GwWAbPFtf7 /QgTIf0ffxyqxqNhqinA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phFk6-00Fl7B-0l; Tue, 28 Mar 2023 20:16:30 +0000 Received: from mail-ot1-f47.google.com ([209.85.210.47]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phFjt-00Fl1Q-1q for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2023 20:16:19 +0000 Received: by mail-ot1-f47.google.com with SMTP id r17-20020a05683002f100b006a131458abfso4483343ote.2 for ; Tue, 28 Mar 2023 13:16:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680034575; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KPV83Ku05eVtYDdjByFRpdT6sBQBYt8mDRN3PCU3Qec=; b=EMfatHrsSQK1daNgH81Iazb2EvsZKF4BSEFNcSbrKBOIsM0hgoMPROY3h3PaOmSjSP kmg2ksYVEpVPMYrLIPR30Um5VHN+iWjU2X3rDXM+K2hFV47i4n+OtYlHZp7T7idDdxQ4 yONTK7yRxzqCsjUpsC04azchm+nr+v+UJjYp3rosquDGeQx2ZRCL6hrBB1as944qk34h CBlDsK5lWTzkR5YnuDmQJLxB3gi9QKq4VgB6V/50W7j8t9tD695k5wwqqYyiMQ9vddj+ yEx/HFMwiiE0NWFTjPdAQFYoUSNxVoZoP6wgX6g3KmYUz/apphzZf3nalNiBfqt5dlrm UepA== X-Gm-Message-State: AAQBX9fQ+6/5o5NjJm6vH7ih9ZmQB+11xuVtgTB5ClI8SRmSVrK/PPqL 0I7SQSfvPTcc8HU1M9X4Eg== X-Google-Smtp-Source: AKy350Yvh7h3jcQs0qnOEKMeNpdXqJbdelh/CYaGEedZYqt4AXoReTYyPgoYdksvfizCTRrhxzbqJg== X-Received: by 2002:a9d:6c93:0:b0:69f:b065:7716 with SMTP id c19-20020a9d6c93000000b0069fb0657716mr8330440otr.11.1680034575472; Tue, 28 Mar 2023 13:16:15 -0700 (PDT) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id d11-20020a05683018eb00b0069f1774cde8sm6583848otf.71.2023.03.28.13.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 13:16:15 -0700 (PDT) Received: (nullmailer pid 3993727 invoked by uid 1000); Tue, 28 Mar 2023 20:16:10 -0000 From: Rob Herring Date: Tue, 28 Mar 2023 15:15:58 -0500 Subject: [PATCH 3/5] of/address: Add support for 3 address cell bus MIME-Version: 1.0 Message-Id: <20230328-dt-address-helpers-v1-3-e2456c3e77ab@kernel.org> References: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> In-Reply-To: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Stuart Yoder , Laurentiu Tudor , Benjamin Herrenschmidt Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org X-Mailer: b4 0.13-dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230328_131617_609890_27C460CF X-CRM114-Status: GOOD ( 22.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There's a few custom bus bindings (e.g. fsl,qoriq-mc) which use a 3 cell format with custom flags in the high cell. We can match these buses as a fallback if we didn't match on PCI bus which is the only standard bus binding with 3 address cells. Signed-off-by: Rob Herring --- drivers/of/address.c | 22 +++++++++++ drivers/of/unittest-data/tests-address.dtsi | 9 ++++- drivers/of/unittest.c | 58 ++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index b79f005834fc..8cfae24148e0 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -95,11 +95,17 @@ static int of_bus_default_translate(__be32 *addr, u64 offset, int na) return 0; } +static unsigned int of_bus_default_flags_get_flags(const __be32 *addr) +{ + return of_read_number(addr, 1); +} + static unsigned int of_bus_default_get_flags(const __be32 *addr) { return IORESOURCE_MEM; } + #ifdef CONFIG_PCI static unsigned int of_bus_pci_get_flags(const __be32 *addr) { @@ -344,6 +350,11 @@ static unsigned int of_bus_isa_get_flags(const __be32 *addr) return flags; } +static int of_bus_default_flags_match(struct device_node *np) +{ + return of_bus_n_addr_cells(np) == 3; +} + /* * Array of bus specific translators */ @@ -373,6 +384,17 @@ static struct of_bus of_busses[] = { .has_flags = true, .get_flags = of_bus_isa_get_flags, }, + /* Default with flags cell */ + { + .name = "default-flags", + .addresses = "reg", + .match = of_bus_default_flags_match, + .count_cells = of_bus_default_count_cells, + .map = of_bus_default_map, + .translate = of_bus_default_translate, + .has_flags = true, + .get_flags = of_bus_default_flags_get_flags, + }, /* Default */ { .name = "default", diff --git a/drivers/of/unittest-data/tests-address.dtsi b/drivers/of/unittest-data/tests-address.dtsi index 6604a52bf6cb..bc0029cbf8ea 100644 --- a/drivers/of/unittest-data/tests-address.dtsi +++ b/drivers/of/unittest-data/tests-address.dtsi @@ -14,7 +14,7 @@ address-tests { #size-cells = <1>; /* ranges here is to make sure we don't use it for * dma-ranges translation */ - ranges = <0x70000000 0x70000000 0x40000000>, + ranges = <0x70000000 0x70000000 0x50000000>, <0x00000000 0xd0000000 0x20000000>; dma-ranges = <0x0 0x20000000 0x40000000>; @@ -43,6 +43,13 @@ pci@90000000 { <0x42000000 0x0 0xc0000000 0x20000000 0x0 0x10000000>; }; + bus@a0000000 { + #address-cells = <3>; + #size-cells = <2>; + ranges = <0xf00baa 0x0 0x0 0xa0000000 0x0 0x100000>, + <0xf00bee 0x1 0x0 0xb0000000 0x0 0x200000>; + }; + }; }; }; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 945288d5672f..29066ecbed47 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1048,7 +1048,7 @@ static void __init of_unittest_bus_ranges(void) "for_each_of_range wrong flags on node %pOF flags=%x (expected %x)\n", np, range.flags, IORESOURCE_MEM); if (!i) { - unittest(range.size == 0x40000000, + unittest(range.size == 0x50000000, "for_each_of_range wrong size on node %pOF size=%llx\n", np, range.size); unittest(range.cpu_addr == 0x70000000, @@ -1074,6 +1074,61 @@ static void __init of_unittest_bus_ranges(void) of_node_put(np); } +static void __init of_unittest_bus_3cell_ranges(void) +{ + struct device_node *np; + struct of_range range; + struct of_range_parser parser; + int i = 0; + + np = of_find_node_by_path("/testcase-data/address-tests/bus@a0000000"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + if (of_range_parser_init(&parser, np)) { + pr_err("missing ranges property\n"); + return; + } + + /* + * Get the "ranges" from the device tree + */ + for_each_of_range(&parser, &range) { + if (!i) { + unittest(range.flags == 0xf00baa, + "for_each_of_range wrong flags on node %pOF flags=%x\n", + np, range.flags); + unittest(range.size == 0x100000, + "for_each_of_range wrong size on node %pOF size=%llx\n", + np, range.size); + unittest(range.cpu_addr == 0xa0000000, + "for_each_of_range wrong CPU addr (%llx) on node %pOF", + range.cpu_addr, np); + unittest(range.bus_addr == 0x0, + "for_each_of_range wrong bus addr (%llx) on node %pOF", + range.pci_addr, np); + } else { + unittest(range.flags == 0xf00bee, + "for_each_of_range wrong flags on node %pOF flags=%x\n", + np, range.flags); + unittest(range.size == 0x200000, + "for_each_of_range wrong size on node %pOF size=%llx\n", + np, range.size); + unittest(range.cpu_addr == 0xb0000000, + "for_each_of_range wrong CPU addr (%llx) on node %pOF", + range.cpu_addr, np); + unittest(range.bus_addr == 0x100000000, + "for_each_of_range wrong bus addr (%llx) on node %pOF", + range.pci_addr, np); + } + i++; + } + + of_node_put(np); +} + static void __init of_unittest_parse_interrupts(void) { struct device_node *np; @@ -3711,6 +3766,7 @@ static int __init of_unittest(void) of_unittest_parse_dma_ranges(); of_unittest_pci_dma_ranges(); of_unittest_bus_ranges(); + of_unittest_bus_3cell_ranges(); of_unittest_match_node(); of_unittest_platform_populate(); of_unittest_overlay(); From patchwork Tue Mar 28 20:15:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 13191519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2A28C76196 for ; Tue, 28 Mar 2023 20:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gMbSHuhph+cMdnK/qNwWaMVv56FbKML1ttcsZAri1Z8=; b=CXAx2O7UqNEEZ4 kkE2elpgw/rknvDiECIRfbez57lKoErHjZUyy/JhfcVU7gByeIWwYC32hj8/zwgnvZwTUlCV0v4ed 8A1HCXZ+cmb9THBhH9hHZd0CR44tp68WBT57UWstVshcGfhIu0DQKlGHFsEHm9cL5TplErvbQaSI0 oYr2bLt8MHO85tIItQONcU8k6dPjm6k25KfhHOeYykrr3SwLDhwCZLz3JvMNo+a0VJhIhWUil0Pp4 O4q48DLVh0tCpl7l+Mw9cbb6fM2t6RvY+4JCw/F6ws5HuEUXKpj4aVjq91gNS7YClq1wk2HkxhzFX Lpygw1Qg2R1IeyK+Vt5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phFk4-00Fl6A-0g; Tue, 28 Mar 2023 20:16:28 +0000 Received: from mail-oo1-f53.google.com ([209.85.161.53]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phFjs-00Fl18-1h for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2023 20:16:17 +0000 Received: by mail-oo1-f53.google.com with SMTP id g21-20020a4ad855000000b0053e563c2f72so886451oov.6 for ; Tue, 28 Mar 2023 13:16:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680034574; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wq9MleJbVtyTb3QrV3Xlq0I3I3gqQWPoavFTMvWxBWU=; b=lnJitPzVf3NgW7K6xDMVMPxbT+Yn1WklDFWbi62D/OEyPzCRlX6/fKkntEEvPcSc8p 90JuhvVLAaZ+X+5d+3NnyaZvaTzHTzC0CGfJwVkvc3TwEyzfzRyOEujbCWXAzgWqkTqT oe0IaRCpUITikBnwlgsXTQLWyKXHCOKTWWJGWGwNyDHnd85TWs8ggiuCHDb2XFURl1Yn eHbsxjXbEkV/5g9v53nRwD6F4ljMFKHj6AXWbieqwv6f+jEflzWx7HaPHo7iZ2bXx9Ju jSDhE46cEjKPgP8DjVJtFKlRKfg23Vz0EqcvYSsjZAwiJVnkjE4aOpN2PAjmfm6mRkC7 Q5Uw== X-Gm-Message-State: AO0yUKXcG8Pe20H3jXRaXzZyDq+Yw8ugSbztLfUTV8EbMXfAEF8XjgD+ ZUKaOiGsE87e6chlZbHDTg== X-Google-Smtp-Source: AK7set9De6XnycHJIQgLEMSB8BvrDZtnx3/knyjsjlWaCorjvDtfznD+X/H4ZPT08mbWWvY4Eor3wg== X-Received: by 2002:a4a:4f83:0:b0:53b:4b94:45bf with SMTP id c125-20020a4a4f83000000b0053b4b9445bfmr8745156oob.3.1680034574395; Tue, 28 Mar 2023 13:16:14 -0700 (PDT) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id c192-20020a4a4fc9000000b0053b88b03e24sm7136185oob.18.2023.03.28.13.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 13:16:13 -0700 (PDT) Received: (nullmailer pid 3993734 invoked by uid 1000); Tue, 28 Mar 2023 20:16:10 -0000 From: Rob Herring Date: Tue, 28 Mar 2023 15:15:59 -0500 Subject: [PATCH 4/5] of/address: Add of_range_count() helper MIME-Version: 1.0 Message-Id: <20230328-dt-address-helpers-v1-4-e2456c3e77ab@kernel.org> References: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> In-Reply-To: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Stuart Yoder , Laurentiu Tudor , Benjamin Herrenschmidt Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org X-Mailer: b4 0.13-dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230328_131616_563386_53B5C550 X-CRM114-Status: GOOD ( 17.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some users need a count of the number of ranges entries before iterating over the entries. Typically this is for allocating some data structure based on the size. Add a helper, of_range_count(), to get the count. The helper must be called with an struct of_range_parser initialized by of_range_parser_init(). Signed-off-by: Rob Herring --- drivers/of/unittest.c | 7 ++++++- include/linux/of_address.h | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 29066ecbed47..eaeb58065acc 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1014,7 +1014,7 @@ static void __init of_unittest_bus_ranges(void) struct of_range range; struct of_range_parser parser; struct resource res; - int ret, i = 0; + int ret, count, i = 0; np = of_find_node_by_path("/testcase-data/address-tests"); if (!np) { @@ -1040,6 +1040,11 @@ static void __init of_unittest_bus_ranges(void) "of_range_to_resource wrong resource start address on node %pOF res=%pR\n", np, &res); + count = of_range_count(&parser); + unittest(count == 2, + "of_range_count wrong size on node %pOF count=%d\n", + np, count); + /* * Get the "ranges" from the device tree */ diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 1d005439f026..5292f62c1baa 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -35,6 +35,22 @@ struct of_pci_range { for (; of_pci_range_parser_one(parser, range);) #define for_each_of_range for_each_of_pci_range +/* + * of_range_count - Get the number of "ranges" or "dma-ranges" entries + * @parser: Parser state initialized by of_range_parser_init() + * + * Returns the number of entries or 0 if none. + * + * Note that calling this within or after the for_each_of_range() iterator will + * be inaccurate giving the number of entries remaining. + */ +static inline int of_range_count(const struct of_range_parser *parser) +{ + if (!parser || !parser->node || !parser->range || parser->range == parser->end) + return 0; + return (parser->end - parser->range) / (parser->na + parser->pna + parser->ns); +} + /* Translate a DMA address from device space to CPU space */ extern u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr); From patchwork Tue Mar 28 20:16:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 13191522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDC65C6FD18 for ; Tue, 28 Mar 2023 20:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1Zxy+q1yt0kB4nALQZdFupiiQttWliBfjUUaao3vTA4=; b=a1VlTg3IZbyxtZ FxfaqThHZi3Hki+lkjCbArrlVs/yXC1matxIRgk9+qxF/yZ51wplx1WFxItvoF2Nq3mBKPo6FyHKF gWagBe9cHdI3uq2umv8hTp56HUQQm98XoA8r0LGNFQYxycbAN/Vcf968SuM9G3uKuBmn6F3ZyFrgF x6Fqn9sGuTR2lLG+TgecJ5WFbOtnCo1dtzHwxV5OidTz4y56hgqJoMqyzh2RUHiFF4H5jCzKKxTTF 8xvyKORlblVASg42GlW+VXr+TyJmb+4WJUS6nAKyyLMsZe0jqwokZ9ZTVNqP3UaxMXy2ipA5hU62c jG7hjlT2KD6WTicUdTvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phFk8-00Fl8R-1M; Tue, 28 Mar 2023 20:16:32 +0000 Received: from mail-oa1-f52.google.com ([209.85.160.52]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phFjw-00Fl2n-0h for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2023 20:16:21 +0000 Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-17aeb49429eso14017707fac.6 for ; Tue, 28 Mar 2023 13:16:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680034578; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bCPFOdIpNQUFJhPrmeiDu2DdLbGsab44HmyQyVjGzEY=; b=vDSYKC2sw22QfNmGwq2R/qRSFf1uzSsXBtMQwCHEOReewhQXxY5LYnOZiO8rKQ7AxX E9PXQszRDk4vnu8wq8fDT9D0qKhZFnezpBcsg0zi5NuvccEIg6ce5v7sjJ/YIkN951RT xpMi7MZfwQFOzxJ4JZl2XXofF/CxFNIOHucfkHPoqZMTcpGIo5El/IghWOGJYJRYaHqB H1CA31QMUdZQgWvm19tCfEOiGlKIf8P53XtNQ+Ufu0Sw834KJhdVBYEdXT+EHP4fjGqn GaFUoTRtOotaZ8jcNZ4PPRZW7AP/Fn01k7MDja6BotRzJbATdxxaN8vmG39oocseWbxL c5iw== X-Gm-Message-State: AAQBX9d7UEeGYcow5hsd3TasGazS6iQFfZwUwxBSCAMKS5ns7gNgnGx1 bj/YoEMzTuA9uNR/KkyLbA== X-Google-Smtp-Source: AK7set/9uPgN0yCrXLJT35rq7Qat3QtTAkbocxc8t5r/+YdjprY4iCDY11yfxUH4UdUAQpsUjhc5qg== X-Received: by 2002:a05:6870:a454:b0:177:c8dc:501f with SMTP id n20-20020a056870a45400b00177c8dc501fmr12122129oal.29.1680034578097; Tue, 28 Mar 2023 13:16:18 -0700 (PDT) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id v23-20020a056870709700b0017280f7d653sm11129807oae.35.2023.03.28.13.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 13:16:17 -0700 (PDT) Received: (nullmailer pid 3993737 invoked by uid 1000); Tue, 28 Mar 2023 20:16:10 -0000 From: Rob Herring Date: Tue, 28 Mar 2023 15:16:00 -0500 Subject: [PATCH 5/5] of/address: Add of_property_read_reg() helper MIME-Version: 1.0 Message-Id: <20230328-dt-address-helpers-v1-5-e2456c3e77ab@kernel.org> References: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> In-Reply-To: <20230328-dt-address-helpers-v1-0-e2456c3e77ab@kernel.org> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Stuart Yoder , Laurentiu Tudor , Benjamin Herrenschmidt Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org X-Mailer: b4 0.13-dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230328_131620_254619_F5AEB810 X-CRM114-Status: GOOD ( 14.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a helper, of_property_read_reg(), to read "reg" entries untranslated address and size. This function is intended mainly for cases with an untranslatable "reg" address (i.e. not MMIO). There's also a few translatable cases such as address cells containing a bus chip-select number. Signed-off-by: Rob Herring --- drivers/of/address.c | 23 +++++++++++++++++++++++ drivers/of/unittest.c | 22 ++++++++++++++++++++++ include/linux/of_address.h | 7 +++++++ 3 files changed, 52 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index 8cfae24148e0..fdb15c6fb3b1 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -760,6 +760,29 @@ const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, } EXPORT_SYMBOL(__of_get_address); +/** + * of_property_read_reg - Retrieve the specified "reg" entry index without translating + * @np: device tree node for which to retrieve "reg" from + * @idx: "reg" entry index to read + * @addr: return value for the untranslated address + * @size: return value for the entry size + * + * Returns -EINVAL if "reg" is not found. Returns 0 on success with addr and + * size values filled in. + */ +int of_property_read_reg(struct device_node *np, int idx, u64 *addr, u64 *size) +{ + const __be32 *prop = of_get_address(np, idx, size, NULL); + + if (!prop) + return -EINVAL; + + *addr = of_read_number(prop, of_n_addr_cells(np)); + + return 0; +} +EXPORT_SYMBOL(of_property_read_reg); + static int parser_init(struct of_pci_range_parser *parser, struct device_node *node, const char *name) { diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index eaeb58065acc..e73ecbef977b 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1134,6 +1134,27 @@ static void __init of_unittest_bus_3cell_ranges(void) of_node_put(np); } +static void __init of_unittest_reg(void) +{ + struct device_node *np; + int ret; + u64 addr, size; + + np = of_find_node_by_path("/testcase-data/address-tests/bus@80000000/device@1000"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + ret = of_property_read_reg(np, 0, &addr, &size); + unittest(!ret, "of_property_read_reg(%pOF) returned error %d\n", + np, ret); + unittest(addr == 0x1000, "of_property_read_reg(%pOF) untranslated address (%llx) incorrect\n", + np, addr); + + of_node_put(np); +} + static void __init of_unittest_parse_interrupts(void) { struct device_node *np; @@ -3772,6 +3793,7 @@ static int __init of_unittest(void) of_unittest_pci_dma_ranges(); of_unittest_bus_ranges(); of_unittest_bus_3cell_ranges(); + of_unittest_reg(); of_unittest_match_node(); of_unittest_platform_populate(); of_unittest_overlay(); diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 5292f62c1baa..95cb6c5c2d67 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -72,6 +72,8 @@ void __iomem *of_io_request_and_map(struct device_node *device, extern const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, u64 *size, unsigned int *flags); +int of_property_read_reg(struct device_node *np, int idx, u64 *addr, u64 *size); + extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, struct device_node *node); extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, @@ -106,6 +108,11 @@ static inline const __be32 *__of_get_address(struct device_node *dev, int index, return NULL; } +static int of_property_read_reg(struct device_node *np, int idx, u64 *addr, u64 *size) +{ + return -ENOSYS; +} + static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser, struct device_node *node) {