cgs_common.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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__PCIE,
  33. CGS_IND_REG__SMC,
  34. CGS_IND_REG__UVD_CTX,
  35. CGS_IND_REG__DIDT,
  36. CGS_IND_REG_GC_CAC,
  37. CGS_IND_REG_SE_CAC,
  38. CGS_IND_REG__AUDIO_ENDPT
  39. };
  40. /*
  41. * enum cgs_ucode_id - Firmware types for different IPs
  42. */
  43. enum cgs_ucode_id {
  44. CGS_UCODE_ID_SMU = 0,
  45. CGS_UCODE_ID_SMU_SK,
  46. CGS_UCODE_ID_SDMA0,
  47. CGS_UCODE_ID_SDMA1,
  48. CGS_UCODE_ID_CP_CE,
  49. CGS_UCODE_ID_CP_PFP,
  50. CGS_UCODE_ID_CP_ME,
  51. CGS_UCODE_ID_CP_MEC,
  52. CGS_UCODE_ID_CP_MEC_JT1,
  53. CGS_UCODE_ID_CP_MEC_JT2,
  54. CGS_UCODE_ID_GMCON_RENG,
  55. CGS_UCODE_ID_RLC_G,
  56. CGS_UCODE_ID_STORAGE,
  57. CGS_UCODE_ID_MAXIMUM,
  58. };
  59. /**
  60. * struct cgs_firmware_info - Firmware information
  61. */
  62. struct cgs_firmware_info {
  63. uint16_t version;
  64. uint16_t fw_version;
  65. uint16_t feature_version;
  66. uint32_t image_size;
  67. uint64_t mc_addr;
  68. /* only for smc firmware */
  69. uint32_t ucode_start_address;
  70. void *kptr;
  71. bool is_kicker;
  72. };
  73. typedef unsigned long cgs_handle_t;
  74. /**
  75. * cgs_read_register() - Read an MMIO register
  76. * @cgs_device: opaque device handle
  77. * @offset: register offset
  78. *
  79. * Return: register value
  80. */
  81. typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
  82. /**
  83. * cgs_write_register() - Write an MMIO register
  84. * @cgs_device: opaque device handle
  85. * @offset: register offset
  86. * @value: register value
  87. */
  88. typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
  89. uint32_t value);
  90. /**
  91. * cgs_read_ind_register() - Read an indirect register
  92. * @cgs_device: opaque device handle
  93. * @offset: register offset
  94. *
  95. * Return: register value
  96. */
  97. typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  98. unsigned index);
  99. /**
  100. * cgs_write_ind_register() - Write an indirect register
  101. * @cgs_device: opaque device handle
  102. * @offset: register offset
  103. * @value: register value
  104. */
  105. typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  106. unsigned index, uint32_t value);
  107. #define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  108. #define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  109. #define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \
  110. (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \
  111. (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field))))
  112. #define CGS_REG_GET_FIELD(value, reg, field) \
  113. (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field))
  114. #define CGS_WREG32_FIELD(device, reg, field, val) \
  115. 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))
  116. #define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \
  117. 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))
  118. typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
  119. enum cgs_ucode_id type,
  120. struct cgs_firmware_info *info);
  121. struct cgs_ops {
  122. /* MMIO access */
  123. cgs_read_register_t read_register;
  124. cgs_write_register_t write_register;
  125. cgs_read_ind_register_t read_ind_register;
  126. cgs_write_ind_register_t write_ind_register;
  127. /* Firmware Info */
  128. cgs_get_firmware_info get_firmware_info;
  129. };
  130. struct cgs_os_ops; /* To be define in OS-specific CGS header */
  131. struct cgs_device {
  132. const struct cgs_ops *ops;
  133. /* to be embedded at the start of driver private structure */
  134. };
  135. /* Convenience macros that make CGS indirect function calls look like
  136. * normal function calls */
  137. #define CGS_CALL(func, dev, ...) \
  138. (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
  139. #define CGS_OS_CALL(func, dev, ...) \
  140. (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
  141. #define cgs_read_register(dev, offset) \
  142. CGS_CALL(read_register, dev, offset)
  143. #define cgs_write_register(dev, offset, value) \
  144. CGS_CALL(write_register, dev, offset, value)
  145. #define cgs_read_ind_register(dev, space, index) \
  146. CGS_CALL(read_ind_register, dev, space, index)
  147. #define cgs_write_ind_register(dev, space, index, value) \
  148. CGS_CALL(write_ind_register, dev, space, index, value)
  149. #define cgs_get_firmware_info(dev, type, info) \
  150. CGS_CALL(get_firmware_info, dev, type, info)
  151. #endif /* _CGS_COMMON_H */