Commit 2500763d authored by Rob Herring's avatar Rob Herring Committed by Michael Ellerman

powerpc: Use of_address_to_resource()

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: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230329220337.141295-1-robh@kernel.org
parent 83a8fe56
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_address.h>
#include <linux/pfn.h> #include <linux/pfn.h>
#include <linux/cpuset.h> #include <linux/cpuset.h>
#include <linux/node.h> #include <linux/node.h>
...@@ -1288,23 +1289,15 @@ static int hot_add_node_scn_to_nid(unsigned long scn_addr) ...@@ -1288,23 +1289,15 @@ static int hot_add_node_scn_to_nid(unsigned long scn_addr)
int nid = NUMA_NO_NODE; int nid = NUMA_NO_NODE;
for_each_node_by_type(memory, "memory") { for_each_node_by_type(memory, "memory") {
unsigned long start, size; int i = 0;
int ranges;
const __be32 *memcell_buf;
unsigned int len;
memcell_buf = of_get_property(memory, "reg", &len);
if (!memcell_buf || len <= 0)
continue;
/* ranges in cell */ while (1) {
ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells); struct resource res;
while (ranges--) { if (of_address_to_resource(memory, i++, &res))
start = read_n_cells(n_mem_addr_cells, &memcell_buf); break;
size = read_n_cells(n_mem_size_cells, &memcell_buf);
if ((scn_addr < start) || (scn_addr >= (start + size))) if ((scn_addr < res.start) || (scn_addr > res.end))
continue; continue;
nid = of_node_to_nid_single(memory); nid = of_node_to_nid_single(memory);
......
...@@ -54,8 +54,7 @@ static int lite5200_pm_prepare(void) ...@@ -54,8 +54,7 @@ static int lite5200_pm_prepare(void)
{ .type = "builtin", .compatible = "mpc5200", }, /* efika */ { .type = "builtin", .compatible = "mpc5200", }, /* efika */
{} {}
}; };
u64 regaddr64 = 0; struct resource res;
const u32 *regaddr_p;
/* deep sleep? let mpc52xx code handle that */ /* deep sleep? let mpc52xx code handle that */
if (lite5200_pm_target_state == PM_SUSPEND_STANDBY) if (lite5200_pm_target_state == PM_SUSPEND_STANDBY)
...@@ -66,12 +65,10 @@ static int lite5200_pm_prepare(void) ...@@ -66,12 +65,10 @@ static int lite5200_pm_prepare(void)
/* map registers */ /* map registers */
np = of_find_matching_node(NULL, immr_ids); np = of_find_matching_node(NULL, immr_ids);
regaddr_p = of_get_address(np, 0, NULL, NULL); of_address_to_resource(np, 0, &res);
if (regaddr_p)
regaddr64 = of_translate_address(np, regaddr_p);
of_node_put(np); of_node_put(np);
mbar = ioremap((u32) regaddr64, 0xC000); mbar = ioremap(res.start, 0xC000);
if (!mbar) { if (!mbar) {
printk(KERN_ERR "%s:%i Error mapping registers\n", __func__, __LINE__); printk(KERN_ERR "%s:%i Error mapping registers\n", __func__, __LINE__);
return -ENOSYS; return -ENOSYS;
......
...@@ -460,15 +460,14 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_msic, msic_get, msic_set, "%llu\n"); ...@@ -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) void axon_msi_debug_setup(struct device_node *dn, struct axon_msic *msic)
{ {
char name[8]; char name[8];
u64 addr; struct resource res;
addr = of_translate_address(dn, of_get_property(dn, "reg", NULL)); if (of_address_to_resource(dn, 0, &res)) {
if (addr == OF_BAD_ADDR) { pr_devel("axon_msi: couldn't get reg property\n");
pr_devel("axon_msi: couldn't translate reg property\n");
return; return;
} }
msic->trigger = ioremap(addr, 0x4); msic->trigger = ioremap(res.start, 0x4);
if (!msic->trigger) { if (!msic->trigger) {
pr_devel("axon_msi: ioremap failed\n"); pr_devel("axon_msi: ioremap failed\n");
return; return;
......
...@@ -205,16 +205,15 @@ static void __noreturn holly_restart(char *cmd) ...@@ -205,16 +205,15 @@ static void __noreturn holly_restart(char *cmd)
__be32 __iomem *ocn_bar1 = NULL; __be32 __iomem *ocn_bar1 = NULL;
unsigned long bar; unsigned long bar;
struct device_node *bridge = NULL; struct device_node *bridge = NULL;
const void *prop; struct resource res;
int size;
phys_addr_t addr = 0xc0000000; phys_addr_t addr = 0xc0000000;
local_irq_disable(); local_irq_disable();
bridge = of_find_node_by_type(NULL, "tsi-bridge"); bridge = of_find_node_by_type(NULL, "tsi-bridge");
if (bridge) { if (bridge) {
prop = of_get_property(bridge, "reg", &size); of_address_to_resource(bridge, 0, &res);
addr = of_translate_address(bridge, prop); addr = res.start;
of_node_put(bridge); of_node_put(bridge);
} }
addr += (TSI108_PB_OFFSET + 0x414); addr += (TSI108_PB_OFFSET + 0x414);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/serial_reg.h> #include <linux/serial_reg.h>
#include <linux/serial_8250.h> #include <linux/serial_8250.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_address.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/termbits.h> #include <asm/termbits.h>
...@@ -114,22 +115,24 @@ static void __init ls_uart_init(void) ...@@ -114,22 +115,24 @@ static void __init ls_uart_init(void)
static int __init ls_uarts_init(void) static int __init ls_uarts_init(void)
{ {
struct device_node *avr; struct device_node *avr;
phys_addr_t phys_addr; struct resource res;
int len; int len, ret;
avr = of_find_node_by_path("/soc10x/serial@80004500"); avr = of_find_node_by_path("/soc10x/serial@80004500");
if (!avr) if (!avr)
return -EINVAL; return -EINVAL;
avr_clock = *(u32*)of_get_property(avr, "clock-frequency", &len); avr_clock = *(u32*)of_get_property(avr, "clock-frequency", &len);
phys_addr = ((u32*)of_get_property(avr, "reg", &len))[0]; if (!avr_clock)
return -EINVAL;
of_node_put(avr); ret = of_address_to_resource(avr, 0, &res);
if (ret)
return ret;
if (!avr_clock || !phys_addr) of_node_put(avr);
return -EINVAL;
avr_addr = ioremap(phys_addr, 32); avr_addr = ioremap(res.start, 32);
if (!avr_addr) if (!avr_addr)
return -EFAULT; return -EFAULT;
......
...@@ -2545,8 +2545,7 @@ static int __init probe_motherboard(void) ...@@ -2545,8 +2545,7 @@ static int __init probe_motherboard(void)
*/ */
static void __init probe_uninorth(void) static void __init probe_uninorth(void)
{ {
const u32 *addrp; struct resource res;
phys_addr_t address;
unsigned long actrl; unsigned long actrl;
/* Locate core99 Uni-N */ /* Locate core99 Uni-N */
...@@ -2568,18 +2567,15 @@ static void __init probe_uninorth(void) ...@@ -2568,18 +2567,15 @@ static void __init probe_uninorth(void)
return; return;
} }
addrp = of_get_property(uninorth_node, "reg", NULL); if (of_address_to_resource(uninorth_node, 0, &res))
if (addrp == NULL)
return; return;
address = of_translate_address(uninorth_node, addrp);
if (address == 0) uninorth_base = ioremap(res.start, 0x40000);
return;
uninorth_base = ioremap(address, 0x40000);
if (uninorth_base == NULL) if (uninorth_base == NULL)
return; return;
uninorth_rev = in_be32(UN_REG(UNI_N_VERSION)); uninorth_rev = in_be32(UN_REG(UNI_N_VERSION));
if (uninorth_maj == 3 || uninorth_maj == 4) { if (uninorth_maj == 3 || uninorth_maj == 4) {
u3_ht_base = ioremap(address + U3_HT_CONFIG_BASE, 0x1000); u3_ht_base = ioremap(res.start + U3_HT_CONFIG_BASE, 0x1000);
if (u3_ht_base == NULL) { if (u3_ht_base == NULL) {
iounmap(uninorth_base); iounmap(uninorth_base);
return; return;
...@@ -2589,7 +2585,7 @@ static void __init probe_uninorth(void) ...@@ -2589,7 +2585,7 @@ static void __init probe_uninorth(void)
printk(KERN_INFO "Found %s memory controller & host bridge" printk(KERN_INFO "Found %s memory controller & host bridge"
" @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" : " @ 0x%08x revision: 0x%02x\n", uninorth_maj == 3 ? "U3" :
uninorth_maj == 4 ? "U4" : "UniNorth", uninorth_maj == 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); printk(KERN_INFO "Mapped at 0x%08lx\n", (unsigned long)uninorth_base);
/* Set the arbitrer QAck delay according to what Apple does /* Set the arbitrer QAck delay according to what Apple does
......
...@@ -311,11 +311,8 @@ static int pseries_remove_memblock(unsigned long base, unsigned long memblock_si ...@@ -311,11 +311,8 @@ static int pseries_remove_memblock(unsigned long base, unsigned long memblock_si
static int pseries_remove_mem_node(struct device_node *np) static int pseries_remove_mem_node(struct device_node *np)
{ {
const __be32 *prop; int ret;
unsigned long base; struct resource res;
unsigned long lmb_size;
int ret = -EINVAL;
int addr_cells, size_cells;
/* /*
* Check to see if we are actually removing memory * Check to see if we are actually removing memory
...@@ -326,21 +323,11 @@ static int pseries_remove_mem_node(struct device_node *np) ...@@ -326,21 +323,11 @@ static int pseries_remove_mem_node(struct device_node *np)
/* /*
* Find the base address and size of the memblock * Find the base address and size of the memblock
*/ */
prop = of_get_property(np, "reg", NULL); ret = of_address_to_resource(np, 0, &res);
if (!prop) if (ret)
return ret; return ret;
addr_cells = of_n_addr_cells(np); pseries_remove_memblock(res.start, resource_size(&res));
size_cells = of_n_size_cells(np);
/*
* "reg" property represents (addr,size) tuple.
*/
base = of_read_number(prop, addr_cells);
prop += addr_cells;
lmb_size = of_read_number(prop, size_cells);
pseries_remove_memblock(base, lmb_size);
return 0; return 0;
} }
...@@ -929,11 +916,8 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog) ...@@ -929,11 +916,8 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog)
static int pseries_add_mem_node(struct device_node *np) static int pseries_add_mem_node(struct device_node *np)
{ {
const __be32 *prop; int ret;
unsigned long base; struct resource res;
unsigned long lmb_size;
int ret = -EINVAL;
int addr_cells, size_cells;
/* /*
* Check to see if we are actually adding memory * Check to see if we are actually adding memory
...@@ -944,23 +928,14 @@ static int pseries_add_mem_node(struct device_node *np) ...@@ -944,23 +928,14 @@ static int pseries_add_mem_node(struct device_node *np)
/* /*
* Find the base and size of the memblock * Find the base and size of the memblock
*/ */
prop = of_get_property(np, "reg", NULL); ret = of_address_to_resource(np, 0, &res);
if (!prop) if (ret)
return ret; return ret;
addr_cells = of_n_addr_cells(np);
size_cells = of_n_size_cells(np);
/*
* "reg" property represents (addr,size) tuple.
*/
base = of_read_number(prop, addr_cells);
prop += addr_cells;
lmb_size = of_read_number(prop, size_cells);
/* /*
* Update memory region to represent the memory add * Update memory region to represent the memory add
*/ */
ret = memblock_add(base, lmb_size); ret = memblock_add(res.start, resource_size(&res));
return (ret < 0) ? -EINVAL : 0; return (ret < 0) ? -EINVAL : 0;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/crash_dump.h> #include <linux/crash_dump.h>
#include <linux/memory.h> #include <linux/memory.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_address.h>
#include <linux/iommu.h> #include <linux/iommu.h>
#include <linux/rculist.h> #include <linux/rculist.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -1116,27 +1117,16 @@ static LIST_HEAD(failed_ddw_pdn_list); ...@@ -1116,27 +1117,16 @@ static LIST_HEAD(failed_ddw_pdn_list);
static phys_addr_t ddw_memory_hotplug_max(void) static phys_addr_t ddw_memory_hotplug_max(void)
{ {
phys_addr_t max_addr = memory_hotplug_max(); resource_size_t max_addr = memory_hotplug_max();
struct device_node *memory; struct device_node *memory;
for_each_node_by_type(memory, "memory") { for_each_node_by_type(memory, "memory") {
unsigned long start, size; struct resource res;
int n_mem_addr_cells, n_mem_size_cells, len;
const __be32 *memcell_buf;
memcell_buf = of_get_property(memory, "reg", &len); if (of_address_to_resource(memory, 0, &res))
if (!memcell_buf || len <= 0)
continue; continue;
n_mem_addr_cells = of_n_addr_cells(memory); max_addr = max_t(resource_size_t, max_addr, res.end + 1);
n_mem_size_cells = of_n_size_cells(memory);
start = of_read_number(memcell_buf, n_mem_addr_cells);
memcell_buf += n_mem_addr_cells;
size = of_read_number(memcell_buf, n_mem_size_cells);
memcell_buf += n_mem_size_cells;
max_addr = max_t(phys_addr_t, max_addr, start + size);
} }
return max_addr; return max_addr;
......
...@@ -45,9 +45,9 @@ phys_addr_t get_csrbase(void) ...@@ -45,9 +45,9 @@ phys_addr_t get_csrbase(void)
tsi = of_find_node_by_type(NULL, "tsi-bridge"); tsi = of_find_node_by_type(NULL, "tsi-bridge");
if (tsi) { if (tsi) {
unsigned int size; struct resource res;
const void *prop = of_get_property(tsi, "reg", &size); of_address_to_resource(tsi, 0, &res);
tsi108_csr_base = of_translate_address(tsi, prop); tsi108_csr_base = res.start;
of_node_put(tsi); of_node_put(tsi);
} }
return tsi108_csr_base; return tsi108_csr_base;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment