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 "/*(DEBLOBBED)*/"
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.
93 #ifdef CONFIG_DRM_I915_DEBUG_GUC
94 void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
95 enum intel_uc_fw_status status);
97 static inline void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
98 enum intel_uc_fw_status status)
100 uc_fw->__status = status;
105 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
108 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
110 case INTEL_UC_FIRMWARE_UNINITIALIZED:
111 return "UNINITIALIZED";
112 case INTEL_UC_FIRMWARE_DISABLED:
114 case INTEL_UC_FIRMWARE_SELECTED:
116 case INTEL_UC_FIRMWARE_MISSING:
118 case INTEL_UC_FIRMWARE_ERROR:
120 case INTEL_UC_FIRMWARE_AVAILABLE:
122 case INTEL_UC_FIRMWARE_LOADABLE:
124 case INTEL_UC_FIRMWARE_FAIL:
126 case INTEL_UC_FIRMWARE_TRANSFERRED:
127 return "TRANSFERRED";
128 case INTEL_UC_FIRMWARE_RUNNING:
134 static inline int intel_uc_fw_status_to_error(enum intel_uc_fw_status status)
137 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
139 case INTEL_UC_FIRMWARE_UNINITIALIZED:
141 case INTEL_UC_FIRMWARE_DISABLED:
143 case INTEL_UC_FIRMWARE_MISSING:
145 case INTEL_UC_FIRMWARE_ERROR:
147 case INTEL_UC_FIRMWARE_FAIL:
149 case INTEL_UC_FIRMWARE_SELECTED:
151 case INTEL_UC_FIRMWARE_AVAILABLE:
152 case INTEL_UC_FIRMWARE_LOADABLE:
153 case INTEL_UC_FIRMWARE_TRANSFERRED:
154 case INTEL_UC_FIRMWARE_RUNNING:
160 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type)
163 case INTEL_UC_FW_TYPE_GUC:
165 case INTEL_UC_FW_TYPE_HUC:
171 static inline enum intel_uc_fw_status
172 __intel_uc_fw_status(struct intel_uc_fw *uc_fw)
174 /* shouldn't call this before checking hw/blob availability */
175 GEM_BUG_ON(uc_fw->status == INTEL_UC_FIRMWARE_UNINITIALIZED);
176 return uc_fw->status;
179 static inline bool intel_uc_fw_is_supported(struct intel_uc_fw *uc_fw)
181 return __intel_uc_fw_status(uc_fw) != INTEL_UC_FIRMWARE_NOT_SUPPORTED;
184 static inline bool intel_uc_fw_is_enabled(struct intel_uc_fw *uc_fw)
186 return __intel_uc_fw_status(uc_fw) > INTEL_UC_FIRMWARE_DISABLED;
189 static inline bool intel_uc_fw_is_available(struct intel_uc_fw *uc_fw)
191 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_AVAILABLE;
194 static inline bool intel_uc_fw_is_loadable(struct intel_uc_fw *uc_fw)
196 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_LOADABLE;
199 static inline bool intel_uc_fw_is_loaded(struct intel_uc_fw *uc_fw)
201 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_TRANSFERRED;
204 static inline bool intel_uc_fw_is_running(struct intel_uc_fw *uc_fw)
206 return __intel_uc_fw_status(uc_fw) == INTEL_UC_FIRMWARE_RUNNING;
209 static inline bool intel_uc_fw_is_overridden(const struct intel_uc_fw *uc_fw)
211 return uc_fw->user_overridden;
214 static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw)
216 if (intel_uc_fw_is_loaded(uc_fw))
217 intel_uc_fw_change_status(uc_fw, INTEL_UC_FIRMWARE_LOADABLE);
220 static inline u32 __intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
222 return sizeof(struct uc_css_header) + uc_fw->ucode_size;
226 * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
227 * @uc_fw: uC firmware.
229 * Get the size of the firmware and header that will be uploaded to WOPCM.
231 * Return: Upload firmware size, or zero on firmware fetch failure.
233 static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
235 if (!intel_uc_fw_is_available(uc_fw))
238 return __intel_uc_fw_get_upload_size(uc_fw);
241 void intel_uc_fw_init_early(struct intel_uc_fw *uc_fw,
242 enum intel_uc_fw_type type);
243 int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw);
244 void intel_uc_fw_cleanup_fetch(struct intel_uc_fw *uc_fw);
245 int intel_uc_fw_upload(struct intel_uc_fw *uc_fw, u32 offset, u32 dma_flags);
246 int intel_uc_fw_init(struct intel_uc_fw *uc_fw);
247 void intel_uc_fw_fini(struct intel_uc_fw *uc_fw);
248 size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len);
249 void intel_uc_fw_dump(const struct intel_uc_fw *uc_fw, struct drm_printer *p);