1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
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 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #ifndef HI_BUILD_IN_BOOT
20 #ifdef CONFIG_HI_PROC_SHOW_SUPPORT
21 #include "tde_proc.h"
22 #include "tde_hal.h"
23 #endif
24 #include "securec.h"
25
26 #ifdef CONFIG_HI_PROC_SHOW_SUPPORT
27 typedef struct {
28 hi_u32 cur_node;
29 tde_hw_node tde_hw_node[TDE_MAX_PROC_NUM];
30 hi_bool proc_enable;
31 } tde_procinfo;
32
33 tde_procinfo g_tde_proc_info = {
34 .cur_node = 0,
35 .proc_enable = HI_TRUE,
36 };
37
tdeproc_record_node(tde_hw_node * hw_node)38 hi_void tdeproc_record_node(tde_hw_node *hw_node)
39 {
40 if ((!g_tde_proc_info.proc_enable) || (hw_node == HI_NULL)) {
41 return;
42 }
43
44 if (g_tde_proc_info.cur_node >= TDE_MAX_PROC_NUM) {
45 return;
46 }
47 if (memcpy_s(&g_tde_proc_info.tde_hw_node[g_tde_proc_info.cur_node], sizeof(tde_hw_node), hw_node,
48 sizeof(tde_hw_node)) != EOK) {
49 tde_error("secure function failure\n");
50 return;
51 }
52 g_tde_proc_info.cur_node++;
53 g_tde_proc_info.cur_node = (g_tde_proc_info.cur_node) % TDE_MAX_PROC_NUM;
54 }
55
tdeproc_clear_node(hi_void)56 hi_void tdeproc_clear_node(hi_void)
57 {
58 (hi_void)memset_s(&g_tde_proc_info.tde_hw_node[0], sizeof(g_tde_proc_info.tde_hw_node), 0,
59 sizeof(g_tde_proc_info.tde_hw_node));
60 g_tde_proc_info.cur_node = 0;
61 }
62
tde_read_proc(osal_proc_entry_t * p)63 int tde_read_proc(osal_proc_entry_t *p)
64 {
65 hi_u32 j;
66 hi_u32 *cur = HI_NULL;
67 tde_hw_node *hw_node = HI_NULL;
68
69 if (p == HI_NULL) {
70 return HI_FAILURE;
71 }
72
73 hw_node = g_tde_proc_info.tde_hw_node;
74 if (hw_node == NULL) {
75 return HI_FAILURE;
76 }
77 p = wprintinfo(p);
78
79 for (j = 0; j < g_tde_proc_info.cur_node; j++) {
80 cur = (hi_u32 *)&hw_node[j];
81 tde_hal_node_print_info(p, cur);
82 }
83
84 return HI_SUCCESS;
85 }
86 #endif
87 #endif
88