2 * Copyright (C) 2010 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_descriptor_mapping.h
15 #ifndef __UMP_KERNEL_DESCRIPTOR_MAPPING_H__
16 #define __UMP_KERNEL_DESCRIPTOR_MAPPING_H__
21 * The actual descriptor mapping table, never directly accessed by clients
23 typedef struct ump_descriptor_table
25 u32 * usage; /**< Pointer to bitpattern indicating if a descriptor is valid/used or not */
26 void** mappings; /**< Array of the pointers the descriptors map to */
27 } ump_descriptor_table;
30 * The descriptor mapping object
31 * Provides a separate namespace where we can map an integer to a pointer
33 typedef struct ump_descriptor_mapping
35 _mali_osk_lock_t *lock; /**< Lock protecting access to the mapping object */
36 int max_nr_mappings_allowed; /**< Max number of mappings to support in this namespace */
37 int current_nr_mappings; /**< Current number of possible mappings */
38 ump_descriptor_table * table; /**< Pointer to the current mapping table */
39 } ump_descriptor_mapping;
42 * Create a descriptor mapping object
43 * Create a descriptor mapping capable of holding init_entries growable to max_entries
44 * @param init_entries Number of entries to preallocate memory for
45 * @param max_entries Number of entries to max support
46 * @return Pointer to a descriptor mapping object, NULL on failure
48 ump_descriptor_mapping * ump_descriptor_mapping_create(int init_entries, int max_entries);
51 * Destroy a descriptor mapping object
52 * @param map The map to free
54 void ump_descriptor_mapping_destroy(ump_descriptor_mapping * map);
57 * Allocate a new mapping entry (descriptor ID)
58 * Allocates a new entry in the map.
59 * @param map The map to allocate a new entry in
60 * @param target The value to map to
61 * @return The descriptor allocated, a negative value on error
63 int ump_descriptor_mapping_allocate_mapping(ump_descriptor_mapping * map, void * target);
66 * Get the value mapped to by a descriptor ID
67 * @param map The map to lookup the descriptor id in
68 * @param descriptor The descriptor ID to lookup
69 * @param target Pointer to a pointer which will receive the stored value
70 * @return 0 on successful lookup, negative on error
72 int ump_descriptor_mapping_get(ump_descriptor_mapping * map, int descriptor, void** target);
75 * Set the value mapped to by a descriptor ID
76 * @param map The map to lookup the descriptor id in
77 * @param descriptor The descriptor ID to lookup
78 * @param target Pointer to replace the current value with
79 * @return 0 on successful lookup, negative on error
81 int ump_descriptor_mapping_set(ump_descriptor_mapping * map, int descriptor, void * target);
84 * Free the descriptor ID
85 * For the descriptor to be reused it has to be freed
86 * @param map The map to free the descriptor from
87 * @param descriptor The descriptor ID to free
89 void ump_descriptor_mapping_free(ump_descriptor_mapping * map, int descriptor);
91 #endif /* __UMP_KERNEL_DESCRIPTOR_MAPPING_H__ */