2 * Copyright (C) 2010, 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 mali_kernel_descriptor_mapping.h
15 #ifndef __MALI_KERNEL_DESCRIPTOR_MAPPING_H__
16 #define __MALI_KERNEL_DESCRIPTOR_MAPPING_H__
21 * The actual descriptor mapping table, never directly accessed by clients
23 typedef struct mali_descriptor_table {
24 u32 * usage; /**< Pointer to bitpattern indicating if a descriptor is valid/used or not */
25 void** mappings; /**< Array of the pointers the descriptors map to */
26 } mali_descriptor_table;
29 * The descriptor mapping object
30 * Provides a separate namespace where we can map an integer to a pointer
32 typedef struct mali_descriptor_mapping {
33 _mali_osk_mutex_rw_t *lock; /**< Lock protecting access to the mapping object */
34 int max_nr_mappings_allowed; /**< Max number of mappings to support in this namespace */
35 int current_nr_mappings; /**< Current number of possible mappings */
36 mali_descriptor_table * table; /**< Pointer to the current mapping table */
37 } mali_descriptor_mapping;
40 * Create a descriptor mapping object
41 * Create a descriptor mapping capable of holding init_entries growable to max_entries
42 * @param init_entries Number of entries to preallocate memory for
43 * @param max_entries Number of entries to max support
44 * @return Pointer to a descriptor mapping object, NULL on failure
46 mali_descriptor_mapping * mali_descriptor_mapping_create(int init_entries, int max_entries);
49 * Destroy a descriptor mapping object
50 * @param map The map to free
52 void mali_descriptor_mapping_destroy(mali_descriptor_mapping * map);
55 * Allocate a new mapping entry (descriptor ID)
56 * Allocates a new entry in the map.
57 * @param map The map to allocate a new entry in
58 * @param target The value to map to
59 * @return The descriptor allocated, a negative value on error
61 _mali_osk_errcode_t mali_descriptor_mapping_allocate_mapping(mali_descriptor_mapping * map, void * target, int *descriptor);
64 * Get the value mapped to by a descriptor ID
65 * @param map The map to lookup the descriptor id in
66 * @param descriptor The descriptor ID to lookup
67 * @param target Pointer to a pointer which will receive the stored value
68 * @return 0 on successful lookup, negative on error
70 _mali_osk_errcode_t mali_descriptor_mapping_get(mali_descriptor_mapping * map, int descriptor, void** target);
73 * Set the value mapped to by a descriptor ID
74 * @param map The map to lookup the descriptor id in
75 * @param descriptor The descriptor ID to lookup
76 * @param target Pointer to replace the current value with
77 * @return 0 on successful lookup, negative on error
79 _mali_osk_errcode_t mali_descriptor_mapping_set(mali_descriptor_mapping * map, int descriptor, void * target);
82 * Call the specified callback function for each descriptor in map.
83 * Entire function is mutex protected.
84 * @param map The map to do callbacks for
85 * @param callback A callback function which will be calle for each entry in map
87 void mali_descriptor_mapping_call_for_each(mali_descriptor_mapping * map, void (*callback)(int, void*));
90 * Free the descriptor ID
91 * For the descriptor to be reused it has to be freed
92 * @param map The map to free the descriptor from
93 * @param descriptor The descriptor ID to free
95 * @return old value of descriptor mapping
97 void *mali_descriptor_mapping_free(mali_descriptor_mapping * map, int descriptor);
99 #endif /* __MALI_KERNEL_DESCRIPTOR_MAPPING_H__ */