source: rtems/bsps/arm/imx/start/bspstarthooks.c

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (C) 2013, 2018 embedded brains GmbH & Co. KG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#define ARM_CP15_TEXT_SECTION BSP_START_TEXT_SECTION
29
30#include <bsp.h>
31#include <bsp/bootcard.h>
32#include <bsp/fdt.h>
33#include <bsp/linker-symbols.h>
34#include <bsp/start.h>
35#include <bsp/arm-cp15-start.h>
36#include <bsp/arm-a9mpcore-start.h>
37
38#include <rtems/sysinit.h>
39
40#include <libfdt.h>
41
42BSP_START_DATA_SECTION static arm_cp15_start_section_config
43imx_mmu_config_table[] = {
44  ARMV7_CP15_START_DEFAULT_SECTIONS,
45  {
46    .begin = 0x00a00000U,
47    .end = 0x70000000U,
48    .flags = ARMV7_MMU_DEVICE
49  }
50};
51
52BSP_START_DATA_SECTION static char memory_path[] = "/memory";
53
54BSP_START_TEXT_SECTION static void setup_mmu_and_cache(void)
55{
56  const void *fdt;
57  int node;
58  uint32_t ctrl;
59
60  fdt = bsp_fdt_get();
61  node = fdt_path_offset_namelen(
62    fdt,
63    memory_path,
64    (int) sizeof(memory_path) - 1
65  );
66
67  if (node >= 0) {
68    int len;
69    const void *val;
70
71    val = fdt_getprop(fdt, node, "reg", &len);
72    if (len == 8) {
73      uint32_t begin;
74      uint32_t size;
75
76      begin = fdt32_to_cpu(((fdt32_t *) val)[0]);
77      size = fdt32_to_cpu(((fdt32_t *) val)[1]);
78
79      /* The heap code does not like an end address of zero */
80      if (begin + size == 0) {
81        size -= 4;
82      }
83
84      imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end =
85        begin + size;
86    }
87  }
88
89  ctrl = arm_cp15_start_setup_mmu_and_cache(
90    ARM_CP15_CTRL_A,
91    ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z
92  );
93
94  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
95    ctrl,
96    (uint32_t *) bsp_translation_table_base,
97    ARM_MMU_DEFAULT_CLIENT_DOMAIN,
98    &imx_mmu_config_table[0],
99    RTEMS_ARRAY_SIZE(imx_mmu_config_table)
100  );
101}
102
103BSP_START_TEXT_SECTION void bsp_start_hook_0(void)
104{
105#ifdef RTEMS_SMP
106  uint32_t cpu_id = arm_cortex_a9_get_multiprocessor_cpu_id();
107
108  arm_a9mpcore_start_enable_smp_in_auxiliary_control();
109
110  if (cpu_id != 0) {
111    arm_a9mpcore_start_on_secondary_processor();
112  }
113#endif
114}
115
116BSP_START_TEXT_SECTION void bsp_start_hook_1(void)
117{
118  bsp_start_copy_sections();
119  setup_mmu_and_cache();
120  bsp_start_clear_bss();
121}
122
123static Memory_Area _Memory_Areas[1];
124
125static void bsp_memory_initialize(void)
126{
127  const arm_cp15_start_section_config *section;
128
129  section = &imx_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX];
130  _Memory_Initialize(
131    &_Memory_Areas[0],
132    (void *) section->begin,
133    (void *) section->end
134  );
135}
136
137RTEMS_SYSINIT_ITEM(
138  bsp_memory_initialize,
139  RTEMS_SYSINIT_MEMORY,
140  RTEMS_SYSINIT_ORDER_MIDDLE
141);
142
143static const Memory_Information _Memory_Information =
144  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
145
146const Memory_Information *_Memory_Get(void)
147{
148  return &_Memory_Information;
149}
Note: See TracBrowser for help on using the repository browser.