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