You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef _MALLOC_H
  2. #define _MALLOC_H
  3. #include <stdint.h>
  4. /** @file
  5. *
  6. * Dynamic memory allocation
  7. *
  8. */
  9. /*
  10. * Prototypes for the standard functions (malloc() et al) are in
  11. * stdlib.h. Include <malloc.h> only if you need the non-standard
  12. * functions, such as malloc_dma().
  13. *
  14. */
  15. #include <stdlib.h>
  16. extern void * alloc_memblock ( size_t size, size_t align );
  17. extern void free_memblock ( void *ptr, size_t size );
  18. extern void mpopulate ( void *start, size_t len );
  19. extern void mdumpfree ( void );
  20. /**
  21. * Allocate memory for DMA
  22. *
  23. * @v size Requested size
  24. * @v align Physical alignment
  25. * @ret ptr Memory, or NULL
  26. *
  27. * Allocates physically-aligned memory for DMA.
  28. *
  29. * @c align must be a power of two. @c size may not be zero.
  30. */
  31. static inline void * malloc_dma ( size_t size, size_t phys_align ) {
  32. return alloc_memblock ( size, phys_align );
  33. }
  34. /**
  35. * Free memory allocated with malloc_dma()
  36. *
  37. * @v ptr Memory allocated by malloc_dma(), or NULL
  38. * @v size Size of memory, as passed to malloc_dma()
  39. *
  40. * Memory allocated with malloc_dma() can only be freed with
  41. * free_dma(); it cannot be freed with the standard free().
  42. *
  43. * If @c ptr is NULL, no action is taken.
  44. */
  45. static inline void free_dma ( void *ptr, size_t size ) {
  46. free_memblock ( ptr, size );
  47. }
  48. #endif /* _MALLOC_H */