source: rtems/c/src/lib/libbsp/arm/shared/include/arm-a9mpcore-start.h @ 0b74e10f

4.115
Last change on this file since 0b74e10f was 0b74e10f, checked in by Ralf Kirchner <ralf.kirchner@…>, on 02/17/14 at 10:57:19

bsp/arm: Add SCU errata handling for L2C-310 cache

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**
2 *  @file
3 *
4 *  @ingroup arm_shared
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.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#include <bsp/arm-errata.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif /* __cplusplus */
38
39BSP_START_TEXT_SECTION static inline uint32_t
40arm_cp15_get_control(void);
41
42BSP_START_TEXT_SECTION static inline void
43arm_cp15_set_control(uint32_t val);
44
45BSP_START_TEXT_SECTION static inline uint32_t
46arm_cp15_get_auxiliary_control(void);
47
48BSP_START_TEXT_SECTION static inline void
49arm_cp15_set_auxiliary_control(uint32_t val);
50
51BSP_START_TEXT_SECTION static inline void
52arm_cp15_set_vector_base_address(void *base);
53
54BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_set_vector_base(void)
55{
56  /*
57   * Do not use bsp_vector_table_begin == 0, since this will get optimized away.
58  */
59  if (bsp_vector_table_end != bsp_vector_table_size) {
60    uint32_t ctrl;
61
62    /*
63     * For now we assume that every Cortex-A9 MPCore has the Security Extensions.
64     * Later it might be necessary to evaluate the ID_PFR1 register.
65     */
66    arm_cp15_set_vector_base_address(bsp_vector_table_begin);
67
68    ctrl = arm_cp15_get_control();
69    ctrl &= ~ARM_CP15_CTRL_V;
70    arm_cp15_set_control(ctrl);
71  }
72}
73
74BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_scu_invalidate(
75  volatile a9mpcore_scu *scu,
76  uint32_t cpu_id,
77  uint32_t ways
78)
79{
80  scu->invss = (ways & 0xf) << ((cpu_id & 0x3) * 4);
81}
82
83BSP_START_TEXT_SECTION static void inline
84arm_a9mpcore_start_errata_764369_handler(volatile a9mpcore_scu *scu)
85{
86#ifdef RTEMS_SMP
87  if (arm_errata_is_applicable_processor_errata_764369()) {
88    scu->diagn_ctrl |= A9MPCORE_SCU_DIAGN_CTRL_MIGRATORY_BIT_DISABLE;
89  }
90#endif
91}
92
93BSP_START_TEXT_SECTION static inline
94arm_a9mpcore_start_scu_enable(volatile a9mpcore_scu *scu)
95{
96  arm_a9mpcore_start_errata_764369_handler(scu);
97  scu->ctrl |= A9MPCORE_SCU_CTRL_SCU_EN;
98}
99
100BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_hook_0(void)
101{
102  volatile a9mpcore_scu *scu =
103    (volatile a9mpcore_scu *) BSP_ARM_A9MPCORE_SCU_BASE;
104  uint32_t cpu_id;
105
106  arm_a9mpcore_start_scu_enable(scu);
107
108#ifdef RTEMS_SMP
109  /* Enable cache coherency support for this processor */
110  {
111    uint32_t actlr = arm_cp15_get_auxiliary_control();
112    actlr |= ARM_CORTEX_A9_ACTL_SMP;
113    arm_cp15_set_auxiliary_control(actlr);
114  }
115#endif
116
117  cpu_id = arm_cortex_a9_get_multiprocessor_cpu_id();
118
119  arm_a9mpcore_start_scu_invalidate(scu, cpu_id, 0xf);
120
121#ifdef RTEMS_SMP
122  if (cpu_id != 0) {
123    arm_a9mpcore_start_set_vector_base();
124
125    if (cpu_id < rtems_configuration_get_maximum_processors()) {
126      uint32_t ctrl;
127
128      arm_gic_irq_initialize_secondary_cpu();
129
130      ctrl = arm_cp15_start_setup_mmu_and_cache(
131        0,
132        ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z
133      );
134
135      arm_cp15_set_domain_access_control(
136        ARM_CP15_DAC_DOMAIN(ARM_MMU_DEFAULT_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT)
137      );
138
139      /* FIXME: Sharing the translation table between processors is brittle */
140      arm_cp15_set_translation_table_base(
141        (uint32_t *) bsp_translation_table_base
142      );
143
144      ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
145      arm_cp15_set_control(ctrl);
146
147      _SMP_Start_multitasking_on_secondary_processor();
148    } else {
149      /* FIXME: Shutdown processor */
150      while (1) {
151        __asm__ volatile ("wfi");
152      }
153    }
154  }
155#endif
156}
157
158BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_global_timer(void)
159{
160  volatile a9mpcore_gt *gt = (volatile a9mpcore_gt *) BSP_ARM_A9MPCORE_GT_BASE;
161
162  gt->ctrl = 0;
163  gt->cntrlower = 0;
164  gt->cntrupper = 0;
165  gt->ctrl = A9MPCORE_GT_CTRL_TMR_EN;
166}
167
168BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_hook_1(void)
169{
170  arm_a9mpcore_start_global_timer();
171  arm_a9mpcore_start_set_vector_base();
172}
173
174#ifdef __cplusplus
175}
176#endif /* __cplusplus */
177
178#endif /* LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H */
Note: See TracBrowser for help on using the repository browser.