cgs_common.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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_engine - Engines that can be statically power-gated
  43. */
  44. enum cgs_engine {
  45. CGS_ENGINE__UVD,
  46. CGS_ENGINE__VCE,
  47. CGS_ENGINE__VP8,
  48. CGS_ENGINE__ACP_DMA,
  49. CGS_ENGINE__ACP_DSP0,
  50. CGS_ENGINE__ACP_DSP1,
  51. CGS_ENGINE__ISP,
  52. /* ... */
  53. };
  54. /*
  55. * enum cgs_ucode_id - Firmware types for different IPs
  56. */
  57. enum cgs_ucode_id {
  58. CGS_UCODE_ID_SMU = 0,
  59. CGS_UCODE_ID_SMU_SK,
  60. CGS_UCODE_ID_SDMA0,
  61. CGS_UCODE_ID_SDMA1,
  62. CGS_UCODE_ID_CP_CE,
  63. CGS_UCODE_ID_CP_PFP,
  64. CGS_UCODE_ID_CP_ME,
  65. CGS_UCODE_ID_CP_MEC,
  66. CGS_UCODE_ID_CP_MEC_JT1,
  67. CGS_UCODE_ID_CP_MEC_JT2,
  68. CGS_UCODE_ID_GMCON_RENG,
  69. CGS_UCODE_ID_RLC_G,
  70. CGS_UCODE_ID_STORAGE,
  71. CGS_UCODE_ID_MAXIMUM,
  72. };
  73. /*
  74. * enum cgs_resource_type - GPU resource type
  75. */
  76. enum cgs_resource_type {
  77. CGS_RESOURCE_TYPE_MMIO = 0,
  78. CGS_RESOURCE_TYPE_FB,
  79. CGS_RESOURCE_TYPE_IO,
  80. CGS_RESOURCE_TYPE_DOORBELL,
  81. CGS_RESOURCE_TYPE_ROM,
  82. };
  83. /**
  84. * struct cgs_firmware_info - Firmware information
  85. */
  86. struct cgs_firmware_info {
  87. uint16_t version;
  88. uint16_t fw_version;
  89. uint16_t feature_version;
  90. uint32_t image_size;
  91. uint64_t mc_addr;
  92. /* only for smc firmware */
  93. uint32_t ucode_start_address;
  94. void *kptr;
  95. bool is_kicker;
  96. };
  97. struct cgs_mode_info {
  98. uint32_t refresh_rate;
  99. uint32_t vblank_time_us;
  100. };
  101. struct cgs_display_info {
  102. uint32_t display_count;
  103. uint32_t active_display_mask;
  104. struct cgs_mode_info *mode_info;
  105. };
  106. typedef unsigned long cgs_handle_t;
  107. /**
  108. * cgs_read_register() - Read an MMIO register
  109. * @cgs_device: opaque device handle
  110. * @offset: register offset
  111. *
  112. * Return: register value
  113. */
  114. typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
  115. /**
  116. * cgs_write_register() - Write an MMIO register
  117. * @cgs_device: opaque device handle
  118. * @offset: register offset
  119. * @value: register value
  120. */
  121. typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
  122. uint32_t value);
  123. /**
  124. * cgs_read_ind_register() - Read an indirect register
  125. * @cgs_device: opaque device handle
  126. * @offset: register offset
  127. *
  128. * Return: register value
  129. */
  130. typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  131. unsigned index);
  132. /**
  133. * cgs_write_ind_register() - Write an indirect register
  134. * @cgs_device: opaque device handle
  135. * @offset: register offset
  136. * @value: register value
  137. */
  138. typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  139. unsigned index, uint32_t value);
  140. #define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  141. #define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  142. #define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \
  143. (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \
  144. (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field))))
  145. #define CGS_REG_GET_FIELD(value, reg, field) \
  146. (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field))
  147. #define CGS_WREG32_FIELD(device, reg, field, val) \
  148. 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))
  149. #define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \
  150. 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))
  151. /**
  152. * cgs_get_pci_resource() - provide access to a device resource (PCI BAR)
  153. * @cgs_device: opaque device handle
  154. * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL)
  155. * @size: size of the region
  156. * @offset: offset from the start of the region
  157. * @resource_base: base address (not including offset) returned
  158. *
  159. * Return: 0 on success, -errno otherwise
  160. */
  161. typedef int (*cgs_get_pci_resource_t)(struct cgs_device *cgs_device,
  162. enum cgs_resource_type resource_type,
  163. uint64_t size,
  164. uint64_t offset,
  165. uint64_t *resource_base);
  166. /**
  167. * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table
  168. * @cgs_device: opaque device handle
  169. * @table: data table index
  170. * @size: size of the table (output, may be NULL)
  171. * @frev: table format revision (output, may be NULL)
  172. * @crev: table content revision (output, may be NULL)
  173. *
  174. * Return: Pointer to start of the table, or NULL on failure
  175. */
  176. typedef const void *(*cgs_atom_get_data_table_t)(
  177. struct cgs_device *cgs_device, unsigned table,
  178. uint16_t *size, uint8_t *frev, uint8_t *crev);
  179. /**
  180. * cgs_atom_get_cmd_table_revs() - Get ATOM BIOS command table revisions
  181. * @cgs_device: opaque device handle
  182. * @table: data table index
  183. * @frev: table format revision (output, may be NULL)
  184. * @crev: table content revision (output, may be NULL)
  185. *
  186. * Return: 0 on success, -errno otherwise
  187. */
  188. typedef int (*cgs_atom_get_cmd_table_revs_t)(struct cgs_device *cgs_device, unsigned table,
  189. uint8_t *frev, uint8_t *crev);
  190. /**
  191. * cgs_atom_exec_cmd_table() - Execute an ATOM BIOS command table
  192. * @cgs_device: opaque device handle
  193. * @table: command table index
  194. * @args: arguments
  195. *
  196. * Return: 0 on success, -errno otherwise
  197. */
  198. typedef int (*cgs_atom_exec_cmd_table_t)(struct cgs_device *cgs_device,
  199. unsigned table, void *args);
  200. /**
  201. * cgs_get_firmware_info - Get the firmware information from core driver
  202. * @cgs_device: opaque device handle
  203. * @type: the firmware type
  204. * @info: returend firmware information
  205. *
  206. * Return: 0 on success, -errno otherwise
  207. */
  208. typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
  209. enum cgs_ucode_id type,
  210. struct cgs_firmware_info *info);
  211. typedef int (*cgs_rel_firmware)(struct cgs_device *cgs_device,
  212. enum cgs_ucode_id type);
  213. typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
  214. enum amd_ip_block_type block_type,
  215. enum amd_powergating_state state);
  216. typedef int(*cgs_set_clockgating_state)(struct cgs_device *cgs_device,
  217. enum amd_ip_block_type block_type,
  218. enum amd_clockgating_state state);
  219. typedef int(*cgs_get_active_displays_info)(
  220. struct cgs_device *cgs_device,
  221. struct cgs_display_info *info);
  222. typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
  223. typedef int (*cgs_is_virtualization_enabled_t)(void *cgs_device);
  224. typedef int (*cgs_enter_safe_mode)(struct cgs_device *cgs_device, bool en);
  225. typedef void (*cgs_lock_grbm_idx)(struct cgs_device *cgs_device, bool lock);
  226. struct cgs_ops {
  227. /* MMIO access */
  228. cgs_read_register_t read_register;
  229. cgs_write_register_t write_register;
  230. cgs_read_ind_register_t read_ind_register;
  231. cgs_write_ind_register_t write_ind_register;
  232. /* PCI resources */
  233. cgs_get_pci_resource_t get_pci_resource;
  234. /* ATOM BIOS */
  235. cgs_atom_get_data_table_t atom_get_data_table;
  236. cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs;
  237. cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
  238. /* Firmware Info */
  239. cgs_get_firmware_info get_firmware_info;
  240. cgs_rel_firmware rel_firmware;
  241. /* cg pg interface*/
  242. cgs_set_powergating_state set_powergating_state;
  243. cgs_set_clockgating_state set_clockgating_state;
  244. /* display manager */
  245. cgs_get_active_displays_info get_active_displays_info;
  246. /* notify dpm enabled */
  247. cgs_notify_dpm_enabled notify_dpm_enabled;
  248. cgs_is_virtualization_enabled_t is_virtualization_enabled;
  249. cgs_enter_safe_mode enter_safe_mode;
  250. cgs_lock_grbm_idx lock_grbm_idx;
  251. };
  252. struct cgs_os_ops; /* To be define in OS-specific CGS header */
  253. struct cgs_device
  254. {
  255. const struct cgs_ops *ops;
  256. const struct cgs_os_ops *os_ops;
  257. /* to be embedded at the start of driver private structure */
  258. };
  259. /* Convenience macros that make CGS indirect function calls look like
  260. * normal function calls */
  261. #define CGS_CALL(func,dev,...) \
  262. (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
  263. #define CGS_OS_CALL(func,dev,...) \
  264. (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
  265. #define cgs_read_register(dev,offset) \
  266. CGS_CALL(read_register,dev,offset)
  267. #define cgs_write_register(dev,offset,value) \
  268. CGS_CALL(write_register,dev,offset,value)
  269. #define cgs_read_ind_register(dev,space,index) \
  270. CGS_CALL(read_ind_register,dev,space,index)
  271. #define cgs_write_ind_register(dev,space,index,value) \
  272. CGS_CALL(write_ind_register,dev,space,index,value)
  273. #define cgs_atom_get_data_table(dev,table,size,frev,crev) \
  274. CGS_CALL(atom_get_data_table,dev,table,size,frev,crev)
  275. #define cgs_atom_get_cmd_table_revs(dev,table,frev,crev) \
  276. CGS_CALL(atom_get_cmd_table_revs,dev,table,frev,crev)
  277. #define cgs_atom_exec_cmd_table(dev,table,args) \
  278. CGS_CALL(atom_exec_cmd_table,dev,table,args)
  279. #define cgs_get_firmware_info(dev, type, info) \
  280. CGS_CALL(get_firmware_info, dev, type, info)
  281. #define cgs_rel_firmware(dev, type) \
  282. CGS_CALL(rel_firmware, dev, type)
  283. #define cgs_set_powergating_state(dev, block_type, state) \
  284. CGS_CALL(set_powergating_state, dev, block_type, state)
  285. #define cgs_set_clockgating_state(dev, block_type, state) \
  286. CGS_CALL(set_clockgating_state, dev, block_type, state)
  287. #define cgs_notify_dpm_enabled(dev, enabled) \
  288. CGS_CALL(notify_dpm_enabled, dev, enabled)
  289. #define cgs_get_active_displays_info(dev, info) \
  290. CGS_CALL(get_active_displays_info, dev, info)
  291. #define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \
  292. resource_base) \
  293. CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
  294. resource_base)
  295. #define cgs_is_virtualization_enabled(cgs_device) \
  296. CGS_CALL(is_virtualization_enabled, cgs_device)
  297. #define cgs_enter_safe_mode(cgs_device, en) \
  298. CGS_CALL(enter_safe_mode, cgs_device, en)
  299. #define cgs_lock_grbm_idx(cgs_device, lock) \
  300. CGS_CALL(lock_grbm_idx, cgs_device, lock)
  301. #endif /* _CGS_COMMON_H */