Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 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 | */ |
Michal Wajdeczko | ead92ed | 2017-10-06 09:02:09 +0000 | [diff] [blame] | 24 | |
| 25 | #include <linux/types.h> |
| 26 | |
| 27 | #include "intel_huc.h" |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 28 | #include "i915_drv.h" |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 29 | |
| 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 Srivatsa | cd6909857 | 2017-01-18 08:05:54 -0800 | [diff] [blame] | 45 | #define BXT_HUC_FW_MAJOR 01 |
| 46 | #define BXT_HUC_FW_MINOR 07 |
| 47 | #define BXT_BLD_NUM 1398 |
| 48 | |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 49 | #define SKL_HUC_FW_MAJOR 01 |
| 50 | #define SKL_HUC_FW_MINOR 07 |
| 51 | #define SKL_BLD_NUM 1398 |
| 52 | |
Anusha Srivatsa | f2ec71d | 2017-01-18 08:05:55 -0800 | [diff] [blame] | 53 | #define KBL_HUC_FW_MAJOR 02 |
| 54 | #define KBL_HUC_FW_MINOR 00 |
| 55 | #define KBL_BLD_NUM 1810 |
| 56 | |
Anusha Srivatsa | dbc26ebd | 2017-05-18 10:47:11 -0700 | [diff] [blame] | 57 | #define GLK_HUC_FW_MAJOR 02 |
| 58 | #define GLK_HUC_FW_MINOR 00 |
Anusha Srivatsa | db5ba0d | 2017-03-30 13:24:07 -0700 | [diff] [blame] | 59 | #define GLK_BLD_NUM 1748 |
| 60 | |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 61 | #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) |
| 67 | MODULE_FIRMWARE(I915_SKL_HUC_UCODE); |
| 68 | |
Anusha Srivatsa | cd6909857 | 2017-01-18 08:05:54 -0800 | [diff] [blame] | 69 | #define I915_BXT_HUC_UCODE HUC_FW_PATH(bxt, BXT_HUC_FW_MAJOR, \ |
| 70 | BXT_HUC_FW_MINOR, BXT_BLD_NUM) |
| 71 | MODULE_FIRMWARE(I915_BXT_HUC_UCODE); |
Anusha Srivatsa | f2ec71d | 2017-01-18 08:05:55 -0800 | [diff] [blame] | 72 | |
| 73 | #define I915_KBL_HUC_UCODE HUC_FW_PATH(kbl, KBL_HUC_FW_MAJOR, \ |
| 74 | KBL_HUC_FW_MINOR, KBL_BLD_NUM) |
| 75 | MODULE_FIRMWARE(I915_KBL_HUC_UCODE); |
| 76 | |
Anusha Srivatsa | db5ba0d | 2017-03-30 13:24:07 -0700 | [diff] [blame] | 77 | #define I915_GLK_HUC_UCODE HUC_FW_PATH(glk, GLK_HUC_FW_MAJOR, \ |
| 78 | GLK_HUC_FW_MINOR, GLK_BLD_NUM) |
| 79 | |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 80 | static void huc_fw_select(struct intel_uc_fw *huc_fw) |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 81 | { |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 82 | struct intel_huc *huc = container_of(huc_fw, struct intel_huc, fw); |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 83 | struct drm_i915_private *dev_priv = huc_to_i915(huc); |
| 84 | |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 85 | GEM_BUG_ON(huc_fw->type != INTEL_UC_FW_TYPE_HUC); |
| 86 | |
| 87 | if (!HAS_HUC(dev_priv)) |
| 88 | return; |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 89 | |
| 90 | if (i915_modparams.huc_firmware_path) { |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 91 | huc_fw->path = i915_modparams.huc_firmware_path; |
| 92 | huc_fw->major_ver_wanted = 0; |
| 93 | huc_fw->minor_ver_wanted = 0; |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 94 | } else if (IS_SKYLAKE(dev_priv)) { |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 95 | huc_fw->path = I915_SKL_HUC_UCODE; |
| 96 | huc_fw->major_ver_wanted = SKL_HUC_FW_MAJOR; |
| 97 | huc_fw->minor_ver_wanted = SKL_HUC_FW_MINOR; |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 98 | } else if (IS_BROXTON(dev_priv)) { |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 99 | huc_fw->path = I915_BXT_HUC_UCODE; |
| 100 | huc_fw->major_ver_wanted = BXT_HUC_FW_MAJOR; |
| 101 | huc_fw->minor_ver_wanted = BXT_HUC_FW_MINOR; |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 102 | } else if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) { |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 103 | huc_fw->path = I915_KBL_HUC_UCODE; |
| 104 | huc_fw->major_ver_wanted = KBL_HUC_FW_MAJOR; |
| 105 | huc_fw->minor_ver_wanted = KBL_HUC_FW_MINOR; |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 106 | } else if (IS_GEMINILAKE(dev_priv)) { |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 107 | huc_fw->path = I915_GLK_HUC_UCODE; |
| 108 | huc_fw->major_ver_wanted = GLK_HUC_FW_MAJOR; |
| 109 | huc_fw->minor_ver_wanted = GLK_HUC_FW_MINOR; |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 110 | } else { |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 111 | DRM_WARN("%s: No firmware known for this platform!\n", |
| 112 | intel_uc_fw_type_repr(huc_fw->type)); |
Michal Wajdeczko | 543d5e0 | 2017-10-16 14:47:23 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | /** |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame^] | 117 | * intel_huc_init_early() - initializes HuC struct |
| 118 | * @huc: intel_huc struct |
| 119 | * |
| 120 | * On platforms with HuC selects firmware for uploading |
| 121 | */ |
| 122 | void intel_huc_init_early(struct intel_huc *huc) |
| 123 | { |
| 124 | struct intel_uc_fw *huc_fw = &huc->fw; |
| 125 | |
| 126 | intel_uc_fw_init(huc_fw, INTEL_UC_FW_TYPE_HUC); |
| 127 | huc_fw_select(huc_fw); |
| 128 | } |
| 129 | |
| 130 | /** |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 131 | * huc_ucode_xfer() - DMA's the firmware |
| 132 | * @dev_priv: the drm_i915_private device |
| 133 | * |
| 134 | * Transfer the firmware image to RAM for execution by the microcontroller. |
| 135 | * |
| 136 | * Return: 0 on success, non-zero on failure |
| 137 | */ |
Michal Wajdeczko | 4502e9e | 2017-10-16 14:47:21 +0000 | [diff] [blame] | 138 | static int huc_ucode_xfer(struct intel_uc_fw *huc_fw, struct i915_vma *vma) |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 139 | { |
Michal Wajdeczko | 4502e9e | 2017-10-16 14:47:21 +0000 | [diff] [blame] | 140 | struct intel_huc *huc = container_of(huc_fw, struct intel_huc, fw); |
| 141 | struct drm_i915_private *dev_priv = huc_to_i915(huc); |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 142 | unsigned long offset = 0; |
| 143 | u32 size; |
| 144 | int ret; |
| 145 | |
Michal Wajdeczko | 4502e9e | 2017-10-16 14:47:21 +0000 | [diff] [blame] | 146 | GEM_BUG_ON(huc_fw->type != INTEL_UC_FW_TYPE_HUC); |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 147 | |
| 148 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 149 | |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 150 | /* Set the source address for the uCode */ |
| 151 | offset = guc_ggtt_offset(vma) + huc_fw->header_offset; |
| 152 | I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset)); |
| 153 | I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF); |
| 154 | |
| 155 | /* Hardware doesn't look at destination address for HuC. Set it to 0, |
| 156 | * but still program the correct address space. |
| 157 | */ |
| 158 | I915_WRITE(DMA_ADDR_1_LOW, 0); |
| 159 | I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM); |
| 160 | |
| 161 | size = huc_fw->header_size + huc_fw->ucode_size; |
| 162 | I915_WRITE(DMA_COPY_SIZE, size); |
| 163 | |
| 164 | /* Start the DMA */ |
| 165 | I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(HUC_UKERNEL | START_DMA)); |
| 166 | |
| 167 | /* Wait for DMA to finish */ |
Michal Wajdeczko | bad7b7e | 2017-10-24 10:50:56 +0000 | [diff] [blame] | 168 | ret = intel_wait_for_register_fw(dev_priv, DMA_CTRL, START_DMA, 0, 100); |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 169 | |
| 170 | DRM_DEBUG_DRIVER("HuC DMA transfer wait over with ret %d\n", ret); |
| 171 | |
| 172 | /* Disable the bits once DMA is over */ |
| 173 | I915_WRITE(DMA_CTRL, _MASKED_BIT_DISABLE(HUC_UKERNEL)); |
| 174 | |
| 175 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 176 | |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | /** |
Arkadiusz Hiler | 882d1db | 2017-03-14 15:28:07 +0100 | [diff] [blame] | 181 | * intel_huc_init_hw() - load HuC uCode to device |
| 182 | * @huc: intel_huc structure |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 183 | * |
| 184 | * Called from guc_setup() during driver loading and also after a GPU reset. |
| 185 | * Be note that HuC loading must be done before GuC loading. |
| 186 | * |
| 187 | * The firmware image should have already been fetched into memory by the |
| 188 | * earlier call to intel_huc_init(), so here we need only check that |
| 189 | * is succeeded, and then transfer the image to the h/w. |
| 190 | * |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 191 | */ |
Michal Wajdeczko | 01a9ca0 | 2017-03-31 11:57:09 +0000 | [diff] [blame] | 192 | void intel_huc_init_hw(struct intel_huc *huc) |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 193 | { |
Michal Wajdeczko | 4502e9e | 2017-10-16 14:47:21 +0000 | [diff] [blame] | 194 | intel_uc_fw_upload(&huc->fw, huc_ucode_xfer); |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 198 | * intel_huc_auth() - Authenticate HuC uCode |
| 199 | * @huc: intel_huc structure |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 200 | * |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 201 | * Called after HuC and GuC firmware loading during intel_uc_init_hw(). |
| 202 | * |
| 203 | * This function pins HuC firmware image object into GGTT. |
| 204 | * Then it invokes GuC action to authenticate passing the offset to RSA |
| 205 | * signature through intel_guc_auth_huc(). It then waits for 50ms for |
| 206 | * firmware verification ACK and unpins the object. |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 207 | */ |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 208 | void intel_huc_auth(struct intel_huc *huc) |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 209 | { |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 210 | struct drm_i915_private *i915 = huc_to_i915(huc); |
| 211 | struct intel_guc *guc = &i915->guc; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 212 | struct i915_vma *vma; |
| 213 | int ret; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 214 | |
Michał Winiarski | 7e8d12b | 2017-01-20 20:23:46 +0100 | [diff] [blame] | 215 | if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) |
| 216 | return; |
| 217 | |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 218 | vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0, |
| 219 | PIN_OFFSET_BIAS | GUC_WOPCM_TOP); |
| 220 | if (IS_ERR(vma)) { |
| 221 | DRM_ERROR("failed to pin huc fw object %d\n", |
| 222 | (int)PTR_ERR(vma)); |
| 223 | return; |
| 224 | } |
| 225 | |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 226 | ret = intel_guc_auth_huc(guc, |
| 227 | guc_ggtt_offset(vma) + huc->fw.rsa_offset); |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 228 | if (ret) { |
| 229 | DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret); |
| 230 | goto out; |
| 231 | } |
| 232 | |
| 233 | /* Check authentication status, it should be done by now */ |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 234 | ret = intel_wait_for_register(i915, |
| 235 | HUC_STATUS2, |
| 236 | HUC_FW_VERIFIED, |
| 237 | HUC_FW_VERIFIED, |
| 238 | 50); |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 239 | if (ret) { |
| 240 | DRM_ERROR("HuC: Authentication failed %d\n", ret); |
| 241 | goto out; |
| 242 | } |
| 243 | |
| 244 | out: |
| 245 | i915_vma_unpin(vma); |
| 246 | } |