summaryrefslogtreecommitdiff
path: root/src/arch/i386/boot
diff options
context:
space:
mode:
authorRudolf Marek <r.marek@assembler.cz>2009-02-01 18:35:15 +0000
committerRudolf Marek <r.marek@assembler.cz>2009-02-01 18:35:15 +0000
commit293b5f52253ec0e5edb38e9f7113afc7e8f8ba6e (patch)
treed0ab38cd89f3ceace9ee3de1cddd6bb5d9acea1a /src/arch/i386/boot
parent1c49bc9744c2e9044ddd1c8d20a1728f57eda85c (diff)
downloadcoreboot-293b5f52253ec0e5edb38e9f7113afc7e8f8ba6e.tar.xz
Following patch adds dynamic ACPI AML code generator which can be used to
generate run-time ACPI ASL code. Moreover it demonstrates its use on Asus M2V-MX SE where the SSDT table is generated by new function k8acpi_write_vars (technically similar to update_ssdt). But lot of nicer. x Signed-off-by: Rudolf Marek <r.marek@assembler.cz> Acked-by: Peter Stuge <peter@stuge.se> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3925 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src/arch/i386/boot')
-rw-r--r--src/arch/i386/boot/Config.lb2
-rw-r--r--src/arch/i386/boot/acpi.c29
-rw-r--r--src/arch/i386/boot/acpigen.c138
3 files changed, 168 insertions, 1 deletions
diff --git a/src/arch/i386/boot/Config.lb b/src/arch/i386/boot/Config.lb
index bacd1b0181..6526a2f3f6 100644
--- a/src/arch/i386/boot/Config.lb
+++ b/src/arch/i386/boot/Config.lb
@@ -13,5 +13,5 @@ object pirq_routing.o
end
if HAVE_ACPI_TABLES
object acpi.o
+object acpigen.o
end
-
diff --git a/src/arch/i386/boot/acpi.c b/src/arch/i386/boot/acpi.c
index 4c21231467..40fdf3d368 100644
--- a/src/arch/i386/boot/acpi.c
+++ b/src/arch/i386/boot/acpi.c
@@ -24,6 +24,7 @@
#include <console/console.h>
#include <string.h>
#include <arch/acpi.h>
+#include <arch/acpigen.h>
#include <device/pci.h>
u8 acpi_checksum(u8 *table, u32 length)
@@ -181,6 +182,34 @@ void acpi_create_mcfg(acpi_mcfg_t *mcfg)
header->checksum = acpi_checksum((void *)mcfg, header->length);
}
+/* this can be overriden by platform ACPI setup code,
+ if it calls acpi_create_ssdt_generator */
+unsigned long __attribute__((weak)) acpi_fill_ssdt_generator(unsigned long current,
+ char *oem_table_id) {
+ return current;
+}
+
+void acpi_create_ssdt_generator(acpi_header_t *ssdt, char *oem_table_id)
+{
+ unsigned long current=(unsigned long)ssdt+sizeof(acpi_header_t);
+ memset((void *)ssdt, 0, sizeof(acpi_header_t));
+ memcpy(&ssdt->signature, SSDT_NAME, 4);
+ ssdt->revision = 2;
+ memcpy(&ssdt->oem_id, OEM_ID, 6);
+ memcpy(&ssdt->oem_table_id, oem_table_id, 8);
+ ssdt->oem_revision = 42;
+ memcpy(&ssdt->asl_compiler_id, "GENAML", 4);
+ ssdt->asl_compiler_revision = 42;
+ ssdt->length = sizeof(acpi_header_t);
+
+ acpigen_set_current((unsigned char *) current);
+ current = acpi_fill_ssdt_generator(current, oem_table_id);
+
+ /* recalculate length */
+ ssdt->length = current - (unsigned long)ssdt;
+ ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
+}
+
int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
{
lapic->type=0;
diff --git a/src/arch/i386/boot/acpigen.c b/src/arch/i386/boot/acpigen.c
new file mode 100644
index 0000000000..203f5a0f3b
--- /dev/null
+++ b/src/arch/i386/boot/acpigen.c
@@ -0,0 +1,138 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* how many nesting we support */
+#define ACPIGEN_LENSTACK_SIZE 10
+
+/* if you need to change this, change the acpigen_write_f and
+ acpigen_patch_len */
+
+#define ACPIGEN_MAXLEN 0xfff
+
+#include <string.h>
+#include <arch/acpigen.h>
+#include <console/console.h>
+
+static char *gencurrent;
+
+char *len_stack[ACPIGEN_LENSTACK_SIZE];
+int ltop = 0;
+
+static int acpigen_write_len_f()
+{
+ ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1))
+ len_stack[ltop++] = gencurrent;
+ acpigen_emit_byte(0);
+ acpigen_emit_byte(0);
+ return 2;
+}
+
+void acpigen_patch_len(int len)
+{
+ ASSERT(len <= ACPIGEN_MAXLEN)
+ ASSERT(ltop > 0)
+ char *p = len_stack[--ltop];
+ /* generate store length for 0xfff max */
+ p[0] = (0x40 | (len & 0xf));
+ p[1] = (len >> 4 & 0xff);
+
+}
+
+void acpigen_set_current(char *curr) {
+ gencurrent = curr;
+}
+
+char *acpigen_get_current(void) {
+ return gencurrent;
+}
+
+int acpigen_emit_byte(unsigned char b)
+{
+ (*gencurrent++) = b;
+ return 1;
+}
+
+int acpigen_write_package(int nr_el)
+{
+ int len;
+ /* package op */
+ acpigen_emit_byte(0x12);
+ len = acpigen_write_len_f();
+ acpigen_emit_byte(nr_el);
+ return len + 2;
+}
+
+int acpigen_write_byte(unsigned int data)
+{
+ /* byte op */
+ acpigen_emit_byte(0xa);
+ acpigen_emit_byte(data & 0xff);
+ return 2;
+}
+
+int acpigen_write_dword(unsigned int data)
+{
+ /* dword op */
+ acpigen_emit_byte(0xc);
+ acpigen_emit_byte(data & 0xff);
+ acpigen_emit_byte((data >> 8) & 0xff);
+ acpigen_emit_byte((data >> 16) & 0xff);
+ acpigen_emit_byte((data >> 24) & 0xff);
+ return 5;
+}
+
+int acpigen_write_name_byte(char *name, uint8_t val) {
+ int len;
+ len = acpigen_write_name(name);
+ len += acpigen_write_byte(val);
+ return len;
+}
+
+int acpigen_write_name_dword(char *name, uint32_t val) {
+ int len;
+ len = acpigen_write_name(name);
+ len += acpigen_write_dword(val);
+ return len;
+}
+
+int acpigen_emit_stream(char *data, int size) {
+ int i;
+ for (i = 0; i < size; i++) {
+ acpigen_emit_byte(data[i]);
+ }
+ return size;
+}
+
+int acpigen_write_name(char *name)
+{
+ int len = strlen(name);
+ /* name op */
+ acpigen_emit_byte(0x8);
+ acpigen_emit_stream(name, len);
+ return len + 1;
+}
+
+int acpigen_write_scope(char *name)
+{
+ int len;
+ /* scope op */
+ acpigen_emit_byte(0x10);
+ len = acpigen_write_len_f();
+ return len + acpigen_emit_stream(name, strlen(name)) + 1;
+}