blob: 65e2afb9b955e1a35a853a5582eb83f7ef1d656c [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
35/**
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053036 * intel_huc_auth() - Authenticate HuC uCode
37 * @huc: intel_huc structure
Anusha Srivatsadac84a32017-01-18 08:05:57 -080038 *
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053039 * Called after HuC and GuC firmware loading during intel_uc_init_hw().
40 *
41 * This function pins HuC firmware image object into GGTT.
42 * Then it invokes GuC action to authenticate passing the offset to RSA
43 * signature through intel_guc_auth_huc(). It then waits for 50ms for
44 * firmware verification ACK and unpins the object.
Anusha Srivatsadac84a32017-01-18 08:05:57 -080045 */
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +000046int intel_huc_auth(struct intel_huc *huc)
Anusha Srivatsadac84a32017-01-18 08:05:57 -080047{
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053048 struct drm_i915_private *i915 = huc_to_i915(huc);
49 struct intel_guc *guc = &i915->guc;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080050 struct i915_vma *vma;
Michal Wajdeczko7b026762018-03-02 13:37:17 +000051 u32 status;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080052 int ret;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080053
Michał Winiarski7e8d12b2017-01-20 20:23:46 +010054 if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +000055 return -ENOEXEC;
Michał Winiarski7e8d12b2017-01-20 20:23:46 +010056
Anusha Srivatsadac84a32017-01-18 08:05:57 -080057 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
58 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
59 if (IS_ERR(vma)) {
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +000060 ret = PTR_ERR(vma);
61 DRM_ERROR("HuC: Failed to pin huc fw object %d\n", ret);
Michal Wajdeczko7b026762018-03-02 13:37:17 +000062 goto fail;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080063 }
64
Sagar Arun Kamble9a2cbf22017-09-26 12:47:16 +053065 ret = intel_guc_auth_huc(guc,
66 guc_ggtt_offset(vma) + huc->fw.rsa_offset);
Anusha Srivatsadac84a32017-01-18 08:05:57 -080067 if (ret) {
68 DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
Michal Wajdeczko7b026762018-03-02 13:37:17 +000069 goto fail_unpin;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080070 }
71
72 /* Check authentication status, it should be done by now */
Michal Wajdeczko7b026762018-03-02 13:37:17 +000073 ret = __intel_wait_for_register(i915,
74 HUC_STATUS2,
75 HUC_FW_VERIFIED,
76 HUC_FW_VERIFIED,
77 2, 50, &status);
Anusha Srivatsadac84a32017-01-18 08:05:57 -080078 if (ret) {
Michal Wajdeczko7b026762018-03-02 13:37:17 +000079 DRM_ERROR("HuC: Firmware not verified %#x\n", status);
80 goto fail_unpin;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080081 }
82
Anusha Srivatsadac84a32017-01-18 08:05:57 -080083 i915_vma_unpin(vma);
Michal Wajdeczko7b026762018-03-02 13:37:17 +000084 return 0;
85
86fail_unpin:
87 i915_vma_unpin(vma);
88fail:
89 huc->fw.load_status = INTEL_UC_FIRMWARE_FAIL;
90
91 DRM_ERROR("HuC: Authentication failed %d\n", ret);
Michal Wajdeczko0dfa1ce2017-12-06 13:53:16 +000092 return ret;
Anusha Srivatsadac84a32017-01-18 08:05:57 -080093}