• 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 #include <stdio.h>
13 #include <inttypes.h>
14 #include <stdlib.h>
15 #include <priorities.h>
16 #include <fileio.h>
17 #include <ipclib.h>
18 #include <libdrv_frame.h>
19 #include "drv_thread.h"
20 #include "drv_process_mgr.h"
21 #include "tee_log.h"
22 #include "cs.h"
23 
24 const char *g_debug_prefix = "drvmgr";
25 
drv_framework_init(const struct drv_frame_t * drv_frame)26 int32_t drv_framework_init(const struct drv_frame_t *drv_frame)
27 {
28     (void)drv_frame;
29     return 0;
30 }
31 
32 __attribute__((visibility("default"))) \
main(int32_t argc,char * argv[])33 int32_t main(int32_t argc __attribute__((unused)), char *argv[] __attribute__((unused)))
34 {
35     static dispatch_fn_t dispatch_fns[] = {
36         [0] = driver_dispatch,
37     };
38 
39     tlogi("drvmgr main begin\n");
40 
41     struct drv_frame_t drv_frame = { "drvmgr", true, NULL };
42 
43     cref_t ch = 0;
44 
45     int32_t ret = register_drv_framework(&drv_frame, &ch, true);
46     if (ret != 0) {
47         tloge("failed to register drv framework: 0x%x\n", ret);
48         exit(ret);
49     }
50 
51     ret = fileio_init();
52     if (ret != 0) {
53         tloge("file io init failed:0x%x\n", ret);
54         exit(ret);
55     }
56 
57     ret = set_priority(PRIO_TEE_DRV);
58     if (ret < 0) {
59         tloge("failed to set drv server priority\n");
60         exit(ret);
61     }
62 
63     ret = create_spawn_sync_msg_info();
64     if (ret < 0) {
65         tloge("create spawn channel fail\n");
66         exit(ret);
67     }
68 
69     (void)register_base_drv_node();
70 
71     /* stack_size set 0 will use default size */
72     ret = drv_thread_init("drvmgr_multi", 0, DRV_THREAD_MAX);
73     if (ret != 0) {
74         tloge("drv thread init fail\n");
75         exit(ret);
76     }
77 
78     tlogi("%s: start server loop\n", drv_frame.name);
79     cs_server_loop(ch, dispatch_fns, ARRAY_SIZE(dispatch_fns), NULL, NULL);
80 
81     return 0;
82 }
83