2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 * @file ump_kernel_interface.h
14 * This file contains the kernel space part of the UMP API.
17 #ifndef __UMP_KERNEL_INTERFACE_H__
18 #define __UMP_KERNEL_INTERFACE_H__
21 /** @defgroup ump_kernel_space_api UMP Kernel Space API
25 #include "ump_kernel_platform.h"
35 * External representation of a UMP handle in kernel space.
37 typedef void * ump_dd_handle;
40 * Typedef for a secure ID, a system wide identificator for UMP memory buffers.
42 typedef unsigned int ump_secure_id;
46 * Value to indicate an invalid UMP memory handle.
48 #define UMP_DD_HANDLE_INVALID ((ump_dd_handle)0)
52 * Value to indicate an invalid secure Id.
54 #define UMP_INVALID_SECURE_ID ((ump_secure_id)-1)
58 * UMP error codes for kernel space.
62 UMP_DD_SUCCESS, /**< indicates success */
63 UMP_DD_INVALID, /**< indicates failure */
68 * Struct used to describe a physical block used by UMP memory
70 typedef struct ump_dd_physical_block
72 unsigned long addr; /**< The physical address of the block */
73 unsigned long size; /**< The length of the block, typically page aligned */
74 } ump_dd_physical_block;
78 * Retrieves the secure ID for the specified UMP memory.
80 * This identificator is unique across the entire system, and uniquely identifies
81 * the specified UMP memory. This identificator can later be used through the
82 * @ref ump_dd_handle_create_from_secure_id "ump_dd_handle_create_from_secure_id" or
83 * @ref ump_handle_create_from_secure_id "ump_handle_create_from_secure_id"
84 * functions in order to access this UMP memory, for instance from another process.
86 * @note There is a user space equivalent function called @ref ump_secure_id_get "ump_secure_id_get"
88 * @see ump_dd_handle_create_from_secure_id
89 * @see ump_handle_create_from_secure_id
90 * @see ump_secure_id_get
92 * @param mem Handle to UMP memory.
94 * @return Returns the secure ID for the specified UMP memory.
96 UMP_KERNEL_API_EXPORT ump_secure_id ump_dd_secure_id_get(ump_dd_handle mem);
100 * Retrieves a handle to allocated UMP memory.
102 * The usage of UMP memory is reference counted, so this will increment the reference
103 * count by one for the specified UMP memory.
104 * Use @ref ump_dd_reference_release "ump_dd_reference_release" when there is no longer any
105 * use for the retrieved handle.
107 * @note There is a user space equivalent function called @ref ump_handle_create_from_secure_id "ump_handle_create_from_secure_id"
109 * @see ump_dd_reference_release
110 * @see ump_handle_create_from_secure_id
112 * @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.
114 * @return UMP_INVALID_MEMORY_HANDLE indicates failure, otherwise a valid handle is returned.
116 UMP_KERNEL_API_EXPORT ump_dd_handle ump_dd_handle_create_from_secure_id(ump_secure_id secure_id);
120 * Retrieves the number of physical blocks used by the specified UMP memory.
122 * This function retrieves the number of @ref ump_dd_physical_block "ump_dd_physical_block" structs needed
123 * to describe the physical memory layout of the given UMP memory. This can later be used when calling
124 * the functions @ref ump_dd_phys_blocks_get "ump_dd_phys_blocks_get" and
125 * @ref ump_dd_phys_block_get "ump_dd_phys_block_get".
127 * @see ump_dd_phys_blocks_get
128 * @see ump_dd_phys_block_get
130 * @param mem Handle to UMP memory.
132 * @return The number of ump_dd_physical_block structs required to describe the physical memory layout of the specified UMP memory.
134 UMP_KERNEL_API_EXPORT unsigned long ump_dd_phys_block_count_get(ump_dd_handle mem);
138 * Retrieves all physical memory block information for specified UMP memory.
140 * This function can be used by other device drivers in order to create MMU tables.
142 * @note This function will fail if the num_blocks parameter is either to large or to small.
144 * @see ump_dd_phys_block_get
146 * @param mem Handle to UMP memory.
147 * @param blocks An array of @ref ump_dd_physical_block "ump_dd_physical_block" structs that will receive the physical description.
148 * @param num_blocks The number of blocks to return in the blocks array. Use the function
149 * @ref ump_dd_phys_block_count_get "ump_dd_phys_block_count_get" first to determine the number of blocks required.
151 * @return UMP_DD_SUCCESS indicates success, UMP_DD_INVALID indicates failure.
153 UMP_KERNEL_API_EXPORT ump_dd_status_code ump_dd_phys_blocks_get(ump_dd_handle mem, ump_dd_physical_block * blocks, unsigned long num_blocks);
157 * Retrieves the physical memory block information for specified block for the specified UMP memory.
159 * This function can be used by other device drivers in order to create MMU tables.
161 * @note This function will return UMP_DD_INVALID if the specified index is out of range.
163 * @see ump_dd_phys_blocks_get
165 * @param mem Handle to UMP memory.
166 * @param index Which physical info block to retrieve.
167 * @param block Pointer to a @ref ump_dd_physical_block "ump_dd_physical_block" struct which will receive the requested information.
169 * @return UMP_DD_SUCCESS indicates success, UMP_DD_INVALID indicates failure.
171 UMP_KERNEL_API_EXPORT ump_dd_status_code ump_dd_phys_block_get(ump_dd_handle mem, unsigned long index, ump_dd_physical_block * block);
175 * Retrieves the actual size of the specified UMP memory.
177 * The size is reported in bytes, and is typically page aligned.
179 * @note There is a user space equivalent function called @ref ump_size_get "ump_size_get"
183 * @param mem Handle to UMP memory.
185 * @return Returns the allocated size of the specified UMP memory, in bytes.
187 UMP_KERNEL_API_EXPORT unsigned long ump_dd_size_get(ump_dd_handle mem);
191 * Adds an extra reference to the specified UMP memory.
193 * This function adds an extra reference to the specified UMP memory. This function should
194 * be used every time a UMP memory handle is duplicated, that is, assigned to another ump_dd_handle
195 * variable. The function @ref ump_dd_reference_release "ump_dd_reference_release" must then be used
196 * to release each copy of the UMP memory handle.
198 * @note You are not required to call @ref ump_dd_reference_add "ump_dd_reference_add"
199 * for UMP handles returned from
200 * @ref ump_dd_handle_create_from_secure_id "ump_dd_handle_create_from_secure_id",
201 * because these handles are already reference counted by this function.
203 * @note There is a user space equivalent function called @ref ump_reference_add "ump_reference_add"
205 * @see ump_reference_add
207 * @param mem Handle to UMP memory.
209 UMP_KERNEL_API_EXPORT void ump_dd_reference_add(ump_dd_handle mem);
213 * Releases a reference from the specified UMP memory.
215 * This function should be called once for every reference to the UMP memory handle.
216 * When the last reference is released, all resources associated with this UMP memory
219 * @note There is a user space equivalent function called @ref ump_reference_release "ump_reference_release"
221 * @see ump_reference_release
223 * @param mem Handle to UMP memory.
225 UMP_KERNEL_API_EXPORT void ump_dd_reference_release(ump_dd_handle mem);
233 /** @} */ /* end group ump_kernel_space_api */
236 #endif /* __UMP_KERNEL_INTERFACE_H__ */