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.

malloc.h 1.4KB

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