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

4.115
Last change on this file since a91dc98b was ecf7dd9, checked in by Sebastian Huber <sebastian.huber@…>, on May 2, 2013 at 9:41:22 AM

bsps/arm: Move CP15 start initialization

  • Property mode set to 100644
File size: 2.7 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
44typedef struct {
45  uint32_t begin;
46  uint32_t end;
47  uint32_t flags;
48} arm_cp15_start_section_config;
49
50BSP_START_TEXT_SECTION static inline void
51arm_cp15_start_set_translation_table_entries(
52  uint32_t *ttb,
53  const arm_cp15_start_section_config *config
54)
55{
56  uint32_t i = ARM_MMU_SECT_GET_INDEX(config->begin);
57  uint32_t iend =
58    ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end));
59
60  if (config->begin != config->end) {
61    while (i < iend) {
62      ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | config->flags;
63      ++i;
64    }
65  }
66}
67
68BSP_START_TEXT_SECTION static void
69arm_cp15_start_setup_translation_table_and_enable_mmu(
70  uint32_t ctrl,
71  uint32_t *ttb,
72  uint32_t client_domain,
73  const arm_cp15_start_section_config *config_table,
74  size_t config_count
75)
76{
77  uint32_t dac = ARM_CP15_DAC_DOMAIN(client_domain, ARM_CP15_DAC_CLIENT);
78  size_t i;
79
80  arm_cp15_set_domain_access_control(dac);
81  arm_cp15_set_translation_table_base(ttb);
82
83  /* Initialize translation table with invalid entries */
84  for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
85    ttb [i] = 0;
86  }
87
88  for (i = 0; i < config_count; ++i) {
89    arm_cp15_start_set_translation_table_entries(ttb, &config_table [i]);
90  }
91
92  /* Enable MMU and cache */
93  ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
94  arm_cp15_set_control(ctrl);
95}
96
97BSP_START_TEXT_SECTION static inline uint32_t
98arm_cp15_start_setup_mmu_and_cache(uint32_t ctrl_clear, uint32_t ctrl_set)
99{
100  uint32_t ctrl = arm_cp15_get_control();
101
102  ctrl &= ~ctrl_clear;
103  ctrl |= ctrl_set;
104
105  arm_cp15_set_control(ctrl);
106
107  arm_cp15_tlb_invalidate();
108
109  return ctrl;
110}
111
112#ifdef __cplusplus
113}
114#endif /* __cplusplus */
115
116#endif /* LIBBSP_ARM_SHARED_ARM_CP15_START_H */
Note: See TracBrowser for help on using the repository browser.