source: rtems/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h @ db42c079

4.11
Last change on this file since db42c079 was db42c079, checked in by Sebastian Huber <sebastian.huber@…>, on May 31, 2013 at 11:59:47 AM

bsps/arm: Add SMP support

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2009-2013 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#ifndef LIBBSP_ARM_SHARED_ARM_CP15_START_H
16#define LIBBSP_ARM_SHARED_ARM_CP15_START_H
17
18#include <libcpu/arm-cp15.h>
19
20#include <bsp/start.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26BSP_START_TEXT_SECTION static inline void
27arm_cp15_set_domain_access_control(uint32_t val);
28
29BSP_START_TEXT_SECTION static inline void
30arm_cp15_set_translation_table_base(uint32_t *base);
31
32BSP_START_TEXT_SECTION static inline void
33arm_cp15_set_control(uint32_t val);
34
35BSP_START_TEXT_SECTION static inline uint32_t
36arm_cp15_get_control(void);
37
38BSP_START_TEXT_SECTION static inline void
39arm_cp15_cache_invalidate(void);
40
41BSP_START_TEXT_SECTION static inline void
42arm_cp15_tlb_invalidate(void);
43
44BSP_START_TEXT_SECTION static inline uint32_t
45arm_cp15_get_multiprocessor_affinity(void);
46
47BSP_START_TEXT_SECTION static inline uint32_t
48arm_cortex_a9_get_multiprocessor_cpu_id(void);
49
50typedef struct {
51  uint32_t begin;
52  uint32_t end;
53  uint32_t flags;
54} arm_cp15_start_section_config;
55
56BSP_START_TEXT_SECTION static inline void
57arm_cp15_start_set_translation_table_entries(
58  uint32_t *ttb,
59  const arm_cp15_start_section_config *config
60)
61{
62  uint32_t i = ARM_MMU_SECT_GET_INDEX(config->begin);
63  uint32_t iend =
64    ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end));
65
66  if (config->begin != config->end) {
67    while (i < iend) {
68      ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | config->flags;
69      ++i;
70    }
71  }
72}
73
74BSP_START_TEXT_SECTION static void
75arm_cp15_start_setup_translation_table_and_enable_mmu(
76  uint32_t ctrl,
77  uint32_t *ttb,
78  uint32_t client_domain,
79  const arm_cp15_start_section_config *config_table,
80  size_t config_count
81)
82{
83  uint32_t dac = ARM_CP15_DAC_DOMAIN(client_domain, ARM_CP15_DAC_CLIENT);
84  size_t i;
85
86  arm_cp15_set_domain_access_control(dac);
87  arm_cp15_set_translation_table_base(ttb);
88
89  /* Initialize translation table with invalid entries */
90  for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
91    ttb [i] = 0;
92  }
93
94  for (i = 0; i < config_count; ++i) {
95    arm_cp15_start_set_translation_table_entries(ttb, &config_table [i]);
96  }
97
98  /* Enable MMU and cache */
99  ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
100  arm_cp15_set_control(ctrl);
101}
102
103BSP_START_TEXT_SECTION static inline uint32_t
104arm_cp15_start_setup_mmu_and_cache(uint32_t ctrl_clear, uint32_t ctrl_set)
105{
106  uint32_t ctrl = arm_cp15_get_control();
107
108  ctrl &= ~ctrl_clear;
109  ctrl |= ctrl_set;
110
111  arm_cp15_set_control(ctrl);
112
113  arm_cp15_tlb_invalidate();
114
115  return ctrl;
116}
117
118#ifdef __cplusplus
119}
120#endif /* __cplusplus */
121
122#endif /* LIBBSP_ARM_SHARED_ARM_CP15_START_H */
Note: See TracBrowser for help on using the repository browser.