xref: /openbmc/linux/drivers/gpu/drm/i915/gt/uc/intel_huc.h (revision 612cf4d2)
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 
44 void intel_huc_init_early(struct intel_huc *huc);
45 int intel_huc_init(struct intel_huc *huc);
46 void intel_huc_fini(struct intel_huc *huc);
47 void intel_huc_suspend(struct intel_huc *huc);
48 int intel_huc_auth(struct intel_huc *huc);
49 int intel_huc_wait_for_auth_complete(struct intel_huc *huc);
50 int intel_huc_check_status(struct intel_huc *huc);
51 void intel_huc_update_auth_status(struct intel_huc *huc);
52 bool intel_huc_is_authenticated(struct intel_huc *huc);
53 
54 void intel_huc_register_gsc_notifier(struct intel_huc *huc, struct bus_type *bus);
55 void intel_huc_unregister_gsc_notifier(struct intel_huc *huc, struct bus_type *bus);
56 
57 static inline int intel_huc_sanitize(struct intel_huc *huc)
58 {
59 	intel_uc_fw_sanitize(&huc->fw);
60 	return 0;
61 }
62 
63 static inline bool intel_huc_is_supported(struct intel_huc *huc)
64 {
65 	return intel_uc_fw_is_supported(&huc->fw);
66 }
67 
68 static inline bool intel_huc_is_wanted(struct intel_huc *huc)
69 {
70 	return intel_uc_fw_is_enabled(&huc->fw);
71 }
72 
73 static inline bool intel_huc_is_used(struct intel_huc *huc)
74 {
75 	GEM_BUG_ON(__intel_uc_fw_status(&huc->fw) == INTEL_UC_FIRMWARE_SELECTED);
76 	return intel_uc_fw_is_available(&huc->fw);
77 }
78 
79 static inline bool intel_huc_is_loaded_by_gsc(const struct intel_huc *huc)
80 {
81 	return huc->fw.loaded_via_gsc;
82 }
83 
84 static inline bool intel_huc_wait_required(struct intel_huc *huc)
85 {
86 	return intel_huc_is_used(huc) && intel_huc_is_loaded_by_gsc(huc) &&
87 	       !intel_huc_is_authenticated(huc);
88 }
89 
90 void intel_huc_load_status(struct intel_huc *huc, struct drm_printer *p);
91 
92 #endif
93