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 13 #ifndef DRVMGR_TASK_MGR_H 14 #define DRVMGR_TASK_MGR_H 15 16 #include <stdint.h> 17 #include <pthread.h> 18 #include <dlist.h> 19 #include <tee_defines.h> 20 #include <tee_driver_module.h> 21 #include "drv_dispatch.h" 22 #include "drv_dyn_conf_mgr.h" 23 #include "drvcall_dyn_conf_mgr.h" 24 #include "dyn_conf_common.h" 25 26 #define DRVCALL_DEC_CNT_INCLUDE_REGISTER_ONE 2U 27 28 struct drv_tlv; 29 30 enum node_state { 31 TASK_LOAD, /* only used by drv */ 32 TASK_SPAWN, /* only used by drv */ 33 TASK_NORMAL, 34 TASK_SPAWN_FAIL, /* only used by drv */ 35 TASK_EXIT, /* only used by ta since drv cannot support load dynamically */ 36 }; 37 38 struct task_tlv { 39 struct tee_uuid uuid; 40 struct drvcall_perm_apply_item_t *drvcall_perm_apply_list; /* drvcall_perm_apply items list */ 41 uint32_t drvcall_perm_apply_list_size; 42 struct drv_conf_t *drv_conf; 43 }; 44 45 struct drv_task_info { 46 cref_t channel; 47 int32_t drv_index; 48 bool register_policy; 49 }; 50 51 struct task_node { 52 struct dlist_node node_list; 53 int32_t target_type; /* declare drv or ta */ 54 uint32_t pid; 55 uint32_t ref_cnt; /* TA: register +1, unregister -1 */ 56 uint32_t fd_count; /* locked by fd_mtx */ 57 struct dlist_node fd_head; /* locked by fd_mtx */ 58 pthread_mutex_t fd_mtx; 59 enum node_state state; /* drv and ta state */ 60 pthread_cond_t state_cond; 61 pthread_mutex_t state_mtx; 62 struct task_tlv tlv; 63 struct drv_task_info drv_task; 64 }; 65 66 struct task_node *get_drv_node_by_name_with_lock(const char *drv_name, uint32_t len); 67 struct task_node *get_node_by_uuid_with_lock(const struct tee_uuid *uuid, uint32_t taskid); 68 struct task_node *get_ta_node_and_set_exit(const struct tee_uuid *uuid); 69 int32_t get_drvcall_and_fd_node(int64_t fd, const struct tee_drv_param *params, 70 struct task_node **call_node, struct fd_node **fdata); 71 void put_node_with_lock(struct task_node *node, uint32_t dec_cnt); 72 int32_t receive_task_conf(struct task_node *node); 73 74 struct task_node *alloc_and_init_ta_node(const struct drvcall_conf_t *tlv); 75 struct task_node *alloc_and_init_drv_node(struct drv_tlv *tlv); 76 void free_task_node(struct task_node *node); 77 int32_t free_drv_conf_by_service_name(const char *drv_name, uint32_t len); 78 struct task_node *find_drv_node_by_taskid(uint32_t exit_pid); 79 bool check_hardware_type(const struct task_node *node, uint16_t type); 80 81 #ifdef TEE_SUPPORT_DYN_CONF_DEBUG 82 void dump_task_node(void); 83 #endif 84 85 #endif 86