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 | |
Michal Wajdeczko | 2fe2d4e | 2017-12-06 13:53:10 +0000 | [diff] [blame] | 30 | void intel_huc_init_early(struct intel_huc *huc) |
| 31 | { |
Sagar Arun Kamble | 57312ea | 2018-03-01 22:15:45 +0530 | [diff] [blame] | 32 | intel_huc_fw_init_early(huc); |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 33 | } |
| 34 | |
Michal Wajdeczko | f7dc015 | 2018-06-28 14:15:21 +0000 | [diff] [blame] | 35 | int intel_huc_init_misc(struct intel_huc *huc) |
| 36 | { |
| 37 | struct drm_i915_private *i915 = huc_to_i915(huc); |
| 38 | |
| 39 | intel_uc_fw_fetch(i915, &huc->fw); |
| 40 | return 0; |
| 41 | } |
| 42 | |
Anusha Srivatsa | bd13285 | 2017-01-18 08:05:53 -0800 | [diff] [blame] | 43 | /** |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 44 | * intel_huc_auth() - Authenticate HuC uCode |
| 45 | * @huc: intel_huc structure |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 46 | * |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 47 | * Called after HuC and GuC firmware loading during intel_uc_init_hw(). |
| 48 | * |
| 49 | * This function pins HuC firmware image object into GGTT. |
| 50 | * Then it invokes GuC action to authenticate passing the offset to RSA |
| 51 | * signature through intel_guc_auth_huc(). It then waits for 50ms for |
| 52 | * firmware verification ACK and unpins the object. |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 53 | */ |
Michal Wajdeczko | 0dfa1ce | 2017-12-06 13:53:16 +0000 | [diff] [blame] | 54 | int intel_huc_auth(struct intel_huc *huc) |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 55 | { |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 56 | struct drm_i915_private *i915 = huc_to_i915(huc); |
| 57 | struct intel_guc *guc = &i915->guc; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 58 | struct i915_vma *vma; |
Michal Wajdeczko | 7b02676 | 2018-03-02 13:37:17 +0000 | [diff] [blame] | 59 | u32 status; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 60 | int ret; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 61 | |
Michał Winiarski | 7e8d12b | 2017-01-20 20:23:46 +0100 | [diff] [blame] | 62 | if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) |
Michal Wajdeczko | 0dfa1ce | 2017-12-06 13:53:16 +0000 | [diff] [blame] | 63 | return -ENOEXEC; |
Michał Winiarski | 7e8d12b | 2017-01-20 20:23:46 +0100 | [diff] [blame] | 64 | |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 65 | vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0, |
Jakub Bartmiński | dd18ced | 2018-07-27 16:11:45 +0200 | [diff] [blame] | 66 | PIN_OFFSET_BIAS | i915->ggtt.pin_bias); |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 67 | if (IS_ERR(vma)) { |
Michal Wajdeczko | 0dfa1ce | 2017-12-06 13:53:16 +0000 | [diff] [blame] | 68 | ret = PTR_ERR(vma); |
| 69 | DRM_ERROR("HuC: Failed to pin huc fw object %d\n", ret); |
Michal Wajdeczko | 7b02676 | 2018-03-02 13:37:17 +0000 | [diff] [blame] | 70 | goto fail; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Sagar Arun Kamble | 9a2cbf2 | 2017-09-26 12:47:16 +0530 | [diff] [blame] | 73 | ret = intel_guc_auth_huc(guc, |
Jackie Li | 3c009e3 | 2018-03-13 17:32:49 -0700 | [diff] [blame] | 74 | intel_guc_ggtt_offset(guc, vma) + |
| 75 | huc->fw.rsa_offset); |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 76 | if (ret) { |
| 77 | DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret); |
Michal Wajdeczko | 7b02676 | 2018-03-02 13:37:17 +0000 | [diff] [blame] | 78 | goto fail_unpin; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* Check authentication status, it should be done by now */ |
Michal Wajdeczko | 7b02676 | 2018-03-02 13:37:17 +0000 | [diff] [blame] | 82 | ret = __intel_wait_for_register(i915, |
| 83 | HUC_STATUS2, |
| 84 | HUC_FW_VERIFIED, |
| 85 | HUC_FW_VERIFIED, |
| 86 | 2, 50, &status); |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 87 | if (ret) { |
Michal Wajdeczko | 7b02676 | 2018-03-02 13:37:17 +0000 | [diff] [blame] | 88 | DRM_ERROR("HuC: Firmware not verified %#x\n", status); |
| 89 | goto fail_unpin; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 92 | i915_vma_unpin(vma); |
Michal Wajdeczko | 7b02676 | 2018-03-02 13:37:17 +0000 | [diff] [blame] | 93 | return 0; |
| 94 | |
| 95 | fail_unpin: |
| 96 | i915_vma_unpin(vma); |
| 97 | fail: |
| 98 | huc->fw.load_status = INTEL_UC_FIRMWARE_FAIL; |
| 99 | |
| 100 | DRM_ERROR("HuC: Authentication failed %d\n", ret); |
Michal Wajdeczko | 0dfa1ce | 2017-12-06 13:53:16 +0000 | [diff] [blame] | 101 | return ret; |
Anusha Srivatsa | dac84a3 | 2017-01-18 08:05:57 -0800 | [diff] [blame] | 102 | } |
Michal Wajdeczko | fa26527 | 2018-03-14 20:04:29 +0000 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * intel_huc_check_status() - check HuC status |
| 106 | * @huc: intel_huc structure |
| 107 | * |
| 108 | * This function reads status register to verify if HuC |
| 109 | * firmware was successfully loaded. |
| 110 | * |
Michal Wajdeczko | 1a49f53 | 2018-10-17 19:52:45 +0000 | [diff] [blame] | 111 | * Returns: 1 if HuC firmware is loaded and verified, |
| 112 | * 0 if HuC firmware is not loaded and -ENODEV if HuC |
| 113 | * is not present on this platform. |
Michal Wajdeczko | fa26527 | 2018-03-14 20:04:29 +0000 | [diff] [blame] | 114 | */ |
| 115 | int intel_huc_check_status(struct intel_huc *huc) |
| 116 | { |
| 117 | struct drm_i915_private *dev_priv = huc_to_i915(huc); |
Chris Wilson | 3055f0c | 2019-01-14 14:21:17 +0000 | [diff] [blame] | 118 | intel_wakeref_t wakeref; |
Chris Wilson | d4225a5 | 2019-01-14 14:21:23 +0000 | [diff] [blame] | 119 | bool status = false; |
Michal Wajdeczko | fa26527 | 2018-03-14 20:04:29 +0000 | [diff] [blame] | 120 | |
| 121 | if (!HAS_HUC(dev_priv)) |
| 122 | return -ENODEV; |
| 123 | |
Chris Wilson | d4225a5 | 2019-01-14 14:21:23 +0000 | [diff] [blame] | 124 | with_intel_runtime_pm(dev_priv, wakeref) |
| 125 | status = I915_READ(HUC_STATUS2) & HUC_FW_VERIFIED; |
Michal Wajdeczko | fa26527 | 2018-03-14 20:04:29 +0000 | [diff] [blame] | 126 | |
| 127 | return status; |
| 128 | } |