mali mess
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / mt8127 / mali / ump / linux / ump_kernel_random_mapping.h
1 /*
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
5 * ALL RIGHTS RESERVED
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.
9 */
10
11 /**
12 * @file ump_kernel_random_mapping.h
13 */
14
15 #ifndef __UMP_KERNEL_RANDOM_MAPPING_H__
16 #define __UMP_KERNEL_RANDOM_MAPPING_H__
17
18 #include "mali_osk.h"
19 #include <linux/rbtree.h>
20
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 */
24
25 /**
26 * The random mapping object
27 * Provides a separate namespace where we can map an integer to a pointer
28 */
29 typedef struct ump_random_mapping {
30 _mali_osk_mutex_rw_t *lock; /**< Lock protecting access to the mapping object */
31 struct rb_root root;
32 #if UMP_RANDOM_MAP_DELAY
33 struct {
34 unsigned long count;
35 unsigned long timestamp;
36 } failed;
37 #endif
38 } ump_random_mapping;
39
40 /**
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
44 */
45 ump_random_mapping *ump_random_mapping_create(void);
46
47 /**
48 * Destroy a random mapping object
49 * @param map The map to free
50 */
51 void ump_random_mapping_destroy(ump_random_mapping *map);
52
53 /**
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
59 */
60 int ump_random_mapping_insert(ump_random_mapping *map, ump_dd_mem *mem);
61
62 /**
63 * Get the value mapped to by a random ID
64 *
65 * If the lookup fails, punish the calling thread by applying a delay.
66 *
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
71 */
72 ump_dd_mem *ump_random_mapping_get(ump_random_mapping *map, int id);
73
74 void ump_random_mapping_put(ump_dd_mem *mem);
75
76 /**
77 * Free the random ID
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
81 */
82 ump_dd_mem *ump_random_mapping_remove(ump_random_mapping *map, int id);
83
84 #endif /* __UMP_KERNEL_RANDOM_MAPPING_H__ */