File indexing completed on 2025-05-11 08:23:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <bspopts.h>
0021 #include <bsp/start.h>
0022 #include <bsp/raspberrypi.h>
0023 #include <libcpu/arm-cp15.h>
0024 #include <bsp.h>
0025 #include <bsp/bootcard.h>
0026 #include <bsp/linker-symbols.h>
0027 #include <bsp/arm-cp15-start.h>
0028
0029 #include <rtems/sysinit.h>
0030
0031 #ifdef RTEMS_SMP
0032 #include <rtems/score/smp.h>
0033 #endif
0034
0035 #if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG)
0036 #define USE_UBOOT
0037 #endif
0038
0039 #ifdef USE_UBOOT
0040 #include <bsp/u-boot.h>
0041 #else
0042 #include <bsp/vc.h>
0043 #endif
0044
0045 BSP_START_DATA_SECTION static arm_cp15_start_section_config
0046 raspberrypi_mmu_config_table[] = {
0047 ARMV7_CP15_START_DEFAULT_SECTIONS,
0048 {
0049 .begin = RPI_PERIPHERAL_BASE,
0050 .end = RPI_PERIPHERAL_BASE + RPI_PERIPHERAL_SIZE,
0051 .flags = ARMV7_MMU_DEVICE
0052 }
0053 #if (BSP_IS_RPI2 == 1)
0054
0055 , {
0056 .begin = BCM2836_CORE_LOCAL_PERIPH_BASE,
0057 .end = BCM2836_CORE_LOCAL_PERIPH_BASE + BCM2836_CORE_LOCAL_PERIPH_SIZE,
0058 .flags = ARMV7_MMU_DEVICE
0059 }
0060 #endif
0061 };
0062
0063 void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
0064 {
0065
0066 arm_cp15_set_translation_table_base_control_register(0);
0067
0068 #ifdef RTEMS_SMP
0069 if (_SMP_Get_current_processor() == 0) {
0070 rpi_ipi_initialize();
0071 } else {
0072 rpi_start_rtems_on_secondary_processor();
0073 }
0074 #endif
0075 }
0076
0077 BSP_START_TEXT_SECTION static uintptr_t raspberrypi_get_ram_end(void)
0078 {
0079 uintptr_t ram_end;
0080
0081 #ifdef USE_UBOOT
0082 ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
0083 bsp_uboot_board_info.bi_memsize;
0084 #else
0085 bcm2835_get_arm_memory_entries spec;
0086
0087 if (bcm2835_mailbox_get_arm_memory( &spec ) >= 0) {
0088 ram_end = spec.base + spec.size;
0089 } else {
0090
0091 ram_end = (uintptr_t) bsp_section_work_end;
0092 }
0093 #endif
0094
0095 return ram_end;
0096 }
0097
0098 BSP_START_TEXT_SECTION static void bsp_memory_management_initialize(void)
0099 {
0100 uintptr_t ram_end = raspberrypi_get_ram_end();
0101 uint32_t ctrl = arm_cp15_get_control();
0102
0103 ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
0104
0105 raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end =
0106 ram_end;
0107
0108 arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
0109 ctrl,
0110 (uint32_t *) bsp_translation_table_base,
0111 ARM_MMU_DEFAULT_CLIENT_DOMAIN,
0112 &raspberrypi_mmu_config_table[0],
0113 RTEMS_ARRAY_SIZE(raspberrypi_mmu_config_table)
0114 );
0115 }
0116
0117 void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
0118 {
0119 bsp_start_copy_sections();
0120 bsp_memory_management_initialize();
0121 bsp_start_clear_bss();
0122
0123 rpi_video_init();
0124 }
0125
0126 static Memory_Area _Memory_Areas[1];
0127
0128 static void bsp_memory_initialize(void)
0129 {
0130 _Memory_Initialize(
0131 &_Memory_Areas[0],
0132 (void *)
0133 raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
0134 (void *)
0135 raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
0136 );
0137 }
0138
0139 RTEMS_SYSINIT_ITEM(
0140 bsp_memory_initialize,
0141 RTEMS_SYSINIT_MEMORY,
0142 RTEMS_SYSINIT_ORDER_MIDDLE
0143 );
0144
0145 static const Memory_Information _Memory_Information =
0146 MEMORY_INFORMATION_INITIALIZER(_Memory_Areas);
0147
0148 const Memory_Information *_Memory_Get(void)
0149 {
0150 return &_Memory_Information;
0151 }