Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'devicetree-for-6.4-2' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux

Pull more devicetree updates from Rob Herring:

- First part of DT header detangling dropping cpu.h from of_device.h
and replacing some includes with forward declarations. A handful of
drivers needed some adjustment to their includes as a result.

- Refactor of_device.h to be used by bus drivers rather than various
device drivers. This moves non-bus related functions out of
of_device.h. The end goal is for of_platform.h and of_device.h to
stop including each other.

- Refactor open coded parsing of "ranges" in some bus drivers to use DT
address parsing functions

- Add some new address parsing functions of_property_read_reg(),
of_range_count(), and of_range_to_resource() in preparation to
convert more open coded parsing of DT addresses to use them.

- Treewide clean-ups to use of_property_read_bool() and
of_property_present() as appropriate. The ones here are the ones that
didn't get picked up elsewhere.

* tag 'devicetree-for-6.4-2' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux: (34 commits)
bus: tegra-gmi: Replace of_platform.h with explicit includes
hte: Use of_property_present() for testing DT property presence
w1: w1-gpio: Use of_property_read_bool() for boolean properties
virt: fsl: Use of_property_present() for testing DT property presence
soc: fsl: Use of_property_present() for testing DT property presence
sbus: display7seg: Use of_property_read_bool() for boolean properties
sparc: Use of_property_read_bool() for boolean properties
sparc: Use of_property_present() for testing DT property presence
bus: mvebu-mbus: Remove open coded "ranges" parsing
of/address: Add of_property_read_reg() helper
of/address: Add of_range_count() helper
of/address: Add support for 3 address cell bus
of/address: Add of_range_to_resource() helper
of: unittest: Add bus address range parsing tests
of: Drop cpu.h include from of_device.h
OPP: Adjust includes to remove of_device.h
irqchip: loongson-eiointc: Add explicit include for cpuhotplug.h
cpuidle: Adjust includes to remove of_device.h
cpufreq: sun50i: Add explicit include for cpu.h
cpufreq: Adjust includes to remove of_device.h
...

