intel_huc_fw.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * SPDX-License-Identifier: MIT
  3. *
  4. * Copyright © 2014-2018 Intel Corporation
  5. */
  6. #include "intel_huc_fw.h"
  7. #include "i915_drv.h"
  8. /**
  9. * DOC: HuC Firmware
  10. *
  11. * Motivation:
  12. * GEN9 introduces a new dedicated firmware for usage in media HEVC (High
  13. * Efficiency Video Coding) operations. Userspace can use the firmware
  14. * capabilities by adding HuC specific commands to batch buffers.
  15. *
  16. * Implementation:
  17. * The same firmware loader is used as the GuC. However, the actual
  18. * loading to HW is deferred until GEM initialization is done.
  19. *
  20. * Note that HuC firmware loading must be done before GuC loading.
  21. */
  22. #define BXT_HUC_FW_MAJOR 01
  23. #define BXT_HUC_FW_MINOR 07
  24. #define BXT_BLD_NUM 1398
  25. #define SKL_HUC_FW_MAJOR 01
  26. #define SKL_HUC_FW_MINOR 07
  27. #define SKL_BLD_NUM 1398
  28. #define KBL_HUC_FW_MAJOR 02
  29. #define KBL_HUC_FW_MINOR 00
  30. #define KBL_BLD_NUM 1810
  31. #define HUC_FW_PATH(platform, major, minor, bld_num) \
  32. "i915/" __stringify(platform) "_huc_ver" __stringify(major) "_" \
  33. __stringify(minor) "_" __stringify(bld_num) ".bin"
  34. #define I915_SKL_HUC_UCODE HUC_FW_PATH(skl, SKL_HUC_FW_MAJOR, \
  35. SKL_HUC_FW_MINOR, SKL_BLD_NUM)
  36. MODULE_FIRMWARE(I915_SKL_HUC_UCODE);
  37. #define I915_BXT_HUC_UCODE HUC_FW_PATH(bxt, BXT_HUC_FW_MAJOR, \
  38. BXT_HUC_FW_MINOR, BXT_BLD_NUM)
  39. MODULE_FIRMWARE(I915_BXT_HUC_UCODE);
  40. #define I915_KBL_HUC_UCODE HUC_FW_PATH(kbl, KBL_HUC_FW_MAJOR, \
  41. KBL_HUC_FW_MINOR, KBL_BLD_NUM)
  42. MODULE_FIRMWARE(I915_KBL_HUC_UCODE);
  43. static void huc_fw_select(struct intel_uc_fw *huc_fw)
  44. {
  45. struct intel_huc *huc = container_of(huc_fw, struct intel_huc, fw);
  46. struct drm_i915_private *dev_priv = huc_to_i915(huc);
  47. GEM_BUG_ON(huc_fw->type != INTEL_UC_FW_TYPE_HUC);
  48. if (!HAS_HUC(dev_priv))
  49. return;
  50. if (i915_modparams.huc_firmware_path) {
  51. huc_fw->path = i915_modparams.huc_firmware_path;
  52. huc_fw->major_ver_wanted = 0;
  53. huc_fw->minor_ver_wanted = 0;
  54. } else if (IS_SKYLAKE(dev_priv)) {
  55. huc_fw->path = I915_SKL_HUC_UCODE;
  56. huc_fw->major_ver_wanted = SKL_HUC_FW_MAJOR;
  57. huc_fw->minor_ver_wanted = SKL_HUC_FW_MINOR;
  58. } else if (IS_BROXTON(dev_priv)) {
  59. huc_fw->path = I915_BXT_HUC_UCODE;
  60. huc_fw->major_ver_wanted = BXT_HUC_FW_MAJOR;
  61. huc_fw->minor_ver_wanted = BXT_HUC_FW_MINOR;
  62. } else if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
  63. huc_fw->path = I915_KBL_HUC_UCODE;
  64. huc_fw->major_ver_wanted = KBL_HUC_FW_MAJOR;
  65. huc_fw->minor_ver_wanted = KBL_HUC_FW_MINOR;
  66. } else {
  67. DRM_WARN("%s: No firmware known for this platform!\n",
  68. intel_uc_fw_type_repr(huc_fw->type));
  69. }
  70. }
  71. /**
  72. * intel_huc_fw_init_early() - initializes HuC firmware struct
  73. * @huc: intel_huc struct
  74. *
  75. * On platforms with HuC selects firmware for uploading
  76. */
  77. void intel_huc_fw_init_early(struct intel_huc *huc)
  78. {
  79. struct intel_uc_fw *huc_fw = &huc->fw;
  80. intel_uc_fw_init(huc_fw, INTEL_UC_FW_TYPE_HUC);
  81. huc_fw_select(huc_fw);
  82. }
  83. /**
  84. * huc_fw_xfer() - DMA's the firmware
  85. * @huc_fw: the firmware descriptor
  86. * @vma: the firmware image (bound into the GGTT)
  87. *
  88. * Transfer the firmware image to RAM for execution by the microcontroller.
  89. *
  90. * Return: 0 on success, non-zero on failure
  91. */
  92. static int huc_fw_xfer(struct intel_uc_fw *huc_fw, struct i915_vma *vma)
  93. {
  94. struct intel_huc *huc = container_of(huc_fw, struct intel_huc, fw);
  95. struct drm_i915_private *dev_priv = huc_to_i915(huc);
  96. unsigned long offset = 0;
  97. u32 size;
  98. int ret;
  99. GEM_BUG_ON(huc_fw->type != INTEL_UC_FW_TYPE_HUC);
  100. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  101. /* Set the source address for the uCode */
  102. offset = intel_guc_ggtt_offset(&dev_priv->guc, vma) +
  103. huc_fw->header_offset;
  104. I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset));
  105. I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF);
  106. /* Hardware doesn't look at destination address for HuC. Set it to 0,
  107. * but still program the correct address space.
  108. */
  109. I915_WRITE(DMA_ADDR_1_LOW, 0);
  110. I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM);
  111. size = huc_fw->header_size + huc_fw->ucode_size;
  112. I915_WRITE(DMA_COPY_SIZE, size);
  113. /* Start the DMA */
  114. I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(HUC_UKERNEL | START_DMA));
  115. /* Wait for DMA to finish */
  116. ret = intel_wait_for_register_fw(dev_priv, DMA_CTRL, START_DMA, 0, 100);
  117. DRM_DEBUG_DRIVER("HuC DMA transfer wait over with ret %d\n", ret);
  118. /* Disable the bits once DMA is over */
  119. I915_WRITE(DMA_CTRL, _MASKED_BIT_DISABLE(HUC_UKERNEL));
  120. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  121. return ret;
  122. }
  123. /**
  124. * intel_huc_fw_upload() - load HuC uCode to device
  125. * @huc: intel_huc structure
  126. *
  127. * Called from intel_uc_init_hw() during driver load, resume from sleep and
  128. * after a GPU reset. Note that HuC must be loaded before GuC.
  129. *
  130. * The firmware image should have already been fetched into memory, so only
  131. * check that fetch succeeded, and then transfer the image to the h/w.
  132. *
  133. * Return: non-zero code on error
  134. */
  135. int intel_huc_fw_upload(struct intel_huc *huc)
  136. {
  137. return intel_uc_fw_upload(&huc->fw, huc_fw_xfer);
  138. }