[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>
This commit is contained in:
Michael Brown
2012-08-29 15:35:46 +01:00
parent de802310bc
commit e2becce186
2 changed files with 31 additions and 10 deletions

View File

@@ -23,11 +23,33 @@ 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 );
/**
* Allocate memory for DMA
*
* @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_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
*
@@ -40,10 +62,7 @@ extern void mdumpfree ( void );
* @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 );
if ( ptr && size )
VALGRIND_MALLOCLIKE_BLOCK ( ptr, size, 0, 0 );
return ptr;
return malloc_dma_offset ( size, phys_align, 0 );
}
/**