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

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

Complete restructuration of kernel locks.

File size: 3.4 KB
Line 
1/*
2 * sys_get_config.c - get hardware platform parameters.
3 *
4 * Author    Alain Greiner (2016,2017,2018)
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
24#include <hal_kernel_types.h>
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
34#include <syscalls.h>
35
36//////////////////////////////////////
37int sys_get_config( uint32_t * x_size,
38                    uint32_t * y_size,
39                    uint32_t * ncores )
40{
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;
46
47    thread_t  * this    = CURRENT_THREAD;
48    process_t * process = this->process;
49
50#if DEBUG_SYS_GET_CONFIG
51uint64_t     tm_start;
52uint64_t     tm_end;
53tm_start = hal_get_cycles();
54if( DEBUG_SYS_GET_CONFIG < tm_start )
55printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
56__FUNCTION__, this, process->pid, (uint32_t)tm_start );
57#endif
58
59    // check x_size buffer in user space
60    error = vmm_get_vseg( process , (intptr_t)x_size  , &vseg );
61
62        if( error )
63        {
64
65#if DEBUG_SYSCALLS_ERROR
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 );
69#endif
70        this->errno = EINVAL;
71                return -1;
72        }
73
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
104    // get parameters
105        k_x_size  = LOCAL_CLUSTER->x_size;
106        k_y_size  = LOCAL_CLUSTER->y_size;
107        k_ncores  = LOCAL_CLUSTER->cores_nr;
108
109    // copy to user space
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) );
113
114    hal_fence();
115
116#if DEBUG_SYS_GET_CONFIG
117tm_end = hal_get_cycles();
118if( DEBUG_SYS_GET_CONFIG < tm_end )
119printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n",
120__FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end );
121#endif
122
123        return 0; 
124
125}  // end sys_get_config()
Note: See TracBrowser for help on using the repository browser.