xref: /utopia/UTPA2-700.0.x/modules/acp/api/acp/apiACP_v2.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 #include "MsTypes.h"
2 #ifndef MSOS_TYPE_LINUX_KERNEL
3 #include <stdio.h>
4 #include <string.h>
5 #endif
6 #include "MsCommon.h"
7 #include "utopia.h"
8 #include "utopia_dapi.h"
9 #include "apiACP.h"
10 #include "apiACP_private.h"
11 #include "apiACP_v2.h"
12 
13 //-------------------------------------------------------------------------------------------------
14 //  Local Compiler Options
15 //-------------------------------------------------------------------------------------------------
16 // for semaphore POOL
17 
18 
19 //Below is dbg msg for some important dbg function, like:setmux, set gop dst, atexit,etc...
20 
21 
22 //-------------------------------------------------------------------------------------------------
23 //  Local Defines
24 //-------------------------------------------------------------------------------------------------
25 
26 // this func will be call to init by utopia20 framework
ACPRegisterToUtopia(void)27 void ACPRegisterToUtopia(void)
28 {
29     MS_U32 u32ResourceStatusCheck[E_ACP_POOL_ID_MAX] = {UTOPIA_STATUS_FAIL};
30     // 1. deal with module
31     void* pUtopiaModule = NULL;
32 	UtopiaModuleCreate(MODULE_ACP, 8, &pUtopiaModule);
33     UtopiaModuleRegister(pUtopiaModule);
34     // register func for module, after register here, then ap call UtopiaOpen/UtopiaIoctl/UtopiaClose can call to these registered standard func
35     UtopiaModuleSetupFunctionPtr(pUtopiaModule, (FUtopiaOpen)ACPOpen, (FUtopiaClose)ACPClose, (FUtopiaIOctl)ACPIoctl);
36 
37     // 2. deal with resource
38     void* psResource = NULL;
39     // start func to add res, call once will create 2 access in resource. Also can declare BDMA_POOL_ID_BDMA1 for another channel depend on driver owner.
40 	UtopiaModuleAddResourceStart(pUtopiaModule, E_ACP_POOL_ID_INTERNAL_VARIABLE);
41     // resource can alloc private for internal use, ex, BDMA_RESOURCE_PRIVATE
42     u32ResourceStatusCheck[E_ACP_POOL_ID_INTERNAL_VARIABLE] = UtopiaResourceCreate("acp", sizeof(ACP_RESOURCE_PRIVATE), &psResource);
43     // func to reg res
44     UtopiaResourceRegister(pUtopiaModule, psResource, E_ACP_POOL_ID_INTERNAL_VARIABLE);
45 
46 	UtopiaModuleAddResourceEnd(pUtopiaModule, E_ACP_POOL_ID_INTERNAL_VARIABLE);
47 
48     //4. init resource private members here   (aka, global variable)
49     ACP_RESOURCE_PRIVATE* pACPResourcePrivate = NULL;
50     UtopiaResourceGetPrivate(psResource,(void**)(&pACPResourcePrivate));
51 
52     //pXCResourcePrivate->bResourceRegistered will automatically cleared by UtopiaResourceRegister
53     if (u32ResourceStatusCheck[E_ACP_POOL_ID_INTERNAL_VARIABLE] == UTOPIA_STATUS_SHM_EXIST)
54     {
55         // do nothing, since it is already inited
56     }
57     else
58     {
59         // Init flow control related variables here. Other global variable should be
60         // inited in each of its init function relatively.
61         pACPResourcePrivate->bResourceRegistered = TRUE;
62     }
63 }
64 
ACPOpen(void ** ppInstance,const void * const pAttribute)65 MS_U32 ACPOpen(void** ppInstance, const void* const pAttribute)
66 {
67     ACP_INSTANT_PRIVATE *pACPPri = NULL;
68 
69     //UTOPIA_TRACE(MS_UTOPIA_DB_LEVEL_TRACE,printf("enter %s %d\n",__FUNCTION__,__LINE__));
70     // instance is allocated here, also can allocate private for internal use, ex, BDMA_INSTANT_PRIVATE
71     UtopiaInstanceCreate(sizeof(ACP_INSTANT_PRIVATE), ppInstance);
72     // setup func in private and assign the calling func in func ptr in instance private
73     UtopiaInstanceGetPrivate(*ppInstance, (void**)&pACPPri);
74 
75     pACPPri->fpACPSetProtection = MApi_ACP_SetProtection_U2;
76     pACPPri->fpACPSetMVBitControl = MApi_ACP_SetMV_BitControl_U2;
77     pACPPri->fpACPDCSProtection = MApi_DCS_SetProtection_U2;
78     pACPPri->fpACPDCSSetActivationKey = MApi_DCS_SetActivationKey_U2;
79 	return UTOPIA_STATUS_SUCCESS;
80 }
81 
ACPIoctl(void * pInstance,MS_U32 u32Cmd,void * pArgs)82 MS_U32 ACPIoctl(void* pInstance, MS_U32 u32Cmd, void* pArgs)
83 {
84     if(pInstance == NULL)
85     {
86         printf("[%s] pInstance is NULL\n",__FUNCTION__);
87         return UTOPIA_STATUS_FAIL;
88     }
89 	void* pModule = NULL;
90 	UtopiaInstanceGetModule(pInstance, &pModule);
91     ACP_INSTANT_PRIVATE* psACPInstPri = NULL;
92 	UtopiaInstanceGetPrivate(pInstance, (void**)&psACPInstPri);
93     MS_U32 u32Return = UTOPIA_STATUS_FAIL;
94 
95     //printf("[%s] cmd:%lx\n",__FUNCTION__,u32Cmd);
96     switch(u32Cmd)
97     {
98         case E_ACP_SET_PROTECTION:
99         {
100             pstACP_SET_PROTECTION ptr = (pstACP_SET_PROTECTION)pArgs;
101             ptr->eReturnValue = psACPInstPri->fpACPSetProtection(ptr->bEnable,ptr->bIsYPbPr,ptr->u8Type);
102             u32Return = UTOPIA_STATUS_SUCCESS;
103             break;
104         }
105         case E_ACP_SET_MV_BITCONTROL:
106         {
107             pstACP_SET_MV_BITCONTROL ptr = (pstACP_SET_MV_BITCONTROL)pArgs;
108             ptr->eReturnValue = psACPInstPri->fpACPSetMVBitControl(ptr->bEnable,ptr->MV_BitControl_Data);
109             u32Return = UTOPIA_STATUS_SUCCESS;
110             break;
111         }
112         case E_ACP_DCS_PROTECTION:
113         {
114             pstACP_DCS_PROTECTION ptr = (pstACP_DCS_PROTECTION)pArgs;
115             ptr->eReturnValue = psACPInstPri->fpACPDCSProtection(ptr->bEnable,ptr->u8Type);
116             u32Return = UTOPIA_STATUS_SUCCESS;
117             break;
118         }
119         case E_ACP_DCS_SETACTIVATIONKEY:
120         {
121             pstACP_DCS_SETACTIVATIONKEY ptr = (pstACP_DCS_SETACTIVATIONKEY)pArgs;
122             ptr->eReturnValue = psACPInstPri->fpACPDCSSetActivationKey(ptr->pu8ActivationKeyTbl,ptr->u8ActivationKeyTblSize);
123             u32Return = UTOPIA_STATUS_SUCCESS;
124             break;
125         }
126         default:
127             printf("[%s] out of ACP cmd:%d\n",__FUNCTION__,u32Cmd);
128             break;
129     }
130 
131 	return u32Return;
132 }
133 
ACPClose(void * pInstance)134 MS_U32 ACPClose(void* pInstance)
135 {
136 	UtopiaInstanceDelete(pInstance);
137 
138 	return TRUE;
139 }
140 
141 
142