aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/vc04_services/vc-sm-cma/vc_sm_defs.h
blob: 8a0d1f6dbfe89ede896b16549820cc9180f819a0 (plain)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/* SPDX-License-Identifier: GPL-2.0 */

/*
 * VideoCore Shared Memory CMA allocator
 *
 * Copyright: 2018, Raspberry Pi (Trading) Ltd
 *
 * Based on vc_sm_defs.h from the vmcs_sm driver Copyright Broadcom Corporation.
 * All IPC messages are copied across to this file, even if the vc-sm-cma
 * driver is not currently using them.
 *
 ****************************************************************************
 */

#ifndef __VC_SM_DEFS_H__INCLUDED__
#define __VC_SM_DEFS_H__INCLUDED__

/* FourCC code used for VCHI connection */
#define VC_SM_SERVER_NAME MAKE_FOURCC("SMEM")

/* Maximum message length */
#define VC_SM_MAX_MSG_LEN (sizeof(union vc_sm_msg_union_t) + \
	sizeof(struct vc_sm_msg_hdr_t))
#define VC_SM_MAX_RSP_LEN (sizeof(union vc_sm_msg_union_t))

/* Resource name maximum size */
#define VC_SM_RESOURCE_NAME 32

/*
 * Version to be reported to the VPU
 * VPU assumes 0 (aka 1) which does not require the released callback, nor
 * expect the client to handle VC_MEM_REQUESTS.
 * Version 2 requires the released callback, and must support VC_MEM_REQUESTS.
 */
#define VC_SM_PROTOCOL_VERSION	2

enum vc_sm_msg_type {
	/* Message types supported for HOST->VC direction */

	/* Allocate shared memory block */
	VC_SM_MSG_TYPE_ALLOC,
	/* Lock allocated shared memory block */
	VC_SM_MSG_TYPE_LOCK,
	/* Unlock allocated shared memory block */
	VC_SM_MSG_TYPE_UNLOCK,
	/* Unlock allocated shared memory block, do not answer command */
	VC_SM_MSG_TYPE_UNLOCK_NOANS,
	/* Free shared memory block */
	VC_SM_MSG_TYPE_FREE,
	/* Resize a shared memory block */
	VC_SM_MSG_TYPE_RESIZE,
	/* Walk the allocated shared memory block(s) */
	VC_SM_MSG_TYPE_WALK_ALLOC,

	/* A previously applied action will need to be reverted */
	VC_SM_MSG_TYPE_ACTION_CLEAN,

	/*
	 * Import a physical address and wrap into a MEM_HANDLE_T.
	 * Release with VC_SM_MSG_TYPE_FREE.
	 */
	VC_SM_MSG_TYPE_IMPORT,
	/*
	 *Tells VC the protocol version supported by this client.
	 * 2 supports the async/cmd messages from the VPU for final release
	 * of memory, and for VC allocations.
	 */
	VC_SM_MSG_TYPE_CLIENT_VERSION,
	/* Response to VC request for memory */
	VC_SM_MSG_TYPE_VC_MEM_REQUEST_REPLY,

	/*
	 * Asynchronous/cmd messages supported for VC->HOST direction.
	 * Signalled by setting the top bit in vc_sm_result_t trans_id.
	 */

	/*
	 * VC has finished with an imported memory allocation.
	 * Release any Linux reference counts on the underlying block.
	 */
	VC_SM_MSG_TYPE_RELEASED,
	/* VC request for memory */
	VC_SM_MSG_TYPE_VC_MEM_REQUEST,

	VC_SM_MSG_TYPE_MAX
};

/* Type of memory to be allocated */
enum vc_sm_alloc_type_t {
	VC_SM_ALLOC_CACHED,
	VC_SM_ALLOC_NON_CACHED,
};

/* Message header for all messages in HOST->VC direction */
struct vc_sm_msg_hdr_t {
	u32 type;
	u32 trans_id;
	u8 body[0];

};

/* Request to allocate memory (HOST->VC) */
struct vc_sm_alloc_t {
	/* type of memory to allocate */
	enum vc_sm_alloc_type_t type;
	/* byte amount of data to allocate per unit */
	u32 base_unit;
	/* number of unit to allocate */
	u32 num_unit;
	/* alignment to be applied on allocation */
	u32 alignment;
	/* identity of who allocated this block */
	u32 allocator;
	/* resource name (for easier tracking on vc side) */
	char name[VC_SM_RESOURCE_NAME];

};

/* Result of a requested memory allocation (VC->HOST) */
struct vc_sm_alloc_result_t {
	/* Transaction identifier */
	u32 trans_id;

	/* Resource handle */
	u32 res_handle;
	/* Pointer to resource buffer */
	u32 res_mem;
	/* Resource base size (bytes) */
	u32 res_base_size;
	/* Resource number */
	u32 res_num;

};

