2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2008-2011, 2013-2015 ARM Limited
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
12 * @file ump_kernel_random_mapping.h
15 #ifndef __UMP_KERNEL_RANDOM_MAPPING_H__
16 #define __UMP_KERNEL_RANDOM_MAPPING_H__
19 #include <linux/rbtree.h>
21 #define UMP_RANDOM_MAP_DELAY 1
22 #define UMP_FAILED_LOOKUP_DELAY 10 /* ms */
23 #define UMP_FAILED_LOOKUPS_ALLOWED 10 /* number of allowed failed lookups */
26 * The random mapping object
27 * Provides a separate namespace where we can map an integer to a pointer
29 typedef struct ump_random_mapping
{
30 _mali_osk_mutex_rw_t
*lock
; /**< Lock protecting access to the mapping object */
32 #if UMP_RANDOM_MAP_DELAY
35 unsigned long timestamp
;
41 * Create a random mapping object
42 * Create a random mapping capable of holding 2^20 entries
43 * @return Pointer to a random mapping object, NULL on failure
45 ump_random_mapping
*ump_random_mapping_create(void);
48 * Destroy a random mapping object
49 * @param map The map to free
51 void ump_random_mapping_destroy(ump_random_mapping
*map
);
54 * Allocate a new mapping entry (random ID)
55 * Allocates a new entry in the map.
56 * @param map The map to allocate a new entry in
57 * @param target The value to map to
58 * @return The random allocated, a negative value on error
60 int ump_random_mapping_insert(ump_random_mapping
*map
, ump_dd_mem
*mem
);
63 * Get the value mapped to by a random ID
65 * If the lookup fails, punish the calling thread by applying a delay.
67 * @param map The map to lookup the random id in
68 * @param id The ID to lookup
69 * @param target Pointer to a pointer which will receive the stored value
70 * @return ump_dd_mem pointer on successful lookup, NULL on error
72 ump_dd_mem
*ump_random_mapping_get(ump_random_mapping
*map
, int id
);
74 void ump_random_mapping_put(ump_dd_mem
*mem
);
78 * For the random to be reused it has to be freed
79 * @param map The map to free the random from
80 * @param id The ID to free
82 ump_dd_mem
*ump_random_mapping_remove(ump_random_mapping
*map
, int id
);
84 #endif /* __UMP_KERNEL_RANDOM_MAPPING_H__ */