blob: d84c6ea67fecbd1b56ea4dc83ba8872fd57f84f1 [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) 2005
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/*******************************************************************************
37 *
38 * Filename:
39 * ---------
40 * dsmgr.h
41 *
42 * Project:
43 * --------
44 *
45 *
46 * Description:
47 * ------------
48 * Dynamic Section Manager for dynamic section relocation into TCM(internal SRAM)
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *==============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 * removed!
66 *
67 * removed!
68 * removed!
69 * removed!
70 * removed!
71 *
72 * removed!
73 * removed!
74 * removed!
75 * removed!
76 *
77 * removed!
78 * removed!
79 * removed!
80 * removed!
81 *
82 * removed!
83 * removed!
84 * removed!
85 *
86 * removed!
87 * removed!
88 * removed!
89 *
90 * removed!
91 * removed!
92 * removed!
93 *
94 * removed!
95 * removed!
96 * removed!
97 *
98 * removed!
99 * removed!
100 * removed!
101 * removed!
102 * removed!
103 * removed!
104 * removed!
105 * removed!
106 * removed!
107 *
108 * removed!
109 * removed!
110 * removed!
111 *
112 * removed!
113 * removed!
114 * removed!
115 *
116 * removed!
117 * removed!
118 * removed!
119 *
120 * removed!
121 * removed!
122 * removed!
123 *
124 * removed!
125 * removed!
126 * removed!
127 *
128 *------------------------------------------------------------------------------
129 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
130 *==============================================================================
131 *******************************************************************************/
132
133#ifndef __DSMGR_H__
134#define __DSMGR_H__
135
136
137/*******************************************************************************
138 * Included header files
139 *******************************************************************************/
140
141
142
143/*******************************************************************************
144 * definition
145 *******************************************************************************/
146#if defined(__DSM_CONFIGURATION__)
147
148/* If you want to specify a section to be loaded by GDMA or CPU, please add
149 DYNAMIC_SECTION_LOAD_BY_GDMA(section_id) or DYNAMIC_SECTION_LOAD_BY_CPU(section_id) in below, respectively.
150*/
151
152 DYNAMIC_SECTION_LOAD_BY_CPU(DYNAMIC_SECTION_INTSRAM_UBIN_W_CORE0)
153 DYNAMIC_SECTION_LOAD_BY_CPU(DYNAMIC_SECTION_INTSRAM_UBIN_T_CORE0)
154 DYNAMIC_SECTION_LOAD_BY_GDMA(DYNAMIC_SECTION_INTSRAM_ADT_W_CORE0)
155 DYNAMIC_SECTION_LOAD_BY_GDMA(DYNAMIC_SECTION_INTSRAM_ADT_T_CORE0)
156 DYNAMIC_SECTION_LOAD_BY_GDMA(DYNAMIC_SECTION_INTSRAM_ADT_L_CORE0)
157 DYNAMIC_SECTION_LOAD_BY_GDMA(DYNAMIC_SECTION_INTSRAM_ADT_W2_CORE0)
158#else /* !efined(__DSM_CONFIGURATION__) */
159
160 typedef enum {
161 DYNAMIC_SECTION_INTSRAM_UBIN_W_CORE0 = 0,
162 DYNAMIC_SECTION_INTSRAM_UBIN_T_CORE0,
163 DYNAMIC_SECTION_INTSRAM_ADT_W_CORE0,
164 DYNAMIC_SECTION_INTSRAM_ADT_T_CORE0,
165 DYNAMIC_SECTION_INTSRAM_ADT_L_CORE0,
166 DYNAMIC_SECTION_INTSRAM_ADT_W2_CORE0,
167 /* insert id before this line*/
168 DYNAMIC_SECTION_NUM /* 6 = TOTAL_DSM_SECTION */
169 } dsm_section_id;
170
171 /* make sure to define TOTAL_DSM_SECTION as valuse of DYNAMIC_SECTION_NUM */
172 #define TOTAL_DSM_SECTION (6)
173
174#define DSM_TOTAL_RECORD_COUNT 20
175
176typedef enum {
177 DSM_ACTION_NO_ACTION,
178 DSM_ACTION_LOAD_BEFORE,
179 DSM_ACTION_LOAD_START,
180 DSM_ACTION_LOAD_UNLOAD_OVERLAP_SECTION,
181 DSM_ACTION_LOAD_END,
182 DSM_ACTION_LOAD_GDMA_LOAD_END,
183 DSM_ACTION_LOAD_CANCEL_GDMA_LOAD,
184 DSM_ACTION_LOAD_CONFIG_GDMA_LOAD_RO_CODE,
185 DSM_ACTION_UNLOAD_START,
186 DSM_ACTION_UNLOAD_END,
187} DSM_ACTION;
188
189#if defined(__MTK_TARGET__)
190
191#define LOAD_DYNAMIC_SECTION_INTSRAM_UBIN_W DSM_Load(DYNAMIC_SECTION_INTSRAM_UBIN_W_CORE0);
192#define LOAD_DYNAMIC_SECTION_INTSRAM_UBIN_T DSM_Load(DYNAMIC_SECTION_INTSRAM_UBIN_T_CORE0);
193#define LOAD_DYNAMIC_SECTION_INTSRAM_ADT_W DSM_Load(DYNAMIC_SECTION_INTSRAM_ADT_W_CORE0);
194#define LOAD_DYNAMIC_SECTION_INTSRAM_ADT_T DSM_Load(DYNAMIC_SECTION_INTSRAM_ADT_T_CORE0);
195#define LOAD_DYNAMIC_SECTION_INTSRAM_ADT_L DSM_Load(DYNAMIC_SECTION_INTSRAM_ADT_L_CORE0);
196#define LOAD_DYNAMIC_SECTION_INTSRAM_ADT_W2 DSM_Load(DYNAMIC_SECTION_INTSRAM_ADT_W2_CORE0);
197
198#define UNLOAD_DYNAMIC_SECTION_INTSRAM_UBIN_W DSM_Unload(DYNAMIC_SECTION_INTSRAM_UBIN_W_CORE0);
199#define UNLOAD_DYNAMIC_SECTION_INTSRAM_UBIN_T DSM_Unload(DYNAMIC_SECTION_INTSRAM_UBIN_T_CORE0);
200#define UNLOAD_DYNAMIC_SECTION_INTSRAM_ADT_W DSM_Unload(DYNAMIC_SECTION_INTSRAM_ADT_W_CORE0);
201#define UNLOAD_DYNAMIC_SECTION_INTSRAM_ADT_T DSM_Unload(DYNAMIC_SECTION_INTSRAM_ADT_T_CORE0);
202#define UNLOAD_DYNAMIC_SECTION_INTSRAM_ADT_L DSM_Unload(DYNAMIC_SECTION_INTSRAM_ADT_L_CORE0);
203#define UNLOAD_DYNAMIC_SECTION_INTSRAM_ADT_W2 DSM_Unload(DYNAMIC_SECTION_INTSRAM_ADT_W2_CORE0);
204
205#endif
206
207#define DYNAMIC_SECTION_INTSRAM_UBIN_W DYNAMIC_SECTION_INTSRAM_UBIN_W_CORE0
208#define DYNAMIC_SECTION_INTSRAM_UBIN_T DYNAMIC_SECTION_INTSRAM_UBIN_T_CORE0
209
210
211/* define dsm function return status */
212typedef enum {
213 DSM_FAIL, /* the operation has failed */
214 DSM_SUCCESS, /* the operation is succeeded */
215 DSM_LOAD_BEFORE, /* the section has been load before */
216 DSM_FAIL_TO_CANCEL_GDMA_LOADING, /* the section is loaded by CPU or loading by GDMA is done */
217 DSM_LOAD_BY_GDMA, /* the section will be load by GDMA */
218} dsm_status;
219
220/* define dsm section status */
221typedef enum {
222 DSM_LOAD, /* the section is loaded */
223 DSM_LOADING, /* the section is during loading */
224 DSM_UNLOAD, /* the section is not loaded */
225 DSM_UNLOADING, /* the section is during unloading */
226} dsm_section_status;
227
228
229
230typedef void (*DSM_gdma_pcb_f)(void *info);
231
232
233/*******************************************************************************
234 * External Function Declaration
235 *******************************************************************************/
236 /*******************************************************************************
237 * <GROUP Functions>
238 *
239 * FUNCTION
240 * DSM_Load
241 * DESCRIPTION
242 * This function will load specified section to corresponding address which overlaps with other sections.
243 * There are 2 ways to load a section
244 * 1) Load by CPU (default)
245 * 2) Load by GDMA
246 * If the section is loaded by CPU, it will return DSM_SUCCESS after the loading is done.
247 * If the section is loaded by GDMA, it will return directly with return value DSM_LOAD_BY_GDMA. You can
248 * register a callback function by using DSM_RegisterGDMACallback. After the section is loaded by GDMA,
249 * the callback function will be executed in GDMA LISR.
250 * If the specified section is loaded before, it will return directly with return value DSM_LOAD_BEFORE.
251 * If there is an overlapped section is loaded,
252 * 1) if no data in the overlapped loaded section, system will mark the loaded section to unload status and
253 * keep loading specified section to overwrite the overlapped section;
254 * 2) otherwise, fatal error will happened since there are unloaded data in overlapped section which could
255 * not be overwritten.
256 * PARAMETERS
257 * dynamic_section_id: [IN] id of specified section to load
258 * RETURN VALUES
259 * 1) DSM_SUCCESS: load the specified section successfully
260 * 2) DSM_LOAD_BEFORE: the specified section has been load before
261 * 3) DSM_LOAD_BY_GDMA: the section will be load by GDMA
262 * NOTE
263 * If the specified section has not been loaded before, the section will be set to initial value which means
264 * loaded from load view; otherwise, the data will be restored from system.
265 * SEE ALSO
266 * DSM_Unload, DSM_IsLoad, DSM_RegisterGDMACallback, DSM_CancelLoadingByGDMA
267 ******************************************************************************/
268dsm_status DSM_Load(kal_uint32 dynamic_section_id);
269
270/*******************************************************************************
271 * <GROUP Functions>
272 *
273 * FUNCTION
274 * DSM_Unload
275 * DESCRIPTION
276 * This function will unload specified section which means the data in the specified section will be backed up
277 * by system. System backup the data by CPU.
278 * It will return DSM_SUCCESS after the un-loading is done.
279 * If there is no data to backup, it will return directly with return value DSM_UNLOAD_NOTHING.
280 * Fatal error will happened if specified section has not been loaded before.
281 * PARAMETERS
282 * dynamic_section_id: [IN] id of specified section to unload
283 * RETURN VALUES
284 * 1) DSM_SUCCESS: unload the specified section successfully
285 * 2) DSM_UNLOAD_NOTHING.: there is no data to backup
286 * NOTE
287 * N/A
288 * SEE ALSO
289 * DSM_Load, DSM_QuerySectionStatus, DSM_IsLoad, DSM_RegisterGDMACallback, DSM_CancelLoadingByGDMA
290 ******************************************************************************/
291dsm_status DSM_Unload(kal_uint32 dynamic_section_id);
292
293/*******************************************************************************
294 * <GROUP Functions>
295 *
296 * FUNCTION
297 * DSM_QuerySectionStatus
298 * DESCRIPTION
299 * This function return the status of specified section
300 * PARAMETERS
301 * dynamic_section_id: [IN] id of specified section to query
302 * RETURN VALUES
303 * 1) DSM_LOAD: the section is loaded
304 * 2) DSM_LOADING: the section is during loading
305 * 3) DSM_UNLOAD: the section is not loaded
306 * 4) DSM_UNLOADING: the section is during unloading
307 * NOTE
308 * N/A
309 * SEE ALSO
310 * DSM_Load, DSM_Unload
311 ******************************************************************************/
312dsm_section_status DSM_QuerySectionStatus(kal_uint32 dynamic_section_id);
313
314
315
316/*******************************************************************************
317 * <GROUP Functions>
318 *
319 * FUNCTION
320 * DSM_IsLoad
321 * DESCRIPTION
322 * This function return true if the specified section is loaded.
323 * PARAMETERS
324 * dynamic_section_id: [IN] id of specified section to query
325 * RETURN VALUES
326 * 1) KAL_TRUE: the specified section is loaded.
327 * 2) KAL_FALSE: the specified section is not loaded.
328 * NOTE
329 * N/A
330 * SEE ALSO
331 * DSM_Load, DSM_Unload, DSM_QuerySectionStatus
332 ******************************************************************************/
333kal_bool DSM_IsLoad(kal_uint32 dynamic_section_id);
334
335/*******************************************************************************
336 * <GROUP Functions>
337 *
338 * FUNCTION
339 * DSM_RegisterGDMACallback
340 * DESCRIPTION
341 * This function is designed for user to register callback function. If the specified section is loaded by GDMA
342 * and loading by GDMA is done, the callback function will be called during GDMA LISR.
343 * PARAMETERS
344 * dynamic_section_id: [IN] id of specified section
345 * DSM_gdma_cb: [IN] callback function. Prototype is "typedef void (*DSM_gdma_pcb_f)(void *info)"
346 * DSM_gdma_param: [IN] the argument for callback function
347 * RETURN VALUES
348 * N/A
349 * NOTE
350 * Fatal error is happened if the specified section is not load by GDMA.
351 * SEE ALSO
352 * DSM_Load, DSM_IsLoad, DSM_QuerySectionStatus, DSM_CancelLoadingByGDMA
353 ******************************************************************************/
354void DSM_RegisterGDMACallback(kal_uint32 dynamic_section_id, DSM_gdma_pcb_f DSM_gdma_cb, void * DSM_gdma_param);
355
356/*******************************************************************************
357 * <GROUP Functions>
358 *
359 * FUNCTION
360 * DSM_CancelLoadingByGDMA
361 * DESCRIPTION
362 * This function will stop loading target section by GDMA.
363 * PARAMETERS
364 * dynamic_section_id: [IN] id of specified section
365 * RETURN VALUES
366 * DSM_FAIL_TO_CANCEL_GDMA_LOADING : if the section not loading GDMA (i.e. loading by CPU)
367 * DSM_SUCCESS : cancel loading successfully
368 * NOTE
369 * (1) it may late to stop GDMA and the callback function will be executed in LISR before we stop GDMA.
370 * Make sure to revert the things done by your callback function
371 * (2) Do not cancel your first loading if there are RWZI in your section; Otherwise, we will restore
372 * unexpected value from EMI and cause fatal error (checksum fail)
373 * (3) If cancel your non-first loading with RWZI in your section; we will restore the data which unload
374 * by you last time
375 * SEE ALSO
376 * DSM_Load, DSM_IsLoad, DSM_QuerySectionStatus
377 ******************************************************************************/
378dsm_status DSM_CancelLoadingByGDMA(kal_uint32 dynamic_section_id);
379
380
381#endif /* end of !efined(__DSM_CONFIGURATION__) */
382
383#endif /* __DSMGR_H__ */