[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v3 02/11] hw/i386/acpi-build: move generic acpi
From: |
Shannon Zhao |
Subject: |
[Qemu-devel] [RFC PATCH v3 02/11] hw/i386/acpi-build: move generic acpi building helpers into dedictated file |
Date: |
Tue, 17 Feb 2015 10:08:40 +0800 |
Move generic acpi building helpers into dedictated file and this
can be shared with other machines.
Signed-off-by: Shannon Zhao <address@hidden>
---
hw/acpi/aml-build.c | 58 ++++++++++++++++++++++++
hw/i386/acpi-build.c | 104 +++++++++----------------------------------
hw/i386/acpi-build.h | 5 ++
include/hw/acpi/aml-build.h | 28 ++++++++++--
4 files changed, 108 insertions(+), 87 deletions(-)
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 8f06f56..f49e653 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -937,3 +937,61 @@ Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
dec, addr_gran, addr_min, addr_max,
addr_trans, len, flags);
}
+
+void
+build_header(GArray *linker, GArray *table_data, AcpiTableHeader *h,
+ const char *sig, const char *ome_id, const char *asl_id,
+ int len, uint8_t rev)
+{
+ memcpy(&h->signature, sig, 4);
+ h->length = cpu_to_le32(len);
+ h->revision = rev;
+ memcpy(h->oem_id, ome_id, 6);
+ memcpy(h->oem_table_id, asl_id, 4);
+ memcpy(h->oem_table_id + 4, sig, 4);
+ h->oem_revision = cpu_to_le32(1);
+ memcpy(h->asl_compiler_id, asl_id, 4);
+ h->asl_compiler_revision = cpu_to_le32(1);
+ h->checksum = 0;
+ /* Checksum to be filled in by Guest linker */
+ bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE,
+ table_data->data, h, len, &h->checksum);
+}
+
+void *acpi_data_push(GArray *table_data, unsigned size)
+{
+ unsigned off = table_data->len;
+ g_array_set_size(table_data, off + size);
+ return table_data->data + off;
+}
+
+unsigned acpi_data_len(GArray *table)
+{
+#if GLIB_CHECK_VERSION(2, 22, 0)
+ assert(g_array_get_element_size(table) == 1);
+#endif
+ return table->len;
+}
+
+void acpi_add_table(GArray *table_offsets, GArray *table_data)
+{
+ uint32_t offset = cpu_to_le32(table_data->len);
+ g_array_append_val(table_offsets, offset);
+}
+
+void acpi_build_tables_init(AcpiBuildTables *tables)
+{
+ tables->rsdp = g_array_new(false, true /* clear */, 1);
+ tables->tcpalog = g_array_new(false, true /* clear */, 1);
+ tables->linker = bios_linker_loader_init();
+ tables->table_data = init_aml_allocator(tables->linker);
+}
+
+void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
+{
+ void *linker_data = bios_linker_loader_cleanup(tables->linker);
+ free_aml_allocator();
+ g_free(linker_data);
+ g_array_free(tables->rsdp, mfre);
+ g_array_free(tables->tcpalog, mfre);
+}
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index f6e571f..e9c6eb3 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -70,9 +70,6 @@
#define ACPI_BUILD_TABLE_SIZE 0x20000
-/* Reserve RAM space for tables: add another order of magnitude. */
-#define ACPI_BUILD_TABLE_MAX_SIZE 0x200000
-
/* #define DEBUG_ACPI_BUILD */
#ifdef DEBUG_ACPI_BUILD
#define ACPI_BUILD_DPRINTF(fmt, ...) \
@@ -267,45 +264,8 @@ static void acpi_get_pci_info(PcPciInfo *info)
NULL);
}
-#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
-#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
-
-static void
-build_header(GArray *linker, GArray *table_data,
- AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
-{
- memcpy(&h->signature, sig, 4);
- h->length = cpu_to_le32(len);
- h->revision = rev;
- memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
- memcpy(h->oem_table_id, ACPI_BUILD_APPNAME4, 4);
- memcpy(h->oem_table_id + 4, sig, 4);
- h->oem_revision = cpu_to_le32(1);
- memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME4, 4);
- h->asl_compiler_revision = cpu_to_le32(1);
- h->checksum = 0;
- /* Checksum to be filled in by Guest linker */
- bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE,
- table_data->data, h, len, &h->checksum);
-}
-
#define ACPI_PORT_SMI_CMD 0x00b2 /* TODO: this is APM_CNT_IOPORT */
-static inline void *acpi_data_push(GArray *table_data, unsigned size)
-{
- unsigned off = table_data->len;
- g_array_set_size(table_data, off + size);
- return table_data->data + off;
-}
-
-static unsigned acpi_data_len(GArray *table)
-{
-#if GLIB_CHECK_VERSION(2, 22, 0)
- assert(g_array_get_element_size(table) == 1);
-#endif
- return table->len;
-}
-
static void acpi_align_size(GArray *blob, unsigned align)
{
/* Align size to multiple of given size. This reduces the chance
@@ -314,12 +274,6 @@ static void acpi_align_size(GArray *blob, unsigned align)
g_array_set_size(blob, ROUND_UP(acpi_data_len(blob), align));
}
-static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
-{
- uint32_t offset = cpu_to_le32(table_data->len);
- g_array_append_val(table_offsets, offset);
-}
-
/* FACS */
static void
build_facs(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
@@ -387,8 +341,9 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo
*pm,
fadt_setup(fadt, pm);
- build_header(linker, table_data,
- (void *)fadt, "FACP", sizeof(*fadt), 1);
+ build_header(linker, table_data, (void *)fadt, "FACP",
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
+ sizeof(*fadt), 1);
}
static void
@@ -458,6 +413,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo
*cpu,
build_header(linker, table_data,
(void *)(table_data->data + madt_start), "APIC",
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
table_data->len - madt_start, 1);
}
@@ -996,8 +952,9 @@ build_hpet(GArray *table_data, GArray *linker)
*/
hpet->timer_block_id = cpu_to_le32(0x8086a201);
hpet->addr.address = cpu_to_le64(HPET_BASE);
- build_header(linker, table_data,
- (void *)hpet, "HPET", sizeof(*hpet), 1);
+ build_header(linker, table_data, (void *)hpet, "HPET",
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
+ sizeof(*hpet), 1);
}
static void
@@ -1019,8 +976,9 @@ build_tpm_tcpa(GArray *table_data, GArray *linker, GArray
*tcpalog)
table_data, &tcpa->log_area_start_address,
sizeof(tcpa->log_area_start_address));
- build_header(linker, table_data,
- (void *)tcpa, "TCPA", sizeof(*tcpa), 2);
+ build_header(linker, table_data, (void *)tcpa, "TCPA",
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
+ sizeof(*tcpa), 2);
acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
}
@@ -1143,8 +1101,8 @@ build_srat(GArray *table_data, GArray *linker,
PcGuestInfo *guest_info)
}
build_header(linker, table_data,
- (void *)(table_data->data + srat_start),
- "SRAT",
+ (void *)(table_data->data + srat_start), "SRAT",
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
table_data->len - srat_start, 1);
}
@@ -1174,7 +1132,9 @@ build_mcfg_q35(GArray *table_data, GArray *linker,
AcpiMcfgInfo *info)
} else {
sig = "MCFG";
}
- build_header(linker, table_data, (void *)mcfg, sig, len, 1);
+ build_header(linker, table_data, (void *)mcfg, sig,
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
+ len, 1);
}
static void
@@ -1198,7 +1158,8 @@ build_dmar_q35(GArray *table_data, GArray *linker)
drhd->address = cpu_to_le64(Q35_HOST_BRIDGE_IOMMU_ADDR);
build_header(linker, table_data, (void *)(table_data->data + dmar_start),
- "DMAR", table_data->len - dmar_start, 1);
+ "DMAR", ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
+ table_data->len - dmar_start, 1);
}
static void
@@ -1213,6 +1174,7 @@ build_dsdt(GArray *table_data, GArray *linker,
AcpiMiscInfo *misc)
memset(dsdt, 0, sizeof *dsdt);
build_header(linker, table_data, dsdt, "DSDT",
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
misc->dsdt_size, 1);
}
@@ -1236,8 +1198,9 @@ build_rsdt(GArray *table_data, GArray *linker, GArray
*table_offsets)
table_data,
&rsdt->table_offset_entry[i],
sizeof(uint32_t));
}
- build_header(linker, table_data,
- (void *)rsdt, "RSDT", rsdt_len, 1);
+ build_header(linker, table_data, (void *)rsdt, "RSDT",
+ ACPI_BUILD_APPNAME6, ACPI_BUILD_APPNAME4,
+ rsdt_len, 1);
}
static GArray *
@@ -1265,31 +1228,6 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned
rsdt)
}
typedef
-struct AcpiBuildTables {
- Aml *table_data;
- GArray *rsdp;
- GArray *tcpalog;
- GArray *linker;
-} AcpiBuildTables;
-
-static inline void acpi_build_tables_init(AcpiBuildTables *tables)
-{
- tables->rsdp = g_array_new(false, true /* clear */, 1);
- tables->tcpalog = g_array_new(false, true /* clear */, 1);
- tables->linker = bios_linker_loader_init();
- tables->table_data = init_aml_allocator(tables->linker);
-}
-
-static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool
mfre)
-{
- void *linker_data = bios_linker_loader_cleanup(tables->linker);
- free_aml_allocator();
- g_free(linker_data);
- g_array_free(tables->rsdp, mfre);
- g_array_free(tables->tcpalog, mfre);
-}
-
-typedef
struct AcpiBuildState {
/* Copy of table in RAM (for patching). */
ram_addr_t table_ram;
diff --git a/hw/i386/acpi-build.h b/hw/i386/acpi-build.h
index e57b1aa..b11b404 100644
--- a/hw/i386/acpi-build.h
+++ b/hw/i386/acpi-build.h
@@ -4,6 +4,11 @@
#include "qemu/typedefs.h"
+#define ACPI_BUILD_APPNAME "Bochs"
+#define ACPI_BUILD_APPNAME6 "BOCHS "
+#define ACPI_BUILD_APPNAME4 "BXPC"
+#define ACPI_BUILD_APPNAME4_HEX 0x43505842
+
void acpi_setup(PcGuestInfo *);
#endif
diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 7e9ce38..6296ea1 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -4,12 +4,14 @@
#include <stdint.h>
#include <glib.h>
#include "qemu/compiler.h"
+#include "hw/acpi/acpi-defs.h"
+
+/* Reserve RAM space for tables: add another order of magnitude. */
+#define ACPI_BUILD_TABLE_MAX_SIZE 0x200000
#define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
-#define ACPI_BUILD_APPNAME "Bochs"
-#define ACPI_BUILD_APPNAME6 "BOCHS "
-#define ACPI_BUILD_APPNAME4 "BXPC"
-#define ACPI_BUILD_APPNAME4_HEX 0x43505842
+#define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
+#define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
typedef enum {
AML_HELPER = 0,
@@ -101,6 +103,14 @@ typedef enum {
aml_ReadWrite = 1,
} AmlReadAndWrite;
+typedef
+struct AcpiBuildTables {
+ Aml *table_data;
+ GArray *rsdp;
+ GArray *tcpalog;
+ GArray *linker;
+} AcpiBuildTables;
+
/**
* init_aml_allocator:
* @linker: linker that used by API for registering ACPI tables
@@ -202,4 +212,14 @@ Aml *aml_resource_template(void);
Aml *aml_field(const char *name, AmlFieldFlags flags);
Aml *aml_varpackage(uint32_t num_elements);
+void
+build_header(GArray *linker, GArray *table_data, AcpiTableHeader *h,
+ const char *sig, const char *ome_id, const char *asl_id,
+ int len, uint8_t rev);
+void *acpi_data_push(GArray *table_data, unsigned size);
+unsigned acpi_data_len(GArray *table);
+void acpi_add_table(GArray *table_offsets, GArray *table_data);
+void acpi_build_tables_init(AcpiBuildTables *tables);
+void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
+
#endif
--
1.7.1
- [Qemu-devel] [RFC PATCH v3 00/11] Generate ACPI v5.1 tables and expose it to guest over fw_cfg on ARM, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 04/11] hw/acpi/aml-build: Add aml_memory32_fixed() and aml_interrupt(), Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 08/11] hw/arm/virt-acpi-build: Generate GTDT table, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 03/11] hw/arm/virt-acpi-build: Basic framework for building ACPI tables on ARM, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 09/11] hw/arm/virt-acpi-build: Generate RSDT table, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 06/11] hw/arm/virt-acpi-build: Generate FADT table and update ACPI headers, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 01/11] hw/i386: Move ACPI header definitions in an arch-independent location, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 02/11] hw/i386/acpi-build: move generic acpi building helpers into dedictated file,
Shannon Zhao <=
- [Qemu-devel] [RFC PATCH v3 07/11] hw/arm/virt-acpi-build: Generate MADT table, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 05/11] hw/arm/virt-acpi-build: Generation of DSDT table for virt devices, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 10/11] hw/arm/virt-acpi-build: Generate RSDP table, Shannon Zhao, 2015/02/16
- [Qemu-devel] [RFC PATCH v3 11/11] hw/arm/virt: Enable dynamic generation of ACPI v5.1 tables, Shannon Zhao, 2015/02/16