[coreboot-gerrit] Patch set updated for coreboot: 6e6237e NOTFORMERGE: Implement ACPI in collaborative way

Vladimir Serbinenko (phcoder@gmail.com) gerrit at coreboot.org
Sat Aug 30 21:25:36 CEST 2014


Vladimir Serbinenko (phcoder at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6801

-gerrit

commit 6e6237ea34db33e158873c44ea57f7a1dcbf11c6
Author: Vladimir Serbinenko <phcoder at gmail.com>
Date:   Sat Aug 30 19:28:05 2014 +0200

    NOTFORMERGE: Implement ACPI in collaborative way
    
    This approach avoids having same basic tables 150-lines mantra over 100 times
    in codebase.
    
    Change-Id: I76fb2fbcb9ca0654f2e5fd5d90bd62392165777c
    Signed-off-by: Vladimir Serbinenko <phcoder at gmail.com>
---
 src/Kconfig                 |   4 ++
 src/arch/x86/boot/acpi.c    | 113 +++++++++++++++++++++++++++++++++++++++++++-
 src/include/device/device.h |   6 +++
 3 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/src/Kconfig b/src/Kconfig
index 6b674ed..e1a02d4 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -462,6 +462,10 @@ config MAX_PIRQ_LINKS
 	  table specifies links greater than 4, pirq_route_irqs will not
 	  function properly, unless this variable is correctly set.
 
+config COLLABORATIVE_ACPI_TABLES
+	bool
+	default n
+
 #These Options are here to avoid "undefined" warnings.
 #The actual selection and help texts are in the following menu.
 
diff --git a/src/arch/x86/boot/acpi.c b/src/arch/x86/boot/acpi.c
index d76882a..28a6b9e 100644
--- a/src/arch/x86/boot/acpi.c
+++ b/src/arch/x86/boot/acpi.c
@@ -247,15 +247,17 @@ void acpi_create_mcfg(acpi_mcfg_t *mcfg)
 	header->checksum = acpi_checksum((void *)mcfg, header->length);
 }
 
+#if !CONFIG_COLLABORATIVE_ACPI_TABLES
 /*
  * This can be overridden by platform ACPI setup code, if it calls
  * acpi_create_ssdt_generator().
  */
 unsigned long __attribute__((weak)) acpi_fill_ssdt_generator(
-			unsigned long current, const char *oem_table_id)
+	unsigned long current, const char *oem_table_id)
 {
 	return current;
 }
+#endif
 
 void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
 {
@@ -273,7 +275,17 @@ void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
 	ssdt->length = sizeof(acpi_header_t);
 
 	acpigen_set_current((char *) current);
-	current = acpi_fill_ssdt_generator(current, oem_table_id);
+	{
+#if CONFIG_COLLABORATIVE_ACPI_TABLES
+		device_t dev;
+		for (dev = all_devices; dev; dev = dev->next)
+			if (dev->ops && dev->ops->acpi_fill_ssdt_generator) {
+				current = dev->ops->acpi_fill_ssdt_generator(current, oem_table_id);
+			}
+#else
+		current = acpi_fill_ssdt_generator(current, oem_table_id);
+#endif
+	}
 
 	/* (Re)calculate length and checksum. */
 	ssdt->length = current - (unsigned long)ssdt;
@@ -693,6 +705,103 @@ static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
 	return rsdp;
 }
 
