| 1 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // File : boot_init.c |
|---|
| 3 | // Date : 01/04/2012 |
|---|
| 4 | // Author : alain greiner |
|---|
| 5 | // Copyright (c) UPMC-LIP6 |
|---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | // The boot_init.c file is part of the GIET-VM nano-kernel. |
|---|
| 8 | // This code is executed in the boot phase by proc[0] to initialize the |
|---|
| 9 | // peripherals and the kernel data structures: |
|---|
| 10 | // - pages tables for the various vspaces |
|---|
| 11 | // - shedulers for processors (including the tasks contexts and interrupt vectors) |
|---|
| 12 | // |
|---|
| 13 | // This nano-kernel has been written for the MIPS32 processor. |
|---|
| 14 | // The virtual adresses are on 32 bits and use the (unsigned int) type, but the |
|---|
| 15 | // physicals addresses can have up to 40 bits, and use the (unsigned long long) type. |
|---|
| 16 | // |
|---|
| 17 | // The GIET-VM uses the paged virtual memory and the MAPPING_INFO binary file |
|---|
| 18 | // to provides two services: |
|---|
| 19 | // 1) classical memory protection, when several independant applications compiled |
|---|
| 20 | // in different virtual spaces are executing on the same hardware platform. |
|---|
| 21 | // 2) data placement in NUMA architectures, when we want to control the placement |
|---|
| 22 | // of the software objects (virtual segments) on the physical memory banks. |
|---|
| 23 | // |
|---|
| 24 | // The MAPPING_INFO binary data structure must be loaded in the the seg_boot_mapping |
|---|
| 25 | // segment (at address seg_mapping_base). |
|---|
| 26 | // This MAPPING_INFO data structure defines |
|---|
| 27 | // - the hardware architecture: number of clusters, number or processors, |
|---|
| 28 | // size of the memory segments, and peripherals in each cluster. |
|---|
| 29 | // - The structure of the various multi-threaded software applications: |
|---|
| 30 | // number of tasks, communication channels. |
|---|
| 31 | // - The mapping: placement of virtual objects (vobj) in the virtual segments (vseg), |
|---|
| 32 | // placement of virtual segments (vseg) in the physical segments (pseg), placement |
|---|
| 33 | // of software tasks on the processors, |
|---|
| 34 | // |
|---|
| 35 | // The page table are statically build in the boot phase, and they do not |
|---|
| 36 | // change during execution. The GIET uses only 4 Kbytes pages. |
|---|
| 37 | // As most applications use only a limited number of segments, the number of PT2s |
|---|
| 38 | // actually used by a given virtual space is generally smaller than 2048, and is |
|---|
| 39 | // computed during the boot phase. |
|---|
| 40 | // The max number of virtual spaces (GIET_NB_VSPACE_MAX) is a configuration parameter. |
|---|
| 41 | // |
|---|
| 42 | // Each page table (one page table per virtual space) is monolithic, and contains |
|---|
| 43 | // one PT1 and up to (GIET_NB_PT2_MAX) PT2s. The PT1 is addressed using the ix1 field |
|---|
| 44 | // (11 bits) of the VPN, and the selected PT2 is addressed using the ix2 field (9 bits). |
|---|
| 45 | // - PT1[2048] : a first 8K aligned array of unsigned int, indexed by (ix1) field of VPN. |
|---|
| 46 | // Each entry in the PT1 contains a 32 bits PTD. The MSB bit PTD[31] is |
|---|
| 47 | // the PTD valid bit, and LSB bits PTD[19:0] are the 20 MSB bits of the physical base |
|---|
| 48 | // address of the selected PT2. |
|---|
| 49 | // The PT1 contains 2048 PTD of 4 bytes => 8K bytes. |
|---|
| 50 | // - PT2[1024][GIET_NB_PT2_MAX] : an array of array of unsigned int. |
|---|
| 51 | // Each PT2[1024] must be 4K aligned, each entry in a PT2 contains two unsigned int: |
|---|
| 52 | // the first word contains the protection flags, and the second word contains the PPN. |
|---|
| 53 | // Each PT2 contains 512 PTE2 of 8bytes => 4K bytes. |
|---|
| 54 | // The total size of a page table is finally = 8K + (GIET_NB_PT2_MAX)*4K bytes. |
|---|
| 55 | //////////////////////////////////////////////////////////////////////////////////// |
|---|
| 56 | |
|---|
| 57 | #include <common.h> |
|---|
| 58 | #include <mips32_registers.h> |
|---|
| 59 | #include <giet_config.h> |
|---|
| 60 | #include <mapping_info.h> |
|---|
| 61 | #include <mwmr_channel.h> |
|---|
| 62 | #include <barrier.h> |
|---|
| 63 | #include <memspace.h> |
|---|
| 64 | #include <irq_handler.h> |
|---|
| 65 | #include <ctx_handler.h> |
|---|
| 66 | #include <vm_handler.h> |
|---|
| 67 | #include <hwr_mapping.h> |
|---|
| 68 | |
|---|
| 69 | #include <stdarg.h> |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | #if !defined(NB_CLUSTERS) |
|---|
| 73 | # error The NB_CLUSTERS value must be defined in the 'giet_config.h' file ! |
|---|
| 74 | #endif |
|---|
| 75 | |
|---|
| 76 | #if !defined(NB_PROCS_MAX) |
|---|
| 77 | # error The NB_PROCS_MAX value must be defined in the 'giet_config.h' file ! |
|---|
| 78 | #endif |
|---|
| 79 | |
|---|
| 80 | #if !defined(GIET_NB_VSPACE_MAX) |
|---|
| 81 | # error The GIET_NB_VSPACE_MAX value must be defined in the 'giet_config.h' file ! |
|---|
| 82 | #endif |
|---|
| 83 | |
|---|
| 84 | #define max(x, y) (((x) > (y)) ? (x) : (y)) |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 88 | // Global variables for boot code |
|---|
| 89 | // Both the page tables for the various virtual spaces, and the schedulers |
|---|
| 90 | // for the processors are physically distributed on the clusters. |
|---|
| 91 | // These global variables are just arrays of pointers. |
|---|
| 92 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 93 | |
|---|
| 94 | // Page table addresses arrays |
|---|
| 95 | __attribute__((section (".wdata"))) |
|---|
| 96 | paddr_t boot_ptabs_paddr[GIET_NB_VSPACE_MAX]; |
|---|
| 97 | |
|---|
| 98 | __attribute__((section (".wdata"))) |
|---|
| 99 | unsigned int boot_ptabs_vaddr[GIET_NB_VSPACE_MAX]; |
|---|
| 100 | |
|---|
| 101 | // Scheduler pointers array (virtual addresses) |
|---|
| 102 | __attribute__((section (".wdata"))) |
|---|
| 103 | static_scheduler_t* boot_schedulers[NB_CLUSTERS * NB_PROCS_MAX]; |
|---|
| 104 | |
|---|
| 105 | // Next free PT2 index array |
|---|
| 106 | __attribute__((section (".wdata"))) |
|---|
| 107 | unsigned int boot_next_free_pt2[GIET_NB_VSPACE_MAX] = |
|---|
| 108 | { [0 ... GIET_NB_VSPACE_MAX - 1] = 0 }; |
|---|
| 109 | |
|---|
| 110 | // Max PT2 index |
|---|
| 111 | __attribute__((section (".wdata"))) |
|---|
| 112 | unsigned int boot_max_pt2[GIET_NB_VSPACE_MAX] = |
|---|
| 113 | { [0 ... GIET_NB_VSPACE_MAX - 1] = 0 }; |
|---|
| 114 | |
|---|
| 115 | // lock protecting TTY0 |
|---|
| 116 | __attribute__((section (".wdata"))) |
|---|
| 117 | unsigned int boot_tty0_lock = 0; |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 121 | // boot_procid() |
|---|
| 122 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 123 | inline unsigned int boot_procid() |
|---|
| 124 | { |
|---|
| 125 | unsigned int ret; |
|---|
| 126 | asm volatile ("mfc0 %0, $15, 1":"=r" (ret)); |
|---|
| 127 | return (ret & 0x3FF); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 131 | // boot_proctime() |
|---|
| 132 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 133 | inline unsigned int boot_proctime() |
|---|
| 134 | { |
|---|
| 135 | unsigned int ret; |
|---|
| 136 | asm volatile ("mfc0 %0, $9":"=r" (ret)); |
|---|
| 137 | return ret; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 141 | // boot_exit() |
|---|
| 142 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 143 | void boot_exit() |
|---|
| 144 | { |
|---|
| 145 | while (1) { asm volatile ("nop"); } |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 149 | // boot_eret() |
|---|
| 150 | // The address of this function is used to initialise the return address (RA) |
|---|
| 151 | // in all task contexts (when the task has never been executed. |
|---|
| 152 | /////////////////////////////////"///////////////////////////////////////////// |
|---|
| 153 | void boot_eret() |
|---|
| 154 | { |
|---|
| 155 | asm volatile ("eret"); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 159 | // boot_physical_read() |
|---|
| 160 | // This function makes a physical read access to a 32 bits word in memory, |
|---|
| 161 | // after a temporary DTLB de-activation and paddr extension. |
|---|
| 162 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 163 | unsigned int boot_physical_read(paddr_t paddr) |
|---|
| 164 | { |
|---|
| 165 | unsigned int value; |
|---|
| 166 | unsigned int lsb = (unsigned int) paddr; |
|---|
| 167 | unsigned int msb = (unsigned int) (paddr >> 32); |
|---|
| 168 | |
|---|
| 169 | asm volatile( |
|---|
| 170 | "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ |
|---|
| 171 | "andi $3, $2, 0xb \n" |
|---|
| 172 | "mtc2 $3, $1 \n" /* DTLB off */ |
|---|
| 173 | |
|---|
| 174 | "mtc2 %2, $24 \n" /* PADDR_EXT <= msb */ |
|---|
| 175 | "lw %0, 0(%1) \n" /* value <= *paddr */ |
|---|
| 176 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
|---|
| 177 | |
|---|
| 178 | "mtc2 $2, $1 \n" /* restore MMU_MODE */ |
|---|
| 179 | : "=r" (value) |
|---|
| 180 | : "r" (lsb), "r" (msb) |
|---|
| 181 | : "$2", "$3"); |
|---|
| 182 | return value; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 186 | // boot_physical_write() |
|---|
| 187 | // This function makes a physical write access to a 32 bits word in memory, |
|---|
| 188 | // after a temporary DTLB de-activation and paddr extension. |
|---|
| 189 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 190 | void boot_physical_write(paddr_t paddr, |
|---|
| 191 | unsigned int value) |
|---|
| 192 | { |
|---|
| 193 | unsigned int lsb = (unsigned int)paddr; |
|---|
| 194 | unsigned int msb = (unsigned int)(paddr >> 32); |
|---|
| 195 | |
|---|
| 196 | asm volatile( |
|---|
| 197 | "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ |
|---|
| 198 | "andi $3, $2, 0xb \n" |
|---|
| 199 | "mtc2 $3, $1 \n" /* DTLB off */ |
|---|
| 200 | |
|---|
| 201 | "mtc2 %2, $24 \n" /* PADDR_EXT <= msb */ |
|---|
| 202 | "sw %0, 0(%1) \n" /* *paddr <= value */ |
|---|
| 203 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
|---|
| 204 | |
|---|
| 205 | "mtc2 $2, $1 \n" /* restore MMU_MODE */ |
|---|
| 206 | : |
|---|
| 207 | : "r" (value), "r" (lsb), "r" (msb) |
|---|
| 208 | : "$2", "$3"); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 212 | // boot_set_mmu_ptpr() |
|---|
| 213 | // This function set a new value for the MMU PTPR register. |
|---|
| 214 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 215 | inline void boot_set_mmu_ptpr(unsigned int val) |
|---|
| 216 | { |
|---|
| 217 | asm volatile ("mtc2 %0, $0"::"r" (val)); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 221 | // boot_set_mmu_mode() |
|---|
| 222 | // This function set a new value for the MMU MODE register. |
|---|
| 223 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 224 | inline void boot_set_mmu_mode(unsigned int val) |
|---|
| 225 | { |
|---|
| 226 | asm volatile ("mtc2 %0, $1"::"r" (val)); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 230 | // boot_puts() |
|---|
| 231 | // display a string on TTY0 |
|---|
| 232 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 233 | void boot_puts(const char * buffer) |
|---|
| 234 | { |
|---|
| 235 | unsigned int *tty_address = (unsigned int *) &seg_tty_base; |
|---|
| 236 | unsigned int n; |
|---|
| 237 | |
|---|
| 238 | for (n = 0; n < 100; n++) |
|---|
| 239 | { |
|---|
| 240 | if (buffer[n] == 0) break; |
|---|
| 241 | tty_address[TTY_WRITE] = (unsigned int) buffer[n]; |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 246 | // boot_putx() |
|---|
| 247 | // display a 32 bits unsigned int as an hexadecimal string on TTY0 |
|---|
| 248 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 249 | void boot_putx(unsigned int val) |
|---|
| 250 | { |
|---|
| 251 | static const char HexaTab[] = "0123456789ABCDEF"; |
|---|
| 252 | char buf[11]; |
|---|
| 253 | unsigned int c; |
|---|
| 254 | |
|---|
| 255 | buf[0] = '0'; |
|---|
| 256 | buf[1] = 'x'; |
|---|
| 257 | buf[10] = 0; |
|---|
| 258 | |
|---|
| 259 | for (c = 0; c < 8; c++) |
|---|
| 260 | { |
|---|
| 261 | buf[9 - c] = HexaTab[val & 0xF]; |
|---|
| 262 | val = val >> 4; |
|---|
| 263 | } |
|---|
| 264 | boot_puts(buf); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 268 | // boot_putl() |
|---|
| 269 | // display a 64 bits unsigned long as an hexadecimal string on TTY0 |
|---|
| 270 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 271 | void boot_putl(paddr_t val) |
|---|
| 272 | { |
|---|
| 273 | static const char HexaTab[] = "0123456789ABCDEF"; |
|---|
| 274 | char buf[19]; |
|---|
| 275 | unsigned int c; |
|---|
| 276 | |
|---|
| 277 | buf[0] = '0'; |
|---|
| 278 | buf[1] = 'x'; |
|---|
| 279 | buf[18] = 0; |
|---|
| 280 | |
|---|
| 281 | for (c = 0; c < 16; c++) |
|---|
| 282 | { |
|---|
| 283 | buf[17 - c] = HexaTab[(unsigned int)val & 0xF]; |
|---|
| 284 | val = val >> 4; |
|---|
| 285 | } |
|---|
| 286 | boot_puts(buf); |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 290 | // boot_putd() |
|---|
| 291 | // display a 32 bits unsigned int as a decimal string on TTY0 |
|---|
| 292 | //////////////////////////////////////////////////////////////////////////// |
|---|
| 293 | void boot_putd(unsigned int val) |
|---|
| 294 | { |
|---|
| 295 | static const char DecTab[] = "0123456789"; |
|---|
| 296 | char buf[11]; |
|---|
| 297 | unsigned int i; |
|---|
| 298 | unsigned int first; |
|---|
| 299 | |
|---|
| 300 | buf[10] = 0; |
|---|
| 301 | |
|---|
| 302 | for (i = 0; i < 10; i++) |
|---|
| 303 | { |
|---|
| 304 | if ((val != 0) || (i == 0)) |
|---|
| 305 | { |
|---|
| 306 | buf[9 - i] = DecTab[val % 10]; |
|---|
| 307 | first = 9 - i; |
|---|
| 308 | } |
|---|
| 309 | else |
|---|
| 310 | { |
|---|
| 311 | break; |
|---|
| 312 | } |
|---|
| 313 | val /= 10; |
|---|
| 314 | } |
|---|
| 315 | boot_puts(&buf[first]); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 319 | // mapping_info data structure access functions |
|---|
| 320 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 321 | inline mapping_cluster_t *boot_get_cluster_base(mapping_header_t * header) |
|---|
| 322 | { |
|---|
| 323 | return (mapping_cluster_t *) ((char *) header + MAPPING_HEADER_SIZE); |
|---|
| 324 | } |
|---|
| 325 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 326 | inline mapping_pseg_t *boot_get_pseg_base(mapping_header_t * header) |
|---|
| 327 | { |
|---|
| 328 | return (mapping_pseg_t *) ((char *) header + |
|---|
| 329 | MAPPING_HEADER_SIZE + |
|---|
| 330 | MAPPING_CLUSTER_SIZE * header->clusters); |
|---|
| 331 | } |
|---|
| 332 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 333 | inline mapping_vspace_t *boot_get_vspace_base(mapping_header_t * header) |
|---|
| 334 | { |
|---|
| 335 | return (mapping_vspace_t *) ((char *) header + |
|---|
| 336 | MAPPING_HEADER_SIZE + |
|---|
| 337 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 338 | MAPPING_PSEG_SIZE * header->psegs); |
|---|
| 339 | } |
|---|
| 340 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 341 | inline mapping_vseg_t *boot_get_vseg_base(mapping_header_t * header) |
|---|
| 342 | { |
|---|
| 343 | return (mapping_vseg_t *) ((char *) header + |
|---|
| 344 | MAPPING_HEADER_SIZE + |
|---|
| 345 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 346 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 347 | MAPPING_VSPACE_SIZE * header->vspaces); |
|---|
| 348 | } |
|---|
| 349 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 350 | inline mapping_vobj_t *boot_get_vobj_base(mapping_header_t * header) |
|---|
| 351 | { |
|---|
| 352 | return (mapping_vobj_t *) ((char *) header + |
|---|
| 353 | MAPPING_HEADER_SIZE + |
|---|
| 354 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 355 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 356 | MAPPING_VSPACE_SIZE * header->vspaces + |
|---|
| 357 | MAPPING_VSEG_SIZE * header->vsegs); |
|---|
| 358 | } |
|---|
| 359 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 360 | inline mapping_task_t *boot_get_task_base(mapping_header_t * header) |
|---|
| 361 | { |
|---|
| 362 | return (mapping_task_t *) ((char *) header + |
|---|
| 363 | MAPPING_HEADER_SIZE + |
|---|
| 364 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 365 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 366 | MAPPING_VSPACE_SIZE * header->vspaces + |
|---|
| 367 | MAPPING_VSEG_SIZE * header->vsegs + |
|---|
| 368 | MAPPING_VOBJ_SIZE * header->vobjs); |
|---|
| 369 | } |
|---|
| 370 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 371 | inline mapping_proc_t *boot_get_proc_base(mapping_header_t * header) |
|---|
| 372 | { |
|---|
| 373 | return (mapping_proc_t *) ((char *) header + |
|---|
| 374 | MAPPING_HEADER_SIZE + |
|---|
| 375 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 376 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 377 | MAPPING_VSPACE_SIZE * header->vspaces + |
|---|
| 378 | MAPPING_VSEG_SIZE * header->vsegs + |
|---|
| 379 | MAPPING_VOBJ_SIZE * header->vobjs + |
|---|
| 380 | MAPPING_TASK_SIZE * header->tasks); |
|---|
| 381 | } |
|---|
| 382 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 383 | inline mapping_irq_t *boot_get_irq_base(mapping_header_t * header) |
|---|
| 384 | { |
|---|
| 385 | return (mapping_irq_t *) ((char *) header + |
|---|
| 386 | MAPPING_HEADER_SIZE + |
|---|
| 387 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 388 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 389 | MAPPING_VSPACE_SIZE * header->vspaces + |
|---|
| 390 | MAPPING_VSEG_SIZE * header->vsegs + |
|---|
| 391 | MAPPING_VOBJ_SIZE * header->vobjs + |
|---|
| 392 | MAPPING_TASK_SIZE * header->tasks + |
|---|
| 393 | MAPPING_PROC_SIZE * header->procs); |
|---|
| 394 | } |
|---|
| 395 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 396 | inline mapping_coproc_t *boot_get_coproc_base(mapping_header_t * header) |
|---|
| 397 | { |
|---|
| 398 | return (mapping_coproc_t *) ((char *) header + |
|---|
| 399 | MAPPING_HEADER_SIZE + |
|---|
| 400 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 401 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 402 | MAPPING_VSPACE_SIZE * header->vspaces + |
|---|
| 403 | MAPPING_VOBJ_SIZE * header->vobjs + |
|---|
| 404 | MAPPING_VSEG_SIZE * header->vsegs + |
|---|
| 405 | MAPPING_TASK_SIZE * header->tasks + |
|---|
| 406 | MAPPING_PROC_SIZE * header->procs + |
|---|
| 407 | MAPPING_IRQ_SIZE * header->irqs); |
|---|
| 408 | } |
|---|
| 409 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 410 | inline mapping_cp_port_t *boot_get_cp_port_base(mapping_header_t * header) |
|---|
| 411 | { |
|---|
| 412 | return (mapping_cp_port_t *) ((char *) header + |
|---|
| 413 | MAPPING_HEADER_SIZE + |
|---|
| 414 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 415 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 416 | MAPPING_VSPACE_SIZE * header->vspaces + |
|---|
| 417 | MAPPING_VOBJ_SIZE * header->vobjs + |
|---|
| 418 | MAPPING_VSEG_SIZE * header->vsegs + |
|---|
| 419 | MAPPING_TASK_SIZE * header->tasks + |
|---|
| 420 | MAPPING_PROC_SIZE * header->procs + |
|---|
| 421 | MAPPING_IRQ_SIZE * header->irqs + |
|---|
| 422 | MAPPING_COPROC_SIZE * header->coprocs); |
|---|
| 423 | } |
|---|
| 424 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 425 | inline mapping_periph_t *boot_get_periph_base(mapping_header_t * header) |
|---|
| 426 | { |
|---|
| 427 | return (mapping_periph_t *) ((char *) header + |
|---|
| 428 | MAPPING_HEADER_SIZE + |
|---|
| 429 | MAPPING_CLUSTER_SIZE * header->clusters + |
|---|
| 430 | MAPPING_PSEG_SIZE * header->psegs + |
|---|
| 431 | MAPPING_VSPACE_SIZE * header->vspaces + |
|---|
| 432 | MAPPING_VOBJ_SIZE * header->vobjs + |
|---|
| 433 | MAPPING_VSEG_SIZE * header->vsegs + |
|---|
| 434 | MAPPING_TASK_SIZE * header->tasks + |
|---|
| 435 | MAPPING_PROC_SIZE * header->procs + |
|---|
| 436 | MAPPING_IRQ_SIZE * header->irqs + |
|---|
| 437 | MAPPING_COPROC_SIZE * header->coprocs + |
|---|
| 438 | MAPPING_CP_PORT_SIZE * header->cp_ports); |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 442 | // boot_pseg_get() |
|---|
| 443 | // This function returns the pointer on a physical segment |
|---|
| 444 | // identified by the pseg index. |
|---|
| 445 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 446 | mapping_pseg_t *boot_pseg_get(unsigned int seg_id) |
|---|
| 447 | { |
|---|
| 448 | mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 449 | mapping_pseg_t * pseg = boot_get_pseg_base(header); |
|---|
| 450 | |
|---|
| 451 | // checking argument |
|---|
| 452 | if (seg_id >= header->psegs) |
|---|
| 453 | { |
|---|
| 454 | boot_puts("\n[BOOT ERROR] : seg_id argument too large\n"); |
|---|
| 455 | boot_puts(" in function boot_pseg_get()\n"); |
|---|
| 456 | boot_exit(); |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | return &pseg[seg_id]; |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 463 | // boot_add_pte() |
|---|
| 464 | // This function registers a new PTE in the page table defined |
|---|
| 465 | // by the vspace_id argument, and updates both PT1 and PT2. |
|---|
| 466 | // A new PT2 is used when required. |
|---|
| 467 | // As the set of PT2s is implemented as a fixed size array (no dynamic |
|---|
| 468 | // allocation), this function checks a possible overflow of the PT2 array. |
|---|
| 469 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 470 | void boot_add_pte(unsigned int vspace_id, |
|---|
| 471 | unsigned int vpn, |
|---|
| 472 | unsigned int flags, |
|---|
| 473 | unsigned int ppn, |
|---|
| 474 | unsigned int verbose) |
|---|
| 475 | { |
|---|
| 476 | unsigned int ix1; |
|---|
| 477 | unsigned int ix2; |
|---|
| 478 | paddr_t pt1_pbase; // PT1 physical base address |
|---|
| 479 | paddr_t pt2_pbase; // PT2 physical base address |
|---|
| 480 | paddr_t pte_paddr; // PTE physucal address |
|---|
| 481 | unsigned int pt2_id; // PT2 index |
|---|
| 482 | unsigned int ptd; // PTD : entry in PT1 |
|---|
| 483 | unsigned int max_pt2; // max number of PT2s for a given vspace |
|---|
| 484 | |
|---|
| 485 | ix1 = vpn >> 9; // 11 bits |
|---|
| 486 | ix2 = vpn & 0x1FF; // 9 bits |
|---|
| 487 | |
|---|
| 488 | // check that the boot_max_pt2[vspace_id] has been set |
|---|
| 489 | max_pt2 = boot_max_pt2[vspace_id]; |
|---|
| 490 | |
|---|
| 491 | if (max_pt2 == 0) |
|---|
| 492 | { |
|---|
| 493 | boot_puts("Undefined page table for vspace "); |
|---|
| 494 | boot_putd(vspace_id); |
|---|
| 495 | boot_puts("\n"); |
|---|
| 496 | boot_exit(); |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | // get page table physical base address |
|---|
| 501 | pt1_pbase = boot_ptabs_paddr[vspace_id]; |
|---|
| 502 | |
|---|
| 503 | // get ptd in PT1 |
|---|
| 504 | ptd = boot_physical_read(pt1_pbase + 4 * ix1); |
|---|
| 505 | |
|---|
| 506 | if ((ptd & PTE_V) == 0) // invalid PTD: compute PT2 base address, |
|---|
| 507 | // and set a new PTD in PT1 |
|---|
| 508 | { |
|---|
| 509 | pt2_id = boot_next_free_pt2[vspace_id]; |
|---|
| 510 | if (pt2_id == max_pt2) |
|---|
| 511 | { |
|---|
| 512 | boot_puts("\n[BOOT ERROR] in boot_add_pte() function\n"); |
|---|
| 513 | boot_puts("the length of the ptab vobj is too small\n"); |
|---|
| 514 | |
|---|
| 515 | boot_puts(" max_pt2 = "); |
|---|
| 516 | boot_putd( max_pt2 ); |
|---|
| 517 | boot_puts("\n"); |
|---|
| 518 | boot_puts(" pt2_id = "); |
|---|
| 519 | boot_putd( pt2_id ); |
|---|
| 520 | boot_puts("\n"); |
|---|
| 521 | |
|---|
| 522 | boot_exit(); |
|---|
| 523 | } |
|---|
| 524 | else |
|---|
| 525 | { |
|---|
| 526 | pt2_pbase = pt1_pbase + PT1_SIZE + PT2_SIZE * pt2_id; |
|---|
| 527 | ptd = PTE_V | PTE_T | (unsigned int) (pt2_pbase >> 12); |
|---|
| 528 | boot_physical_write( pt1_pbase + 4 * ix1, ptd); |
|---|
| 529 | boot_next_free_pt2[vspace_id] = pt2_id + 1; |
|---|
| 530 | } |
|---|
| 531 | } |
|---|
| 532 | else // valid PTD: compute PT2 base address |
|---|
| 533 | { |
|---|
| 534 | pt2_pbase = ((paddr_t)(ptd & 0x0FFFFFFF)) << 12; |
|---|
| 535 | } |
|---|
| 536 | |
|---|
| 537 | // set PTE in PT2 : flags & PPN in two 32 bits words |
|---|
| 538 | pte_paddr = pt2_pbase + 8 * ix2; |
|---|
| 539 | boot_physical_write(pte_paddr , flags); |
|---|
| 540 | boot_physical_write(pte_paddr + 4, ppn); |
|---|
| 541 | |
|---|
| 542 | if (verbose) |
|---|
| 543 | { |
|---|
| 544 | boot_puts(" / pt1_pbase = "); |
|---|
| 545 | boot_putl( pt1_pbase ); |
|---|
| 546 | boot_puts(" / ptd = "); |
|---|
| 547 | boot_putl( ptd ); |
|---|
| 548 | boot_puts(" / pt2_pbase = "); |
|---|
| 549 | boot_putl( pt2_pbase ); |
|---|
| 550 | boot_puts(" / pte_paddr = "); |
|---|
| 551 | boot_putl( pte_paddr ); |
|---|
| 552 | boot_puts(" / ppn = "); |
|---|
| 553 | boot_putx( ppn ); |
|---|
| 554 | boot_puts("/\n"); |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | } // end boot_add_pte() |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | ///////////////////////////////////////////////////////////////////// |
|---|
| 561 | // This function builds the page table for a given vspace. |
|---|
| 562 | // The physical base addresses for all vsegs (global and private) |
|---|
| 563 | // must have been previously computed and stored in the mapping. |
|---|
| 564 | // It initializes the MWMR channels. |
|---|
| 565 | ///////////////////////////////////////////////////////////////////// |
|---|
| 566 | void boot_vspace_pt_build(unsigned int vspace_id) |
|---|
| 567 | { |
|---|
| 568 | unsigned int vseg_id; |
|---|
| 569 | unsigned int npages; |
|---|
| 570 | unsigned int ppn; |
|---|
| 571 | unsigned int vpn; |
|---|
| 572 | unsigned int flags; |
|---|
| 573 | unsigned int page_id; |
|---|
| 574 | unsigned int verbose = 0; // can be used to activate trace in add_pte() |
|---|
| 575 | |
|---|
| 576 | mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 577 | mapping_vspace_t * vspace = boot_get_vspace_base(header); |
|---|
| 578 | mapping_vseg_t * vseg = boot_get_vseg_base(header); |
|---|
| 579 | |
|---|
| 580 | // private segments |
|---|
| 581 | for (vseg_id = vspace[vspace_id].vseg_offset; |
|---|
| 582 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
|---|
| 583 | vseg_id++) |
|---|
| 584 | { |
|---|
| 585 | vpn = vseg[vseg_id].vbase >> 12; |
|---|
| 586 | ppn = (unsigned int) (vseg[vseg_id].pbase >> 12); |
|---|
| 587 | |
|---|
| 588 | npages = vseg[vseg_id].length >> 12; |
|---|
| 589 | if ((vseg[vseg_id].length & 0xFFF) != 0) npages++; |
|---|
| 590 | |
|---|
| 591 | flags = PTE_V; |
|---|
| 592 | if (vseg[vseg_id].mode & C_MODE_MASK) flags = flags | PTE_C; |
|---|
| 593 | if (vseg[vseg_id].mode & X_MODE_MASK) flags = flags | PTE_X; |
|---|
| 594 | if (vseg[vseg_id].mode & W_MODE_MASK) flags = flags | PTE_W; |
|---|
| 595 | if (vseg[vseg_id].mode & U_MODE_MASK) flags = flags | PTE_U; |
|---|
| 596 | |
|---|
| 597 | #if BOOT_DEBUG_PT |
|---|
| 598 | boot_puts(vseg[vseg_id].name); |
|---|
| 599 | boot_puts(" : flags = "); |
|---|
| 600 | boot_putx(flags); |
|---|
| 601 | boot_puts(" / npages = "); |
|---|
| 602 | boot_putd(npages); |
|---|
| 603 | boot_puts(" / vbase = "); |
|---|
| 604 | boot_putx(vseg[vseg_id].vbase); |
|---|
| 605 | boot_puts(" / pbase = "); |
|---|
| 606 | boot_putl(vseg[vseg_id].pbase); |
|---|
| 607 | boot_puts("\n"); |
|---|
| 608 | #endif |
|---|
| 609 | // loop on 4K pages |
|---|
| 610 | for (page_id = 0; page_id < npages; page_id++) |
|---|
| 611 | { |
|---|
| 612 | boot_add_pte(vspace_id, vpn, flags, ppn, verbose); |
|---|
| 613 | vpn++; |
|---|
| 614 | ppn++; |
|---|
| 615 | } |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | // global segments |
|---|
| 619 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
|---|
| 620 | { |
|---|
| 621 | vpn = vseg[vseg_id].vbase >> 12; |
|---|
| 622 | ppn = (unsigned int) (vseg[vseg_id].pbase >> 12); |
|---|
| 623 | npages = vseg[vseg_id].length >> 12; |
|---|
| 624 | if ((vseg[vseg_id].length & 0xFFF) != 0) npages++; |
|---|
| 625 | |
|---|
| 626 | flags = PTE_V; |
|---|
| 627 | if (vseg[vseg_id].mode & C_MODE_MASK) flags = flags | PTE_C; |
|---|
| 628 | if (vseg[vseg_id].mode & X_MODE_MASK) flags = flags | PTE_X; |
|---|
| 629 | if (vseg[vseg_id].mode & W_MODE_MASK) flags = flags | PTE_W; |
|---|
| 630 | if (vseg[vseg_id].mode & U_MODE_MASK) flags = flags | PTE_U; |
|---|
| 631 | |
|---|
| 632 | #if BOOT_DEBUG_PT |
|---|
| 633 | boot_puts(vseg[vseg_id].name); |
|---|
| 634 | boot_puts(" : flags = "); |
|---|
| 635 | boot_putx(flags); |
|---|
| 636 | boot_puts(" / npages = "); |
|---|
| 637 | boot_putd(npages); |
|---|
| 638 | boot_puts(" / vbase = "); |
|---|
| 639 | boot_putx(vseg[vseg_id].vbase); |
|---|
| 640 | boot_puts(" / pbase = "); |
|---|
| 641 | boot_putl(vseg[vseg_id].pbase); |
|---|
| 642 | boot_puts("\n"); |
|---|
| 643 | #endif |
|---|
| 644 | // loop on 4K pages |
|---|
| 645 | for (page_id = 0; page_id < npages; page_id++) |
|---|
| 646 | { |
|---|
| 647 | boot_add_pte(vspace_id, vpn, flags, ppn, verbose); |
|---|
| 648 | vpn++; |
|---|
| 649 | ppn++; |
|---|
| 650 | } |
|---|
| 651 | } |
|---|
| 652 | } // end boot_vspace_pt_build() |
|---|
| 653 | |
|---|
| 654 | |
|---|
| 655 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 656 | // Aligns the value of paddr or vaddr to the required alignement, |
|---|
| 657 | // defined by alignPow2 == L2(alignement). |
|---|
| 658 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 659 | paddr_t paddr_align_to(paddr_t paddr, unsigned int alignPow2) |
|---|
| 660 | { |
|---|
| 661 | paddr_t mask = (1 << alignPow2) - 1; |
|---|
| 662 | return ((paddr + mask) & ~mask); |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | unsigned int vaddr_align_to(unsigned int vaddr, unsigned int alignPow2) |
|---|
| 666 | { |
|---|
| 667 | unsigned int mask = (1 << alignPow2) - 1; |
|---|
| 668 | return ((vaddr + mask) & ~mask); |
|---|
| 669 | } |
|---|
| 670 | |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | /////////////////////////////////////////////////////////// |
|---|
| 674 | // Maps vseg on a pbase with identity mapping required |
|---|
| 675 | // The pseg is already set |
|---|
| 676 | // The length of the vseg must already be known |
|---|
| 677 | /////////////////////////////////////////////////////////// |
|---|
| 678 | void boot_vseg_set_paddr_ident(mapping_vseg_t * vseg) { |
|---|
| 679 | unsigned int vseg_id; |
|---|
| 680 | |
|---|
| 681 | mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 682 | mapping_vseg_t * vseg_base = boot_get_vseg_base(header); |
|---|
| 683 | |
|---|
| 684 | if (vseg->pbase_set != 0) { |
|---|
| 685 | boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function (internal error):\n"); |
|---|
| 686 | boot_puts("*** vseg->pbase already set\n"); |
|---|
| 687 | boot_exit(); |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { |
|---|
| 691 | // Already mapped vseg on the same pseg |
|---|
| 692 | if (vseg_base[vseg_id].psegid == vseg->psegid && vseg_base[vseg_id].pbase_set == 1) { |
|---|
| 693 | // Checking overlap condition |
|---|
| 694 | if (vseg->vbase == vseg_base[vseg_id].pbase || |
|---|
| 695 | ((vseg->vbase < vseg_base[vseg_id].pbase) && (vseg->vbase + vseg->length > vseg_base[vseg_id].pbase)) || |
|---|
| 696 | ((vseg->vbase > vseg_base[vseg_id].pbase) && (vseg_base[vseg_id].pbase + vseg_base[vseg_id].length > vseg->vbase))) { |
|---|
| 697 | boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr_ident() function\n"); |
|---|
| 698 | boot_puts("*** Overlapping segments:\n"); |
|---|
| 699 | boot_puts(" seg with base = "); |
|---|
| 700 | boot_putl(vseg->vbase); |
|---|
| 701 | boot_puts(" - length = "); |
|---|
| 702 | boot_putl(vseg->length); |
|---|
| 703 | boot_puts("\n"); |
|---|
| 704 | boot_puts(" seg with base = \n"); |
|---|
| 705 | boot_putl(vseg_base[vseg_id].vbase); |
|---|
| 706 | boot_puts(" - length = "); |
|---|
| 707 | boot_putl(vseg_base[vseg_id].length); |
|---|
| 708 | boot_puts("\n"); |
|---|
| 709 | boot_exit(); |
|---|
| 710 | } |
|---|
| 711 | } |
|---|
| 712 | } |
|---|
| 713 | vseg->pbase = vseg->vbase; |
|---|
| 714 | vseg->pbase_set = 1; |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | /////////////////////////////////////////////////////////// |
|---|
| 720 | // Maps vseg on a pbase with no identity mapping required |
|---|
| 721 | // The pseg is already set |
|---|
| 722 | // The length of the vseg must already be known |
|---|
| 723 | /////////////////////////////////////////////////////////// |
|---|
| 724 | void boot_vseg_set_paddr(mapping_vseg_t * vseg) { |
|---|
| 725 | unsigned int vseg_id; |
|---|
| 726 | unsigned int nb_vsegs_mapped = 0; |
|---|
| 727 | unsigned int mapped = 0; |
|---|
| 728 | int i = 0; |
|---|
| 729 | |
|---|
| 730 | paddr_t prev_base; |
|---|
| 731 | paddr_t prev_length = 0; |
|---|
| 732 | paddr_t curr_base = 0; |
|---|
| 733 | paddr_t curr_length = 0; |
|---|
| 734 | paddr_t next_base = 0; |
|---|
| 735 | paddr_t next_length = 0; |
|---|
| 736 | |
|---|
| 737 | mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 738 | mapping_vseg_t * vseg_base = boot_get_vseg_base(header); |
|---|
| 739 | mapping_vobj_t * vobj_base = boot_get_vobj_base(header); |
|---|
| 740 | mapping_pseg_t * pseg = boot_pseg_get(vseg->psegid); |
|---|
| 741 | |
|---|
| 742 | const int align = max(vobj_base[vseg->vobj_offset].align, 12); |
|---|
| 743 | |
|---|
| 744 | prev_base = pseg->base; |
|---|
| 745 | |
|---|
| 746 | if (vseg->pbase_set != 0) { |
|---|
| 747 | boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function (internal error):\n"); |
|---|
| 748 | boot_puts("*** vseg->pbase already set\n"); |
|---|
| 749 | boot_exit(); |
|---|
| 750 | } |
|---|
| 751 | |
|---|
| 752 | // We now determinine the physical base address of the vseg |
|---|
| 753 | // Method: |
|---|
| 754 | // Now that all identity segments have been mapped |
|---|
| 755 | // We are free to place the vseg where we want |
|---|
| 756 | // From a logical point of view, we have the list of mapped vsegs ordered by their pbase (increasing) |
|---|
| 757 | // We try to place the vseg between two consecutive elements of this list |
|---|
| 758 | // If this fails, we try between the next two mapped vsegs |
|---|
| 759 | |
|---|
| 760 | // Counting the number of vsegs mapped on this pseg |
|---|
| 761 | // We also initialize curr_base and curr_length with some values |
|---|
| 762 | for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { |
|---|
| 763 | if (vseg_base[vseg_id].psegid == vseg->psegid && vseg_base[vseg_id].pbase_set == 1) { |
|---|
| 764 | nb_vsegs_mapped++; |
|---|
| 765 | curr_base = vseg_base[vseg_id].pbase; |
|---|
| 766 | curr_length = vseg_base[vseg_id].length; |
|---|
| 767 | } |
|---|
| 768 | } |
|---|
| 769 | |
|---|
| 770 | if (nb_vsegs_mapped == 0) { |
|---|
| 771 | if (vseg->length <= pseg->length) { |
|---|
| 772 | vseg->pbase = pseg->base; |
|---|
| 773 | vseg->pbase_set = 1; |
|---|
| 774 | return; |
|---|
| 775 | } |
|---|
| 776 | else { |
|---|
| 777 | boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function\n"); |
|---|
| 778 | boot_puts("*** PSEG is too small for mapping vseg (base:"); |
|---|
| 779 | boot_putl(vseg->vbase); |
|---|
| 780 | boot_puts(" - length: "); |
|---|
| 781 | boot_putl(vseg->length); |
|---|
| 782 | boot_puts(")\n"); |
|---|
| 783 | boot_exit(); |
|---|
| 784 | } |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | // We look for the vseg mapped on the same pseg having the smallest vaddr |
|---|
| 788 | for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { |
|---|
| 789 | if (vseg_base[vseg_id].psegid == vseg->psegid |
|---|
| 790 | && &vseg_base[vseg_id] != vseg |
|---|
| 791 | && vseg_base[vseg_id].pbase_set == 1 |
|---|
| 792 | && vseg_base[vseg_id].pbase < curr_base) { |
|---|
| 793 | curr_base = vseg_base[vseg_id].pbase; |
|---|
| 794 | curr_length = vseg_base[vseg_id].length; |
|---|
| 795 | } |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | // We iterate on each vseg mapped in the order of their growing pbase |
|---|
| 799 | // and try to insert the current vseg right after each |
|---|
| 800 | while (i < nb_vsegs_mapped) { |
|---|
| 801 | if (paddr_align_to(prev_base + prev_length, align) + vseg->length <= curr_base) { |
|---|
| 802 | vseg->pbase = paddr_align_to(prev_base + prev_length, align); |
|---|
| 803 | vseg->pbase_set = 1; |
|---|
| 804 | mapped = 1; |
|---|
| 805 | break; |
|---|
| 806 | } |
|---|
| 807 | else if (i < nb_vsegs_mapped - 1) { |
|---|
| 808 | int found = 0; |
|---|
| 809 | next_base = 0; |
|---|
| 810 | // We search for the vseg having the minimal pbase which is more than the pbase of the current vseg |
|---|
| 811 | for (vseg_id = 0; vseg_id < header->vsegs; vseg_id++) { |
|---|
| 812 | if (vseg_base[vseg_id].psegid == vseg->psegid |
|---|
| 813 | && &vseg_base[vseg_id] != vseg |
|---|
| 814 | && vseg_base[vseg_id].pbase_set == 1 |
|---|
| 815 | && (vseg_base[vseg_id].pbase < next_base || !found) |
|---|
| 816 | && vseg_base[vseg_id].pbase > curr_base) { |
|---|
| 817 | found = 1; |
|---|
| 818 | next_base = vseg_base[vseg_id].pbase; |
|---|
| 819 | next_length = vseg_base[vseg_id].length; |
|---|
| 820 | } |
|---|
| 821 | } |
|---|
| 822 | if (!found) { |
|---|
| 823 | boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function (internal error):\n"); |
|---|
| 824 | boot_puts("*** Next vseg not found\n"); |
|---|
| 825 | boot_exit(); |
|---|
| 826 | } |
|---|
| 827 | |
|---|
| 828 | prev_base = curr_base; |
|---|
| 829 | prev_length = curr_length; |
|---|
| 830 | |
|---|
| 831 | curr_base = next_base; |
|---|
| 832 | curr_length = next_length; |
|---|
| 833 | } |
|---|
| 834 | else { |
|---|
| 835 | // The current vseg is the last one (highest mapped paddr on this pseg) |
|---|
| 836 | // We try to insert the current vseg after it |
|---|
| 837 | if (paddr_align_to(curr_base + curr_length, align) + vseg->length <= pseg->base + pseg->length) { |
|---|
| 838 | vseg->pbase = paddr_align_to(curr_base + curr_length, align); |
|---|
| 839 | vseg->pbase_set = 1; |
|---|
| 840 | mapped = 1; |
|---|
| 841 | } |
|---|
| 842 | } |
|---|
| 843 | i++; |
|---|
| 844 | } |
|---|
| 845 | |
|---|
| 846 | if (!mapped) { |
|---|
| 847 | boot_puts("\n[BOOT ERROR] in boot_vseg_set_paddr() function:\n"); |
|---|
| 848 | boot_puts("*** Not enough space to map vseg (base: "); |
|---|
| 849 | boot_putl(vseg->vbase); |
|---|
| 850 | boot_puts(" - length: "); |
|---|
| 851 | boot_putl(vseg->length); |
|---|
| 852 | boot_puts(")\n"); |
|---|
| 853 | boot_exit(); |
|---|
| 854 | } |
|---|
| 855 | } |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 859 | // This function computes the physical base address for a vseg |
|---|
| 860 | // as specified in the mapping info data structure. |
|---|
| 861 | // It updates the pbase and the length fields of the vseg. |
|---|
| 862 | // It updates the pbase and vbase fields of all vobjs in the vseg. |
|---|
| 863 | // It updates the boot_ptabs_paddr[] and boot_ptabs_vaddr[] arrays. |
|---|
| 864 | // It is a global vseg if vspace_id = (-1). |
|---|
| 865 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 866 | void boot_vseg_map(mapping_vseg_t * vseg, unsigned int vspace_id) |
|---|
| 867 | { |
|---|
| 868 | unsigned int vobj_id; |
|---|
| 869 | unsigned int cur_vaddr; |
|---|
| 870 | paddr_t cur_paddr; |
|---|
| 871 | paddr_t cur_length; |
|---|
| 872 | unsigned int offset; |
|---|
| 873 | |
|---|
| 874 | mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 875 | mapping_vobj_t * vobj = boot_get_vobj_base(header); |
|---|
| 876 | |
|---|
| 877 | // We make a first loop on the vobj of the vseg to determine the real length of the vseg |
|---|
| 878 | // This length is required to determine the pbase of the vseg |
|---|
| 879 | cur_length = 0; |
|---|
| 880 | for (vobj_id = vseg->vobj_offset; vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) { |
|---|
| 881 | if (vobj[vobj_id].align) { |
|---|
| 882 | cur_length = vaddr_align_to(cur_length, vobj[vobj_id].align); |
|---|
| 883 | } |
|---|
| 884 | cur_length += vobj[vobj_id].length; |
|---|
| 885 | } |
|---|
| 886 | vseg->length = paddr_align_to(cur_length, 12); |
|---|
| 887 | |
|---|
| 888 | // We can now compute the vseg physical base address |
|---|
| 889 | if (vseg->ident != 0) { |
|---|
| 890 | // identity mapping required |
|---|
| 891 | boot_vseg_set_paddr_ident(vseg); |
|---|
| 892 | } |
|---|
| 893 | else { |
|---|
| 894 | // unconstrained mapping |
|---|
| 895 | boot_vseg_set_paddr(vseg); |
|---|
| 896 | } |
|---|
| 897 | |
|---|
| 898 | |
|---|
| 899 | // loop on vobjs contained in vseg to : |
|---|
| 900 | // (1) computes the length of the vseg, |
|---|
| 901 | // (2) initialize the vaddr and paddr fields of all vobjs, |
|---|
| 902 | // (3) initialize the page table pointers arrays |
|---|
| 903 | |
|---|
| 904 | cur_vaddr = vseg->vbase; |
|---|
| 905 | cur_paddr = vseg->pbase; |
|---|
| 906 | |
|---|
| 907 | for (vobj_id = vseg->vobj_offset; |
|---|
| 908 | vobj_id < (vseg->vobj_offset + vseg->vobjs); vobj_id++) { |
|---|
| 909 | if (vobj[vobj_id].align) { |
|---|
| 910 | cur_paddr = paddr_align_to(cur_paddr, vobj[vobj_id].align); |
|---|
| 911 | cur_vaddr = vaddr_align_to(cur_vaddr, vobj[vobj_id].align); |
|---|
| 912 | } |
|---|
| 913 | // set vaddr/paddr for current vobj |
|---|
| 914 | vobj[vobj_id].vaddr = cur_vaddr; |
|---|
| 915 | vobj[vobj_id].paddr = cur_paddr; |
|---|
| 916 | |
|---|
| 917 | // initialize boot_ptabs_vaddr[] & boot_ptabs-paddr[] if PTAB |
|---|
| 918 | if (vobj[vobj_id].type == VOBJ_TYPE_PTAB) |
|---|
| 919 | { |
|---|
| 920 | if (vspace_id == ((unsigned int) -1)) // global vseg |
|---|
| 921 | { |
|---|
| 922 | boot_puts("\n[BOOT ERROR] in boot_vseg_map() function: "); |
|---|
| 923 | boot_puts("a PTAB vobj cannot be global"); |
|---|
| 924 | boot_exit(); |
|---|
| 925 | } |
|---|
| 926 | // we need at least one PT2 |
|---|
| 927 | if (vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE)) |
|---|
| 928 | { |
|---|
| 929 | boot_puts("\n[BOOT ERROR] in boot_vseg_map() function, "); |
|---|
| 930 | boot_puts("PTAB too small, minumum size is: "); |
|---|
| 931 | boot_putx(PT1_SIZE + PT2_SIZE); |
|---|
| 932 | boot_exit(); |
|---|
| 933 | } |
|---|
| 934 | // register both physical and virtual page table address |
|---|
| 935 | boot_ptabs_vaddr[vspace_id] = vobj[vobj_id].vaddr; |
|---|
| 936 | boot_ptabs_paddr[vspace_id] = vobj[vobj_id].paddr; |
|---|
| 937 | |
|---|
| 938 | // reset all valid bits in PT1 |
|---|
| 939 | for (offset = 0; offset < 8192; offset = offset + 4) |
|---|
| 940 | { |
|---|
| 941 | boot_physical_write(cur_paddr + offset, 0); |
|---|
| 942 | } |
|---|
| 943 | |
|---|
| 944 | // computing the number of second level pages |
|---|
| 945 | boot_max_pt2[vspace_id] = (vobj[vobj_id].length - PT1_SIZE) / PT2_SIZE; |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | // set next vaddr/paddr |
|---|
| 949 | cur_vaddr = cur_vaddr + vobj[vobj_id].length; |
|---|
| 950 | cur_paddr = cur_paddr + vobj[vobj_id].length; |
|---|
| 951 | } // end for vobjs |
|---|
| 952 | |
|---|
| 953 | #if BOOT_DEBUG_PT |
|---|
| 954 | boot_puts(vseg->name); |
|---|
| 955 | boot_puts(" : len = "); |
|---|
| 956 | boot_putx(vseg->length); |
|---|
| 957 | boot_puts(" / vbase = "); |
|---|
| 958 | boot_putx(vseg->vbase); |
|---|
| 959 | boot_puts(" / pbase = "); |
|---|
| 960 | boot_putl(vseg->pbase); |
|---|
| 961 | boot_puts("\n"); |
|---|
| 962 | #endif |
|---|
| 963 | |
|---|
| 964 | } // end boot_vseg_map() |
|---|
| 965 | |
|---|
| 966 | ///////////////////////////////////////////////////////////////////// |
|---|
| 967 | // This function checks consistence beween the mapping_info data |
|---|
| 968 | // structure (soft), and the giet_config file (hard). |
|---|
| 969 | ///////////////////////////////////////////////////////////////////// |
|---|
| 970 | void boot_check_mapping() |
|---|
| 971 | { |
|---|
| 972 | mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 973 | |
|---|
| 974 | // checking mapping availability |
|---|
| 975 | if (header->signature != IN_MAPPING_SIGNATURE) |
|---|
| 976 | { |
|---|
| 977 | boot_puts("\n[BOOT ERROR] Illegal mapping signature: "); |
|---|
| 978 | boot_putx(header->signature); |
|---|
| 979 | boot_puts("\n"); |
|---|
| 980 | boot_exit(); |
|---|
| 981 | } |
|---|
| 982 | // checking number of clusters |
|---|
| 983 | if (header->clusters != NB_CLUSTERS) |
|---|
| 984 | { |
|---|
| 985 | boot_puts("\n[BOOT ERROR] Incoherent NB_CLUSTERS"); |
|---|
| 986 | boot_puts("\n - In giet_config, value = "); |
|---|
| 987 | boot_putd(NB_CLUSTERS); |
|---|
| 988 | boot_puts("\n - In mapping_info, value = "); |
|---|
| 989 | boot_putd(header->clusters); |
|---|
| 990 | boot_puts("\n"); |
|---|
| 991 | boot_exit(); |
|---|
| 992 | } |
|---|
| 993 | // checking number of virtual spaces |
|---|
| 994 | if (header->vspaces > GIET_NB_VSPACE_MAX) |
|---|
| 995 | { |
|---|
| 996 | boot_puts("\n[BOOT ERROR] : number of vspaces > GIET_NB_VSPACE_MAX\n"); |
|---|
| 997 | boot_puts("\n"); |
|---|
| 998 | boot_exit(); |
|---|
| 999 | } |
|---|
| 1000 | |
|---|
| 1001 | #if BOOT_DEBUG_MAPPING |
|---|
| 1002 | boot_puts("\nclusters = "); |
|---|
| 1003 | boot_putd( header->clusters ); |
|---|
| 1004 | boot_puts("\nprocs = "); |
|---|
| 1005 | boot_putd( header->procs ); |
|---|
| 1006 | boot_puts("\nperiphs = "); |
|---|
| 1007 | boot_putd( header->periphs ); |
|---|
| 1008 | boot_puts("\nvspaces = "); |
|---|
| 1009 | boot_putd( header->vspaces ); |
|---|
| 1010 | boot_puts("\ntasks = "); |
|---|
| 1011 | boot_putd( header->tasks ); |
|---|
| 1012 | boot_puts("\n"); |
|---|
| 1013 | |
|---|
| 1014 | unsigned int cluster_id; |
|---|
| 1015 | mapping_cluster_t * cluster = boot_get_cluster_base(header); |
|---|
| 1016 | for (cluster_id = 0; cluster_id < NB_CLUSTERS; cluster_id++) |
|---|
| 1017 | { |
|---|
| 1018 | boot_puts("\n cluster = "); |
|---|
| 1019 | boot_putd( cluster_id ); |
|---|
| 1020 | boot_puts("\n procs = "); |
|---|
| 1021 | boot_putd( cluster[cluster_id].procs ); |
|---|
| 1022 | boot_puts("\n psegs = "); |
|---|
| 1023 | boot_putd( cluster[cluster_id].psegs ); |
|---|
| 1024 | boot_puts("\n periphs = "); |
|---|
| 1025 | boot_putd( cluster[cluster_id].periphs ); |
|---|
| 1026 | boot_puts("\n"); |
|---|
| 1027 | } |
|---|
| 1028 | #endif |
|---|
| 1029 | |
|---|
| 1030 | boot_puts("\n[BOOT] Mapping check completed at cycle "); |
|---|
| 1031 | boot_putd(boot_proctime()); |
|---|
| 1032 | boot_puts(" for "); |
|---|
| 1033 | boot_puts( header->name ); |
|---|
| 1034 | boot_puts("\n"); |
|---|
| 1035 | |
|---|
| 1036 | } // end boot_check_mapping() |
|---|
| 1037 | |
|---|
| 1038 | |
|---|
| 1039 | ///////////////////////////////////////////////////////////////////// |
|---|
| 1040 | // This function builds the page tables for all virtual spaces |
|---|
| 1041 | // defined in the mapping_info data structure, in three steps: |
|---|
| 1042 | // - step 1 : It computes the physical base address for global vsegs |
|---|
| 1043 | // and for all associated vobjs. |
|---|
| 1044 | // - step 2 : It computes the physical base address for all private |
|---|
| 1045 | // vsegs and all vobjs in each virtual space. |
|---|
| 1046 | // - step 3 : It actually fill the page table for each vspace. |
|---|
| 1047 | ///////////////////////////////////////////////////////////////////// |
|---|
| 1048 | void boot_pt_init() |
|---|
| 1049 | { |
|---|
| 1050 | mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; |
|---|
| 1051 | mapping_vspace_t * vspace = boot_get_vspace_base(header); |
|---|
| 1052 | mapping_vseg_t * vseg = boot_get_vseg_base(header); |
|---|
| 1053 | |
|---|
| 1054 | unsigned int vspace_id; |
|---|
| 1055 | unsigned int vseg_id; |
|---|
| 1056 | |
|---|
| 1057 | #if BOOT_DEBUG_PT |
|---|
| 1058 | boot_puts("\n[BOOT DEBUG] ****** mapping global vsegs ******\n"); |
|---|
| 1059 | #endif |
|---|
| 1060 | |
|---|
| 1061 | // step 1 : loop on virtual spaces to map global vsegs |
|---|
| 1062 | // Identity vseg first |
|---|
| 1063 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
|---|
| 1064 | { |
|---|
| 1065 | if (vseg[vseg_id].ident == 1) { |
|---|
| 1066 | boot_vseg_map(&vseg[vseg_id], ((unsigned int) (-1))); |
|---|
| 1067 | } |
|---|
| 1068 | } |
|---|
| 1069 | // Non identity vseg second |
|---|
| 1070 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
|---|
| 1071 | { |
|---|
| 1072 | if (vseg[vseg_id].ident == 0) { |
|---|
| 1073 | boot_vseg_map(&vseg[vseg_id], ((unsigned int) (-1))); |
|---|
| 1074 | } |
|---|
| 1075 | } |
|---|
| 1076 | |
|---|
| 1077 | |
|---|
| 1078 | // step 2 : loop on virtual vspaces to map private vsegs |
|---|
| 1079 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
|---|
| 1080 | { |
|---|
| 1081 | |
|---|
| 1082 | #if BOOT_DEBUG_PT |
|---|
| 1083 | boot_puts("\n[BOOT DEBUG] ****** mapping private vsegs in vspace "); |
|---|
| 1084 | boot_puts(vspace[vspace_id].name); |
|---|
| 1085 | boot_puts(" ******\n"); |
|---|
| 1086 | #endif |
|---|
| 1087 | |
|---|
| 1088 | // Identity vseg first |
|---|
| 1089 | for (vseg_id = vspace[vspace_id].vseg_offset; |
|---|
| 1090 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
|---|
| 1091 | vseg_id++) { |
|---|
| 1092 | if (vseg[vseg_id].ident == 1) { |
|---|
| 1093 | boot_vseg_map(&vseg[vseg_id], vspace_id); |
|---|
| 1094 | } |
|---|
| 1095 | } |
|---|
| 1096 | // Non identity vseg second |
|---|
| 1097 | for (vseg_id = vspace[vspace_id].vseg_offset; |
|---|
| 1098 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
|---|
| 1099 | vseg_id++) { |
|---|
| 1100 | if (vseg[vseg_id].ident == 0) { |
|---|
| 1101 | boot_vseg_map(&vseg[vseg_id], vspace_id); |
|---|
| 1102 | } |
|---|
| 1103 | } |
|---|
| 1104 | } |
|---|
| 1105 | |
|---|
| 1106 | // step 3 : loop on the vspaces to build the page tables |
|---|
| 1107 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
|---|
| 1108 | { |
|---|
| 1109 | #if BOOT_DEBUG_PT |
|---|
| 1110 | boot_puts("\n[BOOT DEBUG] ****** building page table for vspace "); |
|---|
| 1111 | boot_puts(vspace[vspace_id].name); |
|---|
| 1112 | boot_puts(" ******\n"); |
|---|
| 1113 | #endif |
|---|
| 1114 | |
|---|
| 1115 | boot_vspace_pt_build(vspace_id); |
|---|
| 1116 | |
|---|
| 1117 | #if BOOT_DEBUG_PT |
|---|
| 1118 | boot_puts("\n>>> page table physical address = "); |
|---|
| 1119 | boot_putl(boot_ptabs_paddr[vspace_id]); |
|---|
| 1120 | boot_puts(", number of PT2 = "); |
|---|
| 1121 | boot_putd((unsigned int) boot_max_pt2[vspace_id]); |
|---|
| 1122 | boot_puts("\n"); |
|---|
| 1123 | #endif |
|---|
| 1124 | } |
|---|
| 1125 | |
|---|
| 1126 | boot_puts("\n[BOOT] Page Tables initialization completed at cycle "); |
|---|
| 1127 | boot_putd(boot_proctime()); |
|---|
| 1128 | boot_puts("\n"); |
|---|
| 1129 | |
|---|
| 1130 | } // end boot_pt_init() |
|---|
| 1131 | |
|---|
| 1132 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 1133 | // This function initializes all private vobjs defined in the vspaces, |
|---|
| 1134 | // such as mwmr channels, barriers and locks, because these vobjs |
|---|
| 1135 | // are not known, and not initialized by the compiler. |
|---|
| 1136 | // Warning : The MMU is supposed to be activated... |
|---|
| 1137 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 1138 | void boot_vobjs_init() |
|---|
| 1139 | { |
|---|
| 1140 | mapping_header_t* header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 1141 | mapping_vspace_t* vspace = boot_get_vspace_base(header); |
|---|
| 1142 | mapping_vobj_t* vobj = boot_get_vobj_base(header); |
|---|
| 1143 | |
|---|
| 1144 | unsigned int vspace_id; |
|---|
| 1145 | unsigned int vobj_id; |
|---|
| 1146 | |
|---|
| 1147 | // loop on the vspaces |
|---|
| 1148 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
|---|
| 1149 | { |
|---|
| 1150 | boot_set_mmu_ptpr((unsigned int) (boot_ptabs_paddr[vspace_id] >> 13)); |
|---|
| 1151 | |
|---|
| 1152 | #if BOOT_DEBUG_VOBJS |
|---|
| 1153 | boot_puts("\n[BOOT DEBUG] ****** vobjs initialisation in vspace "); |
|---|
| 1154 | boot_puts(vspace[vspace_id].name); |
|---|
| 1155 | boot_puts(" ******\n"); |
|---|
| 1156 | #endif |
|---|
| 1157 | |
|---|
| 1158 | unsigned int ptab_found = 0; |
|---|
| 1159 | |
|---|
| 1160 | // loop on the vobjs |
|---|
| 1161 | for (vobj_id = vspace[vspace_id].vobj_offset; |
|---|
| 1162 | vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); |
|---|
| 1163 | vobj_id++) |
|---|
| 1164 | { |
|---|
| 1165 | switch (vobj[vobj_id].type) |
|---|
| 1166 | { |
|---|
| 1167 | case VOBJ_TYPE_MWMR: // storage capacity is (vobj.length/4 - 5) words |
|---|
| 1168 | { |
|---|
| 1169 | mwmr_channel_t* mwmr = (mwmr_channel_t *) (vobj[vobj_id].vaddr); |
|---|
| 1170 | mwmr->ptw = 0; |
|---|
| 1171 | mwmr->ptr = 0; |
|---|
| 1172 | mwmr->sts = 0; |
|---|
| 1173 | mwmr->width = vobj[vobj_id].init; |
|---|
| 1174 | mwmr->depth = (vobj[vobj_id].length >> 2) - 6; |
|---|
| 1175 | mwmr->lock = 0; |
|---|
| 1176 | #if BOOT_DEBUG_VOBJS |
|---|
| 1177 | boot_puts("MWMR : "); |
|---|
| 1178 | boot_puts(vobj[vobj_id].name); |
|---|
| 1179 | boot_puts(" / depth = "); |
|---|
| 1180 | boot_putd(mwmr->depth); |
|---|
| 1181 | boot_puts(" / width = "); |
|---|
| 1182 | boot_putd(mwmr->width); |
|---|
| 1183 | boot_puts("\n"); |
|---|
| 1184 | #endif |
|---|
| 1185 | break; |
|---|
| 1186 | } |
|---|
| 1187 | case VOBJ_TYPE_ELF: // initialisation done by the loader |
|---|
| 1188 | { |
|---|
| 1189 | #if BOOT_DEBUG_VOBJS |
|---|
| 1190 | boot_puts("ELF : "); |
|---|
| 1191 | boot_puts(vobj[vobj_id].name); |
|---|
| 1192 | boot_puts(" / length = "); |
|---|
| 1193 | boot_putx(vobj[vobj_id].length); |
|---|
| 1194 | boot_puts("\n"); |
|---|
| 1195 | #endif |
|---|
| 1196 | break; |
|---|
| 1197 | } |
|---|
| 1198 | case VOBJ_TYPE_BLOB: // initialisation done by the loader |
|---|
| 1199 | { |
|---|
| 1200 | #if BOOT_DEBUG_VOBJS |
|---|
| 1201 | boot_puts("BLOB : "); |
|---|
| 1202 | boot_puts(vobj[vobj_id].name); |
|---|
| 1203 | boot_puts(" / length = "); |
|---|
| 1204 | boot_putx(vobj[vobj_id].length); |
|---|
| 1205 | boot_puts("\n"); |
|---|
| 1206 | #endif |
|---|
| 1207 | break; |
|---|
| 1208 | } |
|---|
| 1209 | case VOBJ_TYPE_BARRIER: // init is the number of participants |
|---|
| 1210 | { |
|---|
| 1211 | giet_barrier_t* barrier = (giet_barrier_t *) (vobj[vobj_id].vaddr); |
|---|
| 1212 | barrier->count = vobj[vobj_id].init; |
|---|
| 1213 | barrier->init = vobj[vobj_id].init; |
|---|
| 1214 | #if BOOT_DEBUG_VOBJS |
|---|
| 1215 | boot_puts("BARRIER : "); |
|---|
| 1216 | boot_puts(vobj[vobj_id].name); |
|---|
| 1217 | boot_puts(" / init_value = "); |
|---|
| 1218 | boot_putd(barrier->init); |
|---|
| 1219 | boot_puts("\n"); |
|---|
| 1220 | #endif |
|---|
| 1221 | break; |
|---|
| 1222 | } |
|---|
| 1223 | case VOBJ_TYPE_LOCK: // init value is "not taken" |
|---|
| 1224 | { |
|---|
| 1225 | unsigned int* lock = (unsigned int *) (vobj[vobj_id].vaddr); |
|---|
| 1226 | *lock = 0; |
|---|
| 1227 | #if BOOT_DEBUG_VOBJS |
|---|
| 1228 | boot_puts("LOCK : "); |
|---|
| 1229 | boot_puts(vobj[vobj_id].name); |
|---|
| 1230 | boot_puts("\n"); |
|---|
| 1231 | #endif |
|---|
| 1232 | break; |
|---|
| 1233 | } |
|---|
| 1234 | case VOBJ_TYPE_BUFFER: // nothing to initialise |
|---|
| 1235 | { |
|---|
| 1236 | #if BOOT_DEBUG_VOBJS |
|---|
| 1237 | boot_puts("BUFFER : "); |
|---|
| 1238 | boot_puts(vobj[vobj_id].name); |
|---|
| 1239 | boot_puts(" / paddr = "); |
|---|
| 1240 | boot_putl(vobj[vobj_id].paddr); |
|---|
| 1241 | boot_puts(" / length = "); |
|---|
| 1242 | boot_putx(vobj[vobj_id].length); |
|---|
| 1243 | boot_puts("\n"); |
|---|
| 1244 | #endif |
|---|
| 1245 | break; |
|---|
| 1246 | } |
|---|
| 1247 | case VOBJ_TYPE_MEMSPACE: |
|---|
| 1248 | { |
|---|
| 1249 | giet_memspace_t * memspace = (giet_memspace_t *) vobj[vobj_id].vaddr; |
|---|
| 1250 | memspace->buffer = (void *) vobj[vobj_id].vaddr + 8; |
|---|
| 1251 | memspace->size = vobj[vobj_id].length - 8; |
|---|
| 1252 | #if BOOT_DEBUG_VOBJS |
|---|
| 1253 | boot_puts("MEMSPACE : "); |
|---|
| 1254 | boot_puts(vobj[vobj_id].name); |
|---|
| 1255 | boot_puts(" / vaddr = "); |
|---|
| 1256 | boot_putx(vobj[vobj_id].vaddr); |
|---|
| 1257 | boot_puts(" / length = "); |
|---|
| 1258 | boot_putx(vobj[vobj_id].length); |
|---|
| 1259 | boot_puts(" / buffer = "); |
|---|
| 1260 | boot_putx((unsigned int) memspace->buffer); |
|---|
| 1261 | boot_puts(" / size = "); |
|---|
| 1262 | boot_putx(memspace->size); |
|---|
| 1263 | boot_puts("\n"); |
|---|
| 1264 | #endif |
|---|
| 1265 | break; |
|---|
| 1266 | } |
|---|
| 1267 | case VOBJ_TYPE_PTAB: // nothing to initialize |
|---|
| 1268 | { |
|---|
| 1269 | ptab_found = 1; |
|---|
| 1270 | #if BOOT_DEBUG_VOBJS |
|---|
| 1271 | boot_puts("PTAB : "); |
|---|
| 1272 | boot_puts(vobj[vobj_id].name); |
|---|
| 1273 | boot_puts(" / length = "); |
|---|
| 1274 | boot_putx(vobj[vobj_id].length); |
|---|
| 1275 | boot_puts("\n"); |
|---|
| 1276 | #endif |
|---|
| 1277 | break; |
|---|
| 1278 | } |
|---|
| 1279 | case VOBJ_TYPE_CONST: |
|---|
| 1280 | { |
|---|
| 1281 | unsigned int* addr = (unsigned int *) vobj[vobj_id].vaddr; |
|---|
| 1282 | *addr = vobj[vobj_id].init; |
|---|
| 1283 | #if BOOT_DEBUG_VOBJS |
|---|
| 1284 | boot_puts("CONST : "); |
|---|
| 1285 | boot_puts(vobj[vobj_id].name); |
|---|
| 1286 | boot_puts(" / Paddr :"); |
|---|
| 1287 | boot_putl(vobj[vobj_id].paddr); |
|---|
| 1288 | boot_puts(" / init = "); |
|---|
| 1289 | boot_putx(*addr); |
|---|
| 1290 | boot_puts("\n"); |
|---|
| 1291 | #endif |
|---|
| 1292 | break; |
|---|
| 1293 | } |
|---|
| 1294 | default: |
|---|
| 1295 | { |
|---|
| 1296 | boot_puts("\n[BOOT ERROR] illegal vobj type: "); |
|---|
| 1297 | boot_putd(vobj[vobj_id].type); |
|---|
| 1298 | boot_puts("\n"); |
|---|
| 1299 | boot_exit(); |
|---|
| 1300 | } |
|---|
| 1301 | } // end switch type |
|---|
| 1302 | } // end loop on vobjs |
|---|
| 1303 | if (ptab_found == 0) |
|---|
| 1304 | { |
|---|
| 1305 | boot_puts("\n[BOOT ERROR] Missing PTAB for vspace "); |
|---|
| 1306 | boot_putd(vspace_id); |
|---|
| 1307 | boot_exit(); |
|---|
| 1308 | } |
|---|
| 1309 | } // end loop on vspaces |
|---|
| 1310 | |
|---|
| 1311 | boot_puts("\n[BOOT] Vobjs initialisation completed at cycle : "); |
|---|
| 1312 | boot_putd(boot_proctime()); |
|---|
| 1313 | boot_puts("\n"); |
|---|
| 1314 | |
|---|
| 1315 | } // end boot_vobjs_init() |
|---|
| 1316 | |
|---|
| 1317 | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 1318 | // This function initializes one MWMR controller channel. |
|---|
| 1319 | // - coproc_pbase : physical base address of the Coproc configuration segment |
|---|
| 1320 | // - channel_pbase : physical base address of the MWMR channel segment |
|---|
| 1321 | // Warning : the channel physical base address should be on 32 bits, as the |
|---|
| 1322 | // MWMR controller configuration registers are 32 bits. |
|---|
| 1323 | // TODO : Introduce a MWMR_CONFIG_PADDR_EXT register in the MWMR coprocessor |
|---|
| 1324 | // To support addresses > 32 bits and remove this limitation... |
|---|
| 1325 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 1326 | void mwmr_hw_init(paddr_t coproc_pbase, |
|---|
| 1327 | enum mwmrPortDirection way, |
|---|
| 1328 | unsigned int no, |
|---|
| 1329 | paddr_t channel_pbase) |
|---|
| 1330 | { |
|---|
| 1331 | if ( (channel_pbase>>32) != 0 ) |
|---|
| 1332 | { |
|---|
| 1333 | boot_puts("\n[BOOT ERROR] MWMR controller does not support address > 32 bits\n"); |
|---|
| 1334 | boot_exit(); |
|---|
| 1335 | } |
|---|
| 1336 | |
|---|
| 1337 | unsigned int lsb = (unsigned int)channel_pbase; |
|---|
| 1338 | // unsigned int msb = (unsigned int)(channel_pbase>>32); |
|---|
| 1339 | |
|---|
| 1340 | unsigned int depth = boot_physical_read( channel_pbase + 16 ); |
|---|
| 1341 | unsigned int width = boot_physical_read( channel_pbase + 20 ); |
|---|
| 1342 | |
|---|
| 1343 | boot_physical_write( coproc_pbase + MWMR_CONFIG_FIFO_WAY*4, way ); |
|---|
| 1344 | boot_physical_write( coproc_pbase + MWMR_CONFIG_FIFO_NO*4, no ); |
|---|
| 1345 | boot_physical_write( coproc_pbase + MWMR_CONFIG_WIDTH*4, width); |
|---|
| 1346 | boot_physical_write( coproc_pbase + MWMR_CONFIG_DEPTH*4, depth); |
|---|
| 1347 | boot_physical_write( coproc_pbase + MWMR_CONFIG_STATUS_ADDR*4, lsb); |
|---|
| 1348 | boot_physical_write( coproc_pbase + MWMR_CONFIG_BUFFER_ADDR*4, lsb + 24 ); |
|---|
| 1349 | // boot_physical_write( coproc_pbase + MWMR_CONFIG_PADDR_EXT*4, msb); |
|---|
| 1350 | boot_physical_write( coproc_pbase + MWMR_CONFIG_RUNNING*4, 1 ); |
|---|
| 1351 | } |
|---|
| 1352 | |
|---|
| 1353 | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 1354 | // This function intializes the periherals and coprocessors, as specified |
|---|
| 1355 | // in the mapping_info file. |
|---|
| 1356 | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 1357 | void boot_peripherals_init() |
|---|
| 1358 | { |
|---|
| 1359 | mapping_header_t * header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 1360 | mapping_cluster_t * cluster = boot_get_cluster_base(header); |
|---|
| 1361 | mapping_periph_t * periph = boot_get_periph_base(header); |
|---|
| 1362 | mapping_pseg_t * pseg = boot_get_pseg_base(header); |
|---|
| 1363 | mapping_vobj_t * vobj = boot_get_vobj_base(header); |
|---|
| 1364 | mapping_vspace_t * vspace = boot_get_vspace_base(header); |
|---|
| 1365 | mapping_coproc_t * coproc = boot_get_coproc_base(header); |
|---|
| 1366 | mapping_cp_port_t * cp_port = boot_get_cp_port_base(header); |
|---|
| 1367 | |
|---|
| 1368 | unsigned int cluster_id; |
|---|
| 1369 | unsigned int periph_id; |
|---|
| 1370 | unsigned int coproc_id; |
|---|
| 1371 | unsigned int cp_port_id; |
|---|
| 1372 | unsigned int channel_id; |
|---|
| 1373 | |
|---|
| 1374 | for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) |
|---|
| 1375 | { |
|---|
| 1376 | |
|---|
| 1377 | #if BOOT_DEBUG_PERI |
|---|
| 1378 | boot_puts("\n[BOOT DEBUG] ****** peripherals initialisation in cluster "); |
|---|
| 1379 | boot_putd(cluster_id); |
|---|
| 1380 | boot_puts(" ******\n"); |
|---|
| 1381 | #endif |
|---|
| 1382 | |
|---|
| 1383 | for (periph_id = cluster[cluster_id].periph_offset; |
|---|
| 1384 | periph_id < cluster[cluster_id].periph_offset + |
|---|
| 1385 | cluster[cluster_id].periphs; periph_id++) |
|---|
| 1386 | { |
|---|
| 1387 | unsigned int type = periph[periph_id].type; |
|---|
| 1388 | unsigned int channels = periph[periph_id].channels; |
|---|
| 1389 | unsigned int pseg_id = periph[periph_id].psegid; |
|---|
| 1390 | |
|---|
| 1391 | paddr_t pbase = pseg[pseg_id].base; |
|---|
| 1392 | |
|---|
| 1393 | #if BOOT_DEBUG_PERI |
|---|
| 1394 | boot_puts("- peripheral type : "); |
|---|
| 1395 | boot_putd(type); |
|---|
| 1396 | boot_puts(" / pbase = "); |
|---|
| 1397 | boot_putl(pbase); |
|---|
| 1398 | boot_puts(" / channels = "); |
|---|
| 1399 | boot_putd(channels); |
|---|
| 1400 | boot_puts("\n"); |
|---|
| 1401 | #endif |
|---|
| 1402 | |
|---|
| 1403 | switch (type) |
|---|
| 1404 | { |
|---|
| 1405 | case PERIPH_TYPE_IOC: // vci_block_device component |
|---|
| 1406 | { |
|---|
| 1407 | paddr_t paddr = pbase + BLOCK_DEVICE_IRQ_ENABLE*4; |
|---|
| 1408 | boot_physical_write(paddr, 1); |
|---|
| 1409 | #if BOOT_DEBUG_PERI |
|---|
| 1410 | boot_puts("- IOC initialised\n"); |
|---|
| 1411 | #endif |
|---|
| 1412 | } |
|---|
| 1413 | break; |
|---|
| 1414 | case PERIPH_TYPE_DMA: // vci_multi_dma component |
|---|
| 1415 | for (channel_id = 0; channel_id < channels; channel_id++) |
|---|
| 1416 | { |
|---|
| 1417 | paddr_t paddr = pbase + (channel_id*DMA_SPAN + DMA_IRQ_DISABLE) * 4; |
|---|
| 1418 | boot_physical_write(paddr, 0); |
|---|
| 1419 | } |
|---|
| 1420 | #if BOOT_DEBUG_PERI |
|---|
| 1421 | boot_puts("- DMA initialised\n"); |
|---|
| 1422 | #endif |
|---|
| 1423 | break; |
|---|
| 1424 | case PERIPH_TYPE_NIC: // vci_multi_nic component |
|---|
| 1425 | for (channel_id = 0; channel_id < channels; channel_id++) |
|---|
| 1426 | { |
|---|
| 1427 | // TODO |
|---|
| 1428 | } |
|---|
| 1429 | #if BOOT_DEBUG_PERI |
|---|
| 1430 | boot_puts("- NIC initialised\n"); |
|---|
| 1431 | #endif |
|---|
| 1432 | break; |
|---|
| 1433 | case PERIPH_TYPE_TTY: // vci_multi_tty component |
|---|
| 1434 | #if BOOT_DEBUG_PERI |
|---|
| 1435 | boot_puts("- TTY initialised\n"); |
|---|
| 1436 | #endif |
|---|
| 1437 | break; |
|---|
| 1438 | case PERIPH_TYPE_IOB: // vci_io_bridge component |
|---|
| 1439 | if (USE_IOB) |
|---|
| 1440 | { |
|---|
| 1441 | // TODO |
|---|
| 1442 | // get the iommu page table physical address |
|---|
| 1443 | // define IPI address mapping the IOC interrupt |
|---|
| 1444 | // set IOMMU page table address |
|---|
| 1445 | // pseg_base[IOB_IOMMU_PTPR] = ptab_pbase; |
|---|
| 1446 | // activate IOMMU |
|---|
| 1447 | // pseg_base[IOB_IOMMU_ACTIVE] = 1; |
|---|
| 1448 | } |
|---|
| 1449 | #if BOOT_DEBUG_PERI |
|---|
| 1450 | boot_puts("- IOB initialised\n"); |
|---|
| 1451 | #endif |
|---|
| 1452 | break; |
|---|
| 1453 | } // end switch periph type |
|---|
| 1454 | } // end for periphs |
|---|
| 1455 | |
|---|
| 1456 | #if BOOT_DEBUG_PERI |
|---|
| 1457 | boot_puts("\n[BOOT DEBUG] ****** coprocessors initialisation in cluster "); |
|---|
| 1458 | boot_putd(cluster_id); |
|---|
| 1459 | boot_puts(" ******\n"); |
|---|
| 1460 | #endif |
|---|
| 1461 | |
|---|
| 1462 | for (coproc_id = cluster[cluster_id].coproc_offset; |
|---|
| 1463 | coproc_id < cluster[cluster_id].coproc_offset + |
|---|
| 1464 | cluster[cluster_id].coprocs; coproc_id++) |
|---|
| 1465 | { |
|---|
| 1466 | unsigned no_fifo_to = 0; //FIXME: should the map.xml define the order? |
|---|
| 1467 | unsigned no_fifo_from = 0; |
|---|
| 1468 | |
|---|
| 1469 | // Get physical base address for MWMR controler |
|---|
| 1470 | paddr_t coproc_pbase = pseg[coproc[coproc_id].psegid].base; |
|---|
| 1471 | |
|---|
| 1472 | #if BOOT_DEBUG_PERI |
|---|
| 1473 | boot_puts("- coprocessor name : "); |
|---|
| 1474 | boot_puts(coproc[coproc_id].name); |
|---|
| 1475 | boot_puts(" / nb ports = "); |
|---|
| 1476 | boot_putd((unsigned int) coproc[coproc_id].ports); |
|---|
| 1477 | boot_puts("\n"); |
|---|
| 1478 | #endif |
|---|
| 1479 | |
|---|
| 1480 | for (cp_port_id = coproc[coproc_id].port_offset; |
|---|
| 1481 | cp_port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports; |
|---|
| 1482 | cp_port_id++) |
|---|
| 1483 | { |
|---|
| 1484 | unsigned int vspace_id = cp_port[cp_port_id].vspaceid; |
|---|
| 1485 | unsigned int vobj_id = cp_port[cp_port_id].mwmr_vobjid + |
|---|
| 1486 | vspace[vspace_id].vobj_offset; |
|---|
| 1487 | |
|---|
| 1488 | // Get MWMR channel base address |
|---|
| 1489 | paddr_t channel_pbase = vobj[vobj_id].paddr; |
|---|
| 1490 | |
|---|
| 1491 | if (cp_port[cp_port_id].direction == PORT_TO_COPROC) |
|---|
| 1492 | { |
|---|
| 1493 | #if BOOT_DEBUG_PERI |
|---|
| 1494 | boot_puts(" port direction: PORT_TO_COPROC"); |
|---|
| 1495 | #endif |
|---|
| 1496 | mwmr_hw_init(coproc_pbase, |
|---|
| 1497 | PORT_TO_COPROC, |
|---|
| 1498 | no_fifo_to, |
|---|
| 1499 | channel_pbase); |
|---|
| 1500 | no_fifo_to++; |
|---|
| 1501 | } |
|---|
| 1502 | else |
|---|
| 1503 | { |
|---|
| 1504 | #if BOOT_DEBUG_PERI |
|---|
| 1505 | boot_puts(" port direction: PORT_FROM_COPROC"); |
|---|
| 1506 | #endif |
|---|
| 1507 | mwmr_hw_init(coproc_pbase, |
|---|
| 1508 | PORT_FROM_COPROC, |
|---|
| 1509 | no_fifo_from, |
|---|
| 1510 | channel_pbase); |
|---|
| 1511 | no_fifo_from++; |
|---|
| 1512 | } |
|---|
| 1513 | #if BOOT_DEBUG_PERI |
|---|
| 1514 | boot_puts(", with mwmr: "); |
|---|
| 1515 | boot_puts(vobj[vobj_id].name); |
|---|
| 1516 | boot_puts(" of vspace: "); |
|---|
| 1517 | boot_puts(vspace[vspace_id].name); |
|---|
| 1518 | #endif |
|---|
| 1519 | } // end for cp_ports |
|---|
| 1520 | } // end for coprocs |
|---|
| 1521 | } // end for clusters |
|---|
| 1522 | |
|---|
| 1523 | boot_puts("\n[BOOT] Peripherals initialisation completed at cycle "); |
|---|
| 1524 | boot_putd(boot_proctime()); |
|---|
| 1525 | boot_puts("\n"); |
|---|
| 1526 | |
|---|
| 1527 | } // end boot_peripherals_init() |
|---|
| 1528 | |
|---|
| 1529 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 1530 | // This function returns in the vbase and length buffers the virtual base |
|---|
| 1531 | // address and the length of the segment allocated to the schedulers array |
|---|
| 1532 | // in the cluster defined by the clusterid argument. |
|---|
| 1533 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 1534 | void boot_get_sched_vaddr( unsigned int cluster_id, |
|---|
| 1535 | unsigned int* vbase, |
|---|
| 1536 | unsigned int* length ) |
|---|
| 1537 | { |
|---|
| 1538 | mapping_header_t* header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 1539 | mapping_vobj_t* vobj = boot_get_vobj_base(header); |
|---|
| 1540 | mapping_vseg_t* vseg = boot_get_vseg_base(header); |
|---|
| 1541 | mapping_pseg_t* pseg = boot_get_pseg_base(header); |
|---|
| 1542 | |
|---|
| 1543 | unsigned int vseg_id; |
|---|
| 1544 | unsigned int found = 0; |
|---|
| 1545 | |
|---|
| 1546 | for ( vseg_id = 0 ; (vseg_id < header->vsegs) && (found == 0) ; vseg_id++ ) |
|---|
| 1547 | { |
|---|
| 1548 | if ( (vobj[vseg[vseg_id].vobj_offset].type == VOBJ_TYPE_SCHED) && |
|---|
| 1549 | (pseg[vseg[vseg_id].psegid].cluster == cluster_id ) ) |
|---|
| 1550 | { |
|---|
| 1551 | *vbase = vseg[vseg_id].vbase; |
|---|
| 1552 | *length = vobj[vseg[vseg_id].vobj_offset].length; |
|---|
| 1553 | found = 1; |
|---|
| 1554 | } |
|---|
| 1555 | } |
|---|
| 1556 | if ( found == 0 ) |
|---|
| 1557 | { |
|---|
| 1558 | boot_puts("\n[BOOT ERROR] No vobj of type SCHED in cluster "); |
|---|
| 1559 | boot_putd(cluster_id); |
|---|
| 1560 | boot_puts("\n"); |
|---|
| 1561 | boot_exit(); |
|---|
| 1562 | } |
|---|
| 1563 | } // end boot_get_sched_vaddr() |
|---|
| 1564 | |
|---|
| 1565 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 1566 | // This function initialises all processors schedulers. |
|---|
| 1567 | // This is done by processor 0, and the MMU must be activated. |
|---|
| 1568 | // It initialises the boot_chedulers[gpid] pointers array. |
|---|
| 1569 | // Finally, it scan all tasks in all vspaces to initialise the tasks contexts, |
|---|
| 1570 | // as specified in the mapping_info data structure. |
|---|
| 1571 | // For each task, a TTY channel, a TIMER channel, a FBDMA channel, and a NIC |
|---|
| 1572 | // channel are allocated if required. |
|---|
| 1573 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 1574 | void boot_schedulers_init() |
|---|
| 1575 | { |
|---|
| 1576 | mapping_header_t* header = (mapping_header_t *) & seg_mapping_base; |
|---|
| 1577 | mapping_cluster_t* cluster = boot_get_cluster_base(header); |
|---|
| 1578 | mapping_vspace_t* vspace = boot_get_vspace_base(header); |
|---|
| 1579 | mapping_task_t* task = boot_get_task_base(header); |
|---|
| 1580 | mapping_vobj_t* vobj = boot_get_vobj_base(header); |
|---|
| 1581 | mapping_proc_t* proc = boot_get_proc_base(header); |
|---|
| 1582 | mapping_irq_t* irq = boot_get_irq_base(header); |
|---|
| 1583 | |
|---|
| 1584 | unsigned int cluster_id; // cluster index in mapping_info |
|---|
| 1585 | unsigned int proc_id; // processor index in mapping_info |
|---|
| 1586 | unsigned int irq_id; // irq index in mapping_info |
|---|
| 1587 | unsigned int vspace_id; // vspace index in mapping_info |
|---|
| 1588 | unsigned int task_id; // task index in mapping_info |
|---|
| 1589 | |
|---|
| 1590 | unsigned int alloc_tty_channel = 1; // TTY channel allocator |
|---|
| 1591 | unsigned int alloc_nic_channel = 0; // NIC channel allocator |
|---|
| 1592 | unsigned int alloc_cma_channel = 0; // CMA channel allocator |
|---|
| 1593 | unsigned int alloc_ioc_channel = 0; // IOC channel allocator |
|---|
| 1594 | unsigned int alloc_dma_channel[NB_CLUSTERS]; // DMA channel allocators |
|---|
| 1595 | unsigned int alloc_tim_channel[NB_CLUSTERS]; // user TIMER allocators |
|---|
| 1596 | |
|---|
| 1597 | ///////////////////////////////////////////////////////////////////////// |
|---|
| 1598 | // Step 1 : loop on the clusters and on the processors |
|---|
| 1599 | // to initialize the schedulers[] array of pointers and |
|---|
| 1600 | // the interrupt vectors. |
|---|
| 1601 | // Implementation note: |
|---|
| 1602 | // We need to use both proc_id to scan the mapping info structure, |
|---|
| 1603 | // and lpid to access the schedulers array. |
|---|
| 1604 | // - the boot_schedulers[] array of pointers can contain "holes", because |
|---|
| 1605 | // it is indexed by the global pid = cluster_id*NB_PROCS_MAX + ltid |
|---|
| 1606 | // - the mapping info array of processors is contiguous, it is indexed |
|---|
| 1607 | // by proc_id, and use an offset specific in each cluster. |
|---|
| 1608 | |
|---|
| 1609 | for (cluster_id = 0; cluster_id < header->clusters; cluster_id++) |
|---|
| 1610 | { |
|---|
| 1611 | |
|---|
| 1612 | #if BOOT_DEBUG_SCHED |
|---|
| 1613 | boot_puts("\n[BOOT DEBUG] Initialise schedulers in cluster "); |
|---|
| 1614 | boot_putd(cluster_id); |
|---|
| 1615 | boot_puts("\n"); |
|---|
| 1616 | #endif |
|---|
| 1617 | |
|---|
| 1618 | // TTY, NIC, CMA, IOC, TIM and DMA channels allocators |
|---|
| 1619 | // - TTY[0] is reserved for the kernel |
|---|
| 1620 | // - In all clusters the first NB_PROCS_MAX timers |
|---|
| 1621 | // are reserved for the kernel (context switch) |
|---|
| 1622 | |
|---|
| 1623 | alloc_dma_channel[cluster_id] = 0; |
|---|
| 1624 | alloc_tim_channel[cluster_id] = NB_PROCS_MAX; |
|---|
| 1625 | |
|---|
| 1626 | unsigned int lpid; // processor local index in cluster |
|---|
| 1627 | unsigned int sched_vbase; // schedulers segment virtual base address |
|---|
| 1628 | unsigned int sched_length; // schedulers segment length |
|---|
| 1629 | unsigned int nprocs; // number of processors in cluster |
|---|
| 1630 | |
|---|
| 1631 | nprocs = cluster[cluster_id].procs; |
|---|
| 1632 | |
|---|
| 1633 | // checking processors number |
|---|
| 1634 | if ( nprocs > NB_PROCS_MAX ) |
|---|
| 1635 | { |
|---|
| 1636 | boot_puts("\n[BOOT ERROR] Too much processors in cluster "); |
|---|
| 1637 | boot_putd(cluster_id); |
|---|
| 1638 | boot_puts("\n"); |
|---|
| 1639 | boot_exit(); |
|---|
| 1640 | } |
|---|
| 1641 | |
|---|
| 1642 | // get scheduler array virtual base address for cluster_id |
|---|
| 1643 | boot_get_sched_vaddr( cluster_id, &sched_vbase, &sched_length ); |
|---|
| 1644 | |
|---|
| 1645 | // each processor scheduler requires 4 Kbytes |
|---|
| 1646 | if ( sched_length < (nprocs<<12) ) |
|---|
| 1647 | { |
|---|
| 1648 | boot_puts("\n[BOOT ERROR] Schedulers segment too small in cluster "); |
|---|
| 1649 | boot_putd(cluster_id); |
|---|
| 1650 | boot_puts("\n"); |
|---|
| 1651 | boot_exit(); |
|---|
| 1652 | } |
|---|
| 1653 | |
|---|
| 1654 | for ( proc_id = cluster[cluster_id].proc_offset, lpid = 0 ; |
|---|
| 1655 | proc_id < cluster[cluster_id].proc_offset + cluster[cluster_id].procs; |
|---|
| 1656 | proc_id++, lpid++ ) |
|---|
| 1657 | { |
|---|
| 1658 | // set the schedulers pointers array |
|---|
| 1659 | boot_schedulers[cluster_id * NB_PROCS_MAX + lpid] = |
|---|
| 1660 | (static_scheduler_t*)( sched_vbase + (lpid<<12) ); |
|---|
| 1661 | |
|---|
| 1662 | #if BOOT_DEBUG_SCHED |
|---|
| 1663 | boot_puts("\nProc "); |
|---|
| 1664 | boot_putd(lpid); |
|---|
| 1665 | boot_puts(" : scheduler virtual base address = "); |
|---|
| 1666 | boot_putx( sched_vbase + (lpid<<12) ); |
|---|
| 1667 | boot_puts("\n"); |
|---|
| 1668 | #endif |
|---|
| 1669 | // current processor scheduler pointer : psched |
|---|
| 1670 | static_scheduler_t* psched = (static_scheduler_t*)(sched_vbase+(lpid<<12)); |
|---|
| 1671 | |
|---|
| 1672 | // initialise the "tasks" variable |
|---|
| 1673 | psched->tasks = 0; |
|---|
| 1674 | |
|---|
| 1675 | // initialise the interrupt_vector with ISR_DEFAULT |
|---|
| 1676 | unsigned int slot; |
|---|
| 1677 | for (slot = 0; slot < 32; slot++) psched->interrupt_vector[slot] = 0; |
|---|
| 1678 | |
|---|
| 1679 | // scan the IRQs actually allocated to current processor |
|---|
| 1680 | for (irq_id = proc[proc_id].irq_offset; |
|---|
| 1681 | irq_id < proc[proc_id].irq_offset + proc[proc_id].irqs; |
|---|
| 1682 | irq_id++) |
|---|
| 1683 | { |
|---|
| 1684 | unsigned int type = irq[irq_id].type; |
|---|
| 1685 | unsigned int icu_id = irq[irq_id].icuid; |
|---|
| 1686 | unsigned int isr_id = irq[irq_id].isr; |
|---|
| 1687 | unsigned int channel = irq[irq_id].channel; |
|---|
| 1688 | unsigned int value = isr_id | (type << 8) | (channel << 16); |
|---|
| 1689 | psched->interrupt_vector[icu_id] = value; |
|---|
| 1690 | |
|---|
| 1691 | #if BOOT_DEBUG_SCHED |
|---|
| 1692 | boot_puts("- IRQ : icu = "); |
|---|
| 1693 | boot_putd(icu_id); |
|---|
| 1694 | boot_puts(" / type = "); |
|---|
| 1695 | boot_putd(type); |
|---|
| 1696 | boot_puts(" / isr = "); |
|---|
| 1697 | boot_putd(isr_id); |
|---|
| 1698 | boot_puts(" / channel = "); |
|---|
| 1699 | boot_putd(channel); |
|---|
| 1700 | boot_puts(" => vector_entry = "); |
|---|
| 1701 | boot_putx( value ); |
|---|
| 1702 | boot_puts("\n"); |
|---|
| 1703 | #endif |
|---|
| 1704 | } |
|---|
| 1705 | } // end for procs |
|---|
| 1706 | } // end for clusters |
|---|
| 1707 | |
|---|
| 1708 | /////////////////////////////////////////////////////////////////// |
|---|
| 1709 | // Step 2 : loop on the vspaces and the tasks |
|---|
| 1710 | // to initialise the schedulers and the task contexts. |
|---|
| 1711 | // Implementation note: |
|---|
| 1712 | // This function initialises the task context for all tasks. |
|---|
| 1713 | // For each processor, the scheduler virtual base address |
|---|
| 1714 | // is written in the CP0_SCHED register in reset.S |
|---|
| 1715 | |
|---|
| 1716 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
|---|
| 1717 | { |
|---|
| 1718 | |
|---|
| 1719 | #if BOOT_DEBUG_SCHED |
|---|
| 1720 | boot_puts("\n[BOOT DEBUG] Initialise task contexts for vspace "); |
|---|
| 1721 | boot_puts(vspace[vspace_id].name); |
|---|
| 1722 | boot_puts("\n"); |
|---|
| 1723 | #endif |
|---|
| 1724 | // We must set the PTPR depending on the vspace, because the start_vector |
|---|
| 1725 | // and the stack address are defined in virtual space. |
|---|
| 1726 | boot_set_mmu_ptpr( (unsigned int)(boot_ptabs_paddr[vspace_id] >> 13) ); |
|---|
| 1727 | |
|---|
| 1728 | // loop on the tasks in vspace (task_id is the global index) |
|---|
| 1729 | for (task_id = vspace[vspace_id].task_offset; |
|---|
| 1730 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); |
|---|
| 1731 | task_id++) |
|---|
| 1732 | { |
|---|
| 1733 | // compute gpid (global processor index) and scheduler base address |
|---|
| 1734 | unsigned int gpid = task[task_id].clusterid * NB_PROCS_MAX + |
|---|
| 1735 | task[task_id].proclocid; |
|---|
| 1736 | static_scheduler_t* psched = boot_schedulers[gpid]; |
|---|
| 1737 | |
|---|
| 1738 | // ctx_ra : the return address is &boot_eret() |
|---|
| 1739 | unsigned int ctx_ra = (unsigned int) &boot_eret; |
|---|
| 1740 | |
|---|
| 1741 | // ctx_sr : value required before an eret instruction |
|---|
| 1742 | unsigned int ctx_sr = 0x0000FF13; |
|---|
| 1743 | |
|---|
| 1744 | // ctx_ptpr : page table physical base address (shifted by 13 bit) |
|---|
| 1745 | unsigned int ctx_ptpr = (unsigned int)(boot_ptabs_paddr[vspace_id] >> 13); |
|---|
| 1746 | |
|---|
| 1747 | // ctx_ptab : page_table virtual base address |
|---|
| 1748 | unsigned int ctx_ptab = boot_ptabs_vaddr[vspace_id]; |
|---|
| 1749 | |
|---|
| 1750 | // ctx_tty : terminal global index provided by the global allocator |
|---|
| 1751 | unsigned int ctx_tty = 0xFFFFFFFF; |
|---|
| 1752 | if (task[task_id].use_tty) |
|---|
| 1753 | { |
|---|
| 1754 | if (alloc_tty_channel >= NB_TTY_CHANNELS) |
|---|
| 1755 | { |
|---|
| 1756 | boot_puts("\n[BOOT ERROR] TTY index too large for task "); |
|---|
| 1757 | boot_puts(task[task_id].name); |
|---|
| 1758 | boot_puts(" in vspace "); |
|---|
| 1759 | boot_puts(vspace[vspace_id].name); |
|---|
| 1760 | boot_puts("\n"); |
|---|
| 1761 | boot_exit(); |
|---|
| 1762 | } |
|---|
| 1763 | ctx_tty = alloc_tty_channel; |
|---|
| 1764 | alloc_tty_channel++; |
|---|
| 1765 | } |
|---|
| 1766 | // ctx_nic : NIC channel global index provided by the global allocator |
|---|
| 1767 | unsigned int ctx_nic = 0xFFFFFFFF; |
|---|
| 1768 | if (task[task_id].use_nic) |
|---|
| 1769 | { |
|---|
| 1770 | if (alloc_nic_channel >= NB_NIC_CHANNELS) |
|---|
| 1771 | { |
|---|
| 1772 | boot_puts("\n[BOOT ERROR] NIC channel index too large for task "); |
|---|
| 1773 | boot_puts(task[task_id].name); |
|---|
| 1774 | boot_puts(" in vspace "); |
|---|
| 1775 | boot_puts(vspace[vspace_id].name); |
|---|
| 1776 | boot_puts("\n"); |
|---|
| 1777 | boot_exit(); |
|---|
| 1778 | } |
|---|
| 1779 | ctx_nic = alloc_nic_channel; |
|---|
| 1780 | alloc_nic_channel++; |
|---|
| 1781 | } |
|---|
| 1782 | // ctx_cma : CMA channel global index provided by the global allocator |
|---|
| 1783 | unsigned int ctx_cma = 0xFFFFFFFF; |
|---|
| 1784 | if (task[task_id].use_cma) |
|---|
| 1785 | { |
|---|
| 1786 | if (alloc_cma_channel >= NB_CMA_CHANNELS) |
|---|
| 1787 | { |
|---|
| 1788 | boot_puts("\n[BOOT ERROR] CMA channel index too large for task "); |
|---|
| 1789 | boot_puts(task[task_id].name); |
|---|
| 1790 | boot_puts(" in vspace "); |
|---|
| 1791 | boot_puts(vspace[vspace_id].name); |
|---|
| 1792 | boot_puts("\n"); |
|---|
| 1793 | boot_exit(); |
|---|
| 1794 | } |
|---|
| 1795 | ctx_cma = alloc_cma_channel; |
|---|
| 1796 | alloc_cma_channel++; |
|---|
| 1797 | } |
|---|
| 1798 | // ctx_ioc : IOC channel global index provided by the global allocator |
|---|
| 1799 | unsigned int ctx_ioc = 0xFFFFFFFF; |
|---|
| 1800 | if (task[task_id].use_ioc) |
|---|
| 1801 | { |
|---|
| 1802 | if (alloc_ioc_channel >= NB_IOC_CHANNELS) |
|---|
| 1803 | { |
|---|
| 1804 | boot_puts("\n[BOOT ERROR] IOC channel index too large for task "); |
|---|
| 1805 | boot_puts(task[task_id].name); |
|---|
| 1806 | boot_puts(" in vspace "); |
|---|
| 1807 | boot_puts(vspace[vspace_id].name); |
|---|
| 1808 | boot_puts("\n"); |
|---|
| 1809 | boot_exit(); |
|---|
| 1810 | } |
|---|
| 1811 | ctx_ioc = alloc_ioc_channel; |
|---|
| 1812 | alloc_ioc_channel++; |
|---|
| 1813 | } |
|---|
| 1814 | // ctx_tim : TIMER local channel index provided by the cluster allocator |
|---|
| 1815 | unsigned int ctx_tim = 0xFFFFFFFF; |
|---|
| 1816 | if (task[task_id].use_tim) |
|---|
| 1817 | { |
|---|
| 1818 | unsigned int cluster_id = task[task_id].clusterid; |
|---|
| 1819 | |
|---|
| 1820 | if ( alloc_tim_channel[cluster_id] >= NB_TIM_CHANNELS ) |
|---|
| 1821 | { |
|---|
| 1822 | boot_puts("\n[BOOT ERROR] local TIMER index too large for task "); |
|---|
| 1823 | boot_puts(task[task_id].name); |
|---|
| 1824 | boot_puts(" in vspace "); |
|---|
| 1825 | boot_puts(vspace[vspace_id].name); |
|---|
| 1826 | boot_puts("\n"); |
|---|
| 1827 | boot_exit(); |
|---|
| 1828 | } |
|---|
| 1829 | |
|---|
| 1830 | // checking that there is a well defined ISR_TIMER installed |
|---|
| 1831 | unsigned int found = 0; |
|---|
| 1832 | for ( irq_id = 0 ; irq_id < 32 ; irq_id++ ) |
|---|
| 1833 | { |
|---|
| 1834 | unsigned int entry = psched->interrupt_vector[irq_id]; |
|---|
| 1835 | unsigned int isr = entry & 0x000000FF; |
|---|
| 1836 | unsigned int channel = entry>>16; |
|---|
| 1837 | if ( (isr == ISR_TIMER) && (channel == alloc_tim_channel[cluster_id]) ) |
|---|
| 1838 | { |
|---|
| 1839 | found = 1; |
|---|
| 1840 | ctx_tim = alloc_tim_channel[cluster_id]; |
|---|
| 1841 | alloc_tim_channel[cluster_id]++; |
|---|
| 1842 | break; |
|---|
| 1843 | } |
|---|
| 1844 | } |
|---|
| 1845 | if (!found) |
|---|
| 1846 | { |
|---|
| 1847 | boot_puts("\n[BOOT ERROR] No ISR_TIMER installed for task "); |
|---|
| 1848 | boot_puts(task[task_id].name); |
|---|
| 1849 | boot_puts(" in vspace "); |
|---|
| 1850 | boot_puts(vspace[vspace_id].name); |
|---|
| 1851 | boot_puts("\n"); |
|---|
| 1852 | boot_exit(); |
|---|
| 1853 | } |
|---|
| 1854 | } |
|---|
| 1855 | // ctx_dma : the local channel index is defined by the cluster allocator |
|---|
| 1856 | // but the ctx_dma value is a global index |
|---|
| 1857 | unsigned int ctx_dma = 0xFFFFFFFF; |
|---|
| 1858 | if ( task[task_id].use_dma ) |
|---|
| 1859 | { |
|---|
| 1860 | unsigned int cluster_id = task[task_id].clusterid; |
|---|
| 1861 | |
|---|
| 1862 | if (alloc_dma_channel[cluster_id] >= NB_DMA_CHANNELS) |
|---|
| 1863 | { |
|---|
| 1864 | boot_puts("\n[BOOT ERROR] local DMA index too large for task "); |
|---|
| 1865 | boot_puts(task[task_id].name); |
|---|
| 1866 | boot_puts(" in vspace "); |
|---|
| 1867 | boot_puts(vspace[vspace_id].name); |
|---|
| 1868 | boot_puts("\n"); |
|---|
| 1869 | boot_exit(); |
|---|
| 1870 | } |
|---|
| 1871 | ctx_dma = cluster_id * NB_DMA_CHANNELS + alloc_dma_channel[cluster_id]; |
|---|
| 1872 | alloc_dma_channel[cluster_id]++; |
|---|
| 1873 | } |
|---|
| 1874 | // ctx_epc : Get the virtual address of the start function |
|---|
| 1875 | mapping_vobj_t* pvobj = &vobj[vspace[vspace_id].vobj_offset + |
|---|
| 1876 | vspace[vspace_id].start_offset]; |
|---|
| 1877 | unsigned int* start_vector_vbase = (unsigned int *) pvobj->vaddr; |
|---|
| 1878 | unsigned int ctx_epc = start_vector_vbase[task[task_id].startid]; |
|---|
| 1879 | |
|---|
| 1880 | // ctx_sp : Get the vobj containing the stack |
|---|
| 1881 | unsigned int vobj_id = task[task_id].stack_vobjid + vspace[vspace_id].vobj_offset; |
|---|
| 1882 | unsigned int ctx_sp = vobj[vobj_id].vaddr + vobj[vobj_id].length; |
|---|
| 1883 | |
|---|
| 1884 | // get local task index in scheduler |
|---|
| 1885 | unsigned int ltid = psched->tasks; |
|---|
| 1886 | |
|---|
| 1887 | if (ltid >= IDLE_TASK_INDEX) |
|---|
| 1888 | { |
|---|
| 1889 | boot_puts("\n[BOOT ERROR] : "); |
|---|
| 1890 | boot_putd(ltid); |
|---|
| 1891 | boot_puts(" tasks allocated to processor "); |
|---|
| 1892 | boot_putd(gpid); |
|---|
| 1893 | boot_puts(" / max is 15\n"); |
|---|
| 1894 | boot_exit(); |
|---|
| 1895 | } |
|---|
| 1896 | // update the "tasks" field in scheduler |
|---|
| 1897 | psched->tasks = ltid + 1; |
|---|
| 1898 | |
|---|
| 1899 | // update the "current" field in scheduler |
|---|
| 1900 | psched->current = 0; |
|---|
| 1901 | |
|---|
| 1902 | // initializes the task context in scheduler |
|---|
| 1903 | psched->context[ltid][CTX_SR_ID] = ctx_sr; |
|---|
| 1904 | psched->context[ltid][CTX_SP_ID] = ctx_sp; |
|---|
| 1905 | psched->context[ltid][CTX_RA_ID] = ctx_ra; |
|---|
| 1906 | psched->context[ltid][CTX_EPC_ID] = ctx_epc; |
|---|
| 1907 | psched->context[ltid][CTX_PTPR_ID] = ctx_ptpr; |
|---|
| 1908 | psched->context[ltid][CTX_TTY_ID] = ctx_tty; |
|---|
| 1909 | psched->context[ltid][CTX_CMA_ID] = ctx_cma; |
|---|
| 1910 | psched->context[ltid][CTX_IOC_ID] = ctx_ioc; |
|---|
| 1911 | psched->context[ltid][CTX_NIC_ID] = ctx_nic; |
|---|
| 1912 | psched->context[ltid][CTX_TIM_ID] = ctx_tim; |
|---|
| 1913 | psched->context[ltid][CTX_DMA_ID] = ctx_dma; |
|---|
| 1914 | psched->context[ltid][CTX_PTAB_ID] = ctx_ptab; |
|---|
| 1915 | psched->context[ltid][CTX_LTID_ID] = ltid; |
|---|
| 1916 | psched->context[ltid][CTX_GTID_ID] = task_id; |
|---|
| 1917 | psched->context[ltid][CTX_VSID_ID] = vspace_id; |
|---|
| 1918 | psched->context[ltid][CTX_RUN_ID] = 1; |
|---|
| 1919 | |
|---|
| 1920 | #if BOOT_DEBUG_SCHED |
|---|
| 1921 | boot_puts("\nTask "); |
|---|
| 1922 | boot_puts(task[task_id].name); |
|---|
| 1923 | boot_puts(" ("); |
|---|
| 1924 | boot_putd(task_id); |
|---|
| 1925 | boot_puts(") allocated to processor "); |
|---|
| 1926 | boot_putd(gpid); |
|---|
| 1927 | boot_puts("\n - ctx[LTID] = "); |
|---|
| 1928 | boot_putd(ltid); |
|---|
| 1929 | boot_puts("\n - ctx[SR] = "); |
|---|
| 1930 | boot_putx(ctx_sr); |
|---|
| 1931 | boot_puts("\n - ctx[SR] = "); |
|---|
| 1932 | boot_putx(ctx_sp); |
|---|
| 1933 | boot_puts("\n - ctx[RA] = "); |
|---|
| 1934 | boot_putx(ctx_ra); |
|---|
| 1935 | boot_puts("\n - ctx[EPC] = "); |
|---|
| 1936 | boot_putx(ctx_epc); |
|---|
| 1937 | boot_puts("\n - ctx[PTPR] = "); |
|---|
| 1938 | boot_putx(ctx_ptpr); |
|---|
| 1939 | boot_puts("\n - ctx[TTY] = "); |
|---|
| 1940 | boot_putd(ctx_tty); |
|---|
| 1941 | boot_puts("\n - ctx[NIC] = "); |
|---|
| 1942 | boot_putd(ctx_nic); |
|---|
| 1943 | boot_puts("\n - ctx[CMA] = "); |
|---|
| 1944 | boot_putd(ctx_cma); |
|---|
| 1945 | boot_puts("\n - ctx[IOC] = "); |
|---|
| 1946 | boot_putd(ctx_ioc); |
|---|
| 1947 | boot_puts("\n - ctx[TIM] = "); |
|---|
| 1948 | boot_putd(ctx_tim); |
|---|
| 1949 | boot_puts("\n - ctx[DMA] = "); |
|---|
| 1950 | boot_putd(ctx_dma); |
|---|
| 1951 | boot_puts("\n - ctx[PTAB] = "); |
|---|
| 1952 | boot_putx(ctx_ptab); |
|---|
| 1953 | boot_puts("\n - ctx[GTID] = "); |
|---|
| 1954 | boot_putd(task_id); |
|---|
| 1955 | boot_puts("\n - ctx[VSID] = "); |
|---|
| 1956 | boot_putd(vspace_id); |
|---|
| 1957 | boot_puts("\n"); |
|---|
| 1958 | #endif |
|---|
| 1959 | |
|---|
| 1960 | } // end loop on tasks |
|---|
| 1961 | } // end loop on vspaces |
|---|
| 1962 | |
|---|
| 1963 | boot_puts("\n[BOOT] Schedulers initialisation completed at cycle "); |
|---|
| 1964 | boot_putd(boot_proctime()); |
|---|
| 1965 | boot_puts("\n"); |
|---|
| 1966 | |
|---|
| 1967 | } // end boot_schedulers_init() |
|---|
| 1968 | |
|---|
| 1969 | |
|---|
| 1970 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 1971 | // This function is executed by P[0] to wakeup all processors. |
|---|
| 1972 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 1973 | void boot_start_all_procs() |
|---|
| 1974 | { |
|---|
| 1975 | mapping_header_t * header = (mapping_header_t *) &seg_mapping_base; |
|---|
| 1976 | header->signature = OUT_MAPPING_SIGNATURE; |
|---|
| 1977 | } |
|---|
| 1978 | |
|---|
| 1979 | |
|---|
| 1980 | ///////////////////////////////////////////////////////////////////// |
|---|
| 1981 | // This function is the entry point of the initialisation procedure |
|---|
| 1982 | ///////////////////////////////////////////////////////////////////// |
|---|
| 1983 | void boot_init() { |
|---|
| 1984 | |
|---|
| 1985 | // mapping_info checking |
|---|
| 1986 | boot_check_mapping(); |
|---|
| 1987 | |
|---|
| 1988 | // page table building |
|---|
| 1989 | boot_pt_init(); |
|---|
| 1990 | |
|---|
| 1991 | // mmu activation (with page table [0]) |
|---|
| 1992 | boot_set_mmu_ptpr((unsigned int) (boot_ptabs_paddr[0] >> 13)); |
|---|
| 1993 | boot_set_mmu_mode(0xF); |
|---|
| 1994 | |
|---|
| 1995 | boot_puts("\n[BOOT] Proc 0 MMU activation at cycle "); |
|---|
| 1996 | boot_putd(boot_proctime()); |
|---|
| 1997 | boot_puts("\n"); |
|---|
| 1998 | |
|---|
| 1999 | // vobjs initialisation |
|---|
| 2000 | boot_vobjs_init(); |
|---|
| 2001 | |
|---|
| 2002 | // reset ptpr with page table 0 |
|---|
| 2003 | boot_set_mmu_ptpr((unsigned int) (boot_ptabs_paddr[0] >> 13)); |
|---|
| 2004 | |
|---|
| 2005 | // peripherals initialisation |
|---|
| 2006 | boot_peripherals_init(); |
|---|
| 2007 | |
|---|
| 2008 | // schedulers initialisation |
|---|
| 2009 | boot_schedulers_init(); |
|---|
| 2010 | |
|---|
| 2011 | // start all processors |
|---|
| 2012 | boot_start_all_procs(); |
|---|
| 2013 | |
|---|
| 2014 | } // end boot_init() |
|---|
| 2015 | |
|---|
| 2016 | |
|---|
| 2017 | // Local Variables: |
|---|
| 2018 | // tab-width: 4 |
|---|
| 2019 | // c-basic-offset: 4 |
|---|
| 2020 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 2021 | // indent-tabs-mode: nil |
|---|
| 2022 | // End: |
|---|
| 2023 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 2024 | |
|---|