1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : boot.c |
---|
3 | // Date : 01/11/2013 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
7 | // The boot.c file contains the bootloader for the GIET-VM static OS. |
---|
8 | // |
---|
9 | // This code has been written for the MIPS32 processor. |
---|
10 | // The virtual adresses are on 32 bits and use the (unsigned int) type. The |
---|
11 | // physicals addresses can have up to 40 bits, and use the (unsigned long long) type. |
---|
12 | // It natively supports clusterised shared memory multi-processors architectures, |
---|
13 | // where each processor is identified by a composite index [x,y,p], |
---|
14 | // and where there is one physical memory bank per cluster. |
---|
15 | // |
---|
16 | // The boot.elf file is stored on disk and is loaded into memory by proc[0,0,0], |
---|
17 | // executing the generic preloader (stored in ROM). The boot-loader code itself |
---|
18 | // is executed in parallel by all proc[x,y,0], and performs the following tasks: |
---|
19 | // - load into memory various binary files, from a FAT32 file system. |
---|
20 | // - build the various page tables (one page table per vspace). |
---|
21 | // - initialize the shedulers (one scheduler per processor). |
---|
22 | // - initialize the external peripherals. |
---|
23 | // |
---|
24 | // 1) The binary files to be loaded are: |
---|
25 | // - the "map.bin" file contains the hardware architecture description and the |
---|
26 | // mapping directives. It must be stored in the the seg_boot_mapping segment |
---|
27 | // (at address SEG_BOOT_MAPPING_BASE defined in hard_config.h file). |
---|
28 | // - the "kernel.elf" file contains the kernel binary code and data. |
---|
29 | // - the various "application.elf" files. |
---|
30 | // |
---|
31 | // 2) The "map.bin" file contains the C binary structure defining: |
---|
32 | // - the hardware architecture: number of clusters, number or processors, |
---|
33 | // size of the memory segments, and peripherals in each cluster. |
---|
34 | // - The structure of the various multi-threaded software applications: |
---|
35 | // number of tasks, communication channels. |
---|
36 | // - The mapping: grouping of virtual objects (vobj) in the virtual segments (vseg), |
---|
37 | // placement of virtual segments (vseg) in the physical segments (pseg), placement |
---|
38 | // of software tasks on the processors, |
---|
39 | // |
---|
40 | // 3) The GIET-VM uses the paged virtual memory to provides two services: |
---|
41 | // - classical memory protection, when several independant applications compiled |
---|
42 | // in different virtual spaces are executing on the same hardware platform. |
---|
43 | // - data placement in NUMA architectures, to control the placement |
---|
44 | // of the software objects (vsegs) on the physical memory banks (psegs). |
---|
45 | // |
---|
46 | // The max number of vspaces (GIET_NB_VSPACE_MAX) is a configuration parameter, |
---|
47 | // and - for each application - the tasks are statically allocateded on procesors. |
---|
48 | // The page table are statically build in the boot phase, and they do not |
---|
49 | // change during execution. |
---|
50 | // The GIET_VM uses both small pages (4 Kbytes), and big pages (2 Mbytes). |
---|
51 | // |
---|
52 | // Each page table (one page table per virtual space) is monolithic, and contains |
---|
53 | // one PT1 (8 Kbytes) and a variable number of PT2s (4 Kbytes each). For each vspace, |
---|
54 | // the numberof PT2s is defined by the size of the PTAB vobj in the mapping. |
---|
55 | // The PT1 is indexed by the ix1 field (11 bits) of the VPN. Each entry is 32 bits. |
---|
56 | // A PT2 is indexed the ix2 field (9 bits) of the VPN. Each entry is a double word. |
---|
57 | // The first word contains the flags, the second word contains the PPN. |
---|
58 | // The page tables are distributed/replicated in all clusters. |
---|
59 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
60 | // Implementation Notes: |
---|
61 | // |
---|
62 | // 1) The cluster_id variable is a linear index in the mapping_info array of clusters. |
---|
63 | // The cluster_xy variable is the tological index = x << Y_WIDTH + y |
---|
64 | // |
---|
65 | // 2) We set the _tty0_boot_mode variable to force the _printf() function to use |
---|
66 | // the tty0_spin_lock for exclusive access to TTY0. |
---|
67 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
68 | |
---|
69 | #include <giet_config.h> |
---|
70 | #include <hard_config.h> |
---|
71 | #include <mapping_info.h> |
---|
72 | #include <kernel_malloc.h> |
---|
73 | #include <memspace.h> |
---|
74 | #include <tty_driver.h> |
---|
75 | #include <xcu_driver.h> |
---|
76 | #include <bdv_driver.h> |
---|
77 | #include <hba_driver.h> |
---|
78 | #include <dma_driver.h> |
---|
79 | #include <cma_driver.h> |
---|
80 | #include <nic_driver.h> |
---|
81 | #include <ioc_driver.h> |
---|
82 | #include <iob_driver.h> |
---|
83 | #include <pic_driver.h> |
---|
84 | #include <mwr_driver.h> |
---|
85 | #include <ctx_handler.h> |
---|
86 | #include <irq_handler.h> |
---|
87 | #include <vmem.h> |
---|
88 | #include <pmem.h> |
---|
89 | #include <utils.h> |
---|
90 | #include <tty0.h> |
---|
91 | #include <kernel_locks.h> |
---|
92 | #include <kernel_barriers.h> |
---|
93 | #include <elf-types.h> |
---|
94 | #include <fat32.h> |
---|
95 | #include <mips32_registers.h> |
---|
96 | #include <stdarg.h> |
---|
97 | |
---|
98 | #if !defined(X_SIZE) |
---|
99 | # error: The X_SIZE value must be defined in the 'hard_config.h' file ! |
---|
100 | #endif |
---|
101 | |
---|
102 | #if !defined(Y_SIZE) |
---|
103 | # error: The Y_SIZE value must be defined in the 'hard_config.h' file ! |
---|
104 | #endif |
---|
105 | |
---|
106 | #if !defined(X_WIDTH) |
---|
107 | # error: The X_WIDTH value must be defined in the 'hard_config.h' file ! |
---|
108 | #endif |
---|
109 | |
---|
110 | #if !defined(Y_WIDTH) |
---|
111 | # error: The Y_WIDTH value must be defined in the 'hard_config.h' file ! |
---|
112 | #endif |
---|
113 | |
---|
114 | #if !defined(SEG_BOOT_MAPPING_BASE) |
---|
115 | # error: The SEG_BOOT_MAPPING_BASE value must be defined in the hard_config.h file ! |
---|
116 | #endif |
---|
117 | |
---|
118 | #if !defined(NB_PROCS_MAX) |
---|
119 | # error: The NB_PROCS_MAX value must be defined in the 'hard_config.h' file ! |
---|
120 | #endif |
---|
121 | |
---|
122 | #if !defined(GIET_NB_VSPACE_MAX) |
---|
123 | # error: The GIET_NB_VSPACE_MAX value must be defined in the 'giet_config.h' file ! |
---|
124 | #endif |
---|
125 | |
---|
126 | #if !defined(GIET_ELF_BUFFER_SIZE) |
---|
127 | # error: The GIET_ELF_BUFFER_SIZE value must be defined in the giet_config.h file ! |
---|
128 | #endif |
---|
129 | |
---|
130 | //////////////////////////////////////////////////////////////////////////// |
---|
131 | // Global variables for boot code |
---|
132 | //////////////////////////////////////////////////////////////////////////// |
---|
133 | |
---|
134 | extern void boot_entry(); |
---|
135 | |
---|
136 | // FAT internal representation for boot code |
---|
137 | __attribute__((section(".kdata"))) |
---|
138 | fat32_fs_t fat __attribute__((aligned(512))); |
---|
139 | |
---|
140 | // Temporaty buffer used to load one complete .elf file |
---|
141 | __attribute__((section(".kdata"))) |
---|
142 | char boot_elf_buffer[GIET_ELF_BUFFER_SIZE] __attribute__((aligned(512))); |
---|
143 | |
---|
144 | // Physical memory allocators array (one per cluster) |
---|
145 | __attribute__((section(".kdata"))) |
---|
146 | pmem_alloc_t boot_pmem_alloc[X_SIZE][Y_SIZE]; |
---|
147 | |
---|
148 | // Distributed kernel heap (one per cluster) |
---|
149 | // __attribute__((section(".kdata"))) |
---|
150 | // kernel_heap_t kernel_heap[X_SIZE][Y_SIZE]; |
---|
151 | |
---|
152 | // Schedulers virtual base addresses array (one per processor) |
---|
153 | __attribute__((section(".kdata"))) |
---|
154 | static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX]; |
---|
155 | |
---|
156 | // Page tables virtual base addresses array (one per vspace) |
---|
157 | __attribute__((section(".kdata"))) |
---|
158 | unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; |
---|
159 | |
---|
160 | // Page tables physical base addresses (one per vspace and per cluster) |
---|
161 | __attribute__((section(".kdata"))) |
---|
162 | paddr_t _ptabs_paddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; |
---|
163 | |
---|
164 | // Page tables pt2 allocators (one per vspace and per cluster) |
---|
165 | __attribute__((section(".kdata"))) |
---|
166 | unsigned int _ptabs_next_pt2[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; |
---|
167 | |
---|
168 | // Page tables max_pt2 (same value for all page tables) |
---|
169 | __attribute__((section(".kdata"))) |
---|
170 | unsigned int _ptabs_max_pt2; |
---|
171 | |
---|
172 | // WTI channel allocator (one per cluster) |
---|
173 | __attribute__((section(".kdata"))) |
---|
174 | unsigned int _wti_channel_alloc[X_SIZE][Y_SIZE]; |
---|
175 | |
---|
176 | // boot code uses a spin lock to protect TTY0 |
---|
177 | __attribute__((section(".kdata"))) |
---|
178 | unsigned int _tty0_boot_mode = 1; |
---|
179 | |
---|
180 | __attribute__((section(".kdata"))) |
---|
181 | spin_lock_t _ptabs_spin_lock[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; |
---|
182 | |
---|
183 | // barrier used by boot code for parallel execution |
---|
184 | __attribute__((section(".kdata"))) |
---|
185 | simple_barrier_t _barrier_all_clusters; |
---|
186 | |
---|
187 | // this variable is defined in the tty0.c file |
---|
188 | extern spin_lock_t _tty0_spin_lock; |
---|
189 | |
---|
190 | ////////////////////////////////////////////////////////////////////////////// |
---|
191 | // This function registers a new PTE1 in the page table defined |
---|
192 | // by the vspace_id argument, and the (x,y) coordinates. |
---|
193 | // It updates only the first level PT1. |
---|
194 | // As each vseg is mapped by a different processor, the PT1 entry cannot |
---|
195 | // be concurrently accessed, and we don't need to take any lock. |
---|
196 | ////////////////////////////////////////////////////////////////////////////// |
---|
197 | void boot_add_pte1( unsigned int vspace_id, |
---|
198 | unsigned int x, |
---|
199 | unsigned int y, |
---|
200 | unsigned int vpn, // 20 bits right-justified |
---|
201 | unsigned int flags, // 10 bits left-justified |
---|
202 | unsigned int ppn ) // 28 bits right-justified |
---|
203 | { |
---|
204 | // compute index in PT1 |
---|
205 | unsigned int ix1 = vpn >> 9; // 11 bits for ix1 |
---|
206 | |
---|
207 | // get page table physical base address |
---|
208 | paddr_t pt1_pbase = _ptabs_paddr[vspace_id][x][y]; |
---|
209 | |
---|
210 | if ( pt1_pbase == 0 ) |
---|
211 | { |
---|
212 | _printf("\n[BOOT ERROR] in boot_add_pte1() : no PTAB in cluster[%d,%d]" |
---|
213 | " containing processors\n", x , y ); |
---|
214 | _exit(); |
---|
215 | } |
---|
216 | |
---|
217 | // compute pte1 : 2 bits V T / 8 bits flags / 3 bits RSVD / 19 bits bppi |
---|
218 | unsigned int pte1 = PTE_V | |
---|
219 | (flags & 0x3FC00000) | |
---|
220 | ((ppn>>9) & 0x0007FFFF); |
---|
221 | |
---|
222 | // write pte1 in PT1 |
---|
223 | _physical_write( pt1_pbase + 4*ix1, pte1 ); |
---|
224 | |
---|
225 | asm volatile ("sync"); |
---|
226 | |
---|
227 | } // end boot_add_pte1() |
---|
228 | |
---|
229 | ////////////////////////////////////////////////////////////////////////////// |
---|
230 | // This function registers a new PTE2 in the page table defined |
---|
231 | // by the vspace_id argument, and the (x,y) coordinates. |
---|
232 | // It updates both the first level PT1 and the second level PT2. |
---|
233 | // As the set of PT2s is implemented as a fixed size array (no dynamic |
---|
234 | // allocation), this function checks a possible overflow of the PT2 array. |
---|
235 | // As a given entry in PT1 can be shared by several vsegs, mapped by |
---|
236 | // different processors, we need to take the lock protecting PTAB[v][x]y]. |
---|
237 | ////////////////////////////////////////////////////////////////////////////// |
---|
238 | void boot_add_pte2( unsigned int vspace_id, |
---|
239 | unsigned int x, |
---|
240 | unsigned int y, |
---|
241 | unsigned int vpn, // 20 bits right-justified |
---|
242 | unsigned int flags, // 10 bits left-justified |
---|
243 | unsigned int ppn ) // 28 bits right-justified |
---|
244 | { |
---|
245 | unsigned int ix1; |
---|
246 | unsigned int ix2; |
---|
247 | paddr_t pt2_pbase; // PT2 physical base address |
---|
248 | paddr_t pte2_paddr; // PTE2 physical address |
---|
249 | unsigned int pt2_id; // PT2 index |
---|
250 | unsigned int ptd; // PTD : entry in PT1 |
---|
251 | |
---|
252 | ix1 = vpn >> 9; // 11 bits for ix1 |
---|
253 | ix2 = vpn & 0x1FF; // 9 bits for ix2 |
---|
254 | |
---|
255 | // get page table physical base address |
---|
256 | paddr_t pt1_pbase = _ptabs_paddr[vspace_id][x][y]; |
---|
257 | |
---|
258 | if ( pt1_pbase == 0 ) |
---|
259 | { |
---|
260 | _printf("\n[BOOT ERROR] in boot_add_pte2() : no PTAB for vspace %d " |
---|
261 | "in cluster[%d,%d]\n", vspace_id , x , y ); |
---|
262 | _exit(); |
---|
263 | } |
---|
264 | |
---|
265 | // get lock protecting PTAB[vspace_id][x][y] |
---|
266 | _spin_lock_acquire( &_ptabs_spin_lock[vspace_id][x][y] ); |
---|
267 | |
---|
268 | // get ptd in PT1 |
---|
269 | ptd = _physical_read( pt1_pbase + 4 * ix1 ); |
---|
270 | |
---|
271 | if ((ptd & PTE_V) == 0) // undefined PTD: compute PT2 base address, |
---|
272 | // and set a new PTD in PT1 |
---|
273 | { |
---|
274 | // get a new pt2_id |
---|
275 | pt2_id = _ptabs_next_pt2[vspace_id][x][y]; |
---|
276 | _ptabs_next_pt2[vspace_id][x][y] = pt2_id + 1; |
---|
277 | |
---|
278 | // check overflow |
---|
279 | if (pt2_id == _ptabs_max_pt2) |
---|
280 | { |
---|
281 | _printf("\n[BOOT ERROR] in boot_add_pte2() : PTAB[%d,%d,%d]" |
---|
282 | " contains not enough PT2s\n", vspace_id, x, y ); |
---|
283 | _exit(); |
---|
284 | } |
---|
285 | |
---|
286 | pt2_pbase = pt1_pbase + PT1_SIZE + PT2_SIZE * pt2_id; |
---|
287 | ptd = PTE_V | PTE_T | (unsigned int) (pt2_pbase >> 12); |
---|
288 | |
---|
289 | // set PTD into PT1 |
---|
290 | _physical_write( pt1_pbase + 4*ix1, ptd); |
---|
291 | } |
---|
292 | else // valid PTD: compute PT2 base address |
---|
293 | { |
---|
294 | pt2_pbase = ((paddr_t)(ptd & 0x0FFFFFFF)) << 12; |
---|
295 | } |
---|
296 | |
---|
297 | // set PTE in PT2 : flags & PPN in two 32 bits words |
---|
298 | pte2_paddr = pt2_pbase + 8 * ix2; |
---|
299 | _physical_write(pte2_paddr , (PTE_V | flags) ); |
---|
300 | _physical_write(pte2_paddr + 4 , ppn ); |
---|
301 | |
---|
302 | // release lock protecting PTAB[vspace_id][x][y] |
---|
303 | _spin_lock_release( &_ptabs_spin_lock[vspace_id][x][y] ); |
---|
304 | |
---|
305 | asm volatile ("sync"); |
---|
306 | |
---|
307 | } // end boot_add_pte2() |
---|
308 | |
---|
309 | //////////////////////////////////////////////////////////////////////////////////// |
---|
310 | // Align the value of paddr or vaddr to the required alignement, |
---|
311 | // defined by alignPow2 == L2(alignement). |
---|
312 | //////////////////////////////////////////////////////////////////////////////////// |
---|
313 | paddr_t paddr_align_to( paddr_t paddr, unsigned int alignPow2 ) |
---|
314 | { |
---|
315 | paddr_t mask = (1 << alignPow2) - 1; |
---|
316 | return ((paddr + mask) & ~mask); |
---|
317 | } |
---|
318 | |
---|
319 | unsigned int vaddr_align_to( unsigned int vaddr, unsigned int alignPow2 ) |
---|
320 | { |
---|
321 | unsigned int mask = (1 << alignPow2) - 1; |
---|
322 | return ((vaddr + mask) & ~mask); |
---|
323 | } |
---|
324 | |
---|
325 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
326 | // This function map a vseg identified by the vseg pointer. |
---|
327 | // |
---|
328 | // A given vseg can be mapped in a Big Physical Pages (BPP: 2 Mbytes) or in a |
---|
329 | // Small Physical Pages (SPP: 4 Kbytes), depending on the "big" attribute of vseg, |
---|
330 | // with the following rules: |
---|
331 | // - SPP : There is only one vseg in a small physical page, but a single vseg |
---|
332 | // can cover several contiguous small physical pages. |
---|
333 | // - BPP : It can exist several vsegs in a single big physical page, and a single |
---|
334 | // vseg can cover several contiguous big physical pages. |
---|
335 | // |
---|
336 | // 1) First step: it computes the vseg length, and register it in vseg->length field. |
---|
337 | // It computes - for each vobj - the actual vbase address, taking into |
---|
338 | // account the alignment constraints and register it in vobj->vbase field. |
---|
339 | // |
---|
340 | // 2) Second step: it allocates the required number of contiguous physical pages, |
---|
341 | // computes the physical base address (if the vseg is not identity mapping), |
---|
342 | // and register it in the vseg pbase field. |
---|
343 | // Only the vsegs used by the boot code and the peripheral vsegs |
---|
344 | // can be identity mapping. The first big physical page in cluster[0,0] |
---|
345 | // is reserved for the boot vsegs. |
---|
346 | // |
---|
347 | // 3) Third step (only for vseg that have the VOBJ_TYPE_PTAB): the M page tables |
---|
348 | // associated to the M vspaces must be packed in the same vseg. |
---|
349 | // We divide this vseg in M sub-segments, and compute the vbase and pbase |
---|
350 | // addresses for M page tables, and register these addresses in the _ptabs_paddr |
---|
351 | // and _ptabs_vaddr arrays. |
---|
352 | // |
---|
353 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
354 | void boot_vseg_map( mapping_vseg_t* vseg, |
---|
355 | unsigned int vspace_id ) |
---|
356 | { |
---|
357 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
358 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
359 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
360 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
361 | |
---|
362 | // compute destination cluster pointer & coordinates |
---|
363 | pseg = pseg + vseg->psegid; |
---|
364 | cluster = cluster + pseg->clusterid; |
---|
365 | unsigned int x_dest = cluster->x; |
---|
366 | unsigned int y_dest = cluster->y; |
---|
367 | |
---|
368 | // compute the first vobj global index |
---|
369 | unsigned int vobj_id = vseg->vobj_offset; |
---|
370 | |
---|
371 | // compute the "big" vseg attribute |
---|
372 | unsigned int big = vseg->big; |
---|
373 | |
---|
374 | // compute the "is_ram" vseg attribute |
---|
375 | unsigned int is_ram; |
---|
376 | if ( pseg->type == PSEG_TYPE_RAM ) is_ram = 1; |
---|
377 | else is_ram = 0; |
---|
378 | |
---|
379 | // compute the "is_ptab" attribute |
---|
380 | unsigned int is_ptab; |
---|
381 | if ( vobj[vobj_id].type == VOBJ_TYPE_PTAB ) is_ptab = 1; |
---|
382 | else is_ptab = 0; |
---|
383 | |
---|
384 | // compute actual vspace index |
---|
385 | unsigned int vsid; |
---|
386 | if ( vspace_id == 0xFFFFFFFF ) vsid = 0; |
---|
387 | else vsid = vspace_id; |
---|
388 | |
---|
389 | //////////// First step : compute vseg length and vobj(s) vbase |
---|
390 | |
---|
391 | unsigned int vobj_vbase = vseg->vbase; // min vbase for first vobj |
---|
392 | |
---|
393 | for ( vobj_id = vseg->vobj_offset ; |
---|
394 | vobj_id < (vseg->vobj_offset + vseg->vobjs) ; |
---|
395 | vobj_id++ ) |
---|
396 | { |
---|
397 | // compute and register vobj vbase |
---|
398 | vobj[vobj_id].vbase = vaddr_align_to( vobj_vbase, vobj[vobj_id].align ); |
---|
399 | |
---|
400 | // compute min vbase for next vobj |
---|
401 | vobj_vbase = vobj[vobj_id].vbase + vobj[vobj_id].length; |
---|
402 | } |
---|
403 | |
---|
404 | // compute and register vseg length (multiple of 4 Kbytes) |
---|
405 | vseg->length = vaddr_align_to( vobj_vbase - vseg->vbase, 12 ); |
---|
406 | |
---|
407 | //////////// Second step : compute ppn and npages |
---|
408 | //////////// - if identity mapping : ppn <= vpn |
---|
409 | //////////// - if vseg is periph : ppn <= pseg.base >> 12 |
---|
410 | //////////// - if vseg is ram : ppn <= physical memory allocator |
---|
411 | |
---|
412 | unsigned int ppn; // first physical page index (28 bits = |x|y|bppi|sppi|) |
---|
413 | unsigned int vpn; // first virtual page index (20 bits = |ix1|ix2|) |
---|
414 | unsigned int vpn_max; // last virtual page index (20 bits = |ix1|ix2|) |
---|
415 | |
---|
416 | vpn = vseg->vbase >> 12; |
---|
417 | vpn_max = (vseg->vbase + vseg->length - 1) >> 12; |
---|
418 | |
---|
419 | // compute npages |
---|
420 | unsigned int npages; // number of required (big or small) pages |
---|
421 | if ( big == 0 ) npages = vpn_max - vpn + 1; // number of small pages |
---|
422 | else npages = (vpn_max>>9) - (vpn>>9) + 1; // number of big pages |
---|
423 | |
---|
424 | // compute ppn |
---|
425 | if ( vseg->ident ) // identity mapping |
---|
426 | { |
---|
427 | ppn = vpn; |
---|
428 | } |
---|
429 | else // not identity mapping |
---|
430 | { |
---|
431 | if ( is_ram ) // RAM : physical memory allocation required |
---|
432 | { |
---|
433 | // compute pointer on physical memory allocator in dest cluster |
---|
434 | pmem_alloc_t* palloc = &boot_pmem_alloc[x_dest][y_dest]; |
---|
435 | |
---|
436 | if ( big == 0 ) // SPP : small physical pages |
---|
437 | { |
---|
438 | // allocate contiguous small physical pages |
---|
439 | ppn = _get_small_ppn( palloc, npages ); |
---|
440 | } |
---|
441 | else // BPP : big physical pages |
---|
442 | { |
---|
443 | |
---|
444 | // one big page can be shared by several vsegs |
---|
445 | // we must chek if BPP already allocated |
---|
446 | if ( is_ptab ) // It cannot be mapped |
---|
447 | { |
---|
448 | ppn = _get_big_ppn( palloc, npages ); |
---|
449 | } |
---|
450 | else // It can be mapped |
---|
451 | { |
---|
452 | unsigned int ix1 = vpn >> 9; // 11 bits |
---|
453 | paddr_t paddr = _ptabs_paddr[vsid][x_dest][y_dest] + (ix1<<2); |
---|
454 | unsigned int pte1 = _physical_read( paddr ); |
---|
455 | |
---|
456 | if ( (pte1 & PTE_V) == 0 ) // BPP not allocated yet |
---|
457 | { |
---|
458 | // allocate contiguous big physical pages |
---|
459 | ppn = _get_big_ppn( palloc, npages ); |
---|
460 | } |
---|
461 | else // BPP already allocated |
---|
462 | { |
---|
463 | // test if new vseg has the same mode bits than |
---|
464 | // the other vsegs in the same big page |
---|
465 | unsigned int pte1_mode = 0; |
---|
466 | if (pte1 & PTE_C) pte1_mode |= C_MODE_MASK; |
---|
467 | if (pte1 & PTE_X) pte1_mode |= X_MODE_MASK; |
---|
468 | if (pte1 & PTE_W) pte1_mode |= W_MODE_MASK; |
---|
469 | if (pte1 & PTE_U) pte1_mode |= U_MODE_MASK; |
---|
470 | if (vseg->mode != pte1_mode) |
---|
471 | { |
---|
472 | _printf("\n[BOOT ERROR] in boot_vseg_map() : " |
---|
473 | "vseg %s has different flags than another vseg " |
---|
474 | "in the same BPP\n", vseg->name ); |
---|
475 | _exit(); |
---|
476 | } |
---|
477 | ppn = ((pte1 << 9) & 0x0FFFFE00); |
---|
478 | } |
---|
479 | } |
---|
480 | ppn = ppn | (vpn & 0x1FF); |
---|
481 | } |
---|
482 | } |
---|
483 | else // PERI : no memory allocation required |
---|
484 | { |
---|
485 | ppn = pseg->base >> 12; |
---|
486 | } |
---|
487 | } |
---|
488 | |
---|
489 | // update vseg.pbase field and update vsegs chaining |
---|
490 | vseg->pbase = ((paddr_t)ppn) << 12; |
---|
491 | vseg->mapped = 1; |
---|
492 | vseg->next_vseg = pseg->next_vseg; |
---|
493 | pseg->next_vseg = (unsigned int)vseg; |
---|
494 | |
---|
495 | |
---|
496 | //////////// Third step : (only if the vseg is a page table) |
---|
497 | //////////// - compute the physical & virtual base address for each vspace |
---|
498 | //////////// by dividing the vseg in several sub-segments. |
---|
499 | //////////// - register it in _ptabs_vaddr & _ptabs_paddr arrays, |
---|
500 | //////////// and initialize next_pt2 allocators. |
---|
501 | //////////// - reset all entries in first level page tables |
---|
502 | |
---|
503 | if ( is_ptab ) |
---|
504 | { |
---|
505 | unsigned int vs; // vspace index |
---|
506 | unsigned int nspaces; // number of vspaces |
---|
507 | unsigned int nsp; // number of small pages for one PTAB |
---|
508 | unsigned int offset; // address offset for current PTAB |
---|
509 | |
---|
510 | nspaces = header->vspaces; |
---|
511 | offset = 0; |
---|
512 | |
---|
513 | // each PTAB must be aligned on a 8 Kbytes boundary |
---|
514 | nsp = ( vseg->length >> 12 ) / nspaces; |
---|
515 | if ( (nsp & 0x1) == 0x1 ) nsp = nsp - 1; |
---|
516 | |
---|
517 | // compute max_pt2 |
---|
518 | _ptabs_max_pt2 = ((nsp<<12) - PT1_SIZE) / PT2_SIZE; |
---|
519 | |
---|
520 | for ( vs = 0 ; vs < nspaces ; vs++ ) |
---|
521 | { |
---|
522 | _ptabs_vaddr [vs][x_dest][y_dest] = (vpn + offset) << 12; |
---|
523 | _ptabs_paddr [vs][x_dest][y_dest] = ((paddr_t)(ppn + offset)) << 12; |
---|
524 | _ptabs_next_pt2[vs][x_dest][y_dest] = 0; |
---|
525 | offset += nsp; |
---|
526 | |
---|
527 | // reset all entries in PT1 (8 Kbytes) |
---|
528 | _physical_memset( _ptabs_paddr[vs][x_dest][y_dest], PT1_SIZE, 0 ); |
---|
529 | } |
---|
530 | } |
---|
531 | |
---|
532 | asm volatile ("sync"); |
---|
533 | |
---|
534 | #if BOOT_DEBUG_PT |
---|
535 | if ( big ) |
---|
536 | _printf("\n[BOOT] vseg %s : cluster[%d,%d] / " |
---|
537 | "vbase = %x / length = %x / BIG / npages = %d / pbase = %l\n", |
---|
538 | vseg->name, x_dest, y_dest, vseg->vbase, vseg->length, npages, vseg-> pbase ); |
---|
539 | else |
---|
540 | _printf("\n[BOOT] vseg %s : cluster[%d,%d] / " |
---|
541 | "vbase = %x / length = %x / SMALL / npages = %d / pbase = %l\n", |
---|
542 | vseg->name, x_dest, y_dest, vseg->vbase, vseg->length, npages, vseg-> pbase ); |
---|
543 | #endif |
---|
544 | |
---|
545 | } // end boot_vseg_map() |
---|
546 | |
---|
547 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
548 | // For the vseg defined by the vseg pointer, this function register PTEs |
---|
549 | // in one or several page tables. |
---|
550 | // It is a global vseg (kernel vseg) if (vspace_id == 0xFFFFFFFF). |
---|
551 | // The number of involved PTABs depends on the "local" and "global" attributes: |
---|
552 | // - PTEs are replicated in all vspaces for a global vseg. |
---|
553 | // - PTEs are replicated in all clusters containing procs for a non local vseg. |
---|
554 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
555 | void boot_vseg_pte( mapping_vseg_t* vseg, |
---|
556 | unsigned int vspace_id ) |
---|
557 | { |
---|
558 | // compute the "global" vseg attribute and actual vspace index |
---|
559 | unsigned int global; |
---|
560 | unsigned int vsid; |
---|
561 | if ( vspace_id == 0xFFFFFFFF ) |
---|
562 | { |
---|
563 | global = 1; |
---|
564 | vsid = 0; |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | global = 0; |
---|
569 | vsid = vspace_id; |
---|
570 | } |
---|
571 | |
---|
572 | // compute the "local" and "big" attributes |
---|
573 | unsigned int local = vseg->local; |
---|
574 | unsigned int big = vseg->big; |
---|
575 | |
---|
576 | // compute vseg flags |
---|
577 | // The three flags (Local, Remote and Dirty) are set to 1 |
---|
578 | // to avoid hardware update for these flags, because GIET_VM |
---|
579 | // does use these flags. |
---|
580 | unsigned int flags = 0; |
---|
581 | if (vseg->mode & C_MODE_MASK) flags |= PTE_C; |
---|
582 | if (vseg->mode & X_MODE_MASK) flags |= PTE_X; |
---|
583 | if (vseg->mode & W_MODE_MASK) flags |= PTE_W; |
---|
584 | if (vseg->mode & U_MODE_MASK) flags |= PTE_U; |
---|
585 | if ( global ) flags |= PTE_G; |
---|
586 | flags |= PTE_L; |
---|
587 | flags |= PTE_R; |
---|
588 | flags |= PTE_D; |
---|
589 | |
---|
590 | // compute VPN, PPN and number of pages (big or small) |
---|
591 | unsigned int vpn = vseg->vbase >> 12; |
---|
592 | unsigned int vpn_max = (vseg->vbase + vseg->length - 1) >> 12; |
---|
593 | unsigned int ppn = (unsigned int)(vseg->pbase >> 12); |
---|
594 | unsigned int npages; |
---|
595 | if ( big == 0 ) npages = vpn_max - vpn + 1; |
---|
596 | else npages = (vpn_max>>9) - (vpn>>9) + 1; |
---|
597 | |
---|
598 | // compute destination cluster coordinates, for local vsegs |
---|
599 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
600 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
601 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
602 | mapping_pseg_t* pseg_dest = &pseg[vseg->psegid]; |
---|
603 | mapping_cluster_t* cluster_dest = &cluster[pseg_dest->clusterid]; |
---|
604 | unsigned int x_dest = cluster_dest->x; |
---|
605 | unsigned int y_dest = cluster_dest->y; |
---|
606 | |
---|
607 | unsigned int p; // iterator for physical page index |
---|
608 | unsigned int x; // iterator for cluster x coordinate |
---|
609 | unsigned int y; // iterator for cluster y coordinate |
---|
610 | unsigned int v; // iterator for vspace index |
---|
611 | |
---|
612 | // loop on PTEs |
---|
613 | for ( p = 0 ; p < npages ; p++ ) |
---|
614 | { |
---|
615 | if ( (local != 0) && (global == 0) ) // one cluster / one vspace |
---|
616 | { |
---|
617 | if ( big ) // big pages => PTE1s |
---|
618 | { |
---|
619 | boot_add_pte1( vsid, |
---|
620 | x_dest, |
---|
621 | y_dest, |
---|
622 | vpn + (p<<9), |
---|
623 | flags, |
---|
624 | ppn + (p<<9) ); |
---|
625 | } |
---|
626 | else // small pages => PTE2s |
---|
627 | { |
---|
628 | boot_add_pte2( vsid, |
---|
629 | x_dest, |
---|
630 | y_dest, |
---|
631 | vpn + p, |
---|
632 | flags, |
---|
633 | ppn + p ); |
---|
634 | } |
---|
635 | } |
---|
636 | else if ( (local == 0) && (global == 0) ) // all clusters / one vspace |
---|
637 | { |
---|
638 | for ( x = 0 ; x < X_SIZE ; x++ ) |
---|
639 | { |
---|
640 | for ( y = 0 ; y < Y_SIZE ; y++ ) |
---|
641 | { |
---|
642 | if ( cluster[(x * Y_SIZE) + y].procs ) |
---|
643 | { |
---|
644 | if ( big ) // big pages => PTE1s |
---|
645 | { |
---|
646 | boot_add_pte1( vsid, |
---|
647 | x, |
---|
648 | y, |
---|
649 | vpn + (p<<9), |
---|
650 | flags, |
---|
651 | ppn + (p<<9) ); |
---|
652 | } |
---|
653 | else // small pages => PTE2s |
---|
654 | { |
---|
655 | boot_add_pte2( vsid, |
---|
656 | x, |
---|
657 | y, |
---|
658 | vpn + p, |
---|
659 | flags, |
---|
660 | ppn + p ); |
---|
661 | } |
---|
662 | } |
---|
663 | } |
---|
664 | } |
---|
665 | } |
---|
666 | else if ( (local != 0) && (global != 0) ) // one cluster / all vspaces |
---|
667 | { |
---|
668 | for ( v = 0 ; v < header->vspaces ; v++ ) |
---|
669 | { |
---|
670 | if ( big ) // big pages => PTE1s |
---|
671 | { |
---|
672 | boot_add_pte1( v, |
---|
673 | x_dest, |
---|
674 | y_dest, |
---|
675 | vpn + (p<<9), |
---|
676 | flags, |
---|
677 | ppn + (p<<9) ); |
---|
678 | } |
---|
679 | else // small pages = PTE2s |
---|
680 | { |
---|
681 | boot_add_pte2( v, |
---|
682 | x_dest, |
---|
683 | y_dest, |
---|
684 | vpn + p, |
---|
685 | flags, |
---|
686 | ppn + p ); |
---|
687 | } |
---|
688 | } |
---|
689 | } |
---|
690 | else if ( (local == 0) && (global != 0) ) // all clusters / all vspaces |
---|
691 | { |
---|
692 | for ( x = 0 ; x < X_SIZE ; x++ ) |
---|
693 | { |
---|
694 | for ( y = 0 ; y < Y_SIZE ; y++ ) |
---|
695 | { |
---|
696 | if ( cluster[(x * Y_SIZE) + y].procs ) |
---|
697 | { |
---|
698 | for ( v = 0 ; v < header->vspaces ; v++ ) |
---|
699 | { |
---|
700 | if ( big ) // big pages => PTE1s |
---|
701 | { |
---|
702 | boot_add_pte1( v, |
---|
703 | x, |
---|
704 | y, |
---|
705 | vpn + (p<<9), |
---|
706 | flags, |
---|
707 | ppn + (p<<9) ); |
---|
708 | } |
---|
709 | else // small pages -> PTE2s |
---|
710 | { |
---|
711 | boot_add_pte2( v, |
---|
712 | x, |
---|
713 | y, |
---|
714 | vpn + p, |
---|
715 | flags, |
---|
716 | ppn + p ); |
---|
717 | } |
---|
718 | } |
---|
719 | } |
---|
720 | } |
---|
721 | } |
---|
722 | } |
---|
723 | } // end for pages |
---|
724 | |
---|
725 | asm volatile ("sync"); |
---|
726 | |
---|
727 | } // end boot_vseg_pte() |
---|
728 | |
---|
729 | |
---|
730 | /////////////////////////////////////////////////////////////////////////////// |
---|
731 | // Processor P[x][y][0] computes physical base address for all globals vsegs, |
---|
732 | // using the local Page Table, to check page tables initialisation. |
---|
733 | /////////////////////////////////////////////////////////////////////////////// |
---|
734 | void boot_ptab_check( unsigned int x, |
---|
735 | unsigned int y ) |
---|
736 | { |
---|
737 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
738 | mapping_vseg_t* vseg = _get_vseg_base(header); |
---|
739 | page_table_t* ptab = (page_table_t*)_ptabs_vaddr[0][x][y]; |
---|
740 | |
---|
741 | unsigned int vseg_id; |
---|
742 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
743 | { |
---|
744 | unsigned int vpn = vseg[vseg_id].vbase >> 12; |
---|
745 | unsigned int ppn = 0; |
---|
746 | unsigned int flags = 0; |
---|
747 | _v2p_translate( ptab , vpn , &ppn , &flags ); |
---|
748 | _printf("@@@ P[%d,%d,0] access vseg %s : vpn = %x / ppn = %x\n", |
---|
749 | x , y , vseg[vseg_id].name , vpn , ppn ); |
---|
750 | } |
---|
751 | } |
---|
752 | |
---|
753 | /////////////////////////////////////////////////////////////////////////////// |
---|
754 | // This function is executed by processor[x][y][0] in each cluster |
---|
755 | // containing at least one processor. |
---|
756 | // It initialises all page table for all global or private vsegs |
---|
757 | // mapped in cluster[x][y], as specified in the mapping. |
---|
758 | // In each cluster all page tables for the different vspaces must be |
---|
759 | // packed in one vseg occupying one single BPP (Big Physical Page). |
---|
760 | // |
---|
761 | // For each vseg, the mapping is done in two steps: |
---|
762 | // 1) mapping : the boot_vseg_map() function allocates contiguous BPPs |
---|
763 | // or SPPs (if the vseg is not associated to a peripheral), and register |
---|
764 | // the physical base address in the vseg pbase field. It initialises the |
---|
765 | // _ptabs_vaddr[] and _ptabs_paddr[] arrays if the vseg is a PTAB. |
---|
766 | // |
---|
767 | // 2) page table initialisation : the boot_vseg_pte() function initialise |
---|
768 | // the PTEs (both PTE1 and PTE2) in one or several page tables: |
---|
769 | // - PTEs are replicated in all vspaces for a global vseg. |
---|
770 | // - PTEs are replicated in all clusters for a non local vseg. |
---|
771 | // |
---|
772 | // We must handle vsegs in the following order |
---|
773 | // 1) global vseg containing PTAB mapped in cluster[x][y], |
---|
774 | // 2) global vsegs occupying more than one BPP mapped in cluster[x][y], |
---|
775 | // 3) others global vsegs mapped in cluster[x][y], |
---|
776 | // 4) all private vsegs in all user spaces mapped in cluster[x][y]. |
---|
777 | /////////////////////////////////////////////////////////////////////////////// |
---|
778 | void boot_ptab_init( unsigned int cx, |
---|
779 | unsigned int cy ) |
---|
780 | { |
---|
781 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
782 | mapping_vspace_t* vspace = _get_vspace_base(header); |
---|
783 | mapping_vseg_t* vseg = _get_vseg_base(header); |
---|
784 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
785 | mapping_cluster_t* cluster ; |
---|
786 | mapping_pseg_t* pseg ; |
---|
787 | |
---|
788 | unsigned int vspace_id; |
---|
789 | unsigned int vseg_id; |
---|
790 | |
---|
791 | unsigned int procid = _get_procid(); |
---|
792 | unsigned int lpid = procid & ((1<<P_WIDTH)-1); |
---|
793 | |
---|
794 | if( lpid ) |
---|
795 | { |
---|
796 | _printf("\n[BOOT ERROR] in boot_ptab_init() : " |
---|
797 | "P[%d][%d][%d] should not execute it\n", cx, cy, lpid ); |
---|
798 | _exit(); |
---|
799 | } |
---|
800 | |
---|
801 | if ( header->vspaces == 0 ) |
---|
802 | { |
---|
803 | _printf("\n[BOOT ERROR] in boot_ptab_init() : " |
---|
804 | "mapping %s contains no vspace\n", header->name ); |
---|
805 | _exit(); |
---|
806 | } |
---|
807 | |
---|
808 | ///////// Phase 1 : global vseg containing the PTAB (two barriers required) |
---|
809 | |
---|
810 | // get local PTAB vseg |
---|
811 | unsigned int found = 0; |
---|
812 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
813 | { |
---|
814 | unsigned int vobj_id = vseg[vseg_id].vobj_offset; |
---|
815 | pseg = _get_pseg_base(header) + vseg[vseg_id].psegid; |
---|
816 | cluster = _get_cluster_base(header) + pseg->clusterid; |
---|
817 | if ( (vobj[vobj_id].type == VOBJ_TYPE_PTAB) && |
---|
818 | (cluster->x == cx) && (cluster->y == cy) ) |
---|
819 | { |
---|
820 | found = 1; |
---|
821 | break; |
---|
822 | } |
---|
823 | } |
---|
824 | if ( found == 0 ) |
---|
825 | { |
---|
826 | _printf("\n[BOOT ERROR] in boot_ptab_init() : " |
---|
827 | "cluster[%d][%d] contains no PTAB vseg\n", cx , cy ); |
---|
828 | _exit(); |
---|
829 | } |
---|
830 | |
---|
831 | boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
832 | |
---|
833 | ////////////////////////////////////////////// |
---|
834 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
835 | ////////////////////////////////////////////// |
---|
836 | |
---|
837 | boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
838 | |
---|
839 | ////////////////////////////////////////////// |
---|
840 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
841 | ////////////////////////////////////////////// |
---|
842 | |
---|
843 | ///////// Phase 2 : global vsegs occupying more than one BPP |
---|
844 | |
---|
845 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
846 | { |
---|
847 | unsigned int vobj_id = vseg[vseg_id].vobj_offset; |
---|
848 | pseg = _get_pseg_base(header) + vseg[vseg_id].psegid; |
---|
849 | cluster = _get_cluster_base(header) + pseg->clusterid; |
---|
850 | if ( (vobj[vobj_id].length > 0x200000) && |
---|
851 | (vseg[vseg_id].mapped == 0) && |
---|
852 | (cluster->x == cx) && (cluster->y == cy) ) |
---|
853 | { |
---|
854 | boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
855 | boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
856 | } |
---|
857 | } |
---|
858 | |
---|
859 | ///////// Phase 3 : all others global vsegs |
---|
860 | |
---|
861 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
862 | { |
---|
863 | pseg = _get_pseg_base(header) + vseg[vseg_id].psegid; |
---|
864 | cluster = _get_cluster_base(header) + pseg->clusterid; |
---|
865 | if ( (vseg[vseg_id].mapped == 0) && |
---|
866 | (cluster->x == cx) && (cluster->y == cy) ) |
---|
867 | { |
---|
868 | boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
869 | boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
870 | } |
---|
871 | } |
---|
872 | |
---|
873 | ///////// Phase 4 : all private vsegs |
---|
874 | |
---|
875 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
---|
876 | { |
---|
877 | for (vseg_id = vspace[vspace_id].vseg_offset; |
---|
878 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
---|
879 | vseg_id++) |
---|
880 | { |
---|
881 | pseg = _get_pseg_base(header) + vseg[vseg_id].psegid; |
---|
882 | cluster = _get_cluster_base(header) + pseg->clusterid; |
---|
883 | if ( (cluster->x == cx) && (cluster->y == cy) ) |
---|
884 | { |
---|
885 | boot_vseg_map( &vseg[vseg_id], vspace_id ); |
---|
886 | boot_vseg_pte( &vseg[vseg_id], vspace_id ); |
---|
887 | } |
---|
888 | } |
---|
889 | } |
---|
890 | |
---|
891 | ////////////////////////////////////////////// |
---|
892 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
893 | ////////////////////////////////////////////// |
---|
894 | |
---|
895 | } // end boot_ptab_init() |
---|
896 | |
---|
897 | //////////////////////////////////////////////////////////////////////////////// |
---|
898 | // This function should be executed by P[0][0][0] only. It complete the |
---|
899 | // page table initialisation, taking care of all global vsegs that are |
---|
900 | // not mapped in a cluster containing a processor, and have not been |
---|
901 | // handled by the boot_ptab_init(x,y) function. |
---|
902 | // An example of such vsegs are the external peripherals in TSAR_LETI platform. |
---|
903 | //////////////////////////////////////////////////////////////////////////////// |
---|
904 | void boot_ptab_extend() |
---|
905 | { |
---|
906 | |
---|
907 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
908 | mapping_vseg_t* vseg = _get_vseg_base(header); |
---|
909 | |
---|
910 | unsigned int vseg_id; |
---|
911 | |
---|
912 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
913 | { |
---|
914 | if ( vseg[vseg_id].mapped == 0 ) |
---|
915 | { |
---|
916 | boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
917 | boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
918 | } |
---|
919 | } |
---|
920 | } // end boot_ptab_extend() |
---|
921 | |
---|
922 | /////////////////////////////////////////////////////////////////////////////// |
---|
923 | // This function returns in the vbase and length buffers the virtual base |
---|
924 | // address and the length of the segment allocated to the schedulers array |
---|
925 | // in the cluster defined by the clusterid argument. |
---|
926 | /////////////////////////////////////////////////////////////////////////////// |
---|
927 | void boot_get_sched_vaddr( unsigned int cluster_id, |
---|
928 | unsigned int* vbase, |
---|
929 | unsigned int* length ) |
---|
930 | { |
---|
931 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
932 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
933 | mapping_vseg_t* vseg = _get_vseg_base(header); |
---|
934 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
935 | |
---|
936 | unsigned int vseg_id; |
---|
937 | unsigned int found = 0; |
---|
938 | |
---|
939 | for ( vseg_id = 0 ; (vseg_id < header->vsegs) && (found == 0) ; vseg_id++ ) |
---|
940 | { |
---|
941 | if ( (vobj[vseg[vseg_id].vobj_offset].type == VOBJ_TYPE_SCHED) && |
---|
942 | (pseg[vseg[vseg_id].psegid].clusterid == cluster_id ) ) |
---|
943 | { |
---|
944 | *vbase = vseg[vseg_id].vbase; |
---|
945 | *length = vobj[vseg[vseg_id].vobj_offset].length; |
---|
946 | found = 1; |
---|
947 | } |
---|
948 | } |
---|
949 | if ( found == 0 ) |
---|
950 | { |
---|
951 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
952 | _printf("\n[BOOT ERROR] No vobj of type SCHED in cluster [%d,%d]\n", |
---|
953 | cluster[cluster_id].x, cluster[cluster_id].y ); |
---|
954 | _exit(); |
---|
955 | } |
---|
956 | } // end boot_get_sched_vaddr() |
---|
957 | |
---|
958 | //////////////////////////////////////////////////////////////////////////////////// |
---|
959 | // This function is executed in parallel by all processors P[x][y][0]. |
---|
960 | // It initialises all schedulers in cluster [x][y]. The MMU must be activated. |
---|
961 | // It is split in two phases separated by a synchronisation barrier. |
---|
962 | // - In Step 1, it initialises the _schedulers[x][y][l] pointers array, |
---|
963 | // the idle_task context and the HWI / PTI vectors. |
---|
964 | // - In Step 2, it scan all tasks in all vspaces to complete the tasks contexts, |
---|
965 | // initialisation as specified in the mapping_info data structure, |
---|
966 | // and set the CP0_SCHED register. |
---|
967 | //////////////////////////////////////////////////////////////////////////////////// |
---|
968 | void boot_scheduler_init( unsigned int x, |
---|
969 | unsigned int y ) |
---|
970 | { |
---|
971 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
972 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
973 | mapping_vspace_t* vspace = _get_vspace_base(header); |
---|
974 | mapping_task_t* task = _get_task_base(header); |
---|
975 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
976 | mapping_periph_t* periph = _get_periph_base(header); |
---|
977 | mapping_irq_t* irq = _get_irq_base(header); |
---|
978 | |
---|
979 | unsigned int periph_id; |
---|
980 | unsigned int irq_id; |
---|
981 | unsigned int vspace_id; |
---|
982 | unsigned int task_id; |
---|
983 | unsigned int vobj_id; |
---|
984 | |
---|
985 | unsigned int sched_vbase; // schedulers array vbase address |
---|
986 | unsigned int sched_length; // schedulers array length |
---|
987 | static_scheduler_t* psched; // pointer on processor scheduler |
---|
988 | |
---|
989 | unsigned int cluster_id = x * Y_SIZE + y; |
---|
990 | unsigned int nprocs = cluster[cluster_id].procs; |
---|
991 | unsigned int lpid; |
---|
992 | |
---|
993 | ///////////////////////////////////////////////////////////////////////// |
---|
994 | // Step 1 : initialize the schedulers[] array of pointers, |
---|
995 | // the idle task context and the HWI and PTI interrupt vectors. |
---|
996 | // The WTI interrupt vector entries corresponding to interrupts |
---|
997 | // generated by the PIC component are handled later. |
---|
998 | |
---|
999 | // get scheduler array virtual base address in cluster[x,y] |
---|
1000 | boot_get_sched_vaddr( cluster_id, &sched_vbase, &sched_length ); |
---|
1001 | |
---|
1002 | if ( sched_length < (nprocs<<13) ) // 8 Kbytes per scheduler |
---|
1003 | { |
---|
1004 | _printf("\n[BOOT ERROR] Sched segment too small in cluster[%d,%d]\n", x, y ); |
---|
1005 | _exit(); |
---|
1006 | } |
---|
1007 | |
---|
1008 | // loop on local processors |
---|
1009 | for ( lpid = 0 ; lpid < nprocs ; lpid++ ) |
---|
1010 | { |
---|
1011 | // get scheduler pointer and initialise the schedulers pointers array |
---|
1012 | psched = (static_scheduler_t*)(sched_vbase + (lpid<<13)); |
---|
1013 | _schedulers[x][y][lpid] = psched; |
---|
1014 | |
---|
1015 | // initialise the "tasks" and "current" variables default values |
---|
1016 | psched->tasks = 0; |
---|
1017 | psched->current = IDLE_TASK_INDEX; |
---|
1018 | |
---|
1019 | // default values for HWI / PTI / SWI vectors (valid bit = 0) |
---|
1020 | unsigned int slot; |
---|
1021 | for (slot = 0; slot < 32; slot++) |
---|
1022 | { |
---|
1023 | psched->hwi_vector[slot] = 0; |
---|
1024 | psched->pti_vector[slot] = 0; |
---|
1025 | psched->wti_vector[slot] = 0; |
---|
1026 | } |
---|
1027 | |
---|
1028 | // WTI[lpid] <= ISR_WAKUP / PTI[lpid] <= ISR_TICK |
---|
1029 | psched->wti_vector[lpid] = ISR_WAKUP | 0x80000000; |
---|
1030 | psched->pti_vector[lpid] = ISR_TICK | 0x80000000; |
---|
1031 | |
---|
1032 | // initializes the idle_task context: |
---|
1033 | // - the SR slot is 0xFF03 because this task run in kernel mode. |
---|
1034 | // - it uses the page table of vspace[0] |
---|
1035 | // - it uses the kernel TTY terminal |
---|
1036 | // - slots containing addresses (SP,RA,EPC) are initialised by kernel_init() |
---|
1037 | |
---|
1038 | psched->context[IDLE_TASK_INDEX][CTX_CR_ID] = 0; |
---|
1039 | psched->context[IDLE_TASK_INDEX][CTX_SR_ID] = 0xFF03; |
---|
1040 | psched->context[IDLE_TASK_INDEX][CTX_PTPR_ID] = _ptabs_paddr[0][x][y]>>13; |
---|
1041 | psched->context[IDLE_TASK_INDEX][CTX_PTAB_ID] = _ptabs_vaddr[0][x][y]; |
---|
1042 | psched->context[IDLE_TASK_INDEX][CTX_TTY_ID] = 0; |
---|
1043 | psched->context[IDLE_TASK_INDEX][CTX_LTID_ID] = IDLE_TASK_INDEX; |
---|
1044 | psched->context[IDLE_TASK_INDEX][CTX_VSID_ID] = 0; |
---|
1045 | psched->context[IDLE_TASK_INDEX][CTX_RUN_ID] = 1; |
---|
1046 | } |
---|
1047 | |
---|
1048 | // scan local peripherals to get local XCU |
---|
1049 | mapping_periph_t* xcu = NULL; |
---|
1050 | |
---|
1051 | for ( periph_id = cluster[cluster_id].periph_offset ; |
---|
1052 | periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs; |
---|
1053 | periph_id++ ) |
---|
1054 | { |
---|
1055 | if( periph[periph_id].type == PERIPH_TYPE_XCU ) |
---|
1056 | { |
---|
1057 | xcu = &periph[periph_id]; |
---|
1058 | |
---|
1059 | if ( xcu->arg < (nprocs * header->irq_per_proc) ) |
---|
1060 | { |
---|
1061 | _printf("\n[BOOT ERROR] Not enough inputs for XCU[%d,%d]\n", x, y ); |
---|
1062 | _exit(); |
---|
1063 | } |
---|
1064 | } |
---|
1065 | } |
---|
1066 | |
---|
1067 | if ( xcu == NULL ) |
---|
1068 | { |
---|
1069 | _printf("\n[BOOT ERROR] missing XCU in cluster[%d,%d]\n", x , y ); |
---|
1070 | _exit(); |
---|
1071 | } |
---|
1072 | |
---|
1073 | // scan HWIs connected to local XCU |
---|
1074 | // for round-robin allocation to local processors |
---|
1075 | lpid = 0; |
---|
1076 | for ( irq_id = xcu->irq_offset ; |
---|
1077 | irq_id < xcu->irq_offset + xcu->irqs ; |
---|
1078 | irq_id++ ) |
---|
1079 | { |
---|
1080 | unsigned int type = irq[irq_id].srctype; |
---|
1081 | unsigned int srcid = irq[irq_id].srcid; |
---|
1082 | unsigned int isr = irq[irq_id].isr & 0xFFFF; |
---|
1083 | unsigned int channel = irq[irq_id].channel << 16; |
---|
1084 | |
---|
1085 | if ( (type != IRQ_TYPE_HWI) || (srcid > 31) ) |
---|
1086 | { |
---|
1087 | _printf("\n[BOOT ERROR] Bad IRQ in cluster[%d,%d]\n", x, y ); |
---|
1088 | _exit(); |
---|
1089 | } |
---|
1090 | |
---|
1091 | _schedulers[x][y][lpid]->hwi_vector[srcid] = isr | channel | 0x80000000; |
---|
1092 | |
---|
1093 | lpid = (lpid + 1) % nprocs; |
---|
1094 | } // end for irqs |
---|
1095 | |
---|
1096 | ////////////////////////////////////////////// |
---|
1097 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
1098 | ////////////////////////////////////////////// |
---|
1099 | |
---|
1100 | //////////////////////////////////////////////////////////////////////// |
---|
1101 | // Step 2 : Initialise the tasks context. The context of task placed |
---|
1102 | // on processor P must be stored in the scheduler of P. |
---|
1103 | // This require two nested loops: loop on the tasks, and loop |
---|
1104 | // on the local processors. We complete the scheduler when the |
---|
1105 | // required placement fit one local processor. |
---|
1106 | |
---|
1107 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
---|
1108 | { |
---|
1109 | // We must set the PTPR depending on the vspace, because the start_vector |
---|
1110 | // and the stack address are defined in virtual space. |
---|
1111 | _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[vspace_id][x][y] >> 13) ); |
---|
1112 | |
---|
1113 | // loop on the tasks in vspace (task_id is the global index in mapping) |
---|
1114 | for (task_id = vspace[vspace_id].task_offset; |
---|
1115 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); |
---|
1116 | task_id++) |
---|
1117 | { |
---|
1118 | // get the required task placement coordinates [x,y,p] |
---|
1119 | unsigned int req_x = cluster[task[task_id].clusterid].x; |
---|
1120 | unsigned int req_y = cluster[task[task_id].clusterid].y; |
---|
1121 | unsigned int req_p = task[task_id].proclocid; |
---|
1122 | |
---|
1123 | // ctx_sr : value required before an eret instruction |
---|
1124 | unsigned int ctx_sr = 0x2000FF13; |
---|
1125 | |
---|
1126 | // ctx_ptpr : page table physical base address (shifted by 13 bit) |
---|
1127 | unsigned int ctx_ptpr = (_ptabs_paddr[vspace_id][req_x][req_y] >> 13); |
---|
1128 | |
---|
1129 | // ctx_ptab : page_table virtual base address |
---|
1130 | unsigned int ctx_ptab = _ptabs_vaddr[vspace_id][req_x][req_y]; |
---|
1131 | |
---|
1132 | // ctx_epc : Get the virtual address of the memory location containing |
---|
1133 | // the task entry point : the start_vector is stored by GCC in the seg_data |
---|
1134 | // segment and we must wait the .elf loading to get the entry point value... |
---|
1135 | vobj_id = vspace[vspace_id].start_vobj_id; |
---|
1136 | unsigned int ctx_epc = vobj[vobj_id].vbase + (task[task_id].startid)*4; |
---|
1137 | |
---|
1138 | // ctx_sp : Get the vobj containing the stack |
---|
1139 | vobj_id = task[task_id].stack_vobj_id; |
---|
1140 | unsigned int ctx_sp = vobj[vobj_id].vbase + vobj[vobj_id].length; |
---|
1141 | |
---|
1142 | // get vspace thread index |
---|
1143 | unsigned int thread_id = task[task_id].trdid; |
---|
1144 | |
---|
1145 | // loop on the local processors |
---|
1146 | for ( lpid = 0 ; lpid < nprocs ; lpid++ ) |
---|
1147 | { |
---|
1148 | if ( (x == req_x) && (y == req_y) && (req_p == lpid) ) // fit |
---|
1149 | { |
---|
1150 | // pointer on selected scheduler |
---|
1151 | psched = _schedulers[x][y][lpid]; |
---|
1152 | |
---|
1153 | // get local task index in scheduler |
---|
1154 | unsigned int ltid = psched->tasks; |
---|
1155 | |
---|
1156 | // update the "tasks" and "current" fields in scheduler: |
---|
1157 | psched->tasks = ltid + 1; |
---|
1158 | psched->current = 0; |
---|
1159 | |
---|
1160 | // initializes the task context |
---|
1161 | psched->context[ltid][CTX_CR_ID] = 0; |
---|
1162 | psched->context[ltid][CTX_SR_ID] = ctx_sr; |
---|
1163 | psched->context[ltid][CTX_SP_ID] = ctx_sp; |
---|
1164 | psched->context[ltid][CTX_EPC_ID] = ctx_epc; |
---|
1165 | psched->context[ltid][CTX_PTPR_ID] = ctx_ptpr; |
---|
1166 | psched->context[ltid][CTX_PTAB_ID] = ctx_ptab; |
---|
1167 | psched->context[ltid][CTX_LTID_ID] = ltid; |
---|
1168 | psched->context[ltid][CTX_GTID_ID] = task_id; |
---|
1169 | psched->context[ltid][CTX_TRDID_ID] = thread_id; |
---|
1170 | psched->context[ltid][CTX_VSID_ID] = vspace_id; |
---|
1171 | psched->context[ltid][CTX_RUN_ID] = 1; |
---|
1172 | |
---|
1173 | psched->context[ltid][CTX_TTY_ID] = 0xFFFFFFFF; |
---|
1174 | psched->context[ltid][CTX_CMA_FB_ID] = 0xFFFFFFFF; |
---|
1175 | psched->context[ltid][CTX_CMA_RX_ID] = 0xFFFFFFFF; |
---|
1176 | psched->context[ltid][CTX_CMA_TX_ID] = 0xFFFFFFFF; |
---|
1177 | psched->context[ltid][CTX_NIC_RX_ID] = 0xFFFFFFFF; |
---|
1178 | psched->context[ltid][CTX_NIC_TX_ID] = 0xFFFFFFFF; |
---|
1179 | psched->context[ltid][CTX_TIM_ID] = 0xFFFFFFFF; |
---|
1180 | psched->context[ltid][CTX_HBA_ID] = 0xFFFFFFFF; |
---|
1181 | |
---|
1182 | #if BOOT_DEBUG_SCHED |
---|
1183 | _printf("\nTask %s in vspace %s allocated to P[%d,%d,%d]\n" |
---|
1184 | " - ctx[LTID] = %d\n" |
---|
1185 | " - ctx[SR] = %x\n" |
---|
1186 | " - ctx[SP] = %x\n" |
---|
1187 | " - ctx[EPC] = %x\n" |
---|
1188 | " - ctx[PTPR] = %x\n" |
---|
1189 | " - ctx[PTAB] = %x\n" |
---|
1190 | " - ctx[VSID] = %d\n" |
---|
1191 | " - ctx[TRDID] = %d\n", |
---|
1192 | task[task_id].name, |
---|
1193 | vspace[vspace_id].name, |
---|
1194 | x, y, lpid, |
---|
1195 | psched->context[ltid][CTX_LTID_ID], |
---|
1196 | psched->context[ltid][CTX_SR_ID], |
---|
1197 | psched->context[ltid][CTX_SP_ID], |
---|
1198 | psched->context[ltid][CTX_EPC_ID], |
---|
1199 | psched->context[ltid][CTX_PTPR_ID], |
---|
1200 | psched->context[ltid][CTX_PTAB_ID], |
---|
1201 | psched->context[ltid][CTX_VSID_ID], |
---|
1202 | psched->context[ltid][CTX_TRDID_ID] ); |
---|
1203 | #endif |
---|
1204 | } // end if FIT |
---|
1205 | } // end for loop on local procs |
---|
1206 | } // end loop on tasks |
---|
1207 | } // end loop on vspaces |
---|
1208 | } // end boot_scheduler_init() |
---|
1209 | |
---|
1210 | |
---|
1211 | ///////////////////////////////////////////////////////////////////////////// |
---|
1212 | // This function loops on all processors in all clusters to display |
---|
1213 | // the interrupt vectors for each processor. |
---|
1214 | ///////////////////////////////////////////////////////////////////////////// |
---|
1215 | void boot_sched_irq_display() |
---|
1216 | { |
---|
1217 | unsigned int cx; |
---|
1218 | unsigned int cy; |
---|
1219 | unsigned int lpid; |
---|
1220 | unsigned int slot; |
---|
1221 | unsigned int entry; |
---|
1222 | |
---|
1223 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1224 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
1225 | |
---|
1226 | static_scheduler_t* psched; |
---|
1227 | |
---|
1228 | for ( cx = 0 ; cx < X_SIZE ; cx++ ) |
---|
1229 | { |
---|
1230 | for ( cy = 0 ; cy < Y_SIZE ; cy++ ) |
---|
1231 | { |
---|
1232 | unsigned int cluster_id = (cx * Y_SIZE) + cy; |
---|
1233 | unsigned int nprocs = cluster[cluster_id].procs; |
---|
1234 | |
---|
1235 | for ( lpid = 0 ; lpid < nprocs ; lpid++ ) |
---|
1236 | { |
---|
1237 | psched = _schedulers[cx][cy][lpid]; |
---|
1238 | |
---|
1239 | _printf("\n[BOOT] scheduler for proc[%d,%d,%d] : ntasks = %d\n", |
---|
1240 | cx , cy , lpid , psched->tasks ); |
---|
1241 | |
---|
1242 | for ( slot = 0 ; slot < 32 ; slot++ ) |
---|
1243 | { |
---|
1244 | entry = psched->hwi_vector[slot]; |
---|
1245 | if ( entry & 0x80000000 ) |
---|
1246 | _printf(" - HWI %d / isrtype = %d / channel = %d\n", |
---|
1247 | slot , (entry & 0xFFFF) , ((entry >> 16) & 0x7FFF) ); |
---|
1248 | } |
---|
1249 | for ( slot = 0 ; slot < 32 ; slot++ ) |
---|
1250 | { |
---|
1251 | entry = psched->wti_vector[slot]; |
---|
1252 | if ( entry & 0x80000000 ) |
---|
1253 | _printf(" - WTI %d / isrtype = %d / channel = %d\n", |
---|
1254 | slot , (entry & 0xFFFF) , ((entry >> 16) & 0x7FFF) ); |
---|
1255 | } |
---|
1256 | for ( slot = 0 ; slot < 32 ; slot++ ) |
---|
1257 | { |
---|
1258 | entry = psched->pti_vector[slot]; |
---|
1259 | if ( entry & 0x80000000 ) |
---|
1260 | _printf(" - PTI %d / isrtype = %d / channel = %d\n", |
---|
1261 | slot , (entry & 0xFFFF) , ((entry >> 16) & 0x7FFF) ); |
---|
1262 | } |
---|
1263 | } |
---|
1264 | } |
---|
1265 | } |
---|
1266 | } // end boot_sched_display() |
---|
1267 | |
---|
1268 | |
---|
1269 | ///////////////////////////////////////////////////////////////////////////// |
---|
1270 | // This function complete the schedulers initialisation when the platform |
---|
1271 | // contains a PIC component in the IO cluster. |
---|
1272 | // It is executed by P[0][0][0] only. |
---|
1273 | // It scan HWIs connected to PIC for Round Robin allocation to processors, |
---|
1274 | // as WTI. It allocates one WTI per processor, starting from P[0,0,0], |
---|
1275 | // and increments (cluster_id, lpid) as required. |
---|
1276 | ///////////////////////////////////////////////////////////////////////////// |
---|
1277 | void boot_pic_wti_init() |
---|
1278 | { |
---|
1279 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1280 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
1281 | mapping_periph_t* periph = _get_periph_base(header); |
---|
1282 | mapping_irq_t* irq = _get_irq_base(header); |
---|
1283 | |
---|
1284 | unsigned int periph_id; // peripheral index in mapping_info |
---|
1285 | unsigned int irq_id; // irq index in mapping_info |
---|
1286 | |
---|
1287 | // get cluster_io index in mapping |
---|
1288 | unsigned int x_io = header->x_io; |
---|
1289 | unsigned int y_io = header->y_io; |
---|
1290 | unsigned int cluster_io = (x_io * Y_SIZE) + y_io; |
---|
1291 | |
---|
1292 | // scan peripherals in cluster_io to find PIC |
---|
1293 | mapping_periph_t* pic = NULL; |
---|
1294 | |
---|
1295 | for ( periph_id = cluster[cluster_io].periph_offset ; |
---|
1296 | periph_id < cluster[cluster_io].periph_offset + cluster[cluster_io].periphs; |
---|
1297 | periph_id++ ) |
---|
1298 | { |
---|
1299 | if ( periph[periph_id].type == PERIPH_TYPE_PIC ) |
---|
1300 | { |
---|
1301 | pic = &periph[periph_id]; |
---|
1302 | break; |
---|
1303 | } |
---|
1304 | } |
---|
1305 | |
---|
1306 | if ( pic == NULL ) return; |
---|
1307 | |
---|
1308 | // initialize WTI channel allocators in all clusters |
---|
1309 | unsigned int x; |
---|
1310 | unsigned int y; |
---|
1311 | for ( x = 0 ; x < X_SIZE ; x++ ) |
---|
1312 | { |
---|
1313 | for ( y = 0 ; y < Y_SIZE ; y++ ) |
---|
1314 | { |
---|
1315 | _wti_channel_alloc[x][y] = NB_PROCS_MAX; |
---|
1316 | } |
---|
1317 | } |
---|
1318 | |
---|
1319 | // scan IRQS defined in PIC |
---|
1320 | unsigned int cluster_id = 0; |
---|
1321 | unsigned int lpid = 0; |
---|
1322 | unsigned int cx = cluster[cluster_id].x; |
---|
1323 | unsigned int cy = cluster[cluster_id].y; |
---|
1324 | |
---|
1325 | for ( irq_id = pic->irq_offset ; |
---|
1326 | irq_id < pic->irq_offset + pic->irqs ; |
---|
1327 | irq_id++ ) |
---|
1328 | { |
---|
1329 | // compute next values for cluster_id, lpid, cx, cy |
---|
1330 | // if no more WTI allocatable in current cluster |
---|
1331 | unsigned int overflow = 0; |
---|
1332 | |
---|
1333 | while ( (lpid >= cluster[cluster_id].procs) || |
---|
1334 | (_wti_channel_alloc[cx][cy] >= 16) ) |
---|
1335 | { |
---|
1336 | cluster_id = (cluster_id + 1) % (X_SIZE*Y_SIZE); |
---|
1337 | cx = cluster[cluster_id].x; |
---|
1338 | cy = cluster[cluster_id].y; |
---|
1339 | lpid = 0; |
---|
1340 | |
---|
1341 | overflow++; |
---|
1342 | |
---|
1343 | if ( overflow > 1024 ) |
---|
1344 | { |
---|
1345 | _printf("\n[BOOT ERROR] Not enough processors for external IRQs\n"); |
---|
1346 | _exit(); |
---|
1347 | } |
---|
1348 | } |
---|
1349 | // allocate a WTI to processor defined by (cluster_id,lpid) |
---|
1350 | unsigned int type = irq[irq_id].srctype; |
---|
1351 | unsigned int srcid = irq[irq_id].srcid; |
---|
1352 | unsigned int isr = irq[irq_id].isr & 0xFFFF; |
---|
1353 | unsigned int channel = irq[irq_id].channel << 16; |
---|
1354 | |
---|
1355 | if ( (type != IRQ_TYPE_HWI) || (srcid > 31) ) |
---|
1356 | { |
---|
1357 | _printf("\n[BOOT ERROR] in boot_pic_wti_init() Bad IRQ type\n"); |
---|
1358 | _exit(); |
---|
1359 | } |
---|
1360 | |
---|
1361 | // get scheduler address for selected processor |
---|
1362 | static_scheduler_t* psched = _schedulers[cx][cy][lpid]; |
---|
1363 | |
---|
1364 | // update WTI vector for selected processor |
---|
1365 | unsigned int index = _wti_channel_alloc[cx][cy]; |
---|
1366 | psched->wti_vector[index] = isr | channel | 0x80000000; |
---|
1367 | |
---|
1368 | // update IRQ fields in mapping for PIC initialisation |
---|
1369 | irq[irq_id].dest_id = index; |
---|
1370 | irq[irq_id].dest_xy = (cx << Y_WIDTH) + cy; |
---|
1371 | |
---|
1372 | // update pointers |
---|
1373 | _wti_channel_alloc[cx][cy] = index + 1; |
---|
1374 | lpid = lpid + 1; |
---|
1375 | |
---|
1376 | } // end for IRQs |
---|
1377 | |
---|
1378 | #if BOOT_DEBUG_SCHED |
---|
1379 | boot_sched_irq_display(); |
---|
1380 | #endif |
---|
1381 | |
---|
1382 | } // end boot_pic_wti_init() |
---|
1383 | |
---|
1384 | ////////////////////////////////////////////////////////////////////////////////// |
---|
1385 | // This function loads the map.bin file from block device. |
---|
1386 | ////////////////////////////////////////////////////////////////////////////////// |
---|
1387 | void boot_mapping_init() |
---|
1388 | { |
---|
1389 | // desactivates IOC interrupt |
---|
1390 | _ioc_init( 0 ); |
---|
1391 | |
---|
1392 | // open file "map.bin" |
---|
1393 | int fd_id = _fat_open( IOC_BOOT_MODE, |
---|
1394 | "map.bin", |
---|
1395 | 0 ); // no creation |
---|
1396 | if ( fd_id == -1 ) |
---|
1397 | { |
---|
1398 | _printf("\n[BOOT ERROR] : map.bin file not found \n"); |
---|
1399 | _exit(); |
---|
1400 | } |
---|
1401 | |
---|
1402 | #if BOOT_DEBUG_MAPPING |
---|
1403 | _printf("\n[BOOT] map.bin file successfully open at cycle %d\n", _get_proctime() ); |
---|
1404 | #endif |
---|
1405 | |
---|
1406 | // get "map.bin" file size (from fat) and check it |
---|
1407 | unsigned int size = fat.fd[fd_id].file_size; |
---|
1408 | |
---|
1409 | if ( size > SEG_BOOT_MAPPING_SIZE ) |
---|
1410 | { |
---|
1411 | _printf("\n[BOOT ERROR] : allocated segment too small for map.bin file\n"); |
---|
1412 | _exit(); |
---|
1413 | } |
---|
1414 | |
---|
1415 | #if BOOT_DEBUG_MAPPING |
---|
1416 | _printf("\n[BOOT] map.bin buffer pbase = %x / buffer size = %x / file_size = %x\n", |
---|
1417 | SEG_BOOT_MAPPING_BASE , SEG_BOOT_MAPPING_SIZE , size ); |
---|
1418 | #endif |
---|
1419 | |
---|
1420 | // load "map.bin" file into buffer |
---|
1421 | unsigned int nblocks = size >> 9; |
---|
1422 | unsigned int offset = size & 0x1FF; |
---|
1423 | if ( offset ) nblocks++; |
---|
1424 | |
---|
1425 | unsigned int ok = _fat_read( IOC_BOOT_MODE, |
---|
1426 | fd_id, |
---|
1427 | (unsigned int*)SEG_BOOT_MAPPING_BASE, |
---|
1428 | nblocks, |
---|
1429 | 0 ); // offset |
---|
1430 | if ( ok == -1 ) |
---|
1431 | { |
---|
1432 | _printf("\n[BOOT ERROR] : unable to load map.bin file \n"); |
---|
1433 | _exit(); |
---|
1434 | } |
---|
1435 | |
---|
1436 | #if BOOT_DEBUG_MAPPING |
---|
1437 | _printf("\n[BOOT] map.bin file successfully loaded at cycle %d\n", _get_proctime() ); |
---|
1438 | #endif |
---|
1439 | |
---|
1440 | // check mapping signature, number of clusters, number of vspaces |
---|
1441 | mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1442 | if ( (header->signature != IN_MAPPING_SIGNATURE) || |
---|
1443 | (header->x_size != X_SIZE) || |
---|
1444 | (header->y_size != Y_SIZE) || |
---|
1445 | (header->vspaces > GIET_NB_VSPACE_MAX) ) |
---|
1446 | { |
---|
1447 | |
---|
1448 | #if BOOT_DEBUG_MAPPING |
---|
1449 | unsigned int line; |
---|
1450 | unsigned int* pointer = (unsigned int*)SEG_BOOT_MAPPING_BASE; |
---|
1451 | _printf("\n[BOOT] First block of mapping\n"); |
---|
1452 | for ( line = 0 ; line < 8 ; line++ ) |
---|
1453 | { |
---|
1454 | _printf(" | %x | %x | %x | %x | %x | %x | %x | %x |\n", |
---|
1455 | *(pointer + 0), |
---|
1456 | *(pointer + 1), |
---|
1457 | *(pointer + 2), |
---|
1458 | *(pointer + 3), |
---|
1459 | *(pointer + 4), |
---|
1460 | *(pointer + 5), |
---|
1461 | *(pointer + 6), |
---|
1462 | *(pointer + 7) ); |
---|
1463 | |
---|
1464 | pointer = pointer + 8; |
---|
1465 | } |
---|
1466 | #endif |
---|
1467 | _printf("\n[BOOT ERROR] Illegal mapping signature: %x\n", header->signature ); |
---|
1468 | _exit(); |
---|
1469 | } |
---|
1470 | |
---|
1471 | #if BOOT_DEBUG_MAPPING |
---|
1472 | _printf("\n[BOOT] map.bin file checked at cycle %d\n", _get_proctime() ); |
---|
1473 | #endif |
---|
1474 | |
---|
1475 | // close file "map.bin" |
---|
1476 | _fat_close( fd_id ); |
---|
1477 | |
---|
1478 | } // end boot_mapping_init() |
---|
1479 | |
---|
1480 | |
---|
1481 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
1482 | // This function load all loadable segments for one .elf file, identified |
---|
1483 | // by the "pathname" argument. Some loadable segments can be copied in several |
---|
1484 | // clusters: same virtual address but different physical addresses. |
---|
1485 | // - It open the file. |
---|
1486 | // - It loads the complete file in the dedicated boot_elf_buffer. |
---|
1487 | // - It copies each loadable segments at the virtual address defined in |
---|
1488 | // the .elf file, making several copies if the target vseg is not local. |
---|
1489 | // - It closes the file. |
---|
1490 | // This function is supposed to be executed by processor[0,0,0]. |
---|
1491 | // Note: |
---|
1492 | // We must use physical addresses to reach the destination buffers that |
---|
1493 | // can be located in remote clusters. We use either a _physical_memcpy(), |
---|
1494 | // or a _dma_physical_copy() if DMA is available. |
---|
1495 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
1496 | void load_one_elf_file( unsigned int is_kernel, // kernel file if non zero |
---|
1497 | char* pathname, |
---|
1498 | unsigned int vspace_id ) // to scan the proper vspace |
---|
1499 | { |
---|
1500 | mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1501 | mapping_vspace_t * vspace = _get_vspace_base(header); |
---|
1502 | mapping_vseg_t * vseg = _get_vseg_base(header); |
---|
1503 | mapping_vobj_t * vobj = _get_vobj_base(header); |
---|
1504 | |
---|
1505 | unsigned int seg_id; |
---|
1506 | |
---|
1507 | #if BOOT_DEBUG_ELF |
---|
1508 | _printf("\n[BOOT] Start searching file %s at cycle %d\n", |
---|
1509 | pathname, _get_proctime() ); |
---|
1510 | #endif |
---|
1511 | |
---|
1512 | // open .elf file |
---|
1513 | int fd_id = _fat_open( IOC_BOOT_MODE, |
---|
1514 | pathname, |
---|
1515 | 0 ); // no creation |
---|
1516 | if ( fd_id < 0 ) |
---|
1517 | { |
---|
1518 | _printf("\n[BOOT ERROR] load_one_elf_file() : %s not found\n", pathname ); |
---|
1519 | _exit(); |
---|
1520 | } |
---|
1521 | |
---|
1522 | // check buffer size versus file size |
---|
1523 | if ( fat.fd[fd_id].file_size > GIET_ELF_BUFFER_SIZE ) |
---|
1524 | { |
---|
1525 | _printf("\n[BOOT ERROR] in load_one_elf_file() : %s / size = %x " |
---|
1526 | "larger than GIET_ELF_BUFFER_SIZE = %x\n", |
---|
1527 | pathname , fat.fd[fd_id].file_size , GIET_ELF_BUFFER_SIZE ); |
---|
1528 | _exit(); |
---|
1529 | } |
---|
1530 | |
---|
1531 | // compute number of sectors |
---|
1532 | unsigned int nbytes = fat.fd[fd_id].file_size; |
---|
1533 | unsigned int nsectors = nbytes>>9; |
---|
1534 | if( nbytes & 0x1FF) nsectors++; |
---|
1535 | |
---|
1536 | // load file in elf buffer |
---|
1537 | if( _fat_read( IOC_BOOT_MODE, |
---|
1538 | fd_id, |
---|
1539 | boot_elf_buffer, |
---|
1540 | nsectors, |
---|
1541 | 0 ) != nsectors ) |
---|
1542 | { |
---|
1543 | _printf("\n[BOOT ERROR] load_one_elf_file() : unexpected EOF for file %s\n", |
---|
1544 | pathname ); |
---|
1545 | _exit(); |
---|
1546 | } |
---|
1547 | |
---|
1548 | // Check ELF Magic Number in ELF header |
---|
1549 | Elf32_Ehdr* elf_header_ptr = (Elf32_Ehdr*)boot_elf_buffer; |
---|
1550 | |
---|
1551 | if ( (elf_header_ptr->e_ident[EI_MAG0] != ELFMAG0) || |
---|
1552 | (elf_header_ptr->e_ident[EI_MAG1] != ELFMAG1) || |
---|
1553 | (elf_header_ptr->e_ident[EI_MAG2] != ELFMAG2) || |
---|
1554 | (elf_header_ptr->e_ident[EI_MAG3] != ELFMAG3) ) |
---|
1555 | { |
---|
1556 | _printf("\n[BOOT ERROR] load_elf() : file %s does not use ELF format\n", |
---|
1557 | pathname ); |
---|
1558 | _exit(); |
---|
1559 | } |
---|
1560 | |
---|
1561 | // get program header table pointer |
---|
1562 | unsigned int pht_index = elf_header_ptr->e_phoff; |
---|
1563 | if( pht_index == 0 ) |
---|
1564 | { |
---|
1565 | _printf("\n[BOOT ERROR] load_one_elf_file() : file %s " |
---|
1566 | "does not contain loadable segment\n", pathname ); |
---|
1567 | _exit(); |
---|
1568 | } |
---|
1569 | Elf32_Phdr* elf_pht_ptr = (Elf32_Phdr*)(boot_elf_buffer + pht_index); |
---|
1570 | |
---|
1571 | // get number of segments |
---|
1572 | unsigned int nsegments = elf_header_ptr->e_phnum; |
---|
1573 | |
---|
1574 | // Loop on loadable segments in the .elf file |
---|
1575 | for (seg_id = 0 ; seg_id < nsegments ; seg_id++) |
---|
1576 | { |
---|
1577 | if(elf_pht_ptr[seg_id].p_type == PT_LOAD) |
---|
1578 | { |
---|
1579 | // Get segment attributes |
---|
1580 | unsigned int seg_vaddr = elf_pht_ptr[seg_id].p_vaddr; |
---|
1581 | unsigned int seg_offset = elf_pht_ptr[seg_id].p_offset; |
---|
1582 | unsigned int seg_filesz = elf_pht_ptr[seg_id].p_filesz; |
---|
1583 | unsigned int seg_memsz = elf_pht_ptr[seg_id].p_memsz; |
---|
1584 | |
---|
1585 | #if BOOT_DEBUG_ELF |
---|
1586 | _printf("\n[BOOT] Segment %d : vaddr = %x / size = %x\n", |
---|
1587 | seg_id , seg_vaddr , seg_filesz ); |
---|
1588 | #endif |
---|
1589 | |
---|
1590 | if( seg_memsz < seg_filesz ) |
---|
1591 | { |
---|
1592 | _printf("\n[BOOT ERROR] load_one_elf_file() : segment at vaddr = %x" |
---|
1593 | " in file %s has memsize < filesize \n", seg_vaddr, pathname ); |
---|
1594 | _exit(); |
---|
1595 | } |
---|
1596 | |
---|
1597 | // fill empty space with 0 as required |
---|
1598 | if( seg_memsz > seg_filesz ) |
---|
1599 | { |
---|
1600 | unsigned int i; |
---|
1601 | for( i = seg_filesz ; i < seg_memsz ; i++ ) |
---|
1602 | boot_elf_buffer[i+seg_offset] = 0; |
---|
1603 | } |
---|
1604 | |
---|
1605 | unsigned int src_vaddr = (unsigned int)boot_elf_buffer + seg_offset; |
---|
1606 | |
---|
1607 | // search all vsegs matching the virtual address |
---|
1608 | unsigned int vseg_first; |
---|
1609 | unsigned int vseg_last; |
---|
1610 | unsigned int vseg_id; |
---|
1611 | unsigned int found = 0; |
---|
1612 | if ( is_kernel ) |
---|
1613 | { |
---|
1614 | vseg_first = 0; |
---|
1615 | vseg_last = header->globals; |
---|
1616 | } |
---|
1617 | else |
---|
1618 | { |
---|
1619 | vseg_first = vspace[vspace_id].vseg_offset; |
---|
1620 | vseg_last = vseg_first + vspace[vspace_id].vsegs; |
---|
1621 | } |
---|
1622 | |
---|
1623 | for ( vseg_id = vseg_first ; vseg_id < vseg_last ; vseg_id++ ) |
---|
1624 | { |
---|
1625 | if ( seg_vaddr == vseg[vseg_id].vbase ) // matching |
---|
1626 | { |
---|
1627 | found = 1; |
---|
1628 | |
---|
1629 | // get destination buffer physical address and size |
---|
1630 | paddr_t seg_paddr = vseg[vseg_id].pbase; |
---|
1631 | unsigned int vobj_id = vseg[vseg_id].vobj_offset; |
---|
1632 | unsigned int seg_size = vobj[vobj_id].length; |
---|
1633 | |
---|
1634 | #if BOOT_DEBUG_ELF |
---|
1635 | _printf(" loaded into vseg %s at paddr = %l / buffer size = %x\n", |
---|
1636 | vseg[vseg_id].name , seg_paddr , seg_size ); |
---|
1637 | #endif |
---|
1638 | // check vseg size |
---|
1639 | if ( seg_size < seg_filesz ) |
---|
1640 | { |
---|
1641 | _printf("\n[BOOT ERROR] in load_one_elf_file() : vseg %s " |
---|
1642 | "is to small for loadable segment %x in file %s\n", |
---|
1643 | vseg[vseg_id].name , seg_vaddr , pathname ); |
---|
1644 | _exit(); |
---|
1645 | } |
---|
1646 | |
---|
1647 | // copy the segment from boot buffer to destination buffer |
---|
1648 | // using DMA channel[0,0,0] if it is available. |
---|
1649 | if( NB_DMA_CHANNELS > 0 ) |
---|
1650 | { |
---|
1651 | _dma_physical_copy( 0, // DMA in cluster[0,0] |
---|
1652 | 0, // DMA channel 0 |
---|
1653 | (paddr_t)seg_paddr, // destination paddr |
---|
1654 | (paddr_t)src_vaddr, // source paddr |
---|
1655 | seg_filesz ); // size |
---|
1656 | } |
---|
1657 | else |
---|
1658 | { |
---|
1659 | _physical_memcpy( (paddr_t)seg_paddr, // destination paddr |
---|
1660 | (paddr_t)src_vaddr, // source paddr |
---|
1661 | seg_filesz ); // size |
---|
1662 | } |
---|
1663 | } |
---|
1664 | } // end for vsegs in vspace |
---|
1665 | |
---|
1666 | // check at least one matching vseg |
---|
1667 | if ( found == 0 ) |
---|
1668 | { |
---|
1669 | _printf("\n[BOOT ERROR] in load_one_elf_file() : vseg for loadable " |
---|
1670 | "segment %x in file %s not found " |
---|
1671 | "check consistency between the .py and .ld files\n", |
---|
1672 | seg_vaddr, pathname ); |
---|
1673 | _exit(); |
---|
1674 | } |
---|
1675 | } |
---|
1676 | } // end for loadable segments |
---|
1677 | |
---|
1678 | // close .elf file |
---|
1679 | _fat_close( fd_id ); |
---|
1680 | |
---|
1681 | _printf("\n[BOOT] File %s loaded at cycle %d\n", |
---|
1682 | pathname , _get_proctime() ); |
---|
1683 | |
---|
1684 | } // end load_one_elf_file() |
---|
1685 | |
---|
1686 | |
---|
1687 | /////i//////////////////////////////////////////////////////////////////////////////// |
---|
1688 | // This function uses the map.bin data structure to load the "kernel.elf" file |
---|
1689 | // as well as the various "application.elf" files into memory. |
---|
1690 | // - The "preloader.elf" file is not loaded, because it has been burned in the ROM. |
---|
1691 | // - The "boot.elf" file is not loaded, because it has been loaded by the preloader. |
---|
1692 | // This function scans all vobjs defined in the map.bin data structure to collect |
---|
1693 | // all .elf files pathnames, and calls the load_one_elf_file() for each .elf file. |
---|
1694 | // As the code can be replicated in several vsegs, the same code can be copied |
---|
1695 | // in one or several clusters by the load_one_elf_file() function. |
---|
1696 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
1697 | void boot_elf_load() |
---|
1698 | { |
---|
1699 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1700 | mapping_vspace_t* vspace = _get_vspace_base( header ); |
---|
1701 | mapping_vobj_t* vobj = _get_vobj_base( header ); |
---|
1702 | unsigned int vspace_id; |
---|
1703 | unsigned int vobj_id; |
---|
1704 | unsigned int found; |
---|
1705 | |
---|
1706 | // Scan all vobjs corresponding to global vsegs, |
---|
1707 | // to find the pathname to the kernel.elf file |
---|
1708 | found = 0; |
---|
1709 | for( vobj_id = 0 ; vobj_id < header->globals ; vobj_id++ ) |
---|
1710 | { |
---|
1711 | if(vobj[vobj_id].type == VOBJ_TYPE_ELF) |
---|
1712 | { |
---|
1713 | found = 1; |
---|
1714 | break; |
---|
1715 | } |
---|
1716 | } |
---|
1717 | |
---|
1718 | // We need one kernel.elf file |
---|
1719 | if (found == 0) |
---|
1720 | { |
---|
1721 | _printf("\n[BOOT ERROR] boot_elf_load() : kernel.elf file not found\n"); |
---|
1722 | _exit(); |
---|
1723 | } |
---|
1724 | |
---|
1725 | // Load the kernel |
---|
1726 | load_one_elf_file( 1, // kernel file |
---|
1727 | vobj[vobj_id].binpath, // file pathname |
---|
1728 | 0 ); // vspace 0 |
---|
1729 | |
---|
1730 | // loop on the vspaces, scanning all vobjs in the vspace, |
---|
1731 | // to find the pathname of the .elf file associated to the vspace. |
---|
1732 | for( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
1733 | { |
---|
1734 | // loop on the vobjs in vspace (vobj_id is the global index) |
---|
1735 | unsigned int found = 0; |
---|
1736 | for (vobj_id = vspace[vspace_id].vobj_offset; |
---|
1737 | vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); |
---|
1738 | vobj_id++) |
---|
1739 | { |
---|
1740 | if(vobj[vobj_id].type == VOBJ_TYPE_ELF) |
---|
1741 | { |
---|
1742 | found = 1; |
---|
1743 | break; |
---|
1744 | } |
---|
1745 | } |
---|
1746 | |
---|
1747 | // We want one .elf file per vspace |
---|
1748 | if (found == 0) |
---|
1749 | { |
---|
1750 | _printf("\n[BOOT ERROR] boot_elf_load() : " |
---|
1751 | ".elf file not found for vspace %s\n", vspace[vspace_id].name ); |
---|
1752 | _exit(); |
---|
1753 | } |
---|
1754 | |
---|
1755 | load_one_elf_file( 0, // not a kernel file |
---|
1756 | vobj[vobj_id].binpath, // file pathname |
---|
1757 | vspace_id ); // vspace index |
---|
1758 | |
---|
1759 | } // end for vspaces |
---|
1760 | |
---|
1761 | } // end boot_elf_load() |
---|
1762 | |
---|
1763 | //////////////////////////////////////////////////////////////////////////////// |
---|
1764 | // This function intializes the periherals and coprocessors, as specified |
---|
1765 | // in the mapping_info file. |
---|
1766 | //////////////////////////////////////////////////////////////////////////////// |
---|
1767 | void boot_peripherals_init() |
---|
1768 | { |
---|
1769 | mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1770 | mapping_cluster_t * cluster = _get_cluster_base(header); |
---|
1771 | mapping_periph_t * periph = _get_periph_base(header); |
---|
1772 | mapping_vobj_t * vobj = _get_vobj_base(header); |
---|
1773 | mapping_coproc_t * coproc = _get_coproc_base(header); |
---|
1774 | mapping_cp_port_t * cp_port = _get_cp_port_base(header); |
---|
1775 | mapping_irq_t * irq = _get_irq_base(header); |
---|
1776 | |
---|
1777 | unsigned int cluster_id; |
---|
1778 | unsigned int periph_id; |
---|
1779 | unsigned int coproc_id; |
---|
1780 | unsigned int cp_port_id; |
---|
1781 | unsigned int channel_id; |
---|
1782 | |
---|
1783 | // loop on all physical clusters |
---|
1784 | for (cluster_id = 0; cluster_id < X_SIZE*Y_SIZE; cluster_id++) |
---|
1785 | { |
---|
1786 | // computes cluster coordinates |
---|
1787 | unsigned int x = cluster[cluster_id].x; |
---|
1788 | unsigned int y = cluster[cluster_id].y; |
---|
1789 | unsigned int cluster_xy = (x<<Y_WIDTH) + y; |
---|
1790 | |
---|
1791 | #if BOOT_DEBUG_PERI |
---|
1792 | _printf("\n[BOOT] Peripherals initialisation in cluster[%d,%d]\n", x , y ); |
---|
1793 | #endif |
---|
1794 | |
---|
1795 | // loop on peripherals |
---|
1796 | for (periph_id = cluster[cluster_id].periph_offset; |
---|
1797 | periph_id < cluster[cluster_id].periph_offset + |
---|
1798 | cluster[cluster_id].periphs; periph_id++) |
---|
1799 | { |
---|
1800 | unsigned int type = periph[periph_id].type; |
---|
1801 | unsigned int subtype = periph[periph_id].subtype; |
---|
1802 | unsigned int channels = periph[periph_id].channels; |
---|
1803 | |
---|
1804 | switch (type) |
---|
1805 | { |
---|
1806 | case PERIPH_TYPE_IOC: // vci_block_device component |
---|
1807 | { |
---|
1808 | if ( subtype == PERIPH_SUBTYPE_BDV ) |
---|
1809 | { |
---|
1810 | _bdv_init(); |
---|
1811 | } |
---|
1812 | else if ( subtype == PERIPH_SUBTYPE_HBA ) |
---|
1813 | { |
---|
1814 | for (channel_id = 0; channel_id < channels; channel_id++) |
---|
1815 | _hba_init( channel_id ); |
---|
1816 | } |
---|
1817 | else if ( subtype == PERIPH_SUBTYPE_SPI ) |
---|
1818 | { |
---|
1819 | //TODO |
---|
1820 | } |
---|
1821 | break; |
---|
1822 | } |
---|
1823 | case PERIPH_TYPE_TTY: // vci_multi_tty component |
---|
1824 | { |
---|
1825 | for (channel_id = 0; channel_id < channels; channel_id++) |
---|
1826 | { |
---|
1827 | _tty_init( channel_id ); |
---|
1828 | } |
---|
1829 | break; |
---|
1830 | } |
---|
1831 | case PERIPH_TYPE_NIC: // vci_multi_nic component |
---|
1832 | { |
---|
1833 | _nic_global_init( 1, // broadcast accepted |
---|
1834 | 1, // bypass activated |
---|
1835 | 0, // tdm non activated |
---|
1836 | 0 ); // tdm period |
---|
1837 | break; |
---|
1838 | } |
---|
1839 | case PERIPH_TYPE_IOB: // vci_io_bridge component |
---|
1840 | { |
---|
1841 | if (GIET_USE_IOMMU) |
---|
1842 | { |
---|
1843 | // TODO |
---|
1844 | // get the iommu page table physical address |
---|
1845 | // set IOMMU page table address |
---|
1846 | // pseg_base[IOB_IOMMU_PTPR] = ptab_pbase; |
---|
1847 | // activate IOMMU |
---|
1848 | // pseg_base[IOB_IOMMU_ACTIVE] = 1; |
---|
1849 | } |
---|
1850 | break; |
---|
1851 | } |
---|
1852 | case PERIPH_TYPE_PIC: // vci_iopic component |
---|
1853 | { |
---|
1854 | // scan all IRQs defined in mapping for PIC component, |
---|
1855 | // and initialises addresses for WTI IRQs |
---|
1856 | for ( channel_id = periph[periph_id].irq_offset ; |
---|
1857 | channel_id < periph[periph_id].irq_offset + periph[periph_id].irqs ; |
---|
1858 | channel_id++ ) |
---|
1859 | { |
---|
1860 | unsigned int hwi_id = irq[channel_id].srcid; // HWI index in PIC |
---|
1861 | unsigned int wti_id = irq[channel_id].dest_id; // WTI index in XCU |
---|
1862 | unsigned int cluster_xy = irq[channel_id].dest_xy; // XCU coordinates |
---|
1863 | unsigned int vaddr; |
---|
1864 | |
---|
1865 | _xcu_get_wti_address( wti_id, &vaddr ); |
---|
1866 | _pic_init( hwi_id, vaddr, cluster_xy ); |
---|
1867 | |
---|
1868 | #if BOOT_DEBUG_PERI |
---|
1869 | _printf("[BOOT] PIC : hwi_index = %d => wti_index = %d for XCU[%d,%d]\n", |
---|
1870 | hwi_id , wti_id , cluster_xy >> Y_WIDTH , cluster_xy & ((1<<Y_WIDTH)-1) ); |
---|
1871 | #endif |
---|
1872 | } |
---|
1873 | break; |
---|
1874 | } |
---|
1875 | } // end switch periph type |
---|
1876 | } // end for periphs |
---|
1877 | |
---|
1878 | #if BOOT_DEBUG_PERI |
---|
1879 | _printf("\n[BOOT] Coprocessors initialisation in cluster[%d,%d]\n", x , y ); |
---|
1880 | #endif |
---|
1881 | |
---|
1882 | // loop on coprocessors |
---|
1883 | for ( coproc_id = cluster[cluster_id].coproc_offset; |
---|
1884 | coproc_id < cluster[cluster_id].coproc_offset + |
---|
1885 | cluster[cluster_id].coprocs; coproc_id++ ) |
---|
1886 | { |
---|
1887 | // loop on the coprocessor ports |
---|
1888 | for ( cp_port_id = coproc[coproc_id].port_offset; |
---|
1889 | cp_port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports; |
---|
1890 | cp_port_id++ ) |
---|
1891 | { |
---|
1892 | // get global index of associted vobj |
---|
1893 | unsigned int vobj_id = cp_port[cp_port_id].mwmr_vobj_id; |
---|
1894 | |
---|
1895 | // get MWMR channel base address |
---|
1896 | page_table_t* ptab = (page_table_t*)_ptabs_vaddr[0][x][y]; |
---|
1897 | unsigned int vbase = vobj[vobj_id].vbase; |
---|
1898 | unsigned int ppn; |
---|
1899 | unsigned int flags; |
---|
1900 | paddr_t pbase; |
---|
1901 | |
---|
1902 | _v2p_translate( ptab, |
---|
1903 | vbase>>12 , |
---|
1904 | &ppn, |
---|
1905 | &flags ); |
---|
1906 | |
---|
1907 | pbase = ((paddr_t)ppn)<<12; |
---|
1908 | |
---|
1909 | // initialise cp_port |
---|
1910 | _mwr_hw_init( cluster_xy, |
---|
1911 | cp_port_id, |
---|
1912 | cp_port[cp_port_id].direction, |
---|
1913 | pbase ); |
---|
1914 | |
---|
1915 | } // end for cp_ports |
---|
1916 | } // end for coprocs |
---|
1917 | } // end for clusters |
---|
1918 | } // end boot_peripherals_init() |
---|
1919 | |
---|
1920 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
1921 | // This function is executed in parallel by all processors[x][y][0]. |
---|
1922 | // It initialises the physical memory allocator in each cluster containing a RAM pseg. |
---|
1923 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
1924 | void boot_pmem_init( unsigned int cx, |
---|
1925 | unsigned int cy ) |
---|
1926 | { |
---|
1927 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1928 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
1929 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
1930 | |
---|
1931 | unsigned int pseg_id; |
---|
1932 | unsigned int procid = _get_procid(); |
---|
1933 | unsigned int lpid = procid & ((1<<P_WIDTH)-1); |
---|
1934 | |
---|
1935 | if( lpid ) |
---|
1936 | { |
---|
1937 | _printf("\n[BOOT ERROR] boot_pmem_init() : " |
---|
1938 | "P[%d][%d][%d] should not execute it\n", cx, cy, lpid ); |
---|
1939 | _exit(); |
---|
1940 | } |
---|
1941 | |
---|
1942 | // scan the psegs in local cluster to find pseg of type RAM |
---|
1943 | unsigned int found = 0; |
---|
1944 | unsigned int cluster_id = cx * Y_SIZE + cy; |
---|
1945 | unsigned int pseg_min = cluster[cluster_id].pseg_offset; |
---|
1946 | unsigned int pseg_max = pseg_min + cluster[cluster_id].psegs; |
---|
1947 | for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ ) |
---|
1948 | { |
---|
1949 | if ( pseg[pseg_id].type == PSEG_TYPE_RAM ) |
---|
1950 | { |
---|
1951 | unsigned int base = (unsigned int)pseg[pseg_id].base; |
---|
1952 | unsigned int size = (unsigned int)pseg[pseg_id].length; |
---|
1953 | _pmem_alloc_init( cx, cy, base, size ); |
---|
1954 | found = 1; |
---|
1955 | |
---|
1956 | #if BOOT_DEBUG_PT |
---|
1957 | _printf("\n[BOOT] pmem allocator initialised in cluster[%d][%d]" |
---|
1958 | " : base = %x / size = %x\n", cx , cy , base , size ); |
---|
1959 | #endif |
---|
1960 | break; |
---|
1961 | } |
---|
1962 | } |
---|
1963 | |
---|
1964 | if ( found == 0 ) |
---|
1965 | { |
---|
1966 | _printf("\n[BOOT ERROR] boot_pmem_init() : no RAM in cluster[%d][%d]\n", |
---|
1967 | cx , cy ); |
---|
1968 | _exit(); |
---|
1969 | } |
---|
1970 | } // end boot_pmem_init() |
---|
1971 | |
---|
1972 | ///////////////////////////////////////////////////////////////////////// |
---|
1973 | // This function is the entry point of the boot code for all processors. |
---|
1974 | ///////////////////////////////////////////////////////////////////////// |
---|
1975 | void boot_init() |
---|
1976 | { |
---|
1977 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
1978 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
1979 | |
---|
1980 | unsigned int gpid = _get_procid(); |
---|
1981 | unsigned int cx = gpid >> (Y_WIDTH + P_WIDTH); |
---|
1982 | unsigned int cy = (gpid >> P_WIDTH) & ((1<<Y_WIDTH)-1); |
---|
1983 | unsigned int lpid = gpid & ((1 << P_WIDTH) -1); |
---|
1984 | unsigned int cluster_id = (cx * Y_SIZE) + cy; |
---|
1985 | |
---|
1986 | // Phase ONE : only P[0][0][0] execute it |
---|
1987 | if ( gpid == 0 ) |
---|
1988 | { |
---|
1989 | unsigned int cid; // index for loops |
---|
1990 | |
---|
1991 | // initialises the TTY0 spin lock |
---|
1992 | _spin_lock_init( &_tty0_spin_lock ); |
---|
1993 | |
---|
1994 | _printf("\n[BOOT] P[0,0,0] starts at cycle %d\n", _get_proctime() ); |
---|
1995 | |
---|
1996 | // initialises the FAT |
---|
1997 | _fat_init( IOC_BOOT_MODE ); |
---|
1998 | |
---|
1999 | _printf("\n[BOOT] FAT initialised at cycle %d\n", _get_proctime() ); |
---|
2000 | |
---|
2001 | // Load the map.bin file into memory |
---|
2002 | boot_mapping_init(); |
---|
2003 | |
---|
2004 | _printf("\n[BOOT] Mapping %s loaded at cycle %d\n", |
---|
2005 | header->name , _get_proctime() ); |
---|
2006 | |
---|
2007 | // initialises the barrier for all clusters containing processors |
---|
2008 | unsigned int nclusters = 0; |
---|
2009 | for ( cid = 0 ; cid < X_SIZE*Y_SIZE ; cid++ ) |
---|
2010 | { |
---|
2011 | if ( cluster[cid].procs ) nclusters++ ; |
---|
2012 | } |
---|
2013 | |
---|
2014 | _simple_barrier_init( &_barrier_all_clusters , nclusters ); |
---|
2015 | |
---|
2016 | // wake up all processors P[x][y][0] |
---|
2017 | for ( cid = 1 ; cid < X_SIZE*Y_SIZE ; cid++ ) |
---|
2018 | { |
---|
2019 | unsigned int x = cluster[cid].x; |
---|
2020 | unsigned int y = cluster[cid].y; |
---|
2021 | unsigned int cluster_xy = (x << Y_WIDTH) + y; |
---|
2022 | |
---|
2023 | if ( cluster[cid].procs ) |
---|
2024 | { |
---|
2025 | unsigned long long paddr = (((unsigned long long)cluster_xy)<<32) + |
---|
2026 | SEG_XCU_BASE + XCU_REG( XCU_WTI_REG , 0 ); |
---|
2027 | |
---|
2028 | _physical_write( paddr , (unsigned int)boot_entry ); |
---|
2029 | } |
---|
2030 | } |
---|
2031 | |
---|
2032 | _printf("\n[BOOT] Processors P[x,y,0] start at cycle %d\n", _get_proctime() ); |
---|
2033 | } |
---|
2034 | |
---|
2035 | // Phase TWO : All processors P[x][y][0] execute it in parallel |
---|
2036 | if( lpid == 0 ) |
---|
2037 | { |
---|
2038 | // Initializes physical memory allocator in cluster[cx][cy] |
---|
2039 | boot_pmem_init( cx , cy ); |
---|
2040 | |
---|
2041 | // Build page table in cluster[cx][cy] |
---|
2042 | boot_ptab_init( cx , cy ); |
---|
2043 | |
---|
2044 | ////////////////////////////////////////////// |
---|
2045 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
2046 | ////////////////////////////////////////////// |
---|
2047 | |
---|
2048 | // P[0][0][0] complete page tables with vsegs |
---|
2049 | // mapped in clusters without processors |
---|
2050 | if ( gpid == 0 ) |
---|
2051 | { |
---|
2052 | // complete page tables initialisation |
---|
2053 | boot_ptab_extend(); |
---|
2054 | |
---|
2055 | _printf("\n[BOOT] Physical memory allocators and page tables" |
---|
2056 | " initialized at cycle %d\n", _get_proctime() ); |
---|
2057 | } |
---|
2058 | |
---|
2059 | ////////////////////////////////////////////// |
---|
2060 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
2061 | ////////////////////////////////////////////// |
---|
2062 | |
---|
2063 | // All processors P[x,y,0] activate MMU (using local PTAB) |
---|
2064 | _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[0][cx][cy]>>13) ); |
---|
2065 | _set_mmu_mode( 0xF ); |
---|
2066 | |
---|
2067 | // Each processor P[x,y,0] initialises all schedulers in cluster[x,y] |
---|
2068 | boot_scheduler_init( cx , cy ); |
---|
2069 | |
---|
2070 | // Each processor P[x][y][0] initialises its CP0_SCHED register |
---|
2071 | _set_sched( (unsigned int)_schedulers[cx][cy][0] ); |
---|
2072 | |
---|
2073 | ////////////////////////////////////////////// |
---|
2074 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
2075 | ////////////////////////////////////////////// |
---|
2076 | |
---|
2077 | // Processor P[0,0,0] completes schedulers with PIC-WTI |
---|
2078 | // initialises external peripherals and load .elf files. |
---|
2079 | if ( gpid == 0 ) |
---|
2080 | { |
---|
2081 | // complete schedulers initialisation |
---|
2082 | boot_pic_wti_init(); |
---|
2083 | |
---|
2084 | _printf("\n[BOOT] Schedulers initialised at cycle %d\n", _get_proctime() ); |
---|
2085 | |
---|
2086 | // initialize non replicated peripherals |
---|
2087 | boot_peripherals_init(); |
---|
2088 | |
---|
2089 | _printf("\n[BOOT] Peripherals initialised at cycle %d\n", _get_proctime() ); |
---|
2090 | |
---|
2091 | // Loading all .elf files |
---|
2092 | boot_elf_load(); |
---|
2093 | } |
---|
2094 | /* |
---|
2095 | // Each processor P[x][y][0] checks sequencially its local page table |
---|
2096 | unsigned int seq_x; |
---|
2097 | unsigned int seq_y; |
---|
2098 | for ( seq_x = 0 ; seq_x < X_SIZE ; seq_x++ ) |
---|
2099 | { |
---|
2100 | for ( seq_y = 0 ; seq_y < Y_SIZE ; seq_y++ ) |
---|
2101 | { |
---|
2102 | if ( (cx == seq_x) && (cy == seq_y) ) boot_ptab_check( cx , cy ); |
---|
2103 | |
---|
2104 | ////////////////////////////////////////////// |
---|
2105 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
2106 | ////////////////////////////////////////////// |
---|
2107 | } |
---|
2108 | } |
---|
2109 | */ |
---|
2110 | ////////////////////////////////////////////// |
---|
2111 | _simple_barrier_wait( &_barrier_all_clusters ); |
---|
2112 | ////////////////////////////////////////////// |
---|
2113 | |
---|
2114 | // each processor P[x][y][0] wake up other processors in same cluster |
---|
2115 | unsigned int cluster_xy = (cx << Y_WIDTH) + cy; |
---|
2116 | unsigned int p; |
---|
2117 | for ( p = 1 ; p < cluster[cluster_id].procs ; p++ ) |
---|
2118 | { |
---|
2119 | _xcu_send_wti( cluster_xy , p , (unsigned int)boot_entry ); |
---|
2120 | } |
---|
2121 | |
---|
2122 | if ( gpid == 0 ) // only P[0][0][0] makes display |
---|
2123 | _printf("\n[BOOT] All processors start at cycle %d\n", _get_proctime() ); |
---|
2124 | } |
---|
2125 | |
---|
2126 | // Other processors than P[x][y][0] activate MMU (using local PTAB) |
---|
2127 | if ( lpid != 0 ) |
---|
2128 | { |
---|
2129 | _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[0][cx][cy]>>13) ); |
---|
2130 | _set_mmu_mode( 0xF ); |
---|
2131 | } |
---|
2132 | |
---|
2133 | // All processors set CP0_SCHED register |
---|
2134 | _set_sched( (unsigned int)_schedulers[cx][cy][lpid] ); |
---|
2135 | |
---|
2136 | // All processors reset BEV bit in SR to use GIET_VM exception handler |
---|
2137 | _set_sr( 0 ); |
---|
2138 | |
---|
2139 | // All processors jump to kernel_init |
---|
2140 | unsigned int kernel_entry = (unsigned int)&kernel_init_vbase; |
---|
2141 | asm volatile( "jr %0" ::"r"(kernel_entry) ); |
---|
2142 | |
---|
2143 | } // end boot_init() |
---|
2144 | |
---|
2145 | |
---|
2146 | // Local Variables: |
---|
2147 | // tab-width: 4 |
---|
2148 | // c-basic-offset: 4 |
---|
2149 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
2150 | // indent-tabs-mode: nil |
---|
2151 | // End: |
---|
2152 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
2153 | |
---|