@@ -34,12 +34,108 @@ extern const unsigned char dsdt_anycpu_arm[];
_hidden
extern const int dsdt_anycpu_arm_len;
+enum {
+ RSDP,
+ XSDT,
+ GTDT,
+ MADT,
+ FADT,
+ DSDT,
+ NUMS,
+};
+
+struct acpitable {
+ uint64_t addr;
+ size_t size;
+};
+
+static int libxl__estimate_madt_size(libxl__gc *gc,
+ libxl_domain_build_info *info,
+ xc_domain_configuration_t *xc_config)
+{
+ int rc;
+
+ switch (xc_config->gic_version) {
+ case XEN_DOMCTL_CONFIG_GIC_V2:
+ rc = sizeof(struct acpi_table_madt) +
+ sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+ sizeof(struct acpi_madt_generic_distributor);
+ break;
+ case XEN_DOMCTL_CONFIG_GIC_V3:
+ rc = sizeof(struct acpi_table_madt) +
+ sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+ sizeof(struct acpi_madt_generic_distributor) +
+ sizeof(struct acpi_madt_generic_redistributor);
+ break;
+ default:
+ LOG(ERROR, "Unknown GIC version");
+ rc = ERROR_FAIL;
+ break;
+ }
+
+ return rc;
+}
+
+static int libxl__estimate_acpi_size(libxl__gc *gc,
+ libxl_domain_build_info *info,
+ struct xc_dom_image *dom,
+ xc_domain_configuration_t *xc_config,
+ struct acpitable acpitables[])
+{
+ int rc;
+
+ acpitables[RSDP].addr = GUEST_ACPI_BASE;
+ acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 3);
+
+ acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ /*
+ * Currently only 3 tables(GTDT, FADT, MADT) are pointed by XSDT. Alloc
+ * entries for them.
+ */
+ acpitables[XSDT].size = sizeof(struct acpi_table_xsdt) +
+ sizeof(uint64_t) * 2;
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 3);
+
+ acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 3);
+
+ acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+
+ rc = libxl__estimate_madt_size(gc, info, xc_config);
+ if (rc < 0)
+ goto out;
+
+ acpitables[MADT].size = rc;
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 3);
+
+ acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ acpitables[FADT].size = sizeof(struct acpi_table_fadt);
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 3);
+
+ acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ acpitables[DSDT].size = dsdt_anycpu_arm_len;
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 3);
+
+ assert(dom->acpi_modules[0].length <= GUEST_ACPI_SIZE);
+ dom->acpi_modules[0].data = libxl__zalloc(gc, dom->acpi_modules[0].length);
+
+ rc = 0;
+out:
+ return rc;
+}
+
int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
libxl__domain_build_state *state,
struct xc_dom_image *dom)
{
const libxl_version_info *vers;
int rc = 0;
+ struct acpitable acpitables[NUMS];
+
+ /* convenience aliases */
+ xc_domain_configuration_t *xc_config = &state->config;
vers = libxl_get_version_info(CTX);
if (vers == NULL) {
@@ -54,6 +150,8 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
dom->acpi_modules[0].length = 0;
dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
+ rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+
out:
return rc;
}