[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC XEN PATCH v4 34/41] tools/libacpi: probe QEMU ACPI ROMs via fw_cfg interface



Probe following QEMU ACPI ROMs:
 * etc/acpi/rsdp:       QEMU RSDP, which is used to iterate other
                        QEMU ACPI tables in etc/acpi/tables

 * etc/acpi/tables:     other QEMU ACPI tables

 * etc/table-loader:    QEMU BIOSLinkerLoader ROM, which can be
                        executed to load QEMU ACPI tables

 * etc/acpi/nvdimm-mem: RAM which is used as NVDIMM ACPI DSM buffer,
                        the exact location will be allocated during
                        the execution of /etc/table-loader

Signed-off-by: Haozhong Zhang <haozhong.zhang@xxxxxxxxx>
---
Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Cc: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>
Cc: Tim Deegan <tim@xxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/firmware/hvmloader/Makefile |  3 +-
 tools/firmware/hvmloader/util.h   | 13 +++++++
 tools/libacpi/qemu.h              | 52 +++++++++++++++++++++++++
 tools/libacpi/qemu_fw_cfg.c       | 27 +++++++++++++
 tools/libacpi/qemu_loader.c       | 82 +++++++++++++++++++++++++++++++++++++++
 tools/libacpi/qemu_stub.c         | 11 ++++++
 6 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 tools/libacpi/qemu.h
 create mode 100644 tools/libacpi/qemu_loader.c

diff --git a/tools/firmware/hvmloader/Makefile 
b/tools/firmware/hvmloader/Makefile
index 53b99e2c28..eaa175ece6 100644
--- a/tools/firmware/hvmloader/Makefile
+++ b/tools/firmware/hvmloader/Makefile
@@ -76,12 +76,13 @@ smbios.o: CFLAGS += 
-D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\""
 
 ACPI_PATH = ../../libacpi
 DSDT_FILES = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c
-ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o 
qemu_fw_cfg.o
+ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o 
qemu_fw_cfg.o qemu_loader.o
 $(ACPI_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\"
 CFLAGS += -I$(ACPI_PATH)
 vpath build.c $(ACPI_PATH)
 vpath static_tables.c $(ACPI_PATH)
 vpath qemu_fw_cfg.c $(ACPI_PATH)
+vpath qemu_loader.c $(ACPI_PATH)
 OBJS += $(ACPI_OBJS)
 
 hvmloader: $(OBJS)
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index e32b83e721..16244bb0b4 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -66,6 +66,19 @@ static inline int test_and_clear_bit(int nr, volatile void 
*addr)
     return oldbit;
 }
 
+static inline uint32_t be32_to_cpu(uint32_t v)
+{
+    return ((v & 0x000000ffUL) << 24) |
+           ((v & 0x0000ff00UL) << 8)  |
+           ((v & 0x00ff0000UL) >> 8)  |
+           ((v & 0xff000000UL) >> 24);
+}
+
+static inline uint16_t be16_to_cpu(uint16_t v)
+{
+    return ((v & 0x00ff) << 8) | ((v & 0xff00) >> 8);
+}
+
 /* MSR access */
 void wrmsr(uint32_t idx, uint64_t v);
 uint64_t rdmsr(uint32_t idx);
diff --git a/tools/libacpi/qemu.h b/tools/libacpi/qemu.h
new file mode 100644
index 0000000000..940816bf27
--- /dev/null
+++ b/tools/libacpi/qemu.h
@@ -0,0 +1,52 @@
+/*
+ * libacpi/qemu.h
+ *
+ * Header file of QEMU drivers.
+ *
+ * Copyright (C) 2017,  Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License, version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __QEMU_H__
+#define __QEMU_H__
+
+#include LIBACPI_STDUTILS
+#include "libacpi.h"
+
+#define FW_CFG_FILE_PATH_MAX_LENGTH 56
+
+/* An individual file entry, 64 bytes total. */
+struct fw_cfg_file {
+    uint32_t size;      /* size of referenced fw_cfg item, big-endian */
+    uint16_t select;    /* selector key of fw_cfg item, big-endian */
+    uint16_t reserved;
+    char name[FW_CFG_FILE_PATH_MAX_LENGTH]; /* fw_cfg item name,    */
+                                            /* NUL-terminated ascii */
+};
+
+int fw_cfg_probe_roms(struct acpi_ctxt *ctxt);
+
+int loader_add_rom(struct acpi_ctxt* ctxt, const struct fw_cfg_file *file);
+
+#endif /* !__QEMU_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libacpi/qemu_fw_cfg.c b/tools/libacpi/qemu_fw_cfg.c
index 254d2f575d..458b6eabdc 100644
--- a/tools/libacpi/qemu_fw_cfg.c
+++ b/tools/libacpi/qemu_fw_cfg.c
@@ -21,6 +21,7 @@
 
 #include LIBACPI_STDUTILS
 #include "libacpi.h"
