xref: /openbsd-src/sys/dev/pci/drm/i915/gt/uc/abi/guc_communication_ctb_abi.h (revision f005ef32267c16bdb134f0e9fa4477dbe07c263a)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2014-2021 Intel Corporation
4  */
5 
6 #ifndef _ABI_GUC_COMMUNICATION_CTB_ABI_H
7 #define _ABI_GUC_COMMUNICATION_CTB_ABI_H
8 
9 #include <linux/types.h>
10 #include <linux/build_bug.h>
11 
12 #include "guc_messages_abi.h"
13 
14 /**
15  * DOC: CT Buffer
16  *
17  * Circular buffer used to send `CTB Message`_
18  */
19 
20 /**
21  * DOC: CTB Descriptor
22  *
23  *  +---+-------+--------------------------------------------------------------+
24  *  |   | Bits  | Description                                                  |
25  *  +===+=======+==============================================================+
26  *  | 0 |  31:0 | **HEAD** - offset (in dwords) to the last dword that was     |
27  *  |   |       | read from the `CT Buffer`_.                                  |
28  *  |   |       | It can only be updated by the receiver.                      |
29  *  +---+-------+--------------------------------------------------------------+
30  *  | 1 |  31:0 | **TAIL** - offset (in dwords) to the last dword that was     |
31  *  |   |       | written to the `CT Buffer`_.                                 |
32  *  |   |       | It can only be updated by the sender.                        |
33  *  +---+-------+--------------------------------------------------------------+
34  *  | 2 |  31:0 | **STATUS** - status of the CTB                               |
35  *  |   |       |                                                              |
36  *  |   |       |   - _`GUC_CTB_STATUS_NO_ERROR` = 0 (normal operation)        |
37  *  |   |       |   - _`GUC_CTB_STATUS_OVERFLOW` = 1 (head/tail too large)     |
38  *  |   |       |   - _`GUC_CTB_STATUS_UNDERFLOW` = 2 (truncated message)      |
39  *  |   |       |   - _`GUC_CTB_STATUS_MISMATCH` = 4 (head/tail modified)      |
40  *  |   |       |   - _`GUC_CTB_STATUS_UNUSED` = 8 (CTB is not in use)         |
41  *  +---+-------+--------------------------------------------------------------+
42  *  |...|       | RESERVED = MBZ                                               |
43  *  +---+-------+--------------------------------------------------------------+
44  *  | 15|  31:0 | RESERVED = MBZ                                               |
45  *  +---+-------+--------------------------------------------------------------+
46  */
47 
48 struct guc_ct_buffer_desc {
49 	u32 head;
50 	u32 tail;
51 	u32 status;
52 #define GUC_CTB_STATUS_NO_ERROR				0
53 #define GUC_CTB_STATUS_OVERFLOW				BIT(0)
54 #define GUC_CTB_STATUS_UNDERFLOW			BIT(1)
55 #define GUC_CTB_STATUS_MISMATCH				BIT(2)
56 #define GUC_CTB_STATUS_UNUSED				BIT(3)
57 	u32 reserved[13];
58 } __packed;
59 #ifdef notyet
60 static_assert(sizeof(struct guc_ct_buffer_desc) == 64);
61 #endif
62 
63 /**
64  * DOC: CTB Message
65  *
66  *  +---+-------+--------------------------------------------------------------+
67  *  |   | Bits  | Description                                                  |
68  *  +===+=======+==============================================================+
69  *  | 0 | 31:16 | **FENCE** - message identifier                               |
70  *  |   +-------+--------------------------------------------------------------+
71  *  |   | 15:12 | **FORMAT** - format of the CTB message                       |
72  *  |   |       |  - _`GUC_CTB_FORMAT_HXG` = 0 - see `CTB HXG Message`_        |
73  *  |   +-------+--------------------------------------------------------------+
74  *  |   |  11:8 | **RESERVED**                                                 |
75  *  |   +-------+--------------------------------------------------------------+
76  *  |   |   7:0 | **NUM_DWORDS** - length of the CTB message (w/o header)      |
77  *  +---+-------+--------------------------------------------------------------+
78  *  | 1 |  31:0 | optional (depends on FORMAT)                                 |
79  *  +---+-------+                                                              |
80  *  |...|       |                                                              |
81  *  +---+-------+                                                              |
82  *  | n |  31:0 |                                                              |
83  *  +---+-------+--------------------------------------------------------------+
84  */
85 
86 #define GUC_CTB_HDR_LEN				1u
87 #define GUC_CTB_MSG_MIN_LEN			GUC_CTB_HDR_LEN
88 #define GUC_CTB_MSG_MAX_LEN			256u
89 #define GUC_CTB_MSG_0_FENCE			(0xffffU << 16)
90 #define GUC_CTB_MSG_0_FORMAT			(0xf << 12)
91 #define   GUC_CTB_FORMAT_HXG			0u
92 #define GUC_CTB_MSG_0_RESERVED			(0xf << 8)
93 #define GUC_CTB_MSG_0_NUM_DWORDS		(0xff << 0)
94 
95 /**
96  * DOC: CTB HXG Message
97  *
98  *  +---+-------+--------------------------------------------------------------+
99  *  |   | Bits  | Description                                                  |
100  *  +===+=======+==============================================================+
101  *  | 0 | 31:16 | FENCE                                                        |
102  *  |   +-------+--------------------------------------------------------------+
103  *  |   | 15:12 | FORMAT = GUC_CTB_FORMAT_HXG_                                 |
104  *  |   +-------+--------------------------------------------------------------+
105  *  |   |  11:8 | RESERVED = MBZ                                               |
106  *  |   +-------+--------------------------------------------------------------+
107  *  |   |   7:0 | NUM_DWORDS = length (in dwords) of the embedded HXG message  |
108  *  +---+-------+--------------------------------------------------------------+
109  *  | 1 |  31:0 |                                                              |
110  *  +---+-------+                                                              |
111  *  |...|       | [Embedded `HXG Message`_]                                    |
112  *  +---+-------+                                                              |
113  *  | n |  31:0 |                                                              |
114  *  +---+-------+--------------------------------------------------------------+
115  */
116 
117 #define GUC_CTB_HXG_MSG_MIN_LEN		(GUC_CTB_MSG_MIN_LEN + GUC_HXG_MSG_MIN_LEN)
118 #define GUC_CTB_HXG_MSG_MAX_LEN		GUC_CTB_MSG_MAX_LEN
119 
120 /**
121  * DOC: CTB based communication
122  *
123  * The CTB (command transport buffer) communication between Host and GuC
124  * is based on u32 data stream written to the shared buffer. One buffer can
125  * be used to transmit data only in one direction (one-directional channel).
126  *
127  * Current status of the each buffer is stored in the buffer descriptor.
128  * Buffer descriptor holds tail and head fields that represents active data
129  * stream. The tail field is updated by the data producer (sender), and head
130  * field is updated by the data consumer (receiver)::
131  *
132  *      +------------+
133  *      | DESCRIPTOR |          +=================+============+========+
134  *      +============+          |                 | MESSAGE(s) |        |
135  *      | address    |--------->+=================+============+========+
136  *      +------------+
137  *      | head       |          ^-----head--------^
138  *      +------------+
139  *      | tail       |          ^---------tail-----------------^
140  *      +------------+
141  *      | size       |          ^---------------size--------------------^
142  *      +------------+
143  *
144  * Each message in data stream starts with the single u32 treated as a header,
145  * followed by optional set of u32 data that makes message specific payload::
146  *
147  *      +------------+---------+---------+---------+
148  *      |         MESSAGE                          |
149  *      +------------+---------+---------+---------+
150  *      |   msg[0]   |   [1]   |   ...   |  [n-1]  |
151  *      +------------+---------+---------+---------+
152  *      |   MESSAGE  |       MESSAGE PAYLOAD       |
153  *      +   HEADER   +---------+---------+---------+
154  *      |            |    0    |   ...   |    n    |
155  *      +======+=====+=========+=========+=========+
156  *      | 31:16| code|         |         |         |
157  *      +------+-----+         |         |         |
158  *      |  15:5|flags|         |         |         |
159  *      +------+-----+         |         |         |
160  *      |   4:0|  len|         |         |         |
161  *      +------+-----+---------+---------+---------+
162  *
163  *                   ^-------------len-------------^
164  *
165  * The message header consists of:
166  *
167  * - **len**, indicates length of the message payload (in u32)
168  * - **code**, indicates message code
169  * - **flags**, holds various bits to control message handling
170  */
171 
172 #endif /* _ABI_GUC_COMMUNICATION_CTB_ABI_H */
173