summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/xe/xe_uc_fw.h
blob: c108e9d08e7085b29cf5db069b1c0f337de00fa0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* SPDX-License-Identifier: MIT */
/*
 * Copyright © 2022 Intel Corporation
 */

#ifndef _XE_UC_FW_H_
#define _XE_UC_FW_H_

#include <linux/errno.h>

#include "xe_macros.h"
#include "xe_uc_fw_abi.h"
#include "xe_uc_fw_types.h"

struct drm_printer;

int xe_uc_fw_init(struct xe_uc_fw *uc_fw);
size_t xe_uc_fw_copy_rsa(struct xe_uc_fw *uc_fw, void *dst, u32 max_len);
int xe_uc_fw_upload(struct xe_uc_fw *uc_fw, u32 offset, u32 dma_flags);
int xe_uc_fw_check_version_requirements(struct xe_uc_fw *uc_fw);
void xe_uc_fw_print(struct xe_uc_fw *uc_fw, struct drm_printer *p);

static inline u32 xe_uc_fw_rsa_offset(struct xe_uc_fw *uc_fw)
{
	return sizeof(struct uc_css_header) + uc_fw->ucode_size + uc_fw->css_offset;
}

static inline void xe_uc_fw_change_status(struct xe_uc_fw *uc_fw,
					  enum xe_uc_fw_status status)
{
	uc_fw->__status = status;
}

static inline
const char *xe_uc_fw_status_repr(enum xe_uc_fw_status status)
{
	switch (status) {
	case XE_UC_FIRMWARE_NOT_SUPPORTED:
		return "N/A";
	case XE_UC_FIRMWARE_UNINITIALIZED:
		return "UNINITIALIZED";
	case XE_UC_FIRMWARE_DISABLED:
		return "DISABLED";
	case XE_UC_FIRMWARE_SELECTED:
		return "SELECTED";
	case XE_UC_FIRMWARE_MISSING:
		return "MISSING";
	case XE_UC_FIRMWARE_ERROR:
		return "ERROR";
	case XE_UC_FIRMWARE_AVAILABLE:
		return "AVAILABLE";
	case XE_UC_FIRMWARE_INIT_FAIL:
		return "INIT FAIL";
	case XE_UC_FIRMWARE_LOADABLE:
		return "LOADABLE";
	case XE_UC_FIRMWARE_LOAD_FAIL:
		return "LOAD FAIL";
	case XE_UC_FIRMWARE_TRANSFERRED:
		return "TRANSFERRED";
	case XE_UC_FIRMWARE_RUNNING:
		return "RUNNING";
	case XE_UC_FIRMWARE_PRELOADED:
		return "PRELOADED";
	}
	return "<invalid>";
}

static inline int xe_uc_fw_status_to_error(enum xe_uc_fw_status status)
{
	switch (status) {
	case XE_UC_FIRMWARE_NOT_SUPPORTED:
		return -ENODEV;
	case XE_UC_FIRMWARE_UNINITIALIZED:
		return -EACCES;
	case XE_UC_FIRMWARE_DISABLED:
		return -EPERM;
	case XE_UC_FIRMWARE_MISSING:
		return -ENOENT;
	case XE_UC_FIRMWARE_ERROR:
		return -ENOEXEC;
	case XE_UC_FIRMWARE_INIT_FAIL:
	case XE_UC_FIRMWARE_LOAD_FAIL:
		return -EIO;
	case XE_UC_FIRMWARE_SELECTED:
		return -ESTALE;
	case XE_UC_FIRMWARE_AVAILABLE:
	case XE_UC_FIRMWARE_LOADABLE:
	case XE_UC_FIRMWARE_TRANSFERRED:
	case XE_UC_FIRMWARE_RUNNING:
	case XE_UC_FIRMWARE_PRELOADED:
		return 0;
	}
	return -EINVAL;
}

static inline const char *xe_uc_fw_type_repr(enum xe_uc_fw_type type)
{
	switch (type) {
	case XE_UC_FW_TYPE_GUC:
		return "GuC";
	case XE_UC_FW_TYPE_HUC:
		return "HuC";
	case XE_UC_FW_TYPE_GSC:
		return "GSC";
	default:
		return "uC";
	}
}

static inline enum xe_uc_fw_status
__xe_uc_fw_status(struct xe_uc_fw *uc_fw)
{
	/* shouldn't call this before checking hw/blob availability */
	XE_WARN_ON(uc_fw->status == XE_UC_FIRMWARE_UNINITIALIZED);
	return uc_fw->status;
}

static inline bool xe_uc_fw_is_supported(struct xe_uc_fw *uc_fw)
{
	return __xe_uc_fw_status(uc_fw) != XE_UC_FIRMWARE_NOT_SUPPORTED;
}

static inline bool xe_uc_fw_is_enabled(struct xe_uc_fw *uc_fw)
{
	return __xe_uc_fw_status(uc_fw) > XE_UC_FIRMWARE_DISABLED;
}

static inline bool xe_uc_fw_is_disabled(struct xe_uc_fw *uc_fw)
{
	return __xe_uc_fw_status(uc_fw) == XE_UC_FIRMWARE_DISABLED;
}

static inline bool xe_uc_fw_is_available(struct xe_uc_fw *uc_fw)
{
	return __xe_uc_fw_status(uc_fw) >= XE_UC_FIRMWARE_AVAILABLE;
}

static inline bool xe_uc_fw_is_loadable(struct xe_uc_fw *uc_fw)
{
	return __xe_uc_fw_status(uc_fw) >= XE_UC_FIRMWARE_LOADABLE &&
		__xe_uc_fw_status(uc_fw) != XE_UC_FIRMWARE_PRELOADED;
}

static inline bool xe_uc_fw_is_loaded(struct xe_uc_fw *uc_fw)
{
	return __xe_uc_fw_status(uc_fw) >= XE_UC_FIRMWARE_TRANSFERRED;
}

static inline bool xe_uc_fw_is_running(struct xe_uc_fw *uc_fw)
{
	return __xe_uc_fw_status(uc_fw) >= XE_UC_FIRMWARE_RUNNING;
}

static inline bool xe_uc_fw_is_overridden(const struct xe_uc_fw *uc_fw)
{
	return uc_fw->user_overridden;
}

static inline void xe_uc_fw_sanitize(struct xe_uc_fw *uc_fw)
{
	if (xe_uc_fw_is_loadable(uc_fw))
		xe_uc_fw_change_status(uc_fw, XE_UC_FIRMWARE_LOADABLE);
}

static inline u32 __xe_uc_fw_get_upload_size(struct xe_uc_fw *uc_fw)
{
	return sizeof(struct uc_css_header) + uc_fw->ucode_size;
}

/**
 * xe_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
 * @uc_fw: uC firmware.
 *
 * Get the size of the firmware and header that will be uploaded to WOPCM.
 *
 * Return: Upload firmware size, or zero on firmware fetch failure.
 */
static inline u32 xe_uc_fw_get_upload_size(struct xe_uc_fw *uc_fw)
{
	if (!xe_uc_fw_is_available(uc_fw))
		return 0;

	return __xe_uc_fw_get_upload_size(uc_fw);
}

#define XE_UC_FIRMWARE_URL "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git"

#endif