source: trunk/kernel/syscalls/sys_get_config.c @ 609

Last change on this file since 609 was 566, checked in by alain, 6 years ago

Complete restructuration of kernel locks.

File size: 3.4 KB
RevLine 
[410]1/*
2 * sys_get_config.c - get hardware platform parameters.
3 *
[440]4 * Author    Alain Greiner (2016,2017,2018)
[410]5 * 
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
[457]24#include <hal_kernel_types.h>
[410]25#include <hal_uspace.h>
26#include <hal_special.h>
27#include <errno.h>
28#include <core.h>
29#include <thread.h>
30#include <process.h>
31#include <vmm.h>
32#include <printk.h>
33
[506]34#include <syscalls.h>
35
[410]36//////////////////////////////////////
37int sys_get_config( uint32_t * x_size,
38                    uint32_t * y_size,
39                    uint32_t * ncores )
40{
[440]41        error_t    error;
42    vseg_t   * vseg;
43    uint32_t   k_x_size;
44    uint32_t   k_y_size;
45    uint32_t   k_ncores;
[410]46
47    thread_t  * this    = CURRENT_THREAD;
48    process_t * process = this->process;
49
[438]50#if DEBUG_SYS_GET_CONFIG
[435]51uint64_t     tm_start;
52uint64_t     tm_end;
53tm_start = hal_get_cycles();
[438]54if( DEBUG_SYS_GET_CONFIG < tm_start )
[435]55printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
56__FUNCTION__, this, process->pid, (uint32_t)tm_start );
57#endif
58
[440]59    // check x_size buffer in user space
60    error = vmm_get_vseg( process , (intptr_t)x_size  , &vseg );
[410]61
62        if( error )
63        {
[435]64
[438]65#if DEBUG_SYSCALLS_ERROR
[440]66printk("\n[ERROR] in %s : x_size buffer unmapped / thread %x / process %x\n",
67__FUNCTION__ , (intptr_t)x_size , this->trdid , process->pid );
68vmm_display( process , false );
[435]69#endif
[440]70        this->errno = EINVAL;
[410]71                return -1;
72        }
73
[440]74    // check y_size buffer in user space
75    error = vmm_get_vseg( process , (intptr_t)y_size  , &vseg );
76
77        if( error )
78        {
79
80#if DEBUG_SYSCALLS_ERROR
81printk("\n[ERROR] in %s : y_size buffer unmapped / thread %x / process %x\n",
82__FUNCTION__ , (intptr_t)y_size , this->trdid , process->pid );
83vmm_display( process , false );
84#endif
85        this->errno = EINVAL;
86                return -1;
87        }
88
89    // check ncores buffer in user space
90    error = vmm_get_vseg( process , (intptr_t)ncores  , &vseg );
91
92        if( error )
93        {
94
95#if DEBUG_SYSCALLS_ERROR
96printk("\n[ERROR] in %s : ncores buffer unmapped / thread %x / process %x\n",
97__FUNCTION__ , (intptr_t)ncores , this->trdid , process->pid );
98vmm_display( process , false );
99#endif
100        this->errno = EINVAL;
101                return -1;
102        }
103
[410]104    // get parameters
[421]105        k_x_size  = LOCAL_CLUSTER->x_size;
106        k_y_size  = LOCAL_CLUSTER->y_size;
107        k_ncores  = LOCAL_CLUSTER->cores_nr;
[410]108
109    // copy to user space
[421]110        hal_copy_to_uspace( x_size  , &k_x_size  , sizeof(uint32_t) );
111        hal_copy_to_uspace( y_size  , &k_y_size  , sizeof(uint32_t) );
112        hal_copy_to_uspace( ncores  , &k_ncores  , sizeof(uint32_t) );
[410]113
[435]114    hal_fence();
115
[438]116#if DEBUG_SYS_GET_CONFIG
[435]117tm_end = hal_get_cycles();
[438]118if( DEBUG_SYS_GET_CONFIG < tm_end )
[436]119printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n",
[435]120__FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end );
121#endif
122
[410]123        return 0; 
124
125}  // end sys_get_config()
Note: See TracBrowser for help on using the repository browser.