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

5
Last change on this file since f1f6cd95 was f1f6cd95, checked in by Christian Mauderer <christian.mauderer@…>, on 12/27/19 at 21:08:12

bsp/raspberrypi: Fix size of work area.

The BSP tried to get the size of the SDRAM based on the revision code.
Unfortunately the code had some bugs so that the default size has been
used. Beneath that the MMU table hasn't been adapted.

This patch queries the SDRAM size via a special VC Mailbox call instead.
For the MMU adaption a simmilar method to the one in the imx BSP is
used.

  • Property mode set to 100644
File size: 4.8 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
14 * embedded brains GmbH
15 * Obere Lagerstr. 30
16 * D-82178 Puchheim
17 * Germany
18 * <rtems@embedded-brains.de>
19 *
20 * The license and distribution terms for this file may be
21 * found in the file LICENSE in this distribution or at
22 * http://www.rtems.org/license/LICENSE
23 */
24
25#include <bspopts.h>
26#include <bsp/start.h>
27#include <bsp/raspberrypi.h>
28#include <libcpu/arm-cp15.h>
29#include <bsp.h>
30#include <bsp/bootcard.h>
31#include <bsp/linker-symbols.h>
32#include <bsp/arm-cp15-start.h>
33
34#ifdef RTEMS_SMP
35#include <rtems/score/smp.h>
36#endif
37
38#if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG)
39  #define USE_UBOOT
40#endif
41
42#ifdef USE_UBOOT
43  #include <bsp/u-boot.h>
44#else
45  #include <bsp/vc.h>
46#endif
47
48BSP_START_DATA_SECTION static arm_cp15_start_section_config
49raspberrypi_mmu_config_table[] = {
50  ARMV7_CP15_START_DEFAULT_SECTIONS,
51  {
52    .begin = RPI_PERIPHERAL_BASE,
53    .end =   RPI_PERIPHERAL_BASE + RPI_PERIPHERAL_SIZE,
54    .flags = ARMV7_MMU_DEVICE
55  }
56#if (BSP_IS_RPI2 == 1)
57  /* Core local peripherals area - timer, mailboxes */
58  , {
59    .begin = BCM2836_CORE_LOCAL_PERIPH_BASE,
60    .end =   BCM2836_CORE_LOCAL_PERIPH_BASE + BCM2836_CORE_LOCAL_PERIPH_SIZE,
61    .flags = ARMV7_MMU_DEVICE
62  }
63#endif
64};
65
66void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
67{
68  uint32_t sctlr_val;
69#ifdef RTEMS_SMP
70  uint32_t cpu_index_self = _SMP_Get_current_processor();
71#endif /* RTEMS_SMP */
72
73  sctlr_val = arm_cp15_get_control();
74
75  /*
76   * Current U-boot loader seems to start kernel image
77   * with I and D caches on and MMU enabled.
78   * If RTEMS application image finds that cache is on
79   * during startup then disable caches.
80   */
81  if (sctlr_val & (ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M)) {
82    if (sctlr_val & (ARM_CP15_CTRL_C | ARM_CP15_CTRL_M)) {
83      /*
84       * If the data cache is on then ensure that it is clean
85       * before switching off to be extra carefull.
86       */
87#ifdef RTEMS_SMP
88      if (cpu_index_self != 0) {
89        arm_cp15_data_cache_clean_level(0);
90        arm_cp15_cache_invalidate_level(0, 0);
91      } else
92#endif /* RTEMS_SMP */
93      {
94        rtems_cache_flush_entire_data();
95        rtems_cache_invalidate_entire_data();
96      }
97    }
98    arm_cp15_flush_prefetch_buffer();
99    sctlr_val &= ~(ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M | ARM_CP15_CTRL_A);
100    arm_cp15_set_control(sctlr_val);
101  }
102#ifdef RTEMS_SMP
103  if (cpu_index_self != 0) {
104    arm_cp15_cache_invalidate_level(0, 0);
105  } else
106#endif /* RTEMS_SMP */
107  {
108    rtems_cache_invalidate_entire_data();
109  }
110  rtems_cache_invalidate_entire_instruction();
111  arm_cp15_branch_predictor_invalidate_all();
112  arm_cp15_tlb_invalidate();
113  arm_cp15_flush_prefetch_buffer();
114
115  /* Clear Translation Table Base Control Register */
116  arm_cp15_set_translation_table_base_control_register(0);
117
118  /* Clear Secure or Non-secure Vector Base Address Register */
119  arm_cp15_set_vector_base_address(bsp_vector_table_begin);
120
121#ifdef RTEMS_SMP
122  if (cpu_index_self == 0) {
123    rpi_ipi_initialize();
124  } else {
125    rpi_start_rtems_on_secondary_processor();
126  }
127#endif
128}
129
130BSP_START_TEXT_SECTION static uintptr_t raspberrypi_get_ram_end(void)
131{
132  uintptr_t ram_end;
133
134#ifdef USE_UBOOT
135  ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
136                        bsp_uboot_board_info.bi_memsize;
137#else
138  bcm2835_get_arm_memory_entries spec;
139
140  if (bcm2835_mailbox_get_arm_memory( &spec ) >= 0) {
141    ram_end = spec.base + spec.size;
142  } else {
143    /* Use the workspace end from the linker command file for fallback. */
144    ram_end = (uintptr_t) bsp_section_work_end;
145  }
146#endif
147
148  return ram_end;
149}
150
151BSP_START_TEXT_SECTION static void bsp_memory_management_initialize(void)
152{
153  uintptr_t ram_end = raspberrypi_get_ram_end();
154  uint32_t ctrl = arm_cp15_get_control();
155
156  ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
157
158  raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end =
159    ram_end;
160
161  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
162    ctrl,
163    (uint32_t *) bsp_translation_table_base,
164    ARM_MMU_DEFAULT_CLIENT_DOMAIN,
165    &raspberrypi_mmu_config_table[0],
166    RTEMS_ARRAY_SIZE(raspberrypi_mmu_config_table)
167  );
168}
169
170void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
171{
172  bsp_start_copy_sections();
173  bsp_memory_management_initialize();
174  bsp_start_clear_bss();
175
176  rpi_video_init();
177}
178
179void bsp_work_area_initialize(void)
180{
181  uintptr_t begin;
182  uintptr_t end;
183
184  begin = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
185          .begin;
186  end = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
187        .end;
188
189  bsp_work_area_initialize_default((void *) begin, end - begin);
190}
Note: See TracBrowser for help on using the repository browser.