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"
16 struct drm_i915_private;
19 /* Home of GuC, HuC and DMC firmwares */
20 #define INTEL_UC_FIRMWARE_URL "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915"
23 * +------------+---------------------------------------------------+
24 * | PHASE | FIRMWARE STATUS TRANSITIONS |
25 * +============+===================================================+
27 * +------------+- / | \ -+
28 * | | DISABLED <--/ | \--> NOT_SUPPORTED |
31 * +------------+- / | \ -+
32 * | | MISSING <--/ | \--> ERROR |
35 * +------------+- | \ -+
36 * | | | \--> INIT FAIL |
38 * | | /------> LOADABLE <----<-----------\ |
39 * +------------+- \ / \ \ \ -+
40 * | | LOAD FAIL <--< \--> TRANSFERRED \ |
41 * | upload | \ / \ / |
42 * | | \---------/ \--> RUNNING |
43 * +------------+---------------------------------------------------+
46 enum intel_uc_fw_status {
47 INTEL_UC_FIRMWARE_NOT_SUPPORTED = -1, /* no uc HW */
48 INTEL_UC_FIRMWARE_UNINITIALIZED = 0, /* used to catch checks done too early */
49 INTEL_UC_FIRMWARE_DISABLED, /* disabled */
50 INTEL_UC_FIRMWARE_SELECTED, /* selected the blob we want to load */
51 INTEL_UC_FIRMWARE_MISSING, /* blob not found on the system */
52 INTEL_UC_FIRMWARE_ERROR, /* invalid format or version */
53 INTEL_UC_FIRMWARE_AVAILABLE, /* blob found and copied in mem */
54 INTEL_UC_FIRMWARE_INIT_FAIL, /* failed to prepare fw objects for load */
55 INTEL_UC_FIRMWARE_LOADABLE, /* all fw-required objects are ready */
56 INTEL_UC_FIRMWARE_LOAD_FAIL, /* failed to xfer or init/auth the fw */
57 INTEL_UC_FIRMWARE_TRANSFERRED, /* dma xfer done */
58 INTEL_UC_FIRMWARE_RUNNING /* init/auth done */
61 enum intel_uc_fw_type {
62 INTEL_UC_FW_TYPE_GUC = 0,
65 #define INTEL_UC_FW_NUM_TYPES 2
68 * This structure encapsulates all the data needed during the process
69 * of fetching, caching, and loading the firmware image into the uC.
72 enum intel_uc_fw_type type;
74 const enum intel_uc_fw_status status;
75 enum intel_uc_fw_status __status; /* no accidental overwrites */
77 const char *wanted_path;
81 struct drm_i915_gem_object *obj;
83 * @dummy: A vma used in binding the uc fw to ggtt. We can't define this
84 * vma on the stack as it can lead to a stack overflow, so we define it
85 * here. Safe to have 1 copy per uc fw because the binding is single
86 * threaded as it done during driver load (inherently single threaded)
87 * or during a GT reset (mutex guarantees single threaded).
89 struct i915_vma_resource dummy;
90 struct i915_vma *rsa_data;
93 * The firmware build process will generate a version header file with major and
94 * minor version defined. The versions are built into CSS header of firmware.
95 * i915 kernel driver set the minimal firmware version required per platform.
111 u32 private_data_size;
116 #ifdef CONFIG_DRM_I915_DEBUG_GUC
117 void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
118 enum intel_uc_fw_status status);
120 static inline void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
121 enum intel_uc_fw_status status)
123 uc_fw->__status = status;
128 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
131 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
133 case INTEL_UC_FIRMWARE_UNINITIALIZED:
134 return "UNINITIALIZED";
135 case INTEL_UC_FIRMWARE_DISABLED:
137 case INTEL_UC_FIRMWARE_SELECTED:
139 case INTEL_UC_FIRMWARE_MISSING:
141 case INTEL_UC_FIRMWARE_ERROR:
143 case INTEL_UC_FIRMWARE_AVAILABLE:
145 case INTEL_UC_FIRMWARE_INIT_FAIL:
147 case INTEL_UC_FIRMWARE_LOADABLE:
149 case INTEL_UC_FIRMWARE_LOAD_FAIL:
151 case INTEL_UC_FIRMWARE_TRANSFERRED:
152 return "TRANSFERRED";
153 case INTEL_UC_FIRMWARE_RUNNING:
159 static inline int intel_uc_fw_status_to_error(enum intel_uc_fw_status status)
162 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
164 case INTEL_UC_FIRMWARE_UNINITIALIZED:
166 case INTEL_UC_FIRMWARE_DISABLED:
168 case INTEL_UC_FIRMWARE_MISSING:
170 case INTEL_UC_FIRMWARE_ERROR:
172 case INTEL_UC_FIRMWARE_INIT_FAIL:
173 case INTEL_UC_FIRMWARE_LOAD_FAIL:
175 case INTEL_UC_FIRMWARE_SELECTED:
177 case INTEL_UC_FIRMWARE_AVAILABLE:
178 case INTEL_UC_FIRMWARE_LOADABLE:
179 case INTEL_UC_FIRMWARE_TRANSFERRED:
180 case INTEL_UC_FIRMWARE_RUNNING:
186 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type)
189 case INTEL_UC_FW_TYPE_GUC:
191 case INTEL_UC_FW_TYPE_HUC:
197 static inline enum intel_uc_fw_status
198 __intel_uc_fw_status(struct intel_uc_fw *uc_fw)
200 /* shouldn't call this before checking hw/blob availability */
201 GEM_BUG_ON(uc_fw->status == INTEL_UC_FIRMWARE_UNINITIALIZED);
202 return uc_fw->status;
205 static inline bool intel_uc_fw_is_supported(struct intel_uc_fw *uc_fw)
207 return __intel_uc_fw_status(uc_fw) != INTEL_UC_FIRMWARE_NOT_SUPPORTED;
210 static inline bool intel_uc_fw_is_enabled(struct intel_uc_fw *uc_fw)
212 return __intel_uc_fw_status(uc_fw) > INTEL_UC_FIRMWARE_DISABLED;
215 static inline bool intel_uc_fw_is_available(struct intel_uc_fw *uc_fw)
217 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_AVAILABLE;
220 static inline bool intel_uc_fw_is_loadable(struct intel_uc_fw *uc_fw)
222 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_LOADABLE;
225 static inline bool intel_uc_fw_is_loaded(struct intel_uc_fw *uc_fw)
227 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_TRANSFERRED;
230 static inline bool intel_uc_fw_is_running(struct intel_uc_fw *uc_fw)
232 return __intel_uc_fw_status(uc_fw) == INTEL_UC_FIRMWARE_RUNNING;
235 static inline bool intel_uc_fw_is_overridden(const struct intel_uc_fw *uc_fw)
237 return uc_fw->user_overridden;
240 static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw)
242 if (intel_uc_fw_is_loaded(uc_fw))
243 intel_uc_fw_change_status(uc_fw, INTEL_UC_FIRMWARE_LOADABLE);
246 static inline u32 __intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
248 return sizeof(struct uc_css_header) + uc_fw->ucode_size;
252 * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
253 * @uc_fw: uC firmware.
255 * Get the size of the firmware and header that will be uploaded to WOPCM.
257 * Return: Upload firmware size, or zero on firmware fetch failure.
259 static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
261 if (!intel_uc_fw_is_available(uc_fw))
264 return __intel_uc_fw_get_upload_size(uc_fw);
267 void intel_uc_fw_init_early(struct intel_uc_fw *uc_fw,
268 enum intel_uc_fw_type type);
269 int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw);
270 void intel_uc_fw_cleanup_fetch(struct intel_uc_fw *uc_fw);
271 int intel_uc_fw_upload(struct intel_uc_fw *uc_fw, u32 offset, u32 dma_flags);
272 int intel_uc_fw_init(struct intel_uc_fw *uc_fw);
273 void intel_uc_fw_fini(struct intel_uc_fw *uc_fw);
274 size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len);
275 void intel_uc_fw_dump(const struct intel_uc_fw *uc_fw, struct drm_printer *p);