amdgpu_atomfirmware.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. */
  23. #include <drm/drmP.h>
  24. #include <drm/amdgpu_drm.h>
  25. #include "amdgpu.h"
  26. #include "atomfirmware.h"
  27. #include "amdgpu_atomfirmware.h"
  28. #include "atom.h"
  29. #include "atombios.h"
  30. #define get_index_into_master_table(master_table, table_name) (offsetof(struct master_table, table_name) / sizeof(uint16_t))
  31. bool amdgpu_atomfirmware_gpu_supports_virtualization(struct amdgpu_device *adev)
  32. {
  33. int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  34. firmwareinfo);
  35. uint16_t data_offset;
  36. if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, NULL,
  37. NULL, NULL, &data_offset)) {
  38. struct atom_firmware_info_v3_1 *firmware_info =
  39. (struct atom_firmware_info_v3_1 *)(adev->mode_info.atom_context->bios +
  40. data_offset);
  41. if (le32_to_cpu(firmware_info->firmware_capability) &
  42. ATOM_FIRMWARE_CAP_GPU_VIRTUALIZATION)
  43. return true;
  44. }
  45. return false;
  46. }
  47. void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev)
  48. {
  49. int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  50. firmwareinfo);
  51. uint16_t data_offset;
  52. if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, NULL,
  53. NULL, NULL, &data_offset)) {
  54. struct atom_firmware_info_v3_1 *firmware_info =
  55. (struct atom_firmware_info_v3_1 *)(adev->mode_info.atom_context->bios +
  56. data_offset);
  57. adev->bios_scratch_reg_offset =
  58. le32_to_cpu(firmware_info->bios_scratch_reg_startaddr);
  59. }
  60. }
  61. int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev)
  62. {
  63. struct atom_context *ctx = adev->mode_info.atom_context;
  64. int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  65. vram_usagebyfirmware);
  66. uint16_t data_offset;
  67. int usage_bytes = 0;
  68. if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
  69. struct vram_usagebyfirmware_v2_1 *firmware_usage =
  70. (struct vram_usagebyfirmware_v2_1 *)(ctx->bios + data_offset);
  71. DRM_DEBUG("atom firmware requested %08x %dkb fw %dkb drv\n",
  72. le32_to_cpu(firmware_usage->start_address_in_kb),
  73. le16_to_cpu(firmware_usage->used_by_firmware_in_kb),
  74. le16_to_cpu(firmware_usage->used_by_driver_in_kb));
  75. usage_bytes = le16_to_cpu(firmware_usage->used_by_driver_in_kb) * 1024;
  76. }
  77. ctx->scratch_size_bytes = 0;
  78. if (usage_bytes == 0)
  79. usage_bytes = 20 * 1024;
  80. /* allocate some scratch memory */
  81. ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL);
  82. if (!ctx->scratch)
  83. return -ENOMEM;
  84. ctx->scratch_size_bytes = usage_bytes;
  85. return 0;
  86. }
  87. union igp_info {
  88. struct atom_integrated_system_info_v1_11 v11;
  89. };
  90. /*
  91. * Return vram width from integrated system info table, if available,
  92. * or 0 if not.
  93. */
  94. int amdgpu_atomfirmware_get_vram_width(struct amdgpu_device *adev)
  95. {
  96. struct amdgpu_mode_info *mode_info = &adev->mode_info;
  97. int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  98. integratedsysteminfo);
  99. u16 data_offset, size;
  100. union igp_info *igp_info;
  101. u8 frev, crev;
  102. /* get any igp specific overrides */
  103. if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, &size,
  104. &frev, &crev, &data_offset)) {
  105. igp_info = (union igp_info *)
  106. (mode_info->atom_context->bios + data_offset);
  107. switch (crev) {
  108. case 11:
  109. return igp_info->v11.umachannelnumber * 64;
  110. default:
  111. return 0;
  112. }
  113. }
  114. return 0;
  115. }
  116. union firmware_info {
  117. struct atom_firmware_info_v3_1 v31;
  118. };
  119. union smu_info {
  120. struct atom_smu_info_v3_1 v31;
  121. };
  122. union umc_info {
  123. struct atom_umc_info_v3_1 v31;
  124. };
  125. int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev)
  126. {
  127. struct amdgpu_mode_info *mode_info = &adev->mode_info;
  128. struct amdgpu_pll *spll = &adev->clock.spll;
  129. struct amdgpu_pll *mpll = &adev->clock.mpll;
  130. uint8_t frev, crev;
  131. uint16_t data_offset;
  132. int ret = -EINVAL, index;
  133. index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  134. firmwareinfo);
  135. if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
  136. &frev, &crev, &data_offset)) {
  137. union firmware_info *firmware_info =
  138. (union firmware_info *)(mode_info->atom_context->bios +
  139. data_offset);
  140. adev->clock.default_sclk =
  141. le32_to_cpu(firmware_info->v31.bootup_sclk_in10khz);
  142. adev->clock.default_mclk =
  143. le32_to_cpu(firmware_info->v31.bootup_mclk_in10khz);
  144. adev->pm.current_sclk = adev->clock.default_sclk;
  145. adev->pm.current_mclk = adev->clock.default_mclk;
  146. /* not technically a clock, but... */
  147. adev->mode_info.firmware_flags =
  148. le32_to_cpu(firmware_info->v31.firmware_capability);
  149. ret = 0;
  150. }
  151. index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  152. smu_info);
  153. if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
  154. &frev, &crev, &data_offset)) {
  155. union smu_info *smu_info =
  156. (union smu_info *)(mode_info->atom_context->bios +
  157. data_offset);
  158. /* system clock */
  159. spll->reference_freq = le32_to_cpu(smu_info->v31.core_refclk_10khz);
  160. spll->reference_div = 0;
  161. spll->min_post_div = 1;
  162. spll->max_post_div = 1;
  163. spll->min_ref_div = 2;
  164. spll->max_ref_div = 0xff;
  165. spll->min_feedback_div = 4;
  166. spll->max_feedback_div = 0xff;
  167. spll->best_vco = 0;
  168. ret = 0;
  169. }
  170. index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  171. umc_info);
  172. if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
  173. &frev, &crev, &data_offset)) {
  174. union umc_info *umc_info =
  175. (union umc_info *)(mode_info->atom_context->bios +
  176. data_offset);
  177. /* memory clock */
  178. mpll->reference_freq = le32_to_cpu(umc_info->v31.mem_refclk_10khz);
  179. mpll->reference_div = 0;
  180. mpll->min_post_div = 1;
  181. mpll->max_post_div = 1;
  182. mpll->min_ref_div = 2;
  183. mpll->max_ref_div = 0xff;
  184. mpll->min_feedback_div = 4;
  185. mpll->max_feedback_div = 0xff;
  186. mpll->best_vco = 0;
  187. ret = 0;
  188. }
  189. return ret;
  190. }