File indexing completed on 2025-05-11 08:24:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include <bsp.h>
0034 #include <bsp/fatal.h>
0035 #include <leon.h>
0036 #include <grlib/ambapp.h>
0037 #include <rtems/score/memory.h>
0038 #include <rtems/sysinit.h>
0039
0040 #include <string.h>
0041
0042 #if !defined(LEON3_GPTIMER_BASE)
0043 unsigned int leon3_timer_prescaler __attribute__((weak)) = 0;
0044 int leon3_timer_core_index __attribute__((weak)) = 0;
0045 #endif
0046
0047
0048
0049
0050
0051
0052 static struct ambapp_bus ambapp_plb_instance;
0053
0054 static void *ambapp_plb_alloc( size_t size )
0055 {
0056 return _Memory_Allocate( _Memory_Get(), size, CPU_HEAP_ALIGNMENT );
0057 }
0058
0059 struct ambapp_bus *ambapp_plb( void )
0060 {
0061 struct ambapp_bus *plb;
0062
0063 plb = &ambapp_plb_instance;
0064
0065 if ( plb->root == NULL ) {
0066 struct ambapp_context ctx;
0067
0068 ctx.copy_from_device = (ambapp_memcpy_t) memcpy;
0069 ctx.alloc = ambapp_plb_alloc;
0070
0071
0072
0073
0074
0075
0076 ambapp_scan( plb, LEON3_IO_AREA, &ctx, NULL );
0077 }
0078
0079 return plb;
0080 }
0081
0082
0083
0084
0085 #ifdef RTEMS_DRVMGR_STARTUP
0086 #include <drvmgr/drvmgr.h>
0087 #include <grlib/ambapp_bus_grlib.h>
0088
0089
0090
0091
0092
0093 struct drvmgr_bus_res grlib_drv_resources __attribute__((weak)) =
0094 {
0095 .next = NULL,
0096 .resource =
0097 {
0098 DRVMGR_RES_EMPTY,
0099 }
0100 };
0101
0102
0103 struct grlib_config grlib_bus_config;
0104
0105 static void ambapp_grlib_root_initialize( void )
0106 {
0107
0108 grlib_bus_config.abus = ambapp_plb();
0109 grlib_bus_config.resources = &grlib_drv_resources;
0110 ambapp_grlib_root_register(&grlib_bus_config);
0111 }
0112
0113 RTEMS_SYSINIT_ITEM(
0114 ambapp_grlib_root_initialize,
0115 RTEMS_SYSINIT_BSP_START,
0116 RTEMS_SYSINIT_ORDER_SECOND
0117 );
0118 #endif
0119
0120 #if !defined(LEON3_IRQAMP_BASE)
0121 irqamp *LEON3_IrqCtrl_Regs;
0122 struct ambapp_dev *LEON3_IrqCtrl_Adev;
0123 #endif
0124
0125 #if !defined(LEON3_GPTIMER_BASE)
0126 gptimer *LEON3_Timer_Regs;
0127 struct ambapp_dev *LEON3_Timer_Adev;
0128 #endif
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 static void amba_initialize(void)
0141 {
0142 struct ambapp_dev *adev;
0143 struct ambapp_bus *plb;
0144
0145 plb = ambapp_plb();
0146 #if defined(LEON3_IRQAMP_BASE) && defined(LEON3_GPTIMER_BASE)
0147 (void) plb;
0148 (void) adev;
0149 #endif
0150
0151 #if !defined(LEON3_IRQAMP_BASE)
0152
0153 adev = (void *)ambapp_for_each(plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
0154 VENDOR_GAISLER, GAISLER_IRQMP,
0155 ambapp_find_by_idx, NULL);
0156 if (adev == NULL) {
0157
0158
0159
0160
0161 bsp_fatal(LEON3_FATAL_NO_IRQMP_CONTROLLER);
0162 }
0163
0164 LEON3_IrqCtrl_Regs = (irqamp *)DEV_TO_APB(adev)->start;
0165 LEON3_IrqCtrl_Adev = adev;
0166 if ((grlib_load_32(&LEON3_IrqCtrl_Regs->asmpctrl) >> 28) > 0) {
0167 uint32_t icsel;
0168
0169
0170
0171
0172
0173
0174 icsel = grlib_load_32(&LEON3_IrqCtrl_Regs->icselr[LEON3_Cpu_Index/8]);
0175 icsel = (icsel >> ((7 - (LEON3_Cpu_Index & 0x7)) * 4)) & 0xf;
0176 LEON3_IrqCtrl_Regs += icsel;
0177 }
0178 #endif
0179
0180 #if !defined(LEON3_GPTIMER_BASE)
0181
0182 adev = (void *)ambapp_for_each(plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
0183 VENDOR_GAISLER, GAISLER_GPTIMER,
0184 ambapp_find_by_idx, &leon3_timer_core_index);
0185 if (adev) {
0186 LEON3_Timer_Regs = (gptimer *)DEV_TO_APB(adev)->start;
0187 LEON3_Timer_Adev = adev;
0188
0189
0190 ambapp_freq_init(
0191 plb,
0192 LEON3_Timer_Adev,
0193 (grlib_load_32(&LEON3_Timer_Regs->sreload) + 1)
0194 * LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER
0195 );
0196
0197
0198
0199
0200
0201 if (leon3_timer_prescaler)
0202 grlib_store_32(&LEON3_Timer_Regs->sreload, leon3_timer_prescaler);
0203 }
0204 #endif
0205 }
0206
0207 RTEMS_SYSINIT_ITEM(
0208 amba_initialize,
0209 RTEMS_SYSINIT_BSP_EARLY,
0210 RTEMS_SYSINIT_ORDER_MIDDLE
0211 );