/* Request to free a previously allocated memory (HOST->VC) */
struct vc_sm_free_t {
	/* Resource handle (returned from alloc) */
	u32 res_handle;
	/* Resource buffer (returned from alloc) */
	u32 res_mem;

};

/* Request to lock a previously allocated memory (HOST->VC) */
struct vc_sm_lock_unlock_t {
	/* Resource handle (returned from alloc) */
	u32 res_handle;
	/* Resource buffer (returned from alloc) */
	u32 res_mem;

};

/* Request to resize a previously allocated memory (HOST->VC) */
struct vc_sm_resize_t {
	/* Resource handle (returned from alloc) */
	u32 res_handle;
	/* Resource buffer (returned from alloc) */
	u32 res_mem;
	/* Resource *new* size requested (bytes) */
	u32 res_new_size;

};

/* Result of a requested memory lock (VC->HOST) */
struct vc_sm_lock_result_t {
	/* Transaction identifier */
	u32 trans_id;

	/* Resource handle */
	u32 res_handle;
	/* Pointer to resource buffer */
	u32 res_mem;
	/*
	 * Pointer to former resource buffer if the memory
	 * was reallocated
	 */
	u32 res_old_mem;

};

/* Generic result for a request (VC->HOST) */
struct vc_sm_result_t {
	/* Transaction identifier */
	u32 trans_id;

	s32 success;

};

/* Request to revert a previously applied action (HOST->VC) */
struct vc_sm_action_clean_t {
	/* Action of interest */
	enum vc_sm_msg_type res_action;
	/* Transaction identifier for the action of interest */
	u32 action_trans_id;

};

/* Request to remove all data associated with a given allocator (HOST->VC) */
struct vc_sm_free_all_t {
	/* Allocator identifier */
	u32 allocator;
};

/* Request to import memory (HOST->VC) */
struct vc_sm_import {
	/* type of memory to allocate */
	enum vc_sm_alloc_type_t type;
	/* pointer to the VC (ie physical) address of the allocated memory */
	u32 addr;
	/* size of buffer */
	u32 size;
	/* opaque handle returned in RELEASED messages */
	u32 kernel_id;
	/* Allocator identifier */
	u32 allocator;
	/* resource name (for easier tracking on vc side) */
	char     name[VC_SM_RESOURCE_NAME];
};

/* Result of a requested memory import (VC->HOST) */
struct vc_sm_import_result {
	/* Transaction identifier */
	u32 trans_id;

	/* Resource handle */
	u32 res_handle;
};

/* Notification that VC has finished with an allocation (VC->HOST) */
struct vc_sm_released {
	/* cmd type / trans_id */
	u32 cmd;

	/* pointer to the VC (ie physical) address of the allocated memory */
	u32 addr;
	/* size of buffer */
	u32 size;
	/* opaque handle returned in RELEASED messages */
	u32 kernel_id;
	u32 vc_handle;
};

/*
 * Client informing VC as to the protocol version it supports.
 * >=2 requires the released callback, and supports VC asking for memory.
 * Failure means that the firmware doesn't support this call, and therefore the
 * client should either fail, or NOT rely on getting the released callback.
 */
struct vc_sm_version {
	u32 version;
};

/* Request FROM VideoCore for some memory */
struct vc_sm_vc_mem_request {
	/* cmd type */
	u32 cmd;

	/* trans_id (from VPU) */
	u32 trans_id;
	/* size of buffer */
	u32 size;
	/* alignment of buffer */
	u32 align;
	/* resource name (for easier tracking) */
	char     name[VC_SM_RESOURCE_NAME];
	/* VPU handle for the resource */
	u32 vc_handle;
};

/* Response from the kernel to provide the VPU with some memory */
struct vc_sm_vc_mem_request_result {
	/* Transaction identifier for the VPU */
	u32 trans_id;
	/* pointer to the physical address of the allocated memory */
	u32 addr;
	/* opaque handle returned in RELEASED messages */
	u32 kernel_id;
};

/* Union of ALL messages */
union vc_sm_msg_union_t {
	struct vc_sm_alloc_t alloc;
	struct vc_sm_alloc_result_t alloc_result;
	struct vc_sm_free_t free;
	struct vc_sm_lock_unlock_t lock_unlock;
	struct vc_sm_action_clean_t action_clean;
	struct vc_sm_resize_t resize;
	struct vc_sm_lock_result_t lock_result;
	struct vc_sm_result_t result;
	struct vc_sm_free_all_t free_all;
	struct vc_sm_import import;
	struct vc_sm_import_result import_result;
	struct vc_sm_version version;
	struct vc_sm_released released;
	struct vc_sm_vc_mem_request vc_request;
	struct vc_sm_vc_mem_request_result vc_request_result;
};

#endif /* __VC_SM_DEFS_H__INCLUDED__ */