diff options
author | Michael Brown | 2012-08-29 16:35:46 +0200 |
---|---|---|
committer | Michael Brown | 2012-08-31 22:22:45 +0200 |
commit | e2becce1862abbf4b656967c2fda95f28a19e0e4 (patch) | |
tree | d7bc42e0ae8e1c829cd1893b654535291a36f53c /src/include/ipxe/malloc.h | |
parent | [retry] Expose retry_poll() to explicitly poll all running timers (diff) | |
download | ipxe-e2becce1862abbf4b656967c2fda95f28a19e0e4.tar.gz ipxe-e2becce1862abbf4b656967c2fda95f28a19e0e4.tar.xz ipxe-e2becce1862abbf4b656967c2fda95f28a19e0e4.zip |
[malloc] Allow allocation of memory with a specified alignment offset
Allow for allocation of memory blocks having a specified offset from a
specified physical alignment, such as being 12 bytes before a 2kB
boundary.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/malloc.h')
-rw-r--r-- | src/include/ipxe/malloc.h | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/include/ipxe/malloc.h b/src/include/ipxe/malloc.h index d41b0562..bbd6cb89 100644 --- a/src/include/ipxe/malloc.h +++ b/src/include/ipxe/malloc.h @@ -23,7 +23,8 @@ FILE_LICENCE ( GPL2_OR_LATER ); extern size_t freemem; -extern void * __malloc alloc_memblock ( size_t size, size_t align ); +extern void * __malloc alloc_memblock ( size_t size, size_t align, + size_t offset ); extern void free_memblock ( void *ptr, size_t size ); extern void mpopulate ( void *start, size_t len ); extern void mdumpfree ( void ); @@ -33,20 +34,38 @@ extern void mdumpfree ( void ); * * @v size Requested size * @v align Physical alignment + * @v offset Offset from physical alignment * @ret ptr Memory, or NULL * * Allocates physically-aligned memory for DMA. * * @c align must be a power of two. @c size may not be zero. */ -static inline void * __malloc malloc_dma ( size_t size, size_t phys_align ) { - void * ptr = alloc_memblock ( size, phys_align ); +static inline void * __malloc malloc_dma_offset ( size_t size, + size_t phys_align, + size_t offset ) { + void * ptr = alloc_memblock ( size, phys_align, offset ); if ( ptr && size ) VALGRIND_MALLOCLIKE_BLOCK ( ptr, size, 0, 0 ); return ptr; } /** + * Allocate memory for DMA + * + * @v size Requested size + * @v align Physical alignment + * @ret ptr Memory, or NULL + * + * Allocates physically-aligned memory for DMA. + * + * @c align must be a power of two. @c size may not be zero. + */ +static inline void * __malloc malloc_dma ( size_t size, size_t phys_align ) { + return malloc_dma_offset ( size, phys_align, 0 ); +} + +/** * Free memory allocated with malloc_dma() * * @v ptr Memory allocated by malloc_dma(), or NULL |