1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup arm_start |
---|
5 | * |
---|
6 | * @brief Rasberry Pi startup code. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2013. Hesham AL-Matary |
---|
11 | * Copyright (c) 2013 by Alan Cudmore |
---|
12 | * based on work by: |
---|
13 | * Copyright (c) 2009 embedded brains GmbH. All rights reserved. |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE |
---|
18 | */ |
---|
19 | |
---|
20 | #include <bspopts.h> |
---|
21 | #include <bsp/start.h> |
---|
22 | #include <bsp/raspberrypi.h> |
---|
23 | #include <libcpu/arm-cp15.h> |
---|
24 | #include <bsp.h> |
---|
25 | #include <bsp/bootcard.h> |
---|
26 | #include <bsp/linker-symbols.h> |
---|
27 | #include <bsp/arm-cp15-start.h> |
---|
28 | |
---|
29 | #include <rtems/sysinit.h> |
---|
30 | |
---|
31 | #ifdef RTEMS_SMP |
---|
32 | #include <rtems/score/smp.h> |
---|
33 | #endif |
---|
34 | |
---|
35 | #if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG) |
---|
36 | #define USE_UBOOT |
---|
37 | #endif |
---|
38 | |
---|
39 | #ifdef USE_UBOOT |
---|
40 | #include <bsp/u-boot.h> |
---|
41 | #else |
---|
42 | #include <bsp/vc.h> |
---|
43 | #endif |
---|
44 | |
---|
45 | BSP_START_DATA_SECTION static arm_cp15_start_section_config |
---|
46 | raspberrypi_mmu_config_table[] = { |
---|
47 | ARMV7_CP15_START_DEFAULT_SECTIONS, |
---|
48 | { |
---|
49 | .begin = RPI_PERIPHERAL_BASE, |
---|
50 | .end = RPI_PERIPHERAL_BASE + RPI_PERIPHERAL_SIZE, |
---|
51 | .flags = ARMV7_MMU_DEVICE |
---|
52 | } |
---|
53 | #if (BSP_IS_RPI2 == 1) |
---|
54 | /* Core local peripherals area - timer, mailboxes */ |
---|
55 | , { |
---|
56 | .begin = BCM2836_CORE_LOCAL_PERIPH_BASE, |
---|
57 | .end = BCM2836_CORE_LOCAL_PERIPH_BASE + BCM2836_CORE_LOCAL_PERIPH_SIZE, |
---|
58 | .flags = ARMV7_MMU_DEVICE |
---|
59 | } |
---|
60 | #endif |
---|
61 | }; |
---|
62 | |
---|
63 | void BSP_START_TEXT_SECTION bsp_start_hook_0(void) |
---|
64 | { |
---|
65 | /* Clear Translation Table Base Control Register */ |
---|
66 | arm_cp15_set_translation_table_base_control_register(0); |
---|
67 | |
---|
68 | #ifdef RTEMS_SMP |
---|
69 | if (_SMP_Get_current_processor() == 0) { |
---|
70 | rpi_ipi_initialize(); |
---|
71 | } else { |
---|
72 | rpi_start_rtems_on_secondary_processor(); |
---|
73 | } |
---|
74 | #endif |
---|
75 | } |
---|
76 | |
---|
77 | BSP_START_TEXT_SECTION static uintptr_t raspberrypi_get_ram_end(void) |
---|
78 | { |
---|
79 | uintptr_t ram_end; |
---|
80 | |
---|
81 | #ifdef USE_UBOOT |
---|
82 | ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart + |
---|
83 | bsp_uboot_board_info.bi_memsize; |
---|
84 | #else |
---|
85 | bcm2835_get_arm_memory_entries spec; |
---|
86 | |
---|
87 | if (bcm2835_mailbox_get_arm_memory( &spec ) >= 0) { |
---|
88 | ram_end = spec.base + spec.size; |
---|
89 | } else { |
---|
90 | /* Use the workspace end from the linker command file for fallback. */ |
---|
91 | ram_end = (uintptr_t) bsp_section_work_end; |
---|
92 | } |
---|
93 | #endif |
---|
94 | |
---|
95 | return ram_end; |
---|
96 | } |
---|
97 | |
---|
98 | BSP_START_TEXT_SECTION static void bsp_memory_management_initialize(void) |
---|
99 | { |
---|
100 | uintptr_t ram_end = raspberrypi_get_ram_end(); |
---|
101 | uint32_t ctrl = arm_cp15_get_control(); |
---|
102 | |
---|
103 | ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP; |
---|
104 | |
---|
105 | raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end = |
---|
106 | ram_end; |
---|
107 | |
---|
108 | arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache( |
---|
109 | ctrl, |
---|
110 | (uint32_t *) bsp_translation_table_base, |
---|
111 | ARM_MMU_DEFAULT_CLIENT_DOMAIN, |
---|
112 | &raspberrypi_mmu_config_table[0], |
---|
113 | RTEMS_ARRAY_SIZE(raspberrypi_mmu_config_table) |
---|
114 | ); |
---|
115 | } |
---|
116 | |
---|
117 | void BSP_START_TEXT_SECTION bsp_start_hook_1(void) |
---|
118 | { |
---|
119 | bsp_start_copy_sections(); |
---|
120 | bsp_memory_management_initialize(); |
---|
121 | bsp_start_clear_bss(); |
---|
122 | |
---|
123 | rpi_video_init(); |
---|
124 | } |
---|
125 | |
---|
126 | static Memory_Area _Memory_Areas[1]; |
---|
127 | |
---|
128 | static void bsp_memory_initialize(void) |
---|
129 | { |
---|
130 | _Memory_Initialize( |
---|
131 | &_Memory_Areas[0], |
---|
132 | (void *) |
---|
133 | raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin, |
---|
134 | (void *) |
---|
135 | raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end |
---|
136 | ); |
---|
137 | } |
---|
138 | |
---|
139 | RTEMS_SYSINIT_ITEM( |
---|
140 | bsp_memory_initialize, |
---|
141 | RTEMS_SYSINIT_MEMORY, |
---|
142 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
143 | ); |
---|
144 | |
---|
145 | static const Memory_Information _Memory_Information = |
---|
146 | MEMORY_INFORMATION_INITIALIZER(_Memory_Areas); |
---|
147 | |
---|
148 | const Memory_Information *_Memory_Get(void) |
---|
149 | { |
---|
150 | return &_Memory_Information; |
---|
151 | } |
---|