1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2014-2019 Intel Corporation
6 #ifndef _INTEL_UC_FW_H_
7 #define _INTEL_UC_FW_H_
9 #include <linux/types.h>
10 #include "intel_uc_fw_abi.h"
11 #include "intel_device_info.h"
15 struct drm_i915_private
;
18 /* Home of GuC, HuC and DMC firmwares */
19 #define INTEL_UC_FIRMWARE_URL "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915"
22 * +------------+---------------------------------------------------+
23 * | PHASE | FIRMWARE STATUS TRANSITIONS |
24 * +============+===================================================+
26 * +------------+- / | \ -+
27 * | | DISABLED <--/ | \--> NOT_SUPPORTED |
30 * +------------+- / | \ -+
31 * | | MISSING <--/ | \--> ERROR |
34 * +------------+- | -+
36 * | | /------> LOADABLE <----<-----------\ |
37 * +------------+- \ / \ \ \ -+
38 * | | FAIL <--< \--> TRANSFERRED \ |
39 * | upload | \ / \ / |
40 * | | \---------/ \--> RUNNING |
41 * +------------+---------------------------------------------------+
44 enum intel_uc_fw_status
{
45 INTEL_UC_FIRMWARE_NOT_SUPPORTED
= -1, /* no uc HW */
46 INTEL_UC_FIRMWARE_UNINITIALIZED
= 0, /* used to catch checks done too early */
47 INTEL_UC_FIRMWARE_DISABLED
, /* disabled */
48 INTEL_UC_FIRMWARE_SELECTED
, /* selected the blob we want to load */
49 INTEL_UC_FIRMWARE_MISSING
, /* blob not found on the system */
50 INTEL_UC_FIRMWARE_ERROR
, /* invalid format or version */
51 INTEL_UC_FIRMWARE_AVAILABLE
, /* blob found and copied in mem */
52 INTEL_UC_FIRMWARE_LOADABLE
, /* all fw-required objects are ready */
53 INTEL_UC_FIRMWARE_FAIL
, /* failed to xfer or init/auth the fw */
54 INTEL_UC_FIRMWARE_TRANSFERRED
, /* dma xfer done */
55 INTEL_UC_FIRMWARE_RUNNING
/* init/auth done */
58 enum intel_uc_fw_type
{
59 INTEL_UC_FW_TYPE_GUC
= 0,
62 #define INTEL_UC_FW_NUM_TYPES 2
65 * This structure encapsulates all the data needed during the process
66 * of fetching, caching, and loading the firmware image into the uC.
69 enum intel_uc_fw_type type
;
71 const enum intel_uc_fw_status status
;
72 enum intel_uc_fw_status __status
; /* no accidental overwrites */
77 struct drm_i915_gem_object
*obj
;
80 * The firmware build process will generate a version header file with major and
81 * minor version defined. The versions are built into CSS header of firmware.
82 * i915 kernel driver set the minimal firmware version required per platform.
92 u32 private_data_size
;
95 #ifdef CONFIG_DRM_I915_DEBUG_GUC
96 void intel_uc_fw_change_status(struct intel_uc_fw
*uc_fw
,
97 enum intel_uc_fw_status status
);
99 static inline void intel_uc_fw_change_status(struct intel_uc_fw
*uc_fw
,
100 enum intel_uc_fw_status status
)
102 uc_fw
->__status
= status
;
107 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status
)
110 case INTEL_UC_FIRMWARE_NOT_SUPPORTED
:
112 case INTEL_UC_FIRMWARE_UNINITIALIZED
:
113 return "UNINITIALIZED";
114 case INTEL_UC_FIRMWARE_DISABLED
:
116 case INTEL_UC_FIRMWARE_SELECTED
:
118 case INTEL_UC_FIRMWARE_MISSING
:
120 case INTEL_UC_FIRMWARE_ERROR
:
122 case INTEL_UC_FIRMWARE_AVAILABLE
:
124 case INTEL_UC_FIRMWARE_LOADABLE
:
126 case INTEL_UC_FIRMWARE_FAIL
:
128 case INTEL_UC_FIRMWARE_TRANSFERRED
:
129 return "TRANSFERRED";
130 case INTEL_UC_FIRMWARE_RUNNING
:
136 static inline int intel_uc_fw_status_to_error(enum intel_uc_fw_status status
)
139 case INTEL_UC_FIRMWARE_NOT_SUPPORTED
:
141 case INTEL_UC_FIRMWARE_UNINITIALIZED
:
143 case INTEL_UC_FIRMWARE_DISABLED
:
145 case INTEL_UC_FIRMWARE_MISSING
:
147 case INTEL_UC_FIRMWARE_ERROR
:
149 case INTEL_UC_FIRMWARE_FAIL
:
151 case INTEL_UC_FIRMWARE_SELECTED
:
153 case INTEL_UC_FIRMWARE_AVAILABLE
:
154 case INTEL_UC_FIRMWARE_LOADABLE
:
155 case INTEL_UC_FIRMWARE_TRANSFERRED
:
156 case INTEL_UC_FIRMWARE_RUNNING
:
162 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type
)
165 case INTEL_UC_FW_TYPE_GUC
:
167 case INTEL_UC_FW_TYPE_HUC
:
173 static inline enum intel_uc_fw_status
174 __intel_uc_fw_status(struct intel_uc_fw
*uc_fw
)
176 /* shouldn't call this before checking hw/blob availability */
177 GEM_BUG_ON(uc_fw
->status
== INTEL_UC_FIRMWARE_UNINITIALIZED
);
178 return uc_fw
->status
;
181 static inline bool intel_uc_fw_is_supported(struct intel_uc_fw
*uc_fw
)
183 return __intel_uc_fw_status(uc_fw
) != INTEL_UC_FIRMWARE_NOT_SUPPORTED
;
186 static inline bool intel_uc_fw_is_enabled(struct intel_uc_fw
*uc_fw
)
188 return __intel_uc_fw_status(uc_fw
) > INTEL_UC_FIRMWARE_DISABLED
;
191 static inline bool intel_uc_fw_is_available(struct intel_uc_fw
*uc_fw
)
193 return __intel_uc_fw_status(uc_fw
) >= INTEL_UC_FIRMWARE_AVAILABLE
;
196 static inline bool intel_uc_fw_is_loadable(struct intel_uc_fw
*uc_fw
)
198 return __intel_uc_fw_status(uc_fw
) >= INTEL_UC_FIRMWARE_LOADABLE
;
201 static inline bool intel_uc_fw_is_loaded(struct intel_uc_fw
*uc_fw
)
203 return __intel_uc_fw_status(uc_fw
) >= INTEL_UC_FIRMWARE_TRANSFERRED
;
206 static inline bool intel_uc_fw_is_running(struct intel_uc_fw
*uc_fw
)
208 return __intel_uc_fw_status(uc_fw
) == INTEL_UC_FIRMWARE_RUNNING
;
211 static inline bool intel_uc_fw_is_overridden(const struct intel_uc_fw
*uc_fw
)
213 return uc_fw
->user_overridden
;
216 static inline void intel_uc_fw_sanitize(struct intel_uc_fw
*uc_fw
)
218 if (intel_uc_fw_is_loaded(uc_fw
))
219 intel_uc_fw_change_status(uc_fw
, INTEL_UC_FIRMWARE_LOADABLE
);
222 static inline u32
__intel_uc_fw_get_upload_size(struct intel_uc_fw
*uc_fw
)
224 return sizeof(struct uc_css_header
) + uc_fw
->ucode_size
;
228 * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
229 * @uc_fw: uC firmware.
231 * Get the size of the firmware and header that will be uploaded to WOPCM.
233 * Return: Upload firmware size, or zero on firmware fetch failure.
235 static inline u32
intel_uc_fw_get_upload_size(struct intel_uc_fw
*uc_fw
)
237 if (!intel_uc_fw_is_available(uc_fw
))
240 return __intel_uc_fw_get_upload_size(uc_fw
);
243 void intel_uc_fw_init_early(struct intel_uc_fw
*uc_fw
,
244 enum intel_uc_fw_type type
);
245 int intel_uc_fw_fetch(struct intel_uc_fw
*uc_fw
);
246 void intel_uc_fw_cleanup_fetch(struct intel_uc_fw
*uc_fw
);
247 int intel_uc_fw_upload(struct intel_uc_fw
*uc_fw
, u32 offset
, u32 dma_flags
);
248 int intel_uc_fw_init(struct intel_uc_fw
*uc_fw
);
249 void intel_uc_fw_fini(struct intel_uc_fw
*uc_fw
);
250 size_t intel_uc_fw_copy_rsa(struct intel_uc_fw
*uc_fw
, void *dst
, u32 max_len
);
251 void intel_uc_fw_dump(const struct intel_uc_fw
*uc_fw
, struct drm_printer
*p
);