ron minnich has uploaded this change for review.

View Change

acpi: add a function to read a table and verify it

coreboot can currently read some ACPI tables from cbfs.
There is a fair amount of repeated code. Add a function
which can take a file name, and a table name, which
reads the file in, verifies its size, and its name,
returns a pointer to it if it is OK, NULL otherwise.

Show one use of the function: if a madt is found in
cbfs, use it instead of generating tables.

Over time, this code might replace other instances
of the copied-pasted code use for, e.g., the SLIT.

One such use of this code is on platforms where an
ACPI table has been supplied and it it not yet possible
to generate one.

Tested-by: Ronald G. Minnich <rminnich@google.com>

Change-Id: Id5e82eb0a82555b7763107e2a1e2a529a0c1b11f
Signed-off-by: Ronald G. Minnich <rminnich@google.com>
---
M src/acpi/acpi.c
1 file changed, 36 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/88/41388/1
diff --git a/src/acpi/acpi.c b/src/acpi/acpi.c
index 8bf4b49..f1d2e78 100644
--- a/src/acpi/acpi.c
+++ b/src/acpi/acpi.c
@@ -39,6 +39,34 @@
}

/**
+ * Read in a named table, and verify its properties
+ */
+acpi_header_t *acpi_read_table(const char *filename, const char *tablename)
+{
+ acpi_header_t *file;
+ size_t table_size;
+
+ file = cbfs_boot_map_with_leak(filename, CBFS_TYPE_RAW, &table_size);
+ if (!file) {
+ printk(BIOS_ERR, "No %s file for table %s\n", filename, tablename);
+ return NULL;
+ }
+ if (file->length > table_size) {
+ printk(BIOS_ERR, "Invalid %s file: file length(%d) > table_size(%ld)\n", filename, file->length, table_size);
+ return NULL;
+ }
+ if (file->length < sizeof(acpi_header_t)) {
+ printk(BIOS_ERR, "Invalid %s file: file length(%d) < table_size(%ld)\n", filename, file->length, table_size);
+ return NULL;
+ }
+ if (memcmp(file->signature, tablename, 4) != 0) {
+ printk(BIOS_ERR, "Invalid %s file, signature(%s) does not match %s\n", filename, file->signature, tablename);
+ return NULL;
+ }
+ return file;
+}
+
+/**
* Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
* and checksum.
*/
@@ -231,9 +259,16 @@

void acpi_create_madt(acpi_madt_t *madt)
{
- acpi_header_t *header = &(madt->header);
+ acpi_header_t *header, *file;
unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);

+ file = acpi_read_table(CONFIG_CBFS_PREFIX "/madt.aml", "APIC");
+ if (file) {
+ memmove(madt, file, file->length);
+ return;
+ }
+
+ header = &(madt->header);
memset((void *)madt, 0, sizeof(acpi_madt_t));

if (!header)

To view, visit change 41388. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Id5e82eb0a82555b7763107e2a1e2a529a0c1b11f
Gerrit-Change-Number: 41388
Gerrit-PatchSet: 1
Gerrit-Owner: ron minnich <rminnich@gmail.com>
Gerrit-MessageType: newchange