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/sizes.h>
10 #include <linux/types.h>
11 #include "intel_uc_fw_abi.h"
12 #include "intel_device_info.h"
17 struct drm_i915_private;
20 /* Home of GuC, HuC and DMC firmwares */
21 #define INTEL_UC_FIRMWARE_URL "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915"
24 * +------------+---------------------------------------------------+
25 * | PHASE | FIRMWARE STATUS TRANSITIONS |
26 * +============+===================================================+
28 * +------------+- / | \ -+
29 * | | DISABLED <--/ | \--> NOT_SUPPORTED |
32 * +------------+- / | \ -+
33 * | | MISSING <--/ | \--> ERROR |
36 * +------------+- | \ -+
37 * | | | \--> INIT FAIL |
39 * | | /------> LOADABLE <----<-----------\ |
40 * +------------+- \ / \ \ \ -+
41 * | | LOAD FAIL <--< \--> TRANSFERRED \ |
42 * | upload | \ / \ / |
43 * | | \---------/ \--> RUNNING |
44 * +------------+---------------------------------------------------+
47 enum intel_uc_fw_status {
48 INTEL_UC_FIRMWARE_NOT_SUPPORTED = -1, /* no uc HW */
49 INTEL_UC_FIRMWARE_UNINITIALIZED = 0, /* used to catch checks done too early */
50 INTEL_UC_FIRMWARE_DISABLED, /* disabled */
51 INTEL_UC_FIRMWARE_SELECTED, /* selected the blob we want to load */
52 INTEL_UC_FIRMWARE_MISSING, /* blob not found on the system */
53 INTEL_UC_FIRMWARE_ERROR, /* invalid format or version */
54 INTEL_UC_FIRMWARE_AVAILABLE, /* blob found and copied in mem */
55 INTEL_UC_FIRMWARE_INIT_FAIL, /* failed to prepare fw objects for load */
56 INTEL_UC_FIRMWARE_LOADABLE, /* all fw-required objects are ready */
57 INTEL_UC_FIRMWARE_LOAD_FAIL, /* failed to xfer or init/auth the fw */
58 INTEL_UC_FIRMWARE_TRANSFERRED, /* dma xfer done */
59 INTEL_UC_FIRMWARE_RUNNING /* init/auth done */
62 enum intel_uc_fw_type {
63 INTEL_UC_FW_TYPE_GUC = 0,
67 #define INTEL_UC_FW_NUM_TYPES 3
69 struct intel_uc_fw_ver {
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.
80 struct intel_uc_fw_file {
82 struct intel_uc_fw_ver ver;
86 * This structure encapsulates all the data needed during the process
87 * of fetching, caching, and loading the firmware image into the uC.
90 enum intel_uc_fw_type type;
92 const enum intel_uc_fw_status status;
93 enum intel_uc_fw_status __status; /* no accidental overwrites */
95 struct intel_uc_fw_file file_wanted;
96 struct intel_uc_fw_file file_selected;
99 struct drm_i915_gem_object *obj;
102 * @needs_ggtt_mapping: indicates whether the fw object needs to be
103 * pinned to ggtt. If true, the fw is pinned at init time and unpinned
104 * during driver unload.
106 bool needs_ggtt_mapping;
109 * @vma_res: A vma resource used in binding the uc fw to ggtt. The fw is
110 * pinned in a reserved area of the ggtt (above the maximum address
111 * usable by GuC); therefore, we can't use the normal vma functions to
112 * do the pinning and we instead use this resource to do so.
114 struct i915_vma_resource vma_res;
115 struct i915_vma *rsa_data;
119 u32 private_data_size;
121 u32 dma_start_offset;
127 * When we load the uC binaries, we pin them in a reserved section at the top of
128 * the GGTT, which is ~18 MBs. On multi-GT systems where the GTs share the GGTT,
129 * we also need to make sure that each binary is pinned to a unique location
130 * during load, because the different GT can go through the FW load at the same
131 * time (see uc_fw_ggtt_offset() for details).
132 * Given that the available space is much greater than what is required by the
133 * binaries, to keep things simple instead of dynamically partitioning the
134 * reserved section to make space for all the blobs we can just reserve a static
135 * chunk for each binary.
137 #define INTEL_UC_RSVD_GGTT_PER_FW SZ_2M
139 #ifdef CONFIG_DRM_I915_DEBUG_GUC
140 void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
141 enum intel_uc_fw_status status);
143 static inline void intel_uc_fw_change_status(struct intel_uc_fw *uc_fw,
144 enum intel_uc_fw_status status)
146 uc_fw->__status = status;
151 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
154 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
156 case INTEL_UC_FIRMWARE_UNINITIALIZED:
157 return "UNINITIALIZED";
158 case INTEL_UC_FIRMWARE_DISABLED:
160 case INTEL_UC_FIRMWARE_SELECTED:
162 case INTEL_UC_FIRMWARE_MISSING:
164 case INTEL_UC_FIRMWARE_ERROR:
166 case INTEL_UC_FIRMWARE_AVAILABLE:
168 case INTEL_UC_FIRMWARE_INIT_FAIL:
170 case INTEL_UC_FIRMWARE_LOADABLE:
172 case INTEL_UC_FIRMWARE_LOAD_FAIL:
174 case INTEL_UC_FIRMWARE_TRANSFERRED:
175 return "TRANSFERRED";
176 case INTEL_UC_FIRMWARE_RUNNING:
182 static inline int intel_uc_fw_status_to_error(enum intel_uc_fw_status status)
185 case INTEL_UC_FIRMWARE_NOT_SUPPORTED:
187 case INTEL_UC_FIRMWARE_UNINITIALIZED:
189 case INTEL_UC_FIRMWARE_DISABLED:
191 case INTEL_UC_FIRMWARE_MISSING:
193 case INTEL_UC_FIRMWARE_ERROR:
195 case INTEL_UC_FIRMWARE_INIT_FAIL:
196 case INTEL_UC_FIRMWARE_LOAD_FAIL:
198 case INTEL_UC_FIRMWARE_SELECTED:
200 case INTEL_UC_FIRMWARE_AVAILABLE:
201 case INTEL_UC_FIRMWARE_LOADABLE:
202 case INTEL_UC_FIRMWARE_TRANSFERRED:
203 case INTEL_UC_FIRMWARE_RUNNING:
209 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type)
212 case INTEL_UC_FW_TYPE_GUC:
214 case INTEL_UC_FW_TYPE_HUC:
216 case INTEL_UC_FW_TYPE_GSC:
222 static inline enum intel_uc_fw_status
223 __intel_uc_fw_status(struct intel_uc_fw *uc_fw)
225 /* shouldn't call this before checking hw/blob availability */
226 GEM_BUG_ON(uc_fw->status == INTEL_UC_FIRMWARE_UNINITIALIZED);
227 return uc_fw->status;
230 static inline bool intel_uc_fw_is_supported(struct intel_uc_fw *uc_fw)
232 return __intel_uc_fw_status(uc_fw) != INTEL_UC_FIRMWARE_NOT_SUPPORTED;
235 static inline bool intel_uc_fw_is_enabled(struct intel_uc_fw *uc_fw)
237 return __intel_uc_fw_status(uc_fw) > INTEL_UC_FIRMWARE_DISABLED;
240 static inline bool intel_uc_fw_is_available(struct intel_uc_fw *uc_fw)
242 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_AVAILABLE;
245 static inline bool intel_uc_fw_is_loadable(struct intel_uc_fw *uc_fw)
247 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_LOADABLE;
250 static inline bool intel_uc_fw_is_loaded(struct intel_uc_fw *uc_fw)
252 return __intel_uc_fw_status(uc_fw) >= INTEL_UC_FIRMWARE_TRANSFERRED;
255 static inline bool intel_uc_fw_is_running(struct intel_uc_fw *uc_fw)
257 return __intel_uc_fw_status(uc_fw) == INTEL_UC_FIRMWARE_RUNNING;
260 static inline bool intel_uc_fw_is_overridden(const struct intel_uc_fw *uc_fw)
262 return uc_fw->user_overridden;
265 static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw)
267 if (intel_uc_fw_is_loaded(uc_fw))
268 intel_uc_fw_change_status(uc_fw, INTEL_UC_FIRMWARE_LOADABLE);
271 static inline u32 __intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
273 return sizeof(struct uc_css_header) + uc_fw->ucode_size;
277 * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
278 * @uc_fw: uC firmware.
280 * Get the size of the firmware and header that will be uploaded to WOPCM.
282 * Return: Upload firmware size, or zero on firmware fetch failure.
284 static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
286 if (!intel_uc_fw_is_available(uc_fw))
289 return __intel_uc_fw_get_upload_size(uc_fw);
292 void intel_uc_fw_init_early(struct intel_uc_fw *uc_fw,
293 enum intel_uc_fw_type type,
294 bool needs_ggtt_mapping);
295 int intel_uc_fw_fetch(struct intel_uc_fw *uc_fw);
296 void intel_uc_fw_cleanup_fetch(struct intel_uc_fw *uc_fw);
297 int intel_uc_fw_upload(struct intel_uc_fw *uc_fw, u32 offset, u32 dma_flags);
298 int intel_uc_fw_init(struct intel_uc_fw *uc_fw);
299 void intel_uc_fw_fini(struct intel_uc_fw *uc_fw);
300 void intel_uc_fw_resume_mapping(struct intel_uc_fw *uc_fw);
301 size_t intel_uc_fw_copy_rsa(struct intel_uc_fw *uc_fw, void *dst, u32 max_len);
302 int intel_uc_fw_mark_load_failed(struct intel_uc_fw *uc_fw, int err);
303 void intel_uc_fw_dump(const struct intel_uc_fw *uc_fw, struct drm_printer *p);