xref: /openbmc/linux/drivers/gpu/drm/i915/gt/uc/intel_huc.h (revision 6a9b6c4580af184f1f8744ade1fe1979e3da05ac)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2014-2019 Intel Corporation
4  */
5 
6 #ifndef _INTEL_HUC_H_
7 #define _INTEL_HUC_H_
8 
9 #include "i915_reg_defs.h"
10 #include "i915_sw_fence.h"
11 #include "intel_uc_fw.h"
12 #include "intel_huc_fw.h"
13 
14 #include <linux/notifier.h>
15 #include <linux/hrtimer.h>
16 
17 struct bus_type;
18 
19 enum intel_huc_delayed_load_status {
20 	INTEL_HUC_WAITING_ON_GSC = 0,
21 	INTEL_HUC_WAITING_ON_PXP,
22 	INTEL_HUC_DELAYED_LOAD_ERROR,
23 };
24 
25 struct intel_huc {
26 	/* Generic uC firmware management */
27 	struct intel_uc_fw fw;
28 
29 	/* HuC-specific additions */
30 	struct {
31 		i915_reg_t reg;
32 		u32 mask;
33 		u32 value;
34 	} status;
35 
36 	struct {
37 		struct i915_sw_fence fence;
38 		struct hrtimer timer;
39 		struct notifier_block nb;
40 		enum intel_huc_delayed_load_status status;
41 	} delayed_load;
42 
43 	bool loaded_via_gsc;
44 };
45 
46 int intel_huc_sanitize(struct intel_huc *huc);
47 void intel_huc_init_early(struct intel_huc *huc);
48 int intel_huc_init(struct intel_huc *huc);
49 void intel_huc_fini(struct intel_huc *huc);
50 void intel_huc_suspend(struct intel_huc *huc);
51 int intel_huc_auth(struct intel_huc *huc);
52 int intel_huc_wait_for_auth_complete(struct intel_huc *huc);
53 int intel_huc_check_status(struct intel_huc *huc);
54 void intel_huc_update_auth_status(struct intel_huc *huc);
55 bool intel_huc_is_authenticated(struct intel_huc *huc);
56 
57 void intel_huc_register_gsc_notifier(struct intel_huc *huc, const struct bus_type *bus);
58 void intel_huc_unregister_gsc_notifier(struct intel_huc *huc, const struct bus_type *bus);
59 
60 static inline bool intel_huc_is_supported(struct intel_huc *huc)
61 {
62 	return intel_uc_fw_is_supported(&huc->fw);
63 }
64 
65 static inline bool intel_huc_is_wanted(struct intel_huc *huc)
66 {
67 	return intel_uc_fw_is_enabled(&huc->fw);
68 }
69 
70 static inline bool intel_huc_is_used(struct intel_huc *huc)
71 {
72 	GEM_BUG_ON(__intel_uc_fw_status(&huc->fw) == INTEL_UC_FIRMWARE_SELECTED);
73 	return intel_uc_fw_is_available(&huc->fw);
74 }
75 
76 static inline bool intel_huc_is_loaded_by_gsc(const struct intel_huc *huc)
77 {
78 	return huc->loaded_via_gsc;
79 }
80 
81 static inline bool intel_huc_wait_required(struct intel_huc *huc)
82 {
83 	return intel_huc_is_used(huc) && intel_huc_is_loaded_by_gsc(huc) &&
84 	       !intel_huc_is_authenticated(huc);
85 }
86 
87 void intel_huc_load_status(struct intel_huc *huc, struct drm_printer *p);
88 
89 #endif
90