From f9a163954d8d5bfe7afc234b99e5ecde4f8a96f6 Mon Sep 17 00:00:00 2001 From: Binbin Wu Date: Sun, 14 Oct 2018 20:53:37 +0800 Subject: [PATCH] dm: passthru: fix hardcoded nhlt table length NHLT table contains the settings some audio drivers need. An ACPI method is used to get NHLT table address & length. In current DM code, the NHLT talbe length in the ACPI method is hardcoded, which will cause troubles when the length of the table changed. This patch replaces the hardcoded NHLT table length according to the table length read from SOS. Tracked-On: #1461 Signed-off-by: Binbin Wu Acked-by: Yin Fengwei --- devicemodel/hw/pci/passthrough.c | 7 +++++-- devicemodel/hw/platform/acpi/acpi.c | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/devicemodel/hw/pci/passthrough.c b/devicemodel/hw/pci/passthrough.c index 5507f32ec..4d3243283 100644 --- a/devicemodel/hw/pci/passthrough.c +++ b/devicemodel/hw/pci/passthrough.c @@ -69,6 +69,8 @@ */ #define AUDIO_NHLT_HACK 1 +extern uint64_t audio_nhlt_len; + /* TODO: Add support for IO BAR of PTDev */ static int iofd = -1; @@ -1555,9 +1557,10 @@ write_dsdt_hdas(struct pci_vdev *dev) " MaxNotFixed, NonCacheable, ReadOnly,"); dsdt_line(" 0x0000000000000000, // Granularity"); dsdt_line(" 0x00000000000F2800, // Range Minimum"); - dsdt_line(" 0x00000000000F2FDE, // Range Maximum"); + dsdt_line(" 0x%08X, // Range Maximum", + 0xF2800 + audio_nhlt_len -1); dsdt_line(" 0x0000000000000000, // Translation Offset"); - dsdt_line(" 0x00000000000007DF, // Length"); + dsdt_line(" 0x%08X, // Length", audio_nhlt_len); dsdt_line(" ,, _Y06, AddressRangeACPI, TypeStatic)"); dsdt_line(" })"); dsdt_line(" Name (_S0W, 0x03) // _S0W: S0 Device Wake State"); diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c index b2669665d..460c0e56e 100644 --- a/devicemodel/hw/platform/acpi/acpi.c +++ b/devicemodel/hw/platform/acpi/acpi.c @@ -86,6 +86,8 @@ #define ASL_SUFFIX ".aml" #define ASL_COMPILER "/usr/sbin/iasl" +uint64_t audio_nhlt_len = 0; + static int basl_keep_temps; static int basl_verbose_iasl; static int basl_ncpu; @@ -595,8 +597,10 @@ basl_fwrite_nhlt(FILE *fp, struct vmctx *ctx) return -1; } + + audio_nhlt_len = lseek(fd, 0, SEEK_END); /* check if file size exceeds reserved room */ - if (lseek(fd, 0, SEEK_END) > DSDT_OFFSET - NHLT_OFFSET) { + if (audio_nhlt_len > DSDT_OFFSET - NHLT_OFFSET) { fprintf(stderr, "Host NHLT exceeds reserved room!\n"); close(fd); return -1;