+566 -373
-1
arch/arm/kernel/cpuidle.c
··· 5 5 6 6 #include <linux/cpuidle.h> 7 7 #include <linux/of.h> 8 - #include <linux/of_device.h> 9 8 #include <asm/cpuidle.h> 10 9 11 10 extern struct of_cpuidle_method __cpuidle_method_of_table[];
-1
arch/arm/mach-sunxi/mc_smp.c
··· 19 19 #include <linux/irqchip/arm-gic.h> 20 20 #include <linux/of.h> 21 21 #include <linux/of_address.h> 22 - #include <linux/of_device.h> 23 22 #include <linux/smp.h> 24 23 25 24 #include <asm/cacheflush.h>
-1
arch/riscv/kernel/cacheinfo.c
··· 5 5 6 6 #include <linux/cpu.h> 7 7 #include <linux/of.h> 8 - #include <linux/of_device.h> 9 8 #include <asm/cacheinfo.h> 10 9 11 10 static struct riscv_cacheinfo_ops *rv_cache_ops;
+1 -1
arch/riscv/kernel/setup.c
··· 8 8 * Nick Kossifidis <mick@ics.forth.gr> 9 9 */ 10 10 11 + #include <linux/cpu.h> 11 12 #include <linux/init.h> 12 13 #include <linux/mm.h> 13 14 #include <linux/memblock.h> ··· 16 15 #include <linux/console.h> 17 16 #include <linux/screen_info.h> 18 17 #include <linux/of_fdt.h> 19 - #include <linux/of_platform.h> 20 18 #include <linux/sched/task.h> 21 19 #include <linux/smp.h> 22 20 #include <linux/efi.h>
+3
arch/sparc/include/asm/prom.h
··· 19 19 #include <linux/mutex.h> 20 20 #include <linux/atomic.h> 21 21 #include <linux/irqdomain.h> 22 + #include <linux/spinlock.h> 22 23 23 24 #define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l)) 24 25 #define of_prop_cmp(s1, s2) strcasecmp((s1), (s2)) 25 26 #define of_node_cmp(s1, s2) strcmp((s1), (s2)) 27 + 28 + extern raw_spinlock_t devtree_lock; 26 29 27 30 struct of_irq_controller { 28 31 unsigned int (*irq_build)(struct device_node *, unsigned int, void *);
+2 -2
arch/sparc/kernel/of_device_32.c
··· 29 29 * parent as-is, not with the PCI translate 30 30 * method which chops off the top address cell. 31 31 */ 32 - if (!of_find_property(np, "ranges", NULL)) 32 + if (!of_property_present(np, "ranges")) 33 33 return 0; 34 34 35 35 return 1; ··· 223 223 static int __init use_1to1_mapping(struct device_node *pp) 224 224 { 225 225 /* If we have a ranges property in the parent, use it. */ 226 - if (of_find_property(pp, "ranges", NULL) != NULL) 226 + if (of_property_present(pp, "ranges")) 227 227 return 0; 228 228 229 229 /* Some SBUS devices use intermediate nodes to express
+3 -3
arch/sparc/kernel/of_device_64.c
··· 58 58 * parent as-is, not with the PCI translate 59 59 * method which chops off the top address cell. 60 60 */ 61 - if (!of_find_property(np, "ranges", NULL)) 61 + if (!of_property_present(np, "ranges")) 62 62 return 0; 63 63 64 64 return 1; ··· 78 78 * simba. 79 79 */ 80 80 if (of_node_name_eq(np, "pci")) { 81 - if (!of_find_property(np, "ranges", NULL)) 81 + if (!of_property_present(np, "ranges")) 82 82 return 1; 83 83 } 84 84 ··· 283 283 static int __init use_1to1_mapping(struct device_node *pp) 284 284 { 285 285 /* If we have a ranges property in the parent, use it. */ 286 - if (of_find_property(pp, "ranges", NULL) != NULL) 286 + if (of_property_present(pp, "ranges")) 287 287 return 0; 288 288 289 289 /* If the parent is the dma node of an ISA bus, pass
+1 -1
arch/sparc/kernel/of_device_common.c
··· 162 162 * don't have some intervening real bus that provides 163 163 * ranges based translations. 164 164 */ 165 - if (of_find_property(dp, "ranges", NULL) != NULL) 165 + if (of_property_present(dp, "ranges")) 166 166 break; 167 167 168 168 dp = dp->parent;
+1 -1
arch/sparc/kernel/pci_schizo.c
··· 1270 1270 pbm->chip_version >= 0x2) 1271 1271 tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT; 1272 1272 1273 - if (!of_find_property(pbm->op->dev.of_node, "no-bus-parking", NULL)) 1273 + if (!of_property_read_bool(pbm->op->dev.of_node, "no-bus-parking")) 1274 1274 tmp |= SCHIZO_PCICTRL_PARK; 1275 1275 else 1276 1276 tmp &= ~SCHIZO_PCICTRL_PARK;
+1 -1
arch/sparc/kernel/power.c
··· 28 28 { 29 29 if (irq == 0xffffffff) 30 30 return 0; 31 - if (!of_find_property(dp, "button", NULL)) 31 + if (!of_property_read_bool(dp, "button")) 32 32 return 0; 33 33 34 34 return 1;
+1 -1
arch/sparc/kernel/prom_64.c
··· 502 502 struct device_node *portid_parent = NULL; 503 503 int portid = -1; 504 504 505 - if (of_find_property(dp, "cpuid", NULL)) { 505 + if (of_property_present(dp, "cpuid")) { 506 506 int limit = 2; 507 507 508 508 portid_parent = dp;
+1 -1
arch/sparc/kernel/time_32.c
··· 277 277 return -ENODEV; 278 278 279 279 /* Only the primary RTC has an address property */ 280 - if (!of_find_property(dp, "address", NULL)) 280 + if (!of_property_present(dp, "address")) 281 281 return -ENODEV; 282 282 283 283 m48t59_rtc.resource = &op->resource[0];
+1 -1
drivers/base/cacheinfo.c
··· 14 14 #include <linux/cpu.h> 15 15 #include <linux/device.h> 16 16 #include <linux/init.h> 17 - #include <linux/of_device.h> 17 + #include <linux/of.h> 18 18 #include <linux/sched.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/smp.h>
+8 -50
drivers/bus/mvebu-mbus.c
··· 1179 1179 return 0; 1180 1180 } 1181 1181 1182 - static int __init 1183 - mbus_parse_ranges(struct device_node *node, 1184 - int *addr_cells, int *c_addr_cells, int *c_size_cells, 1185 - int *cell_count, const __be32 **ranges_start, 1186 - const __be32 **ranges_end) 1187 - { 1188 - const __be32 *prop; 1189 - int ranges_len, tuple_len; 1190 - 1191 - /* Allow a node with no 'ranges' property */ 1192 - *ranges_start = of_get_property(node, "ranges", &ranges_len); 1193 - if (*ranges_start == NULL) { 1194 - *addr_cells = *c_addr_cells = *c_size_cells = *cell_count = 0; 1195 - *ranges_start = *ranges_end = NULL; 1196 - return 0; 1197 - } 1198 - *ranges_end = *ranges_start + ranges_len / sizeof(__be32); 1199 - 1200 - *addr_cells = of_n_addr_cells(node); 1201 - 1202 - prop = of_get_property(node, "#address-cells", NULL); 1203 - *c_addr_cells = be32_to_cpup(prop); 1204 - 1205 - prop = of_get_property(node, "#size-cells", NULL); 1206 - *c_size_cells = be32_to_cpup(prop); 1207 - 1208 - *cell_count = *addr_cells + *c_addr_cells + *c_size_cells; 1209 - tuple_len = (*cell_count) * sizeof(__be32); 1210 - 1211 - if (ranges_len % tuple_len) { 1212 - pr_warn("malformed ranges entry '%pOFn'\n", node); 1213 - return -EINVAL; 1214 - } 1215 - return 0; 1216 - } 1217 - 1218 1182 static int __init mbus_dt_setup(struct mvebu_mbus_state *mbus, 1219 1183 struct device_node *np) 1220 1184 { 1221 - int addr_cells, c_addr_cells, c_size_cells; 1222 - int i, ret, cell_count; 1223 - const __be32 *r, *ranges_start, *ranges_end; 1185 + int ret; 1186 + struct of_range_parser parser; 1187 + struct of_range range; 1224 1188 1225 - ret = mbus_parse_ranges(np, &addr_cells, &c_addr_cells, 1226 - &c_size_cells, &cell_count, 1227 - &ranges_start, &ranges_end); 1189 + ret = of_range_parser_init(&parser, np); 1228 1190 if (ret < 0) 1229 - return ret; 1191 + return 0; 1230 1192 1231 - for (i = 0, r = ranges_start; r < ranges_end; r += cell_count, i++) { 1232 - u32 windowid, base, size; 1193 + for_each_of_range(&parser, &range) { 1194 + u32 windowid = upper_32_bits(range.bus_addr); 1233 1195 u8 target, attr; 1234 1196 1235 1197 /* 1236 1198 * An entry with a non-zero custom field do not 1237 1199 * correspond to a static window, so skip it. 1238 1200 */ 1239 - windowid = of_read_number(r, 1); 1240 1201 if (CUSTOM(windowid)) 1241 1202 continue; 1242 1203 1243 1204 target = TARGET(windowid); 1244 1205 attr = ATTR(windowid); 1245 1206 1246 - base = of_read_number(r + c_addr_cells, addr_cells); 1247 - size = of_read_number(r + c_addr_cells + addr_cells, 1248 - c_size_cells); 1249 - ret = mbus_dt_setup_win(mbus, base, size, target, attr); 1207 + ret = mbus_dt_setup_win(mbus, range.cpu_addr, range.size, target, attr); 1250 1208 if (ret < 0) 1251 1209 return ret; 1252 1210 }
+3 -1
drivers/bus/tegra-gmi.c
··· 9 9 #include <linux/delay.h> 10 10 #include <linux/io.h> 11 11 #include <linux/module.h> 12 - #include <linux/of_device.h> 12 + #include <linux/of.h> 13 + #include <linux/of_platform.h> 14 + #include <linux/platform_device.h> 13 15 #include <linux/pm_runtime.h> 14 16 #include <linux/reset.h> 15 17
+11 -43
drivers/bus/uniphier-system-bus.c
··· 176 176 { 177 177 struct device *dev = &pdev->dev; 178 178 struct uniphier_system_bus_priv *priv; 179 - const __be32 *ranges; 180 - u32 cells, addr, size; 181 - u64 paddr; 182 - int pna, bank, rlen, rone, ret; 179 + struct of_range_parser parser; 180 + struct of_range range; 181 + int ret; 183 182 184 183 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 185 184 if (!priv) ··· 190 191 191 192 priv->dev = dev; 192 193 193 - pna = of_n_addr_cells(dev->of_node); 194 - 195 - ret = of_property_read_u32(dev->of_node, "#address-cells", &cells); 196 - if (ret) { 197 - dev_err(dev, "failed to get #address-cells\n"); 194 + ret = of_range_parser_init(&parser, dev->of_node); 195 + if (ret) 198 196 return ret; 199 - } 200 - if (cells != 2) { 201 - dev_err(dev, "#address-cells must be 2\n"); 202 - return -EINVAL; 203 - } 204 197 205 - ret = of_property_read_u32(dev->of_node, "#size-cells", &cells); 206 - if (ret) { 207 - dev_err(dev, "failed to get #size-cells\n"); 208 - return ret; 209 - } 210 - if (cells != 1) { 211 - dev_err(dev, "#size-cells must be 1\n"); 212 - return -EINVAL; 213 - } 214 - 215 - ranges = of_get_property(dev->of_node, "ranges", &rlen); 216 - if (!ranges) { 217 - dev_err(dev, "failed to get ranges property\n"); 218 - return -ENOENT; 219 - } 220 - 221 - rlen /= sizeof(*ranges); 222 - rone = pna + 2; 223 - 224 - for (; rlen >= rone; rlen -= rone) { 225 - bank = be32_to_cpup(ranges++); 226 - addr = be32_to_cpup(ranges++); 227 - paddr = of_translate_address(dev->of_node, ranges); 228 - if (paddr == OF_BAD_ADDR) 198 + for_each_of_range(&parser, &range) { 199 + if (range.cpu_addr == OF_BAD_ADDR) 229 200 return -EINVAL; 230 - ranges += pna; 231 - size = be32_to_cpup(ranges++); 232 - 233 - ret = uniphier_system_bus_add_bank(priv, bank, addr, 234 - paddr, size); 201 + ret = uniphier_system_bus_add_bank(priv, 202 + upper_32_bits(range.bus_addr), 203 + lower_32_bits(range.bus_addr), 204 + range.cpu_addr, range.size); 235 205 if (ret) 236 206 return ret; 237 207 }
+1 -2
drivers/clocksource/ingenic-timer.c
··· 9 9 #include <linux/clk.h> 10 10 #include <linux/clockchips.h> 11 11 #include <linux/clocksource.h> 12 + #include <linux/cpuhotplug.h> 12 13 #include <linux/interrupt.h> 13 14 #include <linux/mfd/ingenic-tcu.h> 14 15 #include <linux/mfd/syscon.h> 15 16 #include <linux/of.h> 16 - #include <linux/of_address.h> 17 17 #include <linux/of_irq.h> 18 - #include <linux/of_platform.h> 19 18 #include <linux/overflow.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/regmap.h>
+1
drivers/cpufreq/acpi-cpufreq.c
··· 20 20 #include <linux/dmi.h> 21 21 #include <linux/slab.h> 22 22 #include <linux/string_helpers.h> 23 + #include <linux/platform_device.h> 23 24 24 25 #include <linux/acpi.h> 25 26 #include <linux/io.h>
-1
drivers/cpufreq/cpufreq-dt-platdev.c
··· 6 6 7 7 #include <linux/err.h> 8 8 #include <linux/of.h> 9 - #include <linux/of_device.h> 10 9 #include <linux/platform_device.h> 11 10 12 11 #include "cpufreq-dt.h"
+1 -1
drivers/cpufreq/kirkwood-cpufreq.c
··· 9 9 #include <linux/module.h> 10 10 #include <linux/clk.h> 11 11 #include <linux/cpufreq.h> 12 - #include <linux/of_device.h> 12 + #include <linux/of.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/io.h> 15 15 #include <asm/proc-fns.h>
+1 -1
drivers/cpufreq/maple-cpufreq.c
··· 23 23 #include <linux/completion.h> 24 24 #include <linux/mutex.h> 25 25 #include <linux/time.h> 26 - #include <linux/of_device.h> 26 + #include <linux/of.h> 27 27 28 28 #define DBG(fmt...) pr_debug(fmt) 29 29
+1
drivers/cpufreq/pcc-cpufreq.c
··· 31 31 #include <linux/cpufreq.h> 32 32 #include <linux/compiler.h> 33 33 #include <linux/slab.h> 34 + #include <linux/platform_device.h> 34 35 35 36 #include <linux/acpi.h> 36 37 #include <linux/io.h>
+1 -1
drivers/cpufreq/pmac32-cpufreq.c
··· 23 23 #include <linux/init.h> 24 24 #include <linux/device.h> 25 25 #include <linux/hardirq.h> 26 - #include <linux/of_device.h> 26 + #include <linux/of.h> 27 27 28 28 #include <asm/machdep.h> 29 29 #include <asm/irq.h>
+1 -1
drivers/cpufreq/pmac64-cpufreq.c
··· 21 21 #include <linux/init.h> 22 22 #include <linux/completion.h> 23 23 #include <linux/mutex.h> 24 - #include <linux/of_device.h> 24 + #include <linux/of.h> 25 25 26 26 #include <asm/machdep.h> 27 27 #include <asm/irq.h>
+2 -2
drivers/cpufreq/qcom-cpufreq-hw.c
··· 11 11 #include <linux/interrupt.h> 12 12 #include <linux/kernel.h> 13 13 #include <linux/module.h> 14 - #include <linux/of_address.h> 15 - #include <linux/of_platform.h> 14 + #include <linux/of.h> 15 + #include <linux/platform_device.h> 16 16 #include <linux/pm_opp.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/spinlock.h>
+1 -1
drivers/cpufreq/spear-cpufreq.c
··· 18 18 #include <linux/err.h> 19 19 #include <linux/init.h> 20 20 #include <linux/module.h> 21 - #include <linux/of_device.h> 21 + #include <linux/of.h> 22 22 #include <linux/platform_device.h> 23 23 #include <linux/slab.h> 24 24 #include <linux/types.h>
+2 -1
drivers/cpufreq/sun50i-cpufreq-nvmem.c
··· 10 10 11 11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12 12 13 + #include <linux/cpu.h> 13 14 #include <linux/module.h> 14 15 #include <linux/nvmem-consumer.h> 15 - #include <linux/of_device.h> 16 + #include <linux/of.h> 16 17 #include <linux/platform_device.h> 17 18 #include <linux/pm_opp.h> 18 19 #include <linux/slab.h>
-1
drivers/cpufreq/tegra124-cpufreq.c
··· 11 11 #include <linux/init.h> 12 12 #include <linux/kernel.h> 13 13 #include <linux/module.h> 14 - #include <linux/of_device.h> 15 14 #include <linux/of.h> 16 15 #include <linux/platform_device.h> 17 16 #include <linux/pm_opp.h>
+1 -1
drivers/cpufreq/tegra20-cpufreq.c
··· 12 12 #include <linux/err.h> 13 13 #include <linux/init.h> 14 14 #include <linux/module.h> 15 - #include <linux/of_device.h> 15 + #include <linux/of.h> 16 16 #include <linux/platform_device.h> 17 17 #include <linux/pm_opp.h> 18 18 #include <linux/types.h>
-1
drivers/cpuidle/cpuidle-psci.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <linux/module.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_device.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/psci.h> 22 21 #include <linux/pm_domain.h>
+1 -2
drivers/cpuidle/cpuidle-qcom-spm.c
··· 11 11 #include <linux/io.h> 12 12 #include <linux/slab.h> 13 13 #include <linux/of.h> 14 - #include <linux/of_address.h> 15 - #include <linux/of_device.h> 14 + #include <linux/of_platform.h> 16 15 #include <linux/err.h> 17 16 #include <linux/platform_device.h> 18 17 #include <linux/cpuidle.h>
+1 -1
drivers/cpuidle/cpuidle-riscv-sbi.c
··· 8 8 9 9 #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt 10 10 11 + #include <linux/cpuhotplug.h> 11 12 #include <linux/cpuidle.h> 12 13 #include <linux/cpumask.h> 13 14 #include <linux/cpu_pm.h> ··· 16 15 #include <linux/kernel.h> 17 16 #include <linux/module.h> 18 17 #include <linux/of.h> 19 - #include <linux/of_device.h> 20 18 #include <linux/slab.h> 21 19 #include <linux/platform_device.h> 22 20 #include <linux/pm_domain.h>
-1
drivers/cpuidle/dt_idle_states.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/module.h> 16 16 #include <linux/of.h> 17 - #include <linux/of_device.h> 18 17 19 18 #include "dt_idle_states.h" 20 19
+1 -1
drivers/hte/hte.c
··· 518 518 519 519 np = dev->of_node; 520 520 521 - if (!of_find_property(np, "timestamp-names", NULL)) { 521 + if (!of_property_present(np, "timestamp-names")) { 522 522 /* Let hte core construct it during request time */ 523 523 desc->attr.name = NULL; 524 524 } else {
+1 -4
drivers/irqchip/irq-loongson-eiointc.c
··· 7 7 8 8 #define pr_fmt(fmt) "eiointc: " fmt 9 9 10 + #include <linux/cpuhotplug.h> 10 11 #include <linux/interrupt.h> 11 12 #include <linux/irq.h> 12 13 #include <linux/irqchip.h> 13 14 #include <linux/irqdomain.h> 14 15 #include <linux/irqchip/chained_irq.h> 15 16 #include <linux/kernel.h> 16 - #include <linux/platform_device.h> 17 - #include <linux/of_address.h> 18 - #include <linux/of_irq.h> 19 - #include <linux/of_platform.h> 20 17 #include <linux/syscore_ops.h> 21 18 22 19 #define EIOINTC_REG_NODEMAP 0x14a0
+1 -1
drivers/of/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - obj-y = base.o device.o platform.o property.o 2 + obj-y = base.o cpu.o device.o platform.o property.o 3 3 obj-$(CONFIG_OF_KOBJ) += kobj.o 4 4 obj-$(CONFIG_OF_DYNAMIC) += dynamic.o 5 5 obj-$(CONFIG_OF_FLATTREE) += fdt.o
+73 -3
drivers/of/address.c
··· 90 90 return 0; 91 91 } 92 92 93 + static unsigned int of_bus_default_flags_get_flags(const __be32 *addr) 94 + { 95 + return of_read_number(addr, 1); 96 + } 97 + 93 98 static unsigned int of_bus_default_get_flags(const __be32 *addr) 94 99 { 95 100 return IORESOURCE_MEM; 96 101 } 102 + 97 103 98 104 #ifdef CONFIG_PCI 99 105 static unsigned int of_bus_pci_get_flags(const __be32 *addr) ··· 219 213 res->parent = res->child = res->sibling = NULL; 220 214 res->name = np->full_name; 221 215 222 - if (!IS_ENABLED(CONFIG_PCI)) 223 - return -ENOSYS; 224 - 225 216 if (res->flags & IORESOURCE_IO) { 226 217 unsigned long port; 227 218 err = pci_register_io_range(&np->fwnode, range->cpu_addr, ··· 249 246 return err; 250 247 } 251 248 EXPORT_SYMBOL(of_pci_range_to_resource); 249 + 250 + /* 251 + * of_range_to_resource - Create a resource from a ranges entry 252 + * @np: device node where the range belongs to 253 + * @index: the 'ranges' index to convert to a resource 254 + * @res: pointer to a valid resource that will be updated to 255 + * reflect the values contained in the range. 256 + * 257 + * Returns ENOENT if the entry is not found or EINVAL if the range cannot be 258 + * converted to resource. 259 + */ 260 + int of_range_to_resource(struct device_node *np, int index, struct resource *res) 261 + { 262 + int ret, i = 0; 263 + struct of_range_parser parser; 264 + struct of_range range; 265 + 266 + ret = of_range_parser_init(&parser, np); 267 + if (ret) 268 + return ret; 269 + 270 + for_each_of_range(&parser, &range) 271 + if (i++ == index) 272 + return of_pci_range_to_resource(&range, np, res); 273 + 274 + return -ENOENT; 275 + } 276 + EXPORT_SYMBOL(of_range_to_resource); 252 277 253 278 /* 254 279 * ISA bus specific translator ··· 334 303 return flags; 335 304 } 336 305 306 + static int of_bus_default_flags_match(struct device_node *np) 307 + { 308 + return of_bus_n_addr_cells(np) == 3; 309 + } 310 + 337 311 /* 338 312 * Array of bus specific translators 339 313 */ ··· 367 331 .translate = of_bus_isa_translate, 368 332 .has_flags = true, 369 333 .get_flags = of_bus_isa_get_flags, 334 + }, 335 + /* Default with flags cell */ 336 + { 337 + .name = "default-flags", 338 + .addresses = "reg", 339 + .match = of_bus_default_flags_match, 340 + .count_cells = of_bus_default_count_cells, 341 + .map = of_bus_default_map, 342 + .translate = of_bus_default_translate, 343 + .has_flags = true, 344 + .get_flags = of_bus_default_flags_get_flags, 370 345 }, 371 346 /* Default */ 372 347 { ··· 743 696 return NULL; 744 697 } 745 698 EXPORT_SYMBOL(__of_get_address); 699 + 700 + /** 701 + * of_property_read_reg - Retrieve the specified "reg" entry index without translating 702 + * @np: device tree node for which to retrieve "reg" from 703 + * @idx: "reg" entry index to read 704 + * @addr: return value for the untranslated address 705 + * @size: return value for the entry size 706 + * 707 + * Returns -EINVAL if "reg" is not found. Returns 0 on success with addr and 708 + * size values filled in. 709 + */ 710 + int of_property_read_reg(struct device_node *np, int idx, u64 *addr, u64 *size) 711 + { 712 + const __be32 *prop = of_get_address(np, idx, size, NULL); 713 + 714 + if (!prop) 715 + return -EINVAL; 716 + 717 + *addr = of_read_number(prop, of_n_addr_cells(np)); 718 + 719 + return 0; 720 + } 721 + EXPORT_SYMBOL(of_property_read_reg); 746 722 747 723 static int parser_init(struct of_pci_range_parser *parser, 748 724 struct device_node *node, const char *name)
-187
drivers/of/base.c
··· 287 287 EXPORT_SYMBOL(of_get_property); 288 288 289 289 /** 290 - * of_get_cpu_hwid - Get the hardware ID from a CPU device node 291 - * 292 - * @cpun: CPU number(logical index) for which device node is required 293 - * @thread: The local thread number to get the hardware ID for. 294 - * 295 - * Return: The hardware ID for the CPU node or ~0ULL if not found. 296 - */ 297 - u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread) 298 - { 299 - const __be32 *cell; 300 - int ac, len; 301 - 302 - ac = of_n_addr_cells(cpun); 303 - cell = of_get_property(cpun, "reg", &len); 304 - if (!cell || !ac || ((sizeof(*cell) * ac * (thread + 1)) > len)) 305 - return ~0ULL; 306 - 307 - cell += ac * thread; 308 - return of_read_number(cell, ac); 309 - } 310 - 311 - /* 312 - * arch_match_cpu_phys_id - Match the given logical CPU and physical id 313 - * 314 - * @cpu: logical cpu index of a core/thread 315 - * @phys_id: physical identifier of a core/thread 316 - * 317 - * CPU logical to physical index mapping is architecture specific. 318 - * However this __weak function provides a default match of physical 319 - * id to logical cpu index. phys_id provided here is usually values read 320 - * from the device tree which must match the hardware internal registers. 321 - * 322 - * Returns true if the physical identifier and the logical cpu index 323 - * correspond to the same core/thread, false otherwise. 324 - */ 325 - bool __weak arch_match_cpu_phys_id(int cpu, u64 phys_id) 326 - { 327 - return (u32)phys_id == cpu; 328 - } 329 - 330 - /* 331 - * Checks if the given "prop_name" property holds the physical id of the 332 - * core/thread corresponding to the logical cpu 'cpu'. If 'thread' is not 333 - * NULL, local thread number within the core is returned in it. 334 - */ 335 - static bool __of_find_n_match_cpu_property(struct device_node *cpun, 336 - const char *prop_name, int cpu, unsigned int *thread) 337 - { 338 - const __be32 *cell; 339 - int ac, prop_len, tid; 340 - u64 hwid; 341 - 342 - ac = of_n_addr_cells(cpun); 343 - cell = of_get_property(cpun, prop_name, &prop_len); 344 - if (!cell && !ac && arch_match_cpu_phys_id(cpu, 0)) 345 - return true; 346 - if (!cell || !ac) 347 - return false; 348 - prop_len /= sizeof(*cell) * ac; 349 - for (tid = 0; tid < prop_len; tid++) { 350 - hwid = of_read_number(cell, ac); 351 - if (arch_match_cpu_phys_id(cpu, hwid)) { 352 - if (thread) 353 - *thread = tid; 354 - return true; 355 - } 356 - cell += ac; 357 - } 358 - return false; 359 - } 360 - 361 - /* 362 - * arch_find_n_match_cpu_physical_id - See if the given device node is 363 - * for the cpu corresponding to logical cpu 'cpu'. Return true if so, 364 - * else false. If 'thread' is non-NULL, the local thread number within the 365 - * core is returned in it. 366 - */ 367 - bool __weak arch_find_n_match_cpu_physical_id(struct device_node *cpun, 368 - int cpu, unsigned int *thread) 369 - { 370 - /* Check for non-standard "ibm,ppc-interrupt-server#s" property 371 - * for thread ids on PowerPC. If it doesn't exist fallback to 372 - * standard "reg" property. 373 - */ 374 - if (IS_ENABLED(CONFIG_PPC) && 375 - __of_find_n_match_cpu_property(cpun, 376 - "ibm,ppc-interrupt-server#s", 377 - cpu, thread)) 378 - return true; 379 - 380 - return __of_find_n_match_cpu_property(cpun, "reg", cpu, thread); 381 - } 382 - 383 - /** 384 - * of_get_cpu_node - Get device node associated with the given logical CPU 385 - * 386 - * @cpu: CPU number(logical index) for which device node is required 387 - * @thread: if not NULL, local thread number within the physical core is 388 - * returned 389 - * 390 - * The main purpose of this function is to retrieve the device node for the 391 - * given logical CPU index. It should be used to initialize the of_node in 392 - * cpu device. Once of_node in cpu device is populated, all the further 393 - * references can use that instead. 394 - * 395 - * CPU logical to physical index mapping is architecture specific and is built 396 - * before booting secondary cores. This function uses arch_match_cpu_phys_id 397 - * which can be overridden by architecture specific implementation. 398 - * 399 - * Return: A node pointer for the logical cpu with refcount incremented, use 400 - * of_node_put() on it when done. Returns NULL if not found. 401 - */ 402 - struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) 403 - { 404 - struct device_node *cpun; 405 - 406 - for_each_of_cpu_node(cpun) { 407 - if (arch_find_n_match_cpu_physical_id(cpun, cpu, thread)) 408 - return cpun; 409 - } 410 - return NULL; 411 - } 412 - EXPORT_SYMBOL(of_get_cpu_node); 413 - 414 - /** 415 - * of_cpu_node_to_id: Get the logical CPU number for a given device_node 416 - * 417 - * @cpu_node: Pointer to the device_node for CPU. 418 - * 419 - * Return: The logical CPU number of the given CPU device_node or -ENODEV if the 420 - * CPU is not found. 421 - */ 422 - int of_cpu_node_to_id(struct device_node *cpu_node) 423 - { 424 - int cpu; 425 - bool found = false; 426 - struct device_node *np; 427 - 428 - for_each_possible_cpu(cpu) { 429 - np = of_cpu_device_node_get(cpu); 430 - found = (cpu_node == np); 431 - of_node_put(np); 432 - if (found) 433 - return cpu; 434 - } 435 - 436 - return -ENODEV; 437 - } 438 - EXPORT_SYMBOL(of_cpu_node_to_id); 439 - 440 - /** 441 - * of_get_cpu_state_node - Get CPU's idle state node at the given index 442 - * 443 - * @cpu_node: The device node for the CPU 444 - * @index: The index in the list of the idle states 445 - * 446 - * Two generic methods can be used to describe a CPU's idle states, either via 447 - * a flattened description through the "cpu-idle-states" binding or via the 448 - * hierarchical layout, using the "power-domains" and the "domain-idle-states" 449 - * bindings. This function check for both and returns the idle state node for 450 - * the requested index. 451 - * 452 - * Return: An idle state node if found at @index. The refcount is incremented 453 - * for it, so call of_node_put() on it when done. Returns NULL if not found. 454 - */ 455 - struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, 456 - int index) 457 - { 458 - struct of_phandle_args args; 459 - int err; 460 - 461 - err = of_parse_phandle_with_args(cpu_node, "power-domains", 462 - "#power-domain-cells", 0, &args); 463 - if (!err) { 464 - struct device_node *state_node = 465 - of_parse_phandle(args.np, "domain-idle-states", index); 466 - 467 - of_node_put(args.np); 468 - if (state_node) 469 - return state_node; 470 - } 471 - 472 - return of_parse_phandle(cpu_node, "cpu-idle-states", index); 473 - } 474 - EXPORT_SYMBOL(of_get_cpu_state_node); 475 - 476 - /** 477 290 * __of_device_is_compatible() - Check if the node matches given constraints 478 291 * @device: pointer to node 479 292 * @compat: required compatible string, NULL or "" for any match
+210
drivers/of/cpu.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/cpu.h> 3 + #include <linux/kernel.h> 4 + #include <linux/of.h> 5 + 6 + /** 7 + * of_get_cpu_hwid - Get the hardware ID from a CPU device node 8 + * 9 + * @cpun: CPU number(logical index) for which device node is required 10 + * @thread: The local thread number to get the hardware ID for. 11 + * 12 + * Return: The hardware ID for the CPU node or ~0ULL if not found. 13 + */ 14 + u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread) 15 + { 16 + const __be32 *cell; 17 + int ac, len; 18 + 19 + ac = of_n_addr_cells(cpun); 20 + cell = of_get_property(cpun, "reg", &len); 21 + if (!cell || !ac || ((sizeof(*cell) * ac * (thread + 1)) > len)) 22 + return ~0ULL; 23 + 24 + cell += ac * thread; 25 + return of_read_number(cell, ac); 26 + } 27 + 28 + /* 29 + * arch_match_cpu_phys_id - Match the given logical CPU and physical id 30 + * 31 + * @cpu: logical cpu index of a core/thread 32 + * @phys_id: physical identifier of a core/thread 33 + * 34 + * CPU logical to physical index mapping is architecture specific. 35 + * However this __weak function provides a default match of physical 36 + * id to logical cpu index. phys_id provided here is usually values read 37 + * from the device tree which must match the hardware internal registers. 38 + * 39 + * Returns true if the physical identifier and the logical cpu index 40 + * correspond to the same core/thread, false otherwise. 41 + */ 42 + bool __weak arch_match_cpu_phys_id(int cpu, u64 phys_id) 43 + { 44 + return (u32)phys_id == cpu; 45 + } 46 + 47 + /* 48 + * Checks if the given "prop_name" property holds the physical id of the 49 + * core/thread corresponding to the logical cpu 'cpu'. If 'thread' is not 50 + * NULL, local thread number within the core is returned in it. 51 + */ 52 + static bool __of_find_n_match_cpu_property(struct device_node *cpun, 53 + const char *prop_name, int cpu, unsigned int *thread) 54 + { 55 + const __be32 *cell; 56 + int ac, prop_len, tid; 57 + u64 hwid; 58 + 59 + ac = of_n_addr_cells(cpun); 60 + cell = of_get_property(cpun, prop_name, &prop_len); 61 + if (!cell && !ac && arch_match_cpu_phys_id(cpu, 0)) 62 + return true; 63 + if (!cell || !ac) 64 + return false; 65 + prop_len /= sizeof(*cell) * ac; 66 + for (tid = 0; tid < prop_len; tid++) { 67 + hwid = of_read_number(cell, ac); 68 + if (arch_match_cpu_phys_id(cpu, hwid)) { 69 + if (thread) 70 + *thread = tid; 71 + return true; 72 + } 73 + cell += ac; 74 + } 75 + return false; 76 + } 77 + 78 + /* 79 + * arch_find_n_match_cpu_physical_id - See if the given device node is 80 + * for the cpu corresponding to logical cpu 'cpu'. Return true if so, 81 + * else false. If 'thread' is non-NULL, the local thread number within the 82 + * core is returned in it. 83 + */ 84 + bool __weak arch_find_n_match_cpu_physical_id(struct device_node *cpun, 85 + int cpu, unsigned int *thread) 86 + { 87 + /* Check for non-standard "ibm,ppc-interrupt-server#s" property 88 + * for thread ids on PowerPC. If it doesn't exist fallback to 89 + * standard "reg" property. 90 + */ 91 + if (IS_ENABLED(CONFIG_PPC) && 92 + __of_find_n_match_cpu_property(cpun, 93 + "ibm,ppc-interrupt-server#s", 94 + cpu, thread)) 95 + return true; 96 + 97 + return __of_find_n_match_cpu_property(cpun, "reg", cpu, thread); 98 + } 99 + 100 + /** 101 + * of_get_cpu_node - Get device node associated with the given logical CPU 102 + * 103 + * @cpu: CPU number(logical index) for which device node is required 104 + * @thread: if not NULL, local thread number within the physical core is 105 + * returned 106 + * 107 + * The main purpose of this function is to retrieve the device node for the 108 + * given logical CPU index. It should be used to initialize the of_node in 109 + * cpu device. Once of_node in cpu device is populated, all the further 110 + * references can use that instead. 111 + * 112 + * CPU logical to physical index mapping is architecture specific and is built 113 + * before booting secondary cores. This function uses arch_match_cpu_phys_id 114 + * which can be overridden by architecture specific implementation. 115 + * 116 + * Return: A node pointer for the logical cpu with refcount incremented, use 117 + * of_node_put() on it when done. Returns NULL if not found. 118 + */ 119 + struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) 120 + { 121 + struct device_node *cpun; 122 + 123 + for_each_of_cpu_node(cpun) { 124 + if (arch_find_n_match_cpu_physical_id(cpun, cpu, thread)) 125 + return cpun; 126 + } 127 + return NULL; 128 + } 129 + EXPORT_SYMBOL(of_get_cpu_node); 130 + 131 + /** 132 + * of_cpu_device_node_get: Get the CPU device_node for a given logical CPU number 133 + * 134 + * @cpu: The logical CPU number 135 + * 136 + * Return: Pointer to the device_node for CPU with its reference count 137 + * incremented of the given logical CPU number or NULL if the CPU device_node 138 + * is not found. 139 + */ 140 + struct device_node *of_cpu_device_node_get(int cpu) 141 + { 142 + struct device *cpu_dev; 143 + cpu_dev = get_cpu_device(cpu); 144 + if (!cpu_dev) 145 + return of_get_cpu_node(cpu, NULL); 146 + return of_node_get(cpu_dev->of_node); 147 + } 148 + EXPORT_SYMBOL(of_cpu_device_node_get); 149 + 150 + /** 151 + * of_cpu_node_to_id: Get the logical CPU number for a given device_node 152 + * 153 + * @cpu_node: Pointer to the device_node for CPU. 154 + * 155 + * Return: The logical CPU number of the given CPU device_node or -ENODEV if the 156 + * CPU is not found. 157 + */ 158 + int of_cpu_node_to_id(struct device_node *cpu_node) 159 + { 160 + int cpu; 161 + bool found = false; 162 + struct device_node *np; 163 + 164 + for_each_possible_cpu(cpu) { 165 + np = of_cpu_device_node_get(cpu); 166 + found = (cpu_node == np); 167 + of_node_put(np); 168 + if (found) 169 + return cpu; 170 + } 171 + 172 + return -ENODEV; 173 + } 174 + EXPORT_SYMBOL(of_cpu_node_to_id); 175 + 176 + /** 177 + * of_get_cpu_state_node - Get CPU's idle state node at the given index 178 + * 179 + * @cpu_node: The device node for the CPU 180 + * @index: The index in the list of the idle states 181 + * 182 + * Two generic methods can be used to describe a CPU's idle states, either via 183 + * a flattened description through the "cpu-idle-states" binding or via the 184 + * hierarchical layout, using the "power-domains" and the "domain-idle-states" 185 + * bindings. This function check for both and returns the idle state node for 186 + * the requested index. 187 + * 188 + * Return: An idle state node if found at @index. The refcount is incremented 189 + * for it, so call of_node_put() on it when done. Returns NULL if not found. 190 + */ 191 + struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, 192 + int index) 193 + { 194 + struct of_phandle_args args; 195 + int err; 196 + 197 + err = of_parse_phandle_with_args(cpu_node, "power-domains", 198 + "#power-domain-cells", 0, &args); 199 + if (!err) { 200 + struct device_node *state_node = 201 + of_parse_phandle(args.np, "domain-idle-states", index); 202 + 203 + of_node_put(args.np); 204 + if (state_node) 205 + return state_node; 206 + } 207 + 208 + return of_parse_phandle(cpu_node, "cpu-idle-states", index); 209 + } 210 + EXPORT_SYMBOL(of_get_cpu_state_node);
+1
drivers/of/of_private.h
··· 38 38 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 39 39 40 40 extern struct mutex of_mutex; 41 + extern raw_spinlock_t devtree_lock; 41 42 extern struct list_head aliases_lookup; 42 43 extern struct kset *of_kset; 43 44
+8 -1
drivers/of/unittest-data/tests-address.dtsi
··· 14 14 #size-cells = <1>; 15 15 /* ranges here is to make sure we don't use it for 16 16 * dma-ranges translation */ 17 - ranges = <0x70000000 0x70000000 0x40000000>, 17 + ranges = <0x70000000 0x70000000 0x50000000>, 18 18 <0x00000000 0xd0000000 0x20000000>; 19 19 dma-ranges = <0x0 0x20000000 0x40000000>; 20 20 ··· 41 41 ranges = <0x42000000 0x0 0x40000000 0x40000000 0x0 0x10000000>; 42 42 dma-ranges = <0x42000000 0x0 0x80000000 0x00000000 0x0 0x10000000>, 43 43 <0x42000000 0x0 0xc0000000 0x20000000 0x0 0x10000000>; 44 + }; 45 + 46 + bus@a0000000 { 47 + #address-cells = <3>; 48 + #size-cells = <2>; 49 + ranges = <0xf00baa 0x0 0x0 0xa0000000 0x0 0x100000>, 50 + <0xf00bee 0x1 0x0 0xb0000000 0x0 0x200000>; 44 51 }; 45 52 46 53 };
+150
drivers/of/unittest.c
··· 1008 1008 of_node_put(np); 1009 1009 } 1010 1010 1011 + static void __init of_unittest_bus_ranges(void) 1012 + { 1013 + struct device_node *np; 1014 + struct of_range range; 1015 + struct of_range_parser parser; 1016 + struct resource res; 1017 + int ret, count, i = 0; 1018 + 1019 + np = of_find_node_by_path("/testcase-data/address-tests"); 1020 + if (!np) { 1021 + pr_err("missing testcase data\n"); 1022 + return; 1023 + } 1024 + 1025 + if (of_range_parser_init(&parser, np)) { 1026 + pr_err("missing ranges property\n"); 1027 + return; 1028 + } 1029 + 1030 + ret = of_range_to_resource(np, 1, &res); 1031 + unittest(!ret, "of_range_to_resource returned error (%d) node %pOF\n", 1032 + ret, np); 1033 + unittest(resource_type(&res) == IORESOURCE_MEM, 1034 + "of_range_to_resource wrong resource type on node %pOF res=%pR\n", 1035 + np, &res); 1036 + unittest(res.start == 0xd0000000, 1037 + "of_range_to_resource wrong resource start address on node %pOF res=%pR\n", 1038 + np, &res); 1039 + unittest(resource_size(&res) == 0x20000000, 1040 + "of_range_to_resource wrong resource start address on node %pOF res=%pR\n", 1041 + np, &res); 1042 + 1043 + count = of_range_count(&parser); 1044 + unittest(count == 2, 1045 + "of_range_count wrong size on node %pOF count=%d\n", 1046 + np, count); 1047 + 1048 + /* 1049 + * Get the "ranges" from the device tree 1050 + */ 1051 + for_each_of_range(&parser, &range) { 1052 + unittest(range.flags == IORESOURCE_MEM, 1053 + "for_each_of_range wrong flags on node %pOF flags=%x (expected %x)\n", 1054 + np, range.flags, IORESOURCE_MEM); 1055 + if (!i) { 1056 + unittest(range.size == 0x50000000, 1057 + "for_each_of_range wrong size on node %pOF size=%llx\n", 1058 + np, range.size); 1059 + unittest(range.cpu_addr == 0x70000000, 1060 + "for_each_of_range wrong CPU addr (%llx) on node %pOF", 1061 + range.cpu_addr, np); 1062 + unittest(range.bus_addr == 0x70000000, 1063 + "for_each_of_range wrong bus addr (%llx) on node %pOF", 1064 + range.pci_addr, np); 1065 + } else { 1066 + unittest(range.size == 0x20000000, 1067 + "for_each_of_range wrong size on node %pOF size=%llx\n", 1068 + np, range.size); 1069 + unittest(range.cpu_addr == 0xd0000000, 1070 + "for_each_of_range wrong CPU addr (%llx) on node %pOF", 1071 + range.cpu_addr, np); 1072 + unittest(range.bus_addr == 0x00000000, 1073 + "for_each_of_range wrong bus addr (%llx) on node %pOF", 1074 + range.pci_addr, np); 1075 + } 1076 + i++; 1077 + } 1078 + 1079 + of_node_put(np); 1080 + } 1081 + 1082 + static void __init of_unittest_bus_3cell_ranges(void) 1083 + { 1084 + struct device_node *np; 1085 + struct of_range range; 1086 + struct of_range_parser parser; 1087 + int i = 0; 1088 + 1089 + np = of_find_node_by_path("/testcase-data/address-tests/bus@a0000000"); 1090 + if (!np) { 1091 + pr_err("missing testcase data\n"); 1092 + return; 1093 + } 1094 + 1095 + if (of_range_parser_init(&parser, np)) { 1096 + pr_err("missing ranges property\n"); 1097 + return; 1098 + } 1099 + 1100 + /* 1101 + * Get the "ranges" from the device tree 1102 + */ 1103 + for_each_of_range(&parser, &range) { 1104 + if (!i) { 1105 + unittest(range.flags == 0xf00baa, 1106 + "for_each_of_range wrong flags on node %pOF flags=%x\n", 1107 + np, range.flags); 1108 + unittest(range.size == 0x100000, 1109 + "for_each_of_range wrong size on node %pOF size=%llx\n", 1110 + np, range.size); 1111 + unittest(range.cpu_addr == 0xa0000000, 1112 + "for_each_of_range wrong CPU addr (%llx) on node %pOF", 1113 + range.cpu_addr, np); 1114 + unittest(range.bus_addr == 0x0, 1115 + "for_each_of_range wrong bus addr (%llx) on node %pOF", 1116 + range.pci_addr, np); 1117 + } else { 1118 + unittest(range.flags == 0xf00bee, 1119 + "for_each_of_range wrong flags on node %pOF flags=%x\n", 1120 + np, range.flags); 1121 + unittest(range.size == 0x200000, 1122 + "for_each_of_range wrong size on node %pOF size=%llx\n", 1123 + np, range.size); 1124 + unittest(range.cpu_addr == 0xb0000000, 1125 + "for_each_of_range wrong CPU addr (%llx) on node %pOF", 1126 + range.cpu_addr, np); 1127 + unittest(range.bus_addr == 0x100000000, 1128 + "for_each_of_range wrong bus addr (%llx) on node %pOF", 1129 + range.pci_addr, np); 1130 + } 1131 + i++; 1132 + } 1133 + 1134 + of_node_put(np); 1135 + } 1136 + 1137 + static void __init of_unittest_reg(void) 1138 + { 1139 + struct device_node *np; 1140 + int ret; 1141 + u64 addr, size; 1142 + 1143 + np = of_find_node_by_path("/testcase-data/address-tests/bus@80000000/device@1000"); 1144 + if (!np) { 1145 + pr_err("missing testcase data\n"); 1146 + return; 1147 + } 1148 + 1149 + ret = of_property_read_reg(np, 0, &addr, &size); 1150 + unittest(!ret, "of_property_read_reg(%pOF) returned error %d\n", 1151 + np, ret); 1152 + unittest(addr == 0x1000, "of_property_read_reg(%pOF) untranslated address (%llx) incorrect\n", 1153 + np, addr); 1154 + 1155 + of_node_put(np); 1156 + } 1157 + 1011 1158 static void __init of_unittest_parse_interrupts(void) 1012 1159 { 1013 1160 struct device_node *np; ··· 3782 3635 of_unittest_dma_get_max_cpu_address(); 3783 3636 of_unittest_parse_dma_ranges(); 3784 3637 of_unittest_pci_dma_ranges(); 3638 + of_unittest_bus_ranges(); 3639 + of_unittest_bus_3cell_ranges(); 3640 + of_unittest_reg(); 3785 3641 of_unittest_match_node(); 3786 3642 of_unittest_platform_populate(); 3787 3643 of_unittest_overlay();
+1 -1
drivers/opp/of.c
··· 13 13 #include <linux/cpu.h> 14 14 #include <linux/errno.h> 15 15 #include <linux/device.h> 16 - #include <linux/of_device.h> 16 + #include <linux/of.h> 17 17 #include <linux/pm_domain.h> 18 18 #include <linux/slab.h> 19 19 #include <linux/export.h>
+2 -3
drivers/sbus/char/display7seg.c
··· 200 200 */ 201 201 regs = readb(p->regs); 202 202 opts = of_find_node_by_path("/options"); 203 - if (opts && 204 - of_get_property(opts, "d7s-flipped?", NULL)) 205 - p->flipped = true; 203 + if (opts) 204 + p->flipped = of_property_read_bool(opts, "d7s-flipped?"); 206 205 207 206 if (p->flipped) 208 207 regs |= D7S_FLIP;
+1
drivers/soc/mediatek/mtk-svs.c
··· 7 7 #include <linux/bits.h> 8 8 #include <linux/clk.h> 9 9 #include <linux/completion.h> 10 + #include <linux/cpu.h> 10 11 #include <linux/cpuidle.h> 11 12 #include <linux/debugfs.h> 12 13 #include <linux/device.h>
+2 -1
drivers/thermal/cpuidle_cooling.c
··· 7 7 */ 8 8 #define pr_fmt(fmt) "cpuidle cooling: " fmt 9 9 10 + #include <linux/cpu.h> 10 11 #include <linux/cpu_cooling.h> 11 12 #include <linux/cpuidle.h> 12 13 #include <linux/device.h> 13 14 #include <linux/err.h> 14 15 #include <linux/idle_inject.h> 15 - #include <linux/of_device.h> 16 + #include <linux/of.h> 16 17 #include <linux/slab.h> 17 18 #include <linux/thermal.h> 18 19
+1 -1
drivers/virt/fsl_hypervisor.c
··· 796 796 if (!node) 797 797 return 0; 798 798 799 - ret = of_find_property(node, "fsl,hv-version", NULL) != NULL; 799 + ret = of_property_present(node, "fsl,hv-version"); 800 800 801 801 of_node_put(node); 802 802
+1 -1
drivers/w1/masters/w1-gpio.c
··· 87 87 * driver it high/low like we are in full control of the line and 88 88 * open drain will happen transparently. 89 89 */ 90 - if (of_get_property(np, "linux,open-drain", NULL)) 90 + if (of_property_present(np, "linux,open-drain")) 91 91 gflags = GPIOD_OUT_LOW; 92 92 93 93 pdev->dev.platform_data = pdata;
-1
include/linux/cpufreq.h
··· 15 15 #include <linux/kobject.h> 16 16 #include <linux/notifier.h> 17 17 #include <linux/of.h> 18 - #include <linux/of_device.h> 19 18 #include <linux/pm_opp.h> 20 19 #include <linux/pm_qos.h> 21 20 #include <linux/spinlock.h>
+20 -12
include/linux/of.h
··· 16 16 #include <linux/errno.h> 17 17 #include <linux/kobject.h> 18 18 #include <linux/mod_devicetable.h> 19 - #include <linux/spinlock.h> 20 - #include <linux/topology.h> 21 - #include <linux/notifier.h> 22 19 #include <linux/property.h> 23 20 #include <linux/list.h> 24 21 25 22 #include <asm/byteorder.h> 26 - #include <asm/errno.h> 27 23 28 24 typedef u32 phandle; 29 25 typedef u32 ihandle; ··· 141 145 extern struct device_node *of_chosen; 142 146 extern struct device_node *of_aliases; 143 147 extern struct device_node *of_stdout; 144 - extern raw_spinlock_t devtree_lock; 145 148 146 149 /* 147 150 * struct device_node flag descriptions ··· 356 361 const char *name, 357 362 int *lenp); 358 363 extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); 364 + extern struct device_node *of_cpu_device_node_get(int cpu); 365 + extern int of_cpu_node_to_id(struct device_node *np); 359 366 extern struct device_node *of_get_next_cpu_node(struct device_node *prev); 360 367 extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, 361 368 int index); ··· 370 373 extern int of_n_size_cells(struct device_node *np); 371 374 extern const struct of_device_id *of_match_node( 372 375 const struct of_device_id *matches, const struct device_node *node); 376 + extern const void *of_device_get_match_data(const struct device *dev); 373 377 extern int of_modalias_node(struct device_node *node, char *modalias, int len); 374 378 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args); 375 379 extern int __of_parse_phandle_with_args(const struct device_node *np, ··· 436 438 const char *of_prop_next_string(struct property *prop, const char *cur); 437 439 438 440 bool of_console_check(struct device_node *dn, char *name, int index); 439 - 440 - extern int of_cpu_node_to_id(struct device_node *np); 441 441 442 442 int of_map_id(struct device_node *np, u32 id, 443 443 const char *map_name, const char *map_mask_name, ··· 629 633 unsigned int *thread) 630 634 { 631 635 return NULL; 636 + } 637 + 638 + static inline struct device_node *of_cpu_device_node_get(int cpu) 639 + { 640 + return NULL; 641 + } 642 + 643 + static inline int of_cpu_node_to_id(struct device_node *np) 644 + { 645 + return -ENODEV; 632 646 } 633 647 634 648 static inline struct device_node *of_get_next_cpu_node(struct device_node *prev) ··· 843 837 { 844 838 } 845 839 846 - static inline int of_cpu_node_to_id(struct device_node *np) 847 - { 848 - return -ENODEV; 849 - } 850 - 851 840 static inline int of_map_id(struct device_node *np, u32 id, 852 841 const char *map_name, const char *map_mask_name, 853 842 struct device_node **target, u32 *id_out) ··· 853 852 static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np) 854 853 { 855 854 return PHYS_ADDR_MAX; 855 + } 856 + 857 + static inline const void *of_device_get_match_data(const struct device *dev) 858 + { 859 + return NULL; 856 860 } 857 861 858 862 #define of_match_ptr(_ptr) NULL ··· 1517 1511 OF_RECONFIG_CHANGE_ADD, 1518 1512 OF_RECONFIG_CHANGE_REMOVE, 1519 1513 }; 1514 + 1515 + struct notifier_block; 1520 1516 1521 1517 #ifdef CONFIG_OF_DYNAMIC 1522 1518 extern int of_reconfig_notifier_register(struct notifier_block *);
+31
include/linux/of_address.h
··· 35 35 for (; of_pci_range_parser_one(parser, range);) 36 36 #define for_each_of_range for_each_of_pci_range 37 37 38 + /* 39 + * of_range_count - Get the number of "ranges" or "dma-ranges" entries 40 + * @parser: Parser state initialized by of_range_parser_init() 41 + * 42 + * Returns the number of entries or 0 if none. 43 + * 44 + * Note that calling this within or after the for_each_of_range() iterator will 45 + * be inaccurate giving the number of entries remaining. 46 + */ 47 + static inline int of_range_count(const struct of_range_parser *parser) 48 + { 49 + if (!parser || !parser->node || !parser->range || parser->range == parser->end) 50 + return 0; 51 + return (parser->end - parser->range) / (parser->na + parser->pna + parser->ns); 52 + } 53 + 38 54 /* Translate a DMA address from device space to CPU space */ 39 55 extern u64 of_translate_dma_address(struct device_node *dev, 40 56 const __be32 *in_addr); ··· 72 56 extern const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, 73 57 u64 *size, unsigned int *flags); 74 58 59 + int of_property_read_reg(struct device_node *np, int idx, u64 *addr, u64 *size); 60 + 75 61 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, 76 62 struct device_node *node); 77 63 extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, ··· 86 68 extern int of_pci_range_to_resource(struct of_pci_range *range, 87 69 struct device_node *np, 88 70 struct resource *res); 71 + extern int of_range_to_resource(struct device_node *np, int index, 72 + struct resource *res); 89 73 extern bool of_dma_is_coherent(struct device_node *np); 90 74 #else /* CONFIG_OF_ADDRESS */ 91 75 static inline void __iomem *of_io_request_and_map(struct device_node *device, ··· 106 86 u64 *size, unsigned int *flags) 107 87 { 108 88 return NULL; 89 + } 90 + 91 + static inline int of_property_read_reg(struct device_node *np, int idx, u64 *addr, u64 *size) 92 + { 93 + return -ENOSYS; 109 94 } 110 95 111 96 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser, ··· 141 116 static inline int of_pci_range_to_resource(struct of_pci_range *range, 142 117 struct device_node *np, 143 118 struct resource *res) 119 + { 120 + return -ENOSYS; 121 + } 122 + 123 + static inline int of_range_to_resource(struct device_node *np, int index, 124 + struct resource *res) 144 125 { 145 126 return -ENOSYS; 146 127 }
+2 -27
include/linux/of_device.h
··· 2 2 #ifndef _LINUX_OF_DEVICE_H 3 3 #define _LINUX_OF_DEVICE_H 4 4 5 - #include <linux/cpu.h> 6 5 #include <linux/platform_device.h> 7 6 #include <linux/of_platform.h> /* temporary until merge */ 8 7 9 8 #include <linux/of.h> 10 - #include <linux/mod_devicetable.h> 11 9 12 10 struct device; 11 + struct of_device_id; 12 + struct kobj_uevent_env; 13 13 14 14 #ifdef CONFIG_OF 15 15 extern const struct of_device_id *of_match_device( ··· 26 26 return of_match_device(drv->of_match_table, dev) != NULL; 27 27 } 28 28 29 - extern int of_device_add(struct platform_device *pdev); 30 - extern int of_device_register(struct platform_device *ofdev); 31 - extern void of_device_unregister(struct platform_device *ofdev); 32 - 33 - extern const void *of_device_get_match_data(const struct device *dev); 34 - 35 29 extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len); 36 30 extern int of_device_request_module(struct device *dev); 37 31 38 32 extern void of_device_uevent(const struct device *dev, struct kobj_uevent_env *env); 39 33 extern int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *env); 40 - 41 - static inline struct device_node *of_cpu_device_node_get(int cpu) 42 - { 43 - struct device *cpu_dev; 44 - cpu_dev = get_cpu_device(cpu); 45 - if (!cpu_dev) 46 - return of_get_cpu_node(cpu, NULL); 47 - return of_node_get(cpu_dev->of_node); 48 - } 49 34 50 35 int of_dma_configure_id(struct device *dev, 51 36 struct device_node *np, ··· 52 67 static inline void of_device_uevent(const struct device *dev, 53 68 struct kobj_uevent_env *env) { } 54 69 55 - static inline const void *of_device_get_match_data(const struct device *dev) 56 - { 57 - return NULL; 58 - } 59 - 60 70 static inline int of_device_modalias(struct device *dev, 61 71 char *str, ssize_t len) 62 72 { ··· 71 91 72 92 static inline const struct of_device_id *of_match_device( 73 93 const struct of_device_id *matches, const struct device *dev) 74 - { 75 - return NULL; 76 - } 77 - 78 - static inline struct device_node *of_cpu_device_node_get(int cpu) 79 94 { 80 95 return NULL; 81 96 }
+8 -2
include/linux/of_platform.h
··· 6 6 * <benh@kernel.crashing.org> 7 7 */ 8 8 9 - #include <linux/device.h> 10 9 #include <linux/mod_devicetable.h> 11 - #include <linux/pm.h> 12 10 #include <linux/of_device.h> 13 11 #include <linux/platform_device.h> 12 + 13 + struct device; 14 + struct of_device_id; 14 15 15 16 /** 16 17 * struct of_dev_auxdata - lookup table entry for device names & platform_data ··· 53 52 extern struct platform_device *of_device_alloc(struct device_node *np, 54 53 const char *bus_id, 55 54 struct device *parent); 55 + 56 + extern int of_device_add(struct platform_device *pdev); 57 + extern int of_device_register(struct platform_device *ofdev); 58 + extern void of_device_unregister(struct platform_device *ofdev); 59 + 56 60 #ifdef CONFIG_OF 57 61 extern struct platform_device *of_find_device_by_node(struct device_node *np); 58 62 #else