1 /*
2 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3 * Decription: for pages log cfg api define
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 #include "log_cfg_api.h"
15
16 #include <linux/sizes.h>
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/sysfs.h>
20 #include <linux/semaphore.h>
21 #include <linux/kthread.h>
22 #include <linux/delay.h>
23 #include <linux/stat.h>
24 #include <linux/uaccess.h>
25 #include <linux/syscalls.h>
26 #include <linux/slab.h>
27
28 #include <securec.h>
29 #include "tc_ns_log.h"
30 #include "tlogger.h"
31 #include "shared_mem.h"
32
unregister_log_exception(void)33 void unregister_log_exception(void)
34 {
35 }
36
register_log_exception(void)37 int register_log_exception(void)
38 {
39 return 0;
40 }
41
42 struct pages_module_result {
43 uint64_t log_addr;
44 uint32_t log_len;
45 };
46
47 struct pages_module_result g_mem_info = {0};
48
tee_pages_register_core(void)49 static int tee_pages_register_core(void)
50 {
51 if (g_mem_info.log_addr != 0 || g_mem_info.log_len != 0) {
52 if (memset_s((void *)g_mem_info.log_addr, g_mem_info.log_len, 0, g_mem_info.log_len) != 0) {
53 tloge("clean log memory failed\n");
54 return -EFAULT;
55 }
56 return 0;
57 }
58
59 g_mem_info.log_addr = get_log_mem_vaddr();
60 if (IS_ERR_OR_NULL((void *)(uintptr_t)g_mem_info.log_addr)) {
61 tloge("get log mem error\n");
62 return -1;
63 }
64 g_mem_info.log_len = PAGES_LOG_MEM_LEN;
65 return 0;
66 }
67
68 /* Register log memory */
register_log_mem(uint64_t * addr,uint32_t * len)69 int register_log_mem(uint64_t *addr, uint32_t *len)
70 {
71 int ret;
72 uint64_t mem_addr;
73 uint32_t mem_len;
74
75 if (!addr || !len) {
76 tloge("addr or len is invalid\n");
77 return -1;
78 }
79
80 ret = tee_pages_register_core();
81 if (ret != 0)
82 return ret;
83
84 mem_addr = get_log_mem_paddr(g_mem_info.log_addr);
85 mem_len = g_mem_info.log_len;
86
87 ret = register_mem_to_teeos(mem_addr, mem_len, true);
88 if (ret != 0)
89 return ret;
90
91 *addr = g_mem_info.log_addr;
92 *len = g_mem_info.log_len;
93 return ret;
94 }
95
report_log_system_error(void)96 void report_log_system_error(void)
97 {
98 }
99
report_log_system_panic(void)100 void report_log_system_panic(void)
101 {
102 /* default support trigger ap reset */
103 #ifndef NOT_TRIGGER_AP_RESET
104 panic("TEEOS panic\n");
105 #endif
106 }
107
ta_crash_report_log(void)108 void ta_crash_report_log(void)
109 {
110 }
111
map_log_mem(uint64_t mem_addr,uint32_t mem_len)112 int *map_log_mem(uint64_t mem_addr, uint32_t mem_len)
113 {
114 (void)mem_len;
115 return (int *)(uintptr_t)mem_addr;
116 }
117
unmap_log_mem(int * log_buffer)118 void unmap_log_mem(int *log_buffer)
119 {
120 free_log_mem((uint64_t)(uintptr_t)log_buffer);
121 }
122
get_log_chown(uid_t * user,gid_t * group)123 void get_log_chown(uid_t *user, gid_t *group)
124 {
125 if (!user || !group) {
126 tloge("user or group buffer is null\n");
127 return;
128 }
129
130 *user = ROOT_UID;
131 *group = FILE_CHOWN_GID;
132 }
133