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