2
* Copyright (C) 2010-2012 ARM Limited. All rights reserved.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
20
* This file contains the user space part of the UMP API.
23
#ifndef _UNIFIED_MEMORY_PROVIDER_H_
24
#define _UNIFIED_MEMORY_PROVIDER_H_
27
/** @defgroup ump_user_space_api UMP User Space API
31
#include "ump_platform.h"
40
* External representation of a UMP handle in user space.
42
typedef void * ump_handle;
45
* Typedef for a secure ID, a system wide identificator for UMP memory buffers.
47
typedef unsigned int ump_secure_id;
50
* Value to indicate an invalid UMP memory handle.
52
#define UMP_INVALID_MEMORY_HANDLE ((ump_handle)0)
55
* Value to indicate an invalid secure Id.
57
#define UMP_INVALID_SECURE_ID ((ump_secure_id)-1)
60
* UMP error codes for user space.
64
UMP_OK = 0, /**< indicates success */
65
UMP_ERROR, /**< indicates failure */
70
* Opens and initializes the UMP library.
72
* This function must be called at least once before calling any other UMP API functions.
73
* Each open is reference counted and must be matched with a call to @ref ump_close "ump_close".
77
* @return UMP_OK indicates success, UMP_ERROR indicates failure.
79
UMP_API_EXPORT ump_result ump_open(void);
83
* Terminate the UMP library.
85
* This must be called once for every successful @ref ump_open "ump_open". The UMP library is
86
* terminated when, and only when, the last open reference to the UMP interface is closed.
90
UMP_API_EXPORT void ump_close(void);
94
* Retrieves the secure ID for the specified UMP memory.
96
* This identificator is unique across the entire system, and uniquely identifies
97
* the specified UMP memory. This identificator can later be used through the
98
* @ref ump_handle_create_from_secure_id "ump_handle_create_from_secure_id" or
99
* @ref ump_dd_handle_create_from_secure_id "ump_dd_handle_create_from_secure_id"
100
* functions in order to access this UMP memory, for instance from another process.
102
* @note There is a kernel space equivalent function called @ref ump_dd_secure_id_get "ump_dd_secure_id_get"
104
* @see ump_handle_create_from_secure_id
105
* @see ump_dd_handle_create_from_secure_id
106
* @see ump_dd_secure_id_get
108
* @param mem Handle to UMP memory.
110
* @return Returns the secure ID for the specified UMP memory.
112
UMP_API_EXPORT ump_secure_id ump_secure_id_get(ump_handle mem);
116
* Retrieves a handle to allocated UMP memory.
118
* The usage of UMP memory is reference counted, so this will increment the reference
119
* count by one for the specified UMP memory.
120
* Use @ref ump_reference_release "ump_reference_release" when there is no longer any
121
* use for the retrieved handle.
123
* @note There is a kernel space equivalent function called @ref ump_dd_handle_create_from_secure_id "ump_dd_handle_create_from_secure_id"
125
* @see ump_reference_release
126
* @see ump_dd_handle_create_from_secure_id
128
* @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.
130
* @return UMP_INVALID_MEMORY_HANDLE indicates failure, otherwise a valid handle is returned.
132
UMP_API_EXPORT ump_handle ump_handle_create_from_secure_id(ump_secure_id secure_id);
136
* Retrieves the actual size of the specified UMP memory.
138
* The size is reported in bytes, and is typically page aligned.
140
* @note There is a kernel space equivalent function called @ref ump_dd_size_get "ump_dd_size_get"
142
* @see ump_dd_size_get
144
* @param mem Handle to UMP memory.
146
* @return Returns the allocated size of the specified UMP memory, in bytes.
148
UMP_API_EXPORT unsigned long ump_size_get(ump_handle mem);
152
* Read from specified UMP memory.
154
* Another way of reading from (and writing to) UMP memory is to use the
155
* @ref ump_mapped_pointer_get "ump_mapped_pointer_get" to retrieve
156
* a CPU mapped pointer to the memory.
158
* @see ump_mapped_pointer_get
160
* @param dst Destination buffer.
161
* @param src Handle to UMP memory to read from.
162
* @param offset Where to start reading, given in bytes.
163
* @param length How much to read, given in bytes.
165
UMP_API_EXPORT void ump_read(void * dst, ump_handle src, unsigned long offset, unsigned long length);
169
* Write to specified UMP memory.
171
* Another way of writing to (and reading from) UMP memory is to use the
172
* @ref ump_mapped_pointer_get "ump_mapped_pointer_get" to retrieve
173
* a CPU mapped pointer to the memory.
175
* @see ump_mapped_pointer_get
177
* @param dst Handle to UMP memory to write to.
178
* @param offset Where to start writing, given in bytes.
179
* @param src Buffer to read from.
180
* @param length How much to write, given in bytes.
182
UMP_API_EXPORT void ump_write(ump_handle dst, unsigned long offset, const void * src, unsigned long length);
186
* Retrieves a memory mapped pointer to the specified UMP memory.
188
* This function retrieves a memory mapped pointer to the specified UMP memory,
189
* that can be used by the CPU. Every successful call to
190
* @ref ump_mapped_pointer_get "ump_mapped_pointer_get" is reference counted,
191
* and must therefore be followed by a call to
192
* @ref ump_mapped_pointer_release "ump_mapped_pointer_release " when the
193
* memory mapping is no longer needed.
195
* @note Systems without a MMU for the CPU only return the physical address, because no mapping is required.
197
* @see ump_mapped_pointer_release
199
* @param mem Handle to UMP memory.
201
* @return NULL indicates failure, otherwise a CPU mapped pointer is returned.
203
UMP_API_EXPORT void * ump_mapped_pointer_get(ump_handle mem);
207
* Releases a previously mapped pointer to the specified UMP memory.
209
* The CPU mapping of the specified UMP memory memory is reference counted,
210
* so every call to @ref ump_mapped_pointer_get "ump_mapped_pointer_get" must
211
* be matched with a call to this function when the mapping is no longer needed.
213
* The CPU mapping is not removed before all references to the mapping is released.
215
* @note Systems without a MMU must still implement this function, even though no unmapping should be needed.
217
* @param mem Handle to UMP memory.
219
UMP_API_EXPORT void ump_mapped_pointer_release(ump_handle mem);
223
* Adds an extra reference to the specified UMP memory.
225
* This function adds an extra reference to the specified UMP memory. This function should
226
* be used every time a UMP memory handle is duplicated, that is, assigned to another ump_handle
227
* variable. The function @ref ump_reference_release "ump_reference_release" must then be used
228
* to release each copy of the UMP memory handle.
230
* @note You are not required to call @ref ump_reference_add "ump_reference_add"
231
* for UMP handles returned from
232
* @ref ump_handle_create_from_secure_id "ump_handle_create_from_secure_id",
233
* because these handles are already reference counted by this function.
235
* @note There is a kernel space equivalent function called @ref ump_dd_reference_add "ump_dd_reference_add"
237
* @see ump_dd_reference_add
239
* @param mem Handle to UMP memory.
241
UMP_API_EXPORT void ump_reference_add(ump_handle mem);
245
* Releases a reference from the specified UMP memory.
247
* This function should be called once for every reference to the UMP memory handle.
248
* When the last reference is released, all resources associated with this UMP memory
251
* @note There is a kernel space equivalent function called @ref ump_dd_reference_release "ump_dd_reference_release"
253
* @see ump_dd_reference_release
255
* @param mem Handle to UMP memory.
257
UMP_API_EXPORT void ump_reference_release(ump_handle mem);
265
/** @} */ /* end group ump_user_space_api */
268
#endif /*_UNIFIED_MEMORY_PROVIDER_H_ */