ump_kernel_descriptor_mapping.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2010-2011 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. * @file ump_kernel_descriptor_mapping.h
  12. */
  13. #ifndef __UMP_KERNEL_DESCRIPTOR_MAPPING_H__
  14. #define __UMP_KERNEL_DESCRIPTOR_MAPPING_H__
  15. #include "mali_osk.h"
  16. /**
  17. * The actual descriptor mapping table, never directly accessed by clients
  18. */
  19. typedef struct ump_descriptor_table
  20. {
  21. u32 * usage; /**< Pointer to bitpattern indicating if a descriptor is valid/used or not */
  22. void** mappings; /**< Array of the pointers the descriptors map to */
  23. } ump_descriptor_table;
  24. /**
  25. * The descriptor mapping object
  26. * Provides a separate namespace where we can map an integer to a pointer
  27. */
  28. typedef struct ump_descriptor_mapping
  29. {
  30. _mali_osk_lock_t *lock; /**< Lock protecting access to the mapping object */
  31. int max_nr_mappings_allowed; /**< Max number of mappings to support in this namespace */
  32. int current_nr_mappings; /**< Current number of possible mappings */
  33. ump_descriptor_table * table; /**< Pointer to the current mapping table */
  34. } ump_descriptor_mapping;
  35. /**
  36. * Create a descriptor mapping object
  37. * Create a descriptor mapping capable of holding init_entries growable to max_entries
  38. * @param init_entries Number of entries to preallocate memory for
  39. * @param max_entries Number of entries to max support
  40. * @return Pointer to a descriptor mapping object, NULL on failure
  41. */
  42. ump_descriptor_mapping * ump_descriptor_mapping_create(int init_entries, int max_entries);
  43. /**
  44. * Destroy a descriptor mapping object
  45. * @param map The map to free
  46. */
  47. void ump_descriptor_mapping_destroy(ump_descriptor_mapping * map);
  48. /**
  49. * Allocate a new mapping entry (descriptor ID)
  50. * Allocates a new entry in the map.
  51. * @param map The map to allocate a new entry in
  52. * @param target The value to map to
  53. * @return The descriptor allocated, a negative value on error
  54. */
  55. int ump_descriptor_mapping_allocate_mapping(ump_descriptor_mapping * map, void * target);
  56. /**
  57. * Get the value mapped to by a descriptor ID
  58. * @param map The map to lookup the descriptor id in
  59. * @param descriptor The descriptor ID to lookup
  60. * @param target Pointer to a pointer which will receive the stored value
  61. * @return 0 on successful lookup, negative on error
  62. */
  63. int ump_descriptor_mapping_get(ump_descriptor_mapping * map, int descriptor, void** target);
  64. /**
  65. * Set the value mapped to by a descriptor ID
  66. * @param map The map to lookup the descriptor id in
  67. * @param descriptor The descriptor ID to lookup
  68. * @param target Pointer to replace the current value with
  69. * @return 0 on successful lookup, negative on error
  70. */
  71. int ump_descriptor_mapping_set(ump_descriptor_mapping * map, int descriptor, void * target);
  72. /**
  73. * Free the descriptor ID
  74. * For the descriptor to be reused it has to be freed
  75. * @param map The map to free the descriptor from
  76. * @param descriptor The descriptor ID to free
  77. */
  78. void ump_descriptor_mapping_free(ump_descriptor_mapping * map, int descriptor);
  79. #endif /* __UMP_KERNEL_DESCRIPTOR_MAPPING_H__ */