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 +++--- include/linux/of_fdt.h | 2 +- 2 files changed, 4 insertions(+), 4 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); diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index 587ee507965d..0cf217d404ce 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,7 +37,7 @@ extern bool of_fdt_is_big_endian(const void *blob, unsigned long node); extern int of_fdt_match(const void *blob, unsigned long node, const char *const *compat); -extern void of_fdt_unflatten_tree(unsigned long *blob, +extern void of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ -- 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 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 --- arch/mips/cavium-octeon/Makefile | 3 --- arch/mips/mti-sead3/Makefile | 2 -- arch/powerpc/kernel/Makefile | 1 - drivers/firmware/efi/libstub/Makefile | 2 -- drivers/of/Makefile | 3 --- 5 files changed, 11 deletions(-) (limited to 'drivers/of') diff --git a/arch/mips/cavium-octeon/Makefile b/arch/mips/cavium-octeon/Makefile index 69a8a8dabc2b..2a5926578841 100644 --- a/arch/mips/cavium-octeon/Makefile +++ b/arch/mips/cavium-octeon/Makefile @@ -9,9 +9,6 @@ # Copyright (C) 2005-2009 Cavium Networks # -CFLAGS_octeon-platform.o = -I$(src)/../../../scripts/dtc/libfdt -CFLAGS_setup.o = -I$(src)/../../../scripts/dtc/libfdt - obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o obj-y += dma-octeon.o obj-y += octeon-memcpy.o diff --git a/arch/mips/mti-sead3/Makefile b/arch/mips/mti-sead3/Makefile index ecd71db6258b..2e52cbd20ceb 100644 --- a/arch/mips/mti-sead3/Makefile +++ b/arch/mips/mti-sead3/Makefile @@ -15,5 +15,3 @@ obj-y := sead3-lcd.o sead3-display.o sead3-init.o \ obj-y += leds-sead3.o obj-$(CONFIG_EARLY_PRINTK) += sead3-console.o - -CFLAGS_sead3-setup.o = -I$(src)/../../../scripts/dtc/libfdt diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index c1ebbdaac28f..c16e8362432b 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -2,7 +2,6 @@ # Makefile for the linux kernel. # -CFLAGS_prom.o = -I$(src)/../../../scripts/dtc/libfdt CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 280bc0a63365..816dbe9f4b82 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -24,8 +24,6 @@ KASAN_SANITIZE := n lib-y := efi-stub-helper.o lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o -CFLAGS_fdt.o += -I$(srctree)/scripts/dtc/libfdt/ - # # arm64 puts the stub in the kernel proper, which will unnecessarily retain all # code indefinitely unless it is annotated as __init/__initdata/__initconst etc. 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