1 From 347167bd9ac2a68870064edd921f2525bd569c6d Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Mon, 16 Jul 2018 14:40:13 +0100
4 Subject: [PATCH] dwc-otg: FIQ: Fix "bad mode in data abort handler"
6 Create a semi-static mapping for the USB registers early in the boot
7 process, before additional kernel threads are started, so all threads
8 will have the mappings from the start. This avoids the need for
9 data aborts to lazily update them.
11 See: https://github.com/raspberrypi/linux/issues/2450
13 Signed-off-by: Floris Bos <bos@je-eigen-domein.nl>
15 arch/arm/mach-bcm/board_bcm2835.c | 69 +++++++++++++++++++++++++++++++
16 1 file changed, 69 insertions(+)
18 --- a/arch/arm/mach-bcm/board_bcm2835.c
19 +++ b/arch/arm/mach-bcm/board_bcm2835.c
21 #include <linux/init.h>
22 #include <linux/irqchip.h>
23 #include <linux/of_address.h>
24 +#include <linux/of_fdt.h>
25 #include <asm/system_info.h>
27 #include <asm/mach/arch.h>
32 +#define BCM2835_USB_VIRT_BASE 0xf0980000
33 +#define BCM2835_USB_VIRT_MPHI 0xf0006000
35 static void __init bcm2835_init(void)
37 struct device_node *np = of_find_node_by_path("/system");
38 @@ -25,6 +29,70 @@ static void __init bcm2835_init(void)
39 system_serial_low = val64;
43 + * We need to map registers that are going to be accessed by the FIQ
44 + * very early, before any kernel threads are spawned. Because if done
45 + * later, the mapping tables are not updated instantly but lazily upon
46 + * first access through a data abort handler. While that is fine
47 + * when executing regular kernel code, if the first access in a specific
48 + * thread happens while running FIQ code this will result in a panic.
50 + * For more background see the following old mailing list thread:
51 + * https://www.spinics.net/lists/arm-kernel/msg325250.html
53 +static int __init bcm2835_map_usb(unsigned long node, const char *uname,
54 + int depth, void *data)
56 + struct map_desc map[2];
59 + unsigned long p2b_offset = *((unsigned long *) data);
61 + if (!of_flat_dt_is_compatible(node, "brcm,bcm2708-usb"))
63 + reg = of_get_flat_dt_prop(node, "reg", &len);
64 + if (!reg || len != (sizeof(unsigned long) * 4))
67 + /* Use information about the physical addresses of the
68 + * registers from the device tree, but use legacy
69 + * iotable_init() static mapping function to map them,
70 + * as ioremap() is not functional at this stage in boot.
72 + map[0].virtual = (unsigned long) BCM2835_USB_VIRT_BASE;
73 + map[0].pfn = __phys_to_pfn(be32_to_cpu(reg[0]) - p2b_offset);
74 + map[0].length = be32_to_cpu(reg[1]);
75 + map[0].type = MT_DEVICE;
76 + map[1].virtual = (unsigned long) BCM2835_USB_VIRT_MPHI;
77 + map[1].pfn = __phys_to_pfn(be32_to_cpu(reg[2]) - p2b_offset);
78 + map[1].length = be32_to_cpu(reg[3]);
79 + map[1].type = MT_DEVICE;
80 + iotable_init(map, 2);
85 +static void __init bcm2835_map_io(void)
87 + const __be32 *ranges;
89 + unsigned long p2b_offset;
93 + /* Find out how to map bus to physical address first from soc/ranges */
94 + soc = of_get_flat_dt_subnode_by_name(of_get_flat_dt_root(), "soc");
97 + ranges = of_get_flat_dt_prop(soc, "ranges", &len);
98 + if (!ranges || len < (sizeof(unsigned long) * 3))
100 + p2b_offset = be32_to_cpu(ranges[0]) - be32_to_cpu(ranges[1]);
102 + /* Now search for bcm2708-usb node in device tree */
103 + of_scan_flat_dt(bcm2835_map_usb, &p2b_offset);
106 static const char * const bcm2835_compat[] = {
107 #ifdef CONFIG_ARCH_MULTI_V6
109 @@ -37,6 +105,7 @@ static const char * const bcm2835_compat
112 DT_MACHINE_START(BCM2835, "BCM2835")
113 + .map_io = bcm2835_map_io,
114 .init_machine = bcm2835_init,
115 .dt_compat = bcm2835_compat,
116 .smp = smp_ops(bcm2836_smp_ops),