vcmdswhwregisters.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. /*------------------------------------------------------------------------------
  63. 1. Include headers
  64. ------------------------------------------------------------------------------*/
  65. #ifdef __FREERTOS__
  66. #include "basetype.h"
  67. #include "io_tools.h"
  68. #elif defined(__linux__)
  69. #ifndef MODEL_SIMULATION
  70. #include <linux/ioctl.h>
  71. #include <linux/kernel.h>
  72. #include <linux/module.h>
  73. #endif
  74. #endif
  75. #ifdef __FREERTOS__
  76. //addr_t has been defined in basetype.h //Now the FreeRTOS mem need to support 64bit env
  77. #elif defined(__linux__)
  78. typedef size_t addr_t;
  79. #endif
  80. typedef addr_t ptr_t;
  81. #undef PDEBUG /* undef it, just in case */
  82. #ifdef REGISTER_DEBUG
  83. # ifdef __KERNEL__
  84. /* This one if debugging is on, and kernel space */
  85. # define PDEBUG(fmt, args...) printk( KERN_INFO "memalloc: " fmt, ## args)
  86. # else
  87. /* This one for user space */
  88. # define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
  89. # endif
  90. #else
  91. # define PDEBUG(fmt, ...) /* not debugging: nothing */
  92. #endif
  93. /*------------------------------------------------------------------------------
  94. 2. External compiler flags
  95. --------------------------------------------------------------------------------
  96. --------------------------------------------------------------------------------
  97. 3. Module defines
  98. ------------------------------------------------------------------------------*/
  99. #define ASIC_VCMD_SWREG_AMOUNT 27
  100. #define VCMD_REGISTER_CONTROL_OFFSET 0X40
  101. #define VCMD_REGISTER_INT_STATUS_OFFSET 0X44
  102. #define VCMD_REGISTER_INT_CTL_OFFSET 0X48
  103. #define VCMD_REGISTER_EXT_INT_GATE_OFFSET 0X64
  104. /* HW Register field names */
  105. typedef enum
  106. {
  107. #include "vcmdregisterenum.h"
  108. VcmdRegisterAmount
  109. } regVcmdName;
  110. /* HW Register field descriptions */
  111. typedef struct
  112. {
  113. u32 name; /* Register name and index */
  114. int base; /* Register base address */
  115. u32 mask; /* Bitmask for this field */
  116. int lsb; /* LSB for this field [31..0] */
  117. int trace; /* Enable/disable writing in swreg_params.trc */
  118. int rw; /* 1=Read-only 2=Write-only 3=Read-Write */
  119. char *description; /* Field description */
  120. } regVcmdField_s;
  121. /* Flags for read-only, write-only and read-write */
  122. #define RO 1
  123. #define WO 2
  124. #define RW 3
  125. #define REGBASE(reg) (asicVcmdRegisterDesc[reg].base)
  126. /* Description field only needed for system model build. */
  127. #ifdef TEST_DATA
  128. #define VCMDREG(name, base, mask, lsb, trace, rw, desc) \
  129. {name, base, mask, lsb, trace, rw, desc}
  130. #else
  131. #define VCMDREG(name, base, mask, lsb, trace, rw, desc) \
  132. {name, base, mask, lsb, trace, rw, ""}
  133. #endif
  134. /*------------------------------------------------------------------------------
  135. 4. Function prototypes
  136. ------------------------------------------------------------------------------*/
  137. extern const regVcmdField_s asicVcmdRegisterDesc[];
  138. /*------------------------------------------------------------------------------
  139. EncAsicSetRegisterValue
  140. Set a value into a defined register field
  141. ------------------------------------------------------------------------------*/
  142. static inline void vcmd_set_register_mirror_value(u32 *reg_mirror, regVcmdName name, u32 value)
  143. {
  144. const regVcmdField_s *field;
  145. u32 regVal;
  146. field = &asicVcmdRegisterDesc[name];
  147. #ifdef DEBUG_PRINT_REGS
  148. printf("vcmd_set_register_mirror_value 0x%2x 0x%08x Value: %10d %s\n",
  149. field->base, field->mask, value, field->description);
  150. #endif
  151. /* Check that value fits in field */
  152. PDEBUG("field->name == name=%d\n",field->name == name);
  153. PDEBUG("((field->mask >> field->lsb) << field->lsb) == field->mask=%d\n",((field->mask >> field->lsb) << field->lsb) == field->mask);
  154. PDEBUG("(field->mask >> field->lsb) >= value=%d\n",(field->mask >> field->lsb) >= value);
  155. PDEBUG("field->base < ASIC_VCMD_SWREG_AMOUNT * 4=%d\n",field->base < ASIC_VCMD_SWREG_AMOUNT * 4);
  156. /* Clear previous value of field in register */
  157. regVal = reg_mirror[field->base / 4] & ~(field->mask);
  158. /* Put new value of field in register */
  159. reg_mirror[field->base / 4] = regVal | ((value << field->lsb) & field->mask);
  160. }
  161. static inline u32 vcmd_get_register_mirror_value(u32 *reg_mirror, regVcmdName name)
  162. {
  163. const regVcmdField_s *field;
  164. u32 regVal;
  165. field = &asicVcmdRegisterDesc[name];
  166. /* Check that value fits in field */
  167. PDEBUG("field->name == name=%d\n",field->name == name);
  168. PDEBUG("((field->mask >> field->lsb) << field->lsb) == field->mask=%d\n",((field->mask >> field->lsb) << field->lsb) == field->mask);
  169. PDEBUG("field->base < ASIC_VCMD_SWREG_AMOUNT * 4=%d\n",field->base < ASIC_VCMD_SWREG_AMOUNT * 4);
  170. regVal = reg_mirror[field->base / 4];
  171. regVal = (regVal & field->mask) >> field->lsb;
  172. #ifdef DEBUG_PRINT_REGS
  173. PDEBUG("vcmd_get_register_mirror_value 0x%2x 0x%08x Value: %10d %s\n",
  174. field->base, field->mask, regVal, field->description);
  175. #endif
  176. return regVal;
  177. }
  178. u32 vcmd_read_reg(const void *hwregs, u32 offset);
  179. void vcmd_write_reg(const void *hwregs, u32 offset, u32 val);
  180. void vcmd_write_register_value(const void *hwregs,u32* reg_mirror,regVcmdName name, u32 value);
  181. u32 vcmd_get_register_value(const void *hwregs, u32* reg_mirror,regVcmdName name);
  182. #define vcmd_set_addr_register_value(reg_base, reg_mirror, name, value) do {\
  183. if(sizeof(addr_t) == 8) {\
  184. vcmd_write_register_value((reg_base), (reg_mirror),name, (u32)((addr_t)value)); \
  185. vcmd_write_register_value((reg_base), (reg_mirror),name##_MSB, (u32)(((addr_t)value) >> 32));\
  186. } else {\
  187. vcmd_write_register_value((reg_base),(reg_mirror), name, (u32)((addr_t)value));\
  188. }\
  189. }while (0)
  190. #define VCMDGetAddrRegisterValue(reg_base, reg_mirror,name) \
  191. ((sizeof(addr_t) == 8) ? (\
  192. (((addr_t)vcmd_get_register_value((reg_base),(reg_mirror), name)) | \
  193. (((addr_t)vcmd_get_register_value((reg_base), (reg_mirror),name##_MSB)) << 32))\
  194. ) : ((addr_t)vcmd_get_register_value((reg_base),(reg_mirror), (name))))
  195. #endif /* VCMD_SWHWREGISTERS_H */