summaryrefslogtreecommitdiff
path: root/drivers/mxc/vpu-malone/Malone_Firmware/DecKLib/Control/DecKernelLibHWControl.c
blob: 7861d545e5774718be889d56124f59f2bdbbc9d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/***************************************************
  Copyright (c) 2015 Amphion Semiconductor Ltd
                All rights reserved.
 ***************************************************
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 ****************************************************

  Author    : Media IP FW team ( Belfast and Shanghai )
  File name : DecLibHWControl.c
  Notes     : Processes commands from decoder lib scheduler
              Establishes context for and makes calls to
              the base decoders
              This file provides the hardware facing aspect to
              the interface. It is part of a group with
              DecLibStreamControl.c which provides the
              HW funtionality

 ******************************************************/

/////////////////////////////////////////////////////////////////////////////////
//  Header Files
/////////////////////////////////////////////////////////////////////////////////

#include "basetype.h"
#include "mediaip_fw_types.h"
#include "pal.h"

#include "mvd_types.h"
#include "mvd_reg_map.h"
#include "mvd_sif_control.h"

#include "DecKernelLibPrivate.h"
#include "DecKernelLibHWControl.h"

/////////////////////////////////////////////////////////////////////////////////
//  Extern Function Prototypes
/////////////////////////////////////////////////////////////////////////////////

extern MEDIAIP_IRQ_RETCODE mvd_kernel_hw_primary_isr ( u_int32 irq_val );
extern MEDIAIP_IRQ_RETCODE mvd_kernel_hw_secondary_isr ( u_int32 irq_val );

/////////////////////////////////////////////////////////////////////////////////
//  Private Function Prototypes
/////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////
//  Global Variables
/////////////////////////////////////////////////////////////////////////////////;

extern DEC_KERNEL_LIB              gDecKernelLib;
       MALONE_KERNEL_HW_SESSION    gMvdKernelHw[(DECODERLIB_MAX_MALONES + 1)];
       pMALONE_KERNEL_HW_SESSION   pgMVDKernelHw;

u_int32                    gMaloneList[(DECODERLIB_MAX_MALONES + 1)] = { MALONE_HW_1,
#if DECODERLIB_MAX_MALONES > 1
                                                                         MALONE_HW_2,
#endif
                                                                         MALONE_SW };

static u_int32      uSWMaloneRegSpace[2048];   /* Until we are sure we have eliminated register access */
                                               /* for functions using the 'SW Malone', point them here */

extern u_int32      uDecLibIrqPin[DECODERLIB_MAX_MALONES][0x2];

/////////////////////////////////////////////////////////////////////////////////
//  Code
/////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////
//  FUNCTION:    mvd_kernel_hw_control_init                                         //
//                                                                                //
//  DESCRIPTION: Perform all HW initialisation and shared structure setup         //
//                                                                                //
//  INPUTS:      uMaloneID - The ID of the Malone for which the info is to        //
//                           be restored                                          //
//               pCtxArea  - Pointer to area of memory from which data is to be   //
//                           read                                                 //
//                                                                                //
//  OUTPUTS:     None.                                                            //
//                                                                                //
//  RETURNS:     None.                                                            //
//                                                                                //
//  NOTES:       None.                                                            //
//                                                                                //
//  CONTEXT:     This function must be called from non-interrupt context          //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////

void mvd_kernel_hw_control_init ( DECODERLIB_KERNEL_CFG * pCfg )
{
  /* Init the handles                             */
  /* This sets up the reg pointers so do it first */
  mvd_kernel_hw_init_handles ( pCfg,
                               TRUE );
  
  /* Default global pointers to a 1st Malone focus  */
  mvd_kernel_hw_set_focus ( MALONE_HW_1, &pgMVDKernelHw  );

}


////////////////////////////////////////////////////////////////////////////////////
//  FUNCTION:    mvd_kernel_hw_set_malone_instance                                  //
//                                                                                //
//  DESCRIPTION: Look for the most appropriate Malone instance to service         //
//               the command for a specified stream                               //
//                                                                                //
//  INPUTS:      uStrId   - The Stream ID                                         //
//               bSWCmd   - is the command to be carried out for this stream      //
//                          capable of being handled without using the HW engine? //
//               uHWIndex - HW Index suggested by scheduler                       //
//               bUseSch  - Set to guarantee scheduler suggested unit is used     //
//                                                                                //
//  OUTPUTS:     None.                                                            //
//                                                                                //
//  RETURNS:     The most suitable Malone ID to be used                           //
//                                                                                //
//  NOTES:       This function must return a value.                               //
//                                                                                //
//  CONTEXT:     This function must be called from non-interrupt context          //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////

