xref: /dflybsd-src/sys/dev/drm/i915/intel_guc_fwif.h (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
1a05eeebfSFrançois Tigeot /*
2a05eeebfSFrançois Tigeot  * Copyright © 2014 Intel Corporation
3a05eeebfSFrançois Tigeot  *
4a05eeebfSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
5a05eeebfSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
6a05eeebfSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
7a05eeebfSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8a05eeebfSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
9a05eeebfSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
10a05eeebfSFrançois Tigeot  *
11a05eeebfSFrançois Tigeot  * The above copyright notice and this permission notice (including the next
12a05eeebfSFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
13a05eeebfSFrançois Tigeot  * Software.
14a05eeebfSFrançois Tigeot  *
15a05eeebfSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16a05eeebfSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17a05eeebfSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18a05eeebfSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19a05eeebfSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20a05eeebfSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21a05eeebfSFrançois Tigeot  * IN THE SOFTWARE.
22a05eeebfSFrançois Tigeot  */
23a05eeebfSFrançois Tigeot #ifndef _INTEL_GUC_FWIF_H
24a05eeebfSFrançois Tigeot #define _INTEL_GUC_FWIF_H
25a05eeebfSFrançois Tigeot 
26*3f2dd94aSFrançois Tigeot #define GUC_CORE_FAMILY_GEN9		12
27*3f2dd94aSFrançois Tigeot #define GUC_CORE_FAMILY_UNKNOWN		0x7fffffff
28a05eeebfSFrançois Tigeot 
29a85cb24fSFrançois Tigeot #define GUC_CLIENT_PRIORITY_KMD_HIGH	0
30a85cb24fSFrançois Tigeot #define GUC_CLIENT_PRIORITY_HIGH	1
31a85cb24fSFrançois Tigeot #define GUC_CLIENT_PRIORITY_KMD_NORMAL	2
32a85cb24fSFrançois Tigeot #define GUC_CLIENT_PRIORITY_NORMAL	3
33a85cb24fSFrançois Tigeot #define GUC_CLIENT_PRIORITY_NUM		4
34a05eeebfSFrançois Tigeot 
35a85cb24fSFrançois Tigeot #define GUC_MAX_STAGE_DESCRIPTORS	1024
36a85cb24fSFrançois Tigeot #define	GUC_INVALID_STAGE_ID		GUC_MAX_STAGE_DESCRIPTORS
37a05eeebfSFrançois Tigeot 
38c0e85e96SFrançois Tigeot #define GUC_RENDER_ENGINE		0
39c0e85e96SFrançois Tigeot #define GUC_VIDEO_ENGINE		1
40c0e85e96SFrançois Tigeot #define GUC_BLITTER_ENGINE		2
41c0e85e96SFrançois Tigeot #define GUC_VIDEOENHANCE_ENGINE		3
42c0e85e96SFrançois Tigeot #define GUC_VIDEO_ENGINE2		4
43c0e85e96SFrançois Tigeot #define GUC_MAX_ENGINES_NUM		(GUC_VIDEO_ENGINE2 + 1)
44c0e85e96SFrançois Tigeot 
45a05eeebfSFrançois Tigeot /* Work queue item header definitions */
46a05eeebfSFrançois Tigeot #define WQ_STATUS_ACTIVE		1
47a05eeebfSFrançois Tigeot #define WQ_STATUS_SUSPENDED		2
48a05eeebfSFrançois Tigeot #define WQ_STATUS_CMD_ERROR		3
49a05eeebfSFrançois Tigeot #define WQ_STATUS_ENGINE_ID_NOT_USED	4
50a05eeebfSFrançois Tigeot #define WQ_STATUS_SUSPENDED_FROM_RESET	5
51a05eeebfSFrançois Tigeot #define WQ_TYPE_SHIFT			0
52a05eeebfSFrançois Tigeot #define   WQ_TYPE_BATCH_BUF		(0x1 << WQ_TYPE_SHIFT)
53a05eeebfSFrançois Tigeot #define   WQ_TYPE_PSEUDO		(0x2 << WQ_TYPE_SHIFT)
54a05eeebfSFrançois Tigeot #define   WQ_TYPE_INORDER		(0x3 << WQ_TYPE_SHIFT)
55a05eeebfSFrançois Tigeot #define WQ_TARGET_SHIFT			10
56a05eeebfSFrançois Tigeot #define WQ_LEN_SHIFT			16
57a05eeebfSFrançois Tigeot #define WQ_NO_WCFLUSH_WAIT		(1 << 27)
58a05eeebfSFrançois Tigeot #define WQ_PRESENT_WORKLOAD		(1 << 28)
59a05eeebfSFrançois Tigeot 
60a05eeebfSFrançois Tigeot #define WQ_RING_TAIL_SHIFT		20
611487f786SFrançois Tigeot #define WQ_RING_TAIL_MAX		0x7FF	/* 2^11 QWords */
621487f786SFrançois Tigeot #define WQ_RING_TAIL_MASK		(WQ_RING_TAIL_MAX << WQ_RING_TAIL_SHIFT)
63a05eeebfSFrançois Tigeot 
64a05eeebfSFrançois Tigeot #define GUC_DOORBELL_ENABLED		1
65a05eeebfSFrançois Tigeot #define GUC_DOORBELL_DISABLED		0
66a05eeebfSFrançois Tigeot 
67a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_ACTIVE	BIT(0)
68a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_PENDING_DB	BIT(1)
69a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_KERNEL	BIT(2)
70a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_PREEMPT	BIT(3)
71a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_RESET	BIT(4)
72a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_WQLOCKED	BIT(5)
73a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_PCH		BIT(6)
74a85cb24fSFrançois Tigeot #define GUC_STAGE_DESC_ATTR_TERMINATED	BIT(7)
75a05eeebfSFrançois Tigeot 
76a05eeebfSFrançois Tigeot /* The guc control data is 10 DWORDs */
77a05eeebfSFrançois Tigeot #define GUC_CTL_CTXINFO			0
78a05eeebfSFrançois Tigeot #define   GUC_CTL_CTXNUM_IN16_SHIFT	0
79a05eeebfSFrançois Tigeot #define   GUC_CTL_BASE_ADDR_SHIFT	12
80c0e85e96SFrançois Tigeot 
81a05eeebfSFrançois Tigeot #define GUC_CTL_ARAT_HIGH		1
82a05eeebfSFrançois Tigeot #define GUC_CTL_ARAT_LOW		2
83c0e85e96SFrançois Tigeot 
84a05eeebfSFrançois Tigeot #define GUC_CTL_DEVICE_INFO		3
85*3f2dd94aSFrançois Tigeot #define   GUC_CTL_GT_TYPE_SHIFT		0
86*3f2dd94aSFrançois Tigeot #define   GUC_CTL_CORE_FAMILY_SHIFT	7
87c0e85e96SFrançois Tigeot 
88a05eeebfSFrançois Tigeot #define GUC_CTL_LOG_PARAMS		4
89a05eeebfSFrançois Tigeot #define   GUC_LOG_VALID			(1 << 0)
90a05eeebfSFrançois Tigeot #define   GUC_LOG_NOTIFY_ON_HALF_FULL	(1 << 1)
91a05eeebfSFrançois Tigeot #define   GUC_LOG_ALLOC_IN_MEGABYTE	(1 << 3)
92a05eeebfSFrançois Tigeot #define   GUC_LOG_CRASH_PAGES		1
93a05eeebfSFrançois Tigeot #define   GUC_LOG_CRASH_SHIFT		4
944be47400SFrançois Tigeot #define   GUC_LOG_DPC_PAGES		7
95a05eeebfSFrançois Tigeot #define   GUC_LOG_DPC_SHIFT		6
964be47400SFrançois Tigeot #define   GUC_LOG_ISR_PAGES		7
97a05eeebfSFrançois Tigeot #define   GUC_LOG_ISR_SHIFT		9
98a05eeebfSFrançois Tigeot #define   GUC_LOG_BUF_ADDR_SHIFT	12
99c0e85e96SFrançois Tigeot 
100a05eeebfSFrançois Tigeot #define GUC_CTL_PAGE_FAULT_CONTROL	5
101c0e85e96SFrançois Tigeot 
102a05eeebfSFrançois Tigeot #define GUC_CTL_WA			6
103a05eeebfSFrançois Tigeot #define   GUC_CTL_WA_UK_BY_DRIVER	(1 << 3)
104c0e85e96SFrançois Tigeot 
105a05eeebfSFrançois Tigeot #define GUC_CTL_FEATURE			7
106a05eeebfSFrançois Tigeot #define   GUC_CTL_VCS2_ENABLED		(1 << 0)
107a05eeebfSFrançois Tigeot #define   GUC_CTL_KERNEL_SUBMISSIONS	(1 << 1)
108a05eeebfSFrançois Tigeot #define   GUC_CTL_FEATURE2		(1 << 2)
109a05eeebfSFrançois Tigeot #define   GUC_CTL_POWER_GATING		(1 << 3)
110a05eeebfSFrançois Tigeot #define   GUC_CTL_DISABLE_SCHEDULER	(1 << 4)
111a05eeebfSFrançois Tigeot #define   GUC_CTL_PREEMPTION_LOG	(1 << 5)
112a05eeebfSFrançois Tigeot #define   GUC_CTL_ENABLE_SLPC		(1 << 7)
113352ff8bdSFrançois Tigeot #define   GUC_CTL_RESET_ON_PREMPT_FAILURE	(1 << 8)
114c0e85e96SFrançois Tigeot 
115a05eeebfSFrançois Tigeot #define GUC_CTL_DEBUG			8
116a05eeebfSFrançois Tigeot #define   GUC_LOG_VERBOSITY_SHIFT	0
117a05eeebfSFrançois Tigeot #define   GUC_LOG_VERBOSITY_LOW		(0 << GUC_LOG_VERBOSITY_SHIFT)
118a05eeebfSFrançois Tigeot #define   GUC_LOG_VERBOSITY_MED		(1 << GUC_LOG_VERBOSITY_SHIFT)
119a05eeebfSFrançois Tigeot #define   GUC_LOG_VERBOSITY_HIGH	(2 << GUC_LOG_VERBOSITY_SHIFT)
120a05eeebfSFrançois Tigeot #define   GUC_LOG_VERBOSITY_ULTRA	(3 << GUC_LOG_VERBOSITY_SHIFT)
121a05eeebfSFrançois Tigeot /* Verbosity range-check limits, without the shift */
122a05eeebfSFrançois Tigeot #define	  GUC_LOG_VERBOSITY_MIN		0
123a05eeebfSFrançois Tigeot #define	  GUC_LOG_VERBOSITY_MAX		3
124c0e85e96SFrançois Tigeot #define	  GUC_LOG_VERBOSITY_MASK	0x0000000f
125c0e85e96SFrançois Tigeot #define	  GUC_LOG_DESTINATION_MASK	(3 << 4)
126c0e85e96SFrançois Tigeot #define   GUC_LOG_DISABLED		(1 << 6)
127c0e85e96SFrançois Tigeot #define   GUC_PROFILE_ENABLED		(1 << 7)
128c0e85e96SFrançois Tigeot #define   GUC_WQ_TRACK_ENABLED		(1 << 8)
129c0e85e96SFrançois Tigeot #define   GUC_ADS_ENABLED		(1 << 9)
130c0e85e96SFrançois Tigeot #define   GUC_DEBUG_RESERVED		(1 << 10)
131c0e85e96SFrançois Tigeot #define   GUC_ADS_ADDR_SHIFT		11
132c0e85e96SFrançois Tigeot #define   GUC_ADS_ADDR_MASK		0xfffff800
133c0e85e96SFrançois Tigeot 
134352ff8bdSFrançois Tigeot #define GUC_CTL_RSRVD			9
135a05eeebfSFrançois Tigeot 
136c0e85e96SFrançois Tigeot #define GUC_CTL_MAX_DWORDS		(SOFT_SCRATCH_COUNT - 2) /* [1..14] */
137a05eeebfSFrançois Tigeot 
138aee94f86SFrançois Tigeot /**
139aee94f86SFrançois Tigeot  * DOC: GuC Firmware Layout
140aee94f86SFrançois Tigeot  *
141aee94f86SFrançois Tigeot  * The GuC firmware layout looks like this:
142aee94f86SFrançois Tigeot  *
143aee94f86SFrançois Tigeot  *     +-------------------------------+
144a85cb24fSFrançois Tigeot  *     |         uc_css_header         |
1451e12ee3bSFrançois Tigeot  *     |                               |
146aee94f86SFrançois Tigeot  *     | contains major/minor version  |
147aee94f86SFrançois Tigeot  *     +-------------------------------+
148aee94f86SFrançois Tigeot  *     |             uCode             |
149aee94f86SFrançois Tigeot  *     +-------------------------------+
150aee94f86SFrançois Tigeot  *     |         RSA signature         |
151aee94f86SFrançois Tigeot  *     +-------------------------------+
152aee94f86SFrançois Tigeot  *     |          modulus key          |
153aee94f86SFrançois Tigeot  *     +-------------------------------+
154aee94f86SFrançois Tigeot  *     |          exponent val         |
155aee94f86SFrançois Tigeot  *     +-------------------------------+
156aee94f86SFrançois Tigeot  *
157aee94f86SFrançois Tigeot  * The firmware may or may not have modulus key and exponent data. The header,
158aee94f86SFrançois Tigeot  * uCode and RSA signature are must-have components that will be used by driver.
159aee94f86SFrançois Tigeot  * Length of each components, which is all in dwords, can be found in header.
160aee94f86SFrançois Tigeot  * In the case that modulus and exponent are not present in fw, a.k.a truncated
161aee94f86SFrançois Tigeot  * image, the length value still appears in header.
162aee94f86SFrançois Tigeot  *
163aee94f86SFrançois Tigeot  * Driver will do some basic fw size validation based on the following rules:
164aee94f86SFrançois Tigeot  *
165aee94f86SFrançois Tigeot  * 1. Header, uCode and RSA are must-have components.
166aee94f86SFrançois Tigeot  * 2. All firmware components, if they present, are in the sequence illustrated
167aee94f86SFrançois Tigeot  *    in the layout table above.
168aee94f86SFrançois Tigeot  * 3. Length info of each component can be found in header, in dwords.
169aee94f86SFrançois Tigeot  * 4. Modulus and exponent key are not required by driver. They may not appear
170aee94f86SFrançois Tigeot  *    in fw. So driver will load a truncated firmware in this case.
171a85cb24fSFrançois Tigeot  *
172a85cb24fSFrançois Tigeot  * HuC firmware layout is same as GuC firmware.
173a85cb24fSFrançois Tigeot  *
174a85cb24fSFrançois Tigeot  * HuC firmware css header is different. However, the only difference is where
175a85cb24fSFrançois Tigeot  * the version information is saved. The uc_css_header is unified to support
176a85cb24fSFrançois Tigeot  * both. Driver should get HuC version from uc_css_header.huc_sw_version, while
177a85cb24fSFrançois Tigeot  * uc_css_header.guc_sw_version for GuC.
178aee94f86SFrançois Tigeot  */
179aee94f86SFrançois Tigeot 
180a85cb24fSFrançois Tigeot struct uc_css_header {
181*3f2dd94aSFrançois Tigeot 	u32 module_type;
182aee94f86SFrançois Tigeot 	/* header_size includes all non-uCode bits, including css_header, rsa
183aee94f86SFrançois Tigeot 	 * key, modulus key and exponent data. */
184*3f2dd94aSFrançois Tigeot 	u32 header_size_dw;
185*3f2dd94aSFrançois Tigeot 	u32 header_version;
186*3f2dd94aSFrançois Tigeot 	u32 module_id;
187*3f2dd94aSFrançois Tigeot 	u32 module_vendor;
188aee94f86SFrançois Tigeot 	union {
189aee94f86SFrançois Tigeot 		struct {
190*3f2dd94aSFrançois Tigeot 			u8 day;
191*3f2dd94aSFrançois Tigeot 			u8 month;
192*3f2dd94aSFrançois Tigeot 			u16 year;
193aee94f86SFrançois Tigeot 		};
194*3f2dd94aSFrançois Tigeot 		u32 date;
195aee94f86SFrançois Tigeot 	};
196*3f2dd94aSFrançois Tigeot 	u32 size_dw; /* uCode plus header_size_dw */
197*3f2dd94aSFrançois Tigeot 	u32 key_size_dw;
198*3f2dd94aSFrançois Tigeot 	u32 modulus_size_dw;
199*3f2dd94aSFrançois Tigeot 	u32 exponent_size_dw;
200aee94f86SFrançois Tigeot 	union {
201aee94f86SFrançois Tigeot 		struct {
202*3f2dd94aSFrançois Tigeot 			u8 hour;
203*3f2dd94aSFrançois Tigeot 			u8 min;
204*3f2dd94aSFrançois Tigeot 			u16 sec;
205aee94f86SFrançois Tigeot 		};
206*3f2dd94aSFrançois Tigeot 		u32 time;
207aee94f86SFrançois Tigeot 	};
208aee94f86SFrançois Tigeot 
209aee94f86SFrançois Tigeot 	char username[8];
210aee94f86SFrançois Tigeot 	char buildnumber[12];
211a85cb24fSFrançois Tigeot 	union {
212a85cb24fSFrançois Tigeot 		struct {
213*3f2dd94aSFrançois Tigeot 			u32 branch_client_version;
214*3f2dd94aSFrançois Tigeot 			u32 sw_version;
215a85cb24fSFrançois Tigeot 	} guc;
216a85cb24fSFrançois Tigeot 		struct {
217*3f2dd94aSFrançois Tigeot 			u32 sw_version;
218*3f2dd94aSFrançois Tigeot 			u32 reserved;
219a85cb24fSFrançois Tigeot 	} huc;
220a85cb24fSFrançois Tigeot 	};
221*3f2dd94aSFrançois Tigeot 	u32 prod_preprod_fw;
222*3f2dd94aSFrançois Tigeot 	u32 reserved[12];
223*3f2dd94aSFrançois Tigeot 	u32 header_info;
224aee94f86SFrançois Tigeot } __packed;
225aee94f86SFrançois Tigeot 
226a05eeebfSFrançois Tigeot struct guc_doorbell_info {
227a05eeebfSFrançois Tigeot 	u32 db_status;
228a05eeebfSFrançois Tigeot 	u32 cookie;
229a05eeebfSFrançois Tigeot 	u32 reserved[14];
230a05eeebfSFrançois Tigeot } __packed;
231a05eeebfSFrançois Tigeot 
232a05eeebfSFrançois Tigeot union guc_doorbell_qw {
233a05eeebfSFrançois Tigeot 	struct {
234a05eeebfSFrançois Tigeot 		u32 db_status;
235a05eeebfSFrançois Tigeot 		u32 cookie;
236a05eeebfSFrançois Tigeot 	};
237a05eeebfSFrançois Tigeot 	u64 value_qw;
238a05eeebfSFrançois Tigeot } __packed;
239a05eeebfSFrançois Tigeot 
240a85cb24fSFrançois Tigeot #define GUC_NUM_DOORBELLS	256
241a85cb24fSFrançois Tigeot #define GUC_DOORBELL_INVALID	(GUC_NUM_DOORBELLS)
242a05eeebfSFrançois Tigeot 
243a05eeebfSFrançois Tigeot #define GUC_DB_SIZE			(PAGE_SIZE)
244a05eeebfSFrançois Tigeot #define GUC_WQ_SIZE			(PAGE_SIZE * 2)
245a05eeebfSFrançois Tigeot 
246a05eeebfSFrançois Tigeot /* Work item for submitting workloads into work queue of GuC. */
247a05eeebfSFrançois Tigeot struct guc_wq_item {
248a05eeebfSFrançois Tigeot 	u32 header;
249a05eeebfSFrançois Tigeot 	u32 context_desc;
250a85cb24fSFrançois Tigeot 	u32 submit_element_info;
251a05eeebfSFrançois Tigeot 	u32 fence_id;
252a05eeebfSFrançois Tigeot } __packed;
253a05eeebfSFrançois Tigeot 
254a05eeebfSFrançois Tigeot struct guc_process_desc {
255a85cb24fSFrançois Tigeot 	u32 stage_id;
256a05eeebfSFrançois Tigeot 	u64 db_base_addr;
257a05eeebfSFrançois Tigeot 	u32 head;
258a05eeebfSFrançois Tigeot 	u32 tail;
259a05eeebfSFrançois Tigeot 	u32 error_offset;
260a05eeebfSFrançois Tigeot 	u64 wq_base_addr;
261a05eeebfSFrançois Tigeot 	u32 wq_size_bytes;
262a05eeebfSFrançois Tigeot 	u32 wq_status;
263a05eeebfSFrançois Tigeot 	u32 engine_presence;
264a05eeebfSFrançois Tigeot 	u32 priority;
265a05eeebfSFrançois Tigeot 	u32 reserved[30];
266a05eeebfSFrançois Tigeot } __packed;
267a05eeebfSFrançois Tigeot 
268a05eeebfSFrançois Tigeot /* engine id and context id is packed into guc_execlist_context.context_id*/
269a05eeebfSFrançois Tigeot #define GUC_ELC_CTXID_OFFSET		0
270a05eeebfSFrançois Tigeot #define GUC_ELC_ENGINE_OFFSET		29
271a05eeebfSFrançois Tigeot 
272a05eeebfSFrançois Tigeot /* The execlist context including software and HW information */
273a05eeebfSFrançois Tigeot struct guc_execlist_context {
274a05eeebfSFrançois Tigeot 	u32 context_desc;
275a05eeebfSFrançois Tigeot 	u32 context_id;
276a05eeebfSFrançois Tigeot 	u32 ring_status;
277a85cb24fSFrançois Tigeot 	u32 ring_lrca;
278a05eeebfSFrançois Tigeot 	u32 ring_begin;
279a05eeebfSFrançois Tigeot 	u32 ring_end;
280a05eeebfSFrançois Tigeot 	u32 ring_next_free_location;
281a05eeebfSFrançois Tigeot 	u32 ring_current_tail_pointer_value;
282a05eeebfSFrançois Tigeot 	u8 engine_state_submit_value;
283a05eeebfSFrançois Tigeot 	u8 engine_state_wait_value;
284a05eeebfSFrançois Tigeot 	u16 pagefault_count;
285a05eeebfSFrançois Tigeot 	u16 engine_submit_queue_count;
286a05eeebfSFrançois Tigeot } __packed;
287a05eeebfSFrançois Tigeot 
288a85cb24fSFrançois Tigeot /*
289a85cb24fSFrançois Tigeot  * This structure describes a stage set arranged for a particular communication
290a85cb24fSFrançois Tigeot  * between uKernel (GuC) and Driver (KMD). Technically, this is known as a
291a85cb24fSFrançois Tigeot  * "GuC Context descriptor" in the specs, but we use the term "stage descriptor"
292a85cb24fSFrançois Tigeot  * to avoid confusion with all the other things already named "context" in the
293a85cb24fSFrançois Tigeot  * driver. A static pool of these descriptors are stored inside a GEM object
294a85cb24fSFrançois Tigeot  * (stage_desc_pool) which is held for the entire lifetime of our interaction
295a85cb24fSFrançois Tigeot  * with the GuC, being allocated before the GuC is loaded with its firmware.
296a85cb24fSFrançois Tigeot  */
297a85cb24fSFrançois Tigeot struct guc_stage_desc {
298a05eeebfSFrançois Tigeot 	u32 sched_common_area;
299a85cb24fSFrançois Tigeot 	u32 stage_id;
300a05eeebfSFrançois Tigeot 	u32 pas_id;
301a05eeebfSFrançois Tigeot 	u8 engines_used;
302a05eeebfSFrançois Tigeot 	u64 db_trigger_cpu;
303a05eeebfSFrançois Tigeot 	u32 db_trigger_uk;
304a05eeebfSFrançois Tigeot 	u64 db_trigger_phy;
305a05eeebfSFrançois Tigeot 	u16 db_id;
306a05eeebfSFrançois Tigeot 
307c0e85e96SFrançois Tigeot 	struct guc_execlist_context lrc[GUC_MAX_ENGINES_NUM];
308a05eeebfSFrançois Tigeot 
309a05eeebfSFrançois Tigeot 	u8 attribute;
310a05eeebfSFrançois Tigeot 
311a05eeebfSFrançois Tigeot 	u32 priority;
312a05eeebfSFrançois Tigeot 
313a05eeebfSFrançois Tigeot 	u32 wq_sampled_tail_offset;
314a05eeebfSFrançois Tigeot 	u32 wq_total_submit_enqueues;
315a05eeebfSFrançois Tigeot 
316a05eeebfSFrançois Tigeot 	u32 process_desc;
317a05eeebfSFrançois Tigeot 	u32 wq_addr;
318a05eeebfSFrançois Tigeot 	u32 wq_size;
319a05eeebfSFrançois Tigeot 
320a05eeebfSFrançois Tigeot 	u32 engine_presence;
321a05eeebfSFrançois Tigeot 
322352ff8bdSFrançois Tigeot 	u8 engine_suspended;
323352ff8bdSFrançois Tigeot 
324352ff8bdSFrançois Tigeot 	u8 reserved0[3];
325a05eeebfSFrançois Tigeot 	u64 reserved1[1];
326a05eeebfSFrançois Tigeot 
327a05eeebfSFrançois Tigeot 	u64 desc_private;
328a05eeebfSFrançois Tigeot } __packed;
329a05eeebfSFrançois Tigeot 
330*3f2dd94aSFrançois Tigeot /*
331*3f2dd94aSFrançois Tigeot  * Describes single command transport buffer.
332*3f2dd94aSFrançois Tigeot  * Used by both guc-master and clients.
333*3f2dd94aSFrançois Tigeot  */
334*3f2dd94aSFrançois Tigeot struct guc_ct_buffer_desc {
335*3f2dd94aSFrançois Tigeot 	u32 addr;		/* gfx address */
336*3f2dd94aSFrançois Tigeot 	u64 host_private;	/* host private data */
337*3f2dd94aSFrançois Tigeot 	u32 size;		/* size in bytes */
338*3f2dd94aSFrançois Tigeot 	u32 head;		/* offset updated by GuC*/
339*3f2dd94aSFrançois Tigeot 	u32 tail;		/* offset updated by owner */
340*3f2dd94aSFrançois Tigeot 	u32 is_in_error;	/* error indicator */
341*3f2dd94aSFrançois Tigeot 	u32 fence;		/* fence updated by GuC */
342*3f2dd94aSFrançois Tigeot 	u32 status;		/* status updated by GuC */
343*3f2dd94aSFrançois Tigeot 	u32 owner;		/* id of the channel owner */
344*3f2dd94aSFrançois Tigeot 	u32 owner_sub_id;	/* owner-defined field for extra tracking */
345*3f2dd94aSFrançois Tigeot 	u32 reserved[5];
346*3f2dd94aSFrançois Tigeot } __packed;
347*3f2dd94aSFrançois Tigeot 
348*3f2dd94aSFrançois Tigeot /* Type of command transport buffer */
349*3f2dd94aSFrançois Tigeot #define INTEL_GUC_CT_BUFFER_TYPE_SEND	0x0u
350*3f2dd94aSFrançois Tigeot #define INTEL_GUC_CT_BUFFER_TYPE_RECV	0x1u
351*3f2dd94aSFrançois Tigeot 
352*3f2dd94aSFrançois Tigeot /*
353*3f2dd94aSFrançois Tigeot  * Definition of the command transport message header (DW0)
354*3f2dd94aSFrançois Tigeot  *
355*3f2dd94aSFrançois Tigeot  * bit[4..0]	message len (in dwords)
356*3f2dd94aSFrançois Tigeot  * bit[7..5]	reserved
357*3f2dd94aSFrançois Tigeot  * bit[8]	write fence to desc
358*3f2dd94aSFrançois Tigeot  * bit[9]	write status to H2G buff
359*3f2dd94aSFrançois Tigeot  * bit[10]	send status (via G2H)
360*3f2dd94aSFrançois Tigeot  * bit[15..11]	reserved
361*3f2dd94aSFrançois Tigeot  * bit[31..16]	action code
362*3f2dd94aSFrançois Tigeot  */
363*3f2dd94aSFrançois Tigeot #define GUC_CT_MSG_LEN_SHIFT			0
364*3f2dd94aSFrançois Tigeot #define GUC_CT_MSG_LEN_MASK			0x1F
365*3f2dd94aSFrançois Tigeot #define GUC_CT_MSG_WRITE_FENCE_TO_DESC		(1 << 8)
366*3f2dd94aSFrançois Tigeot #define GUC_CT_MSG_WRITE_STATUS_TO_BUFF		(1 << 9)
367*3f2dd94aSFrançois Tigeot #define GUC_CT_MSG_SEND_STATUS			(1 << 10)
368*3f2dd94aSFrançois Tigeot #define GUC_CT_MSG_ACTION_SHIFT			16
369*3f2dd94aSFrançois Tigeot #define GUC_CT_MSG_ACTION_MASK			0xFFFF
370*3f2dd94aSFrançois Tigeot 
371352ff8bdSFrançois Tigeot #define GUC_FORCEWAKE_RENDER	(1 << 0)
372352ff8bdSFrançois Tigeot #define GUC_FORCEWAKE_MEDIA	(1 << 1)
373352ff8bdSFrançois Tigeot 
374352ff8bdSFrançois Tigeot #define GUC_POWER_UNSPECIFIED	0
375352ff8bdSFrançois Tigeot #define GUC_POWER_D0		1
376352ff8bdSFrançois Tigeot #define GUC_POWER_D1		2
377352ff8bdSFrançois Tigeot #define GUC_POWER_D2		3
378352ff8bdSFrançois Tigeot #define GUC_POWER_D3		4
379352ff8bdSFrançois Tigeot 
380c0e85e96SFrançois Tigeot /* Scheduling policy settings */
381c0e85e96SFrançois Tigeot 
382c0e85e96SFrançois Tigeot /* Reset engine upon preempt failure */
383c0e85e96SFrançois Tigeot #define POLICY_RESET_ENGINE		(1<<0)
384c0e85e96SFrançois Tigeot /* Preempt to idle on quantum expiry */
385c0e85e96SFrançois Tigeot #define POLICY_PREEMPT_TO_IDLE		(1<<1)
386c0e85e96SFrançois Tigeot 
387c0e85e96SFrançois Tigeot #define POLICY_MAX_NUM_WI 15
388*3f2dd94aSFrançois Tigeot #define POLICY_DEFAULT_DPC_PROMOTE_TIME_US 500000
389*3f2dd94aSFrançois Tigeot #define POLICY_DEFAULT_EXECUTION_QUANTUM_US 1000000
390*3f2dd94aSFrançois Tigeot #define POLICY_DEFAULT_PREEMPTION_TIME_US 500000
391*3f2dd94aSFrançois Tigeot #define POLICY_DEFAULT_FAULT_TIME_US 250000
392c0e85e96SFrançois Tigeot 
393c0e85e96SFrançois Tigeot struct guc_policy {
394c0e85e96SFrançois Tigeot 	/* Time for one workload to execute. (in micro seconds) */
395c0e85e96SFrançois Tigeot 	u32 execution_quantum;
396c0e85e96SFrançois Tigeot 	u32 reserved1;
397c0e85e96SFrançois Tigeot 
398c0e85e96SFrançois Tigeot 	/* Time to wait for a preemption request to completed before issuing a
399c0e85e96SFrançois Tigeot 	 * reset. (in micro seconds). */
400c0e85e96SFrançois Tigeot 	u32 preemption_time;
401c0e85e96SFrançois Tigeot 
402c0e85e96SFrançois Tigeot 	/* How much time to allow to run after the first fault is observed.
403c0e85e96SFrançois Tigeot 	 * Then preempt afterwards. (in micro seconds) */
404c0e85e96SFrançois Tigeot 	u32 fault_time;
405c0e85e96SFrançois Tigeot 
406c0e85e96SFrançois Tigeot 	u32 policy_flags;
407c0e85e96SFrançois Tigeot 	u32 reserved[2];
408c0e85e96SFrançois Tigeot } __packed;
409c0e85e96SFrançois Tigeot 
410c0e85e96SFrançois Tigeot struct guc_policies {
411a85cb24fSFrançois Tigeot 	struct guc_policy policy[GUC_CLIENT_PRIORITY_NUM][GUC_MAX_ENGINES_NUM];
412c0e85e96SFrançois Tigeot 
413c0e85e96SFrançois Tigeot 	/* In micro seconds. How much time to allow before DPC processing is
414c0e85e96SFrançois Tigeot 	 * called back via interrupt (to prevent DPC queue drain starving).
415c0e85e96SFrançois Tigeot 	 * Typically 1000s of micro seconds (example only, not granularity). */
416c0e85e96SFrançois Tigeot 	u32 dpc_promote_time;
417c0e85e96SFrançois Tigeot 
418c0e85e96SFrançois Tigeot 	/* Must be set to take these new values. */
419c0e85e96SFrançois Tigeot 	u32 is_valid;
420c0e85e96SFrançois Tigeot 
421c0e85e96SFrançois Tigeot 	/* Max number of WIs to process per call. A large value may keep CS
422c0e85e96SFrançois Tigeot 	 * idle. */
423c0e85e96SFrançois Tigeot 	u32 max_num_work_items;
424c0e85e96SFrançois Tigeot 
425c0e85e96SFrançois Tigeot 	u32 reserved[19];
426c0e85e96SFrançois Tigeot } __packed;
427c0e85e96SFrançois Tigeot 
428c0e85e96SFrançois Tigeot /* GuC MMIO reg state struct */
429c0e85e96SFrançois Tigeot 
430c0e85e96SFrançois Tigeot #define GUC_REGSET_FLAGS_NONE		0x0
431c0e85e96SFrançois Tigeot #define GUC_REGSET_POWERCYCLE		0x1
432c0e85e96SFrançois Tigeot #define GUC_REGSET_MASKED		0x2
433c0e85e96SFrançois Tigeot #define GUC_REGSET_ENGINERESET		0x4
434c0e85e96SFrançois Tigeot #define GUC_REGSET_SAVE_DEFAULT_VALUE	0x8
435c0e85e96SFrançois Tigeot #define GUC_REGSET_SAVE_CURRENT_VALUE	0x10
436c0e85e96SFrançois Tigeot 
437c0e85e96SFrançois Tigeot #define GUC_REGSET_MAX_REGISTERS	25
438c0e85e96SFrançois Tigeot #define GUC_MMIO_WHITE_LIST_START	0x24d0
439c0e85e96SFrançois Tigeot #define GUC_MMIO_WHITE_LIST_MAX		12
440c0e85e96SFrançois Tigeot #define GUC_S3_SAVE_SPACE_PAGES		10
441c0e85e96SFrançois Tigeot 
442c0e85e96SFrançois Tigeot struct guc_mmio_regset {
443c0e85e96SFrançois Tigeot 	struct __packed {
444c0e85e96SFrançois Tigeot 		u32 offset;
445c0e85e96SFrançois Tigeot 		u32 value;
446c0e85e96SFrançois Tigeot 		u32 flags;
447c0e85e96SFrançois Tigeot 	} registers[GUC_REGSET_MAX_REGISTERS];
448c0e85e96SFrançois Tigeot 
449c0e85e96SFrançois Tigeot 	u32 values_valid;
450c0e85e96SFrançois Tigeot 	u32 number_of_registers;
451c0e85e96SFrançois Tigeot } __packed;
452c0e85e96SFrançois Tigeot 
453c0e85e96SFrançois Tigeot /* MMIO registers that are set as non privileged */
454a85cb24fSFrançois Tigeot struct mmio_white_list {
455c0e85e96SFrançois Tigeot 	u32 mmio_start;
456c0e85e96SFrançois Tigeot 	u32 offsets[GUC_MMIO_WHITE_LIST_MAX];
457c0e85e96SFrançois Tigeot 	u32 count;
458a85cb24fSFrançois Tigeot } __packed;
459a85cb24fSFrançois Tigeot 
460a85cb24fSFrançois Tigeot struct guc_mmio_reg_state {
461a85cb24fSFrançois Tigeot 	struct guc_mmio_regset global_reg;
462a85cb24fSFrançois Tigeot 	struct guc_mmio_regset engine_reg[GUC_MAX_ENGINES_NUM];
463a85cb24fSFrançois Tigeot 	struct mmio_white_list white_list[GUC_MAX_ENGINES_NUM];
464c0e85e96SFrançois Tigeot } __packed;
465c0e85e96SFrançois Tigeot 
466c0e85e96SFrançois Tigeot /* GuC Additional Data Struct */
467c0e85e96SFrançois Tigeot 
468c0e85e96SFrançois Tigeot struct guc_ads {
469c0e85e96SFrançois Tigeot 	u32 reg_state_addr;
470c0e85e96SFrançois Tigeot 	u32 reg_state_buffer;
471c0e85e96SFrançois Tigeot 	u32 golden_context_lrca;
472c0e85e96SFrançois Tigeot 	u32 scheduler_policies;
473c0e85e96SFrançois Tigeot 	u32 reserved0[3];
474c0e85e96SFrançois Tigeot 	u32 eng_state_size[GUC_MAX_ENGINES_NUM];
475c0e85e96SFrançois Tigeot 	u32 reserved2[4];
476c0e85e96SFrançois Tigeot } __packed;
477c0e85e96SFrançois Tigeot 
4784be47400SFrançois Tigeot /* GuC logging structures */
4794be47400SFrançois Tigeot 
4804be47400SFrançois Tigeot enum guc_log_buffer_type {
4814be47400SFrançois Tigeot 	GUC_ISR_LOG_BUFFER,
4824be47400SFrançois Tigeot 	GUC_DPC_LOG_BUFFER,
4834be47400SFrançois Tigeot 	GUC_CRASH_DUMP_LOG_BUFFER,
4844be47400SFrançois Tigeot 	GUC_MAX_LOG_BUFFER
4854be47400SFrançois Tigeot };
4864be47400SFrançois Tigeot 
4874be47400SFrançois Tigeot /**
4884be47400SFrançois Tigeot  * DOC: GuC Log buffer Layout
4894be47400SFrançois Tigeot  *
4904be47400SFrançois Tigeot  * Page0  +-------------------------------+
4914be47400SFrançois Tigeot  *        |   ISR state header (32 bytes) |
4924be47400SFrançois Tigeot  *        |      DPC state header         |
4934be47400SFrançois Tigeot  *        |   Crash dump state header     |
4944be47400SFrançois Tigeot  * Page1  +-------------------------------+
4954be47400SFrançois Tigeot  *        |           ISR logs            |
4964be47400SFrançois Tigeot  * Page9  +-------------------------------+
4974be47400SFrançois Tigeot  *        |           DPC logs            |
4984be47400SFrançois Tigeot  * Page17 +-------------------------------+
4994be47400SFrançois Tigeot  *        |         Crash Dump logs       |
5004be47400SFrançois Tigeot  *        +-------------------------------+
5014be47400SFrançois Tigeot  *
5024be47400SFrançois Tigeot  * Below state structure is used for coordination of retrieval of GuC firmware
5034be47400SFrançois Tigeot  * logs. Separate state is maintained for each log buffer type.
5044be47400SFrançois Tigeot  * read_ptr points to the location where i915 read last in log buffer and
5054be47400SFrançois Tigeot  * is read only for GuC firmware. write_ptr is incremented by GuC with number
5064be47400SFrançois Tigeot  * of bytes written for each log entry and is read only for i915.
5074be47400SFrançois Tigeot  * When any type of log buffer becomes half full, GuC sends a flush interrupt.
5084be47400SFrançois Tigeot  * GuC firmware expects that while it is writing to 2nd half of the buffer,
5094be47400SFrançois Tigeot  * first half would get consumed by Host and then get a flush completed
5104be47400SFrançois Tigeot  * acknowledgment from Host, so that it does not end up doing any overwrite
5114be47400SFrançois Tigeot  * causing loss of logs. So when buffer gets half filled & i915 has requested
5124be47400SFrançois Tigeot  * for interrupt, GuC will set flush_to_file field, set the sampled_write_ptr
5134be47400SFrançois Tigeot  * to the value of write_ptr and raise the interrupt.
5144be47400SFrançois Tigeot  * On receiving the interrupt i915 should read the buffer, clear flush_to_file
5154be47400SFrançois Tigeot  * field and also update read_ptr with the value of sample_write_ptr, before
5164be47400SFrançois Tigeot  * sending an acknowledgment to GuC. marker & version fields are for internal
5174be47400SFrançois Tigeot  * usage of GuC and opaque to i915. buffer_full_cnt field is incremented every
5184be47400SFrançois Tigeot  * time GuC detects the log buffer overflow.
5194be47400SFrançois Tigeot  */
5204be47400SFrançois Tigeot struct guc_log_buffer_state {
5214be47400SFrançois Tigeot 	u32 marker[2];
5224be47400SFrançois Tigeot 	u32 read_ptr;
5234be47400SFrançois Tigeot 	u32 write_ptr;
5244be47400SFrançois Tigeot 	u32 size;
5254be47400SFrançois Tigeot 	u32 sampled_write_ptr;
5264be47400SFrançois Tigeot 	union {
5274be47400SFrançois Tigeot 		struct {
5284be47400SFrançois Tigeot 			u32 flush_to_file:1;
5294be47400SFrançois Tigeot 			u32 buffer_full_cnt:4;
5304be47400SFrançois Tigeot 			u32 reserved:27;
5314be47400SFrançois Tigeot 		};
5324be47400SFrançois Tigeot 		u32 flags;
5334be47400SFrançois Tigeot 	};
5344be47400SFrançois Tigeot 	u32 version;
5354be47400SFrançois Tigeot } __packed;
5364be47400SFrançois Tigeot 
5374be47400SFrançois Tigeot union guc_log_control {
5384be47400SFrançois Tigeot 	struct {
5394be47400SFrançois Tigeot 		u32 logging_enabled:1;
5404be47400SFrançois Tigeot 		u32 reserved1:3;
5414be47400SFrançois Tigeot 		u32 verbosity:4;
5424be47400SFrançois Tigeot 		u32 reserved2:24;
5434be47400SFrançois Tigeot 	};
5444be47400SFrançois Tigeot 	u32 value;
5454be47400SFrançois Tigeot } __packed;
5464be47400SFrançois Tigeot 
547a05eeebfSFrançois Tigeot /* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */
548a85cb24fSFrançois Tigeot enum intel_guc_action {
549a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_DEFAULT = 0x0,
550a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_SAMPLE_FORCEWAKE = 0x6,
551a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_ALLOCATE_DOORBELL = 0x10,
552a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_DEALLOCATE_DOORBELL = 0x20,
553a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE = 0x30,
554a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH = 0x302,
555a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_ENTER_S_STATE = 0x501,
556a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_EXIT_S_STATE = 0x502,
557a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_SLPC_REQUEST = 0x3003,
558a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_AUTHENTICATE_HUC = 0x4000,
559*3f2dd94aSFrançois Tigeot 	INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER = 0x4505,
560*3f2dd94aSFrançois Tigeot 	INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER = 0x4506,
561a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING = 0x0E000,
562a85cb24fSFrançois Tigeot 	INTEL_GUC_ACTION_LIMIT
563a05eeebfSFrançois Tigeot };
564a05eeebfSFrançois Tigeot 
565a05eeebfSFrançois Tigeot /*
566a05eeebfSFrançois Tigeot  * The GuC sends its response to a command by overwriting the
567a05eeebfSFrançois Tigeot  * command in SS0. The response is distinguishable from a command
568a05eeebfSFrançois Tigeot  * by the fact that all the MASK bits are set. The remaining bits
569a05eeebfSFrançois Tigeot  * give more detail.
570a05eeebfSFrançois Tigeot  */
571a85cb24fSFrançois Tigeot #define	INTEL_GUC_RECV_MASK	((u32)0xF0000000)
572a85cb24fSFrançois Tigeot #define	INTEL_GUC_RECV_IS_RESPONSE(x)	((u32)(x) >= INTEL_GUC_RECV_MASK)
573a85cb24fSFrançois Tigeot #define	INTEL_GUC_RECV_STATUS(x)	(INTEL_GUC_RECV_MASK | (x))
574a05eeebfSFrançois Tigeot 
575a05eeebfSFrançois Tigeot /* GUC will return status back to SOFT_SCRATCH_O_REG */
576a85cb24fSFrançois Tigeot enum intel_guc_status {
577a85cb24fSFrançois Tigeot 	INTEL_GUC_STATUS_SUCCESS = INTEL_GUC_RECV_STATUS(0x0),
578a85cb24fSFrançois Tigeot 	INTEL_GUC_STATUS_ALLOCATE_DOORBELL_FAIL = INTEL_GUC_RECV_STATUS(0x10),
579a85cb24fSFrançois Tigeot 	INTEL_GUC_STATUS_DEALLOCATE_DOORBELL_FAIL = INTEL_GUC_RECV_STATUS(0x20),
580a85cb24fSFrançois Tigeot 	INTEL_GUC_STATUS_GENERIC_FAIL = INTEL_GUC_RECV_STATUS(0x0000F000)
581a05eeebfSFrançois Tigeot };
582a05eeebfSFrançois Tigeot 
5834be47400SFrançois Tigeot /* This action will be programmed in C1BC - SOFT_SCRATCH_15_REG */
584a85cb24fSFrançois Tigeot enum intel_guc_recv_message {
585a85cb24fSFrançois Tigeot 	INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED = BIT(1),
586a85cb24fSFrançois Tigeot 	INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER = BIT(3)
5874be47400SFrançois Tigeot };
5884be47400SFrançois Tigeot 
589a05eeebfSFrançois Tigeot #endif
590