blob: fd01c448cb2533f53939748861225f01784f4dc5 [file] [log] [blame]
codeworkxf1be2fe2012-03-24 17:38:29 +01001/*
codeworkx62f02ba2012-05-20 12:00:36 +02002 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2008-2010 ARM Limited
5 * ALL RIGHTS RESERVED
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
codeworkxf1be2fe2012-03-24 17:38:29 +01009 */
10
11/**
12 * @file ump.h
13 *
14 * This file contains the user space part of the UMP API.
15 */
16
17#ifndef _UNIFIED_MEMORY_PROVIDER_H_
18#define _UNIFIED_MEMORY_PROVIDER_H_
19
20
21/** @defgroup ump_user_space_api UMP User Space API
22 * @{ */
23
24
25#include "ump_platform.h"
26
27
codeworkx62f02ba2012-05-20 12:00:36 +020028#include "ion.h"
codeworkxf1be2fe2012-03-24 17:38:29 +010029#ifdef __cplusplus
30extern "C" {
31#endif
32
33
34/**
35 * External representation of a UMP handle in user space.
36 */
37typedef void * ump_handle;
38
39/**
40 * Typedef for a secure ID, a system wide identificator for UMP memory buffers.
41 */
42typedef unsigned int ump_secure_id;
43
44/**
45 * Value to indicate an invalid UMP memory handle.
46 */
47#define UMP_INVALID_MEMORY_HANDLE ((ump_handle)0)
48
49/**
50 * Value to indicate an invalid secure Id.
51 */
52#define UMP_INVALID_SECURE_ID ((ump_secure_id)-1)
53
54/**
55 * UMP error codes for user space.
56 */
57typedef enum
58{
codeworkx62f02ba2012-05-20 12:00:36 +020059 UMP_OK, /**< indicates success */
60 UMP_ERROR, /**< indicates failure */
codeworkxf1be2fe2012-03-24 17:38:29 +010061} ump_result;
62
63
64/**
65 * Opens and initializes the UMP library.
66 *
67 * This function must be called at least once before calling any other UMP API functions.
68 * Each open is reference counted and must be matched with a call to @ref ump_close "ump_close".
69 *
70 * @see ump_close
71 *
72 * @return UMP_OK indicates success, UMP_ERROR indicates failure.
73 */
74UMP_API_EXPORT ump_result ump_open(void);
75
76
77/**
78 * Terminate the UMP library.
79 *
80 * This must be called once for every successful @ref ump_open "ump_open". The UMP library is
81 * terminated when, and only when, the last open reference to the UMP interface is closed.
82 *
83 * @see ump_open
84 */
85UMP_API_EXPORT void ump_close(void);
86
87
88/**
89 * Retrieves the secure ID for the specified UMP memory.
90 *
91 * This identificator is unique across the entire system, and uniquely identifies
92 * the specified UMP memory. This identificator can later be used through the
93 * @ref ump_handle_create_from_secure_id "ump_handle_create_from_secure_id" or
94 * @ref ump_dd_handle_create_from_secure_id "ump_dd_handle_create_from_secure_id"
95 * functions in order to access this UMP memory, for instance from another process.
96 *
97 * @note There is a kernel space equivalent function called @ref ump_dd_secure_id_get "ump_dd_secure_id_get"
98 *
99 * @see ump_handle_create_from_secure_id
100 * @see ump_dd_handle_create_from_secure_id
101 * @see ump_dd_secure_id_get
102 *
103 * @param mem Handle to UMP memory.
104 *
105 * @return Returns the secure ID for the specified UMP memory.
106 */
107UMP_API_EXPORT ump_secure_id ump_secure_id_get(ump_handle mem);
108
109
110/**
111 * Retrieves a handle to allocated UMP memory.
112 *
113 * The usage of UMP memory is reference counted, so this will increment the reference
114 * count by one for the specified UMP memory.
115 * Use @ref ump_reference_release "ump_reference_release" when there is no longer any
116 * use for the retrieved handle.
117 *
118 * @note There is a kernel space equivalent function called @ref ump_dd_handle_create_from_secure_id "ump_dd_handle_create_from_secure_id"
119 *
120 * @see ump_reference_release
121 * @see ump_dd_handle_create_from_secure_id
122 *
123 * @param secure_id The secure ID of the UMP memory to open, that can be retrieved using the @ref ump_secure_id_get "ump_secure_id_get " function.
124 *
125 * @return UMP_INVALID_MEMORY_HANDLE indicates failure, otherwise a valid handle is returned.
126 */
127UMP_API_EXPORT ump_handle ump_handle_create_from_secure_id(ump_secure_id secure_id);
128
129
130/**
131 * Retrieves the actual size of the specified UMP memory.
132 *
133 * The size is reported in bytes, and is typically page aligned.
134 *
135 * @note There is a kernel space equivalent function called @ref ump_dd_size_get "ump_dd_size_get"
136 *
137 * @see ump_dd_size_get
138 *
139 * @param mem Handle to UMP memory.
140 *
141 * @return Returns the allocated size of the specified UMP memory, in bytes.
142 */
143UMP_API_EXPORT unsigned long ump_size_get(ump_handle mem);
144
145
146/**
147 * Read from specified UMP memory.
148 *
149 * Another way of reading from (and writing to) UMP memory is to use the
150 * @ref ump_mapped_pointer_get "ump_mapped_pointer_get" to retrieve
151 * a CPU mapped pointer to the memory.
152 *
153 * @see ump_mapped_pointer_get
154 *
155 * @param dst Destination buffer.
156 * @param src Handle to UMP memory to read from.
157 * @param offset Where to start reading, given in bytes.
158 * @param length How much to read, given in bytes.
159 */
160UMP_API_EXPORT void ump_read(void * dst, ump_handle src, unsigned long offset, unsigned long length);
161
162
163/**
164 * Write to specified UMP memory.
165 *
166 * Another way of writing to (and reading from) UMP memory is to use the
167 * @ref ump_mapped_pointer_get "ump_mapped_pointer_get" to retrieve
168 * a CPU mapped pointer to the memory.
169 *
170 * @see ump_mapped_pointer_get
171 *
172 * @param dst Handle to UMP memory to write to.
173 * @param offset Where to start writing, given in bytes.
174 * @param src Buffer to read from.
175 * @param length How much to write, given in bytes.
176 */
177UMP_API_EXPORT void ump_write(ump_handle dst, unsigned long offset, const void * src, unsigned long length);
178
179
180/**
181 * Retrieves a memory mapped pointer to the specified UMP memory.
182 *
183 * This function retrieves a memory mapped pointer to the specified UMP memory,
184 * that can be used by the CPU. Every successful call to
185 * @ref ump_mapped_pointer_get "ump_mapped_pointer_get" is reference counted,
186 * and must therefor be followed by a call to
187 * @ref ump_mapped_pointer_release "ump_mapped_pointer_release " when the
188 * memory mapping is no longer needed.
189 *
190 * @note Systems without a MMU for the CPU only return the physical address, because no mapping is required.
191 *
192 * @see ump_mapped_pointer_release
193 *
194 * @param mem Handle to UMP memory.
195 *
196 * @return NULL indicates failure, otherwise a CPU mapped pointer is returned.
197 */
198UMP_API_EXPORT void * ump_mapped_pointer_get(ump_handle mem);
199
200
201/**
202 * Releases a previously mapped pointer to the specified UMP memory.
203 *
204 * The CPU mapping of the specified UMP memory memory is reference counted,
205 * so every call to @ref ump_mapped_pointer_get "ump_mapped_pointer_get" must
206 * be matched with a call to this function when the mapping is no longer needed.
207 *
208 * The CPU mapping is not removed before all references to the mapping is released.
209 *
210 * @note Systems without a MMU must still implement this function, even though no unmapping should be needed.
211 *
212 * @param mem Handle to UMP memory.
213 */
214UMP_API_EXPORT void ump_mapped_pointer_release(ump_handle mem);
215
216
217/**
218 * Adds an extra reference to the specified UMP memory.
219 *
220 * This function adds an extra reference to the specified UMP memory. This function should
221 * be used every time a UMP memory handle is duplicated, that is, assigned to another ump_handle
222 * variable. The function @ref ump_reference_release "ump_reference_release" must then be used
223 * to release each copy of the UMP memory handle.
224 *
225 * @note You are not required to call @ref ump_reference_add "ump_reference_add"
226 * for UMP handles returned from
227 * @ref ump_handle_create_from_secure_id "ump_handle_create_from_secure_id",
228 * because these handles are already reference counted by this function.
229 *
230 * @note There is a kernel space equivalent function called @ref ump_dd_reference_add "ump_dd_reference_add"
231 *
232 * @see ump_dd_reference_add
233 *
234 * @param mem Handle to UMP memory.
235 */
236UMP_API_EXPORT void ump_reference_add(ump_handle mem);
237
238
239/**
240 * Releases a reference from the specified UMP memory.
241 *
242 * This function should be called once for every reference to the UMP memory handle.
243 * When the last reference is released, all resources associated with this UMP memory
244 * handle are freed.
245 *
246 * @note There is a kernel space equivalent function called @ref ump_dd_reference_release "ump_dd_reference_release"
247 *
248 * @see ump_dd_reference_release
249 *
250 * @param mem Handle to UMP memory.
251 */
252UMP_API_EXPORT void ump_reference_release(ump_handle mem);
253
254
255#ifdef __cplusplus
256}
257#endif
258
259
260/** @} */ /* end group ump_user_space_api */
261
262
263#endif /*_UNIFIED_MEMORY_PROVIDER_H_ */