hvmloader: Add a simple "scratch allocator"
authorIan Campbell <ian.campbell@citrix.com>
Wed, 1 Jun 2011 15:46:28 +0000 (16:46 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 1 Jun 2011 15:46:28 +0000 (16:46 +0100)
Returns memory which is passed to the subsequent BIOS but can be
reused once the contents is consumed. An example of this would be a
BIOS table which the BIOS consumes by copying rather than simply
referencing.

Users which need a temporary scratch buffer for internal use
scratch_start which follows these allocations.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
tools/firmware/hvmloader/config.h
tools/firmware/hvmloader/hvmloader.c
tools/firmware/hvmloader/pci.c
tools/firmware/hvmloader/rombios.c
tools/firmware/hvmloader/util.c
tools/firmware/hvmloader/util.h

index bc6d445fa15a9dfa39e9a02acd226a9bd92aa60f..afce05bbb17d09e49b46c1557406cb9d7c97336b 100644 (file)
@@ -62,6 +62,8 @@ extern unsigned long pci_mem_start, pci_mem_end;
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
 #define HVMLOADER_PHYSICAL_ADDRESS    0x00100000
 
+extern unsigned long scratch_start;
+
 #endif /* __HVMLOADER_CONFIG_H__ */
 
 /*
index 1ba1f37c7f81a7a3841c09559fa219d73d212b96..89407964e7e8e5a9b208460913c9d375c1d59314 100644 (file)
@@ -110,6 +110,8 @@ asm (
     "    .text                       \n"
     );
 
+unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -481,6 +483,9 @@ int main(void)
     cmos_write_memory_size();
 
     printf("BIOS map:\n");
+    if ( SCRATCH_PHYSICAL_ADDRESS != scratch_start )
+        printf(" %05x-%05lx: Scratch space\n",
+               SCRATCH_PHYSICAL_ADDRESS, scratch_start);
     if ( vgabios_sz )
         printf(" %05x-%05x: VGA BIOS\n",
                VGABIOS_PHYSICAL_ADDRESS,
index 2d7243f14de53833cd256b4f5025fdce0c9aecee..61d60c65861d0d66d6a5e5f33b03607db78f9e1c 100644 (file)
@@ -48,7 +48,7 @@ void pci_setup(void)
     /* Create a list of device BARs in descending order of size. */
     struct bars {
         uint32_t devfn, bar_reg, bar_sz;
-    } *bars = (struct bars *)SCRATCH_PHYSICAL_ADDRESS;
+    } *bars = (struct bars *)scratch_start;
     unsigned int i, nr_bars = 0;
 
     /* Program PCI-ISA bridge with appropriate link routes. */
index 376e4136b0fb52f6c4058a5cbc97ff7f39042117..b4006263afac94775833f0a88c97871a02c576bf 100644 (file)
@@ -138,7 +138,7 @@ static void rombios_create_mp_tables(void)
 
 static void rombios_create_smbios_tables(void)
 {
-    hvm_write_smbios_tables(SCRATCH_PHYSICAL_ADDRESS,
+    hvm_write_smbios_tables(scratch_start,
                             SMBIOS_PHYSICAL_ADDRESS,
                             SMBIOS_PHYSICAL_END);
 }
index d16b4b2fd9cff4307b6add10ff109216e20e5453..4d80845fc7e28badf486d264f2389b07e946c0f4 100644 (file)
@@ -362,6 +362,24 @@ void *mem_alloc(uint32_t size, uint32_t align)
     return (void *)(unsigned long)s;
 }
 
+void *scratch_alloc(uint32_t size, uint32_t align)
+{
+    uint32_t s, e;
+
+    /* Align to at least one kilobyte. */
+    if ( align < 1024 )
+        align = 1024;
+
+    s = (scratch_start + align - 1) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON(e < s);
+
+    scratch_start = e;
+
+    return (void *)(unsigned long)s;
+}
+
 uint32_t ioapic_read(uint32_t reg)
 {
     *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00) = reg;
index c08715d59abf4276ac2168448e17f53a3e1a75f5..a9bf47b46e8790708f7f4241d91bf2862eb7cec4 100644 (file)
@@ -168,6 +168,9 @@ int vprintf(const char *fmt, va_list ap);
 void *mem_alloc(uint32_t size, uint32_t align);
 #define virt_to_phys(v) ((unsigned long)(v))
 
+/* Allocate memory in a scratch region */
+void *scratch_alloc(uint32_t size, uint32_t align);
+
 /* Connect our xenbus client to the backend.  
  * Call once, before any other xenbus actions. */
 void xenbus_setup(void);