From 3386e0fa905c31bf1dafa2cbe2ecceb7e5ce2e66 Mon Sep 17 00:00:00 2001 From: Joachim Eastwood Date: Wed, 6 May 2015 20:09:09 +0200 Subject: of: add helper function to retrive match data It's a common operation for device drivers to retrive the data member from of_device_id struct in their probe function. Most driver end up doing: const struct of_device_id *match; match = of_match_device(driver_of_match, &pdev->dev); driver->data = match->data; With the of_device_get_match_data helper function all this can done in one go. Signed-off-by: Joachim Eastwood [robh: add missing inline to dummmy declaration] Signed-off-by: Rob Herring --- drivers/of/device.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/device.c b/drivers/of/device.c index 20c1332a0018..8b91ea241b10 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -163,6 +163,18 @@ void of_device_unregister(struct platform_device *ofdev) } EXPORT_SYMBOL(of_device_unregister); +const void *of_device_get_match_data(const struct device *dev) +{ + const struct of_device_id *match; + + match = of_match_device(dev->driver->of_match_table, dev); + if (!match) + return NULL; + + return match->data; +} +EXPORT_SYMBOL(of_device_get_match_data); + ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) { const char *compat; -- cgit v1.2.3 From 3b1a2c97210b1edd1a999ff8c1f72ab28f7609f7 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 13 May 2015 16:33:56 +0200 Subject: of/fdt: Make fdt blob input parameters of unflatten functions const Operations to unflatten fdt blobs never modify the input blobs, hence make them const. Now we no longer need to cast arbitrary const data to "void *" when calling of_fdt_unflatten_tree(). Signed-off-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- drivers/of/fdt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index cde35c5d0191..9628c4a77f76 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -168,7 +168,7 @@ static void *unflatten_dt_alloc(void **mem, unsigned long size, * @dad: Parent struct device_node * @fpsize: Size of the node path up at the current depth. */ -static void * unflatten_dt_node(void *blob, +static void * unflatten_dt_node(const void *blob, void *mem, int *poffset, struct device_node *dad, @@ -378,7 +378,7 @@ static void * unflatten_dt_node(void *blob, * @dt_alloc: An allocator that provides a virtual address to memory * for the resulting tree */ -static void __unflatten_device_tree(void *blob, +static void __unflatten_device_tree(const void *blob, struct device_node **mynodes, void * (*dt_alloc)(u64 size, u64 align)) { @@ -441,7 +441,7 @@ static void *kernel_tree_alloc(u64 size, u64 align) * pointers of the nodes so the normal device-tree walking functions * can be used. */ -void of_fdt_unflatten_tree(unsigned long *blob, +void of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes) { __unflatten_device_tree(blob, mynodes, &kernel_tree_alloc); -- cgit v1.2.3 From 94a8bf974054e63dfb493f9c22db123c37200955 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 21 May 2015 14:10:26 +0200 Subject: of/overlay: Grammar s/an negative/a negative/ Signed-off-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- drivers/of/overlay.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index dee9270ba547..24e025f79299 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -333,7 +333,7 @@ static DEFINE_IDR(ov_idr); * of the overlay in a list. This list can be used to prevent * illegal overlay removals. * - * Returns the id of the created overlay, or an negative error number + * Returns the id of the created overlay, or a negative error number */ int of_overlay_create(struct device_node *tree) { @@ -481,7 +481,7 @@ static int overlay_removal_is_ok(struct of_overlay *ov) * * Removes an overlay if it is permissible. * - * Returns 0 on success, or an negative error number + * Returns 0 on success, or a negative error number */ int of_overlay_destroy(int id) { @@ -528,7 +528,7 @@ EXPORT_SYMBOL_GPL(of_overlay_destroy); * * Removes all overlays from the system in the correct order. * - * Returns 0 on success, or an negative error number + * Returns 0 on success, or a negative error number */ int of_overlay_destroy_all(void) { -- cgit v1.2.3 From c8fff7bc5bba6bd59cad40441c189c4efe7190f6 Mon Sep 17 00:00:00 2001 From: Konstantin Khlebnikov Date: Wed, 8 Apr 2015 19:59:20 +0300 Subject: of: return NUMA_NO_NODE from fallback of_node_to_nid() Node 0 might be offline as well as any other numa node, in this case kernel cannot handle memory allocation and crashes. Signed-off-by: Konstantin Khlebnikov Fixes: 0c3f061c195c ("of: implement of_node_to_nid as a weak function") Signed-off-by: Grant Likely --- drivers/of/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/base.c b/drivers/of/base.c index 99764db0875a..8e39b38ca206 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -89,7 +89,7 @@ EXPORT_SYMBOL(of_n_size_cells); #ifdef CONFIG_NUMA int __weak of_node_to_nid(struct device_node *np) { - return numa_node_id(); + return NUMA_NO_NODE; } #endif -- cgit v1.2.3 From ce32f859646bab2ed724393398b90aa50149bb44 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 13 Apr 2015 10:30:20 +0900 Subject: of/fdt: fix argument name and add comments of unflatten_dt_node() Match the name of the third argument in the comment block to the actual function: p -> poffset Add missing comments about the arguments "nodepp" and "dryrun". Signed-off-by: Masahiro Yamada Signed-off-by: Grant Likely --- drivers/of/fdt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index cde35c5d0191..293f80bd83dd 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -164,9 +164,12 @@ static void *unflatten_dt_alloc(void **mem, unsigned long size, * unflatten_dt_node - Alloc and populate a device_node from the flat tree * @blob: The parent device tree blob * @mem: Memory chunk to use for allocating device nodes and properties - * @p: pointer to node in flat tree + * @poffset: pointer to node in flat tree * @dad: Parent struct device_node + * @nodepp: The device_node tree created by the call * @fpsize: Size of the node path up at the current depth. + * @dryrun: If true, do not allocate device nodes but still calculate needed + * memory size */ static void * unflatten_dt_node(void *blob, void *mem, -- cgit v1.2.3 From 0166dc11be911213e0b1b764488c671be4c48cf3 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Thu, 28 May 2015 12:48:45 -0500 Subject: of: make CONFIG_OF user selectable With the addition of overlays, it is now plausible to use DT on any arch and without an arch using it at boot time. It is also desirable to expand the compile coverage of the DT code. Make CONFIG_OF user selectable by converting the menu to menuconfig. Signed-off-by: Rob Herring Acked-by: Geert Uytterhoeven Acked-by: Pantelis Antoniou Acked-by: Grant Likely --- drivers/of/Kconfig | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 07bb3c8f191b..fdf7e41e8a4b 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -1,11 +1,15 @@ config DTC bool -config OF - bool +menuconfig OF + bool "Device Tree and Open Firmware support" + help + This option enables the device tree infrastructure. + It is automatically selected by platforms that need it or can + be enabled manually for unittests, overlays or + compile-coverage. -menu "Device Tree and Open Firmware support" - depends on OF +if OF config OF_UNITTEST bool "Device Tree runtime unit tests" @@ -97,4 +101,4 @@ config OF_OVERLAY While this option is selected automatically when needed, you can enable it manually to improve device tree unit test coverage. -endmenu # OF +endif # OF -- cgit v1.2.3 From 649e0a77e28a7796bf62bfda0fe3f2aee094bd58 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Thu, 28 May 2015 12:58:02 -0500 Subject: of: make unittest select OF_EARLY_FLATTREE instead of depend on it The DT unittest currently requires an arch (typically) to select OF_EARLY_FLATTREE. Remove this dependency by selecting it directly so that the unittest can be enabled easily on any architecture. With this and the prior commit, we can easily enable and run unittests starting with x86 defconfig rather than hunting for the combination of config options to enable OF on x86. Signed-off-by: Rob Herring Cc: Geert Uytterhoeven Cc: Pantelis Antoniou Acked-by: Grant Likely --- drivers/of/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index fdf7e41e8a4b..8df1b1777745 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -13,7 +13,8 @@ if OF config OF_UNITTEST bool "Device Tree runtime unit tests" - depends on OF_IRQ && OF_EARLY_FLATTREE + depends on OF_IRQ + select OF_EARLY_FLATTREE select OF_RESOLVE help This option builds in test cases for the device tree infrastructure -- cgit v1.2.3 From 63a4aea556704acba1529df8f896ed65b93e66c1 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 1 Jun 2015 08:42:48 -0500 Subject: of: clean-up unnecessary libfdt include paths With the libfdt include fixups to use "" instead of <> in the latest dtc import in commit 4760597 (scripts/dtc: Update to upstream version 9d3649bd3be245c9), it is no longer necessary to add explicit include paths to use libfdt. Remove these across the kernel. Signed-off-by: Rob Herring Acked-by: Ralf Baechle Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Acked-by: Michael Ellerman Acked-by: Grant Likely Cc: linux-mips@linux-mips.org Cc: linuxppc-dev@lists.ozlabs.org --- drivers/of/Makefile | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/Makefile b/drivers/of/Makefile index fcacb186a67b..156c072b3117 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -16,6 +16,3 @@ obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/ - -CFLAGS_fdt.o = -I$(src)/../../scripts/dtc/libfdt -CFLAGS_fdt_address.o = -I$(src)/../../scripts/dtc/libfdt -- cgit v1.2.3 From aefc7ec27c318faa58e7e92dbe85217b2bab7a0e Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Thu, 18 Jun 2015 20:35:46 -0500 Subject: dt/fdt: add empty versions of early_init_dt_*_memory_arch With the addition of commit 0166dc1 (of: make CONFIG_OF user selectable), architectures which don't enable memblock and don't have their own early_init_dt_*_memory_arch implementations will break when CONFIG_OF is enabled. Really, we should have better separation of CONFIG_OF and CONFIG_OF_EARLY_FLATTREE, but doing that will require quite a bit of shuffling of architecture code. That will have to wait for another day. Signed-off-by: Rob Herring Cc: Grant Likely --- drivers/of/fdt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 9628c4a77f76..0e314ba1f985 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1015,6 +1015,11 @@ void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align) return __va(memblock_alloc(size, align)); } #else +void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) +{ + WARN_ON(1); +} + int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size, bool nomap) { @@ -1022,6 +1027,12 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base, &base, &size, nomap ? " (nomap)" : ""); return -ENOSYS; } + +void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align) +{ + WARN_ON(1); + return NULL; +} #endif bool __init early_init_dt_verify(void *params) -- cgit v1.2.3 From 294240ffe784e951dc2ef070da04fa31ef6db3a0 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Thu, 18 Jun 2015 00:12:27 +0900 Subject: of/address: use atomic allocation in pci_register_io_range() When kzalloc() is called under spin_lock(), GFP_ATOMIC should be used to avoid sleeping allocation. The call tree is: of_pci_range_to_resource() --> pci_register_io_range() <-- takes spin_lock(&io_range_lock); --> kzalloc() Signed-off-by: Jingoo Han Cc: stable@vger.kernel.org # 3.18+ Signed-off-by: Rob Herring --- drivers/of/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/address.c b/drivers/of/address.c index 78a7dcbec7d8..65c3289fb2dc 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -712,7 +712,7 @@ int __weak pci_register_io_range(phys_addr_t addr, resource_size_t size) } /* add the range to the list */ - range = kzalloc(sizeof(*range), GFP_KERNEL); + range = kzalloc(sizeof(*range), GFP_ATOMIC); if (!range) { err = -ENOMEM; goto end_register; -- cgit v1.2.3 From d23b251669e20b3989643d9c38228039c510478f Mon Sep 17 00:00:00 2001 From: Jeremy Linton Date: Mon, 29 Jun 2015 18:50:55 -0500 Subject: of/irq: Fix pSeries boot failure of_irq_parse_raw() needs to return the correct interrupt controller node when an interrupt-map property doesn't exist. It allows of_irq_parse_raw() to return the node pointer of the interrupt controller, rather than the parent bus. This allows ics_rtas_host_match() to detect that the controller is a legacy 8259 and avoid using xics. This avoids an RTAS assertion/crash during early kernel bootstrapping. Signed-off-by: Jeremy Linton Reviewed-by: Benjamin Herrenschmidt Signed-off-by: Grant Likely --- drivers/of/irq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 1a7980692f25..cb4b9aeaa10d 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -252,8 +252,6 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq) * Successfully parsed an interrrupt-map translation; copy new * interrupt specifier into the out_irq structure */ - out_irq->np = newpar; - match_array = imap - newaddrsize - newintsize; for (i = 0; i < newintsize; i++) out_irq->args[i] = be32_to_cpup(imap - newintsize + i); @@ -262,6 +260,7 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq) skiplevel: /* Iterate again with new parent */ + out_irq->np = newpar; pr_debug(" -> new parent: %s\n", of_node_full_name(newpar)); of_node_put(ipar); ipar = newpar; -- cgit v1.2.3 From 48a9b733e644ab4cc8e2a98950a36ddb12b8c54e Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 26 Jun 2015 14:42:45 +0200 Subject: of/irq: Rename "intc_desc" to "of_intc_desc" to fix OF on sh Now CONFIG_OF can be enabled on sh: drivers/of/irq.c:472:8: error: redefinition of 'struct intc_desc' include/linux/sh_intc.h:109:8: note: originally defined here As "intc_desc" is used all over the place in sh platform code, while drivers/of/irq.c has a local definition used in a single function, rename the latter by prefixing it with "of_". Signed-off-by: Geert Uytterhoeven Signed-off-by: Grant Likely --- drivers/of/irq.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/irq.c b/drivers/of/irq.c index cb4b9aeaa10d..3cf7a01f557f 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -468,7 +468,7 @@ int of_irq_to_resource_table(struct device_node *dev, struct resource *res, } EXPORT_SYMBOL_GPL(of_irq_to_resource_table); -struct intc_desc { +struct of_intc_desc { struct list_head list; struct device_node *dev; struct device_node *interrupt_parent; @@ -484,7 +484,7 @@ struct intc_desc { void __init of_irq_init(const struct of_device_id *matches) { struct device_node *np, *parent = NULL; - struct intc_desc *desc, *temp_desc; + struct of_intc_desc *desc, *temp_desc; struct list_head intc_desc_list, intc_parent_list; INIT_LIST_HEAD(&intc_desc_list); @@ -495,7 +495,7 @@ void __init of_irq_init(const struct of_device_id *matches) !of_device_is_available(np)) continue; /* - * Here, we allocate and populate an intc_desc with the node + * Here, we allocate and populate an of_intc_desc with the node * pointer, interrupt-parent device_node etc. */ desc = kzalloc(sizeof(*desc), GFP_KERNEL); -- cgit v1.2.3