2 * Copyright © 2016-2017 Intel Corporation
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:
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
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
24 #include <linux/firmware.h>
32 * GEN9 introduces a new dedicated firmware for usage in media HEVC (High
33 * Efficiency Video Coding) operations. Userspace can use the firmware
34 * capabilities by adding HuC specific commands to batch buffers.
37 * The same firmware loader is used as the GuC. However, the actual
38 * loading to HW is deferred until GEM initialization is done.
40 * Note that HuC firmware loading must be done before GuC loading.
43 #define BXT_HUC_FW_MAJOR 01
44 #define BXT_HUC_FW_MINOR 07
45 #define BXT_BLD_NUM 1398
47 #define SKL_HUC_FW_MAJOR 01
48 #define SKL_HUC_FW_MINOR 07
49 #define SKL_BLD_NUM 1398
51 #define KBL_HUC_FW_MAJOR 02
52 #define KBL_HUC_FW_MINOR 00
53 #define KBL_BLD_NUM 1810
55 #define GLK_HUC_FW_MAJOR 02
56 #define GLK_HUC_FW_MINOR 00
57 #define GLK_BLD_NUM 1748
59 #define HUC_FW_PATH(platform, major, minor, bld_num) \
60 "i915/" __stringify(platform) "_huc_ver" __stringify(major) "_" \
61 __stringify(minor) "_" __stringify(bld_num) ".bin"
63 #define I915_SKL_HUC_UCODE HUC_FW_PATH(skl, SKL_HUC_FW_MAJOR, \
64 SKL_HUC_FW_MINOR, SKL_BLD_NUM)
65 MODULE_FIRMWARE(I915_SKL_HUC_UCODE);
67 #define I915_BXT_HUC_UCODE HUC_FW_PATH(bxt, BXT_HUC_FW_MAJOR, \
68 BXT_HUC_FW_MINOR, BXT_BLD_NUM)
69 MODULE_FIRMWARE(I915_BXT_HUC_UCODE);
71 #define I915_KBL_HUC_UCODE HUC_FW_PATH(kbl, KBL_HUC_FW_MAJOR, \
72 KBL_HUC_FW_MINOR, KBL_BLD_NUM)
73 MODULE_FIRMWARE(I915_KBL_HUC_UCODE);
75 #define I915_GLK_HUC_UCODE HUC_FW_PATH(glk, GLK_HUC_FW_MAJOR, \
76 GLK_HUC_FW_MINOR, GLK_BLD_NUM)
79 * huc_ucode_xfer() - DMA's the firmware
80 * @dev_priv: the drm_i915_private device
82 * Transfer the firmware image to RAM for execution by the microcontroller.
84 * Return: 0 on success, non-zero on failure
86 static int huc_ucode_xfer(struct drm_i915_private *dev_priv)
88 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
90 unsigned long offset = 0;
94 ret = i915_gem_object_set_to_gtt_domain(huc_fw->obj, false);
96 DRM_DEBUG_DRIVER("set-domain failed %d\n", ret);
100 vma = i915_gem_object_ggtt_pin(huc_fw->obj, NULL, 0, 0,
101 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
103 DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma));
107 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
109 /* Set the source address for the uCode */
110 offset = guc_ggtt_offset(vma) + huc_fw->header_offset;
111 I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset));
112 I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF);
114 /* Hardware doesn't look at destination address for HuC. Set it to 0,
115 * but still program the correct address space.
117 I915_WRITE(DMA_ADDR_1_LOW, 0);
118 I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM);
120 size = huc_fw->header_size + huc_fw->ucode_size;
121 I915_WRITE(DMA_COPY_SIZE, size);
124 I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(HUC_UKERNEL | START_DMA));
126 /* Wait for DMA to finish */
127 ret = wait_for((I915_READ(DMA_CTRL) & START_DMA) == 0, 100);
129 DRM_DEBUG_DRIVER("HuC DMA transfer wait over with ret %d\n", ret);
131 /* Disable the bits once DMA is over */
132 I915_WRITE(DMA_CTRL, _MASKED_BIT_DISABLE(HUC_UKERNEL));
134 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
137 * We keep the object pages for reuse during resume. But we can unpin it
138 * now that DMA has completed, so it doesn't continue to take up space.
146 * intel_huc_select_fw() - selects HuC firmware for loading
147 * @huc: intel_huc struct
149 void intel_huc_select_fw(struct intel_huc *huc)
151 struct drm_i915_private *dev_priv = huc_to_i915(huc);
154 huc->fw.fetch_status = INTEL_UC_FIRMWARE_NONE;
155 huc->fw.load_status = INTEL_UC_FIRMWARE_NONE;
156 huc->fw.type = INTEL_UC_FW_TYPE_HUC;
158 if (i915.huc_firmware_path) {
159 huc->fw.path = i915.huc_firmware_path;
160 huc->fw.major_ver_wanted = 0;
161 huc->fw.minor_ver_wanted = 0;
162 } else if (IS_SKYLAKE(dev_priv)) {
163 huc->fw.path = I915_SKL_HUC_UCODE;
164 huc->fw.major_ver_wanted = SKL_HUC_FW_MAJOR;
165 huc->fw.minor_ver_wanted = SKL_HUC_FW_MINOR;
166 } else if (IS_BROXTON(dev_priv)) {
167 huc->fw.path = I915_BXT_HUC_UCODE;
168 huc->fw.major_ver_wanted = BXT_HUC_FW_MAJOR;
169 huc->fw.minor_ver_wanted = BXT_HUC_FW_MINOR;
170 } else if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
171 huc->fw.path = I915_KBL_HUC_UCODE;
172 huc->fw.major_ver_wanted = KBL_HUC_FW_MAJOR;
173 huc->fw.minor_ver_wanted = KBL_HUC_FW_MINOR;
174 } else if (IS_GEMINILAKE(dev_priv)) {
175 huc->fw.path = I915_GLK_HUC_UCODE;
176 huc->fw.major_ver_wanted = GLK_HUC_FW_MAJOR;
177 huc->fw.minor_ver_wanted = GLK_HUC_FW_MINOR;
179 DRM_ERROR("No HuC firmware known for platform with HuC!\n");
185 * intel_huc_init_hw() - load HuC uCode to device
186 * @huc: intel_huc structure
188 * Called from guc_setup() during driver loading and also after a GPU reset.
189 * Be note that HuC loading must be done before GuC loading.
191 * The firmware image should have already been fetched into memory by the
192 * earlier call to intel_huc_init(), so here we need only check that
193 * is succeeded, and then transfer the image to the h/w.
196 void intel_huc_init_hw(struct intel_huc *huc)
198 struct drm_i915_private *dev_priv = huc_to_i915(huc);
201 DRM_DEBUG_DRIVER("%s fw status: fetch %s, load %s\n",
203 intel_uc_fw_status_repr(huc->fw.fetch_status),
204 intel_uc_fw_status_repr(huc->fw.load_status));
206 if (huc->fw.fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
209 huc->fw.load_status = INTEL_UC_FIRMWARE_PENDING;
211 err = huc_ucode_xfer(dev_priv);
213 huc->fw.load_status = err ?
214 INTEL_UC_FIRMWARE_FAIL : INTEL_UC_FIRMWARE_SUCCESS;
216 DRM_DEBUG_DRIVER("%s fw status: fetch %s, load %s\n",
218 intel_uc_fw_status_repr(huc->fw.fetch_status),
219 intel_uc_fw_status_repr(huc->fw.load_status));
221 if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
222 DRM_ERROR("Failed to complete HuC uCode load with ret %d\n", err);
228 * intel_guc_auth_huc() - authenticate ucode
229 * @dev_priv: the drm_i915_device
231 * Triggers a HuC fw authentication request to the GuC via intel_guc_action_
232 * authenticate_huc interface.
234 void intel_guc_auth_huc(struct drm_i915_private *dev_priv)
236 struct intel_guc *guc = &dev_priv->guc;
237 struct intel_huc *huc = &dev_priv->huc;
238 struct i915_vma *vma;
242 if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
245 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
246 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
248 DRM_ERROR("failed to pin huc fw object %d\n",
253 /* Specify auth action and where public signature is. */
254 data[0] = INTEL_GUC_ACTION_AUTHENTICATE_HUC;
255 data[1] = guc_ggtt_offset(vma) + huc->fw.rsa_offset;
257 ret = intel_guc_send(guc, data, ARRAY_SIZE(data));
259 DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
263 /* Check authentication status, it should be done by now */
264 ret = intel_wait_for_register(dev_priv,
271 DRM_ERROR("HuC: Authentication failed %d\n", ret);