aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/broadcom/vc_sm/vc_sm_defs.h
blob: de6afe9f65af45582c79a62abd41c688274ad8f2 (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
/*
 ****************************************************************************
 * Copyright 2011 Broadcom Corporation.  All rights reserved.
 *
 * Unless you and Broadcom execute a separate written software license
 * agreement governing use of this software, this software is licensed to you
 * under the terms of the GNU General Public License version 2, available at
 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
 *
 * Notwithstanding the above, under no circumstances may you combine this
 * software in any way with any other Broadcom software provided under a
 * license other than the GPL, without Broadcom's express prior written
 * consent.
 ****************************************************************************
 */

#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

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,

	/* Message types supported for VC->HOST direction */

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

	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 {
	int32_t type;
	uint32_t trans_id;
	uint8_t 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 */
	uint32_t base_unit;
	/* number of unit to allocate */
	uint32_t num_unit;
	/* alignement to be applied on allocation */
	uint32_t alignement;
	/* identity of who allocated this block */
	uint32_t 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 */
	uint32_t trans_id;

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

};

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

};

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

};

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

};

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

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

};

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

	int32_t 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 */
	uint32_t action_trans_id;

};

/* Request to remove all data associated with a given allocator (HOST->VC) */
struct vc_sm_free_all_t {
	/* Allocator identifier */
	uint32_t 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 */
	uint32_t addr;
	/* size of buffer */
	uint32_t size;
	/* opaque handle returned in RELEASED messages */
	int32_t  kernel_id;
	/* Allocator identifier */
	uint32_t 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 */
	uint32_t trans_id;

	/* Resource handle */
	uint32_t res_handle;
};

/* Notification that VC has finished with an allocation (VC->HOST) */
struct vc_sm_released {
	/* pointer to the VC (ie physical) address of the allocated memory */
	uint32_t addr;
	/* size of buffer */
	uint32_t size;
	/* opaque handle returned in RELEASED messages */
	int32_t  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_released released;
};

#endif /* __VC_SM_DEFS_H__INCLUDED__ */