vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / intel_huc.c
blobffcad5fad6a7b4e6a24b1e34d53964caaeebfaae
1 /*
2 * Copyright © 2016-2017 Intel Corporation
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:
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.
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.
25 #include <linux/types.h>
27 #include "intel_huc.h"
28 #include "i915_drv.h"
30 void intel_huc_init_early(struct intel_huc *huc)
32 intel_huc_fw_init_early(huc);
35 int intel_huc_init_misc(struct intel_huc *huc)
37 struct drm_i915_private *i915 = huc_to_i915(huc);
39 intel_uc_fw_fetch(i915, &huc->fw);
40 return 0;
43 /**
44 * intel_huc_auth() - Authenticate HuC uCode
45 * @huc: intel_huc structure
47 * Called after HuC and GuC firmware loading during intel_uc_init_hw().
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.
54 int intel_huc_auth(struct intel_huc *huc)
56 struct drm_i915_private *i915 = huc_to_i915(huc);
57 struct intel_guc *guc = &i915->guc;
58 struct i915_vma *vma;
59 u32 status;
60 int ret;
62 if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
63 return -ENOEXEC;
65 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
66 PIN_OFFSET_BIAS | guc->ggtt_pin_bias);
67 if (IS_ERR(vma)) {
68 ret = PTR_ERR(vma);
69 DRM_ERROR("HuC: Failed to pin huc fw object %d\n", ret);
70 goto fail;
73 ret = intel_guc_auth_huc(guc,
74 intel_guc_ggtt_offset(guc, vma) +
75 huc->fw.rsa_offset);
76 if (ret) {
77 DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
78 goto fail_unpin;
81 /* Check authentication status, it should be done by now */
82 ret = __intel_wait_for_register(i915,
83 HUC_STATUS2,
84 HUC_FW_VERIFIED,
85 HUC_FW_VERIFIED,
86 2, 50, &status);
87 if (ret) {
88 DRM_ERROR("HuC: Firmware not verified %#x\n", status);
89 goto fail_unpin;
92 i915_vma_unpin(vma);
93 return 0;
95 fail_unpin:
96 i915_vma_unpin(vma);
97 fail:
98 huc->fw.load_status = INTEL_UC_FIRMWARE_FAIL;
100 DRM_ERROR("HuC: Authentication failed %d\n", ret);
101 return ret;
105 * intel_huc_check_status() - check HuC status
106 * @huc: intel_huc structure
108 * This function reads status register to verify if HuC
109 * firmware was successfully loaded.
111 * Returns positive value if HuC firmware is loaded and verified
112 * and -ENODEV if HuC is not present.
114 int intel_huc_check_status(struct intel_huc *huc)
116 struct drm_i915_private *dev_priv = huc_to_i915(huc);
117 u32 status;
119 if (!HAS_HUC(dev_priv))
120 return -ENODEV;
122 intel_runtime_pm_get(dev_priv);
123 status = I915_READ(HUC_STATUS2) & HUC_FW_VERIFIED;
124 intel_runtime_pm_put(dev_priv);
126 return status;