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

[Xen-devel] [RFC XEN PATCH v4 33/41] tools/libacpi, hvmloader: detect QEMU fw_cfg interface



Add a function in libacpi to detect QEMU fw_cfg interface. Limit the
usage of fw_cfg interface to hvmloader now, so use stub functions for
others.

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.c   |  3 ++
 tools/libacpi/build.c             |  1 +
 tools/libacpi/libacpi.h           |  4 +++
 tools/libacpi/qemu_fw_cfg.c       | 66 +++++++++++++++++++++++++++++++++++++++
 tools/libacpi/qemu_stub.c         | 39 +++++++++++++++++++++++
 tools/libxl/Makefile              |  3 +-
 7 files changed, 117 insertions(+), 2 deletions(-)
 create mode 100644 tools/libacpi/qemu_fw_cfg.c
 create mode 100644 tools/libacpi/qemu_stub.c

diff --git a/tools/firmware/hvmloader/Makefile 
b/tools/firmware/hvmloader/Makefile
index a5b4c32c1a..53b99e2c28 100644
--- a/tools/firmware/hvmloader/Makefile
+++ b/tools/firmware/hvmloader/Makefile
@@ -76,11 +76,12 @@ 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
+ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o 
qemu_fw_cfg.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)
 OBJS += $(ACPI_OBJS)
 
 hvmloader: $(OBJS)
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c
index e4a37b3310..be4b64a379 100644
--- a/tools/firmware/hvmloader/util.c
+++ b/tools/firmware/hvmloader/util.c
@@ -979,6 +979,9 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     if ( !strncmp(xenstore_read("platform/acpi_laptop_slate", "0"), "1", 1)  )
         config->table_flags |= ACPI_HAS_SSDT_LAPTOP_SLATE;
 
+    if ( fw_cfg_exists() )
+        config->table_flags |= ACPI_HAS_QEMU_XEN;
+
     config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
                             ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
                             ACPI_HAS_BUTTONS | ACPI_HAS_VGA |
diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c
index f2185589f8..46051c46ac 100644
--- a/tools/libacpi/build.c
+++ b/tools/libacpi/build.c
@@ -531,6 +531,7 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
     nr_tables += construct_passthrough_tables(ctxt, table_ptrs,
                                               nr_tables, config);
 
+
     table_ptrs[nr_tables] = 0;
     return nr_tables;
 }
diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h
index 748a7e4a73..80403f04ab 100644
--- a/tools/libacpi/libacpi.h
+++ b/tools/libacpi/libacpi.h
@@ -20,6 +20,8 @@
 #ifndef __LIBACPI_H__
 #define __LIBACPI_H__
 
+#include <stdbool.h>
+
 #define ACPI_HAS_COM1              (1<<0)
 #define ACPI_HAS_COM2              (1<<1)
 #define ACPI_HAS_LPT1              (1<<2)
@@ -104,6 +106,8 @@ struct acpi_config {
 
 int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config);
 
+bool fw_cfg_exists(void);
+
 #endif /* __LIBACPI_H__ */
 
 /*
diff --git a/tools/libacpi/qemu_fw_cfg.c b/tools/libacpi/qemu_fw_cfg.c
new file mode 100644
index 0000000000..254d2f575d
--- /dev/null
+++ b/tools/libacpi/qemu_fw_cfg.c
@@ -0,0 +1,66 @@
+/*
+ * libacpi/qemu_fw_cfg.c
+ *
+ * Driver of QEMU fw_cfg interface. The reference document can be found at
+ * https://github.com/qemu/qemu/blob/master/docs/specs/fw_cfg.txt.
+ *
+ * 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"
+
+/* QEMU fw_cfg I/O ports on x86 */
+#define FW_CFG_PORT_SEL         0x510
+#define FW_CFG_PORT_DATA        0x511
+
+/* QEMU fw_cfg entries */
+#define FW_CFG_SIGNATURE        0x0000
+
+static inline void fw_cfg_select(uint16_t entry)
+{
+    outw(FW_CFG_PORT_SEL, entry);
+}
+
+static inline void fw_cfg_read(void *buf, uint32_t len)
+{
+    while ( len-- )
+        *(uint8_t *)(buf++) = inb(FW_CFG_PORT_DATA);
+}
+
+static void fw_cfg_read_entry(uint16_t entry, void *buf, uint32_t len)
+{
+    fw_cfg_select(entry);
+    fw_cfg_read(buf, len);
+}
+
+bool fw_cfg_exists(void)
+{
+    uint32_t sig;
+
+    fw_cfg_read_entry(FW_CFG_SIGNATURE, &sig, sizeof(sig));
+
+    return sig == 0x554d4551 /* "QEMU" */;
+}
+
+/*
+ * 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
new file mode 100644
index 0000000000..6506de2d9c
--- /dev/null
+++ b/tools/libacpi/qemu_stub.c
@@ -0,0 +1,39 @@
+/*
+ * libacpi/qemu_stub.c
+ *
+ * Stub functions of QEMU drivers. QEMU drivers are only used with
+ * HVMLoader now. Add stub functions to ensure libacpi can be compiled
+ * with others.
+ *
+ * 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"
+
+bool fw_cfg_exists(void)
+{
+    return false;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index a6f2dbd1cf..b6a8f662ed 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -78,11 +78,12 @@ endif
 
 ACPI_PATH  = $(XEN_ROOT)/tools/libacpi
 DSDT_FILES-$(CONFIG_X86) = dsdt_pvh.c
-ACPI_OBJS  = $(patsubst %.c,%.o,$(DSDT_FILES-y)) build.o static_tables.o
+ACPI_OBJS  = $(patsubst %.c,%.o,$(DSDT_FILES-y)) build.o static_tables.o 
qemu_stub.o
 $(DSDT_FILES-y): acpi
 $(ACPI_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/libxl_x86_acpi.h\"
 vpath build.c $(ACPI_PATH)/
 vpath static_tables.c $(ACPI_PATH)/
+vpath qemu_stub.c $(ACPI_PATH)/
 LIBXL_OBJS-$(CONFIG_X86) += $(ACPI_OBJS)
 
 .PHONY: acpi
-- 
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®.