blob: 8be3bfeb58dd5f41577da4809ee9886da33618bf [file] [log] [blame]
Anusha Srivatsabd132852017-01-18 08:05:53 -08001/*
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 */
Michal Wajdeczkoead92ed2017-10-06 09:02:09 +000024
25#include <linux/types.h>
26
27#include "intel_huc.h"
Anusha Srivatsabd132852017-01-18 08:05:53 -080028#include "i915_drv.h"
Anusha Srivatsabd132852017-01-18 08:05:53 -080029
30/**
31 * DOC: HuC Firmware
32 *
33 * Motivation:
34 * GEN9 introduces a new dedicated firmware for usage in media HEVC (High
35 * Efficiency Video Coding) operations. Userspace can use the firmware
36 * capabilities by adding HuC specific commands to batch buffers.
37 *
38 * Implementation:
39 * The same firmware loader is used as the GuC. However, the actual
40 * loading to HW is deferred until GEM initialization is done.
41 *
42 * Note that HuC firmware loading must be done before GuC loading.
43 */
44
Anusha Srivatsacd690982017-01-18 08:05:54 -080045#define BXT_HUC_FW_MAJOR 01
46#define BXT_HUC_FW_MINOR 07
47#define BXT_BLD_NUM 1398
48
Anusha Srivatsabd132852017-01-18 08:05:53 -080049#define SKL_HUC_FW_MAJOR 01
50#define SKL_HUC_FW_MINOR 07
51#define SKL_BLD_NUM 1398
52
Anusha Srivatsaf2ec71d2017-01-18 08:05:55 -080053#define KBL_HUC_FW_MAJOR 02
54#define KBL_HUC_FW_MINOR 00
55#define KBL_BLD_NUM 1810
56
Anusha Srivatsadbc26ebd2017-05-18 10:47:11 -070057#define GLK_HUC_FW_MAJOR 02
58#define GLK_HUC_FW_MINOR 00
Anusha Srivatsadb5ba0d2017-03-30 13:24:07 -070059#define GLK_BLD_NUM 1748
60
Anusha Srivatsabd132852017-01-18 08:05:53 -080061#define HUC_FW_PATH(platform, major, minor, bld_num) \
62 "i915/" __stringify(platform) "_huc_ver" __stringify(major) "_" \
63 __stringify(minor) "_" __stringify(bld_num) ".bin"
64
65#define I915_SKL_HUC_UCODE HUC_FW_PATH(skl, SKL_HUC_FW_MAJOR, \
66 SKL_HUC_FW_MINOR, SKL_BLD_NUM)
67MODULE_FIRMWARE(I915_SKL_HUC_UCODE);
68
Anusha Srivatsacd690982017-01-18 08:05:54 -080069#define I915_BXT_HUC_UCODE HUC_FW_PATH(bxt, BXT_HUC_FW_MAJOR, \
70 BXT_HUC_FW_MINOR, BXT_BLD_NUM)
71MODULE_FIRMWARE(I915_BXT_HUC_UCODE);
Anusha Srivatsaf2ec71d2017-01-18 08:05:55 -080072
73#define I915_KBL_HUC_UCODE HUC_FW_PATH(kbl, KBL_HUC_FW_MAJOR, \
74 KBL_HUC_FW_MINOR, KBL_BLD_NUM)
75MODULE_FIRMWARE(I915_KBL_HUC_UCODE);
76
Anusha Srivatsadb5ba0d2017-03-30 13:24:07 -070077#define I915_GLK_HUC_UCODE HUC_FW_PATH(glk, GLK_HUC_FW_MAJOR, \
78 GLK_HUC_FW_MINOR, GLK_BLD_NUM)
79
Anusha Srivatsabd132852017-01-18 08:05:53 -080080/**
81 * huc_ucode_xfer() - DMA's the firmware
82 * @dev_priv: the drm_i915_private device
83 *
84 * Transfer the firmware image to RAM for execution by the microcontroller.
85 *
86 * Return: 0 on success, non-zero on failure
87 */
Michal Wajdeczko4502e9e2017-10-16 14:47:21 +000088static int huc_ucode_xfer(struct intel_uc_fw *huc_fw, struct i915_vma *vma)
Anusha Srivatsabd132852017-01-18 08:05:53 -080089{
Michal Wajdeczko4502e9e2017-10-16 14:47:21 +000090 struct intel_huc *huc = container_of(huc_fw, struct intel_huc, fw);
91 struct drm_i915_private *dev_priv = huc_to_i915(huc);
Anusha Srivatsabd132852017-01-18 08:05:53 -080092 unsigned long offset = 0;
93 u32 size;
94 int ret;
95
Michal Wajdeczko4502e9e2017-10-16 14:47:21 +000096 GEM_BUG_ON(huc_fw->type != INTEL_UC_FW_TYPE_HUC);
Anusha Srivatsabd132852017-01-18 08:05:53 -080097
98 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
99
Anusha Srivatsabd132852017-01-18 08:05:53 -0800100 /* Set the source address for the uCode */
101 offset = guc_ggtt_offset(vma) + huc_fw->header_offset;
102 I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset));
103 I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF);
104
105 /* Hardware doesn't look at destination address for HuC. Set it to 0,
106 * but still program the correct address space.
107 */
108 I915_WRITE(DMA_ADDR_1_LOW, 0);
109 I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM);
110
111 size = huc_fw->header_size + huc_fw->ucode_size;
112 I915_WRITE(DMA_COPY_SIZE, size);
113
114 /* Start the DMA */
115 I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(HUC_UKERNEL | START_DMA));
116
117 /* Wait for DMA to finish */
118 ret = wait_for((I915_READ(DMA_CTRL) & START_DMA) == 0, 100);
119
120 DRM_DEBUG_DRIVER("HuC DMA transfer wait over with ret %d\n", ret);
121
122 /* Disable the bits once DMA is over */
123 I915_WRITE(DMA_CTRL, _MASKED_BIT_DISABLE(HUC_UKERNEL));
124
125 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
126
Anusha Srivatsabd132852017-01-18 08:05:53 -0800127 return ret;
128}
129
130/**
Arkadiusz Hilerb551f612017-03-14 15:28:13 +0100131 * intel_huc_select_fw() - selects HuC firmware for loading
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100132 * @huc: intel_huc struct
Anusha Srivatsabd132852017-01-18 08:05:53 -0800133 */
Arkadiusz Hilerb551f612017-03-14 15:28:13 +0100134void intel_huc_select_fw(struct intel_huc *huc)
Anusha Srivatsabd132852017-01-18 08:05:53 -0800135{
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100136 struct drm_i915_private *dev_priv = huc_to_i915(huc);
Anusha Srivatsabd132852017-01-18 08:05:53 -0800137
Michal Wajdeczko959a3b62017-10-04 18:13:43 +0000138 intel_uc_fw_init(&huc->fw, INTEL_UC_FW_TYPE_HUC);
Anusha Srivatsabd132852017-01-18 08:05:53 -0800139
Michal Wajdeczko4f044a82017-09-19 19:38:44 +0000140 if (i915_modparams.huc_firmware_path) {
141 huc->fw.path = i915_modparams.huc_firmware_path;
Arkadiusz Hilerb3420dd2017-03-14 15:28:14 +0100142 huc->fw.major_ver_wanted = 0;
143 huc->fw.minor_ver_wanted = 0;
144 } else if (IS_SKYLAKE(dev_priv)) {
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100145 huc->fw.path = I915_SKL_HUC_UCODE;
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100146 huc->fw.major_ver_wanted = SKL_HUC_FW_MAJOR;
147 huc->fw.minor_ver_wanted = SKL_HUC_FW_MINOR;
Anusha Srivatsacd690982017-01-18 08:05:54 -0800148 } else if (IS_BROXTON(dev_priv)) {
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100149 huc->fw.path = I915_BXT_HUC_UCODE;
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100150 huc->fw.major_ver_wanted = BXT_HUC_FW_MAJOR;
151 huc->fw.minor_ver_wanted = BXT_HUC_FW_MINOR;
Anusha Srivatsa5e5d8b62017-06-08 16:48:24 -0700152 } else if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100153 huc->fw.path = I915_KBL_HUC_UCODE;
Arkadiusz Hiler29ad6a32017-03-14 15:28:09 +0100154 huc->fw.major_ver_wanted = KBL_HUC_FW_MAJOR;
155 huc->fw.minor_ver_wanted = KBL_HUC_FW_MINOR;
Anusha Srivatsadb5ba0d2017-03-30 13:24:07 -0700156 } else if (IS_GEMINILAKE(dev_priv)) {
157 huc->fw.path = I915_GLK_HUC_UCODE;
158 huc->fw.major_ver_wanted = GLK_HUC_FW_MAJOR;
159 huc->fw.minor_ver_wanted = GLK_HUC_FW_MINOR;
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100160 } else {
161 DRM_ERROR("No HuC firmware known for platform with HuC!\n");
Anusha Srivatsa13e867f2017-03-01 11:58:55 -0800162 return;
Arkadiusz Hiler8fc2a4e2017-03-14 15:28:12 +0100163 }
Anusha Srivatsabd132852017-01-18 08:05:53 -0800164}
165
166/**
Arkadiusz Hiler882d1db2017-03-14 15:28:07 +0100167 * intel_huc_init_hw() - load HuC uCode to device
168 * @huc: intel_huc structure
Anusha Srivatsabd132852017-01-18 08:05:53 -0800169 *
170 * Called from guc_setup() during driver loading and also after a GPU reset.
171 * Be note that HuC loading must be done before GuC loading.
172 *
173 * The firmware image should have already been fetched into memory by the
174 * earlier call to intel_huc_init(), so here we need only check that
175 * is succeeded, and then transfer the image to the h/w.
176 *
Anusha Srivatsabd132852017-01-18 08:05:53 -0800177 */
Michal Wajdeczko01a9ca02017-03-31 11:57:09 +0000178void intel_huc_init_hw(struct intel_huc *huc)
Anusha Srivatsabd132852017-01-18 08:05:53 -0800179{
Michal Wajdeczko4502e9e2017-10-16 14:47:21 +0000180 intel_uc_fw_upload(&huc->fw, huc_ucode_xfer);
Anusha Srivatsabd132852017-01-18 08:05:53 -0800181}
182
183/**
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +0530184 * intel_huc_auth() - Authenticate HuC uCode
185 * @huc: intel_huc structure
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800186 *
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +0530187 * Called after HuC and GuC firmware loading during intel_uc_init_hw().
188 *
189 * This function pins HuC firmware image object into GGTT.
190 * Then it invokes GuC action to authenticate passing the offset to RSA
191 * signature through intel_guc_auth_huc(). It then waits for 50ms for
192 * firmware verification ACK and unpins the object.
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800193 */
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +0530194void intel_huc_auth(struct intel_huc *huc)
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800195{
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +0530196 struct drm_i915_private *i915 = huc_to_i915(huc);
197 struct intel_guc *guc = &i915->guc;
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800198 struct i915_vma *vma;
199 int ret;
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800200
Michał Winiarski7e8d12b2017-01-20 20:23:46 +0100201 if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
202 return;
203
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800204 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
205 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
206 if (IS_ERR(vma)) {
207 DRM_ERROR("failed to pin huc fw object %d\n",
208 (int)PTR_ERR(vma));
209 return;
210 }
211
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +0530212 ret = intel_guc_auth_huc(guc,
213 guc_ggtt_offset(vma) + huc->fw.rsa_offset);
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800214 if (ret) {
215 DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
216 goto out;
217 }
218
219 /* Check authentication status, it should be done by now */
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +0530220 ret = intel_wait_for_register(i915,
221 HUC_STATUS2,
222 HUC_FW_VERIFIED,
223 HUC_FW_VERIFIED,
224 50);
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800225 if (ret) {
226 DRM_ERROR("HuC: Authentication failed %d\n", ret);
227 goto out;
228 }
229
230out:
231 i915_vma_unpin(vma);
232}