u_int32 mvd_kernel_hw_set_malone_instance ( u_int32 uStrId,
                                            bool    bSWCmd,
                                            u_int32 uHWIndex,
                                            bool    bUseSch
                                          )
{
  u_int32 uIdx      = 0;

  if ( bUseSch )
  {
    return uHWIndex;
  }

  for ( uIdx = 0; uIdx < gDecKernelLib.uNumMalones; uIdx++ )
  {
    /* Even if there is no command active, this is a valid check as */
    /* it avoids need for a context change if it matches            */
    if ( gMvdKernelHw[uIdx].uStrID == uStrId )
    {
      return uIdx;
    }
  }

  if ( bSWCmd ) return MALONE_SW;

  /* Look for free Malone - this function should not be called */
  /* unless this is a SW command or there is a free Malone     */

  for ( uIdx = 0; uIdx < gDecKernelLib.uNumMalones; uIdx++ )
  {
    /* Even if there is no command active, this is a valid check as */
    /* it avoids need for a context change if it matches            */
    if ( gMvdKernelHw[uIdx].eState == MALONE_INACTIVE )
    {
      break;
    }
  }

  /* Do not assign this stream and do NOT make it active yet */
  /* Only make this malone active when the command is issued */
  /* This is necessary so we we can trigger context switches */

  /* We should set the global pointer though so calls to sif */
  /* etc can get correct functions!!                         */

  mvd_kernel_hw_set_focus ( uIdx, &pgMVDKernelHw );

  return uIdx;

}

////////////////////////////////////////////////////////////////////////////////////
//  FUNCTION:    mvd_kernel_hw_set_focus                                            //
//                                                                                //
//  DESCRIPTION: Changes focus to the selected Malone HW unit                     //
//                                                                                //
//  INPUTS:      uMaloneID - The ID of the Malone                                 //
//                                                                                //
//  OUTPUTS:     ppMVDHw   - Pointer to a HW session structure for the specified  //
//                           Malone                                               //
//                                                                                //
//  RETURNS:     None.                                                            //
//                                                                                //
//  NOTES:       Only makes sense in multi-malone configs                         //
//                                                                                //
//  CONTEXT:     This function may be called from any context                     //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////

void mvd_kernel_hw_set_focus ( u_int32 uMaloneID, pMALONE_KERNEL_HW_SESSION * ppMVDHw )
{
  *ppMVDHw = ( MALONE_KERNEL_HW_SESSION * )&gMvdKernelHw[uMaloneID];
}



////////////////////////////////////////////////////////////////////////////////////
//  FUNCTION:    mvd_kernel_hw_init_handles                                         //
//                                                                                //
//  DESCRIPTION: Initialise the HW session handles                                //
//                                                                                //
//  INPUTS:      pCfg      - A pointer to the DecLib Config structure             //
//               bSoftInit - If set, the FW pointers get established - leave      //
//                           FALSE when restarting from a snapshot                //
//                                                                                //
//  OUTPUTS:     None.                                                            //
//                                                                                //
//  RETURNS:     None.                                                            //
//                                                                                //
//  NOTES:       None.                                                            //
//                                                                                //
//  CONTEXT:     This function must be called from non-interrupt context          //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////

