From: Michael Brown Date: Thu, 15 May 2025 14:35:27 +0000 (+0100) Subject: [bios] Describe umalloc() heap as an in-use memory area X-Git-Tag: rolling/bin~288 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3812860e39faafa56d4b833030b1a8427488bd16;p=thirdparty%2Fipxe.git [bios] Describe umalloc() heap as an in-use memory area Use the concept of an in-use memory region defined as part of the system memory map API to describe the umalloc() heap. Signed-off-by: Michael Brown --- diff --git a/src/arch/x86/include/basemem.h b/src/arch/x86/include/basemem.h index 01c2ea917..9ac918ac0 100644 --- a/src/arch/x86/include/basemem.h +++ b/src/arch/x86/include/basemem.h @@ -27,9 +27,4 @@ static inline unsigned int get_fbms ( void ) { extern void set_fbms ( unsigned int new_fbms ); -/* Actually in hidemem.c, but putting it here avoids polluting the - * architecture-independent include/hidemem.h. - */ -extern void hide_basemem ( void ); - #endif /* _BASEMEM_H */ diff --git a/src/arch/x86/include/ipxe/int15.h b/src/arch/x86/include/ipxe/int15.h index fbd70f8d6..e8aa9e2f5 100644 --- a/src/arch/x86/include/ipxe/int15.h +++ b/src/arch/x86/include/ipxe/int15.h @@ -16,5 +16,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #endif extern void int15_intercept ( int intercept ); +extern void hide_basemem ( void ); #endif /* _IPXE_INT15_H */ diff --git a/src/arch/x86/interface/pcbios/basemem.c b/src/arch/x86/interface/pcbios/basemem.c index 6a46081aa..8f3a30e92 100644 --- a/src/arch/x86/interface/pcbios/basemem.c +++ b/src/arch/x86/interface/pcbios/basemem.c @@ -27,7 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include +#include /** @file * diff --git a/src/arch/x86/interface/pcbios/hidemem.c b/src/arch/x86/interface/pcbios/hidemem.c index f201742cf..d00c02fb6 100644 --- a/src/arch/x86/interface/pcbios/hidemem.c +++ b/src/arch/x86/interface/pcbios/hidemem.c @@ -31,7 +31,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include /** Set to true if you want to test a fake E820 map */ #define FAKE_E820 0 @@ -119,21 +118,32 @@ void hide_basemem ( void ) { } /** - * Hide umalloc() region + * Hide .text and .data * */ -void hide_umalloc ( physaddr_t start, physaddr_t end ) { - assert ( end <= virt_to_phys ( _textdata ) ); - hide_region ( &hidemem_umalloc, start, end ); +void hide_textdata ( void ) { + hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ), + virt_to_phys ( _etextdata ) ); } /** - * Hide .text and .data + * Synchronise in-use regions with the externally visible system memory map * */ -void hide_textdata ( void ) { - hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ), - virt_to_phys ( _etextdata ) ); +static void int15_sync ( void ) { + physaddr_t start; + size_t size; + + /* Besides our fixed base memory and textdata regions, we + * support hiding only a single in-use memory region (the + * umalloc region), which must be placed before the hidden + * textdata region (even if zero-length). + */ + start = umalloc_used.start; + size = umalloc_used.size; + if ( ! size ) + start = virt_to_phys ( _textdata ); + hide_region ( &hidemem_umalloc, start, ( start + size ) ); } /** @@ -172,8 +182,8 @@ static void hide_etherboot ( void ) { /* Initialise the hidden regions */ hide_basemem(); - hide_umalloc ( virt_to_phys ( _textdata ), virt_to_phys ( _textdata ) ); hide_textdata(); + int15_sync(); /* Some really moronic BIOSes bring up the PXE stack via the * UNDI loader entry point and then don't bother to unload it @@ -250,3 +260,5 @@ struct startup_fn hide_etherboot_startup_fn __startup_fn ( STARTUP_EARLY ) = { .startup = hide_etherboot, .shutdown = unhide_etherboot, }; + +PROVIDE_MEMMAP ( int15, memmap_sync, int15_sync ); diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c index bfaffc4bb..99d8f1460 100644 --- a/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c @@ -34,9 +34,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include +#include #include /** Maximum usable address for external allocated memory */ @@ -62,6 +62,22 @@ static void *bottom = NULL; /** Remaining space on heap */ static size_t heap_size; +/** In-use memory region */ +struct used_region umalloc_used __used_region = { + .name = "umalloc", +}; + +/** + * Hide umalloc() region + * + * @v start Start of region + * @v end End of region + */ +static void hide_umalloc ( physaddr_t start, physaddr_t end ) { + + memmap_use ( &umalloc_used, start, ( end - start ) ); +} + /** * Find largest usable memory region * diff --git a/src/include/ipxe/hidemem.h b/src/include/ipxe/hidemem.h deleted file mode 100644 index cc8d5ee37..000000000 --- a/src/include/ipxe/hidemem.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _IPXE_HIDEMEM_H -#define _IPXE_HIDEMEM_H - -/** - * @file - * - * Hidden memory regions - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include - -extern void hide_umalloc ( physaddr_t start, physaddr_t end ); - -#endif /* _IPXE_HIDEMEM_H */ diff --git a/src/include/ipxe/memmap.h b/src/include/ipxe/memmap.h index 0262c68da..cfb9ac934 100644 --- a/src/include/ipxe/memmap.h +++ b/src/include/ipxe/memmap.h @@ -228,6 +228,8 @@ static inline void memmap_dump_all ( int hide ) { memmap_dump ( ®ion ); } +extern struct used_region umalloc_used __used_region; + extern void memmap_update ( struct memmap_region *region, uint64_t start, uint64_t size, unsigned int flags, const char *name );