cgs_common.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 ref_clock;
  100. uint32_t vblank_time_us;
  101. };
  102. struct cgs_display_info {
  103. uint32_t display_count;
  104. uint32_t active_display_mask;
  105. struct cgs_mode_info *mode_info;
  106. };
  107. typedef unsigned long cgs_handle_t;
  108. /**
  109. * cgs_read_register() - Read an MMIO register
  110. * @cgs_device: opaque device handle
  111. * @offset: register offset
  112. *
  113. * Return: register value
  114. */
  115. typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
  116. /**
  117. * cgs_write_register() - Write an MMIO register
  118. * @cgs_device: opaque device handle
  119. * @offset: register offset
  120. * @value: register value
  121. */
  122. typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
  123. uint32_t value);
  124. /**
  125. * cgs_read_ind_register() - Read an indirect register
  126. * @cgs_device: opaque device handle
  127. * @offset: register offset
  128. *
  129. * Return: register value
  130. */
  131. typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  132. unsigned index);
  133. /**
  134. * cgs_write_ind_register() - Write an indirect register
  135. * @cgs_device: opaque device handle
  136. * @offset: register offset
  137. * @value: register value
  138. */
  139. typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
  140. unsigned index, uint32_t value);
  141. #define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  142. #define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK
  143. #define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \
  144. (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \
  145. (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field))))
  146. #define CGS_REG_GET_FIELD(value, reg, field) \
  147. (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field))
  148. #define CGS_WREG32_FIELD(device, reg, field, val) \
  149. 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))
  150. #define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \
  151. 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))
  152. /**
  153. * cgs_get_pci_resource() - provide access to a device resource (PCI BAR)
  154. * @cgs_device: opaque device handle
  155. * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL)
  156. * @size: size of the region
  157. * @offset: offset from the start of the region
  158. * @resource_base: base address (not including offset) returned
  159. *
  160. * Return: 0 on success, -errno otherwise
  161. */
  162. typedef int (*cgs_get_pci_resource_t)(struct cgs_device *cgs_device,
  163. enum cgs_resource_type resource_type,
  164. uint64_t size,
  165. uint64_t offset,
  166. uint64_t *resource_base);
  167. /**
  168. * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table
  169. * @cgs_device: opaque device handle
  170. * @table: data table index
  171. * @size: size of the table (output, may be NULL)
  172. * @frev: table format revision (output, may be NULL)
  173. * @crev: table content revision (output, may be NULL)
  174. *
  175. * Return: Pointer to start of the table, or NULL on failure
  176. */
  177. typedef const void *(*cgs_atom_get_data_table_t)(
  178. struct cgs_device *cgs_device, unsigned table,
  179. uint16_t *size, uint8_t *frev, uint8_t *crev);
  180. /**
  181. * cgs_atom_get_cmd_table_revs() - Get ATOM BIOS command table revisions
  182. * @cgs_device: opaque device handle
  183. * @table: data table index
  184. * @frev: table format revision (output, may be NULL)
  185. * @crev: table content revision (output, may be NULL)
  186. *
  187. * Return: 0 on success, -errno otherwise
  188. */
  189. typedef int (*cgs_atom_get_cmd_table_revs_t)(struct cgs_device *cgs_device, unsigned table,
  190. uint8_t *frev, uint8_t *crev);
  191. /**
  192. * cgs_atom_exec_cmd_table() - Execute an ATOM BIOS command table
  193. * @cgs_device: opaque device handle
  194. * @table: command table index
  195. * @args: arguments
  196. *
  197. * Return: 0 on success, -errno otherwise
  198. */
  199. typedef int (*cgs_atom_exec_cmd_table_t)(struct cgs_device *cgs_device,
  200. unsigned table, void *args);
  201. /**
  202. * cgs_get_firmware_info - Get the firmware information from core driver
  203. * @cgs_device: opaque device handle
  204. * @type: the firmware type
  205. * @info: returend firmware information
  206. *
  207. * Return: 0 on success, -errno otherwise
  208. */
  209. typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
  210. enum cgs_ucode_id type,
  211. struct cgs_firmware_info *info);
  212. typedef int (*cgs_rel_firmware)(struct cgs_device *cgs_device,
  213. enum cgs_ucode_id type);
  214. typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
  215. enum amd_ip_block_type block_type,
  216. enum amd_powergating_state state);
  217. typedef int(*cgs_set_clockgating_state)(struct cgs_device *cgs_device,
  218. enum amd_ip_block_type block_type,
  219. enum amd_clockgating_state state);
  220. typedef int(*cgs_get_active_displays_info)(
  221. struct cgs_device *cgs_device,
  222. struct cgs_display_info *info);
  223. typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
  224. typedef int (*cgs_is_virtualization_enabled_t)(void *cgs_device);
  225. typedef int (*cgs_enter_safe_mode)(struct cgs_device *cgs_device, bool en);
  226. typedef void (*cgs_lock_grbm_idx)(struct cgs_device *cgs_device, bool lock);
  227. struct cgs_ops {
  228. /* MMIO access */
  229. cgs_read_register_t read_register;
  230. cgs_write_register_t write_register;
  231. cgs_read_ind_register_t read_ind_register;
  232. cgs_write_ind_register_t write_ind_register;
  233. /* PCI resources */
  234. cgs_get_pci_resource_t get_pci_resource;
  235. /* ATOM BIOS */
  236. cgs_atom_get_data_table_t atom_get_data_table;
  237. cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs;
  238. cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
  239. /* Firmware Info */
  240. cgs_get_firmware_info get_firmware_info;
  241. cgs_rel_firmware rel_firmware;
  242. /* cg pg interface*/
  243. cgs_set_powergating_state set_powergating_state;
  244. cgs_set_clockgating_state set_clockgating_state;
  245. /* display manager */
  246. cgs_get_active_displays_info get_active_displays_info;
  247. /* notify dpm enabled */
  248. cgs_notify_dpm_enabled notify_dpm_enabled;
  249. cgs_is_virtualization_enabled_t is_virtualization_enabled;
  250. cgs_enter_safe_mode enter_safe_mode;
  251. cgs_lock_grbm_idx lock_grbm_idx;
  252. };
  253. struct cgs_os_ops; /* To be define in OS-specific CGS header */
  254. struct cgs_device
  255. {
  256. const struct cgs_ops *ops;
  257. const struct cgs_os_ops *os_ops;
  258. /* to be embedded at the start of driver private structure */
  259. };
  260. /* Convenience macros that make CGS indirect function calls look like
  261. * normal function calls */
  262. #define CGS_CALL(func,dev,...) \
  263. (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
  264. #define CGS_OS_CALL(func,dev,...) \
  265. (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
  266. #define cgs_read_register(dev,offset) \
  267. CGS_CALL(read_register,dev,offset)
  268. #define cgs_write_register(dev,offset,value) \
  269. CGS_CALL(write_register,dev,offset,value)
  270. #define cgs_read_ind_register(dev,space,index) \
  271. CGS_CALL(read_ind_register,dev,space,index)
  272. #define cgs_write_ind_register(dev,space,index,value) \
  273. CGS_CALL(write_ind_register,dev,space,index,value)
  274. #define cgs_atom_get_data_table(dev,table,size,frev,crev) \
  275. CGS_CALL(atom_get_data_table,dev,table,size,frev,crev)
  276. #define cgs_atom_get_cmd_table_revs(dev,table,frev,crev) \
  277. CGS_CALL(atom_get_cmd_table_revs,dev,table,frev,crev)
  278. #define cgs_atom_exec_cmd_table(dev,table,args) \
  279. CGS_CALL(atom_exec_cmd_table,dev,table,args)
  280. #define cgs_get_firmware_info(dev, type, info) \
  281. CGS_CALL(get_firmware_info, dev, type, info)
  282. #define cgs_rel_firmware(dev, type) \
  283. CGS_CALL(rel_firmware, dev, type)
  284. #define cgs_set_powergating_state(dev, block_type, state) \
  285. CGS_CALL(set_powergating_state, dev, block_type, state)
  286. #define cgs_set_clockgating_state(dev, block_type, state) \
  287. CGS_CALL(set_clockgating_state, dev, block_type, state)
  288. #define cgs_notify_dpm_enabled(dev, enabled) \
  289. CGS_CALL(notify_dpm_enabled, dev, enabled)
  290. #define cgs_get_active_displays_info(dev, info) \
  291. CGS_CALL(get_active_displays_info, dev, info)
  292. #define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \
  293. resource_base) \
  294. CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
  295. resource_base)
  296. #define cgs_is_virtualization_enabled(cgs_device) \
  297. CGS_CALL(is_virtualization_enabled, cgs_device)
  298. #define cgs_enter_safe_mode(cgs_device, en) \
  299. CGS_CALL(enter_safe_mode, cgs_device, en)
  300. #define cgs_lock_grbm_idx(cgs_device, lock) \
  301. CGS_CALL(lock_grbm_idx, cgs_device, lock)
  302. #endif /* _CGS_COMMON_H */