source: trunk/kernel/kern/kernel_init.c@ 539

Last change on this file since 539 was 539, checked in by nicolas.van.phan@…, 8 years ago

TTY MUX 4 : Multiplex TTY character sending

Now, when a thread wants to write to a tty,
when the dev_txt_write() or dev_txt_sync_write() are called,
they all call soclib_mtty_aux() with a channel number.
The soclib_mtty_aux() function will write the string char by char,
with each char preceded by the channel number, so that the receiving end
knows to which tty a character is addressed to.

N.B. dev_txt_write() makes *synchronous* writes for the moment
because unlike the vci_tty_tsar, the vci_multi_tty doesn't raise
interrupt except when a new char is received, so we can't use the
interrupt mechanism for writes.

N.B. Now, the TTY DEV threads all write to the same register (WRITE),
but when a thread sends a 2-byte (tty dest. nb. + char), the two must be
send consecutively, without another thread sending a byte in between.
Consequently, a lock has been added to guarantee this atomicity.

File size: 58.3 KB
Line 
1/*
2 * kernel_init.c - kernel parallel initialization
3 *
4 * Authors : Mohamed Lamine Karaoui (2015)
5 * Alain Greiner (2016,2017)
6 *
7 * Copyright (c) Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#include <kernel_config.h>
26#include <errno.h>
27#include <hal_kernel_types.h>
28#include <hal_special.h>
29#include <hal_context.h>
30#include <hal_irqmask.h>
31#include <hal_ppm.h>
32#include <barrier.h>
33#include <remote_barrier.h>
34#include <remote_fifo.h>
35#include <core.h>
36#include <list.h>
37#include <xlist.h>
38#include <xhtab.h>
39#include <thread.h>
40#include <scheduler.h>
41#include <kmem.h>
42#include <cluster.h>
43#include <string.h>
44#include <memcpy.h>
45#include <ppm.h>
46#include <page.h>
47#include <chdev.h>
48#include <boot_info.h>
49#include <dqdt.h>
50#include <dev_mmc.h>
51#include <dev_dma.h>
52#include <dev_iob.h>
53#include <dev_ioc.h>
54#include <dev_txt.h>
55#include <dev_pic.h>
56#include <printk.h>
57#include <vfs.h>
58#include <devfs.h>
59#include <mapper.h>
60
61///////////////////////////////////////////////////////////////////////////////////////////
62// All the following global variables are replicated in all clusters.
63// They are initialised by the kernel_init() function.
64//
65// WARNING : The section names have been defined to control the base addresses of the
66// boot_info structure and the idle thread descriptors, through the kernel.ld script:
67// - the boot_info structure is built by the bootloader, and used by kernel_init.
68// it must be the first object in the kdata segment.
69// - the array of idle threads descriptors must be placed on the first page boundary after
70// the boot_info structure in the kdata segment.
71///////////////////////////////////////////////////////////////////////////////////////////
72
73// This variable defines the local boot_info structure
74__attribute__((section(".kinfo")))
75boot_info_t boot_info;
76
77// This variable defines the "idle" threads descriptors array
78__attribute__((section(".kidle")))
79char idle_threads[CONFIG_THREAD_DESC_SIZE *
80 CONFIG_MAX_LOCAL_CORES] CONFIG_PPM_PAGE_ALIGNED;
81
82// This variable defines the local cluster manager
83__attribute__((section(".kdata")))
84cluster_t cluster_manager CONFIG_CACHE_LINE_ALIGNED;
85
86// This variable defines the TXT0 kernel terminal (TX only)
87__attribute__((section(".kdata")))
88chdev_t txt0_chdev CONFIG_CACHE_LINE_ALIGNED;
89
90// This variable defines the TXT0 lock for writing characters to MTY0
91__attribute__((section(".kdata")))
92spinlock_t txt0_lock CONFIG_CACHE_LINE_ALIGNED;
93
94// This variables define the kernel process0 descriptor
95__attribute__((section(".kdata")))
96process_t process_zero CONFIG_CACHE_LINE_ALIGNED;
97
98// This variable defines extended pointers on the distributed chdevs
99__attribute__((section(".kdata")))
100chdev_directory_t chdev_dir CONFIG_CACHE_LINE_ALIGNED;
101
102// This variable contains the input IRQ indexes for the IOPIC controller
103__attribute__((section(".kdata")))
104iopic_input_t iopic_input CONFIG_CACHE_LINE_ALIGNED;
105
106// This variable contains the input IRQ indexes for the LAPIC controller
107__attribute__((section(".kdata")))
108lapic_input_t lapic_input CONFIG_CACHE_LINE_ALIGNED;
109
110// This variable defines the local cluster identifier
111__attribute__((section(".kdata")))
112cxy_t local_cxy CONFIG_CACHE_LINE_ALIGNED;
113
114// This variable is used for CP0 cores synchronisation in kernel_init()
115__attribute__((section(".kdata")))
116remote_barrier_t global_barrier CONFIG_CACHE_LINE_ALIGNED;
117
118// This variable is used for local cores synchronisation in kernel_init()
119__attribute__((section(".kdata")))
120barrier_t local_barrier CONFIG_CACHE_LINE_ALIGNED;
121
122// This variable defines the array of supported File System contexts
123__attribute__((section(".kdata")))
124vfs_ctx_t fs_context[FS_TYPES_NR] CONFIG_CACHE_LINE_ALIGNED;
125
126// kernel_init is the entry point defined in hal/tsar_mips32/kernel.ld
127// It will be used by the bootloader.
128extern void kernel_init( boot_info_t * info );
129
130// these debug variables are used to analyse the sys_read() syscall timing
131
132#if DEBUG_SYS_READ
133uint32_t enter_sys_read;
134uint32_t exit_sys_read;
135
136uint32_t enter_devfs_read;
137uint32_t exit_devfs_read;
138
139uint32_t enter_txt_read;
140uint32_t exit_txt_read;
141
142uint32_t enter_chdev_cmd_read;
143uint32_t exit_chdev_cmd_read;
144
145uint32_t enter_chdev_server_read;
146uint32_t exit_chdev_server_read;
147
148uint32_t enter_tty_cmd_read;
149uint32_t exit_tty_cmd_read;
150
151uint32_t enter_tty_isr_read;
152uint32_t exit_tty_isr_read;
153#endif
154
155// these debug variables are used to analyse the sys_write() syscall timing
156
157#if DEBUG_SYS_WRITE
158uint32_t enter_sys_write;
159uint32_t exit_sys_write;
160
161uint32_t enter_devfs_write;
162uint32_t exit_devfs_write;
163
164uint32_t enter_txt_write;
165uint32_t exit_txt_write;
166
167uint32_t enter_chdev_cmd_write;
168uint32_t exit_chdev_cmd_write;
169
170uint32_t enter_chdev_server_write;
171uint32_t exit_chdev_server_write;
172
173uint32_t enter_tty_cmd_write;
174uint32_t exit_tty_cmd_write;
175
176uint32_t enter_tty_isr_write;
177uint32_t exit_tty_isr_write;
178#endif
179
180///////////////////////////////////////////////////////////////////////////////////////////
181// This function displays the ALMOS_MKH banner.
182///////////////////////////////////////////////////////////////////////////////////////////
183static void print_banner( uint32_t nclusters , uint32_t ncores )
184{
185 printk("\n"
186 " _ __ __ _____ ______ __ __ _ __ _ _ \n"
187 " /\\ | | | \\ / | / ___ \\ / _____| | \\ / | | | / / | | | | \n"
188 " / \\ | | | \\/ | | / \\ | | / | \\/ | | |/ / | | | | \n"
189 " / /\\ \\ | | | |\\ /| | | | | | | |_____ ___ | |\\ /| | | / | |___| | \n"
190 " / /__\\ \\ | | | | \\/ | | | | | | \\_____ \\ |___| | | \\/ | | | \\ | ___ | \n"
191 " / ______ \\ | | | | | | | | | | | | | | | | | |\\ \\ | | | | \n"
192 " / / \\ \\ | |____ | | | | | \\___/ | _____/ | | | | | | | \\ \\ | | | | \n"
193 " /_/ \\_\\ |______| |_| |_| \\_____/ |______/ |_| |_| |_| \\_\\ |_| |_| \n"
194 "\n\n\t\t Advanced Locality Management Operating System / Multi Kernel Hybrid\n"
195 "\n\n\t\t %s / %d cluster(s) / %d core(s) per cluster\n\n",
196 CONFIG_ALMOS_VERSION , nclusters , ncores );
197}
198
199
200///////////////////////////////////////////////////////////////////////////////////////////
201// This function initializes the TXT0 chdev descriptor, that is the "kernel terminal",
202// shared by all kernel instances for debug messages.
203// It is a global variable (replicated in all clusters), because this terminal is used
204// before the kmem allocator initialisation, but only the instance in cluster containing
205// the calling core is registered in the "chdev_dir" directory.
206// As this TXT0 chdev supports only the TXT_SYNC_WRITE command, we don't create
207// a server thread, we don't allocate a WTI, and we don't initialize the waiting queue.
208///////////////////////////////////////////////////////////////////////////////////////////
209// @ info : pointer on the local boot-info structure.
210///////////////////////////////////////////////////////////////////////////////////////////
211static void txt0_device_init( boot_info_t * info )
212{
213 boot_device_t * dev_tbl; // pointer on array of devices in boot_info
214 uint32_t dev_nr; // actual number of devices in this cluster
215 xptr_t base; // remote pointer on segment base
216 uint32_t func; // device functional index
217 uint32_t impl; // device implementation index
218 uint32_t i; // device index in dev_tbl
219 uint32_t x; // X cluster coordinate
220 uint32_t y; // Y cluster coordinate
221 uint32_t channels; // number of channels
222
223 // get number of peripherals and base of devices array from boot_info
224 dev_nr = info->ext_dev_nr;
225 dev_tbl = info->ext_dev;
226
227 // loop on external peripherals to find TXT device
228 for( i = 0 ; i < dev_nr ; i++ )
229 {
230 base = dev_tbl[i].base;
231 func = FUNC_FROM_TYPE( dev_tbl[i].type );
232 impl = IMPL_FROM_TYPE( dev_tbl[i].type );
233 channels = dev_tbl[i].channels;
234
235 if (func == DEV_FUNC_TXT )
236 {
237 assert( (channels > 0) , "number of TXT channels cannot be 0\n");
238
239 // initializes TXT_TX[0] chdev
240 txt0_chdev.func = func;
241 txt0_chdev.impl = impl;
242 txt0_chdev.channel = 0;
243 txt0_chdev.base = base;
244 txt0_chdev.is_rx = false;
245
246 // initializes lock
247 remote_spinlock_init( XPTR( local_cxy , &txt0_chdev.wait_lock ) );
248
249 // TXT specific initialisation:
250 // no server thread & no IRQ routing for channel 0
251 dev_txt_init( &txt0_chdev );
252
253 // register the TXT0 in all chdev_dir[x][y] structures
254 for( x = 0 ; x < info->x_size ; x++ )
255 {
256 for( y = 0 ; y < info->y_max; y++ ) // [FIXME]
257 {
258 cxy_t cxy = (x<<info->y_width) + y;
259 hal_remote_swd( XPTR( cxy , &chdev_dir.txt_tx[0] ) ,
260 XPTR( local_cxy , &txt0_chdev ) );
261 }
262 }
263 }
264 } // end loop on devices
265} // end txt0_device_init()
266
267///////////////////////////////////////////////////////////////////////////////////////////
268// This function is the same as txt0_device_init() but uses the internal multi_tty device
269// attached to cluster (0,0) instead of the external tty_tsar.
270// This function is used instead of txt0_device_init() only for TSAR LETI.
271///////////////////////////////////////////////////////////////////////////////////////////
272// @ info : pointer on the local boot-info structure.
273///////////////////////////////////////////////////////////////////////////////////////////
274static void mtty0_device_init( boot_info_t * info)
275{
276 boot_device_t * dev_tbl; // pointer on array of devices in boot_info
277 uint32_t dev_nr; // actual number of devices in this cluster
278 xptr_t base; // remote pointer on segment base
279 uint32_t func; // device functional index
280 uint32_t impl; // device implementation index
281 uint32_t i; // device index in dev_tbl
282 uint32_t x; // X cluster coordinate
283 uint32_t y; // Y cluster coordinate
284
285 dev_nr = info->int_dev_nr;
286 dev_tbl = info->int_dev;
287
288 // Initialize spinlock for writing to MTY0
289 spinlock_init(&txt0_lock);
290
291 // Loop on internal peripherals of cluster (0,0) to find MTY0
292 for ( i = 0; i < dev_nr; i++ )
293 {
294 base = dev_tbl[i].base;
295 func = FUNC_FROM_TYPE( dev_tbl[i].type );
296 impl = IMPL_FROM_TYPE( dev_tbl[i].type );
297
298 if ( func == DEV_FUNC_TXT )
299 {
300 txt0_chdev.func = func;
301 txt0_chdev.impl = impl;
302 txt0_chdev.channel = 0;
303 txt0_chdev.base = base;
304 txt0_chdev.is_rx = false;
305
306 // Initialize MTY0 chdev lock
307 remote_spinlock_init( XPTR( local_cxy, &txt0_chdev.wait_lock ) );
308
309 // MTY specific initialization
310 dev_txt_init( &txt0_chdev );
311
312 // register the MTY in all chdev_dir[x][y] structures
313 for( x = 0 ; x < info->x_size ; x++ )
314 {
315 for( y = 0 ; y < info->y_max; y++ ) // [FIXME]
316 {
317 cxy_t cxy = (x<<info->y_width) + y;
318 hal_remote_swd( XPTR( cxy , &chdev_dir.txt_tx[0] ) ,
319 XPTR( local_cxy , &txt0_chdev ) );
320 }
321 }
322 }
323 } // end loop on internal devices
324} // end mty0_device_init()
325
326///////////////////////////////////////////////////////////////////////////////////////////
327// This function allocates memory and initializes the chdev descriptors for the internal
328// peripherals contained in the local cluster, other than the LAPIC, as specified by
329// the boot_info, including the linking with the driver for the specified implementation.
330// The relevant entries in all copies of the devices directory are initialised.
331///////////////////////////////////////////////////////////////////////////////////////////
332// @ info : pointer on the local boot-info structure.
333///////////////////////////////////////////////////////////////////////////////////////////
334static void internal_devices_init( boot_info_t * info )
335{
336 boot_device_t * dev_tbl; // pointer on array of internaldevices in boot_info
337 uint32_t dev_nr; // actual number of devices in this cluster
338 xptr_t base; // remote pointer on segment base
339 uint32_t func; // device functionnal index
340 uint32_t impl; // device implementation index
341 uint32_t i; // device index in dev_tbl
342 uint32_t x; // X cluster coordinate
343 uint32_t y; // Y cluster coordinate
344 uint32_t channels; // number of channels
345 uint32_t channel; // channel index
346 chdev_t * chdev_ptr; // local pointer on created chdev
347
348 // get number of internal peripherals and base from boot_info
349 dev_nr = info->int_dev_nr;
350 dev_tbl = info->int_dev;
351
352 // loop on internal peripherals
353 for( i = 0 ; i < dev_nr ; i++ )
354 {
355 base = dev_tbl[i].base;
356 channels = dev_tbl[i].channels;
357 func = FUNC_FROM_TYPE( dev_tbl[i].type );
358 impl = IMPL_FROM_TYPE( dev_tbl[i].type );
359
360 //////////////////////////
361 if( func == DEV_FUNC_MMC )
362 {
363 assert( (channels == 1) , "MMC device must be single channel\n" );
364
365 // create chdev in local cluster
366 chdev_ptr = chdev_create( func,
367 impl,
368 0, // channel
369 false, // direction
370 base );
371
372 assert( (chdev_ptr != NULL) ,
373 "cannot allocate memory for MMC chdev\n" );
374
375 // make MMC specific initialisation
376 dev_mmc_init( chdev_ptr );
377
378 // set the MMC field in all chdev_dir[x][y] structures
379 for( x = 0 ; x < info->x_size ; x++ )
380 {
381 for( y = 0 ; y < info->y_max; y++ ) // [FIXME]
382 {
383 cxy_t cxy = (x<<info->y_width) + y;
384 hal_remote_swd( XPTR( cxy , &chdev_dir.mmc[local_cxy] ),
385 XPTR( local_cxy , chdev_ptr ) );
386 }
387 }
388
389#if( DEBUG_KERNEL_INIT & 0x1 )
390if( hal_time_stamp() > DEBUG_KERNEL_INIT )
391printk("\n[DBG] %s : created MMC in cluster %x / chdev = %x\n",
392__FUNCTION__ , local_cxy , chdev_ptr );
393#endif
394 }
395 ///////////////////////////////
396 else if( func == DEV_FUNC_DMA )
397 {
398 // create one chdev per channel in local cluster
399 for( channel = 0 ; channel < channels ; channel++ )
400 {
401 // create chdev[channel] in local cluster
402 chdev_ptr = chdev_create( func,
403 impl,
404 channel,
405 false, // direction
406 base );
407
408 assert( (chdev_ptr != NULL) , "cannot allocate memory for DMA chdev" );
409
410 // make DMA specific initialisation
411 dev_dma_init( chdev_ptr );
412
413 // initialize only the DMA[channel] field in the local chdev_dir[x][y]
414 // structure because the DMA device is not remotely accessible.
415 chdev_dir.dma[channel] = XPTR( local_cxy , chdev_ptr );
416
417#if( DEBUG_KERNEL_INIT & 0x1 )
418if( hal_time_stamp() > DEBUG_KERNEL_INIT )
419printk("\n[DBG] %s : created DMA[%d] in cluster %x / chdev = %x\n",
420__FUNCTION__ , channel , local_cxy , chdev_ptr );
421#endif
422 }
423 }
424
425 else if ( func == DEV_FUNC_TXT && info->use_mty0 == 1 )
426 {
427 assert(impl == IMPL_TXT_MTY,
428 "Internal TTYs should have MTY implementation\n");
429
430 for ( channel = 0; channel < channels; channel++ )
431 {
432 int rx;
433 for ( rx = 0; rx <= 1; rx++ )
434 {
435 // skip MTY0_TX since it has already been initialized
436 if ( channel == 0 && rx == 0 ) continue;
437
438 // create chdev in local cluster
439 chdev_ptr = chdev_create( func,
440 impl,
441 channel,
442 rx,
443 base );
444
445 assert( (chdev_ptr != NULL) ,
446 "cannot allocate memory for MTY chdev" );
447
448 // make MTY specific initialization
449 dev_txt_init( chdev_ptr );
450
451 // set the MTY fields in all clusters
452 xptr_t *chdev_entry;
453 if ( rx == 1 ) {
454 chdev_entry = &chdev_dir.txt_rx[channel];
455 } else {
456 chdev_entry = &chdev_dir.txt_tx[channel];
457 }
458 for ( x = 0; x < info->x_max; x++ )
459 {
460 for ( y = 0; y < info->y_max; y++ )
461 {
462 cxy_t cxy = (x<<info->y_width) + y;
463 hal_remote_swd( XPTR( cxy, chdev_entry ),
464 XPTR( local_cxy, chdev_ptr ) );
465 }
466 }
467 }
468 }
469 }
470 }
471} // end internal_devices_init()
472
473///////////////////////////////////////////////////////////////////////////////////////////
474// This function allocates memory and initializes the chdev descriptors for the
475// external (shared) peripherals other than the IOPIC, as specified by the boot_info.
476// This includes the dynamic linking with the driver for the specified implementation.
477// These chdev descriptors are distributed on all clusters, using a modulo on a global
478// index, identically computed in all clusters.
479// This function is executed in all clusters by the CP0 core, that computes a global index
480// for all external chdevs. Each CP0 core creates only the chdevs that must be placed in
481// the local cluster, because the global index matches the local index.
482// The relevant entries in all copies of the devices directory are initialised.
483///////////////////////////////////////////////////////////////////////////////////////////
484// @ info : pointer on the local boot-info structure.
485///////////////////////////////////////////////////////////////////////////////////////////
486static void external_devices_init( boot_info_t * info )
487{
488 boot_device_t * dev_tbl; // pointer on array of external devices in boot_info
489 uint32_t dev_nr; // actual number of external devices
490 xptr_t base; // remote pointer on segment base
491 uint32_t func; // device functionnal index
492 uint32_t impl; // device implementation index
493 uint32_t i; // device index in dev_tbl
494 uint32_t x; // X cluster coordinate
495 uint32_t y; // Y cluster coordinate
496 uint32_t channels; // number of channels
497 uint32_t channel; // channel index
498 uint32_t directions; // number of directions (1 or 2)
499 uint32_t rx; // direction index (0 or 1)
500 chdev_t * chdev; // local pointer on one channel_device descriptor
501 uint32_t ext_chdev_gid; // global index of external chdev
502
503 // get number of peripherals and base of devices array from boot_info
504 dev_nr = info->ext_dev_nr;
505 dev_tbl = info->ext_dev;
506
507 // initializes global index (PIC is already placed in cluster 0
508 ext_chdev_gid = 1;
509
510 // loop on external peripherals
511 for( i = 0 ; i < dev_nr ; i++ )
512 {
513 base = dev_tbl[i].base;
514 channels = dev_tbl[i].channels;
515 func = FUNC_FROM_TYPE( dev_tbl[i].type );
516 impl = IMPL_FROM_TYPE( dev_tbl[i].type );
517
518 // There is one chdev per direction for NIC and for TXT
519 if((func == DEV_FUNC_NIC) || (func == DEV_FUNC_TXT)) directions = 2;
520 else directions = 1;
521
522 // do nothing for ROM, that does not require a device descriptor.
523 if( func == DEV_FUNC_ROM ) continue;
524
525 // do nothing for PIC, that is already initialized
526 if( func == DEV_FUNC_PIC ) continue;
527
528 // check PIC device initialized
529 assert( (chdev_dir.pic != XPTR_NULL ) ,
530 "PIC device must be initialized before other devices\n" );
531
532 // check external device functionnal type
533 assert( ( (func == DEV_FUNC_IOB) ||
534 (func == DEV_FUNC_IOC) ||
535 (func == DEV_FUNC_TXT) ||
536 (func == DEV_FUNC_NIC) ||
537 (func == DEV_FUNC_FBF) ) ,
538 "undefined external peripheral type\n" );
539
540 // loops on channels
541 for( channel = 0 ; channel < channels ; channel++ )
542 {
543 // loop on directions
544 for( rx = 0 ; rx < directions ; rx++ )
545 {
546 // skip TXT_TX[0] chdev that has already been created & registered
547 if( info->use_mty0 == 0 && (func == DEV_FUNC_TXT) && (channel == 0) && (rx == 0) )
548 {
549 continue;
550 }
551
552 // skip TXT chdevs because they are initialized in internal_devices_init()
553 if ( info->use_mty0 == 1 && func == DEV_FUNC_TXT )
554 {
555 continue;
556 }
557
558 // compute target cluster for chdev[func,channel,direction]
559 uint32_t offset = ext_chdev_gid % ( info->x_size * (info->y_max) ); // [FIXME]
560 uint32_t cx = offset / (info->y_max); // [FIXME]
561 uint32_t cy = offset % (info->y_max); // [FIXME]
562 uint32_t target_cxy = (cx<<info->y_width) + cy;
563
564 // allocate and initialize a local chdev
565 // when local cluster matches target cluster
566 if( target_cxy == local_cxy )
567 {
568 chdev = chdev_create( func,
569 impl,
570 channel,
571 rx, // direction
572 base );
573
574 assert( (chdev != NULL),
575 "cannot allocate external device" );
576
577 // make device type specific initialisation
578 if ( func == DEV_FUNC_IOB ) dev_iob_init( chdev );
579 else if( func == DEV_FUNC_IOC ) dev_ioc_init( chdev );
580 else if( func == DEV_FUNC_TXT ) dev_txt_init( chdev );
581 else if( func == DEV_FUNC_NIC ) dev_nic_init( chdev );
582 else if( func == DEV_FUNC_FBF ) dev_fbf_init( chdev );
583
584 // all external (shared) devices are remotely accessible
585 // initialize the replicated chdev_dir[x][y] structures
586 // defining the extended pointers on chdev descriptors
587 xptr_t * entry;
588
589 if(func==DEV_FUNC_IOB ) entry = &chdev_dir.iob;
590 if(func==DEV_FUNC_IOC ) entry = &chdev_dir.ioc[channel];
591 if(func==DEV_FUNC_FBF ) entry = &chdev_dir.fbf[channel];
592 if((func==DEV_FUNC_TXT) && (rx==0)) entry = &chdev_dir.txt_tx[channel];
593 if((func==DEV_FUNC_TXT) && (rx==1)) entry = &chdev_dir.txt_rx[channel];
594 if((func==DEV_FUNC_NIC) && (rx==0)) entry = &chdev_dir.nic_tx[channel];
595 if((func==DEV_FUNC_NIC) && (rx==1)) entry = &chdev_dir.nic_rx[channel];
596
597 for( x = 0 ; x < info->x_size ; x++ )
598 {
599 for( y = 0 ; y < info->y_max; y++ ) // [FIXME]
600 {
601 cxy_t cxy = (x<<info->y_width) + y;
602 hal_remote_swd( XPTR( cxy , entry ),
603 XPTR( local_cxy , chdev ) );
604 }
605 }
606
607#if( DEBUG_KERNEL_INIT & 0x1 )
608if( hal_time_stamp() > DEBUG_KERNEL_INIT )
609printk("\n[DBG] %s : create chdev %s / channel = %d / rx = %d / cluster %x / chdev = %x\n",
610__FUNCTION__ , chdev_func_str( func ), channel , rx , local_cxy , chdev );
611#endif
612 } // end if match
613
614 // increment chdev global index (matching or not)
615 ext_chdev_gid++;
616
617 } // end loop on directions
618 } // end loop on channels
619 } // end loop on devices
620} // end external_devices_init()
621
622///////////////////////////////////////////////////////////////////////////////////////////
623// This function is called by CP0 in cluster 0 to allocate memory and initialize the PIC
624// device, namely the informations attached to the external IOPIC controller, that
625// must be replicated in all clusters (struct iopic_input).
626// This initialisation must be done before other devices initialisation because the IRQ
627// routing infrastructure is required for both internal and external devices init.
628///////////////////////////////////////////////////////////////////////////////////////////
629// @ info : pointer on the local boot-info structure.
630///////////////////////////////////////////////////////////////////////////////////////////
631static void iopic_init( boot_info_t * info )
632{
633 boot_device_t * dev_tbl; // pointer on boot_info external devices array
634 uint32_t dev_nr; // actual number of external devices
635 xptr_t base; // remote pointer on segment base
636 uint32_t func; // device functionnal index
637 uint32_t impl; // device implementation index
638 uint32_t i; // device index in dev_tbl
639 uint32_t x; // cluster X coordinate
640 uint32_t y; // cluster Y coordinate
641 bool_t found; // IOPIC found
642 chdev_t * chdev; // pointer on PIC chdev descriptor
643
644 // get number of external peripherals and base of array from boot_info
645 dev_nr = info->ext_dev_nr;
646 dev_tbl = info->ext_dev;
647
648 // loop on external peripherals to get the IOPIC
649 for( i = 0 , found = false ; i < dev_nr ; i++ )
650 {
651 func = FUNC_FROM_TYPE( dev_tbl[i].type );
652
653 if( func == DEV_FUNC_PIC )
654 {
655 base = dev_tbl[i].base;
656 impl = IMPL_FROM_TYPE( dev_tbl[i].type );
657 found = true;
658 break;
659 }
660 }
661
662 assert( found , "PIC device not found\n" );
663
664 // allocate and initialize the PIC chdev in cluster 0
665 chdev = chdev_create( DEV_FUNC_PIC,
666 impl,
667 0, // channel
668 0, // direction,
669 base );
670
671 assert( (chdev != NULL), "no memory for PIC chdev\n" );
672
673 // make PIC device type specific initialisation
674 dev_pic_init( chdev );
675
676 // register, in all clusters, the extended pointer
677 // on PIC chdev in "chdev_dir" array
678 xptr_t * entry = &chdev_dir.pic;
679
680 for( x = 0 ; x < info->x_size ; x++ )
681 {
682 for( y = 0 ; y < info->y_max; y++ ) // [FIXME]
683 {
684 cxy_t cxy = (x<<info->y_width) + y;
685 hal_remote_swd( XPTR( cxy , entry ) ,
686 XPTR( local_cxy , chdev ) );
687 }
688 }
689
690 // initialize, in all clusters, the "iopic_input" structure
691 // defining how external IRQs are connected to IOPIC
692
693 // register default value for unused inputs
694 for( x = 0 ; x < info->x_size ; x++ )
695 {
696 for( y = 0 ; y < info->y_max; y++ ) // [FIXME]
697 {
698 cxy_t cxy = (x<<info->y_width) + y;
699 hal_remote_memset( XPTR( cxy , &iopic_input ) , 0xFF , sizeof(iopic_input_t) );
700 }
701 }
702
703 // register input IRQ index for valid inputs
704 uint32_t id; // input IRQ index
705 uint8_t valid; // input IRQ is connected
706 uint32_t type; // source device type
707 uint8_t channel; // source device channel
708 uint8_t is_rx; // source device direction
709 uint32_t * ptr; // local pointer on one field in iopic_input stucture
710
711 for( id = 0 ; id < CONFIG_MAX_EXTERNAL_IRQS ; id++ )
712 {
713 valid = dev_tbl[i].irq[id].valid;
714 type = dev_tbl[i].irq[id].dev_type;
715 channel = dev_tbl[i].irq[id].channel;
716 is_rx = dev_tbl[i].irq[id].is_rx;
717 func = FUNC_FROM_TYPE( type );
718
719 // get pointer on relevant field in iopic_input
720 if( valid )
721 {
722 if ( func == DEV_FUNC_IOC ) ptr = &iopic_input.ioc[channel];
723 else if((func == DEV_FUNC_TXT) && (is_rx == 0)) ptr = &iopic_input.txt_tx[channel];
724 else if((func == DEV_FUNC_TXT) && (is_rx != 0)) ptr = &iopic_input.txt_rx[channel];
725 else if((func == DEV_FUNC_NIC) && (is_rx == 0)) ptr = &iopic_input.nic_tx[channel];
726 else if((func == DEV_FUNC_NIC) && (is_rx != 0)) ptr = &iopic_input.nic_rx[channel];
727 else if( func == DEV_FUNC_IOB ) ptr = &iopic_input.iob;
728 else assert( false , "illegal source device for IOPIC input" );
729
730 // set one entry in all "iopic_input" structures
731 for( x = 0 ; x < info->x_size ; x++ )
732 {
733 for( y = 0 ; y < info->y_max; y++ ) // [FIXME]
734 {
735 cxy_t cxy = (x<<info->y_width) + y;
736 hal_remote_swd( XPTR( cxy , ptr ) , id );
737 }
738 }
739 }
740 }
741
742#if( DEBUG_KERNEL_INIT & 0x1 )
743if( hal_time_stamp() > DEBUG_KERNEL_INIT )
744{
745 printk("\n[DBG] %s created PIC chdev in cluster %x at cycle %d\n",
746 __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
747 dev_pic_inputs_display();
748}
749#endif
750
751} // end iopic_init()
752
753///////////////////////////////////////////////////////////////////////////////////////////
754// This function is called by all CP0s in all cluster to complete the PIC device
755// initialisation, namely the informations attached to the LAPIC controller.
756// This initialisation must be done after the IOPIC initialisation, but before other
757// devices initialisation because the IRQ routing infrastructure is required for both
758// internal and external devices initialisation.
759///////////////////////////////////////////////////////////////////////////////////////////
760// @ info : pointer on the local boot-info structure.
761///////////////////////////////////////////////////////////////////////////////////////////
762static void lapic_init( boot_info_t * info )
763{
764 boot_device_t * dev_tbl; // pointer on boot_info internal devices array
765 uint32_t dev_nr; // number of internal devices
766 uint32_t i; // device index in dev_tbl
767 xptr_t base; // remote pointer on segment base
768 uint32_t func; // device functionnal type in boot_info
769 bool_t found; // LAPIC found
770
771 // get number of internal peripherals and base
772 dev_nr = info->int_dev_nr;
773 dev_tbl = info->int_dev;
774
775 // loop on internal peripherals to get the lapic device
776 for( i = 0 , found = false ; i < dev_nr ; i++ )
777 {
778 func = FUNC_FROM_TYPE( dev_tbl[i].type );
779
780 if( func == DEV_FUNC_ICU )
781 {
782 base = dev_tbl[i].base;
783 found = true;
784 break;
785 }
786 }
787
788 // if the LAPIC controller is not defined in the boot_info,
789 // we simply don't initialize the PIC extensions in the kernel,
790 // making the assumption that the LAPIC related informations
791 // are hidden in the hardware specific PIC driver.
792 if( found )
793 {
794 // initialise the PIC extensions for
795 // the core descriptor and core manager extensions
796 dev_pic_extend_init( (uint32_t *)GET_PTR( base ) );
797
798 // initialize the "lapic_input" structure
799 // defining how internal IRQs are connected to LAPIC
800 uint32_t id;
801 uint8_t valid;
802 uint8_t channel;
803 uint32_t func;
804
805 for( id = 0 ; id < CONFIG_MAX_INTERNAL_IRQS ; id++ )
806 {
807 valid = dev_tbl[i].irq[id].valid;
808 func = FUNC_FROM_TYPE( dev_tbl[i].irq[id].dev_type );
809 channel = dev_tbl[i].irq[id].channel;
810
811 if( valid ) // only valid local IRQs are registered
812 {
813 if ( func == DEV_FUNC_MMC ) lapic_input.mmc = id;
814 else if( func == DEV_FUNC_DMA ) lapic_input.dma[channel] = id;
815 else if( func == DEV_FUNC_TXT ) lapic_input.mtty = id;
816 else assert( false , "illegal source device for LAPIC input" );
817 }
818 }
819 }
820} // end lapic_init()
821
822///////////////////////////////////////////////////////////////////////////////////////////
823// This static function returns the identifiers of the calling core.
824///////////////////////////////////////////////////////////////////////////////////////////
825// @ info : pointer on boot_info structure.
826// @ lid : [out] core local index in cluster.
827// @ cxy : [out] cluster identifier.
828// @ lid : [out] core global identifier (hardware).
829// @ return 0 if success / return EINVAL if not found.
830///////////////////////////////////////////////////////////////////////////////////////////
831static error_t get_core_identifiers( boot_info_t * info,
832 lid_t * lid,
833 cxy_t * cxy,
834 gid_t * gid )
835{
836 uint32_t i;
837 gid_t global_id;
838
839 // get global identifier from hardware register
840 global_id = hal_get_gid();
841
842 // makes an associative search in boot_info to get (cxy,lid) from global_id
843 for( i = 0 ; i < info->cores_nr ; i++ )
844 {
845 if( global_id == info->core[i].gid )
846 {
847 *lid = info->core[i].lid;
848 *cxy = info->core[i].cxy;
849 *gid = global_id;
850 return 0;
851 }
852 }
853 return EINVAL;
854}
855
856///////////////////////////////////////////////////////////////////////////////////////////
857// This function is the entry point for the kernel initialisation.
858// It is executed by all cores in all clusters, but only core[0], called CP0,
859// initializes the shared resources such as the cluster manager, or the local peripherals.
860// To comply with the multi-kernels paradigm, it accesses only local cluster memory, using
861// only information contained in the local boot_info_t structure, set by the bootloader.
862// Only CP0 in cluster 0 print the log messages.
863///////////////////////////////////////////////////////////////////////////////////////////
864// @ info : pointer on the local boot-info structure.
865///////////////////////////////////////////////////////////////////////////////////////////
866void kernel_init( boot_info_t * info )
867{
868 lid_t core_lid = -1; // running core local index
869 cxy_t core_cxy = -1; // running core cluster identifier
870 gid_t core_gid; // running core hardware identifier
871 cluster_t * cluster; // pointer on local cluster manager
872 core_t * core; // pointer on running core descriptor
873 thread_t * thread; // pointer on idle thread descriptor
874
875 xptr_t vfs_root_inode_xp; // extended pointer on VFS root inode
876 xptr_t devfs_dev_inode_xp; // extended pointer on DEVFS dev inode
877 xptr_t devfs_external_inode_xp; // extended pointer on DEVFS external inode
878 xptr_t devfs_internal_inode_xp; // extended pointer on DEVFS internal inode
879
880 error_t error;
881 reg_t status; // running core status register
882
883 /////////////////////////////////////////////////////////////////////////////////
884 // STEP 0 : Each core get its core identifier from boot_info, and makes
885 // a partial initialisation of its private idle thread descriptor.
886 // CP0 initializes the "local_cxy" global variable.
887 // CP0 in cluster IO initializes the TXT0 chdev to print log messages.
888 /////////////////////////////////////////////////////////////////////////////////
889
890 error = get_core_identifiers( info,
891 &core_lid,
892 &core_cxy,
893 &core_gid );
894
895 // CP0 initializes cluster identifier
896 if( core_lid == 0 ) local_cxy = info->cxy;
897
898 // each core gets a pointer on its private idle thread descriptor
899 thread = (thread_t *)( idle_threads + (core_lid * CONFIG_THREAD_DESC_SIZE) );
900
901 // each core registers this thread pointer in hardware register
902 hal_set_current_thread( thread );
903
904 // each core register core descriptor pointer in idle thread descriptor
905 thread->core = &LOCAL_CLUSTER->core_tbl[core_lid];
906
907 // each core initializes the idle thread lists of locks
908 list_root_init( &thread->locks_root );
909 xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) );
910 thread->local_locks = 0;
911 thread->remote_locks = 0;
912
913 // CP0 in cluster 0 initializes TXT0 chdev descriptor
914 if( core_cxy == 0 && core_lid == 0 ) // [MODIF]
915 {
916 if( info->use_mty0 == 1 ) {
917 mtty0_device_init( info );
918 } else {
919 txt0_device_init( info );
920 }
921 }
922 // [FIXME]
923
924 /////////////////////////////////////////////////////////////////////////////////
925 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
926 (info->x_size * (info->y_max)) );
927 barrier_wait( &local_barrier , info->cores_nr );
928 /////////////////////////////////////////////////////////////////////////////////
929
930#if DEBUG_KERNEL_INIT
931if( (core_lid == 0) & (local_cxy == 0) )
932printk("\n[DBG] %s : exit barrier 0 : TXT0 initialized / cycle %d\n",
933__FUNCTION__, (uint32_t)hal_get_cycles() );
934#endif
935
936 /////////////////////////////////////////////////////////////////////////////
937 // STEP 1 : all cores check core identifier.
938 // CP0 initializes the local cluster manager.
939 // This includes the memory allocators.
940 /////////////////////////////////////////////////////////////////////////////
941
942 // all cores check identifiers
943 if( error )
944 {
945 assert( false ,
946 "illegal core identifiers gid = %x / cxy = %x / lid = %d",
947 core_lid , core_cxy , core_lid );
948 }
949
950 // CP0 initializes cluster manager
951 if( core_lid == 0 )
952 {
953 error = cluster_init( info );
954
955 if( error )
956 {
957 assert( false ,
958 "cannot initialise cluster %x", local_cxy );
959 }
960 }
961
962 /////////////////////////////////////////////////////////////////////////////////
963 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
964 (info->x_size * (info->y_max)) );
965 barrier_wait( &local_barrier , info->cores_nr );
966 /////////////////////////////////////////////////////////////////////////////////
967
968#if DEBUG_KERNEL_INIT
969if( (core_lid == 0) & (local_cxy == 0) )
970printk("\n[DBG] %s : exit barrier 1 : clusters initialised / cycle %d\n",
971__FUNCTION__, (uint32_t)hal_get_cycles() );
972#endif
973
974 /////////////////////////////////////////////////////////////////////////////////
975 // STEP 2 : CP0 initializes the process_zero descriptor.
976 // CP0 in cluster 0 initializes the IOPIC device.
977 /////////////////////////////////////////////////////////////////////////////////
978
979 // all cores get pointer on local cluster manager & core descriptor
980 cluster = &cluster_manager;
981 core = &cluster->core_tbl[core_lid];
982
983 // all CP0s initialize the process_zero descriptor
984 if( core_lid == 0 ) process_zero_create( &process_zero );
985
986 // CP0 in cluster 0 initializes the PIC chdev,
987 if( (core_lid == 0) && (local_cxy == 0) ) iopic_init( info );
988
989 ////////////////////////////////////////////////////////////////////////////////
990 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
991 (info->x_size * (info->y_max)) );
992 barrier_wait( &local_barrier , info->cores_nr );
993 ////////////////////////////////////////////////////////////////////////////////
994
995#if DEBUG_KERNEL_INIT
996if( (core_lid == 0) & (local_cxy == 0) )
997printk("\n[DBG] %s : exit barrier 2 : PIC initialised / cycle %d\n",
998__FUNCTION__, (uint32_t)hal_get_cycles() );
999#endif
1000
1001 ////////////////////////////////////////////////////////////////////////////////
1002 // STEP 3 : CP0 initializes the distibuted LAPIC descriptor.
1003 // CP0 initializes the internal chdev descriptors
1004 // CP0 initialize the local external chdev descriptors
1005 ////////////////////////////////////////////////////////////////////////////////
1006
1007 // all CP0s initialize their local LAPIC extension,
1008 if( core_lid == 0 ) lapic_init( info );
1009
1010 // CP0 scan the internal (private) peripherals,
1011 // and allocates memory for the corresponding chdev descriptors.
1012 if( core_lid == 0 ) internal_devices_init( info );
1013
1014
1015 // All CP0s contribute to initialise external peripheral chdev descriptors.
1016 // Each CP0[cxy] scan the set of external (shared) peripherals (but the TXT0),
1017 // and allocates memory for the chdev descriptors that must be placed
1018 // on the (cxy) cluster according to the global index value.
1019
1020 if( core_lid == 0 ) external_devices_init( info );
1021
1022 /////////////////////////////////////////////////////////////////////////////////
1023 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
1024 (info->x_size * (info->y_max)) );
1025 barrier_wait( &local_barrier , info->cores_nr );
1026 /////////////////////////////////////////////////////////////////////////////////
1027
1028#if DEBUG_KERNEL_INIT
1029if( (core_lid == 0) & (local_cxy == 0) )
1030printk("\n[DBG] %s : exit barrier 3 : all chdev initialised / cycle %d\n",
1031__FUNCTION__, (uint32_t)hal_get_cycles() );
1032#endif
1033
1034#if( DEBUG_KERNEL_INIT & 1 )
1035if( (core_lid == 0) & (local_cxy == 0) )
1036chdev_dir_display();
1037#endif
1038
1039 /////////////////////////////////////////////////////////////////////////////////
1040 // STEP 4 : All cores enable IPI (Inter Procesor Interrupt),
1041 // Alh cores initialize IDLE thread.
1042 // Only CP0 in cluster 0 creates the VFS root inode.
1043 // It access the boot device to initialize the file system context.
1044 /////////////////////////////////////////////////////////////////////////////////
1045
1046 // All cores enable the shared IPI channel
1047 dev_pic_enable_ipi();
1048 hal_enable_irq( &status );
1049
1050#if DEBUG_KERNEL_INIT
1051printk("\n[DBG] %s: IPI enabled for core %d cluster %d\n", __FUNCTION__,
1052 core_lid, local_cxy);
1053#endif
1054
1055 // all cores initialize the idle thread descriptor
1056 thread_idle_init( thread,
1057 THREAD_IDLE,
1058 &thread_idle_func,
1059 NULL,
1060 core_lid );
1061
1062 // all cores unblock idle thread, and register it in scheduler
1063 thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
1064 core->scheduler.idle = thread;
1065
1066#if( DEBUG_KERNEL_INIT & 1 )
1067sched_display( core_lid );
1068#endif
1069
1070 // CPO in cluster 0 creates the VFS root
1071 if( (core_lid == 0) && (local_cxy == 0 ) )
1072 {
1073 vfs_root_inode_xp = XPTR_NULL;
1074
1075 // File System must be FATFS in this implementation,
1076 // but other File System can be introduced here
1077 if( CONFIG_VFS_ROOT_IS_FATFS )
1078 {
1079 // 1. allocate memory for FATFS context in cluster 0
1080 fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc();
1081
1082 assert( (fatfs_ctx != NULL) ,
1083 "cannot create FATFS context in cluster 0\n" );
1084
1085 // 2. access boot device to initialize FATFS context
1086 fatfs_ctx_init( fatfs_ctx );
1087
1088 // 3. get various informations from FATFS context
1089 uint32_t root_dir_cluster = fatfs_ctx->root_dir_cluster;
1090 uint32_t cluster_size = fatfs_ctx->bytes_per_sector *
1091 fatfs_ctx->sectors_per_cluster;
1092 uint32_t total_clusters = fatfs_ctx->fat_sectors_count << 7;
1093
1094 // 4. create VFS root inode in cluster 0
1095 error = vfs_inode_create( XPTR_NULL, // dentry_xp
1096 FS_TYPE_FATFS, // fs_type
1097 INODE_TYPE_DIR, // inode_type
1098 (void *)(intptr_t)root_dir_cluster, // extend
1099 0, // attr
1100 0, // rights
1101 0, // uid
1102 0, // gid
1103 &vfs_root_inode_xp ); // return
1104
1105 assert( (error == 0) ,
1106 "cannot create VFS root inode\n" );
1107
1108 // 5. initialize VFS context for FAT in cluster 0
1109 vfs_ctx_init( FS_TYPE_FATFS, // file system type
1110 0, // attributes
1111 total_clusters,
1112 cluster_size,
1113 vfs_root_inode_xp, // VFS root
1114 fatfs_ctx ); // extend
1115
1116 // 6. check initialisation
1117 vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS];
1118 assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8),
1119 "illegal value for FATFS context in cluster %x\n", local_cxy );
1120 }
1121 else
1122 {
1123 assert( false ,
1124 "root FS must be FATFS" );
1125 }
1126
1127 // register VFS root inode in process_zero descriptor of cluster 0
1128 process_zero.vfs_root_xp = vfs_root_inode_xp;
1129 process_zero.vfs_cwd_xp = vfs_root_inode_xp;
1130 }
1131
1132 /////////////////////////////////////////////////////////////////////////////////
1133 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
1134 (info->x_size * (info->y_max)) );
1135 barrier_wait( &local_barrier , info->cores_nr );
1136 /////////////////////////////////////////////////////////////////////////////////
1137
1138#if DEBUG_KERNEL_INIT
1139if( (core_lid == 0) & (local_cxy == 0) )
1140printk("\n[DBG] %s : exit barrier 4 : VFS_root = %l in cluster 0 / cycle %d\n",
1141__FUNCTION__, vfs_root_inode_xp , (uint32_t)hal_get_cycles());
1142#endif
1143
1144 /////////////////////////////////////////////////////////////////////////////////
1145 // STEP 5 : Other CP0s allocate memory for the selected FS context,
1146 // and initialise both the local FS context and the local VFS context
1147 // from values stored in cluster 0.
1148 // They get the VFS root inode extended pointer from cluster 0.
1149 /////////////////////////////////////////////////////////////////////////////////
1150
1151 if( (core_lid == 0) && (local_cxy != 0) )
1152 {
1153 // File System must be FATFS in this implementation,
1154 // but other File System can be introduced here
1155 if( CONFIG_VFS_ROOT_IS_FATFS )
1156 {
1157 // 1. allocate memory for local FATFS context
1158 fatfs_ctx_t * local_fatfs_ctx = fatfs_ctx_alloc();
1159
1160 assert( (local_fatfs_ctx != NULL) ,
1161 "cannot create FATFS context in cluster %x\n", local_cxy );
1162
1163 // 2. get local pointer on VFS context for FATFS
1164 vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS];
1165
1166 // 3. get local pointer on FATFS context in cluster 0
1167 fatfs_ctx_t * remote_fatfs_ctx = hal_remote_lpt( XPTR( 0 , &vfs_ctx->extend ) );
1168
1169 // 4. copy FATFS context from cluster 0 to local cluster
1170 hal_remote_memcpy( XPTR( local_cxy , local_fatfs_ctx ),
1171 XPTR( 0 , remote_fatfs_ctx ), sizeof(fatfs_ctx_t) );
1172
1173 // 5. copy VFS context from cluster 0 to local cluster
1174 hal_remote_memcpy( XPTR( local_cxy , vfs_ctx ),
1175 XPTR( 0 , vfs_ctx ), sizeof(vfs_ctx_t) );
1176
1177 // 6. update extend field in local copy of VFS context
1178 vfs_ctx->extend = local_fatfs_ctx;
1179
1180 // 7. check initialisation
1181 assert( (((fatfs_ctx_t *)vfs_ctx->extend)->sectors_per_cluster == 8),
1182 "illegal value for FATFS context in cluster %x\n", local_cxy );
1183 }
1184
1185 // get extended pointer on VFS root inode from cluster 0
1186 vfs_root_inode_xp = hal_remote_lwd( XPTR( 0 , &process_zero.vfs_root_xp ) );
1187
1188 // update local process_zero descriptor
1189 process_zero.vfs_root_xp = vfs_root_inode_xp;
1190 process_zero.vfs_cwd_xp = vfs_root_inode_xp;
1191 }
1192
1193 /////////////////////////////////////////////////////////////////////////////////
1194 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
1195 (info->x_size * (info->y_max)) );
1196 barrier_wait( &local_barrier , info->cores_nr );
1197 /////////////////////////////////////////////////////////////////////////////////
1198
1199#if DEBUG_KERNEL_INIT
1200if( (core_lid == 0) & (local_cxy == 0) )
1201printk("\n[DBG] %s : exit barrier 5 : VFS_root = %l in cluster 0 / cycle %d\n",
1202__FUNCTION__, vfs_root_inode_xp , (uint32_t)hal_get_cycles());
1203#endif
1204
1205 /////////////////////////////////////////////////////////////////////////////////
1206 // STEP 6 : CP0 in cluster IO makes the global DEVFS tree initialisation:
1207 // It creates the DEVFS directory "dev", and the DEVFS "external"
1208 // directory in cluster IO and mount these inodes into VFS.
1209 /////////////////////////////////////////////////////////////////////////////////
1210
1211 if( (core_lid == 0) && (local_cxy == 0) ) // [FIXME]
1212 {
1213 // create "dev" and "external" directories.
1214 devfs_global_init( process_zero.vfs_root_xp,
1215 &devfs_dev_inode_xp,
1216 &devfs_external_inode_xp );
1217
1218 // creates the DEVFS context in cluster IO
1219 devfs_ctx_t * devfs_ctx = devfs_ctx_alloc();
1220
1221 assert( (devfs_ctx != NULL) ,
1222 "cannot create DEVFS context in cluster IO\n");
1223
1224 // register DEVFS root and external directories
1225 devfs_ctx_init( devfs_ctx, devfs_dev_inode_xp, devfs_external_inode_xp );
1226 }
1227
1228 /////////////////////////////////////////////////////////////////////////////////
1229 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
1230 (info->x_size * (info->y_max)) );
1231 barrier_wait( &local_barrier , info->cores_nr );
1232 /////////////////////////////////////////////////////////////////////////////////
1233
1234#if DEBUG_KERNEL_INIT
1235if( (core_lid == 0) & (local_cxy == 0) )
1236printk("\n[DBG] %s : exit barrier 6 : dev_root = %l in cluster 0 / cycle %d\n",
1237__FUNCTION__, devfs_dev_inode_xp , (uint32_t)hal_get_cycles() );
1238#endif
1239
1240 /////////////////////////////////////////////////////////////////////////////////
1241 // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
1242 // Each CP0 get the "dev" and "external" extended pointers from
1243 // values stored in cluster IO.
1244 // Then each CP0 in cluster(i) creates the DEVFS "internal directory,
1245 // and creates the pseudo-files for all chdevs in cluster (i).
1246 /////////////////////////////////////////////////////////////////////////////////
1247
1248 if( core_lid == 0 )
1249 {
1250 // get extended pointer on "extend" field of VFS context for DEVFS in cluster IO
1251 xptr_t extend_xp = XPTR( 0 , &fs_context[FS_TYPE_DEVFS].extend ); // [FIXME]
1252
1253 // get pointer on DEVFS context in cluster 0
1254 devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp );
1255
1256 devfs_dev_inode_xp = hal_remote_lwd( XPTR( 0 , &devfs_ctx->dev_inode_xp ) );
1257 devfs_external_inode_xp = hal_remote_lwd( XPTR( 0 , &devfs_ctx->external_inode_xp ) );
1258
1259 // populate DEVFS in all clusters
1260 devfs_local_init( devfs_dev_inode_xp,
1261 devfs_external_inode_xp,
1262 &devfs_internal_inode_xp );
1263 }
1264
1265 /////////////////////////////////////////////////////////////////////////////////
1266 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
1267 (info->x_size * (info->y_max)) );
1268 barrier_wait( &local_barrier , info->cores_nr );
1269 /////////////////////////////////////////////////////////////////////////////////
1270
1271#if DEBUG_KERNEL_INIT
1272if( (core_lid == 0) & (local_cxy == 0) )
1273printk("\n[DBG] %s : exit barrier 7 : dev_root = %l in cluster 0 / cycle %d\n",
1274__FUNCTION__, devfs_dev_inode_xp , (uint32_t)hal_get_cycles() );
1275#endif
1276
1277 /////////////////////////////////////////////////////////////////////////////////
1278 // STEP 8 : CP0 in cluster 0 creates the first user process (process_init)
1279 /////////////////////////////////////////////////////////////////////////////////
1280
1281 if( (core_lid == 0) && (local_cxy == 0) )
1282 {
1283
1284#if( DEBUG_KERNEL_INIT & 1 )
1285vfs_display( vfs_root_inode_xp );
1286#endif
1287
1288 process_init_create();
1289 }
1290
1291 /////////////////////////////////////////////////////////////////////////////////
1292 if( core_lid == 0 ) remote_barrier( XPTR( 0 , &global_barrier ), // [FIXME]
1293 (info->x_size * (info->y_max)) );
1294 barrier_wait( &local_barrier , info->cores_nr );
1295 /////////////////////////////////////////////////////////////////////////////////
1296
1297#if DEBUG_KERNEL_INIT
1298if( (core_lid == 0) & (local_cxy == 0) )
1299printk("\n[DBG] %s : exit barrier 8 : process init created / cycle %d\n",
1300__FUNCTION__ , (uint32_t)hal_get_cycles() );
1301#endif
1302
1303#if (DEBUG_KERNEL_INIT & 1)
1304if( (core_lid == 0) & (local_cxy == 0) )
1305sched_display( 0 );
1306#endif
1307
1308 /////////////////////////////////////////////////////////////////////////////////
1309 // STEP 9 : CP0 in cluster 0 print banner
1310 /////////////////////////////////////////////////////////////////////////////////
1311
1312 if( (core_lid == 0) && (local_cxy == 0) ) // [FIXME]
1313 {
1314 print_banner( (info->x_size * info->y_size) , info->cores_nr );
1315
1316#if( DEBUG_KERNEL_INIT & 1 )
1317printk("\n\n***** memory fooprint for main kernel objects\n\n"
1318 " - thread descriptor : %d bytes\n"
1319 " - process descriptor : %d bytes\n"
1320 " - cluster manager : %d bytes\n"
1321 " - chdev descriptor : %d bytes\n"
1322 " - core descriptor : %d bytes\n"
1323 " - scheduler : %d bytes\n"
1324 " - rpc fifo : %d bytes\n"
1325 " - page descriptor : %d bytes\n"
1326 " - mapper root : %d bytes\n"
1327 " - ppm manager : %d bytes\n"
1328 " - kcm manager : %d bytes\n"
1329 " - khm manager : %d bytes\n"
1330 " - vmm manager : %d bytes\n"
1331 " - gpt root : %d bytes\n"
1332 " - list item : %d bytes\n"
1333 " - xlist item : %d bytes\n"
1334 " - spinlock : %d bytes\n"
1335 " - remote spinlock : %d bytes\n"
1336 " - rwlock : %d bytes\n"
1337 " - remote rwlock : %d bytes\n",
1338 sizeof( thread_t ),
1339 sizeof( process_t ),
1340 sizeof( cluster_t ),
1341 sizeof( chdev_t ),
1342 sizeof( core_t ),
1343 sizeof( scheduler_t ),
1344 sizeof( remote_fifo_t ),
1345 sizeof( page_t ),
1346 sizeof( mapper_t ),
1347 sizeof( ppm_t ),
1348 sizeof( kcm_t ),
1349 sizeof( khm_t ),
1350 sizeof( vmm_t ),
1351 sizeof( gpt_t ),
1352 sizeof( list_entry_t ),
1353 sizeof( xlist_entry_t ),
1354 sizeof( spinlock_t ),
1355 sizeof( remote_spinlock_t ),
1356 sizeof( rwlock_t ),
1357 sizeof( remote_rwlock_t ));
1358#endif
1359
1360 }
1361
1362 // each core activates its private TICK IRQ
1363 dev_pic_enable_timer( CONFIG_SCHED_TICK_MS_PERIOD );
1364
1365#if DEBUG_KERNEL_INIT
1366printk("\n[DBG] %s : thread %x on core[%x,%d] jumps to thread_idle_func() / cycle %d\n",
1367__FUNCTION__ , CURRENT_THREAD , local_cxy , core_lid , (uint32_t)hal_get_cycles() );
1368#endif
1369
1370 // each core jump to thread_idle_func
1371 thread_idle_func();
1372}
1373
Note: See TracBrowser for help on using the repository browser.