aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c16
-rw-r--r--drivers/of/dynamic.c3
-rw-r--r--drivers/of/fdt.c16
-rw-r--r--drivers/of/irq.c17
-rw-r--r--drivers/of/selftest.c40
5 files changed, 67 insertions, 25 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d8574adf0d62..293ed4b687ba 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -138,6 +138,9 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp)
138 /* Important: Don't leak passwords */ 138 /* Important: Don't leak passwords */
139 bool secure = strncmp(pp->name, "security-", 9) == 0; 139 bool secure = strncmp(pp->name, "security-", 9) == 0;
140 140
141 if (!IS_ENABLED(CONFIG_SYSFS))
142 return 0;
143
141 if (!of_kset || !of_node_is_attached(np)) 144 if (!of_kset || !of_node_is_attached(np))
142 return 0; 145 return 0;
143 146
@@ -158,6 +161,9 @@ int __of_attach_node_sysfs(struct device_node *np)
158 struct property *pp; 161 struct property *pp;
159 int rc; 162 int rc;
160 163
164 if (!IS_ENABLED(CONFIG_SYSFS))
165 return 0;
166
161 if (!of_kset) 167 if (!of_kset)
162 return 0; 168 return 0;
163 169
@@ -1713,6 +1719,9 @@ int __of_remove_property(struct device_node *np, struct property *prop)
1713 1719
1714void __of_remove_property_sysfs(struct device_node *np, struct property *prop) 1720void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
1715{ 1721{
1722 if (!IS_ENABLED(CONFIG_SYSFS))
1723 return;
1724
1716 /* at early boot, bail here and defer setup to of_init() */ 1725 /* at early boot, bail here and defer setup to of_init() */
1717 if (of_kset && of_node_is_attached(np)) 1726 if (of_kset && of_node_is_attached(np))
1718 sysfs_remove_bin_file(&np->kobj, &prop->attr); 1727 sysfs_remove_bin_file(&np->kobj, &prop->attr);
@@ -1777,6 +1786,9 @@ int __of_update_property(struct device_node *np, struct property *newprop,
1777void __of_update_property_sysfs(struct device_node *np, struct property *newprop, 1786void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
1778 struct property *oldprop) 1787 struct property *oldprop)
1779{ 1788{
1789 if (!IS_ENABLED(CONFIG_SYSFS))
1790 return;
1791
1780 /* At early boot, bail out and defer setup to of_init() */ 1792 /* At early boot, bail out and defer setup to of_init() */
1781 if (!of_kset) 1793 if (!of_kset)
1782 return; 1794 return;
@@ -1847,6 +1859,7 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
1847{ 1859{
1848 struct property *pp; 1860 struct property *pp;
1849 1861
1862 of_aliases = of_find_node_by_path("/aliases");
1850 of_chosen = of_find_node_by_path("/chosen"); 1863 of_chosen = of_find_node_by_path("/chosen");
1851 if (of_chosen == NULL) 1864 if (of_chosen == NULL)
1852 of_chosen = of_find_node_by_path("/chosen@0"); 1865 of_chosen = of_find_node_by_path("/chosen@0");
@@ -1862,7 +1875,6 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
1862 of_stdout = of_find_node_by_path(name); 1875 of_stdout = of_find_node_by_path(name);
1863 } 1876 }
1864 1877
1865 of_aliases = of_find_node_by_path("/aliases");
1866 if (!of_aliases) 1878 if (!of_aliases)
1867 return; 1879 return;
1868 1880
@@ -1986,7 +1998,7 @@ bool of_console_check(struct device_node *dn, char *name, int index)
1986{ 1998{
1987 if (!dn || dn != of_stdout || console_set_on_cmdline) 1999 if (!dn || dn != of_stdout || console_set_on_cmdline)
1988 return false; 2000 return false;
1989 return add_preferred_console(name, index, NULL); 2001 return !add_preferred_console(name, index, NULL);
1990} 2002}
1991EXPORT_SYMBOL_GPL(of_console_check); 2003EXPORT_SYMBOL_GPL(of_console_check);
1992 2004
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 54fecc49a1fe..f297891d8529 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -45,6 +45,9 @@ void __of_detach_node_sysfs(struct device_node *np)
45{ 45{
46 struct property *pp; 46 struct property *pp;
47 47
48 if (!IS_ENABLED(CONFIG_SYSFS))
49 return;
50
48 BUG_ON(!of_node_is_initialized(np)); 51 BUG_ON(!of_node_is_initialized(np));
49 if (!of_kset) 52 if (!of_kset)
50 return; 53 return;
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index f46a24ffa3fe..d1ffca8b34ea 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -453,7 +453,7 @@ static int __init __reserved_mem_reserve_reg(unsigned long node,
453 base = dt_mem_next_cell(dt_root_addr_cells, &prop); 453 base = dt_mem_next_cell(dt_root_addr_cells, &prop);
454 size = dt_mem_next_cell(dt_root_size_cells, &prop); 454 size = dt_mem_next_cell(dt_root_size_cells, &prop);
455 455
456 if (base && size && 456 if (size &&
457 early_init_dt_reserve_memory_arch(base, size, nomap) == 0) 457 early_init_dt_reserve_memory_arch(base, size, nomap) == 0)
458 pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %ld MiB\n", 458 pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %ld MiB\n",
459 uname, &base, (unsigned long)size / SZ_1M); 459 uname, &base, (unsigned long)size / SZ_1M);
@@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
928void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) 928void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
929{ 929{
930 const u64 phys_offset = __pa(PAGE_OFFSET); 930 const u64 phys_offset = __pa(PAGE_OFFSET);
931 base &= PAGE_MASK; 931
932 if (!PAGE_ALIGNED(base)) {
933 size -= PAGE_SIZE - (base & ~PAGE_MASK);
934 base = PAGE_ALIGN(base);
935 }
932 size &= PAGE_MASK; 936 size &= PAGE_MASK;
933 937
934 if (base > MAX_PHYS_ADDR) { 938 if (base > MAX_PHYS_ADDR) {
@@ -937,10 +941,10 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
937 return; 941 return;
938 } 942 }
939 943
940 if (base + size > MAX_PHYS_ADDR) { 944 if (base + size - 1 > MAX_PHYS_ADDR) {
941 pr_warning("Ignoring memory range 0x%lx - 0x%llx\n", 945 pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
942 ULONG_MAX, base + size); 946 ((u64)MAX_PHYS_ADDR) + 1, base + size);
943 size = MAX_PHYS_ADDR - base; 947 size = MAX_PHYS_ADDR - base + 1;
944 } 948 }
945 949
946 if (base + size < phys_offset) { 950 if (base + size < phys_offset) {
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 3e06a699352d..1471e0a223a5 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -301,16 +301,17 @@ int of_irq_parse_one(struct device_node *device, int index, struct of_phandle_ar
301 /* Get the reg property (if any) */ 301 /* Get the reg property (if any) */
302 addr = of_get_property(device, "reg", NULL); 302 addr = of_get_property(device, "reg", NULL);
303 303
304 /* Try the new-style interrupts-extended first */
305 res = of_parse_phandle_with_args(device, "interrupts-extended",
306 "#interrupt-cells", index, out_irq);
307 if (!res)
308 return of_irq_parse_raw(addr, out_irq);
309
304 /* Get the interrupts property */ 310 /* Get the interrupts property */
305 intspec = of_get_property(device, "interrupts", &intlen); 311 intspec = of_get_property(device, "interrupts", &intlen);
306 if (intspec == NULL) { 312 if (intspec == NULL)
307 /* Try the new-style interrupts-extended */ 313 return -EINVAL;
308 res = of_parse_phandle_with_args(device, "interrupts-extended", 314
309 "#interrupt-cells", index, out_irq);
310 if (res)
311 return -EINVAL;
312 return of_irq_parse_raw(addr, out_irq);
313 }
314 intlen /= sizeof(*intspec); 315 intlen /= sizeof(*intspec);
315 316
316 pr_debug(" intspec=%d intlen=%d\n", be32_to_cpup(intspec), intlen); 317 pr_debug(" intspec=%d intlen=%d\n", be32_to_cpup(intspec), intlen);
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index d41002667833..a737cb5974de 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -27,6 +27,7 @@ static struct selftest_results {
27#define NO_OF_NODES 2 27#define NO_OF_NODES 2
28static struct device_node *nodes[NO_OF_NODES]; 28static struct device_node *nodes[NO_OF_NODES];
29static int last_node_index; 29static int last_node_index;
30static bool selftest_live_tree;
30 31
31#define selftest(result, fmt, ...) { \ 32#define selftest(result, fmt, ...) { \
32 if (!(result)) { \ 33 if (!(result)) { \
@@ -630,13 +631,6 @@ static int attach_node_and_children(struct device_node *np)
630{ 631{
631 struct device_node *next, *root = np, *dup; 632 struct device_node *next, *root = np, *dup;
632 633
633 if (!np) {
634 pr_warn("%s: No tree to attach; not running tests\n",
635 __func__);
636 return -ENODATA;
637 }
638
639
640 /* skip root node */ 634 /* skip root node */
641 np = np->child; 635 np = np->child;
642 /* storing a copy in temporary node */ 636 /* storing a copy in temporary node */
@@ -672,12 +666,12 @@ static int attach_node_and_children(struct device_node *np)
672static int __init selftest_data_add(void) 666static int __init selftest_data_add(void)
673{ 667{
674 void *selftest_data; 668 void *selftest_data;
675 struct device_node *selftest_data_node; 669 struct device_node *selftest_data_node, *np;
676 extern uint8_t __dtb_testcases_begin[]; 670 extern uint8_t __dtb_testcases_begin[];
677 extern uint8_t __dtb_testcases_end[]; 671 extern uint8_t __dtb_testcases_end[];
678 const int size = __dtb_testcases_end - __dtb_testcases_begin; 672 const int size = __dtb_testcases_end - __dtb_testcases_begin;
679 673
680 if (!size || !of_allnodes) { 674 if (!size) {
681 pr_warn("%s: No testcase data to attach; not running tests\n", 675 pr_warn("%s: No testcase data to attach; not running tests\n",
682 __func__); 676 __func__);
683 return -ENODATA; 677 return -ENODATA;
@@ -692,6 +686,22 @@ static int __init selftest_data_add(void)
692 return -ENOMEM; 686 return -ENOMEM;
693 } 687 }
694 of_fdt_unflatten_tree(selftest_data, &selftest_data_node); 688 of_fdt_unflatten_tree(selftest_data, &selftest_data_node);
689 if (!selftest_data_node) {
690 pr_warn("%s: No tree to attach; not running tests\n", __func__);
691 return -ENODATA;
692 }
693
694 if (!of_allnodes) {
695 /* enabling flag for removing nodes */
696 selftest_live_tree = true;
697 of_allnodes = selftest_data_node;
698
699 for_each_of_allnodes(np)
700 __of_attach_node_sysfs(np);
701 of_aliases = of_find_node_by_path("/aliases");
702 of_chosen = of_find_node_by_path("/chosen");
703 return 0;
704 }
695 705
696 /* attach the sub-tree to live tree */ 706 /* attach the sub-tree to live tree */
697 return attach_node_and_children(selftest_data_node); 707 return attach_node_and_children(selftest_data_node);
@@ -723,6 +733,18 @@ static void selftest_data_remove(void)
723 struct device_node *np; 733 struct device_node *np;
724 struct property *prop; 734 struct property *prop;
725 735
736 if (selftest_live_tree) {
737 of_node_put(of_aliases);
738 of_node_put(of_chosen);
739 of_aliases = NULL;
740 of_chosen = NULL;
741 for_each_child_of_node(of_allnodes, np)
742 detach_node_and_children(np);
743 __of_detach_node_sysfs(of_allnodes);
744 of_allnodes = NULL;
745 return;
746 }
747
726 while (last_node_index >= 0) { 748 while (last_node_index >= 0) {
727 if (nodes[last_node_index]) { 749 if (nodes[last_node_index]) {
728 np = of_find_node_by_path(nodes[last_node_index]->full_name); 750 np = of_find_node_by_path(nodes[last_node_index]->full_name);