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

2018-02-28 Thread Haozhong Zhang
On 02/27/18 17:56 +, Anthony PERARD wrote:
> On Thu, Dec 07, 2017 at 06:10:23PM +0800, Haozhong Zhang wrote:
> > 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 
> > ---
> 
> > diff --git a/tools/libacpi/qemu_loader.c b/tools/libacpi/qemu_loader.c
> > new file mode 100644
> > index 00..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.
> 
> That's only a mirror, the official QEMU tree is on git.qemu.org. So I
> think the URL should read:
> https://git.qemu.org/?p=qemu.git;a=blob;f=hw/acpi/bios-linker-loader.c;hb=HEAD

will fix the url

> 
> > + *
> > + * 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 
> > .
> > + */
> > +
> > +#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);
> 
> Is it necessary to filter the "files" that are available via fw_cfg? Is
> there enough memory for hvmloader to just alocate the "struct rom" for
> every available files? Other solution might be to filter base on
> "etc/acpi/*" + "etc/table-loader".
>

The filter here is primarily to avoid loading unused roms in case that
their presence may have harmful side-effects (though I can't image what
side-effects could be).

Haozhong

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

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

2018-02-27 Thread Anthony PERARD
On Thu, Dec 07, 2017 at 06:10:23PM +0800, Haozhong Zhang wrote:
> 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 
> ---

> diff --git a/tools/libacpi/qemu_loader.c b/tools/libacpi/qemu_loader.c
> new file mode 100644
> index 00..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.

That's only a mirror, the official QEMU tree is on git.qemu.org. So I
think the URL should read:
https://git.qemu.org/?p=qemu.git;a=blob;f=hw/acpi/bios-linker-loader.c;hb=HEAD

> + *
> + * 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 
> .
> + */
> +
> +#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);

Is it necessary to filter the "files" that are available via fw_cfg? Is
there enough memory for hvmloader to just alocate the "struct rom" for
every available files? Other solution might be to filter base on
"etc/acpi/*" + "etc/table-loader".


-- 
Anthony PERARD

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

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

2017-12-07 Thread Haozhong Zhang
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 
---
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Jan Beulich 
Cc: Konrad Rzeszutek Wilk 
Cc: Stefano Stabellini 
Cc: Tim Deegan 
Cc: Wei Liu 
---
 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 & 0x00ffUL) << 24) |
+   ((v & 0xff00UL) << 8)  |
+   ((v & 0x00ffUL) >> 8)  |
+   ((v & 0xff00UL) >> 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 00..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 .
+ */
+
+#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