Changeset 440 for soft/giet_vm/giet_kernel/kernel_init.c
- Timestamp:
- Nov 3, 2014, 11:03:55 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/kernel_init.c
r428 r440 5 5 // Copyright (c) UPMC-LIP6 6 6 //////////////////////////////////////////////////////////////////////////////////// 7 // The kernel_init.c file is part of the GIET-VM nano-kernel. 8 // 9 // This nano-kernel has been written for the MIPS32 processor. 10 // The virtual adresses are on 32 bits and use the (unsigned int) type, but the 11 // physicals addresses can have up to 40 bits, and use the (unsigned long long) type. 12 // It natively supports clusterised shared mmemory multi-processors architectures, 13 // where each processor is identified by a composite index [x,y,lpid], 14 // and where there is one physical memory bank per cluster. 15 // 16 // The kernel_init() function is executed sequencially by all procesors. 17 // It completes the system initialisation that has been started by processor[0,0,0] 18 // in the boot_init() function. It makes the following assuptions, regarding the work 19 // bone by the boot code: 20 // 21 // 1) The page tables associated to the various vspaces have been build 22 // in physical memory, and can be used by the kernel code. 23 // 24 // 2) All schedulers (this include all task contexts) have been initialised, 25 // Both the virtual and the physical base addresses of the page tables 26 // are available in the CTX_PTAB and CTX_PTPR slots. 27 // 28 // 3) The CP0_SCHED register of each processor contains a pointer on its 29 // private scheduler (virtual address). 30 // 31 // 4) The CP2_PTPR register of each processor contains a pointer on 32 // the vspace_0 page table (physical address>>13). 33 // 34 // 5) For all processors, the MMU is activated (CP2_MODE contains 0xF). 35 // 36 // This code must be loaded in .kinit section, in order to control seg_kinit_base, 37 // as this address is used by the boot code to jump into kernel code. 38 // 39 // Each processor performs the following actions: 40 // 1/ contribute to _schedulers_paddr[] array initialisation. 41 // 2/ contribute to _ptabs_paddr[] and _ptabs_vaddr arrays initialisation 42 // 3/ completes task context initialisation for ech allocated task 43 // 4/ compute and set the ICU mask for its private ICU channel 44 // 5/ initialise its private TICK timer (if tasks > 0) 45 // 6/ initialise the "idle" task context in its private scheduler 46 // 7/ initialise SP, SR, PTPR, EPC registers and jump to user code with an eret. 7 // This kernel_init.c file is part of the GIET-VM nano-kernel. 47 8 //////////////////////////////////////////////////////////////////////////////////// 48 9 49 10 #include <giet_config.h> 50 51 // kernel libraries 11 #include <hard_config.h> 52 12 #include <utils.h> 13 #include <kernel_utils.h> 53 14 #include <fat32.h> 54 55 //for peripheral initialisation56 #include <dma_driver.h>57 #include <fbf_driver.h>58 #include <tty_driver.h>59 #include <icu_driver.h>60 15 #include <xcu_driver.h> 61 #include <ioc_driver.h>62 #include <mmc_driver.h>63 #include <mwr_driver.h>64 #include <nic_driver.h>65 #include <tim_driver.h>66 67 16 #include <ctx_handler.h> 68 17 #include <irq_handler.h> 69 70 18 #include <mapping_info.h> 71 19 #include <mips32_registers.h> … … 146 94 { 147 95 // gpid : hardware processor index (fixed format: X_WIDTH|Y_WIDTH|P_WIDTH) 148 // lpid : local processor id in a cluster ( lpid< NB_PROCS_MAX)96 // p : local processor id in a cluster ( p < NB_PROCS_MAX) 149 97 // cpid : "continuous" processor index = (((x * Y_SIZE + y) * NB_PROCS_MAX) + p 150 98 … … 153 101 unsigned int x = cluster_xy >> Y_WIDTH & ((1<<X_WIDTH)-1); 154 102 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 155 unsigned int lpid= gpid & ((1<<P_WIDTH)-1);156 unsigned int cpid = ((( x * Y_SIZE) + y) * NB_PROCS_MAX) + lpid;103 unsigned int p = gpid & ((1<<P_WIDTH)-1); 104 unsigned int cpid = ((( x * Y_SIZE) + y) * NB_PROCS_MAX) + p; 157 105 158 106 … … 160 108 while( cpid != kernel_init_barrier ) asm volatile ( "nop" ); 161 109 162 // Step 1 : each processor get its scheduler virtual address from CP0 register163 // and contribute to initialise the _schedulers[] array110 // Step 1 : each processor get its scheduler virtual address from CP0_SCHED register 111 // and contributes to _schedulers[] array initialisation 164 112 165 113 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 166 114 unsigned int tasks = psched->tasks; 167 115 168 _schedulers[x][y][ lpid] = psched;116 _schedulers[x][y][p] = psched; 169 117 170 118 #if GIET_DEBUG_INIT … … 172 120 " - scheduler vbase = %x\n" 173 121 " - tasks = %d\n", 174 x, y, lpid, (unsigned int)psched, tasks );122 x, y, p, (unsigned int)psched, tasks ); 175 123 #endif 176 124 … … 181 129 // - set CTX_EPC slot that must contain the task entry point, 182 130 // and contain only at this point the virtual address of the memory 183 // location containing this entry point. We must switch the PTPR 184 // to use the page table corresponding to the task. 131 // location containing this entry point. 185 132 186 133 unsigned int ltid; … … 188 135 for (ltid = 0; ltid < tasks; ltid++) 189 136 { 190 unsigned int vsid = _get_task_slot( x, y, lpid, ltid , CTX_VSID_ID );191 unsigned int ptab = _get_task_slot( x, y, lpid, ltid , CTX_PTAB_ID );192 unsigned int ptpr = _get_task_slot( x, y, lpid, ltid , CTX_PTPR_ID );137 unsigned int vsid = _get_task_slot( x, y, p, ltid , CTX_VSID_ID ); 138 unsigned int ptab = _get_task_slot( x, y, p, ltid , CTX_PTAB_ID ); 139 unsigned int ptpr = _get_task_slot( x, y, p, ltid , CTX_PTPR_ID ); 193 140 194 141 // initialize PTABS arrays … … 199 146 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] contributes to PTABS arrays\n" 200 147 " - ptabs_vaddr[%d] = %x / ptpr_paddr[%d] = %l\n", 201 x, y, lpid,148 x, y, p, 202 149 vsid, ptab, vsid, ((unsigned long long)ptpr)<<13 ); 203 150 #endif … … 209 156 // compute ctx_ra 210 157 unsigned int ctx_ra = (unsigned int)(&_ctx_eret); 211 _set_task_slot( x, y, lpid, ltid, CTX_RA_ID, ctx_ra );158 _set_task_slot( x, y, p, ltid, CTX_RA_ID, ctx_ra ); 212 159 213 160 // compute ctx_epc 214 unsigned int* ptr = (unsigned int*)_get_task_slot( x, y, lpid, ltid, CTX_EPC_ID );215 _set_task_slot( x, y, lpid, ltid, CTX_EPC_ID, *ptr );161 unsigned int* ptr = (unsigned int*)_get_task_slot( x, y, p, ltid, CTX_EPC_ID ); 162 _set_task_slot( x, y, p, ltid, CTX_EPC_ID, *ptr ); 216 163 217 164 #if GIET_DEBUG_INIT … … 219 166 " - ctx_epc = %x\n" 220 167 " - ctx_ra = %x\n", 221 x, y, lpid, ltid,222 _get_task_slot( x, y, lpid, ltid, CTX_EPC_ID ),223 _get_task_slot( x, y, lpid, ltid, CTX_RA_ID ) );168 x, y, p, ltid, 169 _get_task_slot( x, y, p, ltid, CTX_EPC_ID ), 170 _get_task_slot( x, y, p, ltid, CTX_RA_ID ) ); 224 171 #endif 225 172 226 173 } // end for tasks 227 174 228 // step 4 : compute and set ICU orXCU masks175 // step 4 : compute and set XCU masks 229 176 230 177 unsigned int isr_switch_index = 0xFFFFFFFF; … … 252 199 #if GIET_DEBUG_INIT 253 200 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] sets XCU masks\n" 254 " - ICU HWI_MASK = %x\n" 255 " - ICU WTI_MASK = %x\n" 256 " - ICU PTI_MASK = %x\n", 257 x, y, lpid, hwi_mask, wti_mask, pti_mask ); 258 #endif 259 260 unsigned int channel = lpid * IRQ_PER_PROCESSOR; 261 262 #if USE_XCU 201 " - XCU HWI_MASK = %x\n" 202 " - XCU WTI_MASK = %x\n" 203 " - XCU PTI_MASK = %x\n", 204 x, y, p, hwi_mask, wti_mask, pti_mask ); 205 #endif 206 207 unsigned int channel = p * IRQ_PER_PROCESSOR; 208 263 209 _xcu_set_mask( cluster_xy, channel, hwi_mask, IRQ_TYPE_HWI ); 264 210 _xcu_set_mask( cluster_xy, channel, wti_mask, IRQ_TYPE_WTI ); 265 211 _xcu_set_mask( cluster_xy, channel, pti_mask, IRQ_TYPE_PTI ); 266 #else267 _icu_set_mask( cluster_xy, channel, hwi_mask );268 #endif269 212 270 213 // step 5 : start TICK timer if at least one task … … 275 218 { 276 219 _printf("\n[GIET ERROR] ISR_TICK not found for processor[%d,%d,%d]\n", 277 x, y, lpid);220 x, y, p ); 278 221 _exit(); 279 222 } 280 223 281 224 // start system timer 282 283 #if USE_XCU284 225 _xcu_timer_start( cluster_xy, isr_switch_index, GIET_TICK_VALUE ); 285 #else286 _timer_start( cluster_xy, isr_switch_index, GIET_TICK_VALUE );287 #endif288 226 289 227 } … … 291 229 #if GIET_DEBUG_INIT 292 230 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] starts TICK timer\n", 293 x, y, lpid);231 x, y, p ); 294 232 #endif 295 233 … … 302 240 unsigned int pstack = ((unsigned int)psched) + 0x2000; 303 241 304 _set_task_slot( x, y, lpid, IDLE_TASK_INDEX, CTX_SP_ID, pstack);305 _set_task_slot( x, y, lpid, IDLE_TASK_INDEX, CTX_RA_ID, (unsigned int) &_ctx_eret);306 _set_task_slot( x, y, lpid, IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_idle_task);242 _set_task_slot( x, y, p, IDLE_TASK_INDEX, CTX_SP_ID, pstack); 243 _set_task_slot( x, y, p, IDLE_TASK_INDEX, CTX_RA_ID, (unsigned int) &_ctx_eret); 244 _set_task_slot( x, y, p, IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_idle_task); 307 245 308 246 #if GIET_DEBUG_INIT … … 310 248 " - stack_base = %x\n" 311 249 " - stack_size = 0x1000\n", 312 x, y, lpid, pstack - 0x1000 );250 x, y, p, pstack - 0x1000 ); 313 251 #endif 314 252 … … 324 262 325 263 _printf("\n[GIET WARNING] No task allocated to processor[%d,%d,%d]\n", 326 x, y, lpid);264 x, y, p ); 327 265 } 328 266 else … … 331 269 } 332 270 333 unsigned int sp_value = _get_task_slot( x, y, lpid, ltid, CTX_SP_ID);334 unsigned int sr_value = _get_task_slot( x, y, lpid, ltid, CTX_SR_ID);335 unsigned int ptpr_value = _get_task_slot( x, y, lpid, ltid, CTX_PTPR_ID);336 unsigned int epc_value = _get_task_slot( x, y, lpid, ltid, CTX_EPC_ID);271 unsigned int sp_value = _get_task_slot( x, y, p, ltid, CTX_SP_ID); 272 unsigned int sr_value = _get_task_slot( x, y, p, ltid, CTX_SR_ID); 273 unsigned int ptpr_value = _get_task_slot( x, y, p, ltid, CTX_PTPR_ID); 274 unsigned int epc_value = _get_task_slot( x, y, p, ltid, CTX_EPC_ID); 337 275 338 276 #if GIET_DEBUG_INIT 339 277 _printf("\n[GIET DEBUG INIT] Processor[%d,%d,%d] reach barrier at cycle %d\n", 340 x, y, lpid, _get_proctime() );278 x, y, p, _get_proctime() ); 341 279 #endif 342 280 … … 353 291 " - ptpr = %x\n" 354 292 " - epc = %x\n", 355 x, y, lpid, _get_proctime(),293 x, y, p, _get_proctime(), 356 294 sp_value, sr_value, ptpr_value, epc_value ); 357 295 #endif
Note: See TracChangeset
for help on using the changeset viewer.