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