dm: refine the detection of "iasl" utility

At run time (on the *target* machine), acrn-dm depends on "iasl" to build
the ACPI tables for post-launched VMs.

This patch does:
- remove the dependency on ASL_COMPILER, which would only be used at build time
- add a new acrn-dm parameter "--iasl <iasl_compiler_path>"
  If "--iasl <iasl_compiler_path>" is specified as the acrn-dm parameter,
  acrn-dm uses <iasl_compiler_path> as the path to the "iasl" compiler;
  otherwise, "which iasl" is used to detect the "iasl" compiler.

  If "iasl" is not found at run time, refuse to launch the post-launched VM
  and exit directly.

v2 -> v3:
 - use "strlen" rather than "strncmp" to check whether asl_compiler
   has been set or not

v1 -> v2:
 - remove "iasl_param" and "with_iasl_param" to simplify the logic

Tracked-On: #7880

Signed-off-by: Victor Sun <victor.sun@intel.com>
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Shiqing Gao
2022-07-04 10:40:13 +08:00
committed by acrnsi-robot
parent 7cffac359b
commit cc309bd973
5 changed files with 77 additions and 12 deletions

View File

@@ -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)
{