1515#include <linux/init.h>
1616#include <linux/irqchip.h>
1717#include <linux/of_address.h>
18+ #include <linux/of_fdt.h>
1819#include <linux/clk/bcm2835.h>
1920#include <asm/system_info.h>
2021
2425#include "platsmp.h"
2526#include <linux/dma-mapping.h>
2627
28+ #define BCM2835_USB_VIRT_BASE 0xf0980000
29+ #define BCM2835_USB_VIRT_MPHI 0xf0006000
30+
2731static void __init bcm2835_init (void )
2832{
2933 struct device_node * np = of_find_node_by_path ("/system" );
@@ -44,6 +48,70 @@ static void __init bcm2835_init_early(void)
4448 init_dma_coherent_pool_size (SZ_1M );
4549}
4650
51+ /*
52+ * We need to map registers that are going to be accessed by the FIQ
53+ * very early, before any kernel threads are spawned. Because if done
54+ * later, the mapping tables are not updated instantly but lazily upon
55+ * first access through a data abort handler. While that is fine
56+ * when executing regular kernel code, if the first access in a specific
57+ * thread happens while running FIQ code this will result in a panic.
58+ *
59+ * For more background see the following old mailing list thread:
60+ * https://www.spinics.net/lists/arm-kernel/msg325250.html
61+ */
62+ static int __init bcm2835_map_usb (unsigned long node , const char * uname ,
63+ int depth , void * data )
64+ {
65+ struct map_desc map [2 ];
66+ const __be32 * reg ;
67+ int len ;
68+ unsigned long p2b_offset = * ((unsigned long * ) data );
69+
70+ if (!of_flat_dt_is_compatible (node , "brcm,bcm2708-usb" ))
71+ return 0 ;
72+ reg = of_get_flat_dt_prop (node , "reg" , & len );
73+ if (!reg || len != (sizeof (unsigned long ) * 4 ))
74+ return 0 ;
75+
76+ /* Use information about the physical addresses of the
77+ * registers from the device tree, but use legacy
78+ * iotable_init() static mapping function to map them,
79+ * as ioremap() is not functional at this stage in boot.
80+ */
81+ map [0 ].virtual = (unsigned long ) BCM2835_USB_VIRT_BASE ;
82+ map [0 ].pfn = __phys_to_pfn (be32_to_cpu (reg [0 ]) - p2b_offset );
83+ map [0 ].length = be32_to_cpu (reg [1 ]);
84+ map [0 ].type = MT_DEVICE ;
85+ map [1 ].virtual = (unsigned long ) BCM2835_USB_VIRT_MPHI ;
86+ map [1 ].pfn = __phys_to_pfn (be32_to_cpu (reg [2 ]) - p2b_offset );
87+ map [1 ].length = be32_to_cpu (reg [3 ]);
88+ map [1 ].type = MT_DEVICE ;
89+ iotable_init (map , 2 );
90+
91+ return 1 ;
92+ }
93+
94+ static void __init bcm2835_map_io (void )
95+ {
96+ const __be32 * ranges ;
97+ int soc , len ;
98+ unsigned long p2b_offset ;
99+
100+ debug_ll_io_init ();
101+
102+ /* Find out how to map bus to physical address first from soc/ranges */
103+ soc = of_get_flat_dt_subnode_by_name (of_get_flat_dt_root (), "soc" );
104+ if (soc < 0 )
105+ return ;
106+ ranges = of_get_flat_dt_prop (soc , "ranges" , & len );
107+ if (!ranges || len < (sizeof (unsigned long ) * 3 ))
108+ return ;
109+ p2b_offset = be32_to_cpu (ranges [0 ]) - be32_to_cpu (ranges [1 ]);
110+
111+ /* Now search for bcm2708-usb node in device tree */
112+ of_scan_flat_dt (bcm2835_map_usb , & p2b_offset );
113+ }
114+
47115static const char * const bcm2835_compat [] = {
48116#ifdef CONFIG_ARCH_MULTI_V6
49117 "brcm,bcm2835" ,
@@ -56,6 +124,7 @@ static const char * const bcm2835_compat[] = {
56124};
57125
58126DT_MACHINE_START (BCM2835 , "BCM2835" )
127+ .map_io = bcm2835_map_io ,
59128 .init_machine = bcm2835_init ,
60129 .init_early = bcm2835_init_early ,
61130 .dt_compat = bcm2835_compat ,
0 commit comments