# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1306943188 -3600
# Node ID 26c6382ea52ab18410a62d59683e9f36bc239330
# Parent 07af563619b59d91975aecaf92bf204ab3dfdd58
hvmloader: Add a simple "scratch allocator"
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@xxxxxxxxxx>
---
diff -r 07af563619b5 -r 26c6382ea52a tools/firmware/hvmloader/config.h
--- a/tools/firmware/hvmloader/config.h Wed Jun 01 16:45:05 2011 +0100
+++ b/tools/firmware/hvmloader/config.h Wed Jun 01 16:46:28 2011 +0100
@@ -62,6 +62,8 @@
#define VGABIOS_PHYSICAL_ADDRESS 0x000C0000
#define HVMLOADER_PHYSICAL_ADDRESS 0x00100000
+extern unsigned long scratch_start;
+
#endif /* __HVMLOADER_CONFIG_H__ */
/*
diff -r 07af563619b5 -r 26c6382ea52a tools/firmware/hvmloader/hvmloader.c
--- a/tools/firmware/hvmloader/hvmloader.c Wed Jun 01 16:45:05 2011 +0100
+++ b/tools/firmware/hvmloader/hvmloader.c Wed Jun 01 16:46:28 2011 +0100
@@ -110,6 +110,8 @@
" .text \n"
);
+unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
+
static void init_hypercalls(void)
{
uint32_t eax, ebx, ecx, edx;
@@ -481,6 +483,9 @@
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,
diff -r 07af563619b5 -r 26c6382ea52a tools/firmware/hvmloader/pci.c
--- a/tools/firmware/hvmloader/pci.c Wed Jun 01 16:45:05 2011 +0100
+++ b/tools/firmware/hvmloader/pci.c Wed Jun 01 16:46:28 2011 +0100
@@ -48,7 +48,7 @@
/* 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. */
diff -r 07af563619b5 -r 26c6382ea52a tools/firmware/hvmloader/rombios.c
--- a/tools/firmware/hvmloader/rombios.c Wed Jun 01 16:45:05 2011 +0100
+++ b/tools/firmware/hvmloader/rombios.c Wed Jun 01 16:46:28 2011 +0100
@@ -138,7 +138,7 @@
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);
}
diff -r 07af563619b5 -r 26c6382ea52a tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c Wed Jun 01 16:45:05 2011 +0100
+++ b/tools/firmware/hvmloader/util.c Wed Jun 01 16:46:28 2011 +0100
@@ -362,6 +362,24 @@
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;
diff -r 07af563619b5 -r 26c6382ea52a tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h Wed Jun 01 16:45:05 2011 +0100
+++ b/tools/firmware/hvmloader/util.h Wed Jun 01 16:46:28 2011 +0100
@@ -168,6 +168,9 @@
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);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|