diff --git a/Makefile b/Makefile index 3872b2ce6..b0cdf47bf 100644 --- a/Makefile +++ b/Makefile @@ -132,7 +132,7 @@ hvapplydiffconfig: @$(MAKE) applydiffconfig $(HV_MAKEOPTS) PATCH=$(abspath $(PATCH)) devicemodel: tools - $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) DM_ASL_COMPILER=$(ASL_COMPILER) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE) + $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE) tools: mkdir -p $(TOOLS_OUT) diff --git a/devicemodel/Makefile b/devicemodel/Makefile index dd28db6ec..fc69e1d57 100644 --- a/devicemodel/Makefile +++ b/devicemodel/Makefile @@ -45,10 +45,6 @@ CFLAGS += -I$(SYSROOT)/usr/include/SDL2 CFLAGS += -I$(SYSROOT)/usr/include/EGL CFLAGS += -I$(SYSROOT)/usr/include/GLES2 -ifneq (, $(DM_ASL_COMPILER)) -CFLAGS += -DASL_COMPILER=\"$(DM_ASL_COMPILER)\" -endif - GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1) GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 0e3d77bfa..7a3b46e4f 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -146,6 +146,7 @@ usage(int code) " %*s [-k kernel_image_path]\n" " %*s [-l lpc] [-m mem] [-r ramdisk_image_path]\n" " %*s [-s pci] [--ovmf ovmf_file_path]\n" + " %*s [--iasl iasl_compiler_path]\n" " %*s [--enable_trusty] [--intr_monitor param_setting]\n" " %*s [--acpidev_pt HID] [--mmiodev_pt MMIO_Regions]\n" " %*s [--vtpm2 sock_path] [--virtio_poll interval]\n" @@ -162,6 +163,7 @@ usage(int code) " -s: PCI slot config\n" " -v: version\n" " --ovmf: ovmf file path\n" + " --iasl: iasl compiler path\n" " --ssram: Congfiure Software SRAM parameters\n" " --cpu_affinity: list of Service VM vCPUs assigned to this User VM, the vCPUs are" " identified by their local APIC IDs.\n" @@ -185,7 +187,7 @@ usage(int code) (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "", - (int)strnlen(progname, PATH_MAX), ""); + (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), ""); exit(code); } @@ -762,6 +764,7 @@ sig_handler_term(int signo) enum { CMD_OPT_VSBL = 1000, CMD_OPT_OVMF, + CMD_OPT_IASL, CMD_OPT_CPU_AFFINITY, CMD_OPT_PART_INFO, CMD_OPT_TRUSTY_ENABLE, @@ -806,6 +809,7 @@ static struct option long_options[] = { #endif {"vsbl", required_argument, 0, CMD_OPT_VSBL}, {"ovmf", required_argument, 0, CMD_OPT_OVMF}, + {"iasl", required_argument, 0, CMD_OPT_IASL}, {"cpu_affinity", required_argument, 0, CMD_OPT_CPU_AFFINITY}, {"part_info", required_argument, 0, CMD_OPT_PART_INFO}, {"enable_trusty", no_argument, 0, @@ -926,6 +930,10 @@ main(int argc, char *argv[]) errx(EX_USAGE, "invalid ovmf param %s", optarg); skip_pci_mem64bar_workaround = true; break; + case CMD_OPT_IASL: + if (acrn_parse_iasl(optarg) != 0) + errx(EX_USAGE, "invalid iasl param %s", optarg); + break; case CMD_OPT_CPU_AFFINITY: if (acrn_parse_cpu_affinity(optarg) != 0) errx(EX_USAGE, "invalid pcpu param %s", optarg); @@ -1020,6 +1028,12 @@ main(int argc, char *argv[]) usage(1); } } + + if (get_iasl_compiler() != 0) { + pr_err("Cannot find Intel ACPI ASL compiler tool \"iasl\".\n"); + exit(1); + } + argc -= optind; argv += optind; diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c index 0ba25e879..a0a5fe583 100644 --- a/devicemodel/hw/platform/acpi/acpi.c +++ b/devicemodel/hw/platform/acpi/acpi.c @@ -95,9 +95,8 @@ #define ASL_TEMPLATE "dm.XXXXXXX" #define ASL_SUFFIX ".aml" -#ifndef ASL_COMPILER -#define ASL_COMPILER "/usr/sbin/iasl" -#endif + +static char asl_compiler[MAXPATHLEN] = {0}; uint64_t audio_nhlt_len = 0; @@ -972,7 +971,7 @@ basl_compile(struct vmctx *ctx, uint64_t offset) { struct basl_fio io[2]; - static char iaslbuf[3*MAXPATHLEN + 10]; + static char iaslbuf[4*MAXPATHLEN + 10]; int err; err = basl_start(&io[0], &io[1]); @@ -990,12 +989,12 @@ basl_compile(struct vmctx *ctx, if (basl_verbose_iasl) snprintf(iaslbuf, sizeof(iaslbuf), "%s -p %s %s", - ASL_COMPILER, + asl_compiler, io[1].f_name, io[0].f_name); else snprintf(iaslbuf, sizeof(iaslbuf), "/bin/sh -c \"%s -p %s %s\" 1> /dev/null", - ASL_COMPILER, + asl_compiler, io[1].f_name, io[0].f_name); err = system(iaslbuf); @@ -1110,6 +1109,59 @@ get_acpi_table_length(void) return ACPI_LENGTH; } +int +get_default_iasl_compiler(void) +{ + int ret = -1; + char c; + int i = 0; + FILE *fd_iasl = popen("which iasl", "r"); + + if (fd_iasl != NULL) + { + while (i < (MAXPATHLEN - 1)) { + + c = fgetc(fd_iasl); + if ((c == EOF) || (c == '\n') || (c == '\r') || (c == 0)) { + break; + } + + asl_compiler[i++] = c; + } + if (strlen(asl_compiler) > 0) { + pr_info("Found default iasl path: %s\n", asl_compiler); + ret = 0; + } + pclose(fd_iasl); + } + return ret; +} + +int +acrn_parse_iasl(char *arg) +{ + size_t len = strnlen(arg, MAXPATHLEN); + + if (len < MAXPATHLEN) { + strncpy(asl_compiler, arg, len + 1); + pr_info("iasl path is given by --iasl at run time: %s\n", asl_compiler); + return 0; + } else + return -1; +} + +int +get_iasl_compiler(void) +{ + int ret = 0; + + if(strlen(asl_compiler) == 0) { + ret = get_default_iasl_compiler(); + } + + return ret; +} + int acpi_build(struct vmctx *ctx, int ncpu) { diff --git a/devicemodel/include/acpi.h b/devicemodel/include/acpi.h index 52130d220..0f46e3885 100644 --- a/devicemodel/include/acpi.h +++ b/devicemodel/include/acpi.h @@ -121,4 +121,7 @@ int lapicid_from_pcpuid(int pcpu_id); int lapic_to_pcpu(int lapic); int parse_madt(void); +int acrn_parse_iasl(char *arg); +int get_iasl_compiler(void); + #endif /* _ACPI_H_ */