rgx_compat_bvnc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*************************************************************************/ /*!
  2. @File rgx_compat_bvnc.h
  3. @Title BVNC compatibility check utilities
  4. @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
  5. @Description Utility functions used for packing BNC and V.
  6. @License Dual MIT/GPLv2
  7. The contents of this file are subject to the MIT license as set out below.
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. Alternatively, the contents of this file may be used under the terms of
  17. the GNU General Public License Version 2 ("GPL") in which case the provisions
  18. of GPL are applicable instead of those above.
  19. If you wish to allow use of your version of this file only under the terms of
  20. GPL, and not to allow others to use your version of this file under the terms
  21. of the MIT license, indicate your decision by deleting the provisions above
  22. and replace them with the notice and other provisions required by GPL as set
  23. out in the file called "GPL-COPYING" included in this distribution. If you do
  24. not delete the provisions above, a recipient may use your version of this file
  25. under the terms of either the MIT license or GPL.
  26. This License is also included in this distribution in the file called
  27. "MIT-COPYING".
  28. EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
  29. PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  30. BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  31. PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
  32. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  33. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  34. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35. */ /**************************************************************************/
  36. #if !defined(RGX_COMPAT_BVNC_H)
  37. #define RGX_COMPAT_BVNC_H
  38. #include "img_types.h"
  39. #if defined(RGX_FIRMWARE) /* Services firmware */
  40. # include "rgxfw_utils.h"
  41. # define PVR_COMPAT_ASSERT RGXFW_ASSERT
  42. #elif !defined(RGX_BUILD_BINARY) /* Services host driver code */
  43. # include "pvr_debug.h"
  44. # define PVR_COMPAT_ASSERT PVR_ASSERT
  45. #else /* FW user-mode tools */
  46. # include <assert.h>
  47. # define PVR_COMPAT_ASSERT assert
  48. #endif
  49. /* 64bit endian conversion macros */
  50. #if defined(__BIG_ENDIAN__)
  51. #define RGX_INT64_TO_BE(N) (N)
  52. #define RGX_INT64_FROM_BE(N) (N)
  53. #define RGX_INT32_TO_BE(N) (N)
  54. #define RGX_INT32_FROM_BE(N) (N)
  55. #else
  56. #define RGX_INT64_TO_BE(N) \
  57. ((((N) >> 56) & 0xff) \
  58. | (((N) >> 40) & 0xff00) \
  59. | (((N) >> 24) & 0xff0000) \
  60. | (((N) >> 8) & 0xff000000U) \
  61. | ((N) << 56) \
  62. | (((N) & 0xff00) << 40) \
  63. | (((N) & 0xff0000) << 24) \
  64. | (((N) & 0xff000000U) << 8))
  65. #define RGX_INT64_FROM_BE(N) RGX_INT64_TO_BE(N)
  66. #define RGX_INT32_TO_BE(N) \
  67. ((((N) >> 24) & 0xff) \
  68. | (((N) >> 8) & 0xff00) \
  69. | ((N) << 24) \
  70. | ((((N) & 0xff00) << 8)))
  71. #define RGX_INT32_FROM_BE(N) RGX_INT32_TO_BE(N)
  72. #endif
  73. /******************************************************************************
  74. * RGX Version packed into 64-bit (BVNC) to be used by Compatibility Check
  75. *****************************************************************************/
  76. #define RGX_BVNC_PACK_SHIFT_B 48
  77. #define RGX_BVNC_PACK_SHIFT_V 32
  78. #define RGX_BVNC_PACK_SHIFT_N 16
  79. #define RGX_BVNC_PACK_SHIFT_C 0
  80. #define RGX_BVNC_PACK_MASK_B (IMG_UINT64_C(0xFFFF000000000000))
  81. #define RGX_BVNC_PACK_MASK_V (IMG_UINT64_C(0x0000FFFF00000000))
  82. #define RGX_BVNC_PACK_MASK_N (IMG_UINT64_C(0x00000000FFFF0000))
  83. #define RGX_BVNC_PACK_MASK_C (IMG_UINT64_C(0x000000000000FFFF))
  84. #define RGX_BVNC_PACKED_EXTR_B(BVNC) ((IMG_UINT32)(((BVNC) & RGX_BVNC_PACK_MASK_B) >> RGX_BVNC_PACK_SHIFT_B))
  85. #define RGX_BVNC_PACKED_EXTR_V(BVNC) ((IMG_UINT32)(((BVNC) & RGX_BVNC_PACK_MASK_V) >> RGX_BVNC_PACK_SHIFT_V))
  86. #define RGX_BVNC_PACKED_EXTR_N(BVNC) ((IMG_UINT32)(((BVNC) & RGX_BVNC_PACK_MASK_N) >> RGX_BVNC_PACK_SHIFT_N))
  87. #define RGX_BVNC_PACKED_EXTR_C(BVNC) ((IMG_UINT32)(((BVNC) & RGX_BVNC_PACK_MASK_C) >> RGX_BVNC_PACK_SHIFT_C))
  88. #define RGX_BVNC_EQUAL(L,R,all,version,bvnc) do { \
  89. (bvnc) = IMG_FALSE; \
  90. (version) = ((L).ui32LayoutVersion == (R).ui32LayoutVersion); \
  91. if (version) \
  92. { \
  93. (bvnc) = ((L).ui64BVNC == (R).ui64BVNC); \
  94. } \
  95. (all) = (version) && (bvnc); \
  96. } while (0)
  97. /**************************************************************************//**
  98. * Utility function for packing BVNC
  99. *****************************************************************************/
  100. static inline IMG_UINT64 rgx_bvnc_pack(IMG_UINT32 ui32B, IMG_UINT32 ui32V, IMG_UINT32 ui32N, IMG_UINT32 ui32C)
  101. {
  102. /*
  103. * Test for input B, V, N and C exceeding max bit width.
  104. */
  105. PVR_COMPAT_ASSERT((ui32B & (~(RGX_BVNC_PACK_MASK_B >> RGX_BVNC_PACK_SHIFT_B))) == 0U);
  106. PVR_COMPAT_ASSERT((ui32V & (~(RGX_BVNC_PACK_MASK_V >> RGX_BVNC_PACK_SHIFT_V))) == 0U);
  107. PVR_COMPAT_ASSERT((ui32N & (~(RGX_BVNC_PACK_MASK_N >> RGX_BVNC_PACK_SHIFT_N))) == 0U);
  108. PVR_COMPAT_ASSERT((ui32C & (~(RGX_BVNC_PACK_MASK_C >> RGX_BVNC_PACK_SHIFT_C))) == 0U);
  109. return (((IMG_UINT64)ui32B << RGX_BVNC_PACK_SHIFT_B) |
  110. ((IMG_UINT64)ui32V << RGX_BVNC_PACK_SHIFT_V) |
  111. ((IMG_UINT64)ui32N << RGX_BVNC_PACK_SHIFT_N) |
  112. ((IMG_UINT64)ui32C << RGX_BVNC_PACK_SHIFT_C));
  113. }
  114. #endif /* RGX_COMPAT_BVNC_H */
  115. /******************************************************************************
  116. End of file (rgx_compat_bvnc.h)
  117. ******************************************************************************/