amdgpu_atomfirmware.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #define get_index_into_master_table(master_table, table_name) (offsetof(struct master_table, table_name) / sizeof(uint16_t))
  30. bool amdgpu_atomfirmware_gpu_supports_virtualization(struct amdgpu_device *adev)
  31. {
  32. int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  33. firmwareinfo);
  34. uint16_t data_offset;
  35. if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, NULL,
  36. NULL, NULL, &data_offset)) {
  37. struct atom_firmware_info_v3_1 *firmware_info =
  38. (struct atom_firmware_info_v3_1 *)(adev->mode_info.atom_context->bios +
  39. data_offset);
  40. if (le32_to_cpu(firmware_info->firmware_capability) &
  41. ATOM_FIRMWARE_CAP_GPU_VIRTUALIZATION)
  42. return true;
  43. }
  44. return false;
  45. }
  46. void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev)
  47. {
  48. int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  49. firmwareinfo);
  50. uint16_t data_offset;
  51. if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, NULL,
  52. NULL, NULL, &data_offset)) {
  53. struct atom_firmware_info_v3_1 *firmware_info =
  54. (struct atom_firmware_info_v3_1 *)(adev->mode_info.atom_context->bios +
  55. data_offset);
  56. adev->bios_scratch_reg_offset =
  57. le32_to_cpu(firmware_info->bios_scratch_reg_startaddr);
  58. }
  59. }
  60. void amdgpu_atomfirmware_scratch_regs_save(struct amdgpu_device *adev)
  61. {
  62. int i;
  63. for (i = 0; i < AMDGPU_BIOS_NUM_SCRATCH; i++)
  64. adev->bios_scratch[i] = RREG32(adev->bios_scratch_reg_offset + i);
  65. }
  66. void amdgpu_atomfirmware_scratch_regs_restore(struct amdgpu_device *adev)
  67. {
  68. int i;
  69. for (i = 0; i < AMDGPU_BIOS_NUM_SCRATCH; i++)
  70. WREG32(adev->bios_scratch_reg_offset + i, adev->bios_scratch[i]);
  71. }
  72. int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev)
  73. {
  74. struct atom_context *ctx = adev->mode_info.atom_context;
  75. int index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
  76. vram_usagebyfirmware);
  77. uint16_t data_offset;
  78. int usage_bytes = 0;
  79. if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
  80. struct vram_usagebyfirmware_v2_1 *firmware_usage =
  81. (struct vram_usagebyfirmware_v2_1 *)(ctx->bios + data_offset);
  82. DRM_DEBUG("atom firmware requested %08x %dkb fw %dkb drv\n",
  83. le32_to_cpu(firmware_usage->start_address_in_kb),
  84. le16_to_cpu(firmware_usage->used_by_firmware_in_kb),
  85. le16_to_cpu(firmware_usage->used_by_driver_in_kb));
  86. usage_bytes = le16_to_cpu(firmware_usage->used_by_driver_in_kb) * 1024;
  87. }
  88. ctx->scratch_size_bytes = 0;
  89. if (usage_bytes == 0)
  90. usage_bytes = 20 * 1024;
  91. /* allocate some scratch memory */
  92. ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL);
  93. if (!ctx->scratch)
  94. return -ENOMEM;
  95. ctx->scratch_size_bytes = usage_bytes;
  96. return 0;
  97. }