vcmdswhwregisters.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2014 - 2021 VERISILICON
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (C) 2014 - 2021 VERISILICON
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program; if not, write to the Free Software Foundation,
  43. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  44. *
  45. *****************************************************************************
  46. *
  47. * Note: This software is released under dual MIT and GPL licenses. A
  48. * recipient may use this file under the terms of either the MIT license or
  49. * GPL License. If you wish to use only one license not the other, you can
  50. * indicate your decision by deleting one of the above license notices in your
  51. * version of this file.
  52. *
  53. *****************************************************************************/
  54. /*------------------------------------------------------------------------------
  55. Table of contents
  56. 1. Include headers
  57. 2. External compiler flags
  58. 3. Module defines
  59. ------------------------------------------------------------------------------*/
  60. #ifndef VCMD_SWHWREGISTERS_H
  61. #define VCMD_SWHWREGISTERS_H
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. /*------------------------------------------------------------------------------
  66. 1. Include headers
  67. ------------------------------------------------------------------------------*/
  68. #ifdef __FREERTOS__
  69. #include "base_type.h"
  70. #include "io_tools.h"
  71. #elif defined(__linux__)
  72. #include <linux/ioctl.h>
  73. #include <linux/kernel.h>
  74. #include <linux/module.h>
  75. #endif
  76. #ifdef __FREERTOS__
  77. //ptr_t has been defined in base_type.h //Now the FreeRTOS mem need to support 64bit env
  78. #elif defined(__linux__)
  79. typedef int i32;
  80. typedef size_t ptr_t;
  81. #endif
  82. #undef PDEBUG /* undef it, just in case */
  83. #ifdef REGISTER_DEBUG
  84. # ifdef __KERNEL__
  85. /* This one if debugging is on, and kernel space */
  86. # define PDEBUG(fmt, args...) printk( KERN_INFO "memalloc: " fmt, ## args)
  87. # else
  88. /* This one for user space */
  89. # define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
  90. # endif
  91. #else
  92. # define PDEBUG(fmt, args...) /* not debugging: nothing */
  93. #endif
  94. /*------------------------------------------------------------------------------
  95. 2. External compiler flags
  96. --------------------------------------------------------------------------------
  97. --------------------------------------------------------------------------------
  98. 3. Module defines
  99. ------------------------------------------------------------------------------*/
  100. #ifdef HANTROVCMD_ENABLE_IP_SUPPORT
  101. #define VCMD_REGISTER_INDEX_SW_INIT_CMD0 32
  102. #define ASIC_VCMD_SWREG_AMOUNT 64
  103. #else
  104. #define ASIC_VCMD_SWREG_AMOUNT 27
  105. #endif
  106. #define VCMD_REGISTER_CONTROL_OFFSET 0X40
  107. #define VCMD_REGISTER_INT_STATUS_OFFSET 0X44
  108. #define VCMD_REGISTER_INT_CTL_OFFSET 0X48
  109. #define VCMD_REGISTER_EXT_INT_GATE_OFFSET 0X64
  110. /* HW Register field names */
  111. typedef enum
  112. {
  113. #include "vcmdregisterenum.h"
  114. VcmdRegisterAmount
  115. } regVcmdName;
  116. /* HW Register field descriptions */
  117. typedef struct
  118. {
  119. u32 name; /* Register name and index */
  120. i32 base; /* Register base address */
  121. u32 mask; /* Bitmask for this field */
  122. i32 lsb; /* LSB for this field [31..0] */
  123. i32 trace; /* Enable/disable writing in swreg_params.trc */
  124. i32 rw; /* 1=Read-only 2=Write-only 3=Read-Write */
  125. char *description; /* Field description */
  126. } regVcmdField_s;
  127. /* Flags for read-only, write-only and read-write */
  128. #define RO 1
  129. #define WO 2
  130. #define RW 3
  131. #define REGBASE(reg) (asicVcmdRegisterDesc[reg].base)
  132. /* Description field only needed for system model build. */
  133. #ifdef TEST_DATA
  134. #define VCMDREG(name, base, mask, lsb, trace, rw, desc) \
  135. {name, base, mask, lsb, trace, rw, desc}
  136. #else
  137. #define VCMDREG(name, base, mask, lsb, trace, rw, desc) \
  138. {name, base, mask, lsb, trace, rw, ""}
  139. #endif
  140. /*------------------------------------------------------------------------------
  141. 4. Function prototypes
  142. ------------------------------------------------------------------------------*/
  143. extern const regVcmdField_s asicVcmdRegisterDesc[];
  144. /*------------------------------------------------------------------------------
  145. EncAsicSetRegisterValue
  146. Set a value into a defined register field
  147. ------------------------------------------------------------------------------*/
  148. static inline void vcmd_set_register_mirror_value(u32 *reg_mirror, regVcmdName name, u32 value)
  149. {
  150. const regVcmdField_s *field;
  151. u32 regVal;
  152. field = &asicVcmdRegisterDesc[name];
  153. #ifdef DEBUG_PRINT_REGS
  154. printf("vcmd_set_register_mirror_value 0x%2x 0x%08x Value: %10d %s\n",
  155. field->base, field->mask, value, field->description);
  156. #endif
  157. /* Check that value fits in field */
  158. PDEBUG("field->name == name=%d\n",field->name == name);
  159. PDEBUG("((field->mask >> field->lsb) << field->lsb) == field->mask=%d\n",((field->mask >> field->lsb) << field->lsb) == field->mask);
  160. PDEBUG("(field->mask >> field->lsb) >= value=%d\n",(field->mask >> field->lsb) >= value);
  161. PDEBUG("field->base < ASIC_VCMD_SWREG_AMOUNT * 4=%d\n",field->base < ASIC_VCMD_SWREG_AMOUNT * 4);
  162. /* Clear previous value of field in register */
  163. regVal = reg_mirror[field->base / 4] & ~(field->mask);
  164. /* Put new value of field in register */
  165. reg_mirror[field->base / 4] = regVal | ((value << field->lsb) & field->mask);
  166. }
  167. static inline u32 vcmd_get_register_mirror_value(u32 *reg_mirror, regVcmdName name)
  168. {
  169. const regVcmdField_s *field;
  170. u32 regVal;
  171. field = &asicVcmdRegisterDesc[name];
  172. /* Check that value fits in field */
  173. PDEBUG("field->name == name=%d\n",field->name == name);
  174. PDEBUG("((field->mask >> field->lsb) << field->lsb) == field->mask=%d\n",((field->mask >> field->lsb) << field->lsb) == field->mask);
  175. PDEBUG("field->base < ASIC_VCMD_SWREG_AMOUNT * 4=%d\n",field->base < ASIC_VCMD_SWREG_AMOUNT * 4);
  176. regVal = reg_mirror[field->base / 4];
  177. regVal = (regVal & field->mask) >> field->lsb;
  178. #ifdef DEBUG_PRINT_REGS
  179. PDEBUG("vcmd_get_register_mirror_value 0x%2x 0x%08x Value: %10d %s\n",
  180. field->base, field->mask, regVal, field->description);
  181. #endif
  182. return regVal;
  183. }
  184. u32 vcmd_read_reg(const void *hwregs, u32 offset);
  185. void vcmd_write_reg(const void *hwregs, u32 offset, u32 val);
  186. void vcmd_write_register_value(const void *hwregs,u32* reg_mirror,regVcmdName name, u32 value);
  187. u32 vcmd_get_register_value(const void *hwregs, u32* reg_mirror,regVcmdName name);
  188. #define vcmd_set_addr_register_value(reg_base, reg_mirror, name, value) do {\
  189. if(sizeof(ptr_t) == 8) {\
  190. vcmd_write_register_value((reg_base), (reg_mirror),name, (u32)((ptr_t)value)); \
  191. vcmd_write_register_value((reg_base), (reg_mirror),name##_MSB, (u32)(((ptr_t)value) >> 32));\
  192. } else {\
  193. vcmd_write_register_value((reg_base),(reg_mirror), name, (u32)((ptr_t)value));\
  194. }\
  195. }while (0)
  196. #define VCMDGetAddrRegisterValue(reg_base, reg_mirror,name) \
  197. ((sizeof(ptr_t) == 8) ? (\
  198. (((ptr_t)vcmd_get_register_value((reg_base),(reg_mirror), name)) | \
  199. (((ptr_t)vcmd_get_register_value((reg_base), (reg_mirror),name##_MSB)) << 32))\
  200. ) : ((ptr_t)vcmd_get_register_value((reg_base),(reg_mirror), (name))))
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif /* VCMD_SWHWREGISTERS_H */