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