1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2015-2020 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ////////////////////////////////////////////////////////////////////////////////////////////////////
96 // file halTSP_tee.c
97 // @brief Transport Stream Processer (TSP) HAL
98 // @author MStar Semiconductor,Inc.
99 ////////////////////////////////////////////////////////////////////////////////////////////////////
100 #include "regTSP_tee.h"
101 #include "halTSP_tee.h"
102
103 //--------------------------------------------------------------------------------------------------
104 // Driver Compiler Option
105 //--------------------------------------------------------------------------------------------------
106
107 //--------------------------------------------------------------------------------------------------
108 // TSP Hardware Abstraction Layer
109 //--------------------------------------------------------------------------------------------------
110 static MS_VIRT _virtRegBase = 0;
111
112 //--------------------------------------------------------------------------------------------------
113 // Macro of bit operations
114 //--------------------------------------------------------------------------------------------------
115 #define TSP_TSP0_REG(addr) (*((volatile MS_U16*)(_virtRegBase + 0x2A00 + ((addr)<<2))))
116 #define TSP_TSP1_REG(addr) (*((volatile MS_U16*)(_virtRegBase + 0x2C00 + ((addr)<<2))))
117 #define TSP_MMFI_REG(addr) (*((volatile MS_U16*)(_virtRegBase + 0x3800 + ((addr)<<2))))
118
119 //--------------------------------------------------------------------------------------------------
120 // Forward declaration
121 //--------------------------------------------------------------------------------------------------
122
123 //--------------------------------------------------------------------------------------------------
124 // Implementation
125 //--------------------------------------------------------------------------------------------------
HAL_TSP_Tee_SetBank(MS_VIRT virtBankAddr)126 MS_BOOL HAL_TSP_Tee_SetBank(MS_VIRT virtBankAddr)
127 {
128 _virtRegBase = virtBankAddr;
129
130 return TRUE;
131 }
132
HAL_TSP_Tee_Set_FWBuf(MS_PHY phyAddr,MS_U32 u32Size)133 MS_BOOL HAL_TSP_Tee_Set_FWBuf(MS_PHY phyAddr, MS_U32 u32Size)
134 {
135 MS_U32 u32FwAddr = ((MS_U32)phyAddr >> MIU_BUS) >> TSP_DNLD_ADDR_ALI_SHIFT;
136 MS_U32 u32FwSize = TSP_QMEM_SIZES;
137
138 //printf("[%s][%d] u32FwAddr %x, u32FwSize %x \n", __FUNCTION__, __LINE__, (int)u32FwAddr, (int)u32FwSize);
139
140 TSP_TSP0_REG(REG_TSP0_FW_DMA_ADDR_L) = ((MS_U16)u32FwAddr) & 0xFFFF;
141 TSP_TSP1_REG(REG_TSP1_FW_DMA_ADDR_H) = (MS_U16)(u32FwAddr >> 16) & TSP_FW_DMA_ADDR_H_MASK;
142 TSP_TSP0_REG(REG_TSP0_FW_DMA_NUM) = (MS_U16)u32FwSize;
143
144 //lock down register
145 TSP_TSP1_REG(REG_TSP1_ONEWAY) = TSP_TSP1_REG(REG_TSP1_ONEWAY) | TSP_FW_ONEWAY;
146
147 return TRUE;
148 }
149
HAL_TSP_Tee_Set_VQBuf(MS_PHY phyAddr,MS_U32 u32Size)150 MS_BOOL HAL_TSP_Tee_Set_VQBuf(MS_PHY phyAddr, MS_U32 u32Size)
151 {
152 MS_U32 u32VQSize = 0, u32UnitSize = 0;
153 MS_PHY phyVQBufStart = phyAddr, phyMiuAddr = 0;
154 MS_U8 u8ii = 0;
155
156 u32VQSize = ((u32Size >> MIU_BUS) / TSP_VQ_NUM) << MIU_BUS; //miu alignment
157 u32UnitSize = u32VQSize / TSP_VQ_PITCH;
158
159 //printf("[%s][%d] phyAddr %x, u32Size %x \n", __FUNCTION__, __LINE__, (int)phyAddr, (int)u32Size);
160 for(u8ii = 0; u8ii < TSP_VQ_NUM; u8ii++)
161 {
162 phyMiuAddr = phyVQBufStart >> MIU_BUS;
163 if(u8ii == 0)
164 {
165 TSP_TSP1_REG(REG_TSP1_VQ0_BASE_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
166 TSP_TSP1_REG(REG_TSP1_VQ0_BASE_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
167 TSP_TSP1_REG(REG_TSP1_VQ0_SIZE) = (MS_U16)(u32UnitSize & 0xFFFF);
168 }
169 else if(u8ii == 1)
170 {
171 TSP_TSP1_REG(REG_TSP1_VQ1_BASE_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
172 TSP_TSP1_REG(REG_TSP1_VQ1_BASE_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
173 TSP_TSP1_REG(REG_TSP1_VQ1_SIZE) = (MS_U16)(u32UnitSize & 0xFFFF);
174 }
175 else if(u8ii == 2)
176 {
177 TSP_TSP1_REG(REG_TSP1_VQ2_BASE_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
178 TSP_TSP1_REG(REG_TSP1_VQ2_BASE_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
179 TSP_TSP1_REG(REG_TSP1_VQ2_SIZE) = (MS_U16)(u32UnitSize & 0xFFFF);
180 }
181 else if(u8ii == 3)
182 {
183 TSP_TSP1_REG(REG_TSP1_VQ3_BASE_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
184 TSP_TSP1_REG(REG_TSP1_VQ3_BASE_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
185 TSP_TSP1_REG(REG_TSP1_VQ3_SIZE) = (MS_U16)(u32UnitSize & 0xFFFF);
186 }
187
188 phyVQBufStart += u32VQSize;
189 }
190
191 return TRUE;
192
193 }
194
HAL_TSP_Tee_Set_PvrBuf(MS_U8 u8PvrId,MS_PHY phyAddr0,MS_U32 u32Size0,MS_PHY phyAddr1,MS_U32 u32Size1)195 MS_BOOL HAL_TSP_Tee_Set_PvrBuf(MS_U8 u8PvrId, MS_PHY phyAddr0, MS_U32 u32Size0, MS_PHY phyAddr1, MS_U32 u32Size1)
196 {
197 MS_PHY phyEnd = phyAddr0 + u32Size0;
198 MS_PHY phyMiuAddr = 0;
199
200 if(u8PvrId == 0)
201 {
202 phyMiuAddr = phyAddr0 >> MIU_BUS;
203 TSP_TSP0_REG(REG_TSP0_PVR_HEAD1_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
204 TSP_TSP0_REG(REG_TSP0_PVR_HEAD1_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
205 phyMiuAddr = phyEnd >> MIU_BUS;
206 TSP_TSP0_REG(REG_TSP0_PVR_TAIL1_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
207 TSP_TSP0_REG(REG_TSP0_PVR_TAIL1_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
208 phyEnd = phyAddr1 + u32Size1;
209 phyMiuAddr = phyAddr1 >> MIU_BUS;
210 TSP_TSP0_REG(REG_TSP0_PVR_HEAD2_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
211 TSP_TSP0_REG(REG_TSP0_PVR_HEAD2_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
212 phyMiuAddr = phyEnd >> MIU_BUS;
213 TSP_TSP0_REG(REG_TSP0_PVR_TAIL2_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
214 TSP_TSP0_REG(REG_TSP0_PVR_TAIL2_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
215 }
216 else if(u8PvrId == 1)
217 {
218 phyMiuAddr = phyAddr0 >> MIU_BUS;
219 TSP_TSP0_REG(REG_TSP0_PVR1_HEAD1_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
220 TSP_TSP0_REG(REG_TSP0_PVR1_HEAD1_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
221 phyMiuAddr = phyEnd >> MIU_BUS;
222 TSP_TSP0_REG(REG_TSP0_PVR1_TAIL1_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
223 TSP_TSP0_REG(REG_TSP0_PVR1_TAIL1_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
224 phyEnd = phyAddr1 + u32Size1;
225 phyMiuAddr = phyAddr1 >> MIU_BUS;
226 TSP_TSP0_REG(REG_TSP0_PVR1_HEAD2_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
227 TSP_TSP0_REG(REG_TSP0_PVR1_HEAD2_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
228 phyMiuAddr = phyEnd >> MIU_BUS;
229 TSP_TSP0_REG(REG_TSP0_PVR1_TAIL2_L) = (MS_U16)(phyMiuAddr & 0xFFFF);
230 TSP_TSP0_REG(REG_TSP0_PVR1_TAIL2_H) = (MS_U16)((phyMiuAddr >> 16) & 0xFFFF);
231 }
232 else
233 {
234 return FALSE;
235 }
236
237 return TRUE;
238 }
239
HAL_TSP_Tee_Get_PVRWriteAddr(MS_U8 u8PvrId,MS_PHY * pphyAddr)240 MS_BOOL HAL_TSP_Tee_Get_PVRWriteAddr(MS_U8 u8PvrId, MS_PHY *pphyAddr)
241 {
242 MS_U16 u16addr = 0, u16addr1 = 0;
243
244 *pphyAddr = 0;
245
246 if(u8PvrId >= TSP_PVR_ENG_NUM)
247 return FALSE;
248
249 TSP_TSP1_REG(REG_TSP1_PVR_CFG) = TSP_TSP1_REG(REG_TSP1_PVR_CFG) & ~REG_TSP1_CH_BW_WP_LD;
250 if(u8PvrId == 0)
251 {
252 u16addr = TSP_TSP0_REG(REG_TSP0_PVR_MID1_L);
253 u16addr1 = TSP_TSP0_REG(REG_TSP0_PVR_MID1_H);
254 *pphyAddr = (((MS_U32)u16addr) & 0xFFFF) + ((((MS_U32)u16addr1) << 16) & 0xFFFF0000);
255 *pphyAddr <<= MIU_BUS;
256 }
257 else if(u8PvrId == 1)
258 {
259 u16addr = TSP_TSP0_REG(REG_TSP0_PVR1_MID1_L);
260 u16addr1 = TSP_TSP0_REG(REG_TSP0_PVR1_MID1_H);
261 *pphyAddr = (((MS_U32)u16addr) & 0xFFFF) + ((((MS_U32)u16addr1) << 16) & 0xFFFF0000);
262 *pphyAddr <<= MIU_BUS;
263 }
264 TSP_TSP1_REG(REG_TSP1_PVR_CFG) = TSP_TSP1_REG(REG_TSP1_PVR_CFG) | REG_TSP1_CH_BW_WP_LD;
265
266 return TRUE;
267 }
268
HAL_TSP_Tee_FilePath2Tsif_Mapping(MS_U8 u8FileEng)269 MS_U32 HAL_TSP_Tee_FilePath2Tsif_Mapping(MS_U8 u8FileEng)
270 {
271 return (((MS_U32)u8FileEng) & 0xFF);
272 }
273
HAL_TSP_Tee_Set_FileinBuf(MS_U8 u8EngId,MS_PHY phyAddr,MS_U32 u32Size)274 MS_BOOL HAL_TSP_Tee_Set_FileinBuf(MS_U8 u8EngId, MS_PHY phyAddr, MS_U32 u32Size)
275 {
276 switch(u8EngId)
277 {
278 case 0:
279 TSP_TSP0_REG(REG_TSP0_FILE_ADDR_L) = (MS_U16)(phyAddr & 0xFFFF);
280 TSP_TSP0_REG(REG_TSP0_FILE_ADDR_H) = (MS_U16)((phyAddr >> 16) & 0xFFFF);
281 TSP_TSP0_REG(REG_TSP0_FILE_SIZE_L) = (MS_U16)(u32Size & 0xFFFF);
282 TSP_TSP0_REG(REG_TSP0_FILE_SIZE_H) = (MS_U16)((u32Size >> 16) & 0xFFFF);
283 break;
284 case 1:
285 case 2:
286 return HAL_TSP_Tee_Set_MMFIBuf(u8EngId-1, phyAddr, u32Size);
287 default:
288 return FALSE;
289 }
290
291 return TRUE;
292 }
293
HAL_TSP_Tee_Set_MMFIBuf(MS_U8 u8Id,MS_PHY phyAddr,MS_U32 u32Size)294 MS_BOOL HAL_TSP_Tee_Set_MMFIBuf(MS_U8 u8Id, MS_PHY phyAddr, MS_U32 u32Size)
295 {
296 switch(u8Id)
297 {
298 case 0:
299 TSP_MMFI_REG(REG_MMFI_FILE_ADDR_L) = (MS_U16)(phyAddr & 0xFFFF);
300 TSP_MMFI_REG(REG_MMFI_FILE_ADDR_H) = (MS_U16)((phyAddr >> 16) & 0xFFFF);
301 TSP_MMFI_REG(REG_MMFI_FILE_SIZE_L) = (MS_U16)(u32Size & 0xFFFF);
302 TSP_MMFI_REG(REG_MMFI_FILE_SIZE_H) = (MS_U16)((u32Size >> 16) & 0xFFFF);
303 break;
304 case 1:
305 TSP_MMFI_REG(REG_MMFI1_FILE_ADDR_L) = (MS_U16)(phyAddr & 0xFFFF);
306 TSP_MMFI_REG(REG_MMFI1_FILE_ADDR_H) = (MS_U16)((phyAddr >> 16) & 0xFFFF);
307 TSP_MMFI_REG(REG_MMFI1_FILE_SIZE_L) = (MS_U16)(u32Size & 0xFFFF);
308 TSP_MMFI_REG(REG_MMFI1_FILE_SIZE_H) = (MS_U16)((u32Size >> 16) & 0xFFFF);
309 break;
310 default:
311 return FALSE;
312 }
313
314 return TRUE;
315 }
316