[410] | 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 | |
---|
[435] | 49 | #if CONFIG_DEBUG_SYS_GET_CONFIG |
---|
| 50 | uint64_t tm_start; |
---|
| 51 | uint64_t tm_end; |
---|
| 52 | tm_start = hal_get_cycles(); |
---|
| 53 | if( CONFIG_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 | |
---|
[410] | 58 | // check buffer in user space |
---|
[421] | 59 | error |= vmm_v2p_translate( false , x_size , &paddr ); |
---|
| 60 | error |= vmm_v2p_translate( false , y_size , &paddr ); |
---|
| 61 | error |= vmm_v2p_translate( false , ncores , &paddr ); |
---|
[410] | 62 | |
---|
| 63 | if( error ) |
---|
| 64 | { |
---|
[435] | 65 | |
---|
| 66 | #if CONFIG_DEBUG_SYSCALLS_ERROR |
---|
| 67 | printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n", |
---|
| 68 | __FUNCTION__ , this->trdid , process->pid ); |
---|
| 69 | #endif |
---|
[410] | 70 | this->errno = EFAULT; |
---|
| 71 | return -1; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | // get parameters |
---|
[421] | 75 | k_x_size = LOCAL_CLUSTER->x_size; |
---|
| 76 | k_y_size = LOCAL_CLUSTER->y_size; |
---|
| 77 | k_ncores = LOCAL_CLUSTER->cores_nr; |
---|
[410] | 78 | |
---|
| 79 | // copy to user space |
---|
[421] | 80 | hal_copy_to_uspace( x_size , &k_x_size , sizeof(uint32_t) ); |
---|
| 81 | hal_copy_to_uspace( y_size , &k_y_size , sizeof(uint32_t) ); |
---|
| 82 | hal_copy_to_uspace( ncores , &k_ncores , sizeof(uint32_t) ); |
---|
[410] | 83 | |
---|
[435] | 84 | hal_fence(); |
---|
| 85 | |
---|
| 86 | #if CONFIG_DEBUG_SYS_GET_CONFIG |
---|
| 87 | tm_end = hal_get_cycles(); |
---|
| 88 | if( CONFIG_DEBUG_SYS_GET_CONFIG < tm_end ) |
---|
[436] | 89 | printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n", |
---|
[435] | 90 | __FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end ); |
---|
| 91 | #endif |
---|
| 92 | |
---|
[410] | 93 | return 0; |
---|
| 94 | |
---|
| 95 | } // end sys_get_config() |
---|