void mvd_kernel_hw_init_handles ( DECODERLIB_KERNEL_CFG * pCfg,
                                  bool                    bSoftInit
                                )
{
  u_int32            uIdx;
  pMALONE_KERNEL_HW_SESSION pMVDHw;
  MvdHwRegMap       *pMvdReg;

  for ( uIdx = 0; uIdx < (gDecKernelLib.uNumMalones + 1); uIdx++ )
  {
    /* If we have set up all the HW handles then move to the SW */
    /* handle and set it up                                     */
    if ( uIdx == gDecKernelLib.uNumMalones ) uIdx = DECODERLIB_MAX_MALONES;
    
    pMVDHw                 = &gMvdKernelHw[uIdx];
    
    if ( bSoftInit )
    {
      pMVDHw->eState       = MALONE_INACTIVE;
      pMVDHw->uStrID       = 0;
      pMVDHw->uForceFIQ    = 0;
      pMVDHw->uForceDFEFIQ = 0;

      /* Malone ID that the instance uses, normally fixed... */
      pMVDHw->uMaloneID    = gMaloneList[uIdx];
    }

    if ( pMVDHw->uMaloneID == DECODERLIB_MAX_MALONES )
    {
      pMvdReg = ( MvdHwRegMap * )uSWMaloneRegSpace;
    }
    else if ( pMVDHw->uMaloneID == MALONE_HW_2 )
    {
      pMvdReg = ( MvdHwRegMap * ) ( pCfg->uMaloneBaseAddr[0x1] + pCfg->uMaloneHifOffset[0x1] );
    }
    else
    {
      pMvdReg = ( MvdHwRegMap * ) ( pCfg->uMaloneBaseAddr[0x0] + pCfg->uMaloneHifOffset[0x0] );
    }

    if ( pMVDHw->uMaloneID == MALONE_SW )
    {
      pMVDHw->msd_regp      = ( MvdHwRegMap     * )pMvdReg;
      pMVDHw->hif_regp      = ( MvdHwRegHifMap  * )pMvdReg;
      pMVDHw->sif_regp      = ( MvdHwRegSifMap  * )pMvdReg;
      pMVDHw->ctx_regp      = ( MvdHwRegCtxMap  * )pMvdReg;
      pMVDHw->rsb_regp      = ( MvdHwReg        * )pMvdReg;
      pMVDHw->rpr_regp      = ( MvdHwRegRprMap  * )pMvdReg;
      pMVDHw->spp_regp      = ( MvdHwRegSppMap  * )pMvdReg;
      pMVDHw->avc_regp      = ( MvdHwRegH264Map * )pMvdReg;
      pMVDHw->mp2d_regp     = ( MvdHwRegMp2dMap * )pMvdReg;
      pMVDHw->avsd_regp     = ( MvdHwRegAvsdMap * )pMvdReg;
      pMVDHw->aspd_regp     = ( MvdHwRegAspdMap * )pMvdReg;
      pMVDHw->vc1d_regp     = ( MvdHwRegVc1dMap * )pMvdReg;
      pMVDHw->jpgd_regp     = ( MvdHwRegAspdMap * )pMvdReg;
      pMVDHw->rvid_regp     = ( MvdHwRegRvidMap * )pMvdReg;
      pMVDHw->hevc_regp     = ( MvdHwRegHevcMap * )pMvdReg;
      pMVDHw->on2d_regp     = ( MvdHwRegOn2dMap * )pMvdReg;
      pMVDHw->cq_regp       = ( MvdHwRegCqMap   * )pMvdReg;
      pMVDHw->rc4_regp      = ( MvdHwRegRC4Map  * )pMvdReg;
      pMVDHw->dfe_regp      = ( MvdHwRegDfeMap  * )pMvdReg;
      pMVDHw->dbe_regp[0x0] = ( MvdHwRegDbeMap  * )pMvdReg;
      pMVDHw->dbe_regp[0x1] = ( MvdHwRegDbeMap  * )pMvdReg;

    }
    else
    {
      pMVDHw->msd_regp       = pMvdReg;
      pMVDHw->hif_regp       = &( pMvdReg->HifMap.hif_map );
      pMVDHw->sif_regp       = &( pMvdReg->SifMap.sif_map );
      pMVDHw->ctx_regp       = &( pMvdReg->CtxMap.ctx_map );
      pMVDHw->rpr_regp       = &( pMvdReg->RprMap.rpr_map );
      pMVDHw->spp_regp       = &( pMvdReg->SppMap.spp_map );
      pMVDHw->avc_regp       = &( pMvdReg->DecMap.h264_map );
      pMVDHw->mp2d_regp      = &( pMvdReg->DecMap.mp2d_map );
      pMVDHw->aspd_regp      = &( pMvdReg->DecMap.aspd_map );
      pMVDHw->avsd_regp      = &( pMvdReg->DecMap.avsd_map );
      pMVDHw->vc1d_regp      = &( pMvdReg->DecMap.vc1d_map );
      pMVDHw->jpgd_regp      = &( pMvdReg->DecMap.aspd_map );
      pMVDHw->on2d_regp      = &( pMvdReg->DecMap.on2d_map );
      pMVDHw->rvid_regp      = &( pMvdReg->DecMap.rvid_map );
      pMVDHw->hevc_regp      = &( pMvdReg->DecMap.hevc_map );
      pMVDHw->bbd_regp       = &( pMvdReg->BbdMap.bbd_map );
      pMVDHw->cq_regp        = &( pMvdReg->CqMap.cq_map );
      pMVDHw->rc4_regp       = &( pMvdReg->RC4Map.RC4_map );
      pMVDHw->dfe_regp       = &( pMvdReg->DcpMap.dfe_map );
      pMVDHw->dbe_regp[0x0]  = &( pMvdReg->DcpMap.dbe_map[0x0] );
      pMVDHw->dbe_regp[0x1]  = &( pMvdReg->DcpMap.dbe_map[0x1] );

      if ( pMVDHw->uMaloneID == MALONE_HW_2 )
      {
        pMVDHw->rsb_regp = ( MvdHwReg * ) pCfg->uMaloneBaseAddr[0x1]  ;
      }
      else
      {
        pMVDHw->rsb_regp = ( MvdHwReg * ) pCfg->uMaloneBaseAddr[0x0] ;
      }
    }
  }
}

/* End of File */