[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-3.0.5-testing] hvmloader: Simplify e820_malloc() interface and improve
# HG changeset patch # User Keir Fraser <keir@xxxxxxxxxxxxx> # Date 1177006932 -3600 # Node ID 438f3a016fd804b17a1ee869c5196d092613a780 # Parent ce2b25e1c8f6a1ac3b0be6051c715200063fcfaf hvmloader: Simplify e820_malloc() interface and improve implementation. Strip unnecessary sections from the highmem bios extension elf image. Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx> --- tools/firmware/hvmloader/32bitbios_support.c | 6 - tools/firmware/hvmloader/acpi/build.c | 3 tools/firmware/hvmloader/util.c | 99 +++++++++++++++------------ tools/firmware/hvmloader/util.h | 4 - tools/firmware/rombios/32bit/Makefile | 2 5 files changed, 63 insertions(+), 51 deletions(-) diff -r ce2b25e1c8f6 -r 438f3a016fd8 tools/firmware/hvmloader/32bitbios_support.c --- a/tools/firmware/hvmloader/32bitbios_support.c Thu Apr 19 18:13:09 2007 +0100 +++ b/tools/firmware/hvmloader/32bitbios_support.c Thu Apr 19 19:22:12 2007 +0100 @@ -121,13 +121,9 @@ static void copy_jumptable(char *elfarra static void relocate_32bitbios(char *elfarray, uint32_t elfarraysize) { - uint32_t mask = (64 * 1024) - 1; char *highbiosarea; - highbiosarea = (char *)(long) - e820_malloc((elfarraysize + mask) & ~mask, /* round to 64kb */ - E820_RESERVED, - (uint64_t)0xffffffff); + highbiosarea = (char *)(long)e820_malloc(elfarraysize); if ( highbiosarea == NULL ) { printf("No available memory for BIOS high memory area\n"); diff -r ce2b25e1c8f6 -r 438f3a016fd8 tools/firmware/hvmloader/acpi/build.c --- a/tools/firmware/hvmloader/acpi/build.c Thu Apr 19 18:13:09 2007 +0100 +++ b/tools/firmware/hvmloader/acpi/build.c Thu Apr 19 19:22:12 2007 +0100 @@ -269,8 +269,7 @@ int construct_secondary_tables(uint8_t * tcpa->header.oem_revision = ACPI_OEM_REVISION; tcpa->header.creator_id = ACPI_CREATOR_ID; tcpa->header.creator_revision = ACPI_CREATOR_REVISION; - tcpa->lasa = e820_malloc( - ACPI_2_0_TCPA_LAML_SIZE, E820_RESERVED, (uint32_t)~0); + tcpa->lasa = e820_malloc(ACPI_2_0_TCPA_LAML_SIZE); if ( tcpa->lasa ) { tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE; diff -r ce2b25e1c8f6 -r 438f3a016fd8 tools/firmware/hvmloader/util.c --- a/tools/firmware/hvmloader/util.c Thu Apr 19 18:13:09 2007 +0100 +++ b/tools/firmware/hvmloader/util.c Thu Apr 19 19:22:12 2007 +0100 @@ -134,19 +134,11 @@ void *memcpy(void *dest, const void *src void *memmove(void *dest, const void *src, unsigned n) { - if ( (long)dest > (long)src ) - { - n--; - while ( n > 0 ) - { + if ( (unsigned long)dest > (unsigned long)src ) + while ( n-- != 0 ) ((char *)dest)[n] = ((char *)src)[n]; - n--; - } - } else - { memcpy(dest, src, n); - } return dest; } @@ -292,37 +284,62 @@ uuid_to_string(char *dest, uint8_t *uuid *p = '\0'; } -uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask) -{ - uint64_t addr = 0; - int c = *E820_MAP_NR - 1; - struct e820entry *e820entry = (struct e820entry *)E820_MAP; - - while ( c >= 0 ) - { - if ( (e820entry[c].type == E820_RAM) && - ((e820entry[c].addr & (~mask)) == 0) && - (e820entry[c].size >= size) ) - { - addr = e820entry[c].addr; - if ( e820entry[c].size != size ) - { - (*E820_MAP_NR)++; - memmove(&e820entry[c+1], - &e820entry[c], - (*E820_MAP_NR - c) * - sizeof(struct e820entry)); - e820entry[c].size -= size; - addr += e820entry[c].size; - c++; - } - e820entry[c].addr = addr; - e820entry[c].size = size; - e820entry[c].type = type; - break; - } - c--; - } +static void e820_collapse(void) +{ + int i = 0; + struct e820entry *ent = (struct e820entry *)E820_MAP; + + while ( i < (*E820_MAP_NR-1) ) + { + if ( (ent[i].type == ent[i+1].type) && + ((ent[i].addr + ent[i].size) == ent[i+1].addr) ) + { + ent[i].size += ent[i+1].size; + memcpy(&ent[i+1], &ent[i+2], *E820_MAP_NR - i - 2); + (*E820_MAP_NR)--; + } + else + { + i++; + } + } +} + +uint32_t e820_malloc(uint32_t size) +{ + uint32_t addr; + int i; + struct e820entry *ent = (struct e820entry *)E820_MAP; + + /* Align allocation request to a reasonable boundary (1kB). */ + size = (size + 1023) & ~1023; + + for ( i = *E820_MAP_NR - 1; i >= 0; i-- ) + { + addr = ent[i].addr; + if ( (ent[i].type != E820_RAM) || /* not ram? */ + (ent[i].size < size) || /* too small? */ + (addr != ent[i].addr) || /* starts above 4gb? */ + ((addr + size) < addr) ) /* ends above 4gb? */ + continue; + + if ( ent[i].size != size ) + { + memmove(&ent[i+1], &ent[i], (*E820_MAP_NR - i) * sizeof(*ent)); + (*E820_MAP_NR)++; + ent[i].size -= size; + addr += ent[i].size; + i++; + } + + ent[i].addr = addr; + ent[i].size = size; + ent[i].type = E820_RESERVED; + break; + } + + e820_collapse(); + return addr; } diff -r ce2b25e1c8f6 -r 438f3a016fd8 tools/firmware/hvmloader/util.h --- a/tools/firmware/hvmloader/util.h Thu Apr 19 18:13:09 2007 +0100 +++ b/tools/firmware/hvmloader/util.h Thu Apr 19 19:22:12 2007 +0100 @@ -79,8 +79,8 @@ int printf(const char *fmt, ...) __attri int printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); int vprintf(const char *fmt, va_list ap); -/* Allocate region of specified type in the e820 table. */ -uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask); +/* Reserve a RAM region in the e820 table. */ +uint32_t e820_malloc(uint32_t size); /* General e820 access. */ #include <xen/hvm/e820.h> diff -r ce2b25e1c8f6 -r 438f3a016fd8 tools/firmware/rombios/32bit/Makefile --- a/tools/firmware/rombios/32bit/Makefile Thu Apr 19 18:13:09 2007 +0100 +++ b/tools/firmware/rombios/32bit/Makefile Thu Apr 19 19:22:12 2007 +0100 @@ -32,7 +32,7 @@ clean: done; $(TARGET): subdirs 32bitbios.o util.o - $(LD) $(LDFLAGS_DIRECT) -r 32bitbios.o $(MODULES) util.o -o 32bitbios_all.o + $(LD) $(LDFLAGS_DIRECT) -s -r 32bitbios.o $(MODULES) util.o -o 32bitbios_all.o @nm 32bitbios_all.o | \ grep -E -q '^ +U ' && { \ echo "There are undefined symbols in the BIOS:"; \ _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |