blob: 9bd1c9002c2ad9095cf6d457308df63ef20787b8 [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
Michal Wajdeczko2fe2d4e2017-12-06 13:53:10 +000030void intel_huc_init_early(struct intel_huc *huc)
31{
Sagar Arun Kamble57312ea2018-03-01 22:15:45 +053032 intel_huc_fw_init_early(huc);
Anusha Srivatsabd132852017-01-18 08:05:53 -080033}
34
Michal Wajdeczkof7dc0152018-06-28 14:15:21 +000035int 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 Srivatsabd132852017-01-18 08:05:53 -080043/**
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053044 * intel_huc_auth() - Authenticate HuC uCode
45 * @huc: intel_huc structure
Anusha Srivatsadac84a32017-01-18 08:05:57 -080046 *
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053047 * 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 Srivatsadac84a32017-01-18 08:05:57 -080053 */
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +000054int intel_huc_auth(struct intel_huc *huc)
Anusha Srivatsadac84a32017-01-18 08:05:57 -080055{
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053056 struct drm_i915_private *i915 = huc_to_i915(huc);
57 struct intel_guc *guc = &i915->guc;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080058 struct i915_vma *vma;
Michal Wajdeczko7b026762018-03-02 13:37:17 +000059 u32 status;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080060 int ret;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080061
Michał Winiarski7e8d12b2017-01-20 20:23:46 +010062 if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +000063 return -ENOEXEC;
Michał Winiarski7e8d12b2017-01-20 20:23:46 +010064
Anusha Srivatsadac84a32017-01-18 08:05:57 -080065 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
Jakub Bartmińskidd18ced2018-07-27 16:11:45 +020066 PIN_OFFSET_BIAS | i915->ggtt.pin_bias);
Anusha Srivatsadac84a32017-01-18 08:05:57 -080067 if (IS_ERR(vma)) {
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +000068 ret = PTR_ERR(vma);
69 DRM_ERROR("HuC: Failed to pin huc fw object %d\n", ret);
Michal Wajdeczko7b026762018-03-02 13:37:17 +000070 goto fail;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080071 }
72
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053073 ret = intel_guc_auth_huc(guc,
Jackie Li3c009e32018-03-13 17:32:49 -070074 intel_guc_ggtt_offset(guc, vma) +
75 huc->fw.rsa_offset);
Anusha Srivatsadac84a32017-01-18 08:05:57 -080076 if (ret) {
77 DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
Michal Wajdeczko7b026762018-03-02 13:37:17 +000078 goto fail_unpin;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080079 }
80
81 /* Check authentication status, it should be done by now */
Michal Wajdeczko7b026762018-03-02 13:37:17 +000082 ret = __intel_wait_for_register(i915,
83 HUC_STATUS2,
84 HUC_FW_VERIFIED,
85 HUC_FW_VERIFIED,
86 2, 50, &status);
Anusha Srivatsadac84a32017-01-18 08:05:57 -080087 if (ret) {
Michal Wajdeczko7b026762018-03-02 13:37:17 +000088 DRM_ERROR("HuC: Firmware not verified %#x\n", status);
89 goto fail_unpin;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080090 }
91
Anusha Srivatsadac84a32017-01-18 08:05:57 -080092 i915_vma_unpin(vma);
Michal Wajdeczko7b026762018-03-02 13:37:17 +000093 return 0;
94
95fail_unpin:
96 i915_vma_unpin(vma);
97fail:
98 huc->fw.load_status = INTEL_UC_FIRMWARE_FAIL;
99
100 DRM_ERROR("HuC: Authentication failed %d\n", ret);
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +0000101 return ret;
Anusha Srivatsadac84a32017-01-18 08:05:57 -0800102}
Michal Wajdeczkofa265272018-03-14 20:04:29 +0000103
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 Wajdeczko1a49f532018-10-17 19:52:45 +0000111 * 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 Wajdeczkofa265272018-03-14 20:04:29 +0000114 */
115int intel_huc_check_status(struct intel_huc *huc)
116{
117 struct drm_i915_private *dev_priv = huc_to_i915(huc);
Chris Wilson3055f0c2019-01-14 14:21:17 +0000118 intel_wakeref_t wakeref;
Chris Wilsond4225a52019-01-14 14:21:23 +0000119 bool status = false;
Michal Wajdeczkofa265272018-03-14 20:04:29 +0000120
121 if (!HAS_HUC(dev_priv))
122 return -ENODEV;
123
Chris Wilsond4225a52019-01-14 14:21:23 +0000124 with_intel_runtime_pm(dev_priv, wakeref)
125 status = I915_READ(HUC_STATUS2) & HUC_FW_VERIFIED;
Michal Wajdeczkofa265272018-03-14 20:04:29 +0000126
127 return status;
128}