source: rtems/bsps/arm/raspberrypi/start/bspstarthooks.c @ ba619b7f

Last change on this file since ba619b7f was ba619b7f, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:38:20

bsps/arm/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_start
5 *
6 * @brief Rasberry Pi startup code.
7 */
8
9/*
10 * Copyright (c) 2013. Hesham AL-Matary
11 * Copyright (c) 2013 by Alan Cudmore
12 * based on work by:
13 * Copyright (c) 2009 embedded brains GmbH.  All rights reserved.
14 *
15 * The license and distribution terms for this file may be
16 * found in the file LICENSE in this distribution or at
17 * http://www.rtems.org/license/LICENSE
18 */
19
20#include <bspopts.h>
21#include <bsp/start.h>
22#include <bsp/raspberrypi.h>
23#include <libcpu/arm-cp15.h>
24#include <bsp.h>
25#include <bsp/bootcard.h>
26#include <bsp/linker-symbols.h>
27#include <bsp/arm-cp15-start.h>
28
29#include <rtems/sysinit.h>
30
31#ifdef RTEMS_SMP
32#include <rtems/score/smp.h>
33#endif
34
35#if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG)
36  #define USE_UBOOT
37#endif
38
39#ifdef USE_UBOOT
40  #include <bsp/u-boot.h>
41#else
42  #include <bsp/vc.h>
43#endif
44
45BSP_START_DATA_SECTION static arm_cp15_start_section_config
46raspberrypi_mmu_config_table[] = {
47  ARMV7_CP15_START_DEFAULT_SECTIONS,
48  {
49    .begin = RPI_PERIPHERAL_BASE,
50    .end =   RPI_PERIPHERAL_BASE + RPI_PERIPHERAL_SIZE,
51    .flags = ARMV7_MMU_DEVICE
52  }
53#if (BSP_IS_RPI2 == 1)
54  /* Core local peripherals area - timer, mailboxes */
55  , {
56    .begin = BCM2836_CORE_LOCAL_PERIPH_BASE,
57    .end =   BCM2836_CORE_LOCAL_PERIPH_BASE + BCM2836_CORE_LOCAL_PERIPH_SIZE,
58    .flags = ARMV7_MMU_DEVICE
59  }
60#endif
61};
62
63void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
64{
65  /* Clear Translation Table Base Control Register */
66  arm_cp15_set_translation_table_base_control_register(0);
67
68#ifdef RTEMS_SMP
69  if (_SMP_Get_current_processor() == 0) {
70    rpi_ipi_initialize();
71  } else {
72    rpi_start_rtems_on_secondary_processor();
73  }
74#endif
75}
76
77BSP_START_TEXT_SECTION static uintptr_t raspberrypi_get_ram_end(void)
78{
79  uintptr_t ram_end;
80
81#ifdef USE_UBOOT
82  ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
83                        bsp_uboot_board_info.bi_memsize;
84#else
85  bcm2835_get_arm_memory_entries spec;
86
87  if (bcm2835_mailbox_get_arm_memory( &spec ) >= 0) {
88    ram_end = spec.base + spec.size;
89  } else {
90    /* Use the workspace end from the linker command file for fallback. */
91    ram_end = (uintptr_t) bsp_section_work_end;
92  }
93#endif
94
95  return ram_end;
96}
97
98BSP_START_TEXT_SECTION static void bsp_memory_management_initialize(void)
99{
100  uintptr_t ram_end = raspberrypi_get_ram_end();
101  uint32_t ctrl = arm_cp15_get_control();
102
103  ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
104
105  raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end =
106    ram_end;
107
108  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
109    ctrl,
110    (uint32_t *) bsp_translation_table_base,
111    ARM_MMU_DEFAULT_CLIENT_DOMAIN,
112    &raspberrypi_mmu_config_table[0],
113    RTEMS_ARRAY_SIZE(raspberrypi_mmu_config_table)
114  );
115}
116
117void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
118{
119  bsp_start_copy_sections();
120  bsp_memory_management_initialize();
121  bsp_start_clear_bss();
122
123  rpi_video_init();
124}
125
126static Memory_Area _Memory_Areas[1];
127
128static void bsp_memory_initialize(void)
129{
130  _Memory_Initialize(
131    &_Memory_Areas[0],
132    (void *)
133    raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
134    (void *)
135    raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
136  );
137}
138
139RTEMS_SYSINIT_ITEM(
140  bsp_memory_initialize,
141  RTEMS_SYSINIT_MEMORY,
142  RTEMS_SYSINIT_ORDER_MIDDLE
143);
144
145static const Memory_Information _Memory_Information =
146  MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
147
148const Memory_Information *_Memory_Get(void)
149{
150  return &_Memory_Information;
151}
Note: See TracBrowser for help on using the repository browser.