diff options
author | royger <royger@FreeBSD.org> | 2014-03-11 10:23:03 +0000 |
---|---|---|
committer | royger <royger@FreeBSD.org> | 2014-03-11 10:23:03 +0000 |
commit | 891131cb52c5aa334778f1f5cb0ac125c88c32cb (patch) | |
tree | b7cab660078ecadafa7c5b0f9abceac9a436bff1 /sys/x86 | |
parent | 467e743960e4cc864b1c9be42fb2be7852f0ebb0 (diff) | |
download | FreeBSD-src-891131cb52c5aa334778f1f5cb0ac125c88c32cb.zip FreeBSD-src-891131cb52c5aa334778f1f5cb0ac125c88c32cb.tar.gz |
xen: implement hook to fetch and parse e820 memory map
e820 memory map is fetched using a hypercall under Xen PVH, so add a
hook to init_ops in oder to diverge from bare metal and implement a
Xen variant.
Approved by: gibbs
Sponsored by: Citrix Systems R&D
x86/include/init.h:
- Add a parse_memmap hook to init_ops, that will be called to fetch
and parse the memory map.
amd64/amd64/machdep.c:
- Decouple the fetch and the parse of the memmap, so the parse
function can be shared with Xen code.
- Move code around in order to implement the parse_memmap hook.
amd64/include/pc/bios.h:
- Declare bios_add_smap_entries (implemented in machdep.c).
x86/xen/pv.c:
- Implement fetching of e820 memmap when running as a PVH guest by
using the XENMEM_memory_map hypercall.
Diffstat (limited to 'sys/x86')
-rw-r--r-- | sys/x86/include/init.h | 1 | ||||
-rw-r--r-- | sys/x86/xen/pv.c | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/sys/x86/include/init.h b/sys/x86/include/init.h index c72889f..562e582 100644 --- a/sys/x86/include/init.h +++ b/sys/x86/include/init.h @@ -38,6 +38,7 @@ struct init_ops { caddr_t (*parse_preload_data)(u_int64_t); void (*early_clock_source_init)(void); void (*early_delay)(int); + void (*parse_memmap)(caddr_t, vm_paddr_t *, int *); }; extern struct init_ops init_ops; diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c index 4bc7e86..f7d5e47 100644 --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include <vm/vm_param.h> #include <x86/init.h> +#include <machine/pc/bios.h> #include <xen/xen-os.h> #include <xen/hypervisor.h> @@ -60,8 +61,11 @@ extern u_int64_t hammer_time(u_int64_t, u_int64_t); /* Xen initial function */ uint64_t hammer_time_xen(start_info_t *, uint64_t); +#define MAX_E820_ENTRIES 128 + /*--------------------------- Forward Declarations ---------------------------*/ static caddr_t xen_pv_parse_preload_data(u_int64_t); +static void xen_pv_parse_memmap(caddr_t, vm_paddr_t *, int *); /*-------------------------------- Global Data -------------------------------*/ /* Xen init_ops implementation. */ @@ -69,8 +73,11 @@ struct init_ops xen_init_ops = { .parse_preload_data = xen_pv_parse_preload_data, .early_clock_source_init = xen_clock_init, .early_delay = xen_delay, + .parse_memmap = xen_pv_parse_memmap, }; +static struct bios_smap xen_smap[MAX_E820_ENTRIES]; + /*-------------------------------- Xen PV init -------------------------------*/ /* * First function called by the Xen PVH boot sequence. @@ -189,3 +196,21 @@ xen_pv_parse_preload_data(u_int64_t modulep) return (NULL); } + +static void +xen_pv_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) +{ + struct xen_memory_map memmap; + u_int32_t size; + int rc; + + /* Fetch the E820 map from Xen */ + memmap.nr_entries = MAX_E820_ENTRIES; + set_xen_guest_handle(memmap.buffer, xen_smap); + rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); + if (rc) + panic("unable to fetch Xen E820 memory map"); + size = memmap.nr_entries * sizeof(xen_smap[0]); + + bios_add_smap_entries(xen_smap, size, physmap, physmap_idx); +} |