Vladimir Serbinenko (phcoder@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6801
-gerrit
commit d28ddb45dff3a2470457666f0ca1028da900c272 Author: Vladimir Serbinenko phcoder@gmail.com Date: Sat Aug 30 19:28:05 2014 +0200
Implement ACPI in a 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@gmail.com --- src/Kconfig | 4 ++ src/arch/x86/boot/acpi.c | 112 ++++++++++++++++++++++++++++++++++++++- src/arch/x86/include/arch/acpi.h | 2 + src/include/device/device.h | 6 +++ 4 files changed, 122 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..e897872 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; @@ -620,6 +632,102 @@ void acpi_write_hest(acpi_hest_t *hest) header->checksum = acpi_checksum((void *)hest, header->length); }
+#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 + #if CONFIG_HAVE_ACPI_RESUME void acpi_resume(void *wake_vec) { diff --git a/src/arch/x86/include/arch/acpi.h b/src/arch/x86/include/arch/acpi.h index 9039a90..0682c98 100644 --- a/src/arch/x86/include/arch/acpi.h +++ b/src/arch/x86/include/arch/acpi.h @@ -490,8 +490,10 @@ unsigned long acpi_fill_madt(unsigned long current); unsigned long acpi_fill_mcfg(unsigned long current); unsigned long acpi_fill_srat(unsigned long current); unsigned long acpi_fill_slit(unsigned long current); +#if !CONFIG_COLLABORATIVE_ACPI_TABLES unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id); +#endif void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id); void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt);
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);