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