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 */
80 struct drm_i915_gem_object *obj;
82 * @dummy: A vma used in binding the uc fw to ggtt. We can't define this
83 * vma on the stack as it can lead to a stack overflow, so we define it
84 * here. Safe to have 1 copy per uc fw because the binding is single
85 * threaded as it done during driver load (inherently single threaded)
86 * or during a GT reset (mutex guarantees single threaded).
88 struct i915_vma_resource dummy;
89 struct i915_vma *rsa_data;
92 * The firmware build process will generate a version header file with major and
93 * minor version defined. The versions are built into CSS header of firmware.
94 * i915 kernel driver set the minimal firmware version required per platform.
104 u32 private_data_size;
107 #ifdef CONFIG_DRM_I915_DEBUG_GUC
108 void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
109 enum intel_uc_fw_status status);
111 static inline void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
112 enum intel_uc_fw_status status)
114 uc_fw->__status = status;
119 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
122 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
124 case INTEL_UC_FIRMWARE_UNINITIALIZED:
125 return "UNINITIALIZED";
126 case INTEL_UC_FIRMWARE_DISABLED:
128 case INTEL_UC_FIRMWARE_SELECTED:
130 case INTEL_UC_FIRMWARE_MISSING:
132 case INTEL_UC_FIRMWARE_ERROR:
134 case INTEL_UC_FIRMWARE_AVAILABLE:
136 case INTEL_UC_FIRMWARE_INIT_FAIL:
138 case INTEL_UC_FIRMWARE_LOADABLE:
140 case INTEL_UC_FIRMWARE_LOAD_FAIL:
142 case INTEL_UC_FIRMWARE_TRANSFERRED:
143 return "TRANSFERRED";
144 case INTEL_UC_FIRMWARE_RUNNING:
150 static inline int intel_uc_fw_status_to_error(enum intel_uc_fw_status status)
153 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
155 case INTEL_UC_FIRMWARE_UNINITIALIZED:
157 case INTEL_UC_FIRMWARE_DISABLED:
159 case INTEL_UC_FIRMWARE_MISSING:
161 case INTEL_UC_FIRMWARE_ERROR:
163 case INTEL_UC_FIRMWARE_INIT_FAIL:
164 case INTEL_UC_FIRMWARE_LOAD_FAIL:
166 case INTEL_UC_FIRMWARE_SELECTED:
168 case INTEL_UC_FIRMWARE_AVAILABLE:
169 case INTEL_UC_FIRMWARE_LOADABLE:
170 case INTEL_UC_FIRMWARE_TRANSFERRED:
171 case INTEL_UC_FIRMWARE_RUNNING:
177 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type)
180 case INTEL_UC_FW_TYPE_GUC:
182 case INTEL_UC_FW_TYPE_HUC:
188 static inline enum intel_uc_fw_status
189 __intel_uc_fw_status(struct intel_uc_fw *uc_fw)
191 /* shouldn't call this before checking hw/blob availability */
192 GEM_BUG_ON(uc_fw->status == INTEL_UC_FIRMWARE_UNINITIALIZED);
193 return uc_fw->status;
196 static inline bool intel_uc_fw_is_supported(struct intel_uc_fw *uc_fw)
198 return __intel_uc_fw_status(uc_fw) != INTEL_UC_FIRMWARE_NOT_SUPPORTED;
201 static inline bool intel_uc_fw_is_enabled(struct intel_uc_fw *uc_fw)
203 return __intel_uc_fw_status(uc_fw) > INTEL_UC_FIRMWARE_DISABLED;
206 static inline bool intel_uc_fw_is_available(struct intel_uc_fw *uc_fw)
208 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_AVAILABLE;
211 static inline bool intel_uc_fw_is_loadable(struct intel_uc_fw *uc_fw)
213 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_LOADABLE;
216 static inline bool intel_uc_fw_is_loaded(struct intel_uc_fw *uc_fw)
218 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_TRANSFERRED;
221 static inline bool intel_uc_fw_is_running(struct intel_uc_fw *uc_fw)
223 return __intel_uc_fw_status(uc_fw) == INTEL_UC_FIRMWARE_RUNNING;
226 static inline bool intel_uc_fw_is_overridden(const struct intel_uc_fw *uc_fw)
228 return uc_fw->user_overridden;
231 static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw)
233 if (intel_uc_fw_is_loaded(uc_fw))
234 intel_uc_fw_change_status(uc_fw, INTEL_UC_FIRMWARE_LOADABLE);
237 static inline u32 __intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
239 return sizeof(struct uc_css_header) + uc_fw->ucode_size;
243 * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
244 * @uc_fw: uC firmware.
246 * Get the size of the firmware and header that will be uploaded to WOPCM.
248 * Return: Upload firmware size, or zero on firmware fetch failure.
250 static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
252 if (!intel_uc_fw_is_available(uc_fw))
255 return __intel_uc_fw_get_upload_size(uc_fw);
258 void intel_uc_fw_init_early(struct intel_uc_fw *uc_fw,
259 enum intel_uc_fw_type type);
260 int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw);
261 void intel_uc_fw_cleanup_fetch(struct intel_uc_fw *uc_fw);
262 int intel_uc_fw_upload(struct intel_uc_fw *uc_fw, u32 offset, u32 dma_flags);
263 int intel_uc_fw_init(struct intel_uc_fw *uc_fw);
264 void intel_uc_fw_fini(struct intel_uc_fw *uc_fw);
265 size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len);
266 void intel_uc_fw_dump(const struct intel_uc_fw *uc_fw, struct drm_printer *p);