amdgpu_psp.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2016 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. * Author: Huang Rui
  23. *
  24. */
  25. #ifndef __AMDGPU_PSP_H__
  26. #define __AMDGPU_PSP_H__
  27. #include "amdgpu.h"
  28. #include "psp_gfx_if.h"
  29. #define PSP_FENCE_BUFFER_SIZE 0x1000
  30. #define PSP_CMD_BUFFER_SIZE 0x1000
  31. #define PSP_ASD_SHARED_MEM_SIZE 0x4000
  32. #define PSP_1_MEG 0x100000
  33. struct psp_context;
  34. enum psp_ring_type
  35. {
  36. PSP_RING_TYPE__INVALID = 0,
  37. /*
  38. * These values map to the way the PSP kernel identifies the
  39. * rings.
  40. */
  41. PSP_RING_TYPE__UM = 1, /* User mode ring (formerly called RBI) */
  42. PSP_RING_TYPE__KM = 2 /* Kernel mode ring (formerly called GPCOM) */
  43. };
  44. struct psp_ring
  45. {
  46. enum psp_ring_type ring_type;
  47. struct psp_gfx_rb_frame *ring_mem;
  48. uint64_t ring_mem_mc_addr;
  49. void *ring_mem_handle;
  50. uint32_t ring_size;
  51. };
  52. struct psp_funcs
  53. {
  54. int (*init_microcode)(struct psp_context *psp);
  55. int (*bootloader_load_sysdrv)(struct psp_context *psp);
  56. int (*bootloader_load_sos)(struct psp_context *psp);
  57. int (*prep_cmd_buf)(struct amdgpu_firmware_info *ucode,
  58. struct psp_gfx_cmd_resp *cmd);
  59. int (*ring_init)(struct psp_context *psp, enum psp_ring_type ring_type);
  60. int (*ring_create)(struct psp_context *psp, enum psp_ring_type ring_type);
  61. int (*ring_stop)(struct psp_context *psp,
  62. enum psp_ring_type ring_type);
  63. int (*ring_destroy)(struct psp_context *psp,
  64. enum psp_ring_type ring_type);
  65. int (*cmd_submit)(struct psp_context *psp, struct amdgpu_firmware_info *ucode,
  66. uint64_t cmd_buf_mc_addr, uint64_t fence_mc_addr, int index);
  67. bool (*compare_sram_data)(struct psp_context *psp,
  68. struct amdgpu_firmware_info *ucode,
  69. enum AMDGPU_UCODE_ID ucode_type);
  70. bool (*smu_reload_quirk)(struct psp_context *psp);
  71. int (*mode1_reset)(struct psp_context *psp);
  72. };
  73. struct psp_context
  74. {
  75. struct amdgpu_device *adev;
  76. struct psp_ring km_ring;
  77. struct psp_gfx_cmd_resp *cmd;
  78. const struct psp_funcs *funcs;
  79. /* fence buffer */
  80. struct amdgpu_bo *fw_pri_bo;
  81. uint64_t fw_pri_mc_addr;
  82. void *fw_pri_buf;
  83. /* sos firmware */
  84. const struct firmware *sos_fw;
  85. uint32_t sos_fw_version;
  86. uint32_t sos_feature_version;
  87. uint32_t sys_bin_size;
  88. uint32_t sos_bin_size;
  89. uint8_t *sys_start_addr;
  90. uint8_t *sos_start_addr;
  91. /* tmr buffer */
  92. struct amdgpu_bo *tmr_bo;
  93. uint64_t tmr_mc_addr;
  94. void *tmr_buf;
  95. /* asd firmware and buffer */
  96. const struct firmware *asd_fw;
  97. uint32_t asd_fw_version;
  98. uint32_t asd_feature_version;
  99. uint32_t asd_ucode_size;
  100. uint8_t *asd_start_addr;
  101. struct amdgpu_bo *asd_shared_bo;
  102. uint64_t asd_shared_mc_addr;
  103. void *asd_shared_buf;
  104. /* fence buffer */
  105. struct amdgpu_bo *fence_buf_bo;
  106. uint64_t fence_buf_mc_addr;
  107. void *fence_buf;
  108. /* cmd buffer */
  109. struct amdgpu_bo *cmd_buf_bo;
  110. uint64_t cmd_buf_mc_addr;
  111. struct psp_gfx_cmd_resp *cmd_buf_mem;
  112. };
  113. struct amdgpu_psp_funcs {
  114. bool (*check_fw_loading_status)(struct amdgpu_device *adev,
  115. enum AMDGPU_UCODE_ID);
  116. };
  117. #define psp_prep_cmd_buf(ucode, type) (psp)->funcs->prep_cmd_buf((ucode), (type))
  118. #define psp_ring_init(psp, type) (psp)->funcs->ring_init((psp), (type))
  119. #define psp_ring_create(psp, type) (psp)->funcs->ring_create((psp), (type))
  120. #define psp_ring_stop(psp, type) (psp)->funcs->ring_stop((psp), (type))
  121. #define psp_ring_destroy(psp, type) ((psp)->funcs->ring_destroy((psp), (type)))
  122. #define psp_cmd_submit(psp, ucode, cmd_mc, fence_mc, index) \
  123. (psp)->funcs->cmd_submit((psp), (ucode), (cmd_mc), (fence_mc), (index))
  124. #define psp_compare_sram_data(psp, ucode, type) \
  125. (psp)->funcs->compare_sram_data((psp), (ucode), (type))
  126. #define psp_init_microcode(psp) \
  127. ((psp)->funcs->init_microcode ? (psp)->funcs->init_microcode((psp)) : 0)
  128. #define psp_bootloader_load_sysdrv(psp) \
  129. ((psp)->funcs->bootloader_load_sysdrv ? (psp)->funcs->bootloader_load_sysdrv((psp)) : 0)
  130. #define psp_bootloader_load_sos(psp) \
  131. ((psp)->funcs->bootloader_load_sos ? (psp)->funcs->bootloader_load_sos((psp)) : 0)
  132. #define psp_smu_reload_quirk(psp) \
  133. ((psp)->funcs->smu_reload_quirk ? (psp)->funcs->smu_reload_quirk((psp)) : false)
  134. #define psp_mode1_reset(psp) \
  135. ((psp)->funcs->mode1_reset ? (psp)->funcs->mode1_reset((psp)) : false)
  136. extern const struct amd_ip_funcs psp_ip_funcs;
  137. extern const struct amdgpu_ip_block_version psp_v3_1_ip_block;
  138. extern int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
  139. uint32_t field_val, uint32_t mask, bool check_changed);
  140. extern const struct amdgpu_ip_block_version psp_v10_0_ip_block;
  141. int psp_gpu_reset(struct amdgpu_device *adev);
  142. #endif