drm/GPU: Add support Imagination PowerVR GPU driver v1.17
[platform/kernel/linux-starfive.git] / drivers / gpu / drm / img / img-rogue / include / pvrsrv_tlcommon.h
1 /*************************************************************************/ /*!
2 @File
3 @Title          Services Transport Layer common types and definitions
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Transport layer common types and definitions included into
6                 both user mode and kernel mode source.
7 @License        Dual MIT/GPLv2
8
9 The contents of this file are subject to the MIT license as set out below.
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
20
21 Alternatively, the contents of this file may be used under the terms of
22 the GNU General Public License Version 2 ("GPL") in which case the provisions
23 of GPL are applicable instead of those above.
24
25 If you wish to allow use of your version of this file only under the terms of
26 GPL, and not to allow others to use your version of this file under the terms
27 of the MIT license, indicate your decision by deleting the provisions above
28 and replace them with the notice and other provisions required by GPL as set
29 out in the file called "GPL-COPYING" included in this distribution. If you do
30 not delete the provisions above, a recipient may use your version of this file
31 under the terms of either the MIT license or GPL.
32
33 This License is also included in this distribution in the file called
34 "MIT-COPYING".
35
36 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
37 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
40 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
41 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
42 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 */ /**************************************************************************/
44 #ifndef PVR_TLCOMMON_H
45 #define PVR_TLCOMMON_H
46
47 #if defined(__cplusplus)
48 extern "C" {
49 #endif
50
51 #include "img_defs.h"
52
53
54 /*! Handle type for stream descriptor objects as created by this API */
55 typedef IMG_HANDLE PVRSRVTL_SD;
56
57 /*! Maximum stream name length including the null byte */
58 #define PRVSRVTL_MAX_STREAM_NAME_SIZE   40U
59
60 /*! Maximum number of streams expected to exist */
61 #define PVRSRVTL_MAX_DISCOVERABLE_STREAMS_BUFFER (32*PRVSRVTL_MAX_STREAM_NAME_SIZE)
62
63 /*! Packet lengths are always rounded up to a multiple of 8 bytes */
64 #define PVRSRVTL_PACKET_ALIGNMENT               8U
65 #define PVRSRVTL_ALIGN(x)                               (((x)+PVRSRVTL_PACKET_ALIGNMENT-1U) & ~(PVRSRVTL_PACKET_ALIGNMENT-1U))
66
67
68 /*! A packet is made up of a header structure followed by the data bytes.
69  * There are 3 types of packet: normal (has data), data lost and padding,
70  * see packet flags. Header kept small to reduce data overhead.
71  *
72  * if the ORDER of the structure members is changed, please UPDATE the
73  * PVRSRVTL_PACKET_FLAG_OFFSET macro.
74  *
75  * Layout of uiTypeSize member is :
76  *
77  * |<---------------------------32-bits------------------------------>|
78  * |<----8---->|<-----1----->|<----7--->|<------------16------------->|
79  * |    Type   | Drop-Oldest |  UNUSED  |             Size            |
80  *
81  */
82 typedef struct
83 {
84         IMG_UINT32 uiTypeSize;  /*!< Type, Drop-Oldest flag & number of bytes following header */
85         IMG_UINT32 uiReserved;  /*!< Reserve, packets and data must be 8 byte aligned */
86
87         /* First bytes of TL packet data follow header ... */
88 } PVRSRVTL_PACKETHDR, *PVRSRVTL_PPACKETHDR;
89
90 /* Structure must always be a size multiple of 8 as stream buffer
91  * still an array of IMG_UINT32s.
92  */
93 static_assert((sizeof(PVRSRVTL_PACKETHDR) & (PVRSRVTL_PACKET_ALIGNMENT-1U)) == 0U,
94                           "sizeof(PVRSRVTL_PACKETHDR) must be a multiple of 8");
95
96 /*! Packet header reserved word fingerprint "TLP1" */
97 #define PVRSRVTL_PACKETHDR_RESERVED 0x31504C54U
98
99 /*! Packet header mask used to extract the size from the uiTypeSize member.
100  * Do not use directly, see GET macros.
101  */
102 #define PVRSRVTL_PACKETHDR_SIZE_MASK    0x0000FFFFU
103 #define PVRSRVTL_MAX_PACKET_SIZE        (PVRSRVTL_PACKETHDR_SIZE_MASK & ~0xFU)
104
105
106 /*! Packet header mask used to extract the type from the uiTypeSize member.
107  * Do not use directly, see GET macros.
108  */
109 #define PVRSRVTL_PACKETHDR_TYPE_MASK    0xFF000000U
110 #define PVRSRVTL_PACKETHDR_TYPE_OFFSET  24U
111
112 /*! Packet header mask used to check if packets before this one were dropped
113  * or not. Do not use directly, see GET macros.
114  */
115 #define PVRSRVTL_PACKETHDR_OLDEST_DROPPED_MASK    0x00800000U
116 #define PVRSRVTL_PACKETHDR_OLDEST_DROPPED_OFFSET    23U
117
118 /*! Packet type enumeration.
119  */
120 typedef IMG_UINT32 PVRSRVTL_PACKETTYPE;
121
122 /*! Undefined packet */
123 #define PVRSRVTL_PACKETTYPE_UNDEF 0U
124
125 /*! Normal packet type. Indicates data follows the header.
126  */
127 #define PVRSRVTL_PACKETTYPE_DATA 1U
128
129 /*! When seen this packet type indicates that at this moment in the stream
130  * packet(s) were not able to be accepted due to space constraints and
131  * that recent data may be lost - depends on how the producer handles the
132  * error. Such packets have no data, data length is 0.
133  */
134 #define PVRSRVTL_PACKETTYPE_MOST_RECENT_WRITE_FAILED 2U
135
136 /*! Packets with this type set are padding packets that contain undefined
137  * data and must be ignored/skipped by the client. They are used when the
138  * circular stream buffer wraps around and there is not enough space for
139  * the data at the end of the buffer. Such packets have a length of 0 or
140  * more.
141  */
142 #define PVRSRVTL_PACKETTYPE_PADDING 3U
143
144 /*! This packet type conveys to the stream consumer that the stream
145  * producer has reached the end of data for that data sequence. The
146  * TLDaemon has several options for processing these packets that can
147  * be selected on a per stream basis.
148  */
149 #define PVRSRVTL_PACKETTYPE_MARKER_EOS 4U
150
151 /*! This is same as PVRSRVTL_PACKETTYPE_MARKER_EOS but additionally removes
152  * old data record output file before opening new/next one
153  */
154 #define PVRSRVTL_PACKETTYPE_MARKER_EOS_REMOVEOLD 5U
155
156 /*! Packet emitted on first stream opened by writer. Packet carries a name
157  * of the opened stream in a form of null-terminated string.
158  */
159 #define PVRSRVTL_PACKETTYPE_STREAM_OPEN_FOR_WRITE 6U
160
161 /*! Packet emitted on last stream closed by writer. Packet carries a name
162  * of the closed stream in a form of null-terminated string.
163  */
164 #define PVRSRVTL_PACKETTYPE_STREAM_CLOSE_FOR_WRITE 7U
165
166 #define PVRSRVTL_PACKETTYPE_LAST 8U
167
168 /* The SET_PACKET_* macros rely on the order the PVRSRVTL_PACKETHDR members are declared:
169  * uiFlags is the upper half of a structure consisting of 2 uint16 quantities.
170  */
171 #define PVRSRVTL_SET_PACKET_DATA(len)       (len) | (PVRSRVTL_PACKETTYPE_DATA                     << PVRSRVTL_PACKETHDR_TYPE_OFFSET)
172 #define PVRSRVTL_SET_PACKET_PADDING(len)    (len) | (PVRSRVTL_PACKETTYPE_PADDING                  << PVRSRVTL_PACKETHDR_TYPE_OFFSET)
173 #define PVRSRVTL_SET_PACKET_WRITE_FAILED    (0U)   | (PVRSRVTL_PACKETTYPE_MOST_RECENT_WRITE_FAILED << PVRSRVTL_PACKETHDR_TYPE_OFFSET)
174 #define PVRSRVTL_SET_PACKET_HDR(len, type)  (len) | ((type)                                       << PVRSRVTL_PACKETHDR_TYPE_OFFSET)
175
176 /*! Returns the number of bytes of data in the packet.
177  * p may be any address type.
178  */
179 #define GET_PACKET_DATA_LEN(p)  \
180         ((IMG_UINT32) ((PVRSRVTL_PPACKETHDR) (void *) (p))->uiTypeSize & PVRSRVTL_PACKETHDR_SIZE_MASK)
181
182
183 /*! Returns a IMG_BYTE* pointer to the first byte of data in the packet */
184 #define GET_PACKET_DATA_PTR(p)  \
185         (((IMG_UINT8 *) (void *) (p)) + sizeof(PVRSRVTL_PACKETHDR))
186
187 /*! Turns the packet address p into a PVRSRVTL_PPACKETHDR pointer type.
188  */
189 #define GET_PACKET_HDR(p)               ((PVRSRVTL_PPACKETHDR) ((void *) (p)))
190
191 /*! Given a PVRSRVTL_PPACKETHDR address, return the address of the next pack
192  *  It is up to the caller to determine if the new address is within the
193  *  packet buffer.
194  */
195 #define GET_NEXT_PACKET_ADDR(p) \
196         GET_PACKET_HDR( \
197                 GET_PACKET_DATA_PTR(p) + \
198                 ( \
199                         (GET_PACKET_DATA_LEN(p) + (PVRSRVTL_PACKET_ALIGNMENT-1U)) & \
200                         (~(PVRSRVTL_PACKET_ALIGNMENT-1U)) \
201                 ) \
202         )
203
204 /*! Get the type of the packet. p is of type PVRSRVTL_PPACKETHDR.
205  */
206 #define GET_PACKET_TYPE(p)              (((p)->uiTypeSize & PVRSRVTL_PACKETHDR_TYPE_MASK)>>PVRSRVTL_PACKETHDR_TYPE_OFFSET)
207
208 /*! Set PACKETS_DROPPED flag in packet header as a part of uiTypeSize.
209  * p is of type PVRSRVTL_PPACKETHDR.
210  */
211 #define SET_PACKETS_DROPPED(p)          (((p)->uiTypeSize) | (1UL << PVRSRVTL_PACKETHDR_OLDEST_DROPPED_OFFSET))
212
213 /*! Check if packets were dropped before this packet.
214  * p is of type PVRSRVTL_PPACKETHDR.
215  */
216 #define CHECK_PACKETS_DROPPED(p)        (((p)->uiTypeSize & PVRSRVTL_PACKETHDR_OLDEST_DROPPED_MASK)>>PVRSRVTL_PACKETHDR_OLDEST_DROPPED_OFFSET)
217
218 /*! Flags for use with PVRSRVTLOpenStream
219  * 0x01 - Do not block in PVRSRVTLAcquireData() when no bytes are available
220  * 0x02 - When the stream does not exist wait for a bit (2s) in
221  *        PVRSRVTLOpenStream() and then exit with a timeout error if it still
222  *        does not exist.
223  * 0x04 - Open stream for write only operations.
224  *        If flag is not used stream is opened as read-only. This flag is
225  *        required if one wants to call reserve/commit/write function on the
226  *        stream descriptor. Read from on the stream descriptor opened
227  *        with this flag will fail.
228  * 0x08 - Disable Producer Callback.
229  *        If this flag is set and the stream becomes empty, do not call any
230  *        associated producer callback to generate more data from the reader
231  *        context.
232  * 0x10 - Reset stream on open.
233  *        When this flag is used the stream will drop all of the stored data.
234  * 0x20 - Limit read position to the write position at time the stream
235  *        was opened. Hence this flag will freeze the content read to that
236  *        produced before the stream was opened for reading.
237  * 0x40 - Ignore Open Callback.
238  *        When this flag is set ignore any OnReaderOpenCallback setting for
239  *        the stream. This allows access to the stream to be made without
240  *        generating any extra packets into the stream.
241  */
242
243 #define PVRSRV_STREAM_FLAG_NONE                        (0U)
244 #define PVRSRV_STREAM_FLAG_ACQUIRE_NONBLOCKING         (1U<<0)
245 #define PVRSRV_STREAM_FLAG_OPEN_WAIT                   (1U<<1)
246 #define PVRSRV_STREAM_FLAG_OPEN_WO                     (1U<<2)
247 #define PVRSRV_STREAM_FLAG_DISABLE_PRODUCER_CALLBACK   (1U<<3)
248 #define PVRSRV_STREAM_FLAG_RESET_ON_OPEN               (1U<<4)
249 #define PVRSRV_STREAM_FLAG_READ_LIMIT                  (1U<<5)
250 #define PVRSRV_STREAM_FLAG_IGNORE_OPEN_CALLBACK        (1U<<6)
251
252
253 #if defined(__cplusplus)
254 }
255 #endif
256
257 #endif /* PVR_TLCOMMON_H */
258 /******************************************************************************
259  End of file (pvrsrv_tlcommon.h)
260 ******************************************************************************/