13ea58029SMichal Wajdeczko /* SPDX-License-Identifier: MIT */
20f261b24SDaniele Ceraolo Spurio /*
33ea58029SMichal Wajdeczko * Copyright © 2014-2019 Intel Corporation
40f261b24SDaniele Ceraolo Spurio */
50f261b24SDaniele Ceraolo Spurio
60f261b24SDaniele Ceraolo Spurio #ifndef _INTEL_HUC_H_
70f261b24SDaniele Ceraolo Spurio #define _INTEL_HUC_H_
80f261b24SDaniele Ceraolo Spurio
9ce2fce25SMatt Roper #include "i915_reg_defs.h"
1027536e03SDaniele Ceraolo Spurio #include "i915_sw_fence.h"
110f261b24SDaniele Ceraolo Spurio #include "intel_uc_fw.h"
120f261b24SDaniele Ceraolo Spurio #include "intel_huc_fw.h"
130f261b24SDaniele Ceraolo Spurio
1427536e03SDaniele Ceraolo Spurio #include <linux/notifier.h>
1527536e03SDaniele Ceraolo Spurio #include <linux/hrtimer.h>
1627536e03SDaniele Ceraolo Spurio
1727536e03SDaniele Ceraolo Spurio struct bus_type;
1827536e03SDaniele Ceraolo Spurio struct i915_vma;
1927536e03SDaniele Ceraolo Spurio
2027536e03SDaniele Ceraolo Spurio enum intel_huc_delayed_load_status {
2127536e03SDaniele Ceraolo Spurio INTEL_HUC_WAITING_ON_GSC = 0,
2227536e03SDaniele Ceraolo Spurio INTEL_HUC_WAITING_ON_PXP,
2327536e03SDaniele Ceraolo Spurio INTEL_HUC_DELAYED_LOAD_ERROR,
2427536e03SDaniele Ceraolo Spurio };
250f261b24SDaniele Ceraolo Spurio
260f261b24SDaniele Ceraolo Spurio enum intel_huc_authentication_type {
270f261b24SDaniele Ceraolo Spurio INTEL_HUC_AUTH_BY_GUC = 0,
280f261b24SDaniele Ceraolo Spurio INTEL_HUC_AUTH_BY_GSC,
290f261b24SDaniele Ceraolo Spurio INTEL_HUC_AUTH_MAX_MODES
300f261b24SDaniele Ceraolo Spurio };
310f261b24SDaniele Ceraolo Spurio
320f261b24SDaniele Ceraolo Spurio struct intel_huc {
330f261b24SDaniele Ceraolo Spurio /* Generic uC firmware management */
340f261b24SDaniele Ceraolo Spurio struct intel_uc_fw fw;
3527536e03SDaniele Ceraolo Spurio
3627536e03SDaniele Ceraolo Spurio /* HuC-specific additions */
3727536e03SDaniele Ceraolo Spurio struct {
3827536e03SDaniele Ceraolo Spurio i915_reg_t reg;
3927536e03SDaniele Ceraolo Spurio u32 mask;
4027536e03SDaniele Ceraolo Spurio u32 value;
4127536e03SDaniele Ceraolo Spurio } status[INTEL_HUC_AUTH_MAX_MODES];
420f261b24SDaniele Ceraolo Spurio
430f261b24SDaniele Ceraolo Spurio struct {
44*c7423749SDaniele Ceraolo Spurio struct i915_sw_fence fence;
450f261b24SDaniele Ceraolo Spurio struct hrtimer timer;
460f261b24SDaniele Ceraolo Spurio struct notifier_block nb;
470f261b24SDaniele Ceraolo Spurio enum intel_huc_delayed_load_status status;
4827536e03SDaniele Ceraolo Spurio } delayed_load;
490f261b24SDaniele Ceraolo Spurio
50087b6818SDaniele Ceraolo Spurio /* for load via GSCCS */
510f261b24SDaniele Ceraolo Spurio struct i915_vma *heci_pkt;
526f67930aSDaniele Ceraolo Spurio
53087b6818SDaniele Ceraolo Spurio bool loaded_via_gsc;
540f261b24SDaniele Ceraolo Spurio };
55c9a9f18dSGreg Kroah-Hartman
56c9a9f18dSGreg Kroah-Hartman int intel_huc_sanitize(struct intel_huc *huc);
5727536e03SDaniele Ceraolo Spurio void intel_huc_init_early(struct intel_huc *huc);
58db81bc6eSMichal Wajdeczko int intel_huc_init(struct intel_huc *huc);
59db81bc6eSMichal Wajdeczko void intel_huc_fini(struct intel_huc *huc);
60356c4848SMichal Wajdeczko void intel_huc_suspend(struct intel_huc *huc);
61356c4848SMichal Wajdeczko int intel_huc_auth(struct intel_huc *huc, enum intel_huc_authentication_type type);
62356c4848SMichal Wajdeczko int intel_huc_wait_for_auth_complete(struct intel_huc *huc,
63bfe5a40aSDaniele Ceraolo Spurio enum intel_huc_authentication_type type);
64356c4848SMichal Wajdeczko bool intel_huc_is_authenticated(struct intel_huc *huc,
65356c4848SMichal Wajdeczko enum intel_huc_authentication_type type);
66db81bc6eSMichal Wajdeczko int intel_huc_check_status(struct intel_huc *huc);
67db81bc6eSMichal Wajdeczko void intel_huc_update_auth_status(struct intel_huc *huc);
68bfe5a40aSDaniele Ceraolo Spurio
69bfe5a40aSDaniele Ceraolo Spurio void intel_huc_register_gsc_notifier(struct intel_huc *huc, const struct bus_type *bus);
70bfe5a40aSDaniele Ceraolo Spurio void intel_huc_unregister_gsc_notifier(struct intel_huc *huc, const struct bus_type *bus);
71bfe5a40aSDaniele Ceraolo Spurio
intel_huc_is_supported(struct intel_huc * huc)72bfe5a40aSDaniele Ceraolo Spurio static inline bool intel_huc_is_supported(struct intel_huc *huc)
73bfe5a40aSDaniele Ceraolo Spurio {
746f67930aSDaniele Ceraolo Spurio return intel_uc_fw_is_supported(&huc->fw);
756f67930aSDaniele Ceraolo Spurio }
766f67930aSDaniele Ceraolo Spurio
intel_huc_is_wanted(struct intel_huc * huc)776f67930aSDaniele Ceraolo Spurio static inline bool intel_huc_is_wanted(struct intel_huc *huc)
786f67930aSDaniele Ceraolo Spurio {
79e6177ec5SDaniele Ceraolo Spurio return intel_uc_fw_is_enabled(&huc->fw);
80e6177ec5SDaniele Ceraolo Spurio }
81e6177ec5SDaniele Ceraolo Spurio
intel_huc_is_used(struct intel_huc * huc)82e6177ec5SDaniele Ceraolo Spurio static inline bool intel_huc_is_used(struct intel_huc *huc)
83e6177ec5SDaniele Ceraolo Spurio {
84e6177ec5SDaniele Ceraolo Spurio GEM_BUG_ON(__intel_uc_fw_status(&huc->fw) == INTEL_UC_FIRMWARE_SELECTED);
8534904bd6SDaniele Ceraolo Spurio return intel_uc_fw_is_available(&huc->fw);
8634904bd6SDaniele Ceraolo Spurio }
870f261b24SDaniele Ceraolo Spurio
intel_huc_is_loaded_by_gsc(const struct intel_huc * huc)88 static inline bool intel_huc_is_loaded_by_gsc(const struct intel_huc *huc)
89 {
90 return huc->loaded_via_gsc;
91 }
92
intel_huc_wait_required(struct intel_huc * huc)93 static inline bool intel_huc_wait_required(struct intel_huc *huc)
94 {
95 return intel_huc_is_used(huc) && intel_huc_is_loaded_by_gsc(huc) &&
96 !intel_huc_is_authenticated(huc, INTEL_HUC_AUTH_BY_GSC);
97 }
98
99 void intel_huc_load_status(struct intel_huc *huc, struct drm_printer *p);
100
101 #endif
102