1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup arm_shared |
---|
5 | * |
---|
6 | * @brief A9MPCORE_START Support |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2013 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <info@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.com/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H |
---|
24 | #define LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H |
---|
25 | |
---|
26 | #include <rtems/score/smpimpl.h> |
---|
27 | |
---|
28 | #include <libcpu/arm-cp15.h> |
---|
29 | |
---|
30 | #include <bsp.h> |
---|
31 | #include <bsp/start.h> |
---|
32 | #include <bsp/arm-a9mpcore-regs.h> |
---|
33 | |
---|
34 | #ifdef __cplusplus |
---|
35 | extern "C" { |
---|
36 | #endif /* __cplusplus */ |
---|
37 | |
---|
38 | BSP_START_TEXT_SECTION static inline uint32_t |
---|
39 | arm_cp15_get_control(void); |
---|
40 | |
---|
41 | BSP_START_TEXT_SECTION static inline void |
---|
42 | arm_cp15_set_control(uint32_t val); |
---|
43 | |
---|
44 | BSP_START_TEXT_SECTION static inline uint32_t |
---|
45 | arm_cp15_get_auxiliary_control(void); |
---|
46 | |
---|
47 | BSP_START_TEXT_SECTION static inline void |
---|
48 | arm_cp15_set_auxiliary_control(uint32_t val); |
---|
49 | |
---|
50 | BSP_START_TEXT_SECTION static inline void |
---|
51 | arm_cp15_set_vector_base_address(void *base); |
---|
52 | |
---|
53 | BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_set_vector_base(void) |
---|
54 | { |
---|
55 | /* |
---|
56 | * Do not use bsp_vector_table_begin == 0, since this will get optimized away. |
---|
57 | */ |
---|
58 | if (bsp_vector_table_end != bsp_vector_table_size) { |
---|
59 | uint32_t ctrl; |
---|
60 | |
---|
61 | /* |
---|
62 | * For now we assume that every Cortex-A9 MPCore has the Security Extensions. |
---|
63 | * Later it might be necessary to evaluate the ID_PFR1 register. |
---|
64 | */ |
---|
65 | arm_cp15_set_vector_base_address(bsp_vector_table_begin); |
---|
66 | |
---|
67 | ctrl = arm_cp15_get_control(); |
---|
68 | ctrl &= ~ARM_CP15_CTRL_V; |
---|
69 | arm_cp15_set_control(ctrl); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_hook_0(void) |
---|
74 | { |
---|
75 | #ifdef RTEMS_SMP |
---|
76 | volatile a9mpcore_scu *scu = (volatile a9mpcore_scu *) BSP_ARM_A9MPCORE_SCU_BASE; |
---|
77 | uint32_t cpu_id; |
---|
78 | uint32_t actlr; |
---|
79 | |
---|
80 | /* Enable Snoop Control Unit (SCU) */ |
---|
81 | scu->ctrl |= A9MPCORE_SCU_CTRL_SCU_EN; |
---|
82 | |
---|
83 | /* Enable cache coherency support for this processor */ |
---|
84 | actlr = arm_cp15_get_auxiliary_control(); |
---|
85 | actlr |= ARM_CORTEX_A9_ACTL_SMP; |
---|
86 | arm_cp15_set_auxiliary_control(actlr); |
---|
87 | |
---|
88 | cpu_id = arm_cortex_a9_get_multiprocessor_cpu_id(); |
---|
89 | if (cpu_id != 0) { |
---|
90 | arm_a9mpcore_start_set_vector_base(); |
---|
91 | |
---|
92 | if (cpu_id < rtems_configuration_get_maximum_processors()) { |
---|
93 | uint32_t ctrl; |
---|
94 | |
---|
95 | arm_gic_irq_initialize_secondary_cpu(); |
---|
96 | |
---|
97 | ctrl = arm_cp15_start_setup_mmu_and_cache( |
---|
98 | 0, |
---|
99 | ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z |
---|
100 | ); |
---|
101 | |
---|
102 | arm_cp15_set_domain_access_control( |
---|
103 | ARM_CP15_DAC_DOMAIN(ARM_MMU_DEFAULT_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT) |
---|
104 | ); |
---|
105 | |
---|
106 | /* FIXME: Sharing the translation table between processors is brittle */ |
---|
107 | arm_cp15_set_translation_table_base((uint32_t *) bsp_translation_table_base); |
---|
108 | |
---|
109 | ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M; |
---|
110 | arm_cp15_set_control(ctrl); |
---|
111 | |
---|
112 | _SMP_Start_multitasking_on_secondary_processor(); |
---|
113 | } else { |
---|
114 | /* FIXME: Shutdown processor */ |
---|
115 | while (1) { |
---|
116 | __asm__ volatile ("wfi"); |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|
120 | #endif |
---|
121 | } |
---|
122 | |
---|
123 | BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_global_timer(void) |
---|
124 | { |
---|
125 | volatile a9mpcore_gt *gt = (volatile a9mpcore_gt *) BSP_ARM_A9MPCORE_GT_BASE; |
---|
126 | |
---|
127 | gt->ctrl = 0; |
---|
128 | gt->cntrlower = 0; |
---|
129 | gt->cntrupper = 0; |
---|
130 | gt->ctrl = A9MPCORE_GT_CTRL_TMR_EN; |
---|
131 | } |
---|
132 | |
---|
133 | BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_hook_1(void) |
---|
134 | { |
---|
135 | arm_a9mpcore_start_global_timer(); |
---|
136 | arm_a9mpcore_start_set_vector_base(); |
---|
137 | } |
---|
138 | |
---|
139 | #ifdef __cplusplus |
---|
140 | } |
---|
141 | #endif /* __cplusplus */ |
---|
142 | |
---|
143 | #endif /* LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H */ |
---|