From patchwork Wed Aug 23 19:09:42 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: 13363058 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 84167C3DA6F for ; Wed, 23 Aug 2023 19:12:33 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=A4PG1tGllP8WhhKNVFWzdQ3xlvkLoMKNUC/N3IXMf7E=; b=38Y5TY6hSqdXUU uRmHB6JHRzOfDam3FEx63BYycYXFN2DscXCqe8Rl/ULJ8exC6gOCFZmHo2ZhP8bcbg1OBKnz89KwK nncRPWFW7+jkPCNcV5/zDrNhn4AZDozt4GnqoQTsAYIpCRBtkH1f60zctjrLuaR0QK7TegoSjXVik vC9nibEsaqycaqNpsZfTd92GsATVCj4tQ0Ni8pRSmLiVG8FxsjE8XCr9i6XJ/AbeyIi8wUz1TIOeP BPIu+nrSDTAUoUX2Wcl6rNmJ6I2Yco37N7SlCdIot08STwiL5IZSv7RDC1/CLcaE1jIcG9nEqL59H ZayvfmBLfnNNjr7kRdUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYtGv-001ODP-0B; Wed, 23 Aug 2023 19:12:05 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYtGq-001OCk-23 for linux-arm-kernel@lists.infradead.org; Wed, 23 Aug 2023 19:12:03 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CD70B64673; Wed, 23 Aug 2023 19:11:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BCA1C433C7; Wed, 23 Aug 2023 19:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692817919; bh=s4YOnmi9JvRPm07nshzPHn1qcbZ938a4sogEi3pqxiE=; h=From:List-Id:To:Cc:Subject:Date:From; b=C3uwE0IbDEGfWHsFRUbOovf5gJNgXIYDy4U+Vsp2Gh8xvsJqUiUskwc7k1yFsTZ2j j3a6PzKviaJRaS6N0g8kj/AmZQZ76kMXdBjBkaQagGz/5T+NHPc+JHzsvGWhq7bu9E R2p1uXYYi1YifzKrb3CB8vNKWlbziiTMHteDCobscDeNgar7sGRDlBB0OM8f4TU/RM 2v4i80QZyRUBWhJ25ThImnUb65Fn9cKgmrEQzLg/K32l7Y3xk/kcrZqTpH6YcCYozS BUeZmL6xfhmmO0ClI6mSCN8C00LMo2gaAmiEVqBywOMWEezC3JmPPDuuuo19dPRFdK hO8xr9zu4PK0w== Received: (nullmailer pid 2732794 invoked by uid 1000); Wed, 23 Aug 2023 19:11:57 -0000 From: Rob Herring To: soc@kernel.org, Stuart Yoder , Laurentiu Tudor Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] bus: fsl-mc: Use common ranges functions Date: Wed, 23 Aug 2023 14:09:42 -0500 Message-Id: <20230823190958.2717267-1-robh@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230823_121200_763522_721456DB X-CRM114-Status: GOOD ( 15.22 ) 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 Since commit 3d5089c4263d ("of/address: Add support for 3 address cell bus"), the DT address functions can handle translating buses with 3 address cells. Replace the custom code with the for_each_of_range() iterator. The original code had fallbacks to get "#address-cells"/"#size-cells" from the bus parent node if they are missing. This is non-standard behavior, and AFAICT the upstream .dts files never relied on that. Reviewed-by: Laurentiu Tudor Tested-by: Laurentiu Tudor Signed-off-by: Rob Herring --- v2: Add tags Arnd, Please apply this directly. drivers/bus/fsl-mc/fsl-mc-bus.c | 90 +++++---------------------------- 1 file changed, 13 insertions(+), 77 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 7c57e7d2ff55..2f6d5002e43d 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -995,75 +995,18 @@ struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev, } EXPORT_SYMBOL_GPL(fsl_mc_get_endpoint); -static int parse_mc_ranges(struct device *dev, - int *paddr_cells, - int *mc_addr_cells, - int *mc_size_cells, - const __be32 **ranges_start) -{ - const __be32 *prop; - int range_tuple_cell_count; - int ranges_len; - int tuple_len; - struct device_node *mc_node = dev->of_node; - - *ranges_start = of_get_property(mc_node, "ranges", &ranges_len); - if (!(*ranges_start) || !ranges_len) { - dev_warn(dev, - "missing or empty ranges property for device tree node '%pOFn'\n", - mc_node); - return 0; - } - - *paddr_cells = of_n_addr_cells(mc_node); - - prop = of_get_property(mc_node, "#address-cells", NULL); - if (prop) - *mc_addr_cells = be32_to_cpup(prop); - else - *mc_addr_cells = *paddr_cells; - - prop = of_get_property(mc_node, "#size-cells", NULL); - if (prop) - *mc_size_cells = be32_to_cpup(prop); - else - *mc_size_cells = of_n_size_cells(mc_node); - - range_tuple_cell_count = *paddr_cells + *mc_addr_cells + - *mc_size_cells; - - tuple_len = range_tuple_cell_count * sizeof(__be32); - if (ranges_len % tuple_len != 0) { - dev_err(dev, "malformed ranges property '%pOFn'\n", mc_node); - return -EINVAL; - } - - return ranges_len / tuple_len; -} - static int get_mc_addr_translation_ranges(struct device *dev, struct fsl_mc_addr_translation_range **ranges, u8 *num_ranges) { - int ret; - int paddr_cells; - int mc_addr_cells; - int mc_size_cells; - int i; - const __be32 *ranges_start; - const __be32 *cell; - - ret = parse_mc_ranges(dev, - &paddr_cells, - &mc_addr_cells, - &mc_size_cells, - &ranges_start); - if (ret < 0) - return ret; + struct fsl_mc_addr_translation_range *r; + struct of_range_parser parser; + struct of_range range; - *num_ranges = ret; - if (!ret) { + of_range_parser_init(&parser, dev->of_node); + *num_ranges = of_range_count(&parser); + if (!*num_ranges) { /* * Missing or empty ranges property ("ranges;") for the * 'fsl,qoriq-mc' node. In this case, identity mapping @@ -1079,20 +1022,13 @@ static int get_mc_addr_translation_ranges(struct device *dev, if (!(*ranges)) return -ENOMEM; - cell = ranges_start; - for (i = 0; i < *num_ranges; ++i) { - struct fsl_mc_addr_translation_range *range = &(*ranges)[i]; - - range->mc_region_type = of_read_number(cell, 1); - range->start_mc_offset = of_read_number(cell + 1, - mc_addr_cells - 1); - cell += mc_addr_cells; - range->start_phys_addr = of_read_number(cell, paddr_cells); - cell += paddr_cells; - range->end_mc_offset = range->start_mc_offset + - of_read_number(cell, mc_size_cells); - - cell += mc_size_cells; + r = *ranges; + for_each_of_range(&parser, &range) { + r->mc_region_type = range.flags; + r->start_mc_offset = range.bus_addr; + r->end_mc_offset = range.bus_addr + range.size; + r->start_phys_addr = range.cpu_addr; + r++; } return 0;