1 /* SPDX-License-Identifier: GPL-2.0 */
4 * VideoCore Shared Memory CMA allocator
6 * Copyright: 2018, Raspberry Pi (Trading) Ltd
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.
12 ****************************************************************************
15 #ifndef __VC_SM_DEFS_H__INCLUDED__
16 #define __VC_SM_DEFS_H__INCLUDED__
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))
23 /* Resource name maximum size */
24 #define VC_SM_RESOURCE_NAME 32
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.
32 #define VC_SM_PROTOCOL_VERSION 2
35 /* Message types supported for HOST->VC direction */
37 /* Allocate shared memory block */
39 /* Lock allocated shared memory block */
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 */
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,
52 /* A previously applied action will need to be reverted */
53 VC_SM_MSG_TYPE_ACTION_CLEAN,
56 * Import a physical address and wrap into a MEM_HANDLE_T.
57 * Release with VC_SM_MSG_TYPE_FREE.
59 VC_SM_MSG_TYPE_IMPORT,
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.
65 VC_SM_MSG_TYPE_CLIENT_VERSION,
66 /* Response to VC request for memory */
67 VC_SM_MSG_TYPE_VC_MEM_REQUEST_REPLY,
70 * Asynchronous/cmd messages supported for VC->HOST direction.
71 * Signalled by setting the top bit in vc_sm_result_t trans_id.
75 * VC has finished with an imported memory allocation.
76 * Release any Linux reference counts on the underlying block.
78 VC_SM_MSG_TYPE_RELEASED,
79 /* VC request for memory */
80 VC_SM_MSG_TYPE_VC_MEM_REQUEST,
85 /* Type of memory to be allocated */
86 enum vc_sm_alloc_type_t {
88 VC_SM_ALLOC_NON_CACHED,
91 /* Message header for all messages in HOST->VC direction */
92 struct vc_sm_msg_hdr_t {
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 */
105 /* number of unit to allocate */
107 /* alignment to be applied on allocation */
109 /* identity of who allocated this block */
111 /* resource name (for easier tracking on vc side) */
112 char name[VC_SM_RESOURCE_NAME];
116 /* Result of a requested memory allocation (VC->HOST) */
117 struct vc_sm_alloc_result_t {
118 /* Transaction identifier */
121 /* Resource handle */
123 /* Pointer to resource buffer */
125 /* Resource base size (bytes) */
127 /* Resource number */
132 /* Request to free a previously allocated memory (HOST->VC) */
133 struct vc_sm_free_t {
134 /* Resource handle (returned from alloc) */
136 /* Resource buffer (returned from alloc) */
141 /* Request to lock a previously allocated memory (HOST->VC) */
142 struct vc_sm_lock_unlock_t {
143 /* Resource handle (returned from alloc) */
145 /* Resource buffer (returned from alloc) */
150 /* Request to resize a previously allocated memory (HOST->VC) */
151 struct vc_sm_resize_t {
152 /* Resource handle (returned from alloc) */
154 /* Resource buffer (returned from alloc) */
156 /* Resource *new* size requested (bytes) */
161 /* Result of a requested memory lock (VC->HOST) */
162 struct vc_sm_lock_result_t {
163 /* Transaction identifier */
166 /* Resource handle */
168 /* Pointer to resource buffer */
171 * Pointer to former resource buffer if the memory
178 /* Generic result for a request (VC->HOST) */
179 struct vc_sm_result_t {
180 /* Transaction identifier */
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 */
196 /* Request to remove all data associated with a given allocator (HOST->VC) */
197 struct vc_sm_free_all_t {
198 /* Allocator identifier */
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 */
210 /* opaque handle returned in RELEASED messages */
212 /* Allocator identifier */
214 /* resource name (for easier tracking on vc side) */
215 char name[VC_SM_RESOURCE_NAME];
218 /* Result of a requested memory import (VC->HOST) */
219 struct vc_sm_import_result {
220 /* Transaction identifier */
223 /* Resource handle */
227 /* Notification that VC has finished with an allocation (VC->HOST) */
228 struct vc_sm_released {
229 /* cmd type / trans_id */
232 /* pointer to the VC (ie physical) address of the allocated memory */
236 /* opaque handle returned in RELEASED messages */
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.
247 struct vc_sm_version {
251 /* Request FROM VideoCore for some memory */
252 struct vc_sm_vc_mem_request {
256 /* trans_id (from VPU) */
260 /* alignment of buffer */
262 /* resource name (for easier tracking) */
263 char name[VC_SM_RESOURCE_NAME];
264 /* VPU handle for the resource */
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 */
272 /* pointer to the physical address of the allocated memory */
274 /* opaque handle returned in RELEASED messages */
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;
297 #endif /* __VC_SM_DEFS_H__INCLUDED__ */