ia64/xen-unstable

changeset 14878:438f3a016fd8

hvmloader: Simplify e820_malloc() interface and improve
implementation. Strip unnecessary sections from the highmem bios
extension elf image.
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Thu Apr 19 19:22:12 2007 +0100 (2007-04-19)
parents ce2b25e1c8f6
children 186e2cf99bbb
files tools/firmware/hvmloader/32bitbios_support.c tools/firmware/hvmloader/acpi/build.c tools/firmware/hvmloader/util.c tools/firmware/hvmloader/util.h tools/firmware/rombios/32bit/Makefile
line diff
     1.1 --- a/tools/firmware/hvmloader/32bitbios_support.c	Thu Apr 19 18:13:09 2007 +0100
     1.2 +++ b/tools/firmware/hvmloader/32bitbios_support.c	Thu Apr 19 19:22:12 2007 +0100
     1.3 @@ -121,13 +121,9 @@ static void copy_jumptable(char *elfarra
     1.4  
     1.5  static void relocate_32bitbios(char *elfarray, uint32_t elfarraysize)
     1.6  {
     1.7 -    uint32_t mask = (64 * 1024) - 1;
     1.8      char *highbiosarea;
     1.9  
    1.10 -    highbiosarea = (char *)(long)
    1.11 -        e820_malloc((elfarraysize + mask) & ~mask, /* round to 64kb */
    1.12 -                    E820_RESERVED,
    1.13 -                    (uint64_t)0xffffffff);
    1.14 +    highbiosarea = (char *)(long)e820_malloc(elfarraysize);
    1.15      if ( highbiosarea == NULL )
    1.16      {
    1.17          printf("No available memory for BIOS high memory area\n");
     2.1 --- a/tools/firmware/hvmloader/acpi/build.c	Thu Apr 19 18:13:09 2007 +0100
     2.2 +++ b/tools/firmware/hvmloader/acpi/build.c	Thu Apr 19 19:22:12 2007 +0100
     2.3 @@ -269,8 +269,7 @@ int construct_secondary_tables(uint8_t *
     2.4          tcpa->header.oem_revision = ACPI_OEM_REVISION;
     2.5          tcpa->header.creator_id   = ACPI_CREATOR_ID;
     2.6          tcpa->header.creator_revision = ACPI_CREATOR_REVISION;
     2.7 -        tcpa->lasa = e820_malloc(
     2.8 -            ACPI_2_0_TCPA_LAML_SIZE, E820_RESERVED, (uint32_t)~0);
     2.9 +        tcpa->lasa = e820_malloc(ACPI_2_0_TCPA_LAML_SIZE);
    2.10          if ( tcpa->lasa )
    2.11          {
    2.12              tcpa->laml = ACPI_2_0_TCPA_LAML_SIZE;
     3.1 --- a/tools/firmware/hvmloader/util.c	Thu Apr 19 18:13:09 2007 +0100
     3.2 +++ b/tools/firmware/hvmloader/util.c	Thu Apr 19 19:22:12 2007 +0100
     3.3 @@ -134,19 +134,11 @@ void *memcpy(void *dest, const void *src
     3.4  
     3.5  void *memmove(void *dest, const void *src, unsigned n)
     3.6  {
     3.7 -    if ( (long)dest > (long)src )
     3.8 -    {
     3.9 -        n--;
    3.10 -        while ( n > 0 )
    3.11 -        {
    3.12 +    if ( (unsigned long)dest > (unsigned long)src )
    3.13 +        while ( n-- != 0 )
    3.14              ((char *)dest)[n] = ((char *)src)[n];
    3.15 -            n--;
    3.16 -        }
    3.17 -    }
    3.18      else
    3.19 -    {
    3.20          memcpy(dest, src, n);
    3.21 -    }
    3.22      return dest;
    3.23  }
    3.24  
    3.25 @@ -292,37 +284,62 @@ uuid_to_string(char *dest, uint8_t *uuid
    3.26      *p = '\0';
    3.27  }
    3.28  
    3.29 -uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask)
    3.30 +static void e820_collapse(void)
    3.31  {
    3.32 -    uint64_t addr = 0;
    3.33 -    int c = *E820_MAP_NR - 1;
    3.34 -    struct e820entry *e820entry = (struct e820entry *)E820_MAP;
    3.35 +    int i = 0;
    3.36 +    struct e820entry *ent = (struct e820entry *)E820_MAP;
    3.37  
    3.38 -    while ( c >= 0 )
    3.39 +    while ( i < (*E820_MAP_NR-1) )
    3.40      {
    3.41 -        if ( (e820entry[c].type  == E820_RAM) &&
    3.42 -             ((e820entry[c].addr & (~mask)) == 0) &&
    3.43 -             (e820entry[c].size >= size) )
    3.44 +        if ( (ent[i].type == ent[i+1].type) &&
    3.45 +             ((ent[i].addr + ent[i].size) == ent[i+1].addr) )
    3.46 +        {
    3.47 +            ent[i].size += ent[i+1].size;
    3.48 +            memcpy(&ent[i+1], &ent[i+2], *E820_MAP_NR - i - 2);
    3.49 +            (*E820_MAP_NR)--;
    3.50 +        }
    3.51 +        else
    3.52          {
    3.53 -            addr = e820entry[c].addr;
    3.54 -            if ( e820entry[c].size != size )
    3.55 -            {
    3.56 -                (*E820_MAP_NR)++;
    3.57 -                memmove(&e820entry[c+1],
    3.58 -                        &e820entry[c],
    3.59 -                        (*E820_MAP_NR - c) *
    3.60 -                        sizeof(struct e820entry));
    3.61 -                e820entry[c].size -= size;
    3.62 -                addr += e820entry[c].size;
    3.63 -                c++;
    3.64 -            }
    3.65 -            e820entry[c].addr = addr;
    3.66 -            e820entry[c].size = size;
    3.67 -            e820entry[c].type = type;
    3.68 -            break;
    3.69 +            i++;
    3.70          }
    3.71 -        c--;
    3.72      }
    3.73 +}
    3.74 +
    3.75 +uint32_t e820_malloc(uint32_t size)
    3.76 +{
    3.77 +    uint32_t addr;
    3.78 +    int i;
    3.79 +    struct e820entry *ent = (struct e820entry *)E820_MAP;
    3.80 +
    3.81 +    /* Align allocation request to a reasonable boundary (1kB). */
    3.82 +    size = (size + 1023) & ~1023;
    3.83 +
    3.84 +    for ( i = *E820_MAP_NR - 1; i >= 0; i-- )
    3.85 +    {
    3.86 +        addr = ent[i].addr;
    3.87 +        if ( (ent[i].type != E820_RAM) || /* not ram? */
    3.88 +             (ent[i].size < size) ||      /* too small? */
    3.89 +             (addr != ent[i].addr) ||     /* starts above 4gb? */
    3.90 +             ((addr + size) < addr) )     /* ends above 4gb? */
    3.91 +            continue;
    3.92 +        
    3.93 +        if ( ent[i].size != size )
    3.94 +        {
    3.95 +            memmove(&ent[i+1], &ent[i], (*E820_MAP_NR - i) * sizeof(*ent));
    3.96 +            (*E820_MAP_NR)++;
    3.97 +            ent[i].size -= size;
    3.98 +            addr += ent[i].size;
    3.99 +            i++;
   3.100 +        }
   3.101 +
   3.102 +        ent[i].addr = addr;
   3.103 +        ent[i].size = size;
   3.104 +        ent[i].type = E820_RESERVED;
   3.105 +        break;
   3.106 +    }
   3.107 +
   3.108 +    e820_collapse();
   3.109 +
   3.110      return addr;
   3.111  }
   3.112  
     4.1 --- a/tools/firmware/hvmloader/util.h	Thu Apr 19 18:13:09 2007 +0100
     4.2 +++ b/tools/firmware/hvmloader/util.h	Thu Apr 19 19:22:12 2007 +0100
     4.3 @@ -79,8 +79,8 @@ void uuid_to_string(char *dest, uint8_t 
     4.4  int printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
     4.5  int vprintf(const char *fmt, va_list ap);
     4.6  
     4.7 -/* Allocate region of specified type in the e820 table. */
     4.8 -uint64_t e820_malloc(uint64_t size, uint32_t type, uint64_t mask);
     4.9 +/* Reserve a RAM region in the e820 table. */
    4.10 +uint32_t e820_malloc(uint32_t size);
    4.11  
    4.12  /* General e820 access. */
    4.13  #include <xen/hvm/e820.h>
     5.1 --- a/tools/firmware/rombios/32bit/Makefile	Thu Apr 19 18:13:09 2007 +0100
     5.2 +++ b/tools/firmware/rombios/32bit/Makefile	Thu Apr 19 19:22:12 2007 +0100
     5.3 @@ -32,7 +32,7 @@ clean:
     5.4  	done;
     5.5  
     5.6  $(TARGET): subdirs 32bitbios.o util.o
     5.7 -	$(LD) $(LDFLAGS_DIRECT) -r 32bitbios.o $(MODULES) util.o -o 32bitbios_all.o
     5.8 +	$(LD) $(LDFLAGS_DIRECT) -s -r 32bitbios.o $(MODULES) util.o -o 32bitbios_all.o
     5.9  	@nm 32bitbios_all.o |                                \
    5.10  	  grep -E -q '^ +U ' && {                            \
    5.11  	    echo "There are undefined symbols in the BIOS:"; \