smu9_smumgr.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2018 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. #include "smumgr.h"
  24. #include "vega10_inc.h"
  25. #include "soc15_common.h"
  26. #include "pp_debug.h"
  27. /* MP Apertures */
  28. #define MP0_Public 0x03800000
  29. #define MP0_SRAM 0x03900000
  30. #define MP1_Public 0x03b00000
  31. #define MP1_SRAM 0x03c00004
  32. #define smnMP1_FIRMWARE_FLAGS 0x3010028
  33. bool smu9_is_smc_ram_running(struct pp_hwmgr *hwmgr)
  34. {
  35. struct amdgpu_device *adev = hwmgr->adev;
  36. uint32_t mp1_fw_flags;
  37. WREG32_SOC15(NBIF, 0, mmPCIE_INDEX2,
  38. (MP1_Public | (smnMP1_FIRMWARE_FLAGS & 0xffffffff)));
  39. mp1_fw_flags = RREG32_SOC15(NBIF, 0, mmPCIE_DATA2);
  40. if (mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK)
  41. return true;
  42. return false;
  43. }
  44. /*
  45. * Check if SMC has responded to previous message.
  46. *
  47. * @param smumgr the address of the powerplay hardware manager.
  48. * @return TRUE SMC has responded, FALSE otherwise.
  49. */
  50. static uint32_t smu9_wait_for_response(struct pp_hwmgr *hwmgr)
  51. {
  52. struct amdgpu_device *adev = hwmgr->adev;
  53. uint32_t reg;
  54. uint32_t ret;
  55. reg = SOC15_REG_OFFSET(MP1, 0, mmMP1_SMN_C2PMSG_90);
  56. ret = phm_wait_for_register_unequal(hwmgr, reg,
  57. 0, MP1_C2PMSG_90__CONTENT_MASK);
  58. if (ret)
  59. pr_err("No response from smu\n");
  60. return RREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90);
  61. }
  62. /*
  63. * Send a message to the SMC, and do not wait for its response.
  64. * @param smumgr the address of the powerplay hardware manager.
  65. * @param msg the message to send.
  66. * @return Always return 0.
  67. */
  68. static int smu9_send_msg_to_smc_without_waiting(struct pp_hwmgr *hwmgr,
  69. uint16_t msg)
  70. {
  71. struct amdgpu_device *adev = hwmgr->adev;
  72. WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_66, msg);
  73. return 0;
  74. }
  75. /*
  76. * Send a message to the SMC, and wait for its response.
  77. * @param hwmgr the address of the powerplay hardware manager.
  78. * @param msg the message to send.
  79. * @return Always return 0.
  80. */
  81. int smu9_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t msg)
  82. {
  83. struct amdgpu_device *adev = hwmgr->adev;
  84. uint32_t ret;
  85. smu9_wait_for_response(hwmgr);
  86. WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90, 0);
  87. smu9_send_msg_to_smc_without_waiting(hwmgr, msg);
  88. ret = smu9_wait_for_response(hwmgr);
  89. if (ret != 1)
  90. pr_err("Failed to send message: 0x%x, ret value: 0x%x\n", msg, ret);
  91. return 0;
  92. }
  93. /*
  94. * Send a message to the SMC with parameter
  95. * @param hwmgr: the address of the powerplay hardware manager.
  96. * @param msg: the message to send.
  97. * @param parameter: the parameter to send
  98. * @return Always return 0.
  99. */
  100. int smu9_send_msg_to_smc_with_parameter(struct pp_hwmgr *hwmgr,
  101. uint16_t msg, uint32_t parameter)
  102. {
  103. struct amdgpu_device *adev = hwmgr->adev;
  104. uint32_t ret;
  105. smu9_wait_for_response(hwmgr);
  106. WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90, 0);
  107. WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_82, parameter);
  108. smu9_send_msg_to_smc_without_waiting(hwmgr, msg);
  109. ret = smu9_wait_for_response(hwmgr);
  110. if (ret != 1)
  111. pr_err("Failed message: 0x%x, input parameter: 0x%x, error code: 0x%x\n", msg, parameter, ret);
  112. return 0;
  113. }
  114. uint32_t smu9_get_argument(struct pp_hwmgr *hwmgr)
  115. {
  116. struct amdgpu_device *adev = hwmgr->adev;
  117. return RREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_82);
  118. }