1 | /* |
---|
2 | * sys_get_config.c - get hardware platform parameters. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016,2017,2018,2019,2020) |
---|
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_vmm.h> |
---|
27 | #include <hal_special.h> |
---|
28 | #include <errno.h> |
---|
29 | #include <core.h> |
---|
30 | #include <thread.h> |
---|
31 | #include <process.h> |
---|
32 | #include <vmm.h> |
---|
33 | #include <printk.h> |
---|
34 | |
---|
35 | #include <syscalls.h> |
---|
36 | #include <shared_syscalls.h> |
---|
37 | |
---|
38 | ////////////////////////////////////////////// |
---|
39 | int sys_get_config( hard_config_t * u_config ) |
---|
40 | { |
---|
41 | vseg_t * vseg; |
---|
42 | hard_config_t k_config; // hard_config structure in kernel space |
---|
43 | |
---|
44 | thread_t * this = CURRENT_THREAD; |
---|
45 | process_t * process = this->process; |
---|
46 | |
---|
47 | #if (DEBUG_SYS_GET_CONFIG || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
48 | uint64_t tm_start = hal_get_cycles(); |
---|
49 | #endif |
---|
50 | |
---|
51 | #if DEBUG_SYS_GET_CONFIG |
---|
52 | tm_start = hal_get_cycles(); |
---|
53 | if( DEBUG_SYS_GET_CONFIG < tm_start ) |
---|
54 | printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n", |
---|
55 | __FUNCTION__, this, process->pid, (uint32_t)tm_start ); |
---|
56 | #endif |
---|
57 | |
---|
58 | // check u_config mapped in user space |
---|
59 | if( vmm_get_vseg( process , (intptr_t)u_config , &vseg ) ) |
---|
60 | { |
---|
61 | |
---|
62 | #if DEBUG_SYSCALLS_ERROR |
---|
63 | printk("\n[ERROR] in %s : config pointer %x unmapped / thread %x / process %x\n", |
---|
64 | __FUNCTION__ , (intptr_t)u_config , this->trdid , process->pid ); |
---|
65 | #endif |
---|
66 | this->errno = EINVAL; |
---|
67 | return -1; |
---|
68 | } |
---|
69 | |
---|
70 | // copy config parameters from cluster descriptor to kernel structure |
---|
71 | k_config.x_size = LOCAL_CLUSTER->x_size; |
---|
72 | k_config.y_size = LOCAL_CLUSTER->y_size; |
---|
73 | k_config.ncores = LOCAL_CLUSTER->cores_nr; |
---|
74 | k_config.txt_channels = LOCAL_CLUSTER->nb_txt_channels; |
---|
75 | k_config.nic_channels = LOCAL_CLUSTER->nb_nic_channels; |
---|
76 | k_config.ioc_channels = LOCAL_CLUSTER->nb_ioc_channels; |
---|
77 | k_config.fbf_channels = LOCAL_CLUSTER->nb_fbf_channels; |
---|
78 | |
---|
79 | // copy k_config structure to user space |
---|
80 | hal_copy_to_uspace( u_config , XPTR(local_cxy, &k_config ), sizeof(hard_config_t) ); |
---|
81 | |
---|
82 | hal_fence(); |
---|
83 | |
---|
84 | #if (DEBUG_SYS_GET_CONFIG || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
85 | uint64_t tm_end = hal_get_cycles(); |
---|
86 | #endif |
---|
87 | |
---|
88 | #if DEBUG_SYS_GET_CONFIG |
---|
89 | if( DEBUG_SYS_GET_CONFIG < tm_end ) |
---|
90 | printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n", |
---|
91 | __FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end ); |
---|
92 | #endif |
---|
93 | |
---|
94 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
95 | hal_atomic_add( &syscalls_cumul_cost[SYS_GET_CONFIG] , tm_end - tm_start ); |
---|
96 | hal_atomic_add( &syscalls_occurences[SYS_GET_CONFIG] , 1 ); |
---|
97 | #endif |
---|
98 | |
---|
99 | return 0; |
---|
100 | |
---|
101 | } // end sys_get_config() |
---|