Back to index

libdrm  2.4.37
Classes | Defines | Functions
mm.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mem_block
 Memory manager code. More...

Defines

#define mmInit   drm_mmInit
#define mmAllocMem   drm_mmAllocMem
#define mmFreeMem   drm_mmFreeMem
#define mmFindBlock   drm_mmFindBlock
#define mmDestroy   drm_mmDestroy
#define mmDumpMemInfo   drm_mmDumpMemInfo

Functions

struct mem_blockmmInit (int ofs, int size)
 input: total size in bytes return: a heap pointer if OK, NULL if error
struct mem_blockmmAllocMem (struct mem_block *heap, int size, int align2, int startSearch)
 Allocate 'size' bytes with 2^align2 bytes alignment, restrict the search to free memory after 'startSearch' depth and back buffers should be in different 4mb banks to get better page hits if possible input: size = size of block align2 = 2^align2 bytes alignment startSearch = linear offset from start of heap to begin search return: pointer to the allocated block, 0 if error.
int mmFreeMem (struct mem_block *b)
 Free block starts at offset input: pointer to a block return: 0 if OK, -1 if error.
struct mem_blockmmFindBlock (struct mem_block *heap, int start)
 Free block starts at offset input: pointer to a heap, start offset return: pointer to a block.
void mmDestroy (struct mem_block *mmInit)
 destroy MM
void mmDumpMemInfo (const struct mem_block *mmInit)
 For debuging purpose.

Class Documentation

struct mem_block

Memory manager code.

Primarily used by device drivers to manage texture heaps, etc.

Definition at line 32 of file mm.h.

Collaboration diagram for mem_block:
Class Members
unsigned int free:1
struct mem_block * heap
struct mem_block * next
struct mem_block * next_free
int ofs
struct mem_block * prev
struct mem_block * prev_free
unsigned int reserved:1
int size

Define Documentation

#define mmAllocMem   drm_mmAllocMem

Definition at line 45 of file mm.h.

#define mmDestroy   drm_mmDestroy

Definition at line 48 of file mm.h.

#define mmDumpMemInfo   drm_mmDumpMemInfo

Definition at line 49 of file mm.h.

#define mmFindBlock   drm_mmFindBlock

Definition at line 47 of file mm.h.

#define mmFreeMem   drm_mmFreeMem

Definition at line 46 of file mm.h.

#define mmInit   drm_mmInit

Definition at line 44 of file mm.h.


Function Documentation

struct mem_block* mmAllocMem ( struct mem_block heap,
int  size,
int  align2,
int  startSearch 
) [read]

Allocate 'size' bytes with 2^align2 bytes alignment, restrict the search to free memory after 'startSearch' depth and back buffers should be in different 4mb banks to get better page hits if possible input: size = size of block align2 = 2^align2 bytes alignment startSearch = linear offset from start of heap to begin search return: pointer to the allocated block, 0 if error.

Definition at line 162 of file mm.c.

{
       struct mem_block *p;
       const int mask = (1 << align2) - 1;
       int startofs = 0;
       int endofs;

       if (!heap || align2 < 0 || size <= 0)
              return NULL;

       for (p = heap->next_free; p != heap; p = p->next_free) {
              assert(p->free);

              startofs = (p->ofs + mask) & ~mask;
              if (startofs < startSearch) {
                     startofs = startSearch;
              }
              endofs = startofs + size;
              if (endofs <= (p->ofs + p->size))
                     break;
       }

       if (p == heap)
              return NULL;

       assert(p->free);
       p = SliceBlock(p, startofs, size, 0, mask + 1);

       return p;
}

Here is the call graph for this function:

void mmDestroy ( struct mem_block mmInit)

destroy MM

Definition at line 257 of file mm.c.

{
       struct mem_block *p;

       if (!heap)
              return;

       for (p = heap->next; p != heap;) {
              struct mem_block *next = p->next;
              free(p);
              p = next;
       }

       free(heap);
}
void mmDumpMemInfo ( const struct mem_block mmInit)

For debuging purpose.

Definition at line 31 of file mm.c.

{
       drmMsg("Memory heap %p:\n", (void *)heap);
       if (heap == 0) {
              drmMsg("  heap == 0\n");
       } else {
              const struct mem_block *p;

              for (p = heap->next; p != heap; p = p->next) {
                     drmMsg("  Offset:%08x, Size:%08x, %c%c\n", p->ofs,
                            p->size, p->free ? 'F' : '.',
                            p->reserved ? 'R' : '.');
              }

              drmMsg("\nFree list:\n");

              for (p = heap->next_free; p != heap; p = p->next_free) {
                     drmMsg(" FREE Offset:%08x, Size:%08x, %c%c\n", p->ofs,
                            p->size, p->free ? 'F' : '.',
                            p->reserved ? 'R' : '.');
              }

       }
       drmMsg("End of memory blocks\n");
}

Here is the call graph for this function:

struct mem_block* mmFindBlock ( struct mem_block heap,
int  start 
) [read]

Free block starts at offset input: pointer to a heap, start offset return: pointer to a block.

Definition at line 194 of file mm.c.

{
       struct mem_block *p;

       for (p = heap->next; p != heap; p = p->next) {
              if (p->ofs == start)
                     return p;
       }

       return NULL;
}
int mmFreeMem ( struct mem_block b)

Free block starts at offset input: pointer to a block return: 0 if OK, -1 if error.

Definition at line 230 of file mm.c.

{
       if (!b)
              return 0;

       if (b->free) {
              drmMsg("block already free\n");
              return -1;
       }
       if (b->reserved) {
              drmMsg("block is reserved\n");
              return -1;
       }

       b->free = 1;
       b->next_free = b->heap->next_free;
       b->prev_free = b->heap;
       b->next_free->prev_free = b;
       b->prev_free->next_free = b;

       Join2Blocks(b);
       if (b->prev != b->heap)
              Join2Blocks(b->prev);

       return 0;
}

Here is the call graph for this function:

struct mem_block* mmInit ( int  ofs,
int  size 
) [read]

input: total size in bytes return: a heap pointer if OK, NULL if error

Definition at line 57 of file mm.c.

{
       struct mem_block *heap, *block;

       if (size <= 0)
              return NULL;

       heap = (struct mem_block *)calloc(1, sizeof(struct mem_block));
       if (!heap)
              return NULL;

       block = (struct mem_block *)calloc(1, sizeof(struct mem_block));
       if (!block) {
              free(heap);
              return NULL;
       }

       heap->next = block;
       heap->prev = block;
       heap->next_free = block;
       heap->prev_free = block;

       block->heap = heap;
       block->next = heap;
       block->prev = heap;
       block->next_free = heap;
       block->prev_free = heap;

       block->ofs = ofs;
       block->size = size;
       block->free = 1;

       return heap;
}