dwl_linux_sc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*------------------------------------------------------------------------------
  2. -- Copyright (c) 2015-2017, VeriSilicon Inc. All rights reserved --
  3. -- Copyright (c) 2011-2014, Google Inc. All rights reserved. --
  4. -- Copyright (c) 2007-2010, Hantro OY. All rights reserved. --
  5. -- --
  6. -- This software is confidential and proprietary and may be used only as --
  7. -- expressly authorized by VeriSilicon in a written licensing agreement. --
  8. -- --
  9. -- This entire notice must be reproduced on all copies --
  10. -- and may not be removed. --
  11. -- --
  12. --------------------------------------------------------------------------------
  13. -- Redistribution and use in source and binary forms, with or without --
  14. -- modification, are permitted provided that the following conditions are met:--
  15. -- * Redistributions of source code must retain the above copyright notice, --
  16. -- this list of conditions and the following disclaimer. --
  17. -- * Redistributions in binary form must reproduce the above copyright --
  18. -- notice, this list of conditions and the following disclaimer in the --
  19. -- documentation and/or other materials provided with the distribution. --
  20. -- * Neither the names of Google nor the names of its contributors may be --
  21. -- used to endorse or promote products derived from this software --
  22. -- without specific prior written permission. --
  23. --------------------------------------------------------------------------------
  24. -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"--
  25. -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE --
  26. -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE --
  27. -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE --
  28. -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR --
  29. -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF --
  30. -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS --
  31. -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN --
  32. -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) --
  33. -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE --
  34. -- POSSIBILITY OF SUCH DAMAGE. --
  35. --------------------------------------------------------------------------------
  36. ------------------------------------------------------------------------------*/
  37. #include "basetype.h"
  38. #include "dwl_linux.h"
  39. #include "dwl.h"
  40. #include <linux/vmalloc.h>
  41. #include <linux/mm.h>
  42. #include<linux/slab.h>
  43. //#include <assert.h>
  44. //#include <errno.h>
  45. //#include <signal.h>
  46. //#include <stdio.h>
  47. //#include <stdlib.h>
  48. //#include <string.h>
  49. /*------------------------------------------------------------------------------
  50. Function name : DWLInit
  51. Description : Initialize a DWL instance
  52. Return type : const void * - pointer to a DWL instance
  53. Argument : void * param - not in use, application passes NULL
  54. ------------------------------------------------------------------------------*/
  55. const void *DWLInit(DWLInitParam_t * param)
  56. {
  57. hX170dwl_t *dec_dwl;
  58. dec_dwl = (hX170dwl_t *)kcalloc(1, sizeof(hX170dwl_t), GFP_KERNEL);
  59. if (!dec_dwl)
  60. {
  61. printk("error!!!\n");
  62. goto err;
  63. }
  64. if(dec_dwl == NULL)
  65. {
  66. printk("failed to alloc hX170dwl_t struct\n");
  67. return NULL;
  68. }
  69. dec_dwl->clientType = param->clientType;
  70. switch (dec_dwl->clientType)
  71. {
  72. case DWL_CLIENT_TYPE_H264_DEC:
  73. case DWL_CLIENT_TYPE_MPEG4_DEC:
  74. case DWL_CLIENT_TYPE_JPEG_DEC:
  75. case DWL_CLIENT_TYPE_VC1_DEC:
  76. case DWL_CLIENT_TYPE_MPEG2_DEC:
  77. case DWL_CLIENT_TYPE_VP6_DEC:
  78. case DWL_CLIENT_TYPE_VP8_DEC:
  79. case DWL_CLIENT_TYPE_RV_DEC:
  80. case DWL_CLIENT_TYPE_AVS_DEC:
  81. case DWL_CLIENT_TYPE_PP:
  82. {
  83. break;
  84. }
  85. default:
  86. {
  87. printk("Unknown client type no. %d\n", dec_dwl->clientType);
  88. goto err;
  89. }
  90. }
  91. dec_dwl->regSize = 404;
  92. dec_dwl->numCores = 1;
  93. return dec_dwl;
  94. err:
  95. DWLRelease(dec_dwl);
  96. return NULL;
  97. }
  98. /*------------------------------------------------------------------------------
  99. Function name : DWLRelease
  100. Description : Release a DWl instance
  101. Return type : i32 - 0 for success or a negative error code
  102. Argument : const void * instance - instance to be released
  103. ------------------------------------------------------------------------------*/
  104. i32 DWLRelease(const void *instance)
  105. {
  106. hX170dwl_t *dec_dwl = (hX170dwl_t *) instance;
  107. kfree(dec_dwl);
  108. // printk("DWLRelease SUCCESS\n");
  109. return (DWL_OK);
  110. }
  111. /* HW locking */
  112. /*------------------------------------------------------------------------------
  113. Function name : DWLReserveHwPipe
  114. Description :
  115. Return type : i32
  116. Argument : const void *instance
  117. Argument : i32 *coreID - ID of the reserved HW core
  118. ------------------------------------------------------------------------------*/
  119. i32 DWLReserveHwPipe(const void *instance/*, i32 *coreID*/)
  120. {
  121. hX170dwl_t *dec_dwl = (hX170dwl_t *) instance;
  122. // assert(dec_dwl != NULL);
  123. // assert(dec_dwl->clientType != DWL_CLIENT_TYPE_PP);
  124. DWL_DEBUG("Start\n");
  125. dec_dwl->bPPReserved = 1;
  126. return DWL_OK;
  127. }
  128. /*------------------------------------------------------------------------------
  129. Function name : DWLReserveHw
  130. Description :
  131. Return type : i32
  132. Argument : const void *instance
  133. Argument : i32 *coreID - ID of the reserved HW core
  134. ------------------------------------------------------------------------------*/
  135. i32 DWLReserveHw(const void *instance/*, i32 *coreID*/)
  136. {
  137. hX170dwl_t *dec_dwl = (hX170dwl_t *) instance;
  138. int isPP;
  139. // assert(dec_dwl != NULL);
  140. isPP = dec_dwl->clientType == DWL_CLIENT_TYPE_PP ? 1 : 0;
  141. DWL_DEBUG(" %s\n", isPP ? "PP" : "DEC");
  142. return DWL_OK;
  143. }
  144. /*------------------------------------------------------------------------------
  145. Function name : DWLReleaseHw
  146. Description :
  147. Return type : void
  148. Argument : const void *instance
  149. ------------------------------------------------------------------------------*/
  150. void DWLReleaseHw(const void *instance/*, i32 coreID*/)
  151. {
  152. hX170dwl_t *dec_dwl = (hX170dwl_t *) instance;
  153. int isPP;
  154. i32 coreID = 0;
  155. // assert((u32)coreID < dec_dwl->numCores);
  156. // assert(dec_dwl != NULL);
  157. isPP = dec_dwl->clientType == DWL_CLIENT_TYPE_PP ? 1 : 0;
  158. if ((u32) coreID >= dec_dwl->numCores)
  159. return;
  160. DWL_DEBUG(" %s core %d\n", isPP ? "PP" : "DEC", coreID);
  161. if (isPP)
  162. {
  163. // assert(coreID == 0);
  164. }
  165. else
  166. {
  167. if (dec_dwl->bPPReserved)
  168. {
  169. /* decoder has reserved PP also => release it */
  170. DWL_DEBUG("DEC released PP core %d\n", coreID);
  171. dec_dwl->bPPReserved = 0;
  172. // assert(coreID == 0);
  173. }
  174. }
  175. }