1 /* 2 * Copyright (C) 2010-2011, 2013-2014, 2016-2017 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 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 } ump_descriptor_table; 27 28 /** 29 * The descriptor mapping object 30 * Provides a separate namespace where we can map an integer to a pointer 31 */ 32 typedef struct ump_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 ump_descriptor_table *table; /**< Pointer to the current mapping table */ 37 } ump_descriptor_mapping; 38 39 /** 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 45 */ 46 ump_descriptor_mapping *ump_descriptor_mapping_create(int init_entries, int max_entries); 47 48 /** 49 * Destroy a descriptor mapping object 50 * @param map The map to free 51 */ 52 void ump_descriptor_mapping_destroy(ump_descriptor_mapping *map); 53 54 /** 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 60 */ 61 int ump_descriptor_mapping_allocate_mapping(ump_descriptor_mapping *map, void *target); 62 63 /** 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 69 */ 70 int ump_descriptor_mapping_get(ump_descriptor_mapping *map, int descriptor, void **target); 71 72 /** 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 78 */ 79 int ump_descriptor_mapping_set(ump_descriptor_mapping *map, 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 map The map to free the descriptor from 85 * @param descriptor The descriptor ID to free 86 */ 87 void ump_descriptor_mapping_free(ump_descriptor_mapping *map, int descriptor); 88 89 #endif /* __UMP_KERNEL_DESCRIPTOR_MAPPING_H__ */ 90