diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index d13f45991..7e614051a 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -89,6 +89,7 @@ bool stdio_in_use; bool lapic_pt; bool is_rtvm; bool pt_tpm2; +bool pt_ptct; bool is_winvm; bool skip_pci_mem64bar_workaround = false; diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c index 0c25ff555..2de483ff8 100644 --- a/devicemodel/hw/platform/acpi/acpi.c +++ b/devicemodel/hw/platform/acpi/acpi.c @@ -85,7 +85,8 @@ #define FACS_OFFSET 0x3C0 #define NHLT_OFFSET 0x400 #define TPM2_OFFSET 0xC00 -#define DSDT_OFFSET 0xE40 +#define PTCT_OFFSET 0xF00 +#define DSDT_OFFSET 0x1100 #define ASL_TEMPLATE "dm.XXXXXXX" #define ASL_SUFFIX ".aml" @@ -186,6 +187,11 @@ basl_fwrite_rsdt(FILE *fp, struct vmctx *ctx) EFPRINTF(fp, "[0004]\t\tACPI Table Address %u : %08X\n", num++, basl_acpi_base + TPM2_OFFSET); + if (pt_ptct) { + EFPRINTF(fp, "[0004]\t\tACPI Table Address %u : %08X\n", num++, + basl_acpi_base + PTCT_OFFSET); + } + EFFLUSH(fp); return 0; @@ -228,6 +234,11 @@ basl_fwrite_xsdt(FILE *fp, struct vmctx *ctx) EFPRINTF(fp, "[0004]\t\tACPI Table Address %u : 00000000%08X\n", num++, basl_acpi_base + TPM2_OFFSET); + if (pt_ptct) { + EFPRINTF(fp, "[0004]\t\tACPI Table Address %u : 00000000%08X\n", num++, + basl_acpi_base + PTCT_OFFSET); + } + EFFLUSH(fp); return 0; @@ -1064,6 +1075,41 @@ static struct { { basl_fwrite_dsdt, DSDT_OFFSET, true } }; +int create_and_inject_vptct(struct vmctx *ctx) +{ +#define PTCT_NATIVE_FILE_PATH_IN_SOS "/sys/firmware/acpi/tables/PTCT" +#define PTCT_BUF_LEN 0x200 /* Otherwise, need to modify DSDT_OFFSET corresponding */ + int native_ptct_fd; + int rc; + size_t native_ptct_len; + size_t vptct_len; + uint8_t buf[PTCT_BUF_LEN] = {0}; + + native_ptct_fd = open(PTCT_NATIVE_FILE_PATH_IN_SOS, O_RDONLY); + if (native_ptct_fd < 0){ + pr_err("failed to open /sys/firmware/acpi/tables/PTCT !!!!! errno:%d\n", errno); + return -1; + } + native_ptct_len = lseek(native_ptct_fd, 0, SEEK_END); + if (native_ptct_len > PTCT_BUF_LEN) { + pr_err("%s native_ptct_len = %d large than PTCT_BUF_LEN\n", __func__, native_ptct_len); + return -1; + } + + (void)lseek(native_ptct_fd, 0, SEEK_SET); + rc = read(native_ptct_fd, buf, native_ptct_len); + if (rc < native_ptct_len ){ + pr_err("Native PTCT is not fully read into buf!!!"); + return -1; + } + close(native_ptct_fd); + + vptct_len = native_ptct_len; + + memcpy(vm_map_gpa(ctx, ACPI_BASE + PTCT_OFFSET, vptct_len), buf, vptct_len); + return 0; +}; + void acpi_table_enable(int num) { @@ -1134,5 +1180,9 @@ acpi_build(struct vmctx *ctx, int ncpu) i++; } + if (pt_ptct) { + create_and_inject_vptct(ctx); + } + return err; } diff --git a/devicemodel/include/dm.h b/devicemodel/include/dm.h index 063bd79ba..192649435 100644 --- a/devicemodel/include/dm.h +++ b/devicemodel/include/dm.h @@ -49,6 +49,7 @@ extern char *mac_seed; extern bool lapic_pt; extern bool is_rtvm; extern bool pt_tpm2; +extern bool pt_ptct; extern bool is_winvm; int vmexit_task_switch(struct vmctx *ctx, struct vhm_request *vhm_req,