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 |
33 * | | /------> AVAILABLE <---<-----------\ |
34 * +------------+- \ / \ \ \ -+
35 * | | FAIL <--< \--> TRANSFERRED \ |
36 * | upload | \ / \ / |
37 * | | \---------/ \--> RUNNING |
38 * +------------+---------------------------------------------------+
41 enum intel_uc_fw_status
{
42 INTEL_UC_FIRMWARE_NOT_SUPPORTED
= -1, /* no uc HW */
43 INTEL_UC_FIRMWARE_UNINITIALIZED
= 0, /* used to catch checks done too early */
44 INTEL_UC_FIRMWARE_DISABLED
, /* disabled */
45 INTEL_UC_FIRMWARE_SELECTED
, /* selected the blob we want to load */
46 INTEL_UC_FIRMWARE_MISSING
, /* blob not found on the system */
47 INTEL_UC_FIRMWARE_ERROR
, /* invalid format or version */
48 INTEL_UC_FIRMWARE_AVAILABLE
, /* blob found and copied in mem */
49 INTEL_UC_FIRMWARE_FAIL
, /* failed to xfer or init/auth the fw */
50 INTEL_UC_FIRMWARE_TRANSFERRED
, /* dma xfer done */
51 INTEL_UC_FIRMWARE_RUNNING
/* init/auth done */
54 enum intel_uc_fw_type
{
55 INTEL_UC_FW_TYPE_GUC
= 0,
58 #define INTEL_UC_FW_NUM_TYPES 2
61 * This structure encapsulates all the data needed during the process
62 * of fetching, caching, and loading the firmware image into the uC.
65 enum intel_uc_fw_type type
;
67 const enum intel_uc_fw_status status
;
68 enum intel_uc_fw_status __status
; /* no accidental overwrites */
73 struct drm_i915_gem_object
*obj
;
76 * The firmware build process will generate a version header file with major and
77 * minor version defined. The versions are built into CSS header of firmware.
78 * i915 kernel driver set the minimal firmware version required per platform.
89 #ifdef CONFIG_DRM_I915_DEBUG_GUC
90 void intel_uc_fw_change_status(struct intel_uc_fw
*uc_fw
,
91 enum intel_uc_fw_status status
);
93 static inline void intel_uc_fw_change_status(struct intel_uc_fw
*uc_fw
,
94 enum intel_uc_fw_status status
)
96 uc_fw
->__status
= status
;
101 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status
)
104 case INTEL_UC_FIRMWARE_NOT_SUPPORTED
:
106 case INTEL_UC_FIRMWARE_UNINITIALIZED
:
107 return "UNINITIALIZED";
108 case INTEL_UC_FIRMWARE_DISABLED
:
110 case INTEL_UC_FIRMWARE_SELECTED
:
112 case INTEL_UC_FIRMWARE_MISSING
:
114 case INTEL_UC_FIRMWARE_ERROR
:
116 case INTEL_UC_FIRMWARE_AVAILABLE
:
118 case INTEL_UC_FIRMWARE_FAIL
:
120 case INTEL_UC_FIRMWARE_TRANSFERRED
:
121 return "TRANSFERRED";
122 case INTEL_UC_FIRMWARE_RUNNING
:
128 static inline int intel_uc_fw_status_to_error(enum intel_uc_fw_status status
)
131 case INTEL_UC_FIRMWARE_NOT_SUPPORTED
:
133 case INTEL_UC_FIRMWARE_UNINITIALIZED
:
135 case INTEL_UC_FIRMWARE_DISABLED
:
137 case INTEL_UC_FIRMWARE_MISSING
:
139 case INTEL_UC_FIRMWARE_ERROR
:
141 case INTEL_UC_FIRMWARE_FAIL
:
143 case INTEL_UC_FIRMWARE_SELECTED
:
145 case INTEL_UC_FIRMWARE_AVAILABLE
:
146 case INTEL_UC_FIRMWARE_TRANSFERRED
:
147 case INTEL_UC_FIRMWARE_RUNNING
:
153 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type
)
156 case INTEL_UC_FW_TYPE_GUC
:
158 case INTEL_UC_FW_TYPE_HUC
:
164 static inline enum intel_uc_fw_status
165 __intel_uc_fw_status(struct intel_uc_fw
*uc_fw
)
167 /* shouldn't call this before checking hw/blob availability */
168 GEM_BUG_ON(uc_fw
->status
== INTEL_UC_FIRMWARE_UNINITIALIZED
);
169 return uc_fw
->status
;
172 static inline bool intel_uc_fw_is_supported(struct intel_uc_fw
*uc_fw
)
174 return __intel_uc_fw_status(uc_fw
) != INTEL_UC_FIRMWARE_NOT_SUPPORTED
;
177 static inline bool intel_uc_fw_is_enabled(struct intel_uc_fw
*uc_fw
)
179 return __intel_uc_fw_status(uc_fw
) > INTEL_UC_FIRMWARE_DISABLED
;
182 static inline bool intel_uc_fw_is_available(struct intel_uc_fw
*uc_fw
)
184 return __intel_uc_fw_status(uc_fw
) >= INTEL_UC_FIRMWARE_AVAILABLE
;
187 static inline bool intel_uc_fw_is_loaded(struct intel_uc_fw
*uc_fw
)
189 return __intel_uc_fw_status(uc_fw
) >= INTEL_UC_FIRMWARE_TRANSFERRED
;
192 static inline bool intel_uc_fw_is_running(struct intel_uc_fw
*uc_fw
)
194 return __intel_uc_fw_status(uc_fw
) == INTEL_UC_FIRMWARE_RUNNING
;
197 static inline bool intel_uc_fw_is_overridden(const struct intel_uc_fw
*uc_fw
)
199 return uc_fw
->user_overridden
;
202 static inline void intel_uc_fw_sanitize(struct intel_uc_fw
*uc_fw
)
204 if (intel_uc_fw_is_loaded(uc_fw
))
205 intel_uc_fw_change_status(uc_fw
, INTEL_UC_FIRMWARE_AVAILABLE
);
208 static inline u32
__intel_uc_fw_get_upload_size(struct intel_uc_fw
*uc_fw
)
210 return sizeof(struct uc_css_header
) + uc_fw
->ucode_size
;
214 * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
215 * @uc_fw: uC firmware.
217 * Get the size of the firmware and header that will be uploaded to WOPCM.
219 * Return: Upload firmware size, or zero on firmware fetch failure.
221 static inline u32
intel_uc_fw_get_upload_size(struct intel_uc_fw
*uc_fw
)
223 if (!intel_uc_fw_is_available(uc_fw
))
226 return __intel_uc_fw_get_upload_size(uc_fw
);
229 void intel_uc_fw_init_early(struct intel_uc_fw
*uc_fw
,
230 enum intel_uc_fw_type type
, bool supported
,
231 enum intel_platform platform
, u8 rev
);
232 int intel_uc_fw_fetch(struct intel_uc_fw
*uc_fw
);
233 void intel_uc_fw_cleanup_fetch(struct intel_uc_fw
*uc_fw
);
234 int intel_uc_fw_upload(struct intel_uc_fw
*uc_fw
, u32 offset
, u32 dma_flags
);
235 int intel_uc_fw_init(struct intel_uc_fw
*uc_fw
);
236 void intel_uc_fw_fini(struct intel_uc_fw
*uc_fw
);
237 size_t intel_uc_fw_copy_rsa(struct intel_uc_fw
*uc_fw
, void *dst
, u32 max_len
);
238 void intel_uc_fw_dump(const struct intel_uc_fw
*uc_fw
, struct drm_printer
*p
);