intel_uc_fw.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright © 2014-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. #ifndef _INTEL_UC_FW_H_
  25. #define _INTEL_UC_FW_H_
  26. struct drm_printer;
  27. struct drm_i915_private;
  28. struct i915_vma;
  29. /* Home of GuC, HuC and DMC firmwares */
  30. #define INTEL_UC_FIRMWARE_URL "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915"
  31. enum intel_uc_fw_status {
  32. INTEL_UC_FIRMWARE_FAIL = -1,
  33. INTEL_UC_FIRMWARE_NONE = 0,
  34. INTEL_UC_FIRMWARE_PENDING,
  35. INTEL_UC_FIRMWARE_SUCCESS
  36. };
  37. enum intel_uc_fw_type {
  38. INTEL_UC_FW_TYPE_GUC,
  39. INTEL_UC_FW_TYPE_HUC
  40. };
  41. /*
  42. * This structure encapsulates all the data needed during the process
  43. * of fetching, caching, and loading the firmware image into the uC.
  44. */
  45. struct intel_uc_fw {
  46. const char *path;
  47. size_t size;
  48. struct drm_i915_gem_object *obj;
  49. enum intel_uc_fw_status fetch_status;
  50. enum intel_uc_fw_status load_status;
  51. /*
  52. * The firmware build process will generate a version header file with major and
  53. * minor version defined. The versions are built into CSS header of firmware.
  54. * i915 kernel driver set the minimal firmware version required per platform.
  55. */
  56. u16 major_ver_wanted;
  57. u16 minor_ver_wanted;
  58. u16 major_ver_found;
  59. u16 minor_ver_found;
  60. enum intel_uc_fw_type type;
  61. u32 header_size;
  62. u32 header_offset;
  63. u32 rsa_size;
  64. u32 rsa_offset;
  65. u32 ucode_size;
  66. u32 ucode_offset;
  67. };
  68. static inline
  69. const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
  70. {
  71. switch (status) {
  72. case INTEL_UC_FIRMWARE_FAIL:
  73. return "FAIL";
  74. case INTEL_UC_FIRMWARE_NONE:
  75. return "NONE";
  76. case INTEL_UC_FIRMWARE_PENDING:
  77. return "PENDING";
  78. case INTEL_UC_FIRMWARE_SUCCESS:
  79. return "SUCCESS";
  80. }
  81. return "<invalid>";
  82. }
  83. static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type)
  84. {
  85. switch (type) {
  86. case INTEL_UC_FW_TYPE_GUC:
  87. return "GuC";
  88. case INTEL_UC_FW_TYPE_HUC:
  89. return "HuC";
  90. }
  91. return "uC";
  92. }
  93. static inline
  94. void intel_uc_fw_init(struct intel_uc_fw *uc_fw, enum intel_uc_fw_type type)
  95. {
  96. uc_fw->path = NULL;
  97. uc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
  98. uc_fw->load_status = INTEL_UC_FIRMWARE_NONE;
  99. uc_fw->type = type;
  100. }
  101. static inline bool intel_uc_fw_is_selected(struct intel_uc_fw *uc_fw)
  102. {
  103. return uc_fw->path != NULL;
  104. }
  105. static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw)
  106. {
  107. if (uc_fw->load_status == INTEL_UC_FIRMWARE_SUCCESS)
  108. uc_fw->load_status = INTEL_UC_FIRMWARE_PENDING;
  109. }
  110. /**
  111. * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
  112. * @uc_fw: uC firmware.
  113. *
  114. * Get the size of the firmware and header that will be uploaded to WOPCM.
  115. *
  116. * Return: Upload firmware size, or zero on firmware fetch failure.
  117. */
  118. static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
  119. {
  120. if (uc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
  121. return 0;
  122. return uc_fw->header_size + uc_fw->ucode_size;
  123. }
  124. void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
  125. struct intel_uc_fw *uc_fw);
  126. int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
  127. int (*xfer)(struct intel_uc_fw *uc_fw,
  128. struct i915_vma *vma));
  129. void intel_uc_fw_fini(struct intel_uc_fw *uc_fw);
  130. void intel_uc_fw_dump(const struct intel_uc_fw *uc_fw, struct drm_printer *p);
  131. #endif