Implement ACPI in a per device 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> Reviewed-on: http://review.coreboot.org/6801 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com> Reviewed-by: Aaron Durbin <adurbin@google.com>
This commit is contained in:
parent
a2a906e47a
commit
2d7bd8a6eb
|
@ -462,6 +462,10 @@ config MAX_PIRQ_LINKS
|
||||||
table specifies links greater than 4, pirq_route_irqs will not
|
table specifies links greater than 4, pirq_route_irqs will not
|
||||||
function properly, unless this variable is correctly set.
|
function properly, unless this variable is correctly set.
|
||||||
|
|
||||||
|
config PER_DEVICE_ACPI_TABLES
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
|
||||||
#These Options are here to avoid "undefined" warnings.
|
#These Options are here to avoid "undefined" warnings.
|
||||||
#The actual selection and help texts are in the following menu.
|
#The actual selection and help texts are in the following menu.
|
||||||
|
|
||||||
|
|
|
@ -247,15 +247,17 @@ void acpi_create_mcfg(acpi_mcfg_t *mcfg)
|
||||||
header->checksum = acpi_checksum((void *)mcfg, header->length);
|
header->checksum = acpi_checksum((void *)mcfg, header->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES)
|
||||||
/*
|
/*
|
||||||
* This can be overridden by platform ACPI setup code, if it calls
|
* This can be overridden by platform ACPI setup code, if it calls
|
||||||
* acpi_create_ssdt_generator().
|
* acpi_create_ssdt_generator().
|
||||||
*/
|
*/
|
||||||
unsigned long __attribute__((weak)) acpi_fill_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;
|
return current;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
|
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);
|
ssdt->length = sizeof(acpi_header_t);
|
||||||
|
|
||||||
acpigen_set_current((char *) current);
|
acpigen_set_current((char *) current);
|
||||||
current = acpi_fill_ssdt_generator(current, oem_table_id);
|
{
|
||||||
|
#if IS_ENABLED(CONFIG_PER_DEVICE_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. */
|
/* (Re)calculate length and checksum. */
|
||||||
ssdt->length = current - (unsigned long)ssdt;
|
ssdt->length = current - (unsigned long)ssdt;
|
||||||
|
@ -455,6 +467,24 @@ void acpi_create_hpet(acpi_hpet_t *hpet)
|
||||||
header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
|
header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long acpi_write_hpet(unsigned long current, acpi_rsdp_t *rsdp)
|
||||||
|
{
|
||||||
|
acpi_hpet_t *hpet;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We explicitly add these tables later on:
|
||||||
|
*/
|
||||||
|
printk(BIOS_DEBUG, "ACPI: * HPET\n");
|
||||||
|
|
||||||
|
hpet = (acpi_hpet_t *) current;
|
||||||
|
current += sizeof(acpi_hpet_t);
|
||||||
|
current = ALIGN(current, 16);
|
||||||
|
acpi_create_hpet(hpet);
|
||||||
|
acpi_add_table(rsdp, hpet);
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
void acpi_create_facs(acpi_facs_t *facs)
|
void acpi_create_facs(acpi_facs_t *facs)
|
||||||
{
|
{
|
||||||
memset((void *)facs, 0, sizeof(acpi_facs_t));
|
memset((void *)facs, 0, sizeof(acpi_facs_t));
|
||||||
|
@ -620,6 +650,123 @@ void acpi_write_hest(acpi_hest_t *hest)
|
||||||
header->checksum = acpi_checksum((void *)hest, header->length);
|
header->checksum = acpi_checksum((void *)hest, header->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_PER_DEVICE_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;
|
||||||
|
acpi_mcfg_t *mcfg;
|
||||||
|
acpi_madt_t *madt;
|
||||||
|
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, "ACPI: * MCFG\n");
|
||||||
|
mcfg = (acpi_mcfg_t *) current;
|
||||||
|
acpi_create_mcfg(mcfg);
|
||||||
|
if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
|
||||||
|
current += mcfg->header.length;
|
||||||
|
ALIGN_CURRENT;
|
||||||
|
acpi_add_table(rsdp, mcfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
printk(BIOS_DEBUG, "ACPI: * MADT\n");
|
||||||
|
|
||||||
|
madt = (acpi_madt_t *) current;
|
||||||
|
acpi_create_madt(madt);
|
||||||
|
if (madt->header.length > sizeof(acpi_madt_t)) {
|
||||||
|
current+=madt->header.length;
|
||||||
|
acpi_add_table(rsdp,madt);
|
||||||
|
}
|
||||||
|
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
|
#if CONFIG_HAVE_ACPI_RESUME
|
||||||
void acpi_resume(void *wake_vec)
|
void acpi_resume(void *wake_vec)
|
||||||
{
|
{
|
||||||
|
|
|
@ -490,8 +490,10 @@ unsigned long acpi_fill_madt(unsigned long current);
|
||||||
unsigned long acpi_fill_mcfg(unsigned long current);
|
unsigned long acpi_fill_mcfg(unsigned long current);
|
||||||
unsigned long acpi_fill_srat(unsigned long current);
|
unsigned long acpi_fill_srat(unsigned long current);
|
||||||
unsigned long acpi_fill_slit(unsigned long current);
|
unsigned long acpi_fill_slit(unsigned long current);
|
||||||
|
#if !IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES)
|
||||||
unsigned long acpi_fill_ssdt_generator(unsigned long current,
|
unsigned long acpi_fill_ssdt_generator(unsigned long current,
|
||||||
const char *oem_table_id);
|
const char *oem_table_id);
|
||||||
|
#endif
|
||||||
void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id);
|
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);
|
void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs, void *dsdt);
|
||||||
|
|
||||||
|
@ -526,6 +528,7 @@ void acpi_create_srat(acpi_srat_t *srat);
|
||||||
void acpi_create_slit(acpi_slit_t *slit);
|
void acpi_create_slit(acpi_slit_t *slit);
|
||||||
|
|
||||||
void acpi_create_hpet(acpi_hpet_t *hpet);
|
void acpi_create_hpet(acpi_hpet_t *hpet);
|
||||||
|
unsigned long acpi_write_hpet(unsigned long start, acpi_rsdp_t *rsdp);
|
||||||
|
|
||||||
void acpi_create_mcfg(acpi_mcfg_t *mcfg);
|
void acpi_create_mcfg(acpi_mcfg_t *mcfg);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ struct chip_operations {
|
||||||
struct bus;
|
struct bus;
|
||||||
|
|
||||||
struct smbios_type11;
|
struct smbios_type11;
|
||||||
|
struct acpi_rsdp;
|
||||||
|
|
||||||
struct device_operations {
|
struct device_operations {
|
||||||
void (*read_resources)(device_t dev);
|
void (*read_resources)(device_t dev);
|
||||||
|
@ -55,6 +56,11 @@ struct device_operations {
|
||||||
#if CONFIG_GENERATE_SMBIOS_TABLES
|
#if CONFIG_GENERATE_SMBIOS_TABLES
|
||||||
int (*get_smbios_data)(device_t dev, int *handle, unsigned long *current);
|
int (*get_smbios_data)(device_t dev, int *handle, unsigned long *current);
|
||||||
void (*get_smbios_strings)(device_t dev, struct smbios_type11 *t);
|
void (*get_smbios_strings)(device_t dev, struct smbios_type11 *t);
|
||||||
|
#endif
|
||||||
|
#if IS_ENABLED(CONFIG_GENERATE_ACPI_TABLES) && IS_ENABLED(CONFIG_PER_DEVICE_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
|
#endif
|
||||||
const struct pci_operations *ops_pci;
|
const struct pci_operations *ops_pci;
|
||||||
const struct smbus_bus_operations *ops_smbus_bus;
|
const struct smbus_bus_operations *ops_smbus_bus;
|
||||||
|
|
Loading…
Reference in New Issue