upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / media / video / samsung / ump / common / ump_kernel_descriptor_mapping.h
1 /*
2  * Copyright (C) 2010 ARM Limited. All rights reserved.
3  * 
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.
6  * 
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.
9  */
10
11 /**
12  * @file ump_kernel_descriptor_mapping.h
13  */
14
15 #ifndef __UMP_KERNEL_DESCRIPTOR_MAPPING_H__
16 #define __UMP_KERNEL_DESCRIPTOR_MAPPING_H__
17
18 #include "mali_osk.h"
19
20 /**
21  * The actual descriptor mapping table, never directly accessed by clients
22  */
23 typedef struct ump_descriptor_table
24 {
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;
28
29 /**
30  * The descriptor mapping object
31  * Provides a separate namespace where we can map an integer to a pointer
32  */
33 typedef struct ump_descriptor_mapping
34 {
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;
40
41 /**
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
47  */
48 ump_descriptor_mapping * ump_descriptor_mapping_create(int init_entries, int max_entries);
49
50 /**
51  * Destroy a descriptor mapping object
52  * @param map The map to free
53  */
54 void ump_descriptor_mapping_destroy(ump_descriptor_mapping * map);
55
56 /**
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
62  */
63 int ump_descriptor_mapping_allocate_mapping(ump_descriptor_mapping * map, void * target);
64
65 /**
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
71  */
72 int ump_descriptor_mapping_get(ump_descriptor_mapping * map, int descriptor, void** target);
73
74 /**
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
80  */
81 int ump_descriptor_mapping_set(ump_descriptor_mapping * map, int descriptor, void * target);
82
83 /**
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
88  */
89 void ump_descriptor_mapping_free(ump_descriptor_mapping * map, int descriptor);
90
91 #endif /* __UMP_KERNEL_DESCRIPTOR_MAPPING_H__ */