source: rtems/bsps/arm/include/bsp/arm-a9mpcore-start.h @ 3d7da435

5
Last change on this file since 3d7da435 was 3d7da435, checked in by Sebastian Huber <sebastian.huber@…>, on 10/02/20 at 09:36:20

bsps/arm: Workaround for Errata 845369

Add a workaround for Cortex-A9 Errata 845369: Under Very Rare Timing
Circumstances Transition into Streaming Mode Might Create Data Corruption.

Update #4114.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 *  @file
3 *
4 *  @ingroup RTEMSBSPsARMShared
5 *
6 *  @brief A9MPCORE_START Support
7 */
8
9/*
10 * Copyright (c) 2013-2014 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.org/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#include <bsp/arm-errata.h>
34#include <bsp/arm-gic-irq.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif /* __cplusplus */
39
40BSP_START_TEXT_SECTION static inline void
41arm_a9mpcore_start_set_vector_base(void)
42{
43  /*
44   * Do not use bsp_vector_table_begin == 0, since this will get optimized away.
45  */
46  if (bsp_vector_table_end != bsp_vector_table_size) {
47    uint32_t ctrl;
48
49    /*
50     * For now we assume that every Cortex-A9 MPCore has the Security Extensions.
51     * Later it might be necessary to evaluate the ID_PFR1 register.
52     */
53    arm_cp15_set_vector_base_address(bsp_vector_table_begin);
54
55    ctrl = arm_cp15_get_control();
56    ctrl &= ~ARM_CP15_CTRL_V;
57    arm_cp15_set_control(ctrl);
58  }
59}
60
61BSP_START_TEXT_SECTION static inline void arm_a9mpcore_start_scu_invalidate(
62  volatile a9mpcore_scu *scu,
63  uint32_t cpu_id,
64  uint32_t ways
65)
66{
67  scu->invss = (ways & 0xf) << ((cpu_id & 0x3) * 4);
68}
69
70BSP_START_TEXT_SECTION static inline void
71arm_a9mpcore_start_errata_764369_handler(volatile a9mpcore_scu *scu)
72{
73  if (arm_errata_is_applicable_processor_errata_764369()) {
74    scu->diagn_ctrl |= A9MPCORE_SCU_DIAGN_CTRL_MIGRATORY_BIT_DISABLE;
75  }
76}
77
78BSP_START_TEXT_SECTION static inline void
79arm_a9mpcore_start_scu_enable(volatile a9mpcore_scu *scu)
80{
81  scu->ctrl |= A9MPCORE_SCU_CTRL_SCU_EN;
82  arm_a9mpcore_start_errata_764369_handler(scu);
83}
84
85#ifdef RTEMS_SMP
86BSP_START_TEXT_SECTION static inline void
87arm_a9mpcore_start_on_secondary_processor(void)
88{
89  uint32_t ctrl;
90
91  arm_a9mpcore_start_set_vector_base();
92
93  arm_gic_irq_initialize_secondary_cpu();
94
95  ctrl = arm_cp15_start_setup_mmu_and_cache(
96    0,
97    ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z
98  );
99
100  arm_cp15_set_domain_access_control(
101    ARM_CP15_DAC_DOMAIN(ARM_MMU_DEFAULT_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT)
102  );
103
104  /* FIXME: Sharing the translation table between processors is brittle */
105  arm_cp15_set_translation_table_base(
106    (uint32_t *) bsp_translation_table_base
107  );
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(_Per_CPU_Get());
113}
114
115BSP_START_TEXT_SECTION static inline void
116arm_a9mpcore_start_enable_smp_in_auxiliary_control(void)
117{
118  /*
119   * Enable cache coherency support and cache/MMU maintenance broadcasts for
120   * this processor.
121   */
122  uint32_t actlr = arm_cp15_get_auxiliary_control();
123  actlr |= ARM_CORTEX_A9_ACTL_SMP | ARM_CORTEX_A9_ACTL_FW;
124  arm_cp15_set_auxiliary_control(actlr);
125}
126
127BSP_START_TEXT_SECTION static inline void
128arm_a9mpcore_start_errata_845369_handler(void)
129{
130  uint32_t diag;
131
132  /*
133   * Workaround for Errata 845369: Under Very Rare Timing Circumstances
134   * Transition into Streaming Mode Might Create Data Corruption.
135   */
136  diag = arm_cp15_get_diagnostic_control();
137  diag |= 1U << 22;
138  arm_cp15_set_diagnostic_control(diag);
139}
140#endif
141
142BSP_START_TEXT_SECTION static inline void arm_a9mpcore_start_hook_0(void)
143{
144  volatile a9mpcore_scu *scu =
145    (volatile a9mpcore_scu *) BSP_ARM_A9MPCORE_SCU_BASE;
146  uint32_t cpu_id = arm_cortex_a9_get_multiprocessor_cpu_id();
147
148  arm_cp15_branch_predictor_invalidate_all();
149
150  if (cpu_id == 0) {
151    arm_a9mpcore_start_scu_enable(scu);
152  }
153
154#ifdef RTEMS_SMP
155  arm_a9mpcore_start_errata_845369_handler();
156  arm_a9mpcore_start_enable_smp_in_auxiliary_control();
157#endif
158
159  arm_a9mpcore_start_scu_invalidate(scu, cpu_id, 0xf);
160
161#ifdef RTEMS_SMP
162  if (cpu_id != 0) {
163    arm_a9mpcore_start_on_secondary_processor();
164  }
165#endif
166}
167
168BSP_START_TEXT_SECTION static inline void arm_a9mpcore_start_global_timer(void)
169{
170  volatile a9mpcore_gt *gt = (volatile a9mpcore_gt *) BSP_ARM_A9MPCORE_GT_BASE;
171
172  gt->ctrl = 0;
173  gt->cntrlower = 0;
174  gt->cntrupper = 0;
175  gt->ctrl = A9MPCORE_GT_CTRL_TMR_EN;
176}
177
178BSP_START_TEXT_SECTION static inline void arm_a9mpcore_start_hook_1(void)
179{
180  arm_a9mpcore_start_global_timer();
181  arm_a9mpcore_start_set_vector_base();
182}
183
184#ifdef __cplusplus
185}
186#endif /* __cplusplus */
187
188#endif /* LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H */
Note: See TracBrowser for help on using the repository browser.