cgs_common.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. *
  23. */
  24. #ifndef _CGS_COMMON_H
  25. #define _CGS_COMMON_H
  26. #include "amd_shared.h"
  27. struct cgs_device;
  28. /**
  29. * enum cgs_ind_reg - Indirect register spaces
  30. */
  31. enum cgs_ind_reg {
  32. CGS_IND_REG__MMIO,
  33. CGS_IND_REG__PCIE,
  34. CGS_IND_REG__SMC,
  35. CGS_IND_REG__UVD_CTX,
  36. CGS_IND_REG__DIDT,
  37. CGS_IND_REG_GC_CAC,
  38. CGS_IND_REG_SE_CAC,
  39. CGS_IND_REG__AUDIO_ENDPT
  40. };
  41. /*
  42. * enum cgs_ucode_id - Firmware types for different IPs
  43. */
  44. enum cgs_ucode_id {
  45. CGS_UCODE_ID_SMU = 0,
  46. CGS_UCODE_ID_SMU_SK,
  47. CGS_UCODE_ID_SDMA0,
  48. CGS_UCODE_ID_SDMA1,
  49. CGS_UCODE_ID_CP_CE,
  50. CGS_UCODE_ID_CP_PFP,
  51. CGS_UCODE_ID_CP_ME,
  52. CGS_UCODE_ID_CP_MEC,
  53. CGS_UCODE_ID_CP_MEC_JT1,
  54. CGS_UCODE_ID_CP_MEC_JT2,
  55. CGS_UCODE_ID_GMCON_RENG,
  56. CGS_UCODE_ID_RLC_G,
  57. CGS_UCODE_ID_STORAGE,
  58. CGS_UCODE_ID_MAXIMUM,
  59. };
  60. /**
  61. * struct cgs_firmware_info - Firmware information
  62. */
  63. struct cgs_firmware_info {
  64. uint16_t version;
  65. uint16_t fw_version;
  66. uint16_t feature_version;
  67. uint32_t image_size;
  68. uint64_t mc_addr;
  69. /* only for smc firmware */
  70. uint32_t ucode_start_address;
  71. void *kptr;
  72. bool is_kicker;
  73. };
  74. typedef unsigned long cgs_handle_t;
  75. /**
  76. * cgs_read_register() - Read an MMIO register
  77. * @cgs_device: opaque device handle
  78. * @offset: register offset
  79. *
  80. * Return: register value
  81. */
  82. typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
  83. /**
  84. * cgs_write_register() - Write an MMIO register
  85. * @cgs_device: opaque device handle
  86. * @offset: register offset
  87. * @value: register value
  88. */
  89. typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
  90. uint32_t value);
  91. /**
  92. * cgs_read_ind_register() - Read an indirect register
  93. * @cgs_device: opaque device handle
  94. * @offset: register offset
  95. *
  96. * Return: register value
  97. */
  98. typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  99. unsigned index);
  100. /**
  101. * cgs_write_ind_register() - Write an indirect register
  102. * @cgs_device: opaque device handle
  103. * @offset: register offset
  104. * @value: register value
  105. */
  106. typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  107. unsigned index, uint32_t value);
  108. #define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  109. #define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  110. #define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \
  111. (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \
  112. (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field))))
  113. #define CGS_REG_GET_FIELD(value, reg, field) \
  114. (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field))
  115. #define CGS_WREG32_FIELD(device, reg, field, val) \
  116. cgs_write_register(device, mm##reg, (cgs_read_register(device, mm##reg) & ~CGS_REG_FIELD_MASK(reg, field)) | (val) << CGS_REG_FIELD_SHIFT(reg, field))
  117. #define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \
  118. cgs_write_ind_register(device, space, ix##reg, (cgs_read_ind_register(device, space, ix##reg) & ~CGS_REG_FIELD_MASK(reg, field)) | (val) << CGS_REG_FIELD_SHIFT(reg, field))
  119. typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
  120. enum cgs_ucode_id type,
  121. struct cgs_firmware_info *info);
  122. struct cgs_ops {
  123. /* MMIO access */
  124. cgs_read_register_t read_register;
  125. cgs_write_register_t write_register;
  126. cgs_read_ind_register_t read_ind_register;
  127. cgs_write_ind_register_t write_ind_register;
  128. /* Firmware Info */
  129. cgs_get_firmware_info get_firmware_info;
  130. };
  131. struct cgs_os_ops; /* To be define in OS-specific CGS header */
  132. struct cgs_device
  133. {
  134. const struct cgs_ops *ops;
  135. /* to be embedded at the start of driver private structure */
  136. };
  137. /* Convenience macros that make CGS indirect function calls look like
  138. * normal function calls */
  139. #define CGS_CALL(func,dev,...) \
  140. (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
  141. #define CGS_OS_CALL(func,dev,...) \
  142. (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
  143. #define cgs_read_register(dev,offset) \
  144. CGS_CALL(read_register,dev,offset)
  145. #define cgs_write_register(dev,offset,value) \
  146. CGS_CALL(write_register,dev,offset,value)
  147. #define cgs_read_ind_register(dev,space,index) \
  148. CGS_CALL(read_ind_register,dev,space,index)
  149. #define cgs_write_ind_register(dev,space,index,value) \
  150. CGS_CALL(write_ind_register,dev,space,index,value)
  151. #define cgs_get_firmware_info(dev, type, info) \
  152. CGS_CALL(get_firmware_info, dev, type, info)
  153. #endif /* _CGS_COMMON_H */