• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DRV_DYN_CONF_MGR_H
14 #define DRVMGR_DRV_DYN_CONF_MGR_H
15 
16 #include <pthread.h>
17 #include <dlist.h>
18 #include <tee_defines.h>
19 #include <tee_drv_internal.h>
20 #include "dyn_conf_common.h"
21 #include "task_mgr.h"
22 
23 struct task_node;
24 
25 #define MAX_UUID_SIZE 36
26 #define MAX_CMD_SIZE 40
27 #define CMD_SET_FLAG 1
28 
29 enum drv_receive_list_tag {
30     RECEIVE_IO_MAP_LIST = 1,
31     RECEIVE_IRQ_LIST,
32     RECEIVE_MAP_SECURE_LIST,
33     RECEIVE_MAP_NOSECURE_LIST,
34     RECEIVE_MAC_INFO_LIST,
35     RECEIVE_CMD_PERM_LIST,
36     RECEIVE_MAX_TAG
37 };
38 
39 struct addr_region_t {
40     uint64_t start;
41     uint64_t end;
42 };
43 
44 struct drv_basic_info_t {
45     uint32_t thread_limit;
46     bool upgrade;
47     bool virt2phys;
48     uint8_t exception_mode;
49 };
50 
51 struct drv_map_secure_t {
52     struct tee_uuid uuid;
53     struct addr_region_t region;
54 };
55 
56 struct drv_map_nosecure_t {
57     struct tee_uuid uuid;
58 };
59 
60 struct drv_mac_info_t {
61     struct tee_uuid uuid;
62     uint64_t perm;
63 };
64 
65 struct drv_conf_t {
66     struct drv_mani_t mani;
67     struct drv_basic_info_t drv_basic_info;
68     union {
69         struct addr_region_t *io_map_list;
70         uint64_t tmp_io_map;
71     };
72     union {
73         uint64_t *irq_list;
74         uint64_t tmp_irq;
75     };
76     union {
77         struct drv_map_secure_t *map_secure_list;
78         uint64_t tmp_map_secure;
79     };
80     union {
81         struct drv_map_nosecure_t *map_nosecure_list;
82         uint64_t tmp_nosecure;
83     };
84     union {
85         struct drv_mac_info_t *mac_info_list;
86         uint64_t tmp_mac_info;
87     };
88     union {
89         struct drv_cmd_perm_info_t *cmd_perm_list;
90         uint64_t tmp_cmd_perm;
91     };
92     uint16_t io_map_list_size;
93     uint16_t io_map_list_index;
94     uint16_t irq_list_size;
95     uint16_t irq_list_index;
96     uint16_t map_secure_list_size;
97     uint16_t map_nosecure_list_size;
98     uint16_t map_nosecure_list_index;
99     uint16_t mac_info_list_size;
100     uint16_t mac_info_list_index; /* the index of the newest ava mac */
101     uint16_t cmd_perm_list_size;
102     uint16_t cmd_perm_list_index; /* the index of the newest cmd perm */
103 };
104 
105 struct drv_conf_list_t {
106     struct dlist_node list;
107     pthread_mutex_t lock;
108 };
109 
110 struct drv_tlv {
111     struct tee_uuid uuid;
112     struct drvcall_perm_apply_t drvcall_perm_apply;
113     struct drv_conf_t drv_conf;
114 };
115 
116 enum drv_error {
117     DRV_FAIL = -1,
118     DRV_SUCC = 0,
119     DRV_NEED_SPAWN,
120     DRV_WAIT,
121 };
122 
123 #ifdef TEE_SUPPORT_DYN_CONF_DEBUG
124 void dump_drv_conf(const struct drv_conf_t *drv_conf);
125 #endif
126 
127 void broadcast_drv_state(struct task_node *node, bool spawn_succ);
128 int32_t check_drv_node_state(struct task_node *node);
129 int32_t do_receive_drv_conf(struct drv_conf_t *drv_conf);
130 void free_drv_conf_list(struct drv_conf_t *drv_conf, uint32_t receive_flag);
131 
132 #endif
133