via_ds.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
  4. * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  24. * DEALINGS IN THE SOFTWARE.
  25. */
  26. #ifndef _via_ds_h_
  27. #define _via_ds_h_
  28. #include "drmP.h"
  29. /* Set Data Structure */
  30. #define SET_SIZE 5000
  31. typedef unsigned long ITEM_TYPE;
  32. typedef struct {
  33. ITEM_TYPE val;
  34. int alloc_next, free_next;
  35. } list_item_t;
  36. typedef struct {
  37. int alloc;
  38. int free;
  39. int trace;
  40. list_item_t list[SET_SIZE];
  41. } set_t;
  42. set_t *via_setInit(void);
  43. int via_setAdd(set_t * set, ITEM_TYPE item);
  44. int via_setDel(set_t * set, ITEM_TYPE item);
  45. int via_setFirst(set_t * set, ITEM_TYPE * item);
  46. int via_setNext(set_t * set, ITEM_TYPE * item);
  47. int via_setDestroy(set_t * set);
  48. #endif
  49. #ifndef MM_INC
  50. #define MM_INC
  51. struct mem_block_t {
  52. struct mem_block_t *next;
  53. struct mem_block_t *heap;
  54. int ofs, size;
  55. int align;
  56. unsigned int free:1;
  57. unsigned int reserved:1;
  58. };
  59. typedef struct mem_block_t TMemBlock;
  60. typedef struct mem_block_t *PMemBlock;
  61. /* a heap is just the first block in a chain */
  62. typedef struct mem_block_t memHeap_t;
  63. static __inline__ int mmBlockSize(PMemBlock b)
  64. {
  65. return b->size;
  66. }
  67. static __inline__ int mmOffset(PMemBlock b)
  68. {
  69. return b->ofs;
  70. }
  71. static __inline__ void mmMarkReserved(PMemBlock b)
  72. {
  73. b->reserved = 1;
  74. }
  75. /*
  76. * input: total size in bytes
  77. * return: a heap pointer if OK, NULL if error
  78. */
  79. memHeap_t *via_mmInit(int ofs, int size);
  80. PMemBlock via_mmAllocMem(memHeap_t * heap, int size, int align2,
  81. int startSearch);
  82. /*
  83. * Free block starts at offset
  84. * input: pointer to a block
  85. * return: 0 if OK, -1 if error
  86. */
  87. int via_mmFreeMem(PMemBlock b);
  88. #endif