Initial commit
[kernel/linux-3.0.git] / drivers / gpu / vithar / ump / src / devicedrv / common / ump_kernel_descriptor_mapping.h
1 /*
2  *
3  * (C) COPYRIGHT 2008-2011 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
6  * 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  * 
8  * A copy of the licence is included with the program, and can also be obtained from Free Software
9  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
10  * 
11  */
12
13
14
15 /**
16  * @file ump_kernel_descriptor_mapping.h
17  */
18
19 #ifndef _UMP_KERNEL_DESCRIPTOR_MAPPING_H_
20 #define _UMP_KERNEL_DESCRIPTOR_MAPPING_H_
21
22 #include <linux/rwsem.h>
23 #include <linux/slab.h>
24 /**
25  * The actual descriptor mapping table, never directly accessed by clients
26  */
27 typedef struct umpp_descriptor_table
28 {
29         /* keep as a unsigned long to rely on the OS's bitops support */
30         unsigned long * usage; /**< Pointer to bitpattern indicating if a descriptor is valid/used(1) or not(0) */
31         void** mappings; /**< Array of the pointers the descriptors map to */
32 } umpp_descriptor_table;
33
34 /**
35  * The descriptor mapping object
36  * Provides a separate namespace where we can map an integer to a pointer
37  */
38 typedef struct umpp_descriptor_mapping
39 {
40         struct rw_semaphore lock; /**< Lock protecting access to the mapping object */
41         unsigned int max_nr_mappings_allowed; /**< Max number of mappings to support in this namespace */
42         unsigned int current_nr_mappings; /**< Current number of possible mappings */
43         umpp_descriptor_table * table; /**< Pointer to the current mapping table */
44 } umpp_descriptor_mapping;
45
46 /**
47  * Create a descriptor mapping object.
48  * Create a descriptor mapping capable of holding init_entries growable to max_entries.
49  * ID 0 is reserved so the number of available entries will be max - 1.
50  * @param init_entries Number of entries to preallocate memory for
51  * @param max_entries Number of entries to max support
52  * @return Pointer to a descriptor mapping object, NULL on failure
53  */
54 umpp_descriptor_mapping * umpp_descriptor_mapping_create(unsigned int init_entries, unsigned int max_entries);
55
56 /**
57  * Destroy a descriptor mapping object
58  * @param[in] map The map to free
59  */
60 void umpp_descriptor_mapping_destroy(umpp_descriptor_mapping * map);
61
62 /**
63  * Allocate a new mapping entry (descriptor ID)
64  * Allocates a new entry in the map.
65  * @param[in] map The map to allocate a new entry in
66  * @param[in] target The value to map to
67  * @return The descriptor allocated, ID 0 on failure.
68  */
69 unsigned int umpp_descriptor_mapping_allocate(umpp_descriptor_mapping * map, void * target);
70
71 /**
72  * Get the value mapped to by a descriptor ID
73  * @param[in] map The map to lookup the descriptor id in
74  * @param[in] descriptor The descriptor ID to lookup
75  * @param[out] target Pointer to a pointer which will receive the stored value
76  *
77  * @return 0 on success lookup, -EINVAL on lookup failure.
78  */
79 int umpp_descriptor_mapping_lookup(umpp_descriptor_mapping * map, unsigned int descriptor, void** target);
80
81 /**
82  * Free the descriptor ID
83  * For the descriptor to be reused it has to be freed
84  * @param[in] map The map to free the descriptor from
85  * @param descriptor The descriptor ID to free
86  */
87 void umpp_descriptor_mapping_remove(umpp_descriptor_mapping * map, unsigned int descriptor);
88
89 #endif /* _UMP_KERNEL_DESCRIPTOR_MAPPING_H_ */