1 | /* |
---|
2 | * boot.c - TSAR bootloader implementation. |
---|
3 | * |
---|
4 | * Authors : Alain Greiner / Vu Son (2016) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | /**************************************************************************** |
---|
25 | * This file contains the ALMOS-MKH. boot-loader for the TSAR architecture. * |
---|
26 | * * |
---|
27 | * It supports clusterised shared memory multi-processor architectures, * |
---|
28 | * where each processor core is identified by a composite index [cxy,lid] * |
---|
29 | * with one physical memory bank per cluster. * |
---|
30 | * * |
---|
31 | * The 'boot.elf' file (containing the boot-loader binary code) is stored * |
---|
32 | * on disk and is loaded into memory by core[0,0] (cxy = 0 / lid = 0), * |
---|
33 | * and is copied in each other cluter by the local CP0 (lid = 0]. * |
---|
34 | * * |
---|
35 | * 1) The boot-loader first phase is executed by core[0,0], while * |
---|
36 | * all other cores are waiting in the preloader. * |
---|
37 | * It does the following tasks: * |
---|
38 | * - load into the memory bank of cluster 0 the 'arch_info.bin' * |
---|
39 | * file (containing the hardware architecture description) and the * |
---|
40 | * 'kernel.elf' file, at temporary locations, * |
---|
41 | * - initializes the 'boot_info_t' structure in cluster(0,0) * |
---|
42 | * (there is 1 'boot_info_t' per cluster), which contains both * |
---|
43 | * global and cluster specific information that will be used for * |
---|
44 | * kernel initialisation. * |
---|
45 | * - activate CP0s in all other clusters, using IPIs. * |
---|
46 | * - wait completion reports from CP0s on a global barrier. * |
---|
47 | * * |
---|
48 | * 2) The boot-loader second phase is then executed in parallel by all * |
---|
49 | * CP0s (other than core[0,0]). Each CP0 performs the following tasks: * |
---|
50 | * - copies into the memory bank of the local cluster the 'boot.elf', * |
---|
51 | * the 'arch_info.bin' (at the same addresses as the 'boot.elf' and * |
---|
52 | * the 'arch_info.bin' in the memory bank of the cluster(0,0), and * |
---|
53 | * the kernel image (at address 0x0), * |
---|
54 | * - initializes the 'boot_info_t' structure of the local cluster, * |
---|
55 | * - activate all other cores in the same cluster (CPi). * |
---|
56 | * - wait local CPi completion reports on a local barrier. * |
---|
57 | * - report completion to bscpu on the global barrier. * |
---|
58 | * * |
---|
59 | * 3) The boot-loader third phase is executed in parallel by all cores. * |
---|
60 | * After passing the global barrier the bscpu: * |
---|
61 | * - activates the CPi of cluster(0), * |
---|
62 | * - blocks on the local barrier waiting for all local CPi to report * |
---|
63 | * completion on the local barrier, * |
---|
64 | * - moves the local kernel image from the temporary location to the * |
---|
65 | * address 0x0, (erasing the preloader code). * |
---|
66 | * * |
---|
67 | * 4) All cores have finished the boot phase, they jump to the kern_init() * |
---|
68 | * function (maybe not at the same time). * |
---|
69 | ****************************************************************************/ |
---|
70 | |
---|
71 | #include <elf-types.h> |
---|
72 | #include <hal_kernel_types.h> |
---|
73 | |
---|
74 | #include <kernel_config.h> |
---|
75 | #include <boot_config.h> |
---|
76 | |
---|
77 | #include <arch_info.h> |
---|
78 | #include <boot_info.h> |
---|
79 | |
---|
80 | #include <boot_utils.h> |
---|
81 | #include <boot_fat32.h> |
---|
82 | #include <boot_bdv_driver.h> |
---|
83 | #include <boot_hba_driver.h> |
---|
84 | #include <boot_tty_driver.h> |
---|
85 | |
---|
86 | /***************************************************************************** |
---|
87 | * Macros. |
---|
88 | ****************************************************************************/ |
---|
89 | |
---|
90 | #define PAGE_ROUND_DOWN(x) ((x) & (~PPM_PAGE_SIZE -1)) |
---|
91 | #define PAGE_ROUND_UP(x) (((x) + PPM_PAGE_SIZE-1) & \ |
---|
92 | (~(PPM_PAGE_SIZE-1))) |
---|
93 | |
---|
94 | /***************************************************************************** |
---|
95 | * Global variables. |
---|
96 | ****************************************************************************/ |
---|
97 | |
---|
98 | // synchronization variables. |
---|
99 | |
---|
100 | volatile boot_remote_spinlock_t tty0_lock; // protect TTY0 access |
---|
101 | volatile boot_remote_barrier_t global_barrier; // synchronize CP0 cores |
---|
102 | volatile boot_remote_barrier_t local_barrier; // synchronize cores in one cluster |
---|
103 | uint32_t active_cp0s_nr; // number of expected CP0s |
---|
104 | |
---|
105 | // kernel segments layout variables |
---|
106 | |
---|
107 | uint32_t seg_kcode_base; // kcode segment base address |
---|
108 | uint32_t seg_kcode_size; // kcode segment size (bytes) |
---|
109 | uint32_t seg_kdata_base; // kdata segment base address |
---|
110 | uint32_t seg_kdata_size; // kdata segment size (bytes) |
---|
111 | uint32_t seg_kentry_base; // kcode segment base address |
---|
112 | uint32_t seg_kentry_size; // kcode segment size (bytes) |
---|
113 | |
---|
114 | uint32_t kernel_entry; // kernel entry point |
---|
115 | |
---|
116 | // address used by the WTI to activate remote CP0s |
---|
117 | |
---|
118 | // Functions called by boot_entry.S must be externs. |
---|
119 | extern void boot_entry( void ); // boot_loader entry point |
---|
120 | extern void boot_loader( lid_t lid, cxy_t cxy ); |
---|
121 | |
---|
122 | /********************************************************************************* |
---|
123 | * This function returns the printable string for each device type |
---|
124 | ********************************************************************************/ |
---|
125 | static const char * device_type_str( uint32_t dev_type ) |
---|
126 | { |
---|
127 | if ( dev_type == DEV_TYPE_RAM_SCL ) return "RAM_SCL"; |
---|
128 | else if( dev_type == DEV_TYPE_ROM_SCL ) return "ROM_SCL"; |
---|
129 | else if( dev_type == DEV_TYPE_FBF_SCL ) return "FBF_SCL"; |
---|
130 | else if( dev_type == DEV_TYPE_IOB_TSR ) return "IOB_TSR"; |
---|
131 | else if( dev_type == DEV_TYPE_IOC_BDV ) return "IOC_BDV"; |
---|
132 | else if( dev_type == DEV_TYPE_IOC_HBA ) return "IOC_HBA"; |
---|
133 | else if( dev_type == DEV_TYPE_IOC_SDC ) return "IOC_SDC"; |
---|
134 | else if( dev_type == DEV_TYPE_IOC_SPI ) return "IOC_SPI"; |
---|
135 | else if( dev_type == DEV_TYPE_IOC_RDK ) return "IOC_RDK"; |
---|
136 | else if( dev_type == DEV_TYPE_MMC_TSR ) return "MMC_TSR"; |
---|
137 | else if( dev_type == DEV_TYPE_DMA_SCL ) return "DMA_SCL"; |
---|
138 | else if( dev_type == DEV_TYPE_NIC_CBF ) return "NIC_CBF"; |
---|
139 | else if( dev_type == DEV_TYPE_TIM_SCL ) return "TIM_SCL"; |
---|
140 | else if( dev_type == DEV_TYPE_TXT_TTY ) return "TXT_TTY"; |
---|
141 | else if( dev_type == DEV_TYPE_ICU_XCU ) return "ICU_XCU"; |
---|
142 | else if( dev_type == DEV_TYPE_PIC_TSR ) return "PIC_TSR"; |
---|
143 | else return "undefined"; |
---|
144 | } |
---|
145 | |
---|
146 | /************************************************************************************ |
---|
147 | * This function loads the arch_info.bin file into the boot cluster memory. |
---|
148 | ***********************************************************************************/ |
---|
149 | static void boot_archinfo_load( void ) |
---|
150 | { |
---|
151 | archinfo_header_t* header = (archinfo_header_t*)ARCHINFO_BASE; |
---|
152 | |
---|
153 | // Load file into memory |
---|
154 | if (boot_fat32_load(ARCHINFO_PATHNAME, ARCHINFO_BASE, ARCHINFO_MAX_SIZE)) |
---|
155 | { |
---|
156 | boot_printf("\n[BOOT ERROR]: boot_archinfo_load(): " |
---|
157 | "<%s> file not found\n", |
---|
158 | ARCHINFO_PATHNAME); |
---|
159 | boot_exit(); |
---|
160 | } |
---|
161 | |
---|
162 | if (header->signature != ARCHINFO_SIGNATURE) |
---|
163 | { |
---|
164 | boot_printf("\n[BOOT_ERROR]: boot_archinfo_load(): " |
---|
165 | "<%s> file signature should be %x\n", |
---|
166 | ARCHINFO_PATHNAME, ARCHINFO_SIGNATURE); |
---|
167 | boot_exit(); |
---|
168 | } |
---|
169 | |
---|
170 | #if DEBUG_BOOT_INFO |
---|
171 | boot_printf("\n[BOOT INFO] in %s : file %s loaded at address = %x\n", |
---|
172 | __FUNCTION__ , ARCHINFO_PATHNAME , ARCHINFO_BASE ); |
---|
173 | #endif |
---|
174 | |
---|
175 | } // boot_archinfo_load() |
---|
176 | |
---|
177 | /************************************************************************************** |
---|
178 | * This function loads the 'kernel.elf' file into the boot cluster memory buffer, |
---|
179 | * analyzes it, and places the three kcode, kentry, kdata segments at their final |
---|
180 | * physical adresses (defined the .elf file). |
---|
181 | * It set the global variables defining the kernel layout. |
---|
182 | *************************************************************************************/ |
---|
183 | static void boot_kernel_load( void ) |
---|
184 | { |
---|
185 | Elf32_Ehdr * elf_header; // pointer on kernel.elf header. |
---|
186 | Elf32_Phdr * program_header; // pointer on kernel.elf program header. |
---|
187 | uint32_t phdr_offset; // program header offset in kernel.elf file. |
---|
188 | uint32_t segments_nb; // number of segments in kernel.elf file. |
---|
189 | uint32_t seg_src_addr; // segment address in kernel.elf file (source). |
---|
190 | uint32_t seg_paddr; // segment local physical address of segment |
---|
191 | uint32_t seg_offset; // segment offset in kernel.elf file |
---|
192 | uint32_t seg_filesz; // segment size (bytes) in kernel.elf file |
---|
193 | uint32_t seg_memsz; // segment size (bytes) in memory image. |
---|
194 | bool_t kcode_found; // kcode segment found. |
---|
195 | bool_t kdata_found; // kdata segment found. |
---|
196 | bool_t kentry_found; // kentry segment found. |
---|
197 | uint32_t seg_id; // iterator for segments loop. |
---|
198 | |
---|
199 | #if DEBUG_BOOT_ELF |
---|
200 | boot_printf("\n[BOOT INFO] %s enters for file %s at cycle %d\n", |
---|
201 | __FUNCTION__ , KERNEL_PATHNAME , boot_get_proctime() ); |
---|
202 | #endif |
---|
203 | |
---|
204 | // Load kernel.elf file into memory buffer |
---|
205 | if ( boot_fat32_load(KERNEL_PATHNAME, KERN_BASE, KERN_MAX_SIZE) ) |
---|
206 | { |
---|
207 | boot_printf("\n[BOOT ERROR] in %s : <%s> file not found\n", |
---|
208 | KERNEL_PATHNAME); |
---|
209 | boot_exit(); |
---|
210 | } |
---|
211 | |
---|
212 | // get pointer to kernel.elf header |
---|
213 | elf_header = (Elf32_Ehdr*)KERN_BASE; |
---|
214 | |
---|
215 | // check signature |
---|
216 | if ((elf_header->e_ident[EI_MAG0] != ELFMAG0) || |
---|
217 | (elf_header->e_ident[EI_MAG1] != ELFMAG1) || |
---|
218 | (elf_header->e_ident[EI_MAG2] != ELFMAG2) || |
---|
219 | (elf_header->e_ident[EI_MAG3] != ELFMAG3)) |
---|
220 | { |
---|
221 | boot_printf("\n[BOOT_ERROR]: boot_kernel_load(): " |
---|
222 | "<%s> is not an ELF file\n", |
---|
223 | KERNEL_PATHNAME); |
---|
224 | boot_exit(); |
---|
225 | } |
---|
226 | |
---|
227 | // Get program header table offset and number of segments |
---|
228 | phdr_offset = elf_header->e_phoff; |
---|
229 | segments_nb = elf_header->e_phnum; |
---|
230 | |
---|
231 | // Get program header table pointer |
---|
232 | program_header = (Elf32_Phdr*)(KERN_BASE + phdr_offset); |
---|
233 | |
---|
234 | // loop on segments |
---|
235 | kcode_found = false; |
---|
236 | kdata_found = false; |
---|
237 | kentry_found = false; |
---|
238 | for (seg_id = 0; seg_id < segments_nb; seg_id++) |
---|
239 | { |
---|
240 | if (program_header[seg_id].p_type == PT_LOAD) // Found one loadable segment |
---|
241 | { |
---|
242 | // Get segment attributes. |
---|
243 | seg_paddr = program_header[seg_id].p_paddr; |
---|
244 | seg_offset = program_header[seg_id].p_offset; |
---|
245 | seg_filesz = program_header[seg_id].p_filesz; |
---|
246 | seg_memsz = program_header[seg_id].p_memsz; |
---|
247 | |
---|
248 | // get segment base address in buffer |
---|
249 | seg_src_addr = (uint32_t)KERN_BASE + seg_offset; |
---|
250 | |
---|
251 | // Load segment to its final physical memory address |
---|
252 | boot_memcpy( (void*)seg_paddr, |
---|
253 | (void*)seg_src_addr, |
---|
254 | seg_filesz ); |
---|
255 | |
---|
256 | #if DEBUG_BOOT_ELF |
---|
257 | boot_printf("\n[BOOT INFO] in %s for file %s : found loadable segment\n" |
---|
258 | " base = %x / size = %x\n", |
---|
259 | __FUNCTION__ , KERNEL_PATHNAME , seg_paddr , seg_memsz ); |
---|
260 | #endif |
---|
261 | |
---|
262 | // Fill remaining memory with zero if (filesz < memsz). |
---|
263 | if( seg_memsz < seg_filesz ) |
---|
264 | { |
---|
265 | boot_memset( (void*)(seg_paddr + seg_filesz), 0, seg_memsz - seg_filesz); |
---|
266 | } |
---|
267 | |
---|
268 | // Note: we suppose that the 'kernel.elf' file contains exactly |
---|
269 | // three loadable segments ktext, kentry, & kdata: |
---|
270 | // - the kcode segment is read-only and base == KCODE_BASE |
---|
271 | // - the kentry segment is read-only and base == KENTRY_BASE |
---|
272 | |
---|
273 | if( ((program_header[seg_id].p_flags & PF_W) == 0) && |
---|
274 | (program_header[seg_id].p_paddr == KCODE_BASE) ) // kcode segment |
---|
275 | { |
---|
276 | if( kcode_found ) |
---|
277 | { |
---|
278 | boot_printf("\n[BOOT_ERROR] in %s for file %s :\n" |
---|
279 | " two kcode segments found\n", |
---|
280 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
281 | boot_exit(); |
---|
282 | } |
---|
283 | |
---|
284 | kcode_found = true; |
---|
285 | seg_kcode_base = seg_paddr; |
---|
286 | seg_kcode_size = seg_memsz; |
---|
287 | } |
---|
288 | else if( program_header[seg_id].p_paddr == KENTRY_BASE ) // kentry segment |
---|
289 | { |
---|
290 | if( kentry_found ) |
---|
291 | { |
---|
292 | boot_printf("\n[BOOT_ERROR] in %s for file %s :\n" |
---|
293 | " two kentry segments found\n", |
---|
294 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
295 | boot_exit(); |
---|
296 | } |
---|
297 | |
---|
298 | kentry_found = true; |
---|
299 | seg_kentry_base = seg_paddr; |
---|
300 | seg_kentry_size = seg_memsz; |
---|
301 | } |
---|
302 | else // kdata segment |
---|
303 | { |
---|
304 | if( kdata_found ) |
---|
305 | { |
---|
306 | boot_printf("\n[BOOT_ERROR] in %s for file %s :\n" |
---|
307 | " two loadable kdata segments found\n", |
---|
308 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
309 | boot_exit(); |
---|
310 | } |
---|
311 | |
---|
312 | kdata_found = true; |
---|
313 | seg_kdata_base = seg_paddr; |
---|
314 | seg_kdata_size = seg_memsz; |
---|
315 | } |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | // check kcode & kdata segments found |
---|
320 | if( kcode_found == false ) |
---|
321 | { |
---|
322 | boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kcode not found\n", |
---|
323 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
324 | boot_exit(); |
---|
325 | } |
---|
326 | if( kentry_found == false ) |
---|
327 | { |
---|
328 | boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kentry not found\n", |
---|
329 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
330 | boot_exit(); |
---|
331 | } |
---|
332 | if( kdata_found == false ) |
---|
333 | { |
---|
334 | boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kdata not found\n", |
---|
335 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
336 | boot_exit(); |
---|
337 | } |
---|
338 | |
---|
339 | // check segments sizes |
---|
340 | if( seg_kentry_size > KENTRY_MAX_SIZE ) |
---|
341 | { |
---|
342 | boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kentry too large\n", |
---|
343 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
344 | boot_exit(); |
---|
345 | } |
---|
346 | |
---|
347 | if( (seg_kcode_size + seg_kdata_size) > KCODE_MAX_SIZE ) |
---|
348 | { |
---|
349 | boot_printf("\n[BOOT_ERROR] in %s for file %s : seg_kcode + seg_kdata too large\n", |
---|
350 | __FUNCTION__ , KERNEL_PATHNAME ); |
---|
351 | } |
---|
352 | |
---|
353 | // set entry point |
---|
354 | kernel_entry = (uint32_t)elf_header->e_entry; |
---|
355 | |
---|
356 | #if DEBUG_BOOT_ELF |
---|
357 | boot_printf("\n[BOOT INFO] %s completed for file %s at cycle %d\n", |
---|
358 | __FUNCTION__ , KERNEL_PATHNAME , boot_get_proctime() ); |
---|
359 | #endif |
---|
360 | |
---|
361 | } // boot_kernel_load() |
---|
362 | |
---|
363 | /************************************************************************************* |
---|
364 | * This function initializes the boot_info_t structure for a given cluster. |
---|
365 | * @ boot_info : pointer to local boot_info_t structure |
---|
366 | * @ cxy : cluster identifier |
---|
367 | ************************************************************************************/ |
---|
368 | static void boot_info_init( boot_info_t * boot_info, |
---|
369 | cxy_t cxy ) |
---|
370 | { |
---|
371 | archinfo_header_t * header; |
---|
372 | archinfo_core_t * core_base; |
---|
373 | archinfo_cluster_t * cluster_base; |
---|
374 | archinfo_device_t * device_base; |
---|
375 | archinfo_irq_t * irq_base; |
---|
376 | |
---|
377 | archinfo_cluster_t * cluster; |
---|
378 | archinfo_cluster_t * my_cluster = NULL; // target cluster |
---|
379 | archinfo_cluster_t * io_cluster = NULL; // cluster containing ext. peripherals |
---|
380 | |
---|
381 | archinfo_core_t * core; |
---|
382 | uint32_t core_id; |
---|
383 | archinfo_device_t * device; |
---|
384 | uint32_t device_id; |
---|
385 | archinfo_irq_t * irq; |
---|
386 | uint32_t irq_id; |
---|
387 | uint32_t end; |
---|
388 | boot_device_t * boot_dev; |
---|
389 | |
---|
390 | // get pointer on ARCHINFO header and on the four arch_info arrays |
---|
391 | header = (archinfo_header_t*)ARCHINFO_BASE; |
---|
392 | core_base = archinfo_get_core_base (header); |
---|
393 | cluster_base = archinfo_get_cluster_base(header); |
---|
394 | device_base = archinfo_get_device_base (header); |
---|
395 | irq_base = archinfo_get_irq_base (header); |
---|
396 | |
---|
397 | // Initialize global platform parameters |
---|
398 | boot_info->x_size = header->x_size; |
---|
399 | boot_info->y_size = header->y_size; |
---|
400 | boot_info->x_width = header->x_width; |
---|
401 | boot_info->y_width = header->y_width; |
---|
402 | boot_info->x_max = header->x_size; // [FIXME] |
---|
403 | boot_info->y_max = header->name[5] == 'l' ? header->y_size - 1 : header->y_size; // [FIXME] |
---|
404 | boot_info->paddr_width = header->paddr_width; |
---|
405 | boot_info->io_cxy = header->io_cxy; |
---|
406 | |
---|
407 | // Initialize kernel segments from global variables |
---|
408 | boot_info->kcode_base = seg_kcode_base; |
---|
409 | boot_info->kcode_size = seg_kcode_size; |
---|
410 | boot_info->kdata_base = seg_kdata_base; |
---|
411 | boot_info->kdata_size = seg_kdata_size; |
---|
412 | boot_info->kentry_base = seg_kentry_base; |
---|
413 | boot_info->kentry_size = seg_kentry_size; |
---|
414 | |
---|
415 | // loop on arch_info clusters to get relevant pointers |
---|
416 | for (cluster = cluster_base; |
---|
417 | cluster < &cluster_base[header->x_size * header->y_size]; |
---|
418 | cluster++) |
---|
419 | { |
---|
420 | if( cluster->cxy == cxy ) my_cluster = cluster; |
---|
421 | if( cluster->cxy == header->io_cxy ) io_cluster = cluster; |
---|
422 | } |
---|
423 | |
---|
424 | if( my_cluster == NULL ) |
---|
425 | { |
---|
426 | boot_printf("\n[ERROR] in %s : cannot found cluster %x in arch_info\n", |
---|
427 | __FUNCTION__ , cxy ); |
---|
428 | boot_exit(); |
---|
429 | } |
---|
430 | |
---|
431 | if( io_cluster == NULL ) |
---|
432 | { |
---|
433 | boot_printf("\n[ERROR] in %s : cannot found io_cluster %x in arch_info\n", |
---|
434 | __FUNCTION__ , header->io_cxy ); |
---|
435 | boot_exit(); |
---|
436 | } |
---|
437 | |
---|
438 | ////////////////////////////////////////////////////////// |
---|
439 | // initialize the boot_info array of external peripherals |
---|
440 | |
---|
441 | #if DEBUG_BOOT_INFO |
---|
442 | boot_printf("\n[BOOT INFO] %s : external peripherals at cycle %d\n", |
---|
443 | __FUNCTION__ , boot_get_proctime() ); |
---|
444 | #endif |
---|
445 | |
---|
446 | device_id = 0; |
---|
447 | for (device = &device_base[io_cluster->device_offset]; |
---|
448 | device < &device_base[io_cluster->device_offset + io_cluster->devices]; |
---|
449 | device++ ) |
---|
450 | { |
---|
451 | if( device_id >= CONFIG_MAX_EXT_DEV ) |
---|
452 | { |
---|
453 | boot_printf("\n[ERROR] in %s : too much external devices in arch_info\n", |
---|
454 | __FUNCTION__ ); |
---|
455 | boot_exit(); |
---|
456 | } |
---|
457 | |
---|
458 | // keep only external devices |
---|
459 | if( (device->type != DEV_TYPE_RAM_SCL) && |
---|
460 | (device->type != DEV_TYPE_ICU_XCU) && |
---|
461 | (device->type != DEV_TYPE_MMC_TSR) && |
---|
462 | (device->type != DEV_TYPE_DMA_SCL) ) |
---|
463 | { |
---|
464 | boot_dev = &boot_info->ext_dev[device_id]; |
---|
465 | |
---|
466 | boot_dev->type = device->type; |
---|
467 | boot_dev->base = device->base; |
---|
468 | boot_dev->channels = device->channels; |
---|
469 | boot_dev->param0 = device->arg0; |
---|
470 | boot_dev->param1 = device->arg1; |
---|
471 | boot_dev->param2 = device->arg2; |
---|
472 | boot_dev->param3 = device->arg3; |
---|
473 | boot_dev->irqs = device->irqs; |
---|
474 | |
---|
475 | device_id++; |
---|
476 | |
---|
477 | #if DEBUG_BOOT_INFO |
---|
478 | boot_printf(" - %s : base = %l / size = %l / channels = %d / irqs = %d\n", |
---|
479 | device_type_str( device->type ) , device->base , device->size , |
---|
480 | device->channels , device->irqs ); |
---|
481 | #endif |
---|
482 | } |
---|
483 | |
---|
484 | // handle IRQs for PIC |
---|
485 | if (device->type == DEV_TYPE_PIC_TSR) |
---|
486 | { |
---|
487 | for (irq_id = 0; irq_id < CONFIG_MAX_EXTERNAL_IRQS ; irq_id++) |
---|
488 | { |
---|
489 | boot_dev->irq[irq_id].valid = 0; |
---|
490 | } |
---|
491 | |
---|
492 | for (irq = &irq_base[device->irq_offset]; |
---|
493 | irq < &irq_base[device->irq_offset + device->irqs]; |
---|
494 | irq++) |
---|
495 | { |
---|
496 | boot_dev->irq[irq->port].valid = 1; |
---|
497 | boot_dev->irq[irq->port].dev_type = irq->dev_type; |
---|
498 | boot_dev->irq[irq->port].channel = irq->channel; |
---|
499 | boot_dev->irq[irq->port].is_rx = irq->is_rx; |
---|
500 | |
---|
501 | #if DEBUG_BOOT_INFO |
---|
502 | boot_printf(" . irq_port = %d / source = %s / channel = %d / is_rx = %d\n", |
---|
503 | irq->port , device_type_str( irq->dev_type ) , irq->channel , irq->is_rx ); |
---|
504 | #endif |
---|
505 | } |
---|
506 | } |
---|
507 | } // end loop on io_cluster peripherals |
---|
508 | |
---|
509 | // initialize number of external peripherals |
---|
510 | boot_info->ext_dev_nr = device_id; |
---|
511 | |
---|
512 | // Initialize cluster specific resources |
---|
513 | boot_info->cxy = my_cluster->cxy; |
---|
514 | |
---|
515 | #if DEBUG_BOOT_INFO |
---|
516 | boot_printf("\n[BOOT INFO] %s : cores in cluster %x\n", __FUNCTION__ , cxy ); |
---|
517 | #endif |
---|
518 | |
---|
519 | //////////////////////////////////////// |
---|
520 | // Initialize array of core descriptors |
---|
521 | core_id = 0; |
---|
522 | for (core = &core_base[my_cluster->core_offset]; |
---|
523 | core < &core_base[my_cluster->core_offset + my_cluster->cores]; |
---|
524 | core++ ) |
---|
525 | { |
---|
526 | boot_info->core[core_id].gid = (gid_t)core->gid; |
---|
527 | boot_info->core[core_id].lid = (lid_t)core->lid; |
---|
528 | boot_info->core[core_id].cxy = (cxy_t)core->cxy; |
---|
529 | |
---|
530 | #if DEBUG_BOOT_INFO |
---|
531 | boot_printf(" - core_gid = %x : cxy = %x / lid = %d\n", |
---|
532 | core->gid , core->cxy , core->lid ); |
---|
533 | #endif |
---|
534 | core_id++; |
---|
535 | } |
---|
536 | |
---|
537 | // Initialize number of cores in my_cluster |
---|
538 | boot_info->cores_nr = core_id; |
---|
539 | |
---|
540 | ////////////////////////////////////////////////////////////////////// |
---|
541 | // initialise boot_info array of internal devices (RAM, ICU, MMC, DMA) |
---|
542 | |
---|
543 | #if DEBUG_BOOT_INFO |
---|
544 | boot_printf("\n[BOOT INFO] %s : internal peripherals in cluster %x\n", __FUNCTION__ , cxy ); |
---|
545 | #endif |
---|
546 | |
---|
547 | device_id = 0; |
---|
548 | for (device = &device_base[my_cluster->device_offset]; |
---|
549 | device < &device_base[my_cluster->device_offset + my_cluster->devices]; |
---|
550 | device++ ) |
---|
551 | { |
---|
552 | // keep only internal devices |
---|
553 | if( (device->type == DEV_TYPE_RAM_SCL) || |
---|
554 | (device->type == DEV_TYPE_ICU_XCU) || |
---|
555 | (device->type == DEV_TYPE_MMC_TSR) || |
---|
556 | (device->type == DEV_TYPE_DMA_SCL) ) |
---|
557 | { |
---|
558 | if (device->type == DEV_TYPE_RAM_SCL) // RAM |
---|
559 | { |
---|
560 | // set number of physical memory pages |
---|
561 | boot_info->pages_nr = device->size >> CONFIG_PPM_PAGE_SHIFT; |
---|
562 | |
---|
563 | #if DEBUG_BOOT_INFO |
---|
564 | boot_printf(" - RAM : %x pages\n", boot_info->pages_nr ); |
---|
565 | #endif |
---|
566 | } |
---|
567 | else // ICU / MMC / DMA |
---|
568 | { |
---|
569 | if( device_id >= CONFIG_MAX_INT_DEV ) |
---|
570 | { |
---|
571 | boot_printf("\n[ERROR] in %s : too much internal devices in cluster %x\n", |
---|
572 | __FUNCTION__ , cxy ); |
---|
573 | boot_exit(); |
---|
574 | } |
---|
575 | |
---|
576 | boot_dev = &boot_info->int_dev[device_id]; |
---|
577 | |
---|
578 | boot_dev->type = device->type; |
---|
579 | boot_dev->base = device->base; |
---|
580 | boot_dev->channels = device->channels; |
---|
581 | boot_dev->param0 = device->arg0; |
---|
582 | boot_dev->param1 = device->arg1; |
---|
583 | boot_dev->param2 = device->arg2; |
---|
584 | boot_dev->param3 = device->arg3; |
---|
585 | boot_dev->irqs = device->irqs; |
---|
586 | |
---|
587 | device_id++; |
---|
588 | |
---|
589 | #if DEBUG_BOOT_INFO |
---|
590 | boot_printf(" - %s : base = %l / size = %l / channels = %d / irqs = %d\n", |
---|
591 | device_type_str( device->type ) , device->base , device->size , |
---|
592 | device->channels , device->irqs ); |
---|
593 | #endif |
---|
594 | |
---|
595 | // handle IRQs for ICU |
---|
596 | if (device->type == DEV_TYPE_ICU_XCU) |
---|
597 | { |
---|
598 | for (irq_id = 0; irq_id < CONFIG_MAX_INTERNAL_IRQS ; irq_id++) |
---|
599 | { |
---|
600 | boot_dev->irq[irq_id].valid = 0; |
---|
601 | } |
---|
602 | |
---|
603 | for (irq = &irq_base[device->irq_offset]; |
---|
604 | irq < &irq_base[device->irq_offset + device->irqs] ; irq++) |
---|
605 | { |
---|
606 | boot_dev->irq[irq->port].valid = 1; |
---|
607 | boot_dev->irq[irq->port].dev_type = irq->dev_type; |
---|
608 | boot_dev->irq[irq->port].channel = irq->channel; |
---|
609 | boot_dev->irq[irq->port].is_rx = irq->is_rx; |
---|
610 | |
---|
611 | #if DEBUG_BOOT_INFO |
---|
612 | boot_printf(" . irq_port = %d / source = %s / channel = %d / is_rx = %d\n", |
---|
613 | irq->port , device_type_str( irq->dev_type ) , irq->channel , irq->is_rx ); |
---|
614 | #endif |
---|
615 | |
---|
616 | } |
---|
617 | } |
---|
618 | } |
---|
619 | } |
---|
620 | } // end loop on local peripherals |
---|
621 | |
---|
622 | // initialize number of internal peripherals |
---|
623 | boot_info->int_dev_nr = device_id; |
---|
624 | |
---|
625 | // Get the top address of the kernel segments |
---|
626 | end = boot_info->kdata_base + boot_info->kdata_size; |
---|
627 | |
---|
628 | // compute number of physical pages occupied by the kernel code |
---|
629 | boot_info->pages_offset = ( (end & CONFIG_PPM_PAGE_MASK) == 0 ) ? |
---|
630 | (end >> CONFIG_PPM_PAGE_SHIFT) : (end >> CONFIG_PPM_PAGE_SHIFT) + 1; |
---|
631 | |
---|
632 | // no reserved sones for TSAR architecture |
---|
633 | boot_info->rsvd_nr = 0; |
---|
634 | |
---|
635 | // set boot_info signature |
---|
636 | boot_info->signature = BOOT_INFO_SIGNATURE; |
---|
637 | |
---|
638 | } // boot_info_init() |
---|
639 | |
---|
640 | /*********************************************************************************** |
---|
641 | * This function check the local boot_info_t structure for a given core. |
---|
642 | * @ boot_info : pointer to local 'boot_info_t' structure to be checked. |
---|
643 | * @ lid : core local identifier, index the core descriptor table. |
---|
644 | **********************************************************************************/ |
---|
645 | static void boot_check_core( boot_info_t * boot_info, |
---|
646 | lid_t lid) |
---|
647 | { |
---|
648 | gid_t gid; // global hardware identifier of this core |
---|
649 | boot_core_t * this; // BOOT_INFO core descriptor of this core. |
---|
650 | |
---|
651 | // Get core hardware identifier |
---|
652 | gid = (gid_t)boot_get_procid(); |
---|
653 | |
---|
654 | // get pointer on core descriptor |
---|
655 | this = &boot_info->core[lid]; |
---|
656 | |
---|
657 | if ( (this->gid != gid) || (this->cxy != boot_info->cxy) ) |
---|
658 | { |
---|
659 | boot_printf("\n[BOOT ERROR] in boot_check_core() :\n" |
---|
660 | " - boot_info cxy = %x\n" |
---|
661 | " - boot_info lid = %d\n" |
---|
662 | " - boot_info gid = %x\n" |
---|
663 | " - actual gid = %x\n", |
---|
664 | this->cxy , this->lid , this->gid , gid ); |
---|
665 | boot_exit(); |
---|
666 | } |
---|
667 | |
---|
668 | } // boot_check_core() |
---|
669 | |
---|
670 | /********************************************************************************* |
---|
671 | * This function is called by CP0 in cluster(0,0) to activate all other CP0s. |
---|
672 | * It returns the number of CP0s actually activated. |
---|
673 | ********************************************************************************/ |
---|
674 | static uint32_t boot_wake_all_cp0s( void ) |
---|
675 | { |
---|
676 | archinfo_header_t* header; // Pointer on ARCHINFO header |
---|
677 | archinfo_cluster_t* cluster_base; // Pointer on ARCHINFO clusters base |
---|
678 | archinfo_cluster_t* cluster; // Iterator for loop on clusters |
---|
679 | archinfo_device_t* device_base; // Pointer on ARCHINFO devices base |
---|
680 | archinfo_device_t* device; // Iterator for loop on devices |
---|
681 | uint32_t cp0_nb = 0; // CP0s counter |
---|
682 | |
---|
683 | header = (archinfo_header_t*)ARCHINFO_BASE; |
---|
684 | cluster_base = archinfo_get_cluster_base(header); |
---|
685 | device_base = archinfo_get_device_base (header); |
---|
686 | |
---|
687 | // loop on all clusters |
---|
688 | for (cluster = cluster_base; |
---|
689 | cluster < &cluster_base[header->x_size * header->y_size]; |
---|
690 | cluster++) |
---|
691 | { |
---|
692 | // Skip boot cluster. |
---|
693 | if (cluster->cxy == BOOT_CORE_CXY) |
---|
694 | continue; |
---|
695 | |
---|
696 | // Skip clusters without core (thus without CP0). |
---|
697 | if (cluster->cores == 0) |
---|
698 | continue; |
---|
699 | |
---|
700 | // Skip clusters without device (thus without XICU). |
---|
701 | if (cluster->devices == 0) |
---|
702 | continue; |
---|
703 | |
---|
704 | // search XICU device associated to CP0, and send a WTI to activate it |
---|
705 | for (device = &device_base[cluster->device_offset]; |
---|
706 | device < &device_base[cluster->device_offset + cluster->devices]; |
---|
707 | device++) |
---|
708 | { |
---|
709 | if (device->type == DEV_TYPE_ICU_XCU) |
---|
710 | { |
---|
711 | |
---|
712 | #if DEBUG_BOOT_WAKUP |
---|
713 | boot_printf("\n[BOOT] core[%x,0] activated at cycle %d\n", |
---|
714 | cluster->cxy , boot_get_proctime ); |
---|
715 | #endif |
---|
716 | |
---|
717 | boot_remote_sw((xptr_t)device->base, (uint32_t)boot_entry); |
---|
718 | cp0_nb++; |
---|
719 | } |
---|
720 | } |
---|
721 | } |
---|
722 | return cp0_nb; |
---|
723 | |
---|
724 | } // boot_wake_cp0() |
---|
725 | |
---|
726 | /********************************************************************************* |
---|
727 | * This function is called by all CP0 to activate the other CPi cores. |
---|
728 | * @ boot_info : pointer to local 'boot_info_t' structure. |
---|
729 | *********************************************************************************/ |
---|
730 | static void boot_wake_local_cores(boot_info_t * boot_info) |
---|
731 | { |
---|
732 | unsigned int core_id; |
---|
733 | |
---|
734 | // get pointer on XCU device descriptor in boot_info |
---|
735 | boot_device_t * xcu = &boot_info->int_dev[0]; |
---|
736 | |
---|
737 | // loop on cores |
---|
738 | for (core_id = 1; core_id < boot_info->cores_nr; core_id++) |
---|
739 | { |
---|
740 | |
---|
741 | #if DEBUG_BOOT_WAKUP |
---|
742 | boot_printf("\n[BOOT] core[%x,%d] activated at cycle %d\n", |
---|
743 | boot_info->cxy , core_id , boot_get_proctime() ); |
---|
744 | #endif |
---|
745 | // send an IPI |
---|
746 | boot_remote_sw( (xptr_t)(xcu->base + (core_id << 2)) , (uint32_t)boot_entry ); |
---|
747 | } |
---|
748 | } // boot_wake_local_cores() |
---|
749 | |
---|
750 | |
---|
751 | /********************************************************************************* |
---|
752 | * This main function of the boot-loader is called by the boot_entry() |
---|
753 | * function, and executed by all cores. |
---|
754 | * The arguments values are computed by the boot_entry code. |
---|
755 | * @ lid : core local identifier, |
---|
756 | * @ cxy : cluster identifier, |
---|
757 | *********************************************************************************/ |
---|
758 | void boot_loader( lid_t lid, |
---|
759 | cxy_t cxy ) |
---|
760 | { |
---|
761 | boot_info_t * boot_info; // pointer on local boot_info_t structure |
---|
762 | |
---|
763 | if (lid == 0) |
---|
764 | { |
---|
765 | /**************************************************** |
---|
766 | * PHASE A : only CP0 in boot cluster executes it |
---|
767 | ***************************************************/ |
---|
768 | if (cxy == BOOT_CORE_CXY) |
---|
769 | { |
---|
770 | boot_printf("\n[BOOT] core[%x,%d] enters at cycle %d\n", |
---|
771 | cxy , lid , boot_get_proctime() ); |
---|
772 | |
---|
773 | // Initialize IOC driver |
---|
774 | if (USE_IOC_BDV) boot_bdv_init(); |
---|
775 | else if (USE_IOC_HBA) boot_hba_init(); |
---|
776 | // else if (USE_IOC_SDC) boot_sdc_init(); |
---|
777 | // else if (USE_IOC_SPI) boot_spi_init(); |
---|
778 | else if (!USE_IOC_RDK) |
---|
779 | { |
---|
780 | boot_printf("\n[BOOT ERROR] in %s : no IOC driver\n"); |
---|
781 | boot_exit(); |
---|
782 | } |
---|
783 | |
---|
784 | // Initialize FAT32. |
---|
785 | boot_fat32_init(); |
---|
786 | |
---|
787 | // Load the 'kernel.elf' file into memory from IOC, and set |
---|
788 | // the global variables defining the kernel layout |
---|
789 | boot_kernel_load(); |
---|
790 | |
---|
791 | boot_printf("\n[BOOT] core[%x,%d] loaded kernel at cycle %d\n", |
---|
792 | cxy , lid , boot_get_proctime() ); |
---|
793 | |
---|
794 | // Load the arch_info.bin file into memory. |
---|
795 | boot_archinfo_load(); |
---|
796 | |
---|
797 | // Get local boot_info_t structure base address. |
---|
798 | // It is the first structure in the .kdata segment. |
---|
799 | boot_info = (boot_info_t *)seg_kdata_base; |
---|
800 | |
---|
801 | // Initialize local boot_info_t structure. |
---|
802 | boot_info_init( boot_info , cxy ); |
---|
803 | |
---|
804 | // check boot_info signature |
---|
805 | if (boot_info->signature != BOOT_INFO_SIGNATURE) |
---|
806 | { |
---|
807 | boot_printf("\n[BOOT ERROR] in %s reported by core[%x,%d]\n" |
---|
808 | " illegal boot_info signature / should be %x\n", |
---|
809 | __FUNCTION__ , cxy , lid , BOOT_INFO_SIGNATURE ); |
---|
810 | boot_exit(); |
---|
811 | } |
---|
812 | |
---|
813 | boot_printf("\n[BOOT] core[%x,%d] loaded arch_info at cycle %d\n", |
---|
814 | cxy , lid , boot_get_proctime() ); |
---|
815 | |
---|
816 | // Check core information. |
---|
817 | boot_check_core(boot_info, lid); |
---|
818 | |
---|
819 | // Activate other CP0s / get number of active CP0s |
---|
820 | active_cp0s_nr = boot_wake_all_cp0s() + 1; |
---|
821 | |
---|
822 | // Wait until all clusters (i.e all CP0s) ready to enter kernel. |
---|
823 | boot_remote_barrier( XPTR( BOOT_CORE_CXY , &global_barrier ) , |
---|
824 | active_cp0s_nr ); |
---|
825 | |
---|
826 | // activate other local cores |
---|
827 | boot_wake_local_cores( boot_info ); |
---|
828 | |
---|
829 | // display address extensions |
---|
830 | // uint32_t cp2_data_ext; |
---|
831 | // uint32_t cp2_ins_ext; |
---|
832 | // asm volatile( "mfc2 %0, $24" : "=&r" (cp2_data_ext) ); |
---|
833 | // asm volatile( "mfc2 %0, $25" : "=&r" (cp2_ins_ext) ); |
---|
834 | // boot_printf("\n[BOOT] core[%x,%d] CP2_DATA_EXT = %x / CP2_INS_EXT = %x\n", |
---|
835 | // cxy , lid , cp2_data_ext , cp2_ins_ext ); |
---|
836 | |
---|
837 | // Wait until all local cores in cluster ready |
---|
838 | boot_remote_barrier( XPTR( cxy , &local_barrier ) , |
---|
839 | boot_info->cores_nr ); |
---|
840 | } |
---|
841 | /****************************************************************** |
---|
842 | * PHASE B : all CP0s other than CP0 in boot cluster execute it |
---|
843 | *****************************************************************/ |
---|
844 | else |
---|
845 | { |
---|
846 | // at this point, all INSTRUCTION address extension registers |
---|
847 | // point on cluster(0,0), but the DATA extension registers point |
---|
848 | // already on the local cluster to use the local stack. |
---|
849 | // To access the bootloader global variables we must first copy |
---|
850 | // the boot code (data and instructions) in the local cluster. |
---|
851 | boot_remote_memcpy( XPTR( cxy , BOOT_BASE ), |
---|
852 | XPTR( BOOT_CORE_CXY , BOOT_BASE ), |
---|
853 | BOOT_MAX_SIZE ); |
---|
854 | |
---|
855 | // from now, it is safe to refer to the boot code global variables |
---|
856 | boot_printf("\n[BOOT] core[%x,%d] replicated boot code at cycle %d\n", |
---|
857 | cxy , lid , boot_get_proctime() ); |
---|
858 | |
---|
859 | // switch to the INSTRUCTION local memory space, to avoid contention. |
---|
860 | asm volatile("mtc2 %0, $25" :: "r"(cxy)); |
---|
861 | |
---|
862 | // Copy the arch_info.bin file into the local memory. |
---|
863 | boot_remote_memcpy(XPTR(cxy, ARCHINFO_BASE), |
---|
864 | XPTR(BOOT_CORE_CXY, ARCHINFO_BASE), |
---|
865 | ARCHINFO_MAX_SIZE ); |
---|
866 | |
---|
867 | boot_printf("\n[BOOT] core[%x,%d] replicated arch_info at cycle %d\n", |
---|
868 | cxy , lid , boot_get_proctime() ); |
---|
869 | |
---|
870 | // Copy the kcode segment into local memory |
---|
871 | boot_remote_memcpy( XPTR( cxy , seg_kcode_base ), |
---|
872 | XPTR( BOOT_CORE_CXY , seg_kcode_base ), |
---|
873 | seg_kcode_size ); |
---|
874 | |
---|
875 | // Copy the kdata segment into local memory |
---|
876 | boot_remote_memcpy( XPTR( cxy , seg_kdata_base ), |
---|
877 | XPTR( BOOT_CORE_CXY , seg_kdata_base ), |
---|
878 | seg_kdata_size ); |
---|
879 | |
---|
880 | // Copy the kentry segment into local memory |
---|
881 | boot_remote_memcpy( XPTR( cxy , seg_kentry_base ), |
---|
882 | XPTR( BOOT_CORE_CXY , seg_kentry_base ), |
---|
883 | seg_kentry_size ); |
---|
884 | |
---|
885 | boot_printf("\n[BOOT] core[%x,%d] replicated kernel code at cycle %d\n", |
---|
886 | cxy , lid , boot_get_proctime() ); |
---|
887 | |
---|
888 | // Get local boot_info_t structure base address. |
---|
889 | boot_info = (boot_info_t*)seg_kdata_base; |
---|
890 | |
---|
891 | // Initialize local boot_info_t structure. |
---|
892 | boot_info_init( boot_info , cxy ); |
---|
893 | |
---|
894 | // Check core information. |
---|
895 | boot_check_core( boot_info , lid ); |
---|
896 | |
---|
897 | // get number of active clusters from BOOT_CORE cluster |
---|
898 | uint32_t count = boot_remote_lw( XPTR( BOOT_CORE_CXY , &active_cp0s_nr ) ); |
---|
899 | |
---|
900 | // Wait until all clusters (i.e all CP0s) ready to enter kernel |
---|
901 | boot_remote_barrier( XPTR( BOOT_CORE_CXY , &global_barrier ) , count ); |
---|
902 | |
---|
903 | // activate other local cores |
---|
904 | boot_wake_local_cores( boot_info ); |
---|
905 | |
---|
906 | // display address extensions |
---|
907 | // uint32_t cp2_data_ext; |
---|
908 | // uint32_t cp2_ins_ext; |
---|
909 | // asm volatile( "mfc2 %0, $24" : "=&r" (cp2_data_ext) ); |
---|
910 | // asm volatile( "mfc2 %0, $25" : "=&r" (cp2_ins_ext) ); |
---|
911 | // boot_printf("\n[BOOT] core[%x,%d] CP2_DATA_EXT = %x / CP2_INS_EXT = %x\n", |
---|
912 | // cxy , lid , cp2_data_ext , cp2_ins_ext ); |
---|
913 | |
---|
914 | // Wait until all local cores in cluster ready |
---|
915 | boot_remote_barrier( XPTR( cxy , &local_barrier ) , |
---|
916 | boot_info->cores_nr ); |
---|
917 | } |
---|
918 | } |
---|
919 | else |
---|
920 | { |
---|
921 | /*************************************************************** |
---|
922 | * PHASE C: all non CP0 cores in all clusters execute it |
---|
923 | **************************************************************/ |
---|
924 | |
---|
925 | // Switch to the INSTRUCTIONS local memory space |
---|
926 | // to avoid contention at the boot cluster. |
---|
927 | asm volatile("mtc2 %0, $25" :: "r"(cxy)); |
---|
928 | |
---|
929 | // Get local boot_info_t structure base address. |
---|
930 | boot_info = (boot_info_t *)seg_kdata_base; |
---|
931 | |
---|
932 | // Check core information |
---|
933 | boot_check_core(boot_info, lid); |
---|
934 | |
---|
935 | // display address extensions |
---|
936 | // uint32_t cp2_data_ext; |
---|
937 | // uint32_t cp2_ins_ext; |
---|
938 | // asm volatile( "mfc2 %0, $24" : "=&r" (cp2_data_ext) ); |
---|
939 | // asm volatile( "mfc2 %0, $25" : "=&r" (cp2_ins_ext) ); |
---|
940 | // boot_printf("\n[BOOT] core[%x,%d] CP2_DATA_EXT = %x / CP2_INS_EXT = %x\n", |
---|
941 | // cxy , lid , cp2_data_ext , cp2_ins_ext ); |
---|
942 | |
---|
943 | // Wait until all local cores in cluster ready |
---|
944 | boot_remote_barrier( XPTR( cxy , &local_barrier ) , boot_info->cores_nr ); |
---|
945 | } |
---|
946 | |
---|
947 | // Each core initialise the following registers before jumping to kernel: |
---|
948 | // - sp_29 : stack pointer on idle thread, |
---|
949 | // - c0_sr : reset BEV bit |
---|
950 | // - a0_04 : pointer on boot_info structure |
---|
951 | // - c0_ebase : kentry_base(and jump to kernel_entry. |
---|
952 | |
---|
953 | // The array of idle-thread descriptors is allocated in the kdata segment, |
---|
954 | // just after the boot_info structure |
---|
955 | uint32_t sp; |
---|
956 | uint32_t base; |
---|
957 | uint32_t offset = sizeof( boot_info_t ); |
---|
958 | uint32_t pmask = CONFIG_PPM_PAGE_MASK; |
---|
959 | uint32_t psize = CONFIG_PPM_PAGE_SIZE; |
---|
960 | |
---|
961 | // compute base address of idle thread descriptors array |
---|
962 | if( offset & pmask ) base = seg_kdata_base + (offset & ~pmask) + psize; |
---|
963 | else base = seg_kdata_base + offset; |
---|
964 | |
---|
965 | // compute stack pointer |
---|
966 | sp = base + ((lid + 1) * CONFIG_THREAD_DESC_SIZE) - 16; |
---|
967 | |
---|
968 | asm volatile( "mfc0 $27, $12 \n" |
---|
969 | "lui $26, 0xFFBF \n" |
---|
970 | "ori $26, $26, 0xFFFF \n" |
---|
971 | "and $27, $27, $26 \n" |
---|
972 | "mtc0 $27, $12 \n" |
---|
973 | "move $4, %0 \n" |
---|
974 | "move $29, %1 \n" |
---|
975 | "mtc0 %2, $15, 1 \n" |
---|
976 | "jr %3 \n" |
---|
977 | : |
---|
978 | : "r"(boot_info) , |
---|
979 | "r"(sp) , |
---|
980 | "r"(boot_info->kentry_base) , |
---|
981 | "r"(kernel_entry) |
---|
982 | : "$26" , "$27" , "$29" , "$4" ); |
---|
983 | |
---|
984 | |
---|
985 | } // boot_loader() |
---|