+#include "qemu.h"
 
 /* QEMU fw_cfg I/O ports on x86 */
 #define FW_CFG_PORT_SEL         0x510
@@ -28,6 +29,7 @@
 
 /* QEMU fw_cfg entries */
 #define FW_CFG_SIGNATURE        0x0000
+#define FW_CFG_FILE_DIR         0x0019
 
 static inline void fw_cfg_select(uint16_t entry)
 {
@@ -55,6 +57,31 @@ bool fw_cfg_exists(void)
     return sig == 0x554d4551 /* "QEMU" */;
 }
 
+int fw_cfg_probe_roms(struct acpi_ctxt *ctxt)
+{
+    struct fw_cfg_file file;
+    uint32_t count, i;
+    int rc = 0;
+
+    fw_cfg_read_entry(FW_CFG_FILE_DIR, &count, sizeof(count));
+    count = be32_to_cpu(count);
+
+    for ( i = 0; i < count; i++ )
+    {
+        fw_cfg_read(&file, sizeof(file));
+        rc = loader_add_rom(ctxt, &file);
+        if ( rc )
+        {
+            file.name[FW_CFG_FILE_PATH_MAX_LENGTH - 1] = '\0';
+            printf("ERROR: failed to load QEMU ROM %s, err %d\n",
+                   file.name, rc);
+            break;
+        }
+    }
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libacpi/qemu_loader.c b/tools/libacpi/qemu_loader.c
new file mode 100644
index 0000000000..c0ed3b0ad0
--- /dev/null
+++ b/tools/libacpi/qemu_loader.c
@@ -0,0 +1,82 @@
+/*
+ * libacpi/qemu_loader.c
+ *
+ * Driver of QEMU BIOSLinkerLoader interface. The reference document
+ * can be found at
+ * https://github.com/qemu/qemu/blob/master/hw/acpi/bios-linker-loader.c.
+ *
+ * Copyright (C) 2017,  Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License, version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include LIBACPI_STDUTILS
+#include "libacpi.h"
+#include "qemu.h"
+
+struct rom {
+    struct fw_cfg_file file;
+    struct rom *next;
+};
+
+static struct rom *roms = NULL;
+static struct rom *bios_loader = NULL;
+
+static bool rom_needed(const char *file_name)
+{
+    return
+        !strncmp(file_name, "etc/acpi/rsdp", FW_CFG_FILE_PATH_MAX_LENGTH) ||
+        !strncmp(file_name, "etc/acpi/tables", FW_CFG_FILE_PATH_MAX_LENGTH) ||
+        !strncmp(file_name, "etc/table-loader", FW_CFG_FILE_PATH_MAX_LENGTH) ||
+        !strncmp(file_name, "etc/acpi/nvdimm-mem", 
FW_CFG_FILE_PATH_MAX_LENGTH);
+}
+
+int loader_add_rom(struct acpi_ctxt *ctxt, const struct fw_cfg_file *file)
+{
+    const char *name = file->name;
+    struct rom *rom;
+
+    if ( !rom_needed(name) )
+        return 0;
+
+    rom = roms;
+    while ( rom )
+    {
+        if ( !strncmp(rom->file.name, name, FW_CFG_FILE_PATH_MAX_LENGTH) )
+            return -EEXIST;
+        rom = rom->next;
+    }
+
+    rom = ctxt->mem_ops.alloc(ctxt, sizeof(*rom), 0);
+    if ( !rom )
+        return -ENOMEM;
+
+    memcpy(&rom->file, file, sizeof(*file));
+    rom->next = roms;
+    roms = rom;
+
+    if ( !strncmp(name, "etc/table-loader", FW_CFG_FILE_PATH_MAX_LENGTH) )
+        bios_loader = rom;
+
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libacpi/qemu_stub.c b/tools/libacpi/qemu_stub.c
index 6506de2d9c..fdba5294e1 100644
--- a/tools/libacpi/qemu_stub.c
+++ b/tools/libacpi/qemu_stub.c
@@ -22,12 +22,23 @@
 
 #include LIBACPI_STDUTILS
 #include "libacpi.h"
+#include "qemu.h"
 
 bool fw_cfg_exists(void)
 {
     return false;
 }
 
+int fw_cfg_probe_roms(struct acpi_ctxt *ctxt)
+{
+    return -ENOSYS;
+}
+
+int loader_add_rom(struct acpi_ctxt* ctxt, const struct fw_cfg_file *file)
+{
+    return -ENOSYS;
+}
+
 /*
  * Local variables:
  * mode: C
-- 
2.15.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.