1
0

mm.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * GLX Hardware Device Driver common code
  3. * Copyright (C) 1999 Wittawat Yamwong
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  21. * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. /**
  24. * Memory manager code. Primarily used by device drivers to manage texture
  25. * heaps, etc.
  26. */
  27. #ifndef MM_H
  28. #define MM_H
  29. #include "libdrm_macros.h"
  30. struct mem_block {
  31. struct mem_block *next, *prev;
  32. struct mem_block *next_free, *prev_free;
  33. struct mem_block *heap;
  34. int ofs, size;
  35. unsigned int free:1;
  36. unsigned int reserved:1;
  37. };
  38. /**
  39. * input: total size in bytes
  40. * return: a heap pointer if OK, NULL if error
  41. */
  42. drm_private extern struct mem_block *mmInit(int ofs, int size);
  43. /**
  44. * Allocate 'size' bytes with 2^align2 bytes alignment,
  45. * restrict the search to free memory after 'startSearch'
  46. * depth and back buffers should be in different 4mb banks
  47. * to get better page hits if possible
  48. * input: size = size of block
  49. * align2 = 2^align2 bytes alignment
  50. * startSearch = linear offset from start of heap to begin search
  51. * return: pointer to the allocated block, 0 if error
  52. */
  53. drm_private extern struct mem_block *mmAllocMem(struct mem_block *heap,
  54. int size, int align2,
  55. int startSearch);
  56. /**
  57. * Free block starts at offset
  58. * input: pointer to a block
  59. * return: 0 if OK, -1 if error
  60. */
  61. drm_private extern int mmFreeMem(struct mem_block *b);
  62. /**
  63. * destroy MM
  64. */
  65. drm_private extern void mmDestroy(struct mem_block *mmInit);
  66. /**
  67. * For debugging purpose.
  68. */
  69. drm_private extern void mmDumpMemInfo(const struct mem_block *mmInit);
  70. #endif