blob: 073ae7194ea071a33ef3409bed43860e1f4a9aeb [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2016
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36#include "kal_general_types.h"
37#include "kal_public_api.h"
38
39#include "drv_comm.h"
40#include "sync_data.h"
41
42#include "pdamon_reg.h"
43#include "drv_pcmon.h"
44
45/*****************************************************************************
46 * Extern Functions
47 *****************************************************************************/
48/* Exception entry point for PC_MATCH usage */
49/* Normal flow */
50extern void general_ex_vector(void);
51extern void NMI_handler(void);
52/* Dormant/Boot flow */
53extern void INT_TEMP_general_ex_vector(void);
54
55/*****************************************************************************
56 * Internal Options
57 *****************************************************************************/
58
59/*****************************************************************************
60 * Preprocessor Directives
61 *****************************************************************************/
62
63#define __PDAMON_ALIGNED__ __attribute__((aligned(0x10)))
64#define __SECTION__(S) __attribute__((__section__(#S)))
65#define __ZI__ __attribute__((zero_init))
66#define __PDAMON_NONCACHED_DATA__ __SECTION__(NONCACHEDRW)
67
68#define PDAMON_ISRAM_TC0_SIDX (0)
69#define PDAMON_ISRAM_TC0_EIDX (8)
70#define PDAMON_ISRAM_TC1_SIDX (9)
71#define PDAMON_ISRAM_TC1_EIDX (18)
72#define PDAMON_ISRAM_TC2_SIDX (19)
73#define PDAMON_ISRAM_TC2_EIDX (27)
74#define PDAMON_ISRAM_TC3_SIDX (28)
75#define PDAMON_ISRAM_TC3_EIDX (37)
76#define PDAMON_ISRAM_TC4_SIDX (38)
77#define PDAMON_ISRAM_TC4_EIDX (46)
78#define PDAMON_ISRAM_TC5_SIDX (47)
79#define PDAMON_ISRAM_TC5_EIDX (55)
80
81#define PDAMON_DSRAM_TC0_SIDX (0)
82#define PDAMON_DSRAM_TC0_EIDX (8)
83#define PDAMON_DSRAM_TC1_SIDX (9)
84#define PDAMON_DSRAM_TC1_EIDX (18)
85#define PDAMON_DSRAM_TC2_SIDX (19)
86#define PDAMON_DSRAM_TC2_EIDX (27)
87#define PDAMON_DSRAM_TC3_SIDX (28)
88#define PDAMON_DSRAM_TC3_EIDX (37)
89#define PDAMON_DSRAM_TC4_SIDX (38)
90#define PDAMON_DSRAM_TC4_EIDX (46)
91#define PDAMON_DSRAM_TC5_SIDX (47)
92#define PDAMON_DSRAM_TC5_EIDX (55)
93
94#define PDAMON_DABASE (0x76543210)
95#define PDAMON_DAMASK (0x76543210)
96
97
98#define PDAMON_TC_IA_CNT(core,tc) (g_pdamon_sram_idx.pc[(core)][(tc)].end - g_pdamon_sram_idx.pc[(core)][(tc)].start + 1)
99#define PDAMON_TC_DA_CNT(core,tc) (g_pdamon_sram_idx.da[(core)][(tc)].end - g_pdamon_sram_idx.da[(core)][(tc)].start + 1)
100
101/**
102 * IA and DA counts for EX and NEX
103 * If we want one TC's SRAM counts is 0, we have to
104 * 1. Set PDAMON_{I|D}SRAM_TCx_SIDX = PDAMON_{I|D}SRAM_TCx_EIDX = 32
105 * 2. Set PDAMON_{EX|NEX}_TCx_{IA|DA}_MARGIN to 1
106 */
107#define PDAMON_EX_TC_IA_CNT(tc) (PDAMON_ISRAM_TC##tc##_EIDX - PDAMON_ISRAM_TC##tc##_SIDX + 1 - PDAMON_EX_TC##tc##_IA_MARGIN)
108#define PDAMON_EX_TC_DA_CNT(tc) (PDAMON_DSRAM_TC##tc##_EIDX - PDAMON_DSRAM_TC##tc##_SIDX + 1 - PDAMON_EX_TC##tc##_DA_MARGIN)
109#define PDAMON_NEX_TC_IA_CNT(tc) (PDAMON_ISRAM_TC##tc##_EIDX - PDAMON_ISRAM_TC##tc##_SIDX + 1 - PDAMON_NEX_TC##tc##_IA_MARGIN)
110
111/*****************************************************************************
112 * Macros
113 *****************************************************************************/
114
115#define PDAMON_CORE_CHK \
116 if (core < PDAMON_CORE_0 || core >= PDAMON_CORE_CNT) { \
117 return PDAMON_RET_INVALID_ARGUMENT; \
118 }
119
120/*****************************************************************************
121 * Type Definition
122 *****************************************************************************/
123
124/**
125 * A structure to describe CPU information
126 */
127typedef struct pdamon_cpuinfo {
128 kal_uint8 core_id;
129 kal_uint8 vpe_id;
130 kal_uint8 tc_id;
131} pdamon_cpuinfo_st;
132
133/**
134 * A structure to describe SRAM information of a TC
135 */
136typedef struct pdamon_sram_info {
137 kal_uint32 start_idx; ///< SRAM start index
138 kal_uint32 end_idx; ///< SRAM end index
139 kal_uint32 pairs; ///< SRAM total pairs
140 kal_uint32 first_idx; ///< First pair index in SRAM
141 kal_bool is_wrap; ///< SRAM is wrap
142} pdamon_sram_info_st;
143
144/**
145 * A structure to describe SRAM index of a TC
146 */
147typedef struct pdamon_sram_idx {
148 kal_uint16 start; ///< SRAM start index
149 kal_uint16 end; ///< SRAM end index
150} pdamon_sram_idx_st;
151
152/**
153 * A structure to describe SRAM index setting
154 */
155typedef struct pdamon_sram_idx_info {
156 kal_uint8 start[13]; ///< PDAMON_START
157 pdamon_sram_idx_st pc[PDAMON_CORE_NUM][PDAMON_TC_NUM_PER_CORE]; ///< PC SRAM
158 pdamon_sram_idx_st da[PDAMON_CORE_NUM][PDAMON_TC_NUM_PER_CORE]; ///< DA SRAM
159 kal_bool do_init; ///< Setup SRAM indices at init stage or not
160 kal_uint8 end[13]; ///< PDAMON_END
161} pdamon_sram_idx_info_st;
162
163/**
164 * A structure to describe DABASE/DAMASK of a core
165 */
166typedef struct pdamon_da_base_mask {
167 kal_uint32 base; ///< DA Base
168 kal_uint32 mask; ///< DA Mask
169} pdamon_da_base_mask_st;
170
171/**
172 * A structure to describe DABASE/DAMASK setting
173 */
174typedef struct pdamon_da_base_mask_info {
175 kal_uint8 start[13]; ///< PDAMON_START
176 pdamon_da_base_mask_st base_mask[PDAMON_CORE_NUM]; ///< DA_BASE_MASK
177 kal_bool do_init; ///< Setup SRAM indices at init stage or not
178 kal_uint8 end[13]; ///< PDAMON_END
179} pdamon_da_base_mask_info_st;
180
181/*****************************************************************************
182 * Function Declaration
183 *****************************************************************************/
184
185/*****************************************************************************
186 * Global Variables
187 *****************************************************************************/
188
189__PDAMON_NONCACHED_DATA__ PDAMON_EVENT_MASK g_pdamon_event_mask = {{0}};
190__PDAMON_ALIGNED__ PDAMON_RAW_PER_CORE_T g_pdamon_full[PDAMON_CORE_NUM];
191#if defined(__MD93__)
192__PDAMON_NONCACHED_DATA__ __PDAMON_ALIGNED__ PDAMON_RECORD_STS_V2 g_pdamon_record_sts_dormant_leave[PDAMON_CORE_NUM];
193#endif
194
195/**
196 * A constant table to describe each TC's SRAM capacity
197 * SRAM capacity is configured in drv_pdamon_init()
198 */
199#if defined(__MD93__) || defined(__MD95_IS_2CORES__)
200__attribute__ ((section (".rodatag_pdamon_sram_idx"))) volatile const static pdamon_sram_idx_info_st g_pdamon_sram_idx = {
201 {'P','D','A','M','O','N','_','S','R','A','M','_','S'},
202 {{{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}},
203 {{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}}},
204 {{{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}},
205 {{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}}},
206 KAL_FALSE,
207 {'P','D','A','M','O','N','_','S','R','A','M','_','E'},
208};
209#elif defined(__MD95__)
210__attribute__ ((section (".rodatag_pdamon_sram_idx"))) volatile const static pdamon_sram_idx_info_st g_pdamon_sram_idx = {
211 {'P','D','A','M','O','N','_','S','R','A','M','_','S'},
212 {{{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}},
213 {{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}},
214 {{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}}},
215 {{{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}},
216 {{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}},
217 {{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}}},
218 KAL_FALSE,
219 {'P','D','A','M','O','N','_','S','R','A','M','_','E'},
220};
221#elif defined(__MD97__)
222 #if defined(__MD97_IS_2CORES__)
223 __attribute__ ((section (".rodatag_pdamon_sram_idx"))) volatile const static pdamon_sram_idx_info_st g_pdamon_sram_idx = {
224 {'P','D','A','M','O','N','_','S','R','A','M','_','S'},
225 {{{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}, {PDAMON_ISRAM_TC4_SIDX, PDAMON_ISRAM_TC4_EIDX}, {PDAMON_ISRAM_TC5_SIDX, PDAMON_ISRAM_TC5_EIDX}},
226 {{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}, {PDAMON_ISRAM_TC4_SIDX, PDAMON_ISRAM_TC4_EIDX}, {PDAMON_ISRAM_TC5_SIDX, PDAMON_ISRAM_TC5_EIDX}}},
227 {{{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}, {PDAMON_DSRAM_TC4_SIDX, PDAMON_DSRAM_TC4_EIDX}, {PDAMON_DSRAM_TC5_SIDX, PDAMON_DSRAM_TC5_EIDX}},
228 {{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}, {PDAMON_DSRAM_TC4_SIDX, PDAMON_DSRAM_TC4_EIDX}, {PDAMON_DSRAM_TC5_SIDX, PDAMON_DSRAM_TC5_EIDX}}},
229 KAL_FALSE,
230 {'P','D','A','M','O','N','_','S','R','A','M','_','E'},
231 };
232 #else
233 __attribute__ ((section (".rodatag_pdamon_sram_idx"))) volatile const static pdamon_sram_idx_info_st g_pdamon_sram_idx = {
234 {'P','D','A','M','O','N','_','S','R','A','M','_','S'},
235 {{{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}, {PDAMON_ISRAM_TC4_SIDX, PDAMON_ISRAM_TC4_EIDX}, {PDAMON_ISRAM_TC5_SIDX, PDAMON_ISRAM_TC5_EIDX}},
236 {{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}, {PDAMON_ISRAM_TC4_SIDX, PDAMON_ISRAM_TC4_EIDX}, {PDAMON_ISRAM_TC5_SIDX, PDAMON_ISRAM_TC5_EIDX}},
237 {{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}, {PDAMON_ISRAM_TC4_SIDX, PDAMON_ISRAM_TC4_EIDX}, {PDAMON_ISRAM_TC5_SIDX, PDAMON_ISRAM_TC5_EIDX}},
238 {{PDAMON_ISRAM_TC0_SIDX, PDAMON_ISRAM_TC0_EIDX}, {PDAMON_ISRAM_TC1_SIDX, PDAMON_ISRAM_TC1_EIDX}, {PDAMON_ISRAM_TC2_SIDX, PDAMON_ISRAM_TC2_EIDX}, {PDAMON_ISRAM_TC3_SIDX, PDAMON_ISRAM_TC3_EIDX}, {PDAMON_ISRAM_TC4_SIDX, PDAMON_ISRAM_TC4_EIDX}, {PDAMON_ISRAM_TC5_SIDX, PDAMON_ISRAM_TC5_EIDX}}},
239 {{{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}, {PDAMON_DSRAM_TC4_SIDX, PDAMON_DSRAM_TC4_EIDX}, {PDAMON_DSRAM_TC5_SIDX, PDAMON_DSRAM_TC5_EIDX}},
240 {{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}, {PDAMON_DSRAM_TC4_SIDX, PDAMON_DSRAM_TC4_EIDX}, {PDAMON_DSRAM_TC5_SIDX, PDAMON_DSRAM_TC5_EIDX}},
241 {{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}, {PDAMON_DSRAM_TC4_SIDX, PDAMON_DSRAM_TC4_EIDX}, {PDAMON_DSRAM_TC5_SIDX, PDAMON_DSRAM_TC5_EIDX}},
242 {{PDAMON_DSRAM_TC0_SIDX, PDAMON_DSRAM_TC0_EIDX}, {PDAMON_DSRAM_TC1_SIDX, PDAMON_DSRAM_TC1_EIDX}, {PDAMON_DSRAM_TC2_SIDX, PDAMON_DSRAM_TC2_EIDX}, {PDAMON_DSRAM_TC3_SIDX, PDAMON_DSRAM_TC3_EIDX}, {PDAMON_DSRAM_TC4_SIDX, PDAMON_DSRAM_TC4_EIDX}, {PDAMON_DSRAM_TC5_SIDX, PDAMON_DSRAM_TC5_EIDX}}},
243 KAL_FALSE,
244 {'P','D','A','M','O','N','_','S','R','A','M','_','E'},
245 };
246 #endif
247#else
248 #error "ERROR in drv_pdamon.c, w/o declare g_pdamon_sram_idx"
249#endif
250
251/**
252 * A constant table to describe each TC's DABASE/DAMASK
253 * DABASE/DAMASK is configured in drv_pdamon_init()
254 */
255#if defined(__MD93__) || defined(__MD95_IS_2CORES__)
256__attribute__ ((section (".rodatag_pdamon_da_base_mask"))) volatile const static pdamon_da_base_mask_info_st g_pdamon_da_base_mask = {
257 {'P','D','A','M','O','N','_','D','A','B','M','_','S'},
258 {{PDAMON_DABASE, PDAMON_DAMASK},
259 {PDAMON_DABASE, PDAMON_DAMASK}},
260 KAL_FALSE,
261 {'P','D','A','M','O','N','_','D','A','B','M','_','E'},
262};
263#elif defined(__MD95__)
264__attribute__ ((section (".rodatag_pdamon_da_base_mask"))) volatile const static pdamon_da_base_mask_info_st g_pdamon_da_base_mask = {
265 {'P','D','A','M','O','N','_','D','A','B','M','_','S'},
266 {{PDAMON_DABASE, PDAMON_DAMASK},
267 {PDAMON_DABASE, PDAMON_DAMASK},
268 {PDAMON_DABASE, PDAMON_DAMASK}},
269 KAL_FALSE,
270 {'P','D','A','M','O','N','_','D','A','B','M','_','E'},
271};
272#elif defined(__MD97__)
273 #if defined(__MD97_IS_2CORES__)
274 __attribute__ ((section (".rodatag_pdamon_da_base_mask"))) volatile const static pdamon_da_base_mask_info_st g_pdamon_da_base_mask = {
275 {'P','D','A','M','O','N','_','D','A','B','M','_','S'},
276 {{PDAMON_DABASE, PDAMON_DAMASK},
277 {PDAMON_DABASE, PDAMON_DAMASK}},
278 KAL_FALSE,
279 {'P','D','A','M','O','N','_','D','A','B','M','_','E'},
280 };
281 #else
282 __attribute__ ((section (".rodatag_pdamon_da_base_mask"))) volatile const static pdamon_da_base_mask_info_st g_pdamon_da_base_mask = {
283 {'P','D','A','M','O','N','_','D','A','B','M','_','S'},
284 {{PDAMON_DABASE, PDAMON_DAMASK},
285 {PDAMON_DABASE, PDAMON_DAMASK},
286 {PDAMON_DABASE, PDAMON_DAMASK},
287 {PDAMON_DABASE, PDAMON_DAMASK}},
288 KAL_FALSE,
289 {'P','D','A','M','O','N','_','D','A','B','M','_','E'},
290 };
291 #endif
292#else
293 #error "ERROR in drv_pdamon.c, w/o declare g_pdamon_da_base_mask"
294#endif
295
296/**
297 * A constant table to describe each TC's PC record in EX.
298 */
299__attribute__ ((section (".rodatag_pdamon_ex_ia_cnt"))) volatile const static kal_uint32 g_pdamon_ex_ia_cnt[PDAMON_TC_NUM_PER_CORE] = {
300#if defined(__MD97__)
301 PDAMON_EX_TC_IA_CNT(0), PDAMON_EX_TC_IA_CNT(1), PDAMON_EX_TC_IA_CNT(2), PDAMON_EX_TC_IA_CNT(3), PDAMON_EX_TC_IA_CNT(4), PDAMON_EX_TC_IA_CNT(5),
302#else
303 PDAMON_EX_TC_IA_CNT(0), PDAMON_EX_TC_IA_CNT(1), PDAMON_EX_TC_IA_CNT(2), PDAMON_EX_TC_IA_CNT(3),
304#endif
305};
306
307/**
308 * A constant table to describe each TC's DA record in EX.
309 */
310__attribute__ ((section (".rodatag_pdamon_ex_da_cnt"))) volatile const static kal_uint32 g_pdamon_ex_da_cnt[PDAMON_TC_NUM_PER_CORE] = {
311#if defined(__MD97__)
312 PDAMON_EX_TC_DA_CNT(0), PDAMON_EX_TC_DA_CNT(1), PDAMON_EX_TC_DA_CNT(2), PDAMON_EX_TC_DA_CNT(3), PDAMON_EX_TC_DA_CNT(4), PDAMON_EX_TC_DA_CNT(5),
313#else
314 PDAMON_EX_TC_DA_CNT(0), PDAMON_EX_TC_DA_CNT(1), PDAMON_EX_TC_DA_CNT(2), PDAMON_EX_TC_DA_CNT(3),
315#endif
316};
317
318/**
319 * A constant table to describe each TC's DA record in NEX.
320 */
321__attribute__ ((section (".rodatag_pdamon_nex_ia_cnt"))) volatile const static kal_uint32 g_pdamon_nex_ia_cnt[PDAMON_TC_NUM_PER_CORE] = {
322#if defined(__MD97__)
323 PDAMON_NEX_TC_IA_CNT(0), PDAMON_NEX_TC_IA_CNT(1), PDAMON_NEX_TC_IA_CNT(2), PDAMON_NEX_TC_IA_CNT(3), PDAMON_NEX_TC_IA_CNT(4), PDAMON_NEX_TC_IA_CNT(5),
324#else
325 PDAMON_NEX_TC_IA_CNT(0), PDAMON_NEX_TC_IA_CNT(1), PDAMON_NEX_TC_IA_CNT(2), PDAMON_NEX_TC_IA_CNT(3),
326#endif
327};
328
329/*****************************************************************************
330 * Tool Functions
331 *****************************************************************************/
332
333kal_bool pdamon_find_first_idx(kal_bool pc, pdamon_cpuinfo_st *cpu, pdamon_sram_info_st *info)
334{
335 kal_uint32 i = 0;
336 kal_uint32 idx_value = 0;
337 kal_uint32 idx_first_diff = 0;
338 kal_uint32 start_idx = 0, end_idx = 0;
339 kal_bool ret = KAL_TRUE;
340
341 info->is_wrap = KAL_FALSE;
342 /*
343 * Find first index pair of IA
344 */
345 if (pc == KAL_TRUE) {
346 start_idx = PDAMON_PC_SRAM_START_IDX(cpu->core_id, cpu->tc_id);
347 end_idx = PDAMON_PC_SRAM_END_IDX(cpu->core_id, cpu->tc_id);
348 /* Check SRAM wrap */
349 if (PDAMON_PC_SRAM_IS_WRAP(cpu->core_id, cpu->tc_id) > 0)
350 info->is_wrap = KAL_TRUE;
351 /*
352 * Search from SRAM start index
353 */
354 for (i = start_idx; i <= end_idx; i++) {
355 //PDAMON_MSG("%s - (%d) PDAMON_BREG_PCPAIR_TAG(%d, %d) = 0x%08X = %d\r\n", __FUNCTION__,
356 // i, cpu->core_id, cpu->tc_id, PDAMON_BREG_PCPAIR_TAG(cpu->core_id, i), PDAMON_PCPAIR_IDX_VALUE(DRV_Reg32(PDAMON_BREG_PCPAIR_TAG(cpu->core_id, i))));
357 /* Record the first idx value */
358 if (i == start_idx) {
359 idx_value = PDAMON_PCPAIR_IDX_VALUE(DRV_Reg32(PDAMON_BREG_PCPAIR_TAG(cpu->core_id, i)));
360 } else {
361 /* If idx value is different, this index is the oldest pair */
362 if (PDAMON_PCPAIR_IDX_VALUE(DRV_Reg32(PDAMON_BREG_PCPAIR_TAG(cpu->core_id, i))) != idx_value) {
363 idx_first_diff = i;
364 break;
365 }
366 }
367 }
368 /*
369 * Find first index pair of DA
370 */
371 } else {
372 start_idx = PDAMON_DA_SRAM_START_IDX(cpu->core_id, cpu->tc_id);
373 end_idx = PDAMON_DA_SRAM_END_IDX(cpu->core_id, cpu->tc_id);
374 /* Check SRAM wrap */
375 if (PDAMON_DA_SRAM_IS_WRAP(cpu->core_id, cpu->tc_id) > 0)
376 info->is_wrap = KAL_TRUE;
377 /*
378 * Search from SRAM start index
379 */
380 for (i = start_idx; i <= end_idx; i++) {
381 //PDAMON_MSG("%s - (%d) PDAMON_BREG_DAPAIR_TAG(%d, %d) = 0x%08X = %d\r\n",
382 //__FUNCTION__, i, cpu->core_id, cpu->tc_id,
383 //PDAMON_BREG_DAPAIR_TAG(cpu->core_id, i), PDAMON_DAPAIR_IDX_VALUE(DRV_Reg32(PDAMON_BREG_DAPAIR_TAG(cpu->core_id, i))));
384 /* Record the first idx value */
385 if (i == start_idx) {
386 idx_value = PDAMON_DAPAIR_IDX_VALUE(DRV_Reg32(PDAMON_BREG_DAPAIR_TAG(cpu->core_id, i)));
387 } else {
388 /* If idx value is different, this index is the oldest pair */
389 if (PDAMON_DAPAIR_IDX_VALUE(DRV_Reg32(PDAMON_BREG_DAPAIR_TAG(cpu->core_id, i))) != idx_value) {
390 idx_first_diff = i;
391 break;
392 }
393 }
394 }
395 }
396
397 if (info->is_wrap == KAL_FALSE) {
398 info->start_idx= start_idx;
399 info->end_idx= end_idx;
400 info->first_idx = start_idx;
401 if (pc == KAL_TRUE)
402 info->pairs = PDAMON_PC_SRAM_NONWRAP_COUNT(cpu->core_id, cpu->tc_id);
403 else
404 info->pairs = PDAMON_DA_SRAM_NONWRAP_COUNT(cpu->core_id, cpu->tc_id);
405 } else {
406 /*
407 * Oldest pair is at start index
408 */
409 if ((i > end_idx) && (idx_first_diff == 0)) {
410 info->start_idx= start_idx;
411 info->end_idx= end_idx;
412 info->first_idx = start_idx;
413 info->pairs = end_idx - start_idx + 1;
414 /*
415 * Oldest pair is between start index and end index
416 */
417 } else if ((i <= end_idx) && (idx_first_diff != 0)) {
418 info->start_idx = start_idx;
419 info->end_idx = end_idx;
420 info->first_idx = idx_first_diff;
421 info->pairs = end_idx - start_idx + 1;
422 /* Should never comes here */
423 } else {
424 ret = KAL_FALSE;
425 // ASSERT(0);
426 }
427 }
428
429 return ret;
430}
431
432kal_bool pdamon_get_pc_raw_by_tc(PDAMON_PC_PAIR_RAW_V2_T *raw, kal_uint32 cnt, pdamon_cpuinfo_st *cpu, pdamon_sram_info_st *info)
433{
434 kal_uint32 i = 0;
435 kal_uint32 sram_idx = info->first_idx;
436
437 if (raw == 0)
438 return KAL_FALSE;
439
440 for (i = 0; i < cnt; i++, sram_idx++) {
441 /* Index wrap handling */
442 if (sram_idx > info->end_idx) { sram_idx = info->start_idx; }
443 kal_mem_cpy((void*)&raw[i], (void*)PDAMON_BREG_PCPAIR_SRC(cpu->core_id, sram_idx), sizeof(PDAMON_PC_PAIR_RAW_V2_T));
444 }
445
446 return KAL_TRUE;
447}
448
449kal_bool pdamon_get_da_raw_by_tc(PDAMON_DA_PAIR_RAW_T *raw, kal_uint32 cnt, pdamon_cpuinfo_st *cpu, pdamon_sram_info_st *info)
450{
451 kal_uint32 i = 0;
452 kal_uint32 sram_idx = info->first_idx;
453
454 if (raw == 0)
455 return KAL_FALSE;;
456
457 for (i = 0; i < cnt; i++, sram_idx++) {
458 /* Index wrap handling */
459 if (sram_idx > info->end_idx) { sram_idx = info->start_idx; }
460 kal_mem_cpy((void*)&raw[i], (void*)PDAMON_BREG_DAPAIR_DA(cpu->core_id, sram_idx), sizeof(PDAMON_DA_PAIR_RAW_T));
461 }
462
463 return KAL_TRUE;
464}
465
466kal_bool pdamon_ex_get_pc_raw_by_tc(PDAMON_PC_PAIR_RAW_V2_T *raw, kal_uint32 ex_cnt, pdamon_cpuinfo_st *cpu, pdamon_sram_info_st *info)
467{
468 kal_uint32 i = 0;
469 kal_uint32 sram_idx = info->first_idx;
470
471 if (raw == 0)
472 return KAL_FALSE;
473
474 if ((cpu->tc_id == PDAMON_TC_0) && (g_pdamon_ex_ia_cnt[0] < info->pairs))
475 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_ia_cnt[0]);
476 else if ((cpu->tc_id == PDAMON_TC_1) && (g_pdamon_ex_ia_cnt[1] < info->pairs))
477 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_ia_cnt[1]);
478 else if ((cpu->tc_id == PDAMON_TC_2) && (g_pdamon_ex_ia_cnt[2] < info->pairs))
479 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_ia_cnt[2]);
480 else if ((cpu->tc_id == PDAMON_TC_3) && (g_pdamon_ex_ia_cnt[3] < info->pairs))
481 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_ia_cnt[3]);
482
483 for (i = 0; i < ex_cnt; i++, sram_idx++) {
484 /* Index wrap handling */
485 if (sram_idx > info->end_idx) { sram_idx = info->start_idx; }
486 kal_mem_cpy((void*)&raw[i], (void*)PDAMON_BREG_PCPAIR_SRC(cpu->core_id, sram_idx), sizeof(PDAMON_PC_PAIR_RAW_V2_T));
487 }
488
489 return KAL_TRUE;
490}
491
492kal_bool pdamon_ex_get_da_raw_by_tc(PDAMON_DA_PAIR_RAW_T *raw, kal_uint32 ex_cnt, pdamon_cpuinfo_st *cpu, pdamon_sram_info_st *info)
493{
494 kal_uint32 i = 0;
495 kal_uint32 sram_idx = info->first_idx;
496
497 if (raw == 0)
498 return KAL_FALSE;;
499
500 if ((cpu->tc_id == PDAMON_TC_0) && (g_pdamon_ex_da_cnt[0] < info->pairs))
501 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_da_cnt[0]);
502 else if ((cpu->tc_id == PDAMON_TC_1) && (g_pdamon_ex_da_cnt[1] < info->pairs))
503 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_da_cnt[1]);
504 else if ((cpu->tc_id == PDAMON_TC_2) && (g_pdamon_ex_da_cnt[2] < info->pairs))
505 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_da_cnt[2]);
506 else if ((cpu->tc_id == PDAMON_TC_3) && (g_pdamon_ex_da_cnt[3] < info->pairs))
507 sram_idx = sram_idx + (info->pairs - g_pdamon_ex_da_cnt[3]);
508
509 for (i = 0; i < ex_cnt; i++, sram_idx++) {
510 /* Index wrap handling */
511 if (sram_idx > info->end_idx) { sram_idx = info->start_idx; }
512 kal_mem_cpy((void*)&raw[i], (void*)PDAMON_BREG_DAPAIR_DA(cpu->core_id, sram_idx), sizeof(PDAMON_DA_PAIR_RAW_T));
513 }
514
515 return KAL_TRUE;
516}
517
518/*****************************************************************************
519 * Implementation
520 *****************************************************************************/
521
522/*-----------------------------------------------------------------------
523 * FUNCTION
524 * drv_pdamon_init
525 *
526 * DESCRIPTION
527 * This function is to initialize SW PCMON module.
528 *
529 * PARAMETERS
530 * none
531 *
532 * RETURNS
533 * none
534 *
535 *------------------------------------------------------------------------*/
536#if defined(MT6297_IA) // not porting 97 iA yet
537PDAMON_RET drv_pdamon_init(void)
538{
539 return PDAMON_RET_OK;
540}
541#else
542PDAMON_RET drv_pdamon_init(void)
543{
544 kal_uint32 i = 0, j = 0;
545 kal_uint32 value = 0;
546
547 if (g_pdamon_sram_idx.do_init == KAL_TRUE) {
548 /*
549 * Set SRAM index
550 */
551 drv_pdamon_stop_capture(PDAMON_CORE_ALL);
552 if (drv_pdamon_is_stopped(PDAMON_CORE_ALL) == KAL_TRUE) {
553 /* PC SRAM start index */
554 value = 0;
555 for (i = 0; i < PDAMON_CORE_NUM; i++) {
556 for (j = 0; j < PDAMON_TC_NUM_PER_CORE; j++) {
557 value |= PDAMON_SRAM_IDX_SET(j, g_pdamon_sram_idx.pc[i][j].start);
558 }
559#if defined(__MD97__)
560 DRV_WriteReg32(PDAMON_BREG_PC_SRAM_IDX_START(i, 0), value);
561 DRV_WriteReg32(PDAMON_BREG_PC_SRAM_IDX_START(i, 4), value);
562#else
563 DRV_WriteReg32(PDAMON_BREG_PC_SRAM_IDX_START(i), value);
564#endif
565 }
566 /* PC SRAM end index */
567 value = 0;
568 for (i = 0; i < PDAMON_CORE_NUM; i++) {
569 for (j = 0; j < PDAMON_TC_NUM_PER_CORE; j++) {
570 value |= PDAMON_SRAM_IDX_SET(j, g_pdamon_sram_idx.pc[i][j].end);
571 }
572#if defined(__MD97__)
573 DRV_WriteReg32(PDAMON_BREG_PC_SRAM_IDX_END(i, 0), value);
574 DRV_WriteReg32(PDAMON_BREG_PC_SRAM_IDX_END(i, 4), value);
575#else
576 DRV_WriteReg32(PDAMON_BREG_PC_SRAM_IDX_END(i), value);
577#endif
578 }
579 /* DA SRAM start index */
580 value = 0;
581 for (i = 0; i < PDAMON_CORE_NUM; i++) {
582 for (j = 0; j < PDAMON_TC_NUM_PER_CORE; j++) {
583 value |= PDAMON_SRAM_IDX_SET(j, g_pdamon_sram_idx.da[i][j].start);
584 }
585#if defined(__MD97__)
586 DRV_WriteReg32(PDAMON_BREG_DA_SRAM_IDX_START(i, 0), value);
587 DRV_WriteReg32(PDAMON_BREG_DA_SRAM_IDX_START(i, 4), value);
588#else
589 DRV_WriteReg32(PDAMON_BREG_DA_SRAM_IDX_START(i), value);
590#endif
591 }
592 /* DA SRAM end index */
593 value = 0;
594 for (i = 0; i < PDAMON_CORE_NUM; i++) {
595 for (j = 0; j < PDAMON_TC_NUM_PER_CORE; j++) {
596 value |= PDAMON_SRAM_IDX_SET(j, g_pdamon_sram_idx.da[i][j].end);
597 }
598#if defined(__MD97__)
599 DRV_WriteReg32(PDAMON_BREG_DA_SRAM_IDX_END(i, 0), value);
600 DRV_WriteReg32(PDAMON_BREG_DA_SRAM_IDX_END(i, 4), value);
601#else
602 DRV_WriteReg32(PDAMON_BREG_DA_SRAM_IDX_END(i), value);
603#endif
604 }
605 MO_Sync();
606 drv_pdamon_start_capture(PDAMON_CORE_ALL);
607 } else {
608 ASSERT(0);
609 }
610 }
611
612 if (g_pdamon_da_base_mask.do_init == KAL_TRUE) {
613 /* Configure DABASE/DAMASK register */
614 for (i = 0; i < PDAMON_CORE_NUM; i++) {
615 DRV_WriteReg32(PDAMON_BREG_CORE_DABASE(i), g_pdamon_da_base_mask.base_mask[i].base);
616 DRV_WriteReg32(PDAMON_BREG_CORE_DAMASK(i), g_pdamon_da_base_mask.base_mask[i].mask);
617 }
618 }
619
620#if defined(__MD97__)
621 /*
622 * There is a PC match bug in 97 Apollo. PDAMON HW of Petrus is fixed.
623 * The bug is that PC match only match PCs in pipe PC of PDAMON, instead of dual-issue pipeline of Shaolin.
624 * So, it is possible that CPU executed the address which PC match set but PDAMON didn't stop;
625 * Software workaround: use PC match mask to avoid the situation.
626 * 1) general_ex_vector and INT_TEMP_general_ex_vector addresses always start at XXXXXX180
627 * 2) NMI_handler address is aligned 16 bytes (ask exception owner to add alignment attribute)
628 * NOTE: stop PDAMON when modifying PC match; modify mask first, and then modify addr.
629 */
630 drv_pdamon_set_pc_match_and_mask(0, (kal_uint32)(&general_ex_vector), 0xFFFFFFF0, KAL_TRUE);
631 drv_pdamon_set_pc_match_and_mask(1, (kal_uint32)(&NMI_handler), 0xFFFFFFF0, KAL_TRUE);
632 drv_pdamon_set_pc_match_and_mask(2, (kal_uint32)(&INT_TEMP_general_ex_vector), 0xFFFFFFF0, KAL_TRUE);
633#else
634
635 drv_pdamon_set_pc_match(0, (kal_uint32)(&general_ex_vector), KAL_TRUE);
636 drv_pdamon_set_pc_match(1, (kal_uint32)(&NMI_handler), KAL_TRUE);
637 drv_pdamon_set_pc_match(2, (kal_uint32)(&INT_TEMP_general_ex_vector), KAL_TRUE);
638
639#endif
640
641 g_pdamon_event_mask.Raw |= DRV_Reg32(PDAMON_BREG_EVENT_MASK);
642 DRV_WriteReg32(PDAMON_BREG_EVENT_MASK, g_pdamon_event_mask.Raw);
643 MO_Sync();
644
645 return PDAMON_RET_OK;
646}
647#endif
648
649/*-----------------------------------------------------------------------
650 * FUNCTION
651 * drv_pdamon_configure_dormant_leave
652 *
653 * DESCRIPTION
654 * This function is to configure PCMON module when leave dormant.
655 *
656 * PARAMETERS
657 * none
658 *
659 * RETURNS
660 * none
661 *
662 *------------------------------------------------------------------------*/
663#if defined(__MD93__)
664__PDAMON_NONCACHED_DATA__ volatile kal_uint32 g_pdamon_dormant_debug_trace_1 = PDAMON_DORMANT_TRACE_MAGIC;
665__PDAMON_NONCACHED_DATA__ volatile kal_uint32 g_pdamon_dormant_debug_trace_2 = PDAMON_DORMANT_TRACE_MAGIC;
666
667PDAMON_RET drv_pdamon_configure_dormant_leave(void)
668{
669 kal_uint32 i = 0;
670 kal_uint32 status = 0;
671 kal_uint32 vpe_id;
672 kal_bool restart_flag = KAL_TRUE;
673
674 vpe_id = kal_get_current_vpe_id();
675 /* Only VPE0 to do following configure */
676 if( vpe_id == 0 ) {
677 /* First, Check record_sts, whether SPRAM DECERR bit is asserted or not */
678 if (drv_pdamon_is_stopped(PDAMON_CORE_ALL) == KAL_TRUE) {
679 g_pdamon_dormant_debug_trace_1 = PDAMON_DORMANT_ALREADY_STOPPED;
680 for (i = 0; i < PDAMON_CORE_NUM; i++) {
681 status = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(i));
682 g_pdamon_record_sts_dormant_leave[i].Raw = status;
683 /* If others stop source is asserted, don't care about defualt mask, do not restart PDAMON to keep content */
684 if ((((~PDAMON_EVT_DEFAULT_MASK) & PDAMON_EVT_RECORD_STS_ALL) & status) > 0) {
685 /* break and do nothing */
686 g_pdamon_dormant_debug_trace_2 = PDAMON_DORMANT_STOPPED_BY_OTHERS;
687 restart_flag = KAL_FALSE;
688 break;
689 }
690 /* If default mask is asserted, restarted PDAMON later */
691 if ((PDAMON_EVT_DEFAULT_MASK & status) > 0) {
692 g_pdamon_dormant_debug_trace_2 = PDAMON_DORMANT_STOPPED_BY_MAIN;
693 DRV_WriteReg32(PDAMON_BREG_EVENT_MASK, PDAMON_EVT_DEFAULT_MASK);
694 MO_Sync();
695 }
696 }
697 }
698 else {
699 DRV_WriteReg32(PDAMON_BREG_EVENT_MASK, PDAMON_EVT_DEFAULT_MASK);
700 MO_Sync();
701 g_pdamon_dormant_debug_trace_1 = PDAMON_DORMANT_NON_STOPPED;
702 /* Check again for safety */
703 if (drv_pdamon_is_stopped(PDAMON_CORE_ALL) == KAL_TRUE) {
704 for (i = 0; i < PDAMON_CORE_NUM; i++) {
705 status = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(i));
706 g_pdamon_record_sts_dormant_leave[i].Raw = status;
707 /* If others stop source is asserted, don't care about defualt mask, do not restart PDAMON to keep content */
708 if ((((~PDAMON_EVT_DEFAULT_MASK) & PDAMON_EVT_RECORD_STS_ALL) & status) > 0) {
709 /* break and do nothing */
710 g_pdamon_dormant_debug_trace_2 = PDAMON_DORMANT_STOPPED_BY_OTHERS;
711 restart_flag = KAL_FALSE;
712 break;
713 }
714 /* If default mask is asserted, restarted PDAMON later */
715 if ((PDAMON_EVT_DEFAULT_MASK & status) > 0) {
716 g_pdamon_dormant_debug_trace_2 = PDAMON_DORMANT_STOPPED_BY_MAIN;
717 }
718 }
719 }
720 }
721 /* Second, if restart_flag == KAL_TRUE, restart PDAMON */
722 if (restart_flag == KAL_TRUE) {
723 drv_pdamon_start_capture(PDAMON_CORE_ALL);
724 /* Normal PDAMON init */
725 drv_pdamon_init();
726 }
727 }
728 return PDAMON_RET_OK;
729}
730//#elif defined(__MD95__)
731#elif defined(__MD95__) || defined(__MD97__)
732PDAMON_RET drv_pdamon_configure_dormant_leave(void)
733{
734 kal_uint32 vpe_id;
735
736 vpe_id = kal_get_current_vpe_id();
737 /* Only VPE0 to do following configure */
738 if( vpe_id == 0 ) {
739 /* Normal PDAMON init */
740 drv_pdamon_init();
741 }
742 return PDAMON_RET_OK;
743}
744#endif
745
746/*-----------------------------------------------------------------------*
747 * FUNCTION
748 * drv_pdamon_set_config
749 *
750 * DESCRIPTION
751 * This function is to configure the pcmon .
752 *
753 * PARAMETERS
754 * cfg : PDAMON config parameters
755 *
756 * RETURNS
757 * None
758 *
759 *------------------------------------------------------------------------*/
760PDAMON_RET drv_pdamon_set_config(PDAMON_CFG_T *cfg, PDAMON_CORE_SEL core)
761{
762 kal_uint32 cfg_value = 0;
763 kal_uint32 tmp = 0;
764
765 PDAMON_CORE_CHK;
766
767 /* Stop PDAMON first */
768 if (drv_pdamon_stop_capture(PDAMON_CORE_ALL) == PDAMON_RET_OK) {
769 /* Non-PC_MATCH source */
770 if ((tmp = cfg->stop_src_mask & PDAMON_EVT_MASK_ALL) > 0) {
771 // Event source mask
772 cfg_value |= (tmp << PDAMON_EVT_MASK_SHIFT);
773 // Set configuration
774 DRV_WriteReg32_NPW(PDAMON_BREG_EVENT_MASK, cfg_value);
775 }
776 /* PC_MATCH source */
777 if ((tmp = (cfg->stop_src_mask & (~PDAMON_EVT_MASK_ALL))) > 0) {
778 if ((tmp & PDAMON_SRC_PC0_MATCH) > 0)
779 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(0), 1);
780 if ((tmp & PDAMON_SRC_PC1_MATCH) > 0)
781 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(1), 1);
782 if ((tmp & PDAMON_SRC_PC2_MATCH) > 0)
783 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(2), 1);
784 if ((tmp & PDAMON_SRC_PC3_MATCH) > 0)
785 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(3), 1);
786 if ((tmp & PDAMON_SRC_PC4_MATCH) > 0)
787 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(4), 1);
788 if ((tmp & PDAMON_SRC_PC5_MATCH) > 0)
789 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(5), 1);
790 }
791 return PDAMON_RET_OK;
792 }
793 return PDAMON_RET_FAIL;
794}
795
796PDAMON_RET drv_pdamon_set_pc_match(kal_uint32 index, kal_uint32 addr, kal_bool enabled)
797{
798 if (index >= 0 && index < PDAMON_PC_MATCH_CNT) {
799 /*
800 * Disable PC match
801 */
802 if (enabled == KAL_FALSE) {
803 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(index), 0x1);
804 /*
805 * Enable PC match
806 */
807 } else {
808 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(index), addr);
809 }
810 return PDAMON_RET_OK;
811 }
812
813 return PDAMON_RET_INVALID_ARGUMENT;
814}
815
816#if defined(__MD97__)
817PDAMON_RET drv_pdamon_set_pc_match_and_mask(kal_uint32 index, kal_uint32 addr, kal_uint32 mask, kal_bool enabled)
818{
819 if (index >= 0 && index < PDAMON_PC_MATCH_CNT) {
820 /*
821 * Disable match stop address first to avoid stopping before setting done
822 */
823 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(index), 0x1);
824 /*
825 * For Disable PC match
826 */
827 if (enabled == KAL_FALSE) {
828 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP_MASK(index), 0xFFFFFFFF);
829 /*
830 * For Enable PC match
831 */
832 } else {
833 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP_MASK(index), mask);
834 DRV_WriteReg32_NPW(PDAMON_BREG_PC_MATCH_STOP(index), addr);
835 }
836
837 return PDAMON_RET_OK;
838 }
839
840 return PDAMON_RET_INVALID_ARGUMENT;
841}
842#endif
843
844PDAMON_RET drv_pdamon_start_capture(PDAMON_CORE_SEL core)
845{
846#if 0
847/* under construction !*/
848/* under construction !*/
849#endif
850 /* Start one core */
851 if (core >= PDAMON_CORE_0 && core < PDAMON_CORE_CNT) {
852 DRV_WriteReg32_NPW(PDAMON_BREG_SW_TRIG, PDAMON_SW_RESTART_CORE(core));
853 return PDAMON_RET_OK;
854 /* Start all cores */
855 } else if (core == PDAMON_CORE_ALL) {
856 DRV_WriteReg32_NPW(PDAMON_BREG_SW_TRIG, PDAMON_SW_RESTART_CORE_ALL);
857 return PDAMON_RET_OK;
858 }
859 return PDAMON_RET_INVALID_ARGUMENT;
860}
861
862PDAMON_RET drv_pdamon_stop_capture(PDAMON_CORE_SEL core)
863{
864 /* Stop one core */
865 if (core >= PDAMON_CORE_0 && core < PDAMON_CORE_CNT) {
866 DRV_WriteReg32_NPW(PDAMON_BREG_SW_TRIG, PDAMON_SW_STOP_CORE(core));
867 return PDAMON_RET_OK;
868 /* Stop all cores */
869 } else if (core == PDAMON_CORE_ALL) {
870 DRV_WriteReg32_NPW(PDAMON_BREG_SW_TRIG, PDAMON_SW_STOP_CORE_ALL);
871 return PDAMON_RET_OK;
872 }
873 return PDAMON_RET_INVALID_ARGUMENT;
874}
875
876PDAMON_RET drv_pdamon_gcr_stop_capture(PDAMON_CORE_SEL core)
877{
878 kal_uint32 gcr = 0;
879
880 /* Stop one core */
881 if (core >= PDAMON_CORE_0 && core < PDAMON_CORE_CNT) {
882 DRV_WriteReg32(PDAMON_GCR_BASE, PDAMON_GCR_STOP_CORE(core));
883 gcr = DRV_Reg32(PDAMON_GCR_BASE);
884 gcr = gcr & ~(PDAMON_GCR_STOP_CORE(core));
885 DRV_WriteReg32(PDAMON_GCR_BASE, gcr);
886 gcr = DRV_Reg32(PDAMON_GCR_BASE);
887 return PDAMON_RET_OK;
888 /* Stop all cores */
889 } else if (core == PDAMON_CORE_ALL) {
890 DRV_WriteReg32(PDAMON_GCR_BASE, PDAMON_GCR_STOP_CORE_ALL);
891 gcr = DRV_Reg32(PDAMON_GCR_BASE);
892 DRV_WriteReg32(PDAMON_GCR_BASE, 0);
893 return PDAMON_RET_OK;
894 }
895 return PDAMON_RET_INVALID_ARGUMENT;
896}
897
898/*-----------------------------------------------------------------------*
899 * FUNCTION
900 * drv_pdamon_core_select
901 *
902 * DESCRIPTION
903 *
904 * PARAMETERS
905 * num: Pair number
906 *
907 * RETURNS
908 * None
909 *
910 *------------------------------------------------------------------------*/
911PDAMON_RET drv_pdamon_core_select(PDAMON_CORE_SEL core)
912{
913 return PDAMON_RET_UNSUPPORTED;
914}
915
916/*-----------------------------------------------------------------------*
917 * FUNCTION
918 * drv_pdamon_is_stopped
919 *
920 * DESCRIPTION
921 *
922 * PARAMETERS
923 *
924 * RETURNS
925 * None
926 *
927 *------------------------------------------------------------------------*/
928kal_bool drv_pdamon_is_stopped(PDAMON_CORE_SEL core)
929{
930 PDAMON_CORE_SEL i = PDAMON_CORE_0;
931 kal_bool ret = KAL_FALSE;
932 kal_uint32 status = 0, check = PDAMON_IS_STOP;
933
934 /* One core is stopped */
935 if (core >= PDAMON_CORE_0 && core < PDAMON_CORE_CNT) {
936 status = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(core));
937 if ((status & check) == check)
938 ret = KAL_TRUE;
939 /* All cores are stopped */
940 } else if (core == PDAMON_CORE_ALL) {
941 ret = KAL_TRUE;
942 for (i = PDAMON_CORE_0; i < PDAMON_CORE_CNT; i++) {
943 if ((DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(i)) & check) != check) {
944 ret = KAL_FALSE;
945 break;
946 }
947 }
948 }
949
950 return ret;
951}
952
953/*-----------------------------------------------------------------------*
954 * FUNCTION
955 * drv_pdamon_is_stopped_by_src
956 *
957 * DESCRIPTION
958 *
959 * PARAMETERS
960 *
961 * RETURNS
962 * None
963 *
964 *------------------------------------------------------------------------*/
965kal_bool drv_pdamon_is_stopped_by_source(PDAMON_CORE_SEL core, PDAMON_STOP_SOURCE source)
966{
967 PDAMON_CORE_SEL i = PDAMON_CORE_0;
968 kal_bool ret = KAL_FALSE;
969 kal_uint32 status = 0, check = PDAMON_IS_STOP | source;
970
971 /* One core is stopped */
972 if (core >= PDAMON_CORE_0 && core < PDAMON_CORE_CNT) {
973 status = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(core));
974 if ((status & check) == check)
975 ret = KAL_TRUE;
976 /* All cores are stopped */
977 } else if (core == PDAMON_CORE_ALL) {
978 ret = KAL_TRUE;
979 for (i = PDAMON_CORE_0; i < PDAMON_CORE_CNT; i++) {
980 if ((DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(i)) & check) != check) {
981 ret = KAL_FALSE;
982 break;
983 }
984 }
985 }
986 return ret;
987}
988
989kal_uint32 drv_pdamon_get_pc_count(PDAMON_CORE_SEL core)
990{
991 return 0;
992}
993
994kal_uint32 drv_pdamon_get_pc_count_by_tc(PDAMON_CORE_SEL core, PDAMON_TC_SEL tc)
995{
996 kal_uint32 reg_value = 0;
997
998 // If PDAMON IA record is not wrap, get record count from register
999#if defined(__MD97__)
1000 reg_value = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core,tc));
1001#else
1002 reg_value = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core));
1003#endif
1004 if ((reg_value & PDAMON_SRAM_IS_WRAP(tc)) == 0) {
1005 return ((reg_value & (PDAMON_SRAM_NONWRAP_COUNT_MASK << PDAMON_SRAM_NONWRAP_COUNT_SHIFT(tc))) >> PDAMON_SRAM_NONWRAP_COUNT_SHIFT(tc));
1006 } else {
1007 // TODO :
1008 return PDAMON_IA_RAW_CAPACITY;
1009 }
1010}
1011
1012kal_uint32 drv_pdamon_get_da_count(PDAMON_CORE_SEL core)
1013{
1014 return 0;
1015}
1016
1017kal_uint32 drv_pdamon_get_da_count_by_tc(PDAMON_CORE_SEL core, PDAMON_TC_SEL tc)
1018{
1019 kal_uint32 reg_value = 0;
1020
1021 // If PDAMON IA record is not wrap, get record count from register
1022#if defined(__MD97__)
1023 reg_value = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core, tc));
1024#else
1025 reg_value = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core));
1026#endif
1027 if ((reg_value & PDAMON_SRAM_IS_WRAP(tc)) == 0) {
1028 return ((reg_value & (PDAMON_SRAM_NONWRAP_COUNT_MASK << PDAMON_SRAM_NONWRAP_COUNT_SHIFT(tc))) >> PDAMON_SRAM_NONWRAP_COUNT_SHIFT(tc));
1029 } else {
1030 // TODO :
1031 return PDAMON_DA_RAW_CAPACITY;
1032 }
1033}
1034
1035PDAMON_RET drv_pdamon_get_status(PDAMON_CORE_SEL core, kal_uint32 *status)
1036{
1037 /* Check parameters */
1038 if (status == NULL)
1039 return PDAMON_RET_INVALID_ARGUMENT;
1040 /* Read status */
1041 *status = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(core));
1042
1043 return PDAMON_RET_OK;
1044}
1045
1046PDAMON_RET drv_pdamon_get_raw(PDAMON_CORE_SEL core, PDAMON_RAW_PER_CORE_T *raw)
1047{
1048 kal_uint32 i = 0, j = 0, idx = 0, cnt = 0;
1049 kal_bool flag_sram = KAL_TRUE;
1050 pdamon_cpuinfo_st cpu = {0};
1051 pdamon_sram_info_st info = {0};
1052
1053 if (raw == NULL)
1054 return PDAMON_RET_INVALID_ARGUMENT;
1055 cpu.core_id = core;
1056
1057 raw->last_tc_id = DRV_Reg32(PDAMON_BREG_LAST_TC_ID(cpu.core_id));
1058 /* PC wrap status */
1059#if defined(__MD97__)
1060 raw->pc_wrap.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core, 0));
1061 raw->pc_wrap_ext.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core, 4));
1062#else
1063 raw->pc_wrap.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core));
1064#endif
1065 /* Pipe PC dual-issue status */
1066#if defined(__MD97__) && !defined(MT6297_IA)
1067 raw->piped_pc_dual_issue = DRV_Reg32(PDAMON_BREG_DUAL_ISSUE_STS(core));
1068#endif
1069 /* PC - TC0 */
1070 cpu.tc_id = 0;
1071 idx = 0;
1072 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1073 cnt = (info.pairs > PDAMON_TC_IA_CNT(core, 0)) ? PDAMON_TC_IA_CNT(core, 0) : info.pairs;
1074 pdamon_get_pc_raw_by_tc(&raw->pc[idx], cnt, &cpu, &info);
1075 } else {
1076 // ASSERT(0);
1077 flag_sram = KAL_FALSE;
1078 }
1079 /* PC - TC1 */
1080 cpu.tc_id = 1;
1081 idx += PDAMON_TC_IA_CNT(core, 0);
1082 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1083 cnt = (info.pairs > PDAMON_TC_IA_CNT(core, 1)) ? PDAMON_TC_IA_CNT(core, 1) : info.pairs;
1084 pdamon_get_pc_raw_by_tc(&raw->pc[idx], cnt, &cpu, &info);
1085 } else {
1086 // ASSERT(0);
1087 flag_sram = KAL_FALSE;
1088 }
1089 /* PC - TC2 */
1090 cpu.tc_id = 2;
1091 idx += PDAMON_TC_IA_CNT(core, 1);
1092 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1093 cnt = (info.pairs > PDAMON_TC_IA_CNT(core, 2)) ? PDAMON_TC_IA_CNT(core, 2) : info.pairs;
1094 pdamon_get_pc_raw_by_tc(&raw->pc[idx], cnt, &cpu, &info);
1095 } else {
1096 // ASSERT(0);
1097 flag_sram = KAL_FALSE;
1098 }
1099 /* PC - TC3 */
1100 cpu.tc_id = 3;
1101 idx += PDAMON_TC_IA_CNT(core, 2);
1102 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1103 cnt = (info.pairs > PDAMON_TC_IA_CNT(core, 3)) ? PDAMON_TC_IA_CNT(core, 3) : info.pairs;
1104 pdamon_get_pc_raw_by_tc(&raw->pc[idx], cnt, &cpu, &info);
1105 } else {
1106 // ASSERT(0);
1107 flag_sram = KAL_FALSE;
1108 }
1109#if defined(__MD97__)
1110 /* PC - TC4 */
1111 cpu.tc_id = 4;
1112 idx += PDAMON_TC_IA_CNT(core, 3);
1113 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1114 cnt = (info.pairs > PDAMON_TC_IA_CNT(core, 4)) ? PDAMON_TC_IA_CNT(core, 4) : info.pairs;
1115 pdamon_get_pc_raw_by_tc(&raw->pc[idx], cnt, &cpu, &info);
1116 } else {
1117 // ASSERT(0);
1118 flag_sram = KAL_FALSE;
1119 }
1120 /* PC - TC5 */
1121 cpu.tc_id = 5;
1122 idx += PDAMON_TC_IA_CNT(core, 4);
1123 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1124 cnt = (info.pairs > PDAMON_TC_IA_CNT(core, 5)) ? PDAMON_TC_IA_CNT(core, 5) : info.pairs;
1125 pdamon_get_pc_raw_by_tc(&raw->pc[idx], cnt, &cpu, &info);
1126 } else {
1127 // ASSERT(0);
1128 flag_sram = KAL_FALSE;
1129 }
1130#endif
1131 /* Pipe PC */
1132 for (i = 0; i < PDAMON_TC_NUM_PER_CORE; i++) {
1133 for (j = 0; j < PDAMON_IA_PIPED_CNT; j++) {
1134 raw->piped_pc[i][j].pc = DRV_Reg32(PDAMON_BREG_IA_PC_PIPE(core, i, j));
1135 raw->piped_pc[i][j].tc = i;
1136 raw->piped_pc[i][j].frc = DRV_Reg32(PDAMON_BREG_IA_FRC_PIPE(core, i));
1137 }
1138 }
1139 /* DA wrap status */
1140#if defined(__MD97__)
1141 raw->da_wrap.Raw = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core, 0));
1142 raw->da_wrap_ext.Raw = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core, 4));
1143#else
1144 raw->da_wrap.Raw = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core));
1145#endif
1146 /* DA - TC0 */
1147 cpu.tc_id = 0;
1148 idx = 0;
1149 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1150 cnt = (info.pairs > PDAMON_TC_DA_CNT(core, 0)) ? PDAMON_TC_DA_CNT(core, 0) : info.pairs;
1151 pdamon_get_da_raw_by_tc(&raw->da[idx], cnt, &cpu, &info);
1152 } else {
1153 // ASSERT(0);
1154 flag_sram = KAL_FALSE;
1155 }
1156 /* DA - TC1 */
1157 cpu.tc_id = 1;
1158 idx += PDAMON_TC_DA_CNT(core, 0);
1159 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1160 cnt = (info.pairs > PDAMON_TC_DA_CNT(core, 1)) ? PDAMON_TC_DA_CNT(core, 1) : info.pairs;
1161 pdamon_get_da_raw_by_tc(&raw->da[idx], cnt, &cpu, &info);
1162 } else {
1163 // ASSERT(0);
1164 flag_sram = KAL_FALSE;
1165 }
1166 /* DA - TC2 */
1167 cpu.tc_id = 2;
1168 idx += PDAMON_TC_DA_CNT(core, 1);
1169 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1170 cnt = (info.pairs > PDAMON_TC_DA_CNT(core, 2)) ? PDAMON_TC_DA_CNT(core, 2) : info.pairs;
1171 pdamon_get_da_raw_by_tc(&raw->da[idx], cnt, &cpu, &info);
1172 } else {
1173 // ASSERT(0);
1174 flag_sram = KAL_FALSE;
1175 }
1176 /* DA - TC3 */
1177 cpu.tc_id = 3;
1178 idx += PDAMON_TC_DA_CNT(core, 2);
1179 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1180 cnt = (info.pairs > PDAMON_TC_DA_CNT(core, 3)) ? PDAMON_TC_DA_CNT(core, 3) : info.pairs;
1181 pdamon_get_da_raw_by_tc(&raw->da[idx], cnt, &cpu, &info);
1182 } else {
1183 // ASSERT(0);
1184 flag_sram = KAL_FALSE;
1185 }
1186#if defined(__MD97__)
1187 /* DA - TC4 */
1188 cpu.tc_id = 4;
1189 idx += PDAMON_TC_DA_CNT(core, 3);
1190 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1191 cnt = (info.pairs > PDAMON_TC_DA_CNT(core, 4)) ? PDAMON_TC_DA_CNT(core, 4) : info.pairs;
1192 pdamon_get_da_raw_by_tc(&raw->da[idx], cnt, &cpu, &info);
1193 } else {
1194 // ASSERT(0);
1195 flag_sram = KAL_FALSE;
1196 }
1197 /* DA - TC5 */
1198 cpu.tc_id = 5;
1199 idx += PDAMON_TC_DA_CNT(core, 4);
1200 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1201 cnt = (info.pairs > PDAMON_TC_DA_CNT(core, 5)) ? PDAMON_TC_DA_CNT(core, 5) : info.pairs;
1202 pdamon_get_da_raw_by_tc(&raw->da[idx], cnt, &cpu, &info);
1203 } else {
1204 // ASSERT(0);
1205 flag_sram = KAL_FALSE;
1206 }
1207#endif
1208 /* Pipe DA */
1209 raw->piped_da[0].pc = DRV_Reg32(PDAMON_BREG_DA_PC_PIPE(core));
1210 raw->piped_da[0].da = DRV_Reg32(PDAMON_BREG_DA_DA_PIPE(core));
1211 raw->piped_da[0].frc = DRV_Reg32(PDAMON_BREG_DA_FRC_PIPE(core));
1212#if defined(__MD93__)
1213 raw->piped_da[0].tc = 0xDEADBEEF;
1214#elif defined(__MD95__)
1215 raw->piped_da[0].tc = DRV_Reg32(PDAMON_BREG_DA_TC_PIPE(core));
1216 raw->first_stop.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_EVENT(core));
1217#elif defined(__MD97__)
1218 raw->piped_da[0].tc = DRV_Reg32(PDAMON_BREG_DA_TC_PIPE(core));
1219 raw->first_stop.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_EVENT(core));
1220 raw->first_stop_frc.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_FRC(core));
1221#endif
1222 raw->record_sts.Raw = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(core));
1223 raw->sw_trig = DRV_Reg32(PDAMON_BREG_SW_TRIG);
1224 if(flag_sram == KAL_TRUE)
1225 raw->flag = KAL_TRUE;
1226 else
1227 raw->flag = KAL_FALSE;
1228
1229 return PDAMON_RET_OK;
1230}
1231
1232PDAMON_RET drv_pdamon_ex_get_raw(PDAMON_CORE_SEL core, PDAMON_EX_RAW_T *raw)
1233{
1234 kal_uint32 i = 0, j = 0, ex_idx = 0, ex_cnt = 0;
1235 pdamon_cpuinfo_st cpu = {0};
1236 pdamon_sram_info_st info = {0};
1237
1238 if (raw == NULL)
1239 return PDAMON_RET_INVALID_ARGUMENT;
1240 cpu.core_id = core;
1241
1242 raw->last_tc_id = DRV_Reg32(PDAMON_BREG_LAST_TC_ID(cpu.core_id));
1243 /* PC wrap status */
1244#if defined(__MD97__)
1245 raw->pc_wrap.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core, 0));
1246 raw->pc_wrap_ext.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core, 4));
1247#else
1248 raw->pc_wrap.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core));
1249#endif
1250 /* Pipe PC dual-issue status */
1251#if defined(__MD97__) && !defined(MT6297_IA)
1252 raw->piped_pc_dual_issue = DRV_Reg32(PDAMON_BREG_DUAL_ISSUE_STS(core));
1253#endif
1254 /* Pipe PC */
1255 for (i = 0; i < PDAMON_TC_NUM_PER_CORE; i++) {
1256 for (j = 0; j < PDAMON_IA_PIPED_CNT; j++) {
1257 raw->piped_pc[i][j] = DRV_Reg32(PDAMON_BREG_IA_PC_PIPE(core, i, j));
1258 }
1259 }
1260 /* Pipe PC FRC */
1261 for (i = 0; i < PDAMON_EX_PIPED_FRC_CNT_V2; i++) {
1262 raw->piped_pc_frc[i] = DRV_Reg32(PDAMON_BREG_IA_FRC_PIPE(core, i));
1263 }
1264 /* PC - TC0 */
1265 cpu.tc_id = 0;
1266 ex_idx = 0;
1267 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1268 ex_cnt = (info.pairs > g_pdamon_ex_ia_cnt[0]) ? g_pdamon_ex_ia_cnt[0] : info.pairs;
1269 pdamon_ex_get_pc_raw_by_tc(&raw->pc[ex_idx], ex_cnt, &cpu, &info);
1270 } else {
1271 // ASSERT(0);
1272 }
1273 /* PC - TC1 */
1274 cpu.tc_id = 1;
1275 ex_idx += g_pdamon_ex_ia_cnt[0];
1276 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1277 ex_cnt = (info.pairs > g_pdamon_ex_ia_cnt[1]) ? g_pdamon_ex_ia_cnt[1] : info.pairs;
1278 pdamon_ex_get_pc_raw_by_tc(&raw->pc[ex_idx], ex_cnt, &cpu, &info);
1279 } else {
1280 // ASSERT(0);
1281 }
1282 /* PC - TC2 */
1283 cpu.tc_id = 2;
1284 ex_idx += g_pdamon_ex_ia_cnt[1];
1285 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1286 ex_cnt = (info.pairs > g_pdamon_ex_ia_cnt[2]) ? g_pdamon_ex_ia_cnt[2] : info.pairs;
1287 pdamon_ex_get_pc_raw_by_tc(&raw->pc[ex_idx], ex_cnt, &cpu, &info);
1288 } else {
1289 // ASSERT(0);
1290 }
1291 /* PC - TC3 */
1292 cpu.tc_id = 3;
1293 ex_idx += g_pdamon_ex_ia_cnt[2];
1294 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1295 ex_cnt = (info.pairs > g_pdamon_ex_ia_cnt[3]) ? g_pdamon_ex_ia_cnt[3] : info.pairs;
1296 pdamon_ex_get_pc_raw_by_tc(&raw->pc[ex_idx], ex_cnt, &cpu, &info);
1297 } else {
1298 // ASSERT(0);
1299 }
1300#if defined(__MD97__)
1301 /* PC - TC4 */
1302 cpu.tc_id = 4;
1303 ex_idx += g_pdamon_ex_ia_cnt[3];
1304 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1305 ex_cnt = (info.pairs > g_pdamon_ex_ia_cnt[4]) ? g_pdamon_ex_ia_cnt[4] : info.pairs;
1306 pdamon_ex_get_pc_raw_by_tc(&raw->pc[ex_idx], ex_cnt, &cpu, &info);
1307 } else {
1308 // ASSERT(0);
1309 }
1310 /* PC - TC5 */
1311 cpu.tc_id = 5;
1312 ex_idx += g_pdamon_ex_ia_cnt[4];
1313 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1314 ex_cnt = (info.pairs > g_pdamon_ex_ia_cnt[5]) ? g_pdamon_ex_ia_cnt[5] : info.pairs;
1315 pdamon_ex_get_pc_raw_by_tc(&raw->pc[ex_idx], ex_cnt, &cpu, &info);
1316 } else {
1317 // ASSERT(0);
1318 }
1319#endif
1320 /* DA wrap status */
1321#if defined(__MD97__)
1322 raw->da_wrap.Raw = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core, 0));
1323 raw->da_wrap_ext.Raw = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core, 4));
1324#else
1325 raw->da_wrap.Raw = DRV_Reg32(PDAMON_BREG_DA_SRAM_WRAP_STS(core));
1326#endif
1327 /* Pipe DA */
1328 raw->piped_da[0].pc = DRV_Reg32(PDAMON_BREG_DA_PC_PIPE(core));
1329 raw->piped_da[0].da = DRV_Reg32(PDAMON_BREG_DA_DA_PIPE(core));
1330 raw->piped_da[0].frc = DRV_Reg32(PDAMON_BREG_DA_FRC_PIPE(core));
1331#if defined(__MD93__)
1332 raw->piped_da[0].tc = 0xDEADBEEF;
1333//#elif defined(__MD95__)
1334#elif defined(__MD95__) || defined(__MD97__)
1335 raw->piped_da[0].tc = DRV_Reg32(PDAMON_BREG_DA_TC_PIPE(core));
1336 raw->first_stop.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_EVENT(core));
1337#endif
1338 /* DA - TC0 */
1339 cpu.tc_id = 0;
1340 ex_idx = 0;
1341 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1342 ex_cnt = (info.pairs > g_pdamon_ex_da_cnt[0]) ? g_pdamon_ex_da_cnt[0] : info.pairs;
1343 pdamon_ex_get_da_raw_by_tc(&raw->da[ex_idx], ex_cnt, &cpu, &info);
1344 } else {
1345 // ASSERT(0);
1346 }
1347 /* DA - TC1 */
1348 cpu.tc_id = 1;
1349 ex_idx += g_pdamon_ex_da_cnt[0];
1350 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1351 ex_cnt = (info.pairs > g_pdamon_ex_da_cnt[1]) ? g_pdamon_ex_da_cnt[1] : info.pairs;
1352 pdamon_ex_get_da_raw_by_tc(&raw->da[ex_idx], ex_cnt, &cpu, &info);
1353 } else {
1354 // ASSERT(0);
1355 }
1356 /* DA - TC2 */
1357 cpu.tc_id = 2;
1358 ex_idx += g_pdamon_ex_da_cnt[1];
1359 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1360 ex_cnt = (info.pairs > g_pdamon_ex_da_cnt[2]) ? g_pdamon_ex_da_cnt[2] : info.pairs;
1361 pdamon_ex_get_da_raw_by_tc(&raw->da[ex_idx], ex_cnt, &cpu, &info);
1362 } else {
1363 // ASSERT(0);
1364 }
1365 /* DA - TC3 */
1366 cpu.tc_id = 3;
1367 ex_idx += g_pdamon_ex_da_cnt[2];
1368 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1369 ex_cnt = (info.pairs > g_pdamon_ex_da_cnt[3]) ? g_pdamon_ex_da_cnt[3] : info.pairs;
1370 pdamon_ex_get_da_raw_by_tc(&raw->da[ex_idx], ex_cnt, &cpu, &info);
1371 } else {
1372 // ASSERT(0);
1373 }
1374#if defined(__MD97__)
1375 /* DA - TC4 */
1376 cpu.tc_id = 4;
1377 ex_idx += g_pdamon_ex_da_cnt[3];
1378 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1379 ex_cnt = (info.pairs > g_pdamon_ex_da_cnt[4]) ? g_pdamon_ex_da_cnt[4] : info.pairs;
1380 pdamon_ex_get_da_raw_by_tc(&raw->da[ex_idx], ex_cnt, &cpu, &info);
1381 } else {
1382 // ASSERT(0);
1383 }
1384 /* DA - TC5 */
1385 cpu.tc_id = 5;
1386 ex_idx += g_pdamon_ex_da_cnt[4];
1387 if (pdamon_find_first_idx(KAL_FALSE, &cpu, &info) == KAL_TRUE) {
1388 ex_cnt = (info.pairs > g_pdamon_ex_da_cnt[5]) ? g_pdamon_ex_da_cnt[5] : info.pairs;
1389 pdamon_ex_get_da_raw_by_tc(&raw->da[ex_idx], ex_cnt, &cpu, &info);
1390 } else {
1391 // ASSERT(0);
1392 }
1393#endif
1394 /* Status */
1395 raw->record_sts.Raw = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(core));
1396#if defined(__MD95__)
1397 raw->first_stop.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_EVENT(core));
1398#elif defined(__MD97__)
1399 raw->first_stop.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_EVENT(core));
1400 raw->first_stop_frc.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_FRC(core));
1401#endif
1402 raw->sw_trig = DRV_Reg32(PDAMON_BREG_SW_TRIG);
1403
1404 return PDAMON_RET_OK;
1405}
1406
1407PDAMON_RET drv_pdamon_nex_get_raw(PDAMON_CORE_SEL core, PDAMON_NEX_RAW_T *raw)
1408{
1409 kal_uint32 i = 0, j = 0, nex_idx = 0, nex_cnt = 0;
1410 pdamon_cpuinfo_st cpu = {0};
1411 pdamon_sram_info_st info = {0};
1412
1413 if (raw == NULL)
1414 return PDAMON_RET_INVALID_ARGUMENT;
1415 cpu.core_id = core;
1416
1417 /* Status */
1418 raw->record_sts.Raw = DRV_Reg32(PDAMON_BREG_CORE_RECORD_STS(core));
1419#if defined(__MD95__)
1420 raw->first_stop.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_EVENT(core));
1421#elif defined(__MD97__)
1422 raw->first_stop.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_EVENT(core));
1423 raw->first_stop_frc.Raw = DRV_Reg32(PDAMON_BREG_CORE_FIRST_STOP_FRC(core));
1424#endif
1425 raw->sw_trig = DRV_Reg32(PDAMON_BREG_SW_TRIG);
1426 /* PC wrap status */
1427#if defined(__MD97__)
1428 raw->pc_wrap.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core, 0));
1429 raw->pc_wrap_ext.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core, 4));
1430#else
1431 raw->pc_wrap.Raw = DRV_Reg32(PDAMON_BREG_PC_SRAM_WRAP_STS(core));
1432#endif
1433 /* Pipe PC */
1434 for (i = 0; i < PDAMON_TC_NUM_PER_CORE; i++) {
1435 for (j = 0; j < PDAMON_IA_PIPED_CNT; j++) {
1436 raw->piped_pc[i][j] = DRV_Reg32(PDAMON_BREG_IA_PC_PIPE(core, i, j));
1437 }
1438 }
1439 /* Pipe PC FRC */
1440 for (i = 0; i < PDAMON_NEX_PIPED_FRC_CNT_V2; i++) {
1441 raw->piped_pc_frc[i] = DRV_Reg32(PDAMON_BREG_IA_FRC_PIPE(core, i));
1442 }
1443 /* PC - TC0 */
1444 cpu.tc_id = 0;
1445 nex_idx = 0;
1446 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1447 nex_cnt = (info.pairs > g_pdamon_nex_ia_cnt[0]) ? g_pdamon_nex_ia_cnt[0] : info.pairs;
1448 pdamon_ex_get_pc_raw_by_tc(&raw->pc[nex_idx], nex_cnt, &cpu, &info);
1449 } else {
1450 // ASSERT(0);
1451 }
1452 /* PC - TC1 */
1453 cpu.tc_id = 1;
1454 nex_idx += g_pdamon_nex_ia_cnt[0];
1455 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1456 nex_cnt = (info.pairs > g_pdamon_nex_ia_cnt[1]) ? g_pdamon_nex_ia_cnt[1] : info.pairs;
1457 pdamon_ex_get_pc_raw_by_tc(&raw->pc[nex_idx], nex_cnt, &cpu, &info);
1458 } else {
1459 // ASSERT(0);
1460 }
1461 /* PC - TC2 */
1462 cpu.tc_id = 2;
1463 nex_idx += g_pdamon_nex_ia_cnt[1];
1464 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1465 nex_cnt = (info.pairs > g_pdamon_nex_ia_cnt[2]) ? g_pdamon_nex_ia_cnt[2] : info.pairs;
1466 pdamon_ex_get_pc_raw_by_tc(&raw->pc[nex_idx], nex_cnt, &cpu, &info);
1467 } else {
1468 // ASSERT(0);
1469 }
1470 /* PC - TC3 */
1471 cpu.tc_id = 3;
1472 nex_idx += g_pdamon_nex_ia_cnt[2];
1473 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1474 nex_cnt = (info.pairs > g_pdamon_nex_ia_cnt[3]) ? g_pdamon_nex_ia_cnt[3] : info.pairs;
1475 pdamon_ex_get_pc_raw_by_tc(&raw->pc[nex_idx], nex_cnt, &cpu, &info);
1476 } else {
1477 // ASSERT(0);
1478 }
1479#if defined(__MD97__)
1480 /* PC - TC4 */
1481 cpu.tc_id = 4;
1482 nex_idx += g_pdamon_nex_ia_cnt[3];
1483 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1484 nex_cnt = (info.pairs > g_pdamon_nex_ia_cnt[4]) ? g_pdamon_nex_ia_cnt[4] : info.pairs;
1485 pdamon_ex_get_pc_raw_by_tc(&raw->pc[nex_idx], nex_cnt, &cpu, &info);
1486 } else {
1487 // ASSERT(0);
1488 }
1489 /* PC - TC5 */
1490 cpu.tc_id = 5;
1491 nex_idx += g_pdamon_nex_ia_cnt[4];
1492 if (pdamon_find_first_idx(KAL_TRUE, &cpu, &info) == KAL_TRUE) {
1493 nex_cnt = (info.pairs > g_pdamon_nex_ia_cnt[5]) ? g_pdamon_nex_ia_cnt[5] : info.pairs;
1494 pdamon_ex_get_pc_raw_by_tc(&raw->pc[nex_idx], nex_cnt, &cpu, &info);
1495 } else {
1496 // ASSERT(0);
1497 }
1498#endif
1499
1500 return PDAMON_RET_OK;
1501}
1502
1503PDAMON_RET drv_pdamon_ex_get_all_raw()
1504{
1505 PDAMON_CORE_SEL i = PDAMON_CORE_0;
1506
1507 kal_mem_set(g_pdamon_full, 0, sizeof(PDAMON_RAW_PER_CORE_T) * PDAMON_CORE_NUM);
1508 for (i = PDAMON_CORE_0; i < PDAMON_CORE_CNT; i++) {
1509 /* Get raw data of per core */
1510 drv_pdamon_get_raw(i, &g_pdamon_full[i]);
1511 g_pdamon_full[i].flag = KAL_TRUE;
1512 }
1513
1514 return PDAMON_RET_OK;
1515}
1516
1517PDAMON_RET drv_pdamon_mask_stop_sources(PDAMON_CORE_SEL core, PDAMON_STOP_SOURCE sources, kal_bool mask)
1518{
1519 kal_uint32 mask_ctrl = 0;
1520
1521 if (sources == PDAMON_SRC_NONE) {
1522 return PDAMON_RET_OK;
1523 }
1524
1525 if ((sources & PDAMON_SRC_PC0_MATCH) ||
1526 (sources & PDAMON_SRC_PC1_MATCH) ||
1527 (sources & PDAMON_SRC_PC2_MATCH) ||
1528 (sources & PDAMON_SRC_PC3_MATCH) ||
1529 (sources & PDAMON_SRC_PC4_MATCH) ||
1530 (sources & PDAMON_SRC_PC5_MATCH)) {
1531 return PDAMON_RET_INVALID_ARGUMENT;
1532 }
1533
1534 if (sources & PDAMON_SRC_MDMCU_BUSMON)
1535 mask_ctrl |= PDAMON_EVT_MASK_BUSMON_MDMCU;
1536 if (sources & PDAMON_SRC_MDINFRA_BUSMON)
1537 mask_ctrl |= PDAMON_EVT_MASK_BUSMON_MDINFRA;
1538 if (sources & PDAMON_SRC_MD_BUSERR)
1539 mask_ctrl |= PDAMON_EVT_MASK_BUS_MD;
1540 if (sources & PDAMON_SRC_RGU)
1541 mask_ctrl |= PDAMON_EVT_MASK_RGU;
1542 if (sources & PDAMON_SRC_RMPU)
1543 mask_ctrl |= PDAMON_EVT_MASK_RMPU;
1544 if (sources & PDAMON_SRC_CTI)
1545 mask_ctrl |= PDAMON_EVT_MASK_CTI;
1546 if (sources & PDAMON_SRC_CMERR)
1547 mask_ctrl |= PDAMON_EVT_MASK_CM_DECERR;
1548#if defined(__MD93__)
1549 if (sources & PDAMON_SRC_SPRAM_DECERR)
1550 mask_ctrl |= PDAMON_EVT_MASK_SPRAM_DECERR;
1551#endif
1552 if (sources & PDAMON_SRC_MDMCU_DECERR)
1553 mask_ctrl |= PDAMON_EVT_MASK_MDMCU_DECERR;
1554 if (sources & PDAMON_SRC_GCR)
1555 mask_ctrl |= PDAMON_EVT_MASK_GCR;
1556 if (sources & PDAMON_SRC_SW)
1557 mask_ctrl |= PDAMON_EVT_MASK_SW;
1558
1559 /*
1560 * Mask/Unmask source
1561 */
1562 g_pdamon_event_mask.Raw |= DRV_Reg32(PDAMON_BREG_EVENT_MASK);
1563 if (mask == KAL_TRUE) {
1564 g_pdamon_event_mask.Raw |= mask_ctrl;
1565 } else {
1566 g_pdamon_event_mask.Raw &= (~(mask_ctrl));
1567 }
1568 DRV_WriteReg32(PDAMON_BREG_EVENT_MASK, g_pdamon_event_mask.Raw);
1569 MO_Sync();
1570
1571 return PDAMON_RET_OK;
1572}
1573