1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description: zdiag dfx
15 * This file should be changed only infrequently and with great care.
16 */
17 #include "diag_dfx.h"
18 #include "soc_module.h"
19 #include "diag.h"
20 #include "soc_diag_cmd_id.h"
21 #include "errcode.h"
22 #if !defined __KERNEL__
23 #include "soc_diag_util.h"
24 #endif
25 #include "soc_diag_msg_id.h"
26
27 #undef THIS_FILE_ID
28 #define THIS_FILE_ID DIAG_FILE_ID_TEST_DIAG_D
29
30 #undef THIS_MOD_ID
31 #define THIS_MOD_ID SOC_ID_BSP
32
33 typedef enum {
34 DIAG_DFX_CMD_CASE_GET_STAT,
35 DIAG_DFX_CMD_CASE_REPORT_MSG,
36 DIAG_DFX_CMD_CASE_REPORT_FIX_MSG,
37 DIAG_DFX_CMD_CASE_LAST_DUMP,
38 DIAG_DFX_CMD_CASE_SYS_MSG,
39 DIAG_DFX_CMD_CASE_FAULT_MOCKED,
40 } diag_dfx_cmd_case_id_t;
41
42 zdiag_dfx_stat_t g_zdiag_dfx_stat;
43
44 void dfx_last_dump_data(uint32_t dump_id, uintptr_t addr, uint32_t size);
45
uapi_zdiag_get_dfx_stat(void)46 zdiag_dfx_stat_t *uapi_zdiag_get_dfx_stat(void)
47 {
48 return &g_zdiag_dfx_stat;
49 }
50
diag_dfx_report_sys_msg(uint16_t cmd_id,const void * cmd_param,uint16_t cmd_param_size,const diag_option_t * option)51 STATIC errcode_t diag_dfx_report_sys_msg(uint16_t cmd_id, const void *cmd_param, uint16_t cmd_param_size,
52 const diag_option_t *option)
53 {
54 uint32_t data[] = {1, 2, 3, 4}; /* test val 1 2 3 4 */
55 unused(cmd_id);
56 unused(cmd_param);
57 unused(cmd_param_size);
58 unused(option);
59
60 uapi_diag_report_sys_msg(0, 0x1, (uint8_t*)data, sizeof(data), 1); /* 0 0x1 1 test val */
61 uapi_diag_report_sys_msg(1, 0xfeb40645, (uint8_t*)data, sizeof(data), 2); /* 1 0xfeb40645 2 test val */
62 return ERRCODE_SUCC;
63 }
64
65
diag_dfx_last_dump(uint16_t cmd_id,void * cmd_param,uint16_t cmd_param_size,const diag_option_t * option)66 STATIC errcode_t diag_dfx_last_dump(uint16_t cmd_id, void *cmd_param, uint16_t cmd_param_size,
67 const diag_option_t *option)
68 {
69 unused(cmd_id);
70 unused(cmd_param);
71 unused(cmd_param_size);
72 unused(option);
73
74 diag_dfx_cmd_req_st_t *req = cmd_param;
75
76 dfx_last_dump_data(req->data[0], req->data[1], req->data[2]); /* 0 1 2 为data 下标 */
77 return ERRCODE_SUCC;
78 }
79
diag_dfx_cmd_get_stat(uint16_t cmd_id,const void * cmd_param,uint16_t cmd_param_size,diag_option_t * option)80 STATIC errcode_t diag_dfx_cmd_get_stat(uint16_t cmd_id, const void *cmd_param, uint16_t cmd_param_size,
81 diag_option_t *option)
82 {
83 unused(cmd_id);
84 unused(cmd_param);
85 unused(cmd_param_size);
86 return uapi_diag_report_packet(DIAG_CMD_ID_DIAG_DFX_START, option, (uint8_t *)&g_zdiag_dfx_stat,
87 sizeof(zdiag_dfx_stat_t), true);
88 }
89
diag_dfx_cmd_report_msg(uint16_t cmd_id,const void * cmd_param,uint16_t cmd_param_size,diag_option_t * option)90 STATIC errcode_t diag_dfx_cmd_report_msg(uint16_t cmd_id, const void *cmd_param, uint16_t cmd_param_size,
91 diag_option_t *option)
92 {
93 #if !defined __KERNEL__
94 uapi_diag_info_log1(100, "test_1_log1", 1); /* 100 1 */
95 uapi_diag_warning_log1(101, "test_1_warning1", 2); /* 101 2 test val */
96 uapi_diag_error_log1(102, "test_1_error1", 3); /* 102 3 test val */
97 uapi_diag_info_log1(0x100, "test_2_log1", 4); /* 0x100 4 test val */
98 uapi_diag_warning_log1(0x101, "test_2_warning1", 5); /* 0x101 5 test val */
99 uapi_diag_error_log1(0x102, "test_2_error1", 6); /* 0x102 6 test val */
100 #endif
101 unused(cmd_id);
102 unused(cmd_param_size);
103 return uapi_diag_report_packet(cmd_id, option, (uint8_t *)cmd_param, sizeof(diag_dfx_cmd_req_st_t), false);
104 }
105
diag_dfx_cmd_report_fix_msg(uint16_t cmd_id,const void * cmd_param,uint16_t cmd_param_size,const diag_option_t * option)106 STATIC errcode_t diag_dfx_cmd_report_fix_msg(uint16_t cmd_id, const void *cmd_param, uint16_t cmd_param_size,
107 const diag_option_t *option)
108 {
109 uint32_t data[] = {1, 2, 3, 4}; /* test val 1 2 3 4 */
110 uapi_diag_report_sys_msg(THIS_MOD_ID, SOC_DIAG_MSG_ID_DIAG_TEST_U8_ARRAY, (uint8_t *)data, sizeof(data), 1);
111 uapi_diag_report_sys_msg(THIS_MOD_ID, SOC_DIAG_MSG_ID_DIAG_TEST_U32_ARRAY, (uint8_t *)data, sizeof(data), 1);
112
113 unused(cmd_id);
114 unused(cmd_param);
115 unused(cmd_param_size);
116 unused(option);
117 return ERRCODE_SUCC;
118 }
119
120 #ifndef NDEBUG
diag_dfx_cmd_fault_mocked(uint16_t cmd_id,void * cmd_param,uint16_t cmd_param_size,const diag_option_t * option)121 STATIC errcode_t diag_dfx_cmd_fault_mocked(uint16_t cmd_id, void *cmd_param, uint16_t cmd_param_size,
122 const diag_option_t *option)
123 {
124 diag_dfx_cmd_req_st_t *req = cmd_param;
125
126 if (req->data[0] == 0) {
127 if (req->data[1] == 0) {
128 uint32_t *null_pointer = NULL;
129 *null_pointer = req->case_id;
130 } else {
131 while (true) {}
132 }
133 }
134 unused(cmd_id);
135 unused(cmd_param_size);
136 unused(option);
137 return ERRCODE_SUCC;
138 }
139 #endif
140
diag_dfx_cmd(uint16_t cmd_id,void * cmd_param,uint16_t cmd_param_size,diag_option_t * option)141 errcode_t diag_dfx_cmd(uint16_t cmd_id, void *cmd_param, uint16_t cmd_param_size, diag_option_t *option)
142 {
143 diag_dfx_cmd_req_st_t *req = cmd_param;
144 unused(cmd_param_size);
145 switch (req->case_id) {
146 case DIAG_DFX_CMD_CASE_GET_STAT:
147 return diag_dfx_cmd_get_stat(cmd_id, cmd_param, cmd_param_size, option);
148 case DIAG_DFX_CMD_CASE_REPORT_MSG:
149 return diag_dfx_cmd_report_msg(cmd_id, cmd_param, cmd_param_size, option);
150 case DIAG_DFX_CMD_CASE_REPORT_FIX_MSG:
151 return diag_dfx_cmd_report_fix_msg(cmd_id, cmd_param, cmd_param_size, option);
152 case DIAG_DFX_CMD_CASE_LAST_DUMP:
153 return diag_dfx_last_dump(cmd_id, cmd_param, cmd_param_size, option);
154 case DIAG_DFX_CMD_CASE_SYS_MSG:
155 return diag_dfx_report_sys_msg(cmd_id, cmd_param, cmd_param_size, option);
156 #ifndef NDEBUG
157 case DIAG_DFX_CMD_CASE_FAULT_MOCKED:
158 return diag_dfx_cmd_fault_mocked(cmd_id, cmd_param, cmd_param_size, option);
159 #endif
160 default:
161 return uapi_diag_report_packet(cmd_id, option, (uint8_t *)req, sizeof(diag_dfx_cmd_req_st_t), false);
162 }
163 return ERRCODE_SUCC;
164 }
165