+#if CONFIG_COLLABORATIVE_ACPI_TABLES
+
+extern const unsigned char AmlCode[];
+
+#define ALIGN_CURRENT current = (ALIGN(current, 16))
+unsigned long write_acpi_tables(unsigned long start)
+{
+	unsigned long current;
+	acpi_rsdp_t *rsdp;
+	acpi_rsdt_t *rsdt;
+	acpi_xsdt_t *xsdt;
+	acpi_fadt_t *fadt;
+	acpi_facs_t *facs;
+#if CONFIG_HAVE_ACPI_SLIC
+	acpi_header_t *slic;
+#endif
+	acpi_header_t *ssdt;
+	acpi_header_t *dsdt;
+	device_t dev;
+
+	current = start;
+
+	/* Align ACPI tables to 16byte */
+	ALIGN_CURRENT;
+
+	printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
+
+	/* We need at least an RSDP and an RSDT Table */
+	rsdp = (acpi_rsdp_t *) current;
+	current += sizeof(acpi_rsdp_t);
+	ALIGN_CURRENT;
+	rsdt = (acpi_rsdt_t *) current;
+	current += sizeof(acpi_rsdt_t);
+	ALIGN_CURRENT;
+	xsdt = (acpi_xsdt_t *) current;
+	current += sizeof(acpi_xsdt_t);
+	ALIGN_CURRENT;
+
+	/* clear all table memory */
+	memset((void *) start, 0, current - start);
+
+	acpi_write_rsdp(rsdp, rsdt, xsdt);
+	acpi_write_rsdt(rsdt);
+	acpi_write_xsdt(xsdt);
+
+	printk(BIOS_DEBUG, "ACPI:    * FACS\n");
+	facs = (acpi_facs_t *) current;
+	current += sizeof(acpi_facs_t);
+	ALIGN_CURRENT;
+	acpi_create_facs(facs);
+
+	printk(BIOS_DEBUG, "ACPI:    * DSDT\n");
+	dsdt = (acpi_header_t *) current;
+	memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
+	current += dsdt->length;
+	memcpy(dsdt, &AmlCode, dsdt->length);
+
+	ALIGN_CURRENT;
+
+	printk(BIOS_DEBUG, "ACPI:    * FADT\n");
+	fadt = (acpi_fadt_t *) current;
+	current += sizeof(acpi_fadt_t);
+	ALIGN_CURRENT;
+
+	acpi_create_fadt(fadt, facs, dsdt);
+	acpi_add_table(rsdp, fadt);
+
+#if CONFIG_HAVE_ACPI_SLIC
+	printk(BIOS_DEBUG, "ACPI:     * SLIC\n");
+	slic = (acpi_header_t *)current;
+	current += acpi_create_slic(current);
+	ALIGN_CURRENT;
+	acpi_add_table(rsdp, slic);
+#endif
+
+	printk(BIOS_DEBUG, "ACPI:     * SSDT\n");
+	ssdt = (acpi_header_t *)current;
+	acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
+	current += ssdt->length;
+	acpi_add_table(rsdp, ssdt);
+	ALIGN_CURRENT;
+
+	printk(BIOS_DEBUG, "current = %lx\n", current);
+
+	for (dev = all_devices; dev; dev = dev->next) {
+		if (dev->ops && dev->ops->write_acpi_tables) {
+			current = dev->ops->write_acpi_tables(current, rsdp);
+			ALIGN_CURRENT;
+		}
+	}
+
+	printk(BIOS_INFO, "ACPI: done.\n");
+	return current;
+}
+
+#endif
+
 static acpi_rsdp_t *rsdp;
 
 void *acpi_get_wakeup_rsdp(void)
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 19b5ea0..345212d 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -40,6 +40,7 @@ struct chip_operations {
 struct bus;
 
 struct smbios_type11;
+struct acpi_rsdp;
 
 struct device_operations {
 	void (*read_resources)(device_t dev);
@@ -56,6 +57,11 @@ struct device_operations {
 	int (*get_smbios_data)(device_t dev, int *handle, unsigned long *current);
 	void (*get_smbios_strings)(device_t dev, struct smbios_type11 *t);
 #endif
+#if CONFIG_GENERATE_ACPI_TABLES && CONFIG_COLLABORATIVE_ACPI_TABLES
+	unsigned long (*write_acpi_tables)(unsigned long start,  struct acpi_rsdp *rsdp);
+	unsigned long (*acpi_fill_ssdt_generator)(unsigned long current,
+						  const char *oem_table_id);
+#endif
 	const struct pci_operations *ops_pci;
 	const struct smbus_bus_operations *ops_smbus_bus;
 	const struct pci_bus_operations * (*ops_pci_bus)(device_t dev);



More information about the coreboot-gerrit mailing list