From nobody Mon Feb 9 07:19:24 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC989C6FD18 for ; Wed, 29 Mar 2023 22:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbjC2WDv (ORCPT ); Wed, 29 Mar 2023 18:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjC2WDt (ORCPT ); Wed, 29 Mar 2023 18:03:49 -0400 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37C3DD3 for ; Wed, 29 Mar 2023 15:03:45 -0700 (PDT) Received: by mail-oo1-f52.google.com with SMTP id h22-20020a4ad756000000b0053e4ab58fb5so1639476oot.4 for ; Wed, 29 Mar 2023 15:03:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680127424; 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=wtsyC9FcfV0bm2gVotV6kQPHpkfxWRkbvh8nK94svJo=; b=F3Q5vP1J4MRJyOjD/yM07bQGvBbYxX5FVimmyggGZHOJ59JSjJaFYf/GmZ5ynaY9Js bHnPUWeRtH0Ev8ZjwhZodNtHAnpPe2GNVaiuH8TwkmEO8Gt65t3xnCGTQ2zGBYS8bRtu ttbxoNUfVFKQ5pE5NlyUk15YhWKcpmizX3IWpAeI/i+NhilGYRCHPvE7bvUs3lPYkR7e HTUhvCIlSSJ8yPsguOUY7NYeZnNQl5KRECXSrvYimGZ0oLAdJ6FIBN0Va6tpnj35vYtk a2A2KHBdTPnw9mLTuOWubPnR9yJO+/26OV1LgA6kwCgpT7NuxCLhAqrmbaQnXT7/COCh pjCw== X-Gm-Message-State: AO0yUKVJ4uJeYfSMtkqlhmLzNBEwCNQgT5LCQNr8vUyIXrKPPlDaW+iM 9vAx6UbMMMbNDqN+r0yyew== X-Google-Smtp-Source: AK7set/552RGtpF/a9tcqe/TrH6JVQQ0nht0d35SizWOLKjHpvzC4zVlYXxpfMJNHAGC+405kTChlg== X-Received: by 2002:a4a:4950:0:b0:51a:7a15:9758 with SMTP id z77-20020a4a4950000000b0051a7a159758mr10737941ooa.5.1680127424388; Wed, 29 Mar 2023 15:03:44 -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 y2-20020a4ad642000000b005264a1472adsm4189464oos.15.2023.03.29.15.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 15:03:43 -0700 (PDT) Received: (nullmailer pid 141516 invoked by uid 1000); Wed, 29 Mar 2023 22:03:42 -0000 From: Rob Herring To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Anatolij Gustschin , Arnd Bergmann , Benjamin Herrenschmidt Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] powerpc: Use of_address_to_resource() Date: Wed, 29 Mar 2023 17:03:36 -0500 Message-Id: <20230329220337.141295-1-robh@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace open coded reading of "reg" or of_get_address()/ of_translate_address() calls with a single call to of_address_to_resource(). Signed-off-by: Rob Herring --- v3: - Fix compile in ls_uart.c (sigh) v2: - Fix compile in tsi108_dev.c --- arch/powerpc/mm/numa.c | 21 +++------ arch/powerpc/platforms/52xx/lite5200_pm.c | 9 ++-- arch/powerpc/platforms/cell/axon_msi.c | 9 ++-- arch/powerpc/platforms/embedded6xx/holly.c | 7 ++- arch/powerpc/platforms/embedded6xx/ls_uart.c | 17 ++++--- arch/powerpc/platforms/powermac/feature.c | 16 +++---- .../platforms/pseries/hotplug-memory.c | 45 +++++-------------- arch/powerpc/platforms/pseries/iommu.c | 20 +++------ arch/powerpc/sysdev/tsi108_dev.c | 6 +-- 9 files changed, 51 insertions(+), 99 deletions(-) diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index b44ce71917d7..3a5c0d56b1ad 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1288,23 +1289,15 @@ static int hot_add_node_scn_to_nid(unsigned long sc= n_addr) int nid =3D NUMA_NO_NODE; =20 for_each_node_by_type(memory, "memory") { - unsigned long start, size; - int ranges; - const __be32 *memcell_buf; - unsigned int len; - - memcell_buf =3D of_get_property(memory, "reg", &len); - if (!memcell_buf || len <=3D 0) - continue; + int i =3D 0; =20 - /* ranges in cell */ - ranges =3D (len >> 2) / (n_mem_addr_cells + n_mem_size_cells); + while (1) { + struct resource res; =20 - while (ranges--) { - start =3D read_n_cells(n_mem_addr_cells, &memcell_buf); - size =3D read_n_cells(n_mem_size_cells, &memcell_buf); + if (of_address_to_resource(memory, i++, &res)) + break; =20 - if ((scn_addr < start) || (scn_addr >=3D (start + size))) + if ((scn_addr < res.start) || (scn_addr > res.end)) continue; =20 nid =3D of_node_to_nid_single(memory); diff --git a/arch/powerpc/platforms/52xx/lite5200_pm.c b/arch/powerpc/platf= orms/52xx/lite5200_pm.c index 129313b1d021..ee29b63fca16 100644 --- a/arch/powerpc/platforms/52xx/lite5200_pm.c +++ b/arch/powerpc/platforms/52xx/lite5200_pm.c @@ -54,8 +54,7 @@ static int lite5200_pm_prepare(void) { .type =3D "builtin", .compatible =3D "mpc5200", }, /* efika */ {} }; - u64 regaddr64 =3D 0; - const u32 *regaddr_p; + struct resource res; =20 /* deep sleep? let mpc52xx code handle that */ if (lite5200_pm_target_state =3D=3D PM_SUSPEND_STANDBY) @@ -66,12 +65,10 @@ static int lite5200_pm_prepare(void) =20 /* map registers */ np =3D of_find_matching_node(NULL, immr_ids); - regaddr_p =3D of_get_address(np, 0, NULL, NULL); - if (regaddr_p) - regaddr64 =3D of_translate_address(np, regaddr_p); + of_address_to_resource(np, 0, &res); of_node_put(np); =20 - mbar =3D ioremap((u32) regaddr64, 0xC000); + mbar =3D ioremap(res.start, 0xC000); if (!mbar) { printk(KERN_ERR "%s:%i Error mapping registers\n", __func__, __LINE__); return -ENOSYS; diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platform= s/cell/axon_msi.c index 0c11aad896c7..106000449d3b 100644 --- a/arch/powerpc/platforms/cell/axon_msi.c +++ b/arch/powerpc/platforms/cell/axon_msi.c @@ -460,15 +460,14 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_msic, msic_get, msic_set= , "%llu\n"); void axon_msi_debug_setup(struct device_node *dn, struct axon_msic *msic) { char name[8]; - u64 addr; + struct resource res; =20 - addr =3D of_translate_address(dn, of_get_property(dn, "reg", NULL)); - if (addr =3D=3D OF_BAD_ADDR) { - pr_devel("axon_msi: couldn't translate reg property\n"); + if (of_address_to_resource(dn, 0, &res)) { + pr_devel("axon_msi: couldn't get reg property\n"); return; } =20 - msic->trigger =3D ioremap(addr, 0x4); + msic->trigger =3D ioremap(res.start, 0x4); if (!msic->trigger) { pr_devel("axon_msi: ioremap failed\n"); return; diff --git a/arch/powerpc/platforms/embedded6xx/holly.c b/arch/powerpc/plat= forms/embedded6xx/holly.c index bebc5a972694..f7a17a6e2718 100644 --- a/arch/powerpc/platforms/embedded6xx/holly.c +++ b/arch/powerpc/platforms/embedded6xx/holly.c @@ -205,16 +205,15 @@ static void __noreturn holly_restart(char *cmd) __be32 __iomem *ocn_bar1 =3D NULL; unsigned long bar; struct device_node *bridge =3D NULL; - const void *prop; - int size; + struct resource res; phys_addr_t addr =3D 0xc0000000; =20 local_irq_disable(); =20 bridge =3D of_find_node_by_type(NULL, "tsi-bridge"); if (bridge) { - prop =3D of_get_property(bridge, "reg", &size); - addr =3D of_translate_address(bridge, prop); + of_address_to_resource(bridge, 0, &res); + addr =3D res.start; of_node_put(bridge); } addr +=3D (TSI108_PB_OFFSET + 0x414); diff --git a/arch/powerpc/platforms/embedded6xx/ls_uart.c b/arch/powerpc/pl= atforms/embedded6xx/ls_uart.c index 4ecbc55b37c0..6c1dbf8ae718 100644 --- a/arch/powerpc/platforms/embedded6xx/ls_uart.c +++ b/arch/powerpc/platforms/embedded6xx/ls_uart.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include =20 @@ -114,22 +115,24 @@ static void __init ls_uart_init(void) static int __init ls_uarts_init(void) { struct device_node *avr; - phys_addr_t phys_addr; - int len; + struct resource res; + int len, ret; =20 avr =3D of_find_node_by_path("/soc10x/serial@80004500"); if (!avr) return -EINVAL; =20 avr_clock =3D *(u32*)of_get_property(avr, "clock-frequency", &len); - phys_addr =3D ((u32*)of_get_property(avr, "reg", &len))[0]; + if (!avr_clock) + return -EINVAL; =20 - of_node_put(avr); + ret =3D of_address_to_resource(avr, 0, &res); + if (ret) + return ret; =20 - if (!avr_clock || !phys_addr) - return -EINVAL; + of_node_put(avr); =20 - avr_addr =3D ioremap(phys_addr, 32); + avr_addr =3D ioremap(res.start, 32); if (!avr_addr) return -EFAULT; =20 diff --git a/arch/powerpc/platforms/powermac/feature.c b/arch/powerpc/platf= orms/powermac/feature.c index dd508c2fcb5a..307548f20c1d 100644 --- a/arch/powerpc/platforms/powermac/feature.c +++ b/arch/powerpc/platforms/powermac/feature.c @@ -2545,8 +2545,7 @@ static int __init probe_motherboard(void) */ static void __init probe_uninorth(void) { - const u32 *addrp; - phys_addr_t address; + struct resource res; unsigned long actrl; =20 /* Locate core99 Uni-N */ @@ -2568,18 +2567,15 @@ static void __init probe_uninorth(void) return; } =20 - addrp =3D of_get_property(uninorth_node, "reg", NULL); - if (addrp =3D=3D NULL) + if (of_address_to_resource(uninorth_node, 0, &res)) return; - address =3D of_translate_address(uninorth_node, addrp); - if (address =3D=3D 0) - return; - uninorth_base =3D ioremap(address, 0x40000); + + uninorth_base =3D ioremap(res.start, 0x40000); if (uninorth_base =3D=3D NULL) return; uninorth_rev =3D in_be32(UN_REG(UNI_N_VERSION)); if (uninorth_maj =3D=3D 3 || uninorth_maj =3D=3D 4) { - u3_ht_base =3D ioremap(address + U3_HT_CONFIG_BASE, 0x1000); + u3_ht_base =3D ioremap(res.start + U3_HT_CONFIG_BASE, 0x1000); if (u3_ht_base =3D=3D NULL) { iounmap(uninorth_base); return; @@ -2589,7 +2585,7 @@ static void __init probe_uninorth(void) printk(KERN_INFO "Found %s memory controller & host bridge" " @ 0x%08x revision: 0x%02x\n", uninorth_maj =3D=3D 3 ? "U3" : uninorth_maj =3D=3D 4 ? "U4" : "UniNorth", - (unsigned int)address, uninorth_rev); + (unsigned int)res.start, uninorth_rev); printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base); =20 /* Set the arbitrer QAck delay according to what Apple does diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc= /platforms/pseries/hotplug-memory.c index 2e3a317722a8..9c62c2c3b3d0 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -311,11 +311,8 @@ static int pseries_remove_memblock(unsigned long base,= unsigned long memblock_si =20 static int pseries_remove_mem_node(struct device_node *np) { - const __be32 *prop; - unsigned long base; - unsigned long lmb_size; - int ret =3D -EINVAL; - int addr_cells, size_cells; + int ret; + struct resource res; =20 /* * Check to see if we are actually removing memory @@ -326,21 +323,11 @@ static int pseries_remove_mem_node(struct device_node= *np) /* * Find the base address and size of the memblock */ - prop =3D of_get_property(np, "reg", NULL); - if (!prop) + ret =3D of_address_to_resource(np, 0, &res); + if (ret) return ret; =20 - addr_cells =3D of_n_addr_cells(np); - size_cells =3D of_n_size_cells(np); - - /* - * "reg" property represents (addr,size) tuple. - */ - base =3D of_read_number(prop, addr_cells); - prop +=3D addr_cells; - lmb_size =3D of_read_number(prop, size_cells); - - pseries_remove_memblock(base, lmb_size); + pseries_remove_memblock(res.start, resource_size(&res)); return 0; } =20 @@ -929,11 +916,8 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog) =20 static int pseries_add_mem_node(struct device_node *np) { - const __be32 *prop; - unsigned long base; - unsigned long lmb_size; - int ret =3D -EINVAL; - int addr_cells, size_cells; + int ret; + struct resource res; =20 /* * Check to see if we are actually adding memory @@ -944,23 +928,14 @@ static int pseries_add_mem_node(struct device_node *n= p) /* * Find the base and size of the memblock */ - prop =3D of_get_property(np, "reg", NULL); - if (!prop) + ret =3D of_address_to_resource(np, 0, &res); + if (ret) return ret; =20 - addr_cells =3D of_n_addr_cells(np); - size_cells =3D of_n_size_cells(np); - /* - * "reg" property represents (addr,size) tuple. - */ - base =3D of_read_number(prop, addr_cells); - prop +=3D addr_cells; - lmb_size =3D of_read_number(prop, size_cells); - /* * Update memory region to represent the memory add */ - ret =3D memblock_add(base, lmb_size); + ret =3D memblock_add(res.start, resource_size(&res)); return (ret < 0) ? -EINVAL : 0; } =20 diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platform= s/pseries/iommu.c index c74b71d4733d..f94c78a7bddc 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1111,27 +1112,16 @@ static LIST_HEAD(failed_ddw_pdn_list); =20 static phys_addr_t ddw_memory_hotplug_max(void) { - phys_addr_t max_addr =3D memory_hotplug_max(); + resource_size_t max_addr =3D memory_hotplug_max(); struct device_node *memory; =20 for_each_node_by_type(memory, "memory") { - unsigned long start, size; - int n_mem_addr_cells, n_mem_size_cells, len; - const __be32 *memcell_buf; + struct resource res; =20 - memcell_buf =3D of_get_property(memory, "reg", &len); - if (!memcell_buf || len <=3D 0) + if (of_address_to_resource(memory, 0, &res)) continue; =20 - n_mem_addr_cells =3D of_n_addr_cells(memory); - n_mem_size_cells =3D of_n_size_cells(memory); - - start =3D of_read_number(memcell_buf, n_mem_addr_cells); - memcell_buf +=3D n_mem_addr_cells; - size =3D of_read_number(memcell_buf, n_mem_size_cells); - memcell_buf +=3D n_mem_size_cells; - - max_addr =3D max_t(phys_addr_t, max_addr, start + size); + max_addr =3D max_t(resource_size_t, max_addr, res.end + 1); } =20 return max_addr; diff --git a/arch/powerpc/sysdev/tsi108_dev.c b/arch/powerpc/sysdev/tsi108_= dev.c index 30051397292f..679bd5061201 100644 --- a/arch/powerpc/sysdev/tsi108_dev.c +++ b/arch/powerpc/sysdev/tsi108_dev.c @@ -45,9 +45,9 @@ phys_addr_t get_csrbase(void) =20 tsi =3D of_find_node_by_type(NULL, "tsi-bridge"); if (tsi) { - unsigned int size; - const void *prop =3D of_get_property(tsi, "reg", &size); - tsi108_csr_base =3D of_translate_address(tsi, prop); + struct resource res; + of_address_to_resource(tsi, 0, &res); + tsi108_csr_base =3D res.start; of_node_put(tsi); } return tsi108_csr_base; --=20 2.39.2