1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 #ifndef DRVMGR_SRC_DRV_FD_MANAGER_H 13 #define DRVMGR_SRC_DRV_FD_MANAGER_H 14 15 #include <dlist.h> 16 #include <stdint.h> 17 #include <pthread.h> 18 #include "tee_driver_module.h" 19 #include "drv_dispatch.h" 20 21 #define TASK_FD_COUNT_MAX 32U 22 23 #define CALLER_TASKID_INDEX 4 24 25 struct fd_data { 26 struct dlist_node data_list; 27 uint64_t cmd_perm; 28 pthread_mutex_t ref_mtx; 29 pthread_cond_t ref_cond; 30 uint32_t ref_cnt; /* locked by ref_mtx */ 31 struct drv_data drv; 32 }; 33 34 struct drv_task { 35 struct dlist_node task_list; 36 uint32_t task_pid; 37 uint32_t task_count; /* locked by task_mtx */ 38 struct dlist_node data_head; /* fd_data list head */ 39 pthread_mutex_t task_mtx; 40 uint32_t ref_cnt; /* locked by g_drv_mtx */ 41 }; 42 43 int64_t driver_open(const struct tee_drv_param *params, const struct tee_driver_module *drv_func); 44 int64_t driver_ioctl(uint64_t fd, struct tee_drv_param *params, 45 const struct tee_driver_module *drv_func, int64_t *fn_ret); 46 int64_t driver_close(uint64_t fd, const struct tee_drv_param *params); 47 int32_t driver_close_by_pid(uint32_t pid); 48 void driver_dump(void); 49 int32_t drv_mutex_lock(pthread_mutex_t *mtx); 50 int32_t driver_register_cmd_perm(const struct tee_drv_param *params, int64_t *ret_val); 51 #endif 52