Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / drivers / staging / vc04_services / vc-sm-cma / vc_sm_defs.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /*
4  * VideoCore Shared Memory CMA allocator
5  *
6  * Copyright: 2018, Raspberry Pi (Trading) Ltd
7  *
8  * Based on vc_sm_defs.h from the vmcs_sm driver Copyright Broadcom Corporation.
9  * All IPC messages are copied across to this file, even if the vc-sm-cma
10  * driver is not currently using them.
11  *
12  ****************************************************************************
13  */
14
15 #ifndef __VC_SM_DEFS_H__INCLUDED__
16 #define __VC_SM_DEFS_H__INCLUDED__
17
18 /* Maximum message length */
19 #define VC_SM_MAX_MSG_LEN (sizeof(union vc_sm_msg_union_t) + \
20         sizeof(struct vc_sm_msg_hdr_t))
21 #define VC_SM_MAX_RSP_LEN (sizeof(union vc_sm_msg_union_t))
22
23 /* Resource name maximum size */
24 #define VC_SM_RESOURCE_NAME 32
25
26 /*
27  * Version to be reported to the VPU
28  * VPU assumes 0 (aka 1) which does not require the released callback, nor
29  * expect the client to handle VC_MEM_REQUESTS.
30  * Version 2 requires the released callback, and must support VC_MEM_REQUESTS.
31  */
32 #define VC_SM_PROTOCOL_VERSION  2
33
34 enum vc_sm_msg_type {
35         /* Message types supported for HOST->VC direction */
36
37         /* Allocate shared memory block */
38         VC_SM_MSG_TYPE_ALLOC,
39         /* Lock allocated shared memory block */
40         VC_SM_MSG_TYPE_LOCK,
41         /* Unlock allocated shared memory block */
42         VC_SM_MSG_TYPE_UNLOCK,
43         /* Unlock allocated shared memory block, do not answer command */
44         VC_SM_MSG_TYPE_UNLOCK_NOANS,
45         /* Free shared memory block */
46         VC_SM_MSG_TYPE_FREE,
47         /* Resize a shared memory block */
48         VC_SM_MSG_TYPE_RESIZE,
49         /* Walk the allocated shared memory block(s) */
50         VC_SM_MSG_TYPE_WALK_ALLOC,
51
52         /* A previously applied action will need to be reverted */
53         VC_SM_MSG_TYPE_ACTION_CLEAN,
54
55         /*
56          * Import a physical address and wrap into a MEM_HANDLE_T.
57          * Release with VC_SM_MSG_TYPE_FREE.
58          */
59         VC_SM_MSG_TYPE_IMPORT,
60         /*
61          *Tells VC the protocol version supported by this client.
62          * 2 supports the async/cmd messages from the VPU for final release
63          * of memory, and for VC allocations.
64          */
65         VC_SM_MSG_TYPE_CLIENT_VERSION,
66         /* Response to VC request for memory */
67         VC_SM_MSG_TYPE_VC_MEM_REQUEST_REPLY,
68
69         /*
70          * Asynchronous/cmd messages supported for VC->HOST direction.
71          * Signalled by setting the top bit in vc_sm_result_t trans_id.
72          */
73
74         /*
75          * VC has finished with an imported memory allocation.
76          * Release any Linux reference counts on the underlying block.
77          */
78         VC_SM_MSG_TYPE_RELEASED,
79         /* VC request for memory */
80         VC_SM_MSG_TYPE_VC_MEM_REQUEST,
81
82         VC_SM_MSG_TYPE_MAX
83 };
84
85 /* Type of memory to be allocated */
86 enum vc_sm_alloc_type_t {
87         VC_SM_ALLOC_CACHED,
88         VC_SM_ALLOC_NON_CACHED,
89 };
90
91 /* Message header for all messages in HOST->VC direction */
92 struct vc_sm_msg_hdr_t {
93         u32 type;
94         u32 trans_id;
95         u8 body[0];
96
97 };
98
99 /* Request to allocate memory (HOST->VC) */
100 struct vc_sm_alloc_t {
101         /* type of memory to allocate */
102         enum vc_sm_alloc_type_t type;
103         /* byte amount of data to allocate per unit */
104         u32 base_unit;
105         /* number of unit to allocate */
106         u32 num_unit;
107         /* alignment to be applied on allocation */
108         u32 alignment;
109         /* identity of who allocated this block */
110         u32 allocator;
111         /* resource name (for easier tracking on vc side) */
112         char name[VC_SM_RESOURCE_NAME];
113
114 };
115
116 /* Result of a requested memory allocation (VC->HOST) */
117 struct vc_sm_alloc_result_t {
118         /* Transaction identifier */
119         u32 trans_id;
120
121         /* Resource handle */
122         u32 res_handle;
123         /* Pointer to resource buffer */
124         u32 res_mem;
125         /* Resource base size (bytes) */
126         u32 res_base_size;
127         /* Resource number */
128         u32 res_num;
129
130 };
131
132 /* Request to free a previously allocated memory (HOST->VC) */
133 struct vc_sm_free_t {
134         /* Resource handle (returned from alloc) */
135         u32 res_handle;
136         /* Resource buffer (returned from alloc) */
137         u32 res_mem;
138
139 };
140
141 /* Request to lock a previously allocated memory (HOST->VC) */
142 struct vc_sm_lock_unlock_t {
143         /* Resource handle (returned from alloc) */
144         u32 res_handle;
145         /* Resource buffer (returned from alloc) */
146         u32 res_mem;
147
148 };
149
150 /* Request to resize a previously allocated memory (HOST->VC) */
151 struct vc_sm_resize_t {
152         /* Resource handle (returned from alloc) */
153         u32 res_handle;
154         /* Resource buffer (returned from alloc) */
155         u32 res_mem;
156         /* Resource *new* size requested (bytes) */
157         u32 res_new_size;
158
159 };
160
161 /* Result of a requested memory lock (VC->HOST) */
162 struct vc_sm_lock_result_t {
163         /* Transaction identifier */
164         u32 trans_id;
165
166         /* Resource handle */
167         u32 res_handle;
168         /* Pointer to resource buffer */
169         u32 res_mem;
170         /*
171          * Pointer to former resource buffer if the memory
172          * was reallocated
173          */
174         u32 res_old_mem;
175
176 };
177
178 /* Generic result for a request (VC->HOST) */
179 struct vc_sm_result_t {
180         /* Transaction identifier */
181         u32 trans_id;
182
183         s32 success;
184
185 };
186
187 /* Request to revert a previously applied action (HOST->VC) */
188 struct vc_sm_action_clean_t {
189         /* Action of interest */
190         enum vc_sm_msg_type res_action;
191         /* Transaction identifier for the action of interest */
192         u32 action_trans_id;
193
194 };
195
196 /* Request to remove all data associated with a given allocator (HOST->VC) */
197 struct vc_sm_free_all_t {
198         /* Allocator identifier */
199         u32 allocator;
200 };
201
202 /* Request to import memory (HOST->VC) */
203 struct vc_sm_import {
204         /* type of memory to allocate */
205         enum vc_sm_alloc_type_t type;
206         /* pointer to the VC (ie physical) address of the allocated memory */
207         u32 addr;
208         /* size of buffer */
209         u32 size;
210         /* opaque handle returned in RELEASED messages */
211         u32 kernel_id;
212         /* Allocator identifier */
213         u32 allocator;
214         /* resource name (for easier tracking on vc side) */
215         char     name[VC_SM_RESOURCE_NAME];
216 };
217
218 /* Result of a requested memory import (VC->HOST) */
219 struct vc_sm_import_result {
220         /* Transaction identifier */
221         u32 trans_id;
222
223         /* Resource handle */
224         u32 res_handle;
225 };
226
227 /* Notification that VC has finished with an allocation (VC->HOST) */
228 struct vc_sm_released {
229         /* cmd type / trans_id */
230         u32 cmd;
231
232         /* pointer to the VC (ie physical) address of the allocated memory */
233         u32 addr;
234         /* size of buffer */
235         u32 size;
236         /* opaque handle returned in RELEASED messages */
237         u32 kernel_id;
238         u32 vc_handle;
239 };
240
241 /*
242  * Client informing VC as to the protocol version it supports.
243  * >=2 requires the released callback, and supports VC asking for memory.
244  * Failure means that the firmware doesn't support this call, and therefore the
245  * client should either fail, or NOT rely on getting the released callback.
246  */
247 struct vc_sm_version {
248         u32 version;
249 };
250
251 /* Request FROM VideoCore for some memory */
252 struct vc_sm_vc_mem_request {
253         /* cmd type */
254         u32 cmd;
255
256         /* trans_id (from VPU) */
257         u32 trans_id;
258         /* size of buffer */
259         u32 size;
260         /* alignment of buffer */
261         u32 align;
262         /* resource name (for easier tracking) */
263         char     name[VC_SM_RESOURCE_NAME];
264         /* VPU handle for the resource */
265         u32 vc_handle;
266 };
267
268 /* Response from the kernel to provide the VPU with some memory */
269 struct vc_sm_vc_mem_request_result {
270         /* Transaction identifier for the VPU */
271         u32 trans_id;
272         /* pointer to the physical address of the allocated memory */
273         u32 addr;
274         /* opaque handle returned in RELEASED messages */
275         u32 kernel_id;
276 };
277
278 /* Union of ALL messages */
279 union vc_sm_msg_union_t {
280         struct vc_sm_alloc_t alloc;
281         struct vc_sm_alloc_result_t alloc_result;
282         struct vc_sm_free_t free;
283         struct vc_sm_lock_unlock_t lock_unlock;
284         struct vc_sm_action_clean_t action_clean;
285         struct vc_sm_resize_t resize;
286         struct vc_sm_lock_result_t lock_result;
287         struct vc_sm_result_t result;
288         struct vc_sm_free_all_t free_all;
289         struct vc_sm_import import;
290         struct vc_sm_import_result import_result;
291         struct vc_sm_version version;
292         struct vc_sm_released released;
293         struct vc_sm_vc_mem_request vc_request;
294         struct vc_sm_vc_mem_request_result vc_request_result;
295 };
296
297 #endif /* __VC_SM_DEFS_H__INCLUDED__ */