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