intel_huc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright © 2016-2017 Intel Corporation
  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 (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. */
  24. #include <linux/types.h>
  25. #include "intel_huc.h"
  26. #include "i915_drv.h"
  27. void intel_huc_init_early(struct intel_huc *huc)
  28. {
  29. intel_huc_fw_init_early(huc);
  30. }
  31. int intel_huc_init_misc(struct intel_huc *huc)
  32. {
  33. struct drm_i915_private *i915 = huc_to_i915(huc);
  34. intel_uc_fw_fetch(i915, &huc->fw);
  35. return 0;
  36. }
  37. /**
  38. * intel_huc_auth() - Authenticate HuC uCode
  39. * @huc: intel_huc structure
  40. *
  41. * Called after HuC and GuC firmware loading during intel_uc_init_hw().
  42. *
  43. * This function pins HuC firmware image object into GGTT.
  44. * Then it invokes GuC action to authenticate passing the offset to RSA
  45. * signature through intel_guc_auth_huc(). It then waits for 50ms for
  46. * firmware verification ACK and unpins the object.
  47. */
  48. int intel_huc_auth(struct intel_huc *huc)
  49. {
  50. struct drm_i915_private *i915 = huc_to_i915(huc);
  51. struct intel_guc *guc = &i915->guc;
  52. struct i915_vma *vma;
  53. u32 status;
  54. int ret;
  55. if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
  56. return -ENOEXEC;
  57. vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
  58. PIN_OFFSET_BIAS | guc->ggtt_pin_bias);
  59. if (IS_ERR(vma)) {
  60. ret = PTR_ERR(vma);
  61. DRM_ERROR("HuC: Failed to pin huc fw object %d\n", ret);
  62. goto fail;
  63. }
  64. ret = intel_guc_auth_huc(guc,
  65. intel_guc_ggtt_offset(guc, vma) +
  66. huc->fw.rsa_offset);
  67. if (ret) {
  68. DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
  69. goto fail_unpin;
  70. }
  71. /* Check authentication status, it should be done by now */
  72. ret = __intel_wait_for_register(i915,
  73. HUC_STATUS2,
  74. HUC_FW_VERIFIED,
  75. HUC_FW_VERIFIED,
  76. 2, 50, &status);
  77. if (ret) {
  78. DRM_ERROR("HuC: Firmware not verified %#x\n", status);
  79. goto fail_unpin;
  80. }
  81. i915_vma_unpin(vma);
  82. return 0;
  83. fail_unpin:
  84. i915_vma_unpin(vma);
  85. fail:
  86. huc->fw.load_status = INTEL_UC_FIRMWARE_FAIL;
  87. DRM_ERROR("HuC: Authentication failed %d\n", ret);
  88. return ret;
  89. }
  90. /**
  91. * intel_huc_check_status() - check HuC status
  92. * @huc: intel_huc structure
  93. *
  94. * This function reads status register to verify if HuC
  95. * firmware was successfully loaded.
  96. *
  97. * Returns positive value if HuC firmware is loaded and verified
  98. * and -ENODEV if HuC is not present.
  99. */
  100. int intel_huc_check_status(struct intel_huc *huc)
  101. {
  102. struct drm_i915_private *dev_priv = huc_to_i915(huc);
  103. u32 status;
  104. if (!HAS_HUC(dev_priv))
  105. return -ENODEV;
  106. intel_runtime_pm_get(dev_priv);
  107. status = I915_READ(HUC_STATUS2) & HUC_FW_VERIFIED;
  108. intel_runtime_pm_put(dev_priv);
  109. return status;
  110. }