Attention is currently required from: Lance Zhao, Tim Wawrzynczak.
Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/76143?usp=email )
Change subject: acpi/acpi.c: Move ACPI header creation to a function ......................................................................
acpi/acpi.c: Move ACPI header creation to a function
This reduces boilerplate. One functional difference is that SSDT no longer has oem_revision set to 42.
Signed-off-by: Arthur Heymans arthur@aheymans.xyz Change-Id: Id2e54d61970294e028a61ba86c07c5482784e307 --- M src/acpi/acpi.c 1 file changed, 47 insertions(+), 239 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/43/76143/1
diff --git a/src/acpi/acpi.c b/src/acpi/acpi.c index 885aa27..03ae283 100644 --- a/src/acpi/acpi.c +++ b/src/acpi/acpi.c @@ -110,6 +110,25 @@ i + 1, entries_num, rsdt->header.length); }
+static enum cb_err acpi_fill_header(acpi_header_t *header, const char name[4], + enum acpi_tables table, uint32_t size) +{ + if (!header) + return CB_ERR; + + /* Fill out header fields. */ + memcpy(header->signature, name, 4); + memcpy(header->oem_id, OEM_ID, 6); + memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); + memcpy(header->asl_compiler_id, ASLC, 4); + + header->asl_compiler_revision = asl_revision; + header->revision = get_acpi_table_revision(table); + header->length = size; + + return CB_SUCCESS; +} + static int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end) { @@ -343,19 +362,9 @@ acpi_madt_t *madt = (acpi_madt_t *)header; unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
- if (!header) + if (acpi_fill_header(header, "APIC", MADT, sizeof(acpi_madt_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "APIC", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_madt_t); - header->revision = get_acpi_table_revision(MADT); - madt->lapic_addr = cpu_get_lapic_addr(); if (CONFIG(ACPI_HAVE_PCAT_8259)) madt->flags |= 1; @@ -387,19 +396,10 @@ acpi_mcfg_t *mcfg = (acpi_mcfg_t *)header; unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
- if (!header) + + if (acpi_fill_header(header, "MCFG", MCFG, sizeof(acpi_mcfg_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "MCFG", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_mcfg_t); - header->revision = get_acpi_table_revision(MCFG); - if (CONFIG(ECAM_MMCONF_SUPPORT)) current = acpi_fill_mcfg(current);
@@ -445,19 +445,9 @@ if (!lasa) return;
- if (!header) + if (acpi_fill_header(header, "TCPA", TCPA, sizeof(acpi_tcpa_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "TCPA", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_tcpa_t); - header->revision = get_acpi_table_revision(TCPA); - tcpa->platform_class = 0; tcpa->laml = tcpa_log_len; tcpa->lasa = (uintptr_t)lasa; @@ -505,19 +495,9 @@ if (!lasa) tpm2_log_len = 0;
- if (!header) + if (acpi_fill_header(header, "TPM2", TPM2, sizeof(acpi_tpm2_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "TPM2", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_tpm2_t); - header->revision = get_acpi_table_revision(TPM2); - /* Hard to detect for coreboot. Just set it to 0 */ tpm2->platform_class = 0; if (CONFIG(CRB_TPM)) { @@ -563,16 +543,8 @@ { unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
- memset((void *)ssdt, 0, sizeof(acpi_header_t)); - - memcpy(&ssdt->signature, "SSDT", 4); - ssdt->revision = get_acpi_table_revision(SSDT); - memcpy(&ssdt->oem_id, OEM_ID, 6); - memcpy(&ssdt->oem_table_id, ACPI_TABLE_CREATOR, 8); - ssdt->oem_revision = 42; - memcpy(&ssdt->asl_compiler_id, ASLC, 4); - ssdt->asl_compiler_revision = asl_revision; - ssdt->length = sizeof(acpi_header_t); + if (acpi_fill_header(ssdt, "SSDT", SSDT, sizeof(acpi_header_t)) != CB_SUCCESS) + return;
acpigen_set_current((char *)current);
@@ -659,19 +631,9 @@
memset((void *)srat, 0, sizeof(acpi_srat_t));
- if (!header) + if (acpi_fill_header(header, "SRAT", SRAT, sizeof(acpi_srat_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "SRAT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_srat_t); - header->revision = get_acpi_table_revision(SRAT); - srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
current = acpi_fill_srat(current); @@ -745,19 +707,9 @@
memset((void *)cedt, 0, sizeof(acpi_cedt_t));
- if (!header) + if (acpi_fill_header(header, "CEDT", CEDT, sizeof(acpi_cedt_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "CEDT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_cedt_t); - header->revision = get_acpi_table_revision(CEDT); - current = acpi_fill_cedt(current);
/* (Re)calculate length and checksum. */ @@ -790,19 +742,9 @@
memset((void *)hmat, 0, sizeof(acpi_hmat_t));
- if (!header) + if (acpi_fill_header(header, "HMAT", HMAT, sizeof(acpi_hmat_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "HMAT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_hmat_t); - header->revision = get_acpi_table_revision(HMAT); - current = acpi_fill_hmat(current);
/* (Re)calculate length and checksum. */ @@ -818,19 +760,9 @@
memset((void *)dmar, 0, sizeof(acpi_dmar_t));
- if (!header) + if (acpi_fill_header(header, "DMAR", DMAR, sizeof(acpi_dmar_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "DMAR", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_dmar_t); - header->revision = get_acpi_table_revision(DMAR); - dmar->host_address_width = cpu_phys_address_size() - 1; dmar->flags = flags;
@@ -1009,19 +941,9 @@
memset((void *)slit, 0, sizeof(acpi_slit_t));
- if (!header) + if (acpi_fill_header(header, "SLIT", SLIT, sizeof(acpi_slit_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "SLIT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_slit_t); - header->revision = get_acpi_table_revision(SLIT); - current = acpi_fill_slit(current);
/* (Re)calculate length and checksum. */ @@ -1037,19 +959,9 @@
memset((void *)hpet, 0, sizeof(acpi_hpet_t));
- if (!header) + if (acpi_fill_header(header, "HPET", HPET, sizeof(acpi_hpet_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "HPET", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_hpet_t); - header->revision = get_acpi_table_revision(HPET); - /* Fill out HPET address. */ addr->space_id = ACPI_ADDRESS_SPACE_MEMORY; addr->bit_width = 64; @@ -1192,15 +1104,9 @@
memset((void *)einj, 0, sizeof(*einj));
- /* Fill out header fields. */ - memcpy(header->signature, "EINJ", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); + if (acpi_fill_header(header, "EINJ", EINJ, sizeof(acpi_einj_t)) != CB_SUCCESS) + return;
- header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_einj_t); - header->revision = 1; inj_header->einj_header_size = sizeof(acpi_injection_header_t); inj_header->entry_count = ACTION_COUNT;
@@ -1220,18 +1126,9 @@
memset((void *)vfct, 0, sizeof(acpi_vfct_t));
- if (!header) + if (acpi_fill_header(header, "VFCT", VFCT, sizeof(acpi_vfct_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "VFCT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->revision = get_acpi_table_revision(VFCT); - current = acpi_fill_vfct(device, vfct, current);
/* If no BIOS image, return with header->length == 0. */ @@ -1255,15 +1152,8 @@ acpi_header_t *header = &(spmi->header); memset((void *)spmi, 0, sizeof(struct acpi_spmi));
- /* Fill out header fields. */ - memcpy(header->signature, "SPMI", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(struct acpi_spmi); - header->revision = get_acpi_table_revision(SPMI); + if (acpi_fill_header(header, "SPMI", SPMI, sizeof(struct acpi_spmi)) != CB_SUCCESS) + return;
spmi->reserved = 1;
@@ -1303,19 +1193,9 @@
memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
- if (!header) + if (acpi_fill_header(header, "IVRS", IVRS, sizeof(acpi_ivrs_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "IVRS", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_ivrs_t); - header->revision = get_acpi_table_revision(IVRS); - current = acpi_fill_ivrs(ivrs, current);
/* (Re)calculate length and checksum. */ @@ -1332,19 +1212,9 @@
memset((void *)crat, 0, sizeof(struct acpi_crat_header));
- if (!header) + if (acpi_fill_header(header, "CRAT", CRAT, sizeof(struct acpi_crat_header)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "CRAT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(struct acpi_crat_header); - header->revision = get_acpi_table_revision(CRAT); - current = acpi_fill_crat(crat, current);
/* (Re)calculate length and checksum. */ @@ -1389,16 +1259,9 @@ memset(dbg2, 0, sizeof(acpi_dbg2_header_t)); header = &(dbg2->header);
- if (!header) + if (acpi_fill_header(header, "DBG2", DBG2, sizeof(acpi_dbg2_header_t)) != CB_SUCCESS) return;
- header->revision = get_acpi_table_revision(DBG2); - memcpy(header->signature, "DBG2", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - header->asl_compiler_revision = asl_revision; - /* One debug device defined */ dbg2->devices_offset = sizeof(acpi_dbg2_header_t); dbg2->devices_count = 1; @@ -1511,19 +1374,9 @@ { acpi_header_t *header = &(rsdt->header);
- if (!header) + if (acpi_fill_header(header, "RSDT", RSDT, sizeof(acpi_rsdt_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "RSDT", 4); - memcpy(header->oem_id, oem_id, 6); - memcpy(header->oem_table_id, oem_table_id, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_rsdt_t); - header->revision = get_acpi_table_revision(RSDT); - /* Entries are filled in later, we come with an empty set. */
/* Fix checksum. */ @@ -1534,19 +1387,9 @@ { acpi_header_t *header = &(xsdt->header);
- if (!header) + if (acpi_fill_header(header, "XSDT", XSDT, sizeof(acpi_xsdt_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "XSDT", 4); - memcpy(header->oem_id, oem_id, 6); - memcpy(header->oem_table_id, oem_table_id, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->length = sizeof(acpi_xsdt_t); - header->revision = get_acpi_table_revision(XSDT); - /* Entries are filled in later, we come with an empty set. */
/* Fix checksum. */ @@ -1651,17 +1494,9 @@
memset(hest, 0, sizeof(acpi_hest_t));
- if (!header) + if (acpi_fill_header(header, "HEST", HEST, sizeof(acpi_hest_t)) != CB_SUCCESS) return;
- memcpy(header->signature, "HEST", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - header->asl_compiler_revision = asl_revision; - header->length += sizeof(acpi_hest_t); - header->revision = get_acpi_table_revision(HEST); - acpi_fill_hest(hest);
/* Calculate checksums. */ @@ -1676,21 +1511,13 @@
acpi_bert_t *bert = (acpi_bert_t *)header;
- if (!header) - return; - void *region; size_t size; if (acpi_soc_get_bert_region(®ion, &size) != CB_SUCCESS) return;
- memcpy(header->signature, "BERT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - header->asl_compiler_revision = asl_revision; - header->length += sizeof(acpi_bert_t); - header->revision = get_acpi_table_revision(BERT); + if (acpi_fill_header(header, "BERT", BERT, sizeof(acpi_bert_t)) != CB_SUCCESS) + return;
bert->error_region = (uintptr_t)region; bert->region_length = (size_t)size; @@ -1706,17 +1533,9 @@ acpi_fadt_t *fadt = (acpi_fadt_t *)header; acpi_facs_t *facs = (acpi_facs_t *)(*(acpi_facs_t **)arg1);
- if (!header) + if (acpi_fill_header(header, "FACP", FADT, sizeof(acpi_fadt_t)) != CB_SUCCESS) return;
- memcpy(header->signature, "FACP", 4); - header->length = sizeof(acpi_fadt_t); - header->revision = get_acpi_table_revision(FADT); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - header->asl_compiler_revision = asl_revision; - fadt->FADT_MinorVersion = get_acpi_fadt_minor_version(); fadt->firmware_ctrl = (unsigned long)facs; fadt->x_firmware_ctl_l = (unsigned long)facs; @@ -1757,20 +1576,9 @@ acpi_lpit_t *lpit = (acpi_lpit_t *)header; unsigned long current = (unsigned long)lpit + sizeof(acpi_lpit_t);
- if (!header) + if (acpi_fill_header(header, "LPIT", LPIT, sizeof(acpi_lpit_t)) != CB_SUCCESS) return;
- /* Fill out header fields. */ - memcpy(header->signature, "LPIT", 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); - memcpy(header->asl_compiler_id, ASLC, 4); - - header->asl_compiler_revision = asl_revision; - header->revision = get_acpi_table_revision(LPIT); - header->oem_revision = 42; - header->length = sizeof(acpi_lpit_t); - current = acpi_fill_lpit(current);
/* (Re)calculate length. */