bcm27xx: switch to 5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0071-dwc-otg-FIQ-Fix-bad-mode-in-data-abort-handler.patch
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"
5
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.
10
11 See: https://github.com/raspberrypi/linux/issues/2450
12
13 Signed-off-by: Floris Bos <bos@je-eigen-domein.nl>
14 ---
15 arch/arm/mach-bcm/board_bcm2835.c | 69 +++++++++++++++++++++++++++++++
16 1 file changed, 69 insertions(+)
17
18 --- a/arch/arm/mach-bcm/board_bcm2835.c
19 +++ b/arch/arm/mach-bcm/board_bcm2835.c
20 @@ -6,6 +6,7 @@
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>
26
27 #include <asm/mach/arch.h>
28 @@ -13,6 +14,9 @@
29
30 #include "platsmp.h"
31
32 +#define BCM2835_USB_VIRT_BASE 0xf0980000
33 +#define BCM2835_USB_VIRT_MPHI 0xf0006000
34 +
35 static void __init bcm2835_init(void)
36 {
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;
40 }
41
42 +/*
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.
49 + *
50 + * For more background see the following old mailing list thread:
51 + * https://www.spinics.net/lists/arm-kernel/msg325250.html
52 + */
53 +static int __init bcm2835_map_usb(unsigned long node, const char *uname,
54 + int depth, void *data)
55 +{
56 + struct map_desc map[2];
57 + const __be32 *reg;
58 + int len;
59 + unsigned long p2b_offset = *((unsigned long *) data);
60 +
61 + if (!of_flat_dt_is_compatible(node, "brcm,bcm2708-usb"))
62 + return 0;
63 + reg = of_get_flat_dt_prop(node, "reg", &len);
64 + if (!reg || len != (sizeof(unsigned long) * 4))
65 + return 0;
66 +
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.
71 + */
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);
81 +
82 + return 1;
83 +}
84 +
85 +static void __init bcm2835_map_io(void)
86 +{
87 + const __be32 *ranges;
88 + int soc, len;
89 + unsigned long p2b_offset;
90 +
91 + debug_ll_io_init();
92 +
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");
95 + if (soc < 0)
96 + return;
97 + ranges = of_get_flat_dt_prop(soc, "ranges", &len);
98 + if (!ranges || len < (sizeof(unsigned long) * 3))
99 + return;
100 + p2b_offset = be32_to_cpu(ranges[0]) - be32_to_cpu(ranges[1]);
101 +
102 + /* Now search for bcm2708-usb node in device tree */
103 + of_scan_flat_dt(bcm2835_map_usb, &p2b_offset);
104 +}
105 +
106 static const char * const bcm2835_compat[] = {
107 #ifdef CONFIG_ARCH_MULTI_V6
108 "brcm,bcm2835",
109 @@ -37,6 +105,7 @@ static const char * const bcm2835_compat
110 };
111
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),