From 63c60e3a6dc3eca53714e8a1784c985a552bc5cd Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sun, 5 Apr 2015 16:59:24 +0200 Subject: of: OF_IRQ should depend on IRQ_DOMAIN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If CONFIG_IRQ_DOMAIN=n: drivers/of/irq.c: In function ‘of_irq_get’: drivers/of/irq.c:406: error: implicit declaration of function ‘irq_find_host’ drivers/of/irq.c:406: warning: assignment makes pointer from integer without a cast make[2]: *** [drivers/of/irq.o] Error 1 Signed-off-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- drivers/of/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 7bcaeec876c0..0638efd15fdd 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -46,7 +46,7 @@ config OF_ADDRESS_PCI config OF_IRQ def_bool y - depends on !SPARC + depends on !SPARC && IRQ_DOMAIN config OF_NET depends on NETDEVICES -- cgit v1.2.3 From c954b36e3f5bfdd5aeceba49614a4864d7efec87 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Sun, 12 Apr 2015 13:16:26 -0700 Subject: of/fdt: Remove "reg" data prints from early_init_dt_scan_memory Commit 51975db0b7333 ("of/flattree: merge early_init_dt_scan_memory() common code") consolidated some code from PowerPC (typically big-endian), and ended-up adding a pr_debug() printing reg properties in big-endian (DT native) format, not CPU endian. This debug print suffers from two problems: - we only print 4 "reg" values, while there could be more on typical systems having multiple memory ranges - we print these 4 "reg" values in FDT endianess, that is big-endian, and these values could be confusing for little-endian configurations Since we are already printing the base address and size of the memory regions parsed by early_init_dt_scan_memory() later in a way that is both endian correct, and takes into account arbitrary number of memory banks, just remove that part of the debug print. Suggested-by: Frank Rowand Signed-off-by: Florian Fainelli Signed-off-by: Rob Herring --- drivers/of/fdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 3a896c9aeb74..34bdc4de83d0 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -879,8 +879,7 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname, endp = reg + (l / sizeof(__be32)); - pr_debug("memory scan node %s, reg size %d, data: %x %x %x %x,\n", - uname, l, reg[0], reg[1], reg[2], reg[3]); + pr_debug("memory scan node %s, reg size %d,\n", uname, l); while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { u64 base, size; -- cgit v1.2.3 From 37786c7fee40771d13901de129af7e084ed48b55 Mon Sep 17 00:00:00 2001 From: Kevin Cernekee Date: Thu, 9 Apr 2015 13:05:14 -0700 Subject: of: Add helper function to check MMIO register endianness SoC peripherals can come in several different flavors: - little-endian: registers always need to be accessed in LE mode (so the kernel should perform a swap if the CPU is running BE) - big-endian: registers always need to be accessed in BE mode (so the kernel should perform a swap if the CPU is running LE) - native-endian: the bus will automatically swap accesses, so the kernel should never swap Introduce a function that checks an OF device node to see whether it contains a "big-endian" or "native-endian" property. For the former case, always return true. For the latter case, return true iff the kernel was built for BE (implying that the BE MMIO accessors do not perform a swap). Otherwise return false, assuming LE registers. LE registers are assumed by default because most existing drivers (libahci, serial8250, usb) always use readl/writel in the absence of instructions to the contrary, so that will be our fallback. Signed-off-by: Kevin Cernekee Reviewed-by: Peter Hurley Acked-by: Greg Kroah-Hartman Signed-off-by: Rob Herring --- drivers/of/base.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'drivers') diff --git a/drivers/of/base.c b/drivers/of/base.c index 69566b6a876d..31ca3c8dae61 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -567,6 +567,29 @@ bool of_device_is_available(const struct device_node *device) } EXPORT_SYMBOL(of_device_is_available); +/** + * of_device_is_big_endian - check if a device has BE registers + * + * @device: Node to check for endianness + * + * Returns true if the device has a "big-endian" property, or if the kernel + * was compiled for BE *and* the device has a "native-endian" property. + * Returns false otherwise. + * + * Callers would nominally use ioread32be/iowrite32be if + * of_device_is_big_endian() == true, or readl/writel otherwise. + */ +bool of_device_is_big_endian(const struct device_node *device) +{ + if (of_property_read_bool(device, "big-endian")) + return true; + if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && + of_property_read_bool(device, "native-endian")) + return true; + return false; +} +EXPORT_SYMBOL(of_device_is_big_endian); + /** * of_get_parent - Get a node's parent if any * @node: Node to get parent -- cgit v1.2.3 From cc7837867a559feba70fdf68eb53c24a84e3712f Mon Sep 17 00:00:00 2001 From: Kevin Cernekee Date: Thu, 9 Apr 2015 13:05:15 -0700 Subject: of/fdt: Add endianness helper function for early init code Provide a libfdt-based equivalent for of_device_is_big_endian(), suitable for use in the early_init_* functions. Signed-off-by: Kevin Cernekee Reviewed-by: Peter Hurley Acked-by: Greg Kroah-Hartman Signed-off-by: Rob Herring --- drivers/of/fdt.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'drivers') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 34bdc4de83d0..4b15aa163b6e 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -108,6 +108,25 @@ int of_fdt_is_compatible(const void *blob, return 0; } +/** + * of_fdt_is_big_endian - Return true if given node needs BE MMIO accesses + * @blob: A device tree blob + * @node: node to test + * + * Returns true if the node has a "big-endian" property, or if the kernel + * was compiled for BE *and* the node has a "native-endian" property. + * Returns false otherwise. + */ +bool of_fdt_is_big_endian(const void *blob, unsigned long node) +{ + if (fdt_getprop(blob, node, "big-endian", NULL)) + return true; + if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && + fdt_getprop(blob, node, "native-endian", NULL)) + return true; + return false; +} + /** * of_fdt_match - Return true if node matches a list of compatible values */ -- cgit v1.2.3 From c627f2ceb692e8a9358b64ac2d139314e7bb0d17 Mon Sep 17 00:00:00 2001 From: Kevin Cernekee Date: Thu, 9 Apr 2015 13:05:17 -0700 Subject: serial: 8250: Add support for big-endian MMIO accesses Add cases for UPIO_MEM32BE wherever there are currently cases handling UPIO_MEM32. Signed-off-by: Kevin Cernekee Reviewed-by: Peter Hurley Acked-by: Greg Kroah-Hartman Signed-off-by: Rob Herring --- drivers/tty/serial/8250/8250_core.c | 20 ++++++++++++++++++++ drivers/tty/serial/8250/8250_early.c | 5 +++++ 2 files changed, 25 insertions(+) (limited to 'drivers') diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index deae122c9c4b..0bffa735eaa1 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -439,6 +439,18 @@ static unsigned int mem32_serial_in(struct uart_port *p, int offset) return readl(p->membase + offset); } +static void mem32be_serial_out(struct uart_port *p, int offset, int value) +{ + offset = offset << p->regshift; + iowrite32be(value, p->membase + offset); +} + +static unsigned int mem32be_serial_in(struct uart_port *p, int offset) +{ + offset = offset << p->regshift; + return ioread32be(p->membase + offset); +} + static unsigned int io_serial_in(struct uart_port *p, int offset) { offset = offset << p->regshift; @@ -477,6 +489,11 @@ static void set_io_from_upio(struct uart_port *p) p->serial_out = mem32_serial_out; break; + case UPIO_MEM32BE: + p->serial_in = mem32be_serial_in; + p->serial_out = mem32be_serial_out; + break; + #if defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_SERIAL_8250_RT288X) case UPIO_AU: p->serial_in = au_serial_in; @@ -502,6 +519,7 @@ serial_port_out_sync(struct uart_port *p, int offset, int value) switch (p->iotype) { case UPIO_MEM: case UPIO_MEM32: + case UPIO_MEM32BE: case UPIO_AU: p->serial_out(p, offset, value); p->serial_in(p, UART_LCR); /* safe, no side-effects */ @@ -2743,6 +2761,7 @@ static int serial8250_request_std_resource(struct uart_8250_port *up) case UPIO_AU: case UPIO_TSI: case UPIO_MEM32: + case UPIO_MEM32BE: case UPIO_MEM: if (!port->mapbase) break; @@ -2779,6 +2798,7 @@ static void serial8250_release_std_resource(struct uart_8250_port *up) case UPIO_AU: case UPIO_TSI: case UPIO_MEM32: + case UPIO_MEM32BE: case UPIO_MEM: if (!port->mapbase) break; diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c index c31a22b4f845..84f6d11bbeed 100644 --- a/drivers/tty/serial/8250/8250_early.c +++ b/drivers/tty/serial/8250/8250_early.c @@ -45,6 +45,8 @@ unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offse return readb(port->membase + offset); case UPIO_MEM32: return readl(port->membase + (offset << 2)); + case UPIO_MEM32BE: + return ioread32be(port->membase + (offset << 2)); case UPIO_PORT: return inb(port->iobase + offset); default: @@ -61,6 +63,9 @@ void __weak __init serial8250_early_out(struct uart_port *port, int offset, int case UPIO_MEM32: writel(value, port->membase + (offset << 2)); break; + case UPIO_MEM32BE: + iowrite32be(value, port->membase + (offset << 2)); + break; case UPIO_PORT: outb(value, port->iobase + offset); break; -- cgit v1.2.3 From ebc5e20082160df384dedbe1c95066c3e545b689 Mon Sep 17 00:00:00 2001 From: Kevin Cernekee Date: Thu, 9 Apr 2015 13:05:18 -0700 Subject: serial: of_serial: Support big-endian register accesses If the device node has a "big-endian" property and 32-bit registers, tell the serial driver to use UPIO_MEM32BE instead of UPIO_MEM32. Signed-off-by: Kevin Cernekee Acked-by: Greg Kroah-Hartman Signed-off-by: Rob Herring --- drivers/tty/serial/of_serial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c index 33fb94f78967..e15c443b2a3c 100644 --- a/drivers/tty/serial/of_serial.c +++ b/drivers/tty/serial/of_serial.c @@ -115,7 +115,8 @@ static int of_platform_serial_setup(struct platform_device *ofdev, port->iotype = UPIO_MEM; break; case 4: - port->iotype = UPIO_MEM32; + port->iotype = of_device_is_big_endian(np) ? + UPIO_MEM32BE : UPIO_MEM32; break; default: dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n", -- cgit v1.2.3 From 05f4647b10233dd2e18106abb16ff7fb68abbd08 Mon Sep 17 00:00:00 2001 From: Ricky Liang Date: Tue, 14 Apr 2015 12:36:05 +0800 Subject: of/fdt: fix allocation size for device node path The allocation size of device node path is off by one which drops the '\0' terminator. Signed-off-by: Ricky Liang Signed-off-by: Rob Herring --- drivers/of/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 4b15aa163b6e..cde35c5d0191 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -191,7 +191,7 @@ static void * unflatten_dt_node(void *blob, if (!pathp) return mem; - allocl = l++; + allocl = ++l; /* version 0x10 has a more compact unit name here instead of the full * path. we accumulate the full path size using "fpsize", we'll rebuild -- cgit v1.2.3 From 492a22aceb75e34e7b1c1b300ecc8bef2a2f42dc Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Tue, 7 Apr 2015 22:23:49 +0300 Subject: of: unittest: overlay: Keep track of created overlays During the course of the overlay selftests some of them remain applied. While this does not pose a real problem, make sure you track them and destroy them at the end of the test. Signed-off-by: Pantelis Antoniou Signed-off-by: Rob Herring --- drivers/of/unittest.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'drivers') diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index fdb597766be9..995cc73ed630 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -23,6 +23,8 @@ #include #include +#include + #include "of_private.h" static struct unittest_results { @@ -1095,6 +1097,59 @@ static const char *overlay_path(int nr) static const char *bus_path = "/testcase-data/overlay-node/test-bus"; +/* it is guaranteed that overlay ids are assigned in sequence */ +#define MAX_UNITTEST_OVERLAYS 256 +static unsigned long overlay_id_bits[BITS_TO_LONGS(MAX_UNITTEST_OVERLAYS)]; +static int overlay_first_id = -1; + +static void of_unittest_track_overlay(int id) +{ + if (overlay_first_id < 0) + overlay_first_id = id; + id -= overlay_first_id; + + /* we shouldn't need that many */ + BUG_ON(id >= MAX_UNITTEST_OVERLAYS); + overlay_id_bits[BIT_WORD(id)] |= BIT_MASK(id); +} + +static void of_unittest_untrack_overlay(int id) +{ + if (overlay_first_id < 0) + return; + id -= overlay_first_id; + BUG_ON(id >= MAX_UNITTEST_OVERLAYS); + overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id); +} + +static void of_unittest_destroy_tracked_overlays(void) +{ + int id, ret, defers; + + if (overlay_first_id < 0) + return; + + /* try until no defers */ + do { + defers = 0; + /* remove in reverse order */ + for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) { + if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id))) + continue; + + ret = of_overlay_destroy(id + overlay_first_id); + if (ret != 0) { + defers++; + pr_warn("%s: overlay destroy failed for #%d\n", + __func__, id + overlay_first_id); + continue; + } + + overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id); + } + } while (defers > 0); +} + static int of_unittest_apply_overlay(int unittest_nr, int overlay_nr, int *overlay_id) { @@ -1116,6 +1171,7 @@ static int of_unittest_apply_overlay(int unittest_nr, int overlay_nr, goto out; } id = ret; + of_unittest_track_overlay(id); ret = 0; @@ -1329,6 +1385,7 @@ static void of_unittest_overlay_6(void) return; } ov_id[i] = ret; + of_unittest_track_overlay(ov_id[i]); } for (i = 0; i < 2; i++) { @@ -1353,6 +1410,7 @@ static void of_unittest_overlay_6(void) PDEV_OVERLAY)); return; } + of_unittest_untrack_overlay(ov_id[i]); } for (i = 0; i < 2; i++) { @@ -1397,6 +1455,7 @@ static void of_unittest_overlay_8(void) return; } ov_id[i] = ret; + of_unittest_track_overlay(ov_id[i]); } /* now try to remove first overlay (it should fail) */ @@ -1419,6 +1478,7 @@ static void of_unittest_overlay_8(void) PDEV_OVERLAY)); return; } + of_unittest_untrack_overlay(ov_id[i]); } unittest(1, "overlay test %d passed\n", 8); @@ -1841,6 +1901,8 @@ static void __init of_unittest_overlay(void) of_unittest_overlay_i2c_cleanup(); #endif + of_unittest_destroy_tracked_overlays(); + out: of_node_put(bus_np); } -- cgit v1.2.3 From 6480827357923b3977b97c9413a7307be850975d Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Thu, 19 Mar 2015 14:03:41 +0200 Subject: of: base: improve of_get_next_child() kernel-doc Add two new facts to of_get_next_child() documentation: * of_get_next_child() returns NULL when there is not next child * of_get_next_child() decrements the refcount of prev Signed-off-by: Baruch Siach Signed-off-by: Rob Herring --- drivers/of/base.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/of/base.c b/drivers/of/base.c index 31ca3c8dae61..7183e825d658 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -663,8 +663,9 @@ static struct device_node *__of_get_next_child(const struct device_node *node, * @node: parent node * @prev: previous child of the parent node, or NULL to get first * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. + * Returns a node pointer with refcount incremented, use of_node_put() on + * it when done. Returns NULL when prev is the last child. Decrements the + * refcount of prev. */ struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev) -- cgit v1.2.3