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