diff options
author | Michael Brown <mcb30@etherboot.org> | 2008-10-13 04:32:11 +0100 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2008-10-13 05:33:14 +0100 |
commit | 831e4cfc2718b0784bc22c2d00045481ab3c65b5 (patch) | |
tree | 34d26c6b88381b490d71c020bc9e72b0e90eca37 /src | |
parent | 6554b79ff9eb8992f8cdbc6e13c7b5e346accf16 (diff) | |
download | ipxe-831e4cfc2718b0784bc22c2d00045481ab3c65b5.tar.gz |
[umalloc] Formalise the user memory allocation API
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/i386/include/bits/errfile.h | 2 | ||||
-rw-r--r-- | src/arch/i386/include/bits/umalloc.h | 12 | ||||
-rw-r--r-- | src/arch/i386/include/gpxe/memtop_umalloc.h | 16 | ||||
-rw-r--r-- | src/arch/i386/interface/pcbios/memtop_umalloc.c (renamed from src/arch/i386/core/umalloc.c) | 28 | ||||
-rw-r--r-- | src/config/defaults/pcbios.h | 1 | ||||
-rw-r--r-- | src/config/umalloc.h | 12 | ||||
-rw-r--r-- | src/include/gpxe/umalloc.h | 54 |
7 files changed, 95 insertions, 30 deletions
diff --git a/src/arch/i386/include/bits/errfile.h b/src/arch/i386/include/bits/errfile.h index 99927c283..70c78eaf5 100644 --- a/src/arch/i386/include/bits/errfile.h +++ b/src/arch/i386/include/bits/errfile.h @@ -6,7 +6,7 @@ * @{ */ -#define ERRFILE_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 ) +#define ERRFILE_memtop_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 ) #define ERRFILE_memmap ( ERRFILE_ARCH | ERRFILE_CORE | 0x00010000 ) #define ERRFILE_pnpbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00020000 ) #define ERRFILE_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 ) diff --git a/src/arch/i386/include/bits/umalloc.h b/src/arch/i386/include/bits/umalloc.h new file mode 100644 index 000000000..dcbd0a6b3 --- /dev/null +++ b/src/arch/i386/include/bits/umalloc.h @@ -0,0 +1,12 @@ +#ifndef _BITS_UMALLOC_H +#define _BITS_UMALLOC_H + +/** @file + * + * i386-specific user memory allocation API implementations + * + */ + +#include <gpxe/memtop_umalloc.h> + +#endif /* _BITS_UMALLOC_H */ diff --git a/src/arch/i386/include/gpxe/memtop_umalloc.h b/src/arch/i386/include/gpxe/memtop_umalloc.h new file mode 100644 index 000000000..a3cd2c01a --- /dev/null +++ b/src/arch/i386/include/gpxe/memtop_umalloc.h @@ -0,0 +1,16 @@ +#ifndef _GPXE_MEMTOP_UMALLOC_H +#define _GPXE_MEMTOP_UMALLOC_H + +/** @file + * + * External memory allocation + * + */ + +#ifdef UMALLOC_MEMTOP +#define UMALLOC_PREFIX_memtop +#else +#define UMALLOC_PREFIX_memtop __memtop_ +#endif + +#endif /* _GPXE_MEMTOP_UMALLOC_H */ diff --git a/src/arch/i386/core/umalloc.c b/src/arch/i386/interface/pcbios/memtop_umalloc.c index 3990488cf..2eb7f76db 100644 --- a/src/arch/i386/core/umalloc.c +++ b/src/arch/i386/interface/pcbios/memtop_umalloc.c @@ -36,9 +36,6 @@ /** Equivalent of NOWHERE for user pointers */ #define UNOWHERE ( ~UNULL ) -/** Start of Etherboot text, as defined by the linker */ -extern char _text[]; - /** An external memory block */ struct external_memory { /** Size of this memory block (excluding this header) */ @@ -135,7 +132,7 @@ static void ecollect_free ( void ) { * Calling realloc() with a new size of zero is a valid way to free a * memory block. */ -userptr_t urealloc ( userptr_t ptr, size_t new_size ) { +static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { struct external_memory extmem; userptr_t new = ptr; size_t align; @@ -200,25 +197,4 @@ userptr_t urealloc ( userptr_t ptr, size_t new_size ) { return ( new_size ? new : UNOWHERE ); } -/** - * Allocate external memory - * - * @v size Requested size - * @ret ptr Memory, or UNULL - * - * Memory is guaranteed to be aligned to a page boundary. - */ -userptr_t umalloc ( size_t size ) { - return urealloc ( UNULL, size ); -} - -/** - * Free external memory - * - * @v ptr Memory allocated by umalloc(), or UNULL - * - * If @c ptr is UNULL, no action is taken. - */ -void ufree ( userptr_t ptr ) { - urealloc ( ptr, 0 ); -} +PROVIDE_UMALLOC ( memtop, urealloc, memtop_urealloc ); diff --git a/src/config/defaults/pcbios.h b/src/config/defaults/pcbios.h index 211f28cf7..b782647c8 100644 --- a/src/config/defaults/pcbios.h +++ b/src/config/defaults/pcbios.h @@ -13,5 +13,6 @@ #define TIMER_PCBIOS #define CONSOLE_PCBIOS #define NAP_PCBIOS +#define UMALLOC_MEMTOP #endif /* CONFIG_DEFAULTS_PCBIOS_H */ diff --git a/src/config/umalloc.h b/src/config/umalloc.h new file mode 100644 index 000000000..de4019e50 --- /dev/null +++ b/src/config/umalloc.h @@ -0,0 +1,12 @@ +#ifndef CONFIG_UMALLOC_H +#define CONFIG_UMALLOC_H + +/** @file + * + * User memory allocation API configuration + * + */ + +#include <config/defaults.h> + +#endif /* CONFIG_UMALLOC_H */ diff --git a/src/include/gpxe/umalloc.h b/src/include/gpxe/umalloc.h index 49ec22b47..ffa0c0c49 100644 --- a/src/include/gpxe/umalloc.h +++ b/src/include/gpxe/umalloc.h @@ -8,10 +8,58 @@ * */ +#include <gpxe/api.h> +#include <config/umalloc.h> #include <gpxe/uaccess.h> -extern userptr_t umalloc ( size_t size ); -extern userptr_t urealloc ( userptr_t ptr, size_t new_size ); -extern void ufree ( userptr_t ptr ); +/** + * Provide a user memory allocation API implementation + * + * @v _prefix Subsystem prefix + * @v _api_func API function + * @v _func Implementing function + */ +#define PROVIDE_UMALLOC( _subsys, _api_func, _func ) \ + PROVIDE_SINGLE_API ( UMALLOC_PREFIX_ ## _subsys, _api_func, _func ) + +/* Include all architecture-independent I/O API headers */ + +/* Include all architecture-dependent I/O API headers */ +#include <bits/umalloc.h> + +/** + * Reallocate external memory + * + * @v userptr Memory previously allocated by umalloc(), or UNULL + * @v new_size Requested size + * @ret userptr Allocated memory, or UNULL + * + * Calling realloc() with a new size of zero is a valid way to free a + * memory block. + */ +userptr_t urealloc ( userptr_t userptr, size_t new_size ); + +/** + * Allocate external memory + * + * @v size Requested size + * @ret userptr Memory, or UNULL + * + * Memory is guaranteed to be aligned to a page boundary. + */ +static inline __always_inline userptr_t umalloc ( size_t size ) { + return urealloc ( UNULL, size ); +} + +/** + * Free external memory + * + * @v userptr Memory allocated by umalloc(), or UNULL + * + * If @c ptr is UNULL, no action is taken. + */ +static inline __always_inline void ufree ( userptr_t userptr ) { + urealloc ( userptr, 0 ); +} #endif /* _GPXE_UMALLOC_H */ |