summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/shared/include/arm-a9mpcore-start.h
blob: 3c41d4e9ae66445324bfd0d86972d399207eafb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <info@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#ifndef LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H
#define LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H

#include <rtems/bspsmp.h>

#include <libcpu/arm-cp15.h>

#include <bsp.h>
#include <bsp/start.h>
#include <bsp/arm-a9mpcore-regs.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

BSP_START_TEXT_SECTION static inline uint32_t
arm_cp15_get_control(void);

BSP_START_TEXT_SECTION static inline void
arm_cp15_set_control(uint32_t val);

BSP_START_TEXT_SECTION static inline uint32_t
arm_cp15_get_auxiliary_control(void);

BSP_START_TEXT_SECTION static inline void
arm_cp15_set_auxiliary_control(uint32_t val);

BSP_START_TEXT_SECTION static inline void
arm_cp15_set_vector_base_address(void *base);

BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_set_vector_base(void)
{
  /*
   * Do not use bsp_vector_table_begin == 0, since this will get optimized away.
  */
  if (bsp_vector_table_end != bsp_vector_table_size) {
    uint32_t ctrl;

    /*
     * For now we assume that every Cortex-A9 MPCore has the Security Extensions.
     * Later it might be necessary to evaluate the ID_PFR1 register.
     */
    arm_cp15_set_vector_base_address(bsp_vector_table_begin);

    ctrl = arm_cp15_get_control();
    ctrl &= ~ARM_CP15_CTRL_V;
    arm_cp15_set_control(ctrl);
  }
}

BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_hook_0(void)
{
#ifdef RTEMS_SMP
  volatile a9mpcore_scu *scu = (volatile a9mpcore_scu *) BSP_ARM_A9MPCORE_SCU_BASE;
  uint32_t cpu_id;
  uint32_t actlr;

  /* Enable Snoop Control Unit (SCU) */
  scu->ctrl |= A9MPCORE_SCU_CTRL_SCU_EN;

  /* Enable cache coherency support for this processor */
  actlr = arm_cp15_get_auxiliary_control();
  actlr |= ARM_CORTEX_A9_ACTL_SMP;
  arm_cp15_set_auxiliary_control(actlr);

  cpu_id = arm_cortex_a9_get_multiprocessor_cpu_id();
  if (cpu_id != 0) {
    arm_a9mpcore_start_set_vector_base();

    if (cpu_id < rtems_configuration_get_maximum_processors()) {
      uint32_t ctrl;

      arm_gic_irq_initialize_secondary_cpu();

      ctrl = arm_cp15_start_setup_mmu_and_cache(
        0,
        ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z
      );

      arm_cp15_set_domain_access_control(
        ARM_CP15_DAC_DOMAIN(ARM_MMU_DEFAULT_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT)
      );

      /* FIXME: Sharing the translation table between processors is brittle */
      arm_cp15_set_translation_table_base((uint32_t *) bsp_translation_table_base);

      ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
      arm_cp15_set_control(ctrl);

      rtems_smp_secondary_cpu_initialize();
    } else {
      /* FIXME: Shutdown processor */
      while (1) {
        __asm__ volatile ("wfi");
      }
    }
  }
#endif
}

BSP_START_TEXT_SECTION static inline arm_a9mpcore_start_hook_1(void)
{
  arm_a9mpcore_start_set_vector_base();
}

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* LIBBSP_ARM_SHARED_ARM_A9MPCORE_START_H */