From patchwork Thu Feb 16 18:12:04 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: 13143607 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 9EB8DC61DA4 for ; Thu, 16 Feb 2023 18:13:31 +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=wsUinx18J3mUjlDQeyON/vvj9Y8UgB7CVaSSorFHpdU=; b=VZESFN3cTXMfur 3E30duDizSVKky+vSaYRQSUwx09DH3zTpp1N01omNRW32iaeKxIZVBwMpfB3crZyMZZDdRbfso5fn 4nGkkxh5mGn61VmqnWbQz9JO0VqnjfI5yaMKRS+Z0QXIrPZ7W5KCMcgKiSTltntZHidseBxDyEuTw z7IMmhJ9dgznI04CL8a98WLfboLRKPONECJbG16C7550zVls9RYcdZFojotAJi24qeB+3TugUJUPI lLLnVlkMYcCxKx0RPghrJKg3JwGKJCDcJaj7GALmwy9WZsg6oD1JeltZbfJeiIw+k4qYGpncr0b7V oJTzTsja057uiLauhlKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSikG-00BSCB-Fy; Thu, 16 Feb 2023 18:12:36 +0000 Received: from mail-oi1-f172.google.com ([209.85.167.172]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSikD-00BSB9-B2 for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2023 18:12:34 +0000 Received: by mail-oi1-f172.google.com with SMTP id bx13so2479174oib.13 for ; Thu, 16 Feb 2023 10:12:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AY71C+meiyBHhST24LKS8BIZ3aLMamU0OluZ9cJRz0Q=; b=vgYQzgDX4Ta3mlBesR9aDnL0/n7lKS6QEiQYJF5IbddNAs4RzZYQHt2CKS7uAsgfIJ zX26Kh8D+3ZN03TBuUygIXnBF4ASoNjKAPYsfkWt/McqJb2Yus4tZnUhwAOH9rbSf1VR MmyVWv9sxidwYfDH9skmxv8HeHpuWwh304FFVYoFq5ydHU1wIJ61QxgOCEBDDCFvL3um 6ncKbwgvhcGsTscxSjXe8/dxpBiXS9RjrNNmsSg1sqxIZ+Is826eopH/VAOtrpRLKFWk nW9Mms4/cAy4Thaim/PwkqeJ6ktebz1rYI0p7eDkbVjg8kJm0K+vlIEdgbq4XwfdPPXu LNdA== X-Gm-Message-State: AO0yUKUH0f0sngIqAeQk9rjpjYnb+cJ3tPr2j0fPYyRn3OHrmyYwJ6QJ j2HyL8RUF/P12O6y82ok3A== X-Google-Smtp-Source: AK7set/pbk6oZ0/SkxgTX5KHhHgxu5iymQgCl4ocNvHwABpkAaCU0q6GU9DfXqbnQVqUYbgXmiFHrQ== X-Received: by 2002:a05:6808:192:b0:378:6f44:2a2e with SMTP id w18-20020a056808019200b003786f442a2emr2751994oic.46.1676571149629; Thu, 16 Feb 2023 10:12:29 -0800 (PST) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id r124-20020acaf382000000b0035c073aa0d8sm821386oih.18.2023.02.16.10.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 10:12:29 -0800 (PST) Received: (nullmailer pid 2896124 invoked by uid 1000); Thu, 16 Feb 2023 18:12:28 -0000 From: Rob Herring To: Andrew Lunn , Gregory Clement Cc: linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth , linux-kernel@vger.kernel.org Subject: [PATCH] bus: mvebu-mbus: Remove open coded "ranges" parsing Date: Thu, 16 Feb 2023 12:12:04 -0600 Message-Id: <20230216181204.2895676-1-robh@kernel.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230216_101233_396361_5326003A X-CRM114-Status: GOOD ( 14.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 "ranges" is a standard property, and we have common helper functions for parsing it, so let's use them. Cc: Andrew Lunn Cc: Sebastian Hesselbarth Cc: Gregory Clement Signed-off-by: Rob Herring --- Compile tested only! --- drivers/bus/mvebu-mbus.c | 58 ++++++---------------------------------- 1 file changed, 8 insertions(+), 50 deletions(-) diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c index d51573ac525e..00cb792bda18 100644 --- a/drivers/bus/mvebu-mbus.c +++ b/drivers/bus/mvebu-mbus.c @@ -1179,74 +1179,32 @@ static int __init mbus_dt_setup_win(struct mvebu_mbus_state *mbus, return 0; } -static int __init -mbus_parse_ranges(struct device_node *node, - int *addr_cells, int *c_addr_cells, int *c_size_cells, - int *cell_count, const __be32 **ranges_start, - const __be32 **ranges_end) -{ - const __be32 *prop; - int ranges_len, tuple_len; - - /* Allow a node with no 'ranges' property */ - *ranges_start = of_get_property(node, "ranges", &ranges_len); - if (*ranges_start == NULL) { - *addr_cells = *c_addr_cells = *c_size_cells = *cell_count = 0; - *ranges_start = *ranges_end = NULL; - return 0; - } - *ranges_end = *ranges_start + ranges_len / sizeof(__be32); - - *addr_cells = of_n_addr_cells(node); - - prop = of_get_property(node, "#address-cells", NULL); - *c_addr_cells = be32_to_cpup(prop); - - prop = of_get_property(node, "#size-cells", NULL); - *c_size_cells = be32_to_cpup(prop); - - *cell_count = *addr_cells + *c_addr_cells + *c_size_cells; - tuple_len = (*cell_count) * sizeof(__be32); - - if (ranges_len % tuple_len) { - pr_warn("malformed ranges entry '%pOFn'\n", node); - return -EINVAL; - } - return 0; -} - static int __init mbus_dt_setup(struct mvebu_mbus_state *mbus, struct device_node *np) { - int addr_cells, c_addr_cells, c_size_cells; - int i, ret, cell_count; - const __be32 *r, *ranges_start, *ranges_end; + int ret; + struct of_range_parser parser; + struct of_range range; - ret = mbus_parse_ranges(np, &addr_cells, &c_addr_cells, - &c_size_cells, &cell_count, - &ranges_start, &ranges_end); + ret = of_range_parser_init(&parser, np); if (ret < 0) - return ret; + return 0; - for (i = 0, r = ranges_start; r < ranges_end; r += cell_count, i++) { - u32 windowid, base, size; + for_each_of_range(&parser, &range) { + u32 windowid = upper_32_bits(range.bus_addr); u8 target, attr; /* * An entry with a non-zero custom field do not * correspond to a static window, so skip it. */ - windowid = of_read_number(r, 1); if (CUSTOM(windowid)) continue; target = TARGET(windowid); attr = ATTR(windowid); - base = of_read_number(r + c_addr_cells, addr_cells); - size = of_read_number(r + c_addr_cells + addr_cells, - c_size_cells); - ret = mbus_dt_setup_win(mbus, base, size, target, attr); + ret = mbus_dt_setup_win(mbus, range.cpu_addr, range.size, target, attr); if (ret < 0) return ret; }