[syslinux:master] acpi: Initial stuff to find madt
syslinux-bot for Erwan Velu
erwan.velu at free.fr
Sun Feb 6 14:06:29 PST 2011
Commit-ID: 7533ef22b8c3ee2f3a556c223201c6d0ee99d103
Gitweb: http://syslinux.zytor.com/commit/7533ef22b8c3ee2f3a556c223201c6d0ee99d103
Author: Erwan Velu <erwan.velu at free.fr>
AuthorDate: Mon, 30 Nov 2009 17:09:20 +0100
Committer: Erwan Velu <erwan.velu at free.fr>
CommitDate: Fri, 4 Dec 2009 10:19:00 +0100
acpi: Initial stuff to find madt
Impact: adding madt stuff
Trying to add some madt stuff
---
com32/gplinclude/acpi/acpi.h | 47 +++++++++++++++++++
com32/gpllib/Makefile | 2 +-
com32/gpllib/acpi/acpi.c | 104 ++++++++++++++++++++++++++++++++++++++++++
com32/hdt/hdt-cli.c | 7 +++
4 files changed, 159 insertions(+), 1 deletions(-)
diff --git a/com32/gplinclude/acpi/acpi.h b/com32/gplinclude/acpi/acpi.h
new file mode 100644
index 0000000..c93ace2
--- /dev/null
+++ b/com32/gplinclude/acpi/acpi.h
@@ -0,0 +1,47 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2006 Erwan Velu - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ * Boston MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+#ifndef ACPI_H
+#define ACPI_H
+#include <inttypes.h>
+#include <stdbool.h>
+
+enum { ACPI_FOUND, ENO_ACPI, MADT_FOUND, ENO_MADT};
+
+#define WORD(x) (uint16_t)(*(const uint16_t *)(x))
+#define DWORD(x) (uint32_t)(*(const uint32_t *)(x))
+#define QWORD(x) (*(const uint64_t *)(x))
+
+typedef struct {
+ uint8_t signature[4];
+ uint32_t len;
+ uint8_t revision;
+ uint8_t checksum;
+ uint8_t oem_id[6];
+ uint8_t oem_table_id[8];
+ uint8_t oem_revision[4];
+ uint8_t creator_id[4];
+ uint8_t creator_revision[4];
+} s_madt;
+
+typedef struct {
+ s_madt madt;
+ uint64_t base_address;
+ uint64_t size;
+ bool madt_valid;
+ bool acpi_valid;
+} s_acpi;
+
+int search_acpi(s_acpi *acpi);
+int search_madt(s_acpi *acpi);
+void print_madt(s_acpi *acpi);
+#endif
diff --git a/com32/gpllib/Makefile b/com32/gpllib/Makefile
index fa866db..a174061 100644
--- a/com32/gpllib/Makefile
+++ b/com32/gpllib/Makefile
@@ -8,7 +8,7 @@ include ../lib/MCONFIG
REQFLAGS += -I../gplinclude
-GPLDIRS := . disk dmi vpd
+GPLDIRS := . disk dmi vpd acpi
LIBOBJS := $(foreach dir,$(GPLDIRS),$(patsubst %.c,%.o,$(wildcard $(dir)/*.c)))
BINDIR = /usr/bin
diff --git a/com32/gpllib/acpi/acpi.c b/com32/gpllib/acpi/acpi.c
new file mode 100644
index 0000000..dba8052
--- /dev/null
+++ b/com32/gpllib/acpi/acpi.c
@@ -0,0 +1,104 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2006 Erwan Velu - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * -----------------------------------------------------------------------
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#include "acpi/acpi.h"
+
+void init_acpi(s_acpi *acpi)
+{
+ acpi->acpi_valid=false;
+ acpi->madt_valid=false;
+}
+
+int search_acpi(s_acpi *acpi)
+{
+ init_acpi(acpi);
+ struct e820entry map[E820MAX];
+ struct e820entry nm[E820MAX];
+ int count = 0;
+
+ detect_memory_e820(map, E820MAX, &count);
+ /* Clean up, adjust and copy the BIOS-supplied E820-map. */
+ int nr = sanitize_e820_map(map, nm, count);
+ for (int i = 0; i < nr; i++) {
+ /* Type is ACPI Reclaim */
+ if (nm[i].type == E820_ACPI) {
+ printf("ACPI Table Found\n");
+ acpi->base_address=nm[i].addr;
+ acpi->size=nm[i].size;
+ acpi->acpi_valid=true;
+ return ACPI_FOUND;
+ }
+ }
+ return -ENO_ACPI;
+}
+
+int search_madt(s_acpi *acpi)
+{
+ uint8_t *p, *q;
+ int found = 0;
+
+ if (!acpi->acpi_valid) return -ENO_ACPI;
+
+ p = (uint64_t *) acpi->base_address; /* The start address to look at the dmi table */
+ /* The anchor-string is 16-bytes aligned */
+ for (q = p; q < p + acpi->size; q += 1) {
+ /* To validate the presence of SMBIOS:
+ * + the overall checksum must be correct
+ * + the intermediate anchor-string must be _DMI_
+ * + the intermediate checksum must be correct
+ */
+ if (memcmp(q, "APIC", 4) == 0) {
+ /* Do not return, legacy_decode will need to be called
+ * on the intermediate structure to get the table length
+ * and address
+ */
+ memcpy(&acpi->madt,q,sizeof(acpi->madt));
+ acpi->madt_valid=true;
+ return MADT_FOUND;
+ }
+ }
+ return -ENO_MADT;
+}
+
+void print_madt(s_acpi *acpi)
+{
+ if (!acpi->madt_valid) return;
+ printf("MADT\n");
+ printf(" signature : %s\n",acpi->madt.signature);
+ printf(" length : %d\n",acpi->madt.len);
+ printf(" revision : %d\n",acpi->madt.revision);
+ printf(" checksum : %d\n",acpi->madt.checksum);
+ printf(" oem id : %s\n",acpi->madt.oem_id);
+ printf(" oem table id : %s\n",acpi->madt.oem_table_id);
+ printf(" oem revision : %s\n",acpi->madt.oem_revision);
+ printf(" oem creator id : %s\n",acpi->madt.creator_id);
+ printf(" oem creator rev: %s\n",acpi->madt.creator_revision);
+}
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index 69a2b61..3aa9c38 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <syslinux/config.h>
#include <getkey.h>
+#include <acpi/acpi.h>
#include "hdt-cli.h"
#include "hdt-common.h"
@@ -825,6 +826,12 @@ void start_cli_mode(struct s_hardware *hardware)
reset_prompt();
+ s_acpi acpi;
+ search_acpi(&acpi);
+ if (search_madt(&acpi) == MADT_FOUND) {
+ print_madt(&acpi);
+ };
+
while (hdt_cli.mode != EXIT_MODE) {
/* Display the cursor */
More information about the Syslinux-commits
mailing list