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

Last change on this file since 521 was 506, checked in by viala@…, 8 years ago

[syscalls] add interface in implementation.

Add const where possible, fix protoypes to follow interface.

File size: 3.5 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 * y_width,
40 uint32_t * ncores )
41{
42 error_t error;
43 vseg_t * vseg;
44 uint32_t k_x_size;
45 uint32_t k_y_size;
46 uint32_t k_ncores;
47
48 thread_t * this = CURRENT_THREAD;
49 process_t * process = this->process;
50
51#if DEBUG_SYS_GET_CONFIG
52uint64_t tm_start;
53uint64_t tm_end;
54tm_start = hal_get_cycles();
55if( DEBUG_SYS_GET_CONFIG < tm_start )
56printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
57__FUNCTION__, this, process->pid, (uint32_t)tm_start );
58#endif
59
60 // check x_size buffer in user space
61 error = vmm_get_vseg( process , (intptr_t)x_size , &vseg );
62
63 if( error )
64 {
65
66#if DEBUG_SYSCALLS_ERROR
67printk("\n[ERROR] in %s : x_size buffer unmapped / thread %x / process %x\n",
68__FUNCTION__ , (intptr_t)x_size , this->trdid , process->pid );
69vmm_display( process , false );
70#endif
71 this->errno = EINVAL;
72 return -1;
73 }
74
75 // check y_size buffer in user space
76 error = vmm_get_vseg( process , (intptr_t)y_size , &vseg );
77
78 if( error )
79 {
80
81#if DEBUG_SYSCALLS_ERROR
82printk("\n[ERROR] in %s : y_size buffer unmapped / thread %x / process %x\n",
83__FUNCTION__ , (intptr_t)y_size , this->trdid , process->pid );
84vmm_display( process , false );
85#endif
86 this->errno = EINVAL;
87 return -1;
88 }
89
90 // check ncores buffer in user space
91 error = vmm_get_vseg( process , (intptr_t)ncores , &vseg );
92
93 if( error )
94 {
95
96#if DEBUG_SYSCALLS_ERROR
97printk("\n[ERROR] in %s : ncores buffer unmapped / thread %x / process %x\n",
98__FUNCTION__ , (intptr_t)ncores , this->trdid , process->pid );
99vmm_display( process , false );
100#endif
101 this->errno = EINVAL;
102 return -1;
103 }
104
105 // get parameters
106 k_x_size = LOCAL_CLUSTER->x_size;
107 k_y_size = LOCAL_CLUSTER->y_size;
108 k_ncores = LOCAL_CLUSTER->cores_nr;
109
110 // copy to user space
111 hal_copy_to_uspace( x_size , &k_x_size , sizeof(uint32_t) );
112 hal_copy_to_uspace( y_size , &k_y_size , sizeof(uint32_t) );
113 hal_copy_to_uspace( ncores , &k_ncores , sizeof(uint32_t) );
114
115 hal_fence();
116
117#if DEBUG_SYS_GET_CONFIG
118tm_end = hal_get_cycles();
119if( DEBUG_SYS_GET_CONFIG < tm_end )
120printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n",
121__FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end );
122#endif
123
124 return 0;
125
126} // end sys_get_config()
Note: See TracBrowser for help on using the repository browser.