1 | /* |
---|
2 | * sys_get_config.c - get hardware platform parameters. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016,2017) |
---|
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_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 | ////////////////////////////////////// |
---|
35 | int sys_get_config( uint32_t * x_size, |
---|
36 | uint32_t * y_size, |
---|
37 | uint32_t * ncores ) |
---|
38 | { |
---|
39 | paddr_t paddr; |
---|
40 | uint32_t k_x_size; |
---|
41 | uint32_t k_y_size; |
---|
42 | uint32_t k_ncores; |
---|
43 | |
---|
44 | error_t error = 0; |
---|
45 | |
---|
46 | thread_t * this = CURRENT_THREAD; |
---|
47 | process_t * process = this->process; |
---|
48 | |
---|
49 | // check buffer in user space |
---|
50 | error |= vmm_v2p_translate( false , x_size , &paddr ); |
---|
51 | error |= vmm_v2p_translate( false , y_size , &paddr ); |
---|
52 | error |= vmm_v2p_translate( false , ncores , &paddr ); |
---|
53 | |
---|
54 | if( error ) |
---|
55 | { |
---|
56 | printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n", |
---|
57 | __FUNCTION__ , this->trdid , process->pid ); |
---|
58 | this->errno = EFAULT; |
---|
59 | return -1; |
---|
60 | } |
---|
61 | |
---|
62 | // get parameters |
---|
63 | k_x_size = LOCAL_CLUSTER->x_size; |
---|
64 | k_y_size = LOCAL_CLUSTER->y_size; |
---|
65 | k_ncores = LOCAL_CLUSTER->cores_nr; |
---|
66 | |
---|
67 | // copy to user space |
---|
68 | hal_copy_to_uspace( x_size , &k_x_size , sizeof(uint32_t) ); |
---|
69 | hal_copy_to_uspace( y_size , &k_y_size , sizeof(uint32_t) ); |
---|
70 | hal_copy_to_uspace( ncores , &k_ncores , sizeof(uint32_t) ); |
---|
71 | |
---|
72 | return 0; |
---|
73 | |
---|
74 | } // end sys_get_config() |
---|