Add three properties, memory, mem-min, and mem-max, to the domain node device
tree parsing to define the memory allocation for a domain. All three fields are
expressed in kb and written as a u64 in the device tree entries.
Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
---
Changes since v1
- moved common fdt parsing to libfdt
- dropped ternary for name selection
- swtich over from match_fdt to strncmp
- change mem prints to kb
---
xen/arch/x86/dom0_build.c | 8 +++++++
xen/arch/x86/domain-builder/fdt.c | 34 +++++++++++++++++++++++++++
xen/arch/x86/include/asm/bootdomain.h | 4 ++++
xen/include/xen/libfdt/libfdt-xen.h | 9 +++++++
4 files changed, 55 insertions(+)
diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c
index c231191faec7..1c3b7ff0e658 100644
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -609,6 +609,14 @@ int __init construct_dom0(struct boot_domain *bd)
process_pending_softirqs();
+ /* If param dom0_size was not set and HL config provided memory size */
+ if ( !get_memsize(&dom0_size, LONG_MAX) && bd->mem_pages )
+ dom0_size.nr_pages = bd->mem_pages;
+ if ( !get_memsize(&dom0_min_size, LONG_MAX) && bd->min_pages )
+ dom0_size.nr_pages = bd->min_pages;
+ if ( !get_memsize(&dom0_max_size, LONG_MAX) && bd->max_pages )
+ dom0_size.nr_pages = bd->max_pages;
+
if ( is_hvm_domain(d) )
rc = dom0_construct_pvh(bd);
else if ( is_pv_domain(d) )
diff --git a/xen/arch/x86/domain-builder/fdt.c b/xen/arch/x86/domain-builder/fdt.c
index db584ba78e92..aff1b8c3235d 100644
--- a/xen/arch/x86/domain-builder/fdt.c
+++ b/xen/arch/x86/domain-builder/fdt.c
@@ -6,6 +6,7 @@
#include <xen/init.h>
#include <xen/lib.h>
#include <xen/libfdt/libfdt.h>
+#include <xen/sizes.h>
#include <asm/bootinfo.h>
#include <asm/guest.h>
@@ -113,6 +114,39 @@ static int __init process_domain_node(
else
printk("PV\n");
}
+ else if ( strncmp(prop_name, "memory", name_len) == 0 )
+ {
+ uint64_t kb;
+ if ( fdt_prop_as_u64(prop, &kb) != 0 )
+ {
+ printk(" failed processing memory for domain %s\n", name);
+ return -EINVAL;
+ }
+ bd->mem_pages = PFN_DOWN(kb * SZ_1K);
+ printk(" memory: %ld kb\n", kb);
+ }
+ else if ( strncmp(prop_name, "mem-min", name_len) == 0 )
+ {
+ uint64_t kb;
+ if ( fdt_prop_as_u64(prop, &kb) != 0 )
+ {
+ printk(" failed processing memory for domain %s\n", name);
+ return -EINVAL;
+ }
+ bd->min_pages = PFN_DOWN(kb * SZ_1K);
+ printk(" min memory: %ld kb\n", kb);
+ }
+ else if ( strncmp(prop_name, "mem-max", name_len) == 0 )
+ {
+ uint64_t kb;
+ if ( fdt_prop_as_u64(prop, &kb) != 0 )
+ {
+ printk(" failed processing memory for domain %s\n", name);
+ return -EINVAL;
+ }
+ bd->max_pages = PFN_DOWN(kb * SZ_1K);
+ printk(" max memory: %ld kb\n", kb);
+ }
}
fdt_for_each_subnode(node, fdt, dom_node)
diff --git a/xen/arch/x86/include/asm/bootdomain.h b/xen/arch/x86/include/asm/bootdomain.h
index 5918aaf6bb63..d7092bc32ad7 100644
--- a/xen/arch/x86/include/asm/bootdomain.h
+++ b/xen/arch/x86/include/asm/bootdomain.h
@@ -20,6 +20,10 @@ struct boot_domain {
#define BUILD_MODE_ENABLE_DM (1 << 1) /* HVM | PVH */
uint32_t mode;
+ unsigned long mem_pages;
+ unsigned long min_pages;
+ unsigned long max_pages;
+
struct boot_module *kernel;
struct boot_module *ramdisk;
diff --git a/xen/include/xen/libfdt/libfdt-xen.h b/xen/include/xen/libfdt/libfdt-xen.h
index 2057030dda45..3b653e626842 100644
--- a/xen/include/xen/libfdt/libfdt-xen.h
+++ b/xen/include/xen/libfdt/libfdt-xen.h
@@ -37,6 +37,15 @@ static inline int __init fdt_prop_as_u32(
return fdt_cell_as_u32((fdt32_t *)prop->data, val);
}
+static inline int __init fdt_prop_as_u64(
+ const struct fdt_property *prop, uint64_t *val)
+{
+ if ( !prop || fdt32_to_cpu(prop->len) < sizeof(u64) )
+ return -EINVAL;
+
+ return fdt_cell_as_u64((fdt32_t *)prop->data, val);
+}
+
static inline int __init fdt_get_prop_by_offset(
const void *fdt, int node, const char *name, unsigned long *offset)
{
--
2.30.2