Al Stone 067c49
diff -Naur acpica-unix2-20150515/generate/unix/acpidump/Makefile acpica-unix2-20150515.devmem/generate/unix/acpidump/Makefile
Al Stone 067c49
--- acpica-unix2-20150515/generate/unix/acpidump/Makefile	2015-05-15 17:49:17.000000000 -0600
Al Stone 067c49
+++ acpica-unix2-20150515.devmem/generate/unix/acpidump/Makefile	2015-06-02 15:00:31.813746336 -0600
Al Stone 067c49
@@ -67,10 +67,17 @@
Al Stone 067c49
 OBJECTS += \
Al Stone 067c49
 	$(OBJDIR)/osbsdtbl.o
Al Stone 067c49
 else
Al Stone 067c49
+
Al Stone 067c49
+ifeq ($(NO_DEV_MEM), true)
Al Stone 067c49
+OBJECTS += \
Al Stone 067c49
+	$(OBJDIR)/oslinuxtbl_nodevmem.o
Al Stone 067c49
+else
Al Stone 067c49
 OBJECTS += \
Al Stone 067c49
 	$(OBJDIR)/oslinuxtbl.o
Al Stone 067c49
 endif
Al Stone 067c49
 
Al Stone 067c49
+endif
Al Stone 067c49
+
Al Stone 067c49
 #
Al Stone 067c49
 # Flags specific to acpidump
Al Stone 067c49
 #
Al Stone 067c49
diff -Naur acpica-unix2-20150515/generate/unix/Makefile.config acpica-unix2-20150515.devmem/generate/unix/Makefile.config
Al Stone 067c49
--- acpica-unix2-20150515/generate/unix/Makefile.config	2015-06-03 14:57:30.328724317 -0600
Al Stone 067c49
+++ acpica-unix2-20150515.devmem/generate/unix/Makefile.config	2015-06-02 15:03:53.727560100 -0600
Al Stone 067c49
@@ -49,6 +49,7 @@
Al Stone 067c49
 LINKPROG =   $(CC) $(OBJECTS) -o $(PROG) $(LDFLAGS) $(OPT_LDFLAGS)
Al Stone 067c49
 PREFIX ?=    /usr
Al Stone 067c49
 INSTALLDIR = $(PREFIX)/bin
Al Stone 067c49
+UNAME_M := $(shell uname -m)
Al Stone 067c49
 UNAME_S := $(shell uname -s)
Al Stone 067c49
 
Al Stone 067c49
 #
Al Stone 067c49
@@ -70,6 +71,12 @@
Al Stone 067c49
 HOST =       _NetBSD
Al Stone 067c49
 endif
Al Stone 067c49
 
Al Stone 067c49
+ifeq ($(UNAME_S), Linux)
Al Stone 067c49
+ifeq ($(UNAME_M), aarch64)
Al Stone 067c49
+NO_DEV_MEM ?= true
Al Stone 067c49
+endif
Al Stone 067c49
+endif
Al Stone 067c49
+
Al Stone 067c49
 ifeq ($(HOST), _APPLE)
Al Stone 067c49
 INSTALL  =   cp
Al Stone 067c49
 INSTALLFLAGS ?= -f
Al Stone 067c49
diff -Naur acpica-unix2-20150515/source/os_specific/service_layers/oslinuxtbl_nodevmem.c acpica-unix2-20150515.devmem/source/os_specific/service_layers/oslinuxtbl_nodevmem.c
Al Stone 067c49
--- acpica-unix2-20150515/source/os_specific/service_layers/oslinuxtbl_nodevmem.c	1969-12-31 17:00:00.000000000 -0700
Al Stone 067c49
+++ acpica-unix2-20150515.devmem/source/os_specific/service_layers/oslinuxtbl_nodevmem.c	2015-06-02 16:14:38.088031027 -0600
Al Stone 067c49
@@ -0,0 +1,734 @@
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * Module Name: oslinuxtbl_nodevmem - Linux OSL for obtaining ACPI tables
Al Stone 067c49
+ *                                    that assumes you cannot use /dev/mem
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+#include "acpidump.h"
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+#define _COMPONENT          ACPI_OS_SERVICES
Al Stone 067c49
+        ACPI_MODULE_NAME    ("oslinuxtbl_nodevmem")
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+#ifndef PATH_MAX
Al Stone 067c49
+#define PATH_MAX 256
Al Stone 067c49
+#endif
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/* List of information about obtained ACPI tables */
Al Stone 067c49
+
Al Stone 067c49
+typedef struct osl_table_info
Al Stone 067c49
+{
Al Stone 067c49
+    struct osl_table_info   *Next;
Al Stone 067c49
+    UINT32                  Instance;
Al Stone 067c49
+    char                    Signature[ACPI_NAME_SIZE];
Al Stone 067c49
+
Al Stone 067c49
+} OSL_TABLE_INFO;
Al Stone 067c49
+
Al Stone 067c49
+/* Local prototypes */
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslTableInitialize (
Al Stone 067c49
+    void);
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslTableNameFromFile (
Al Stone 067c49
+    char                    *Filename,
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    UINT32                  *Instance);
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslAddTableToList (
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    UINT32                  Instance);
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslReadTableFromFile (
Al Stone 067c49
+    char                    *Filename,
Al Stone 067c49
+    ACPI_SIZE               FileOffset,
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    ACPI_TABLE_HEADER       **Table);
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslListAcpiTables (
Al Stone 067c49
+    char                    *Directory);
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslGetAcpiTable (
Al Stone 067c49
+    char                    *Pathname,
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    UINT32                  Instance,
Al Stone 067c49
+    ACPI_TABLE_HEADER       **Table,
Al Stone 067c49
+    ACPI_PHYSICAL_ADDRESS   *Address);
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslGetLastStatus (
Al Stone 067c49
+    ACPI_STATUS             DefaultStatus);
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/* File locations */
Al Stone 067c49
+
Al Stone 067c49
+#define DYNAMIC_TABLE_DIR   "/sys/firmware/acpi/tables/dynamic"
Al Stone 067c49
+#define STATIC_TABLE_DIR    "/sys/firmware/acpi/tables"
Al Stone 067c49
+
Al Stone 067c49
+/* Should we get dynamically loaded SSDTs from DYNAMIC_TABLE_DIR? */
Al Stone 067c49
+
Al Stone 067c49
+UINT8                   Gbl_DumpDynamicTables = TRUE;
Al Stone 067c49
+
Al Stone 067c49
+/* Initialization flags */
Al Stone 067c49
+
Al Stone 067c49
+UINT8                   Gbl_TableListInitialized = FALSE;
Al Stone 067c49
+
Al Stone 067c49
+/* Revision of RSD PTR */
Al Stone 067c49
+
Al Stone 067c49
+UINT8                   Gbl_Revision = 0;
Al Stone 067c49
+
Al Stone 067c49
+OSL_TABLE_INFO          *Gbl_TableListHead = NULL;
Al Stone 067c49
+UINT32                  Gbl_TableCount = 0;
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    OslGetLastStatus
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  DefaultStatus   - Default error status to return
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Converted from errno.
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Get last errno and conver it to ACPI_STATUS.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslGetLastStatus (
Al Stone 067c49
+    ACPI_STATUS             DefaultStatus)
Al Stone 067c49
+{
Al Stone 067c49
+
Al Stone 067c49
+    switch (errno)
Al Stone 067c49
+    {
Al Stone 067c49
+    case EACCES:
Al Stone 067c49
+    case EPERM:
Al Stone 067c49
+
Al Stone 067c49
+        return (AE_ACCESS);
Al Stone 067c49
+
Al Stone 067c49
+    case ENOENT:
Al Stone 067c49
+
Al Stone 067c49
+        return (AE_NOT_FOUND);
Al Stone 067c49
+
Al Stone 067c49
+    case ENOMEM:
Al Stone 067c49
+
Al Stone 067c49
+        return (AE_NO_MEMORY);
Al Stone 067c49
+
Al Stone 067c49
+    default:
Al Stone 067c49
+
Al Stone 067c49
+        return (DefaultStatus);
Al Stone 067c49
+    }
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    AcpiOsGetTableByAddress
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Address         - Physical address of the ACPI table
Al Stone 067c49
+ *              Table           - Where a pointer to the table is returned
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Table buffer is returned if AE_OK.
Al Stone 067c49
+ *              AE_NOT_FOUND: A valid table was not found at the address
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Get an ACPI table via a physical memory address.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+ACPI_STATUS
Al Stone 067c49
+AcpiOsGetTableByAddress (
Al Stone 067c49
+    ACPI_PHYSICAL_ADDRESS   Address,
Al Stone 067c49
+    ACPI_TABLE_HEADER       **Table)
Al Stone 067c49
+{
Al Stone 067c49
+    /*
Al Stone 067c49
+     * If this source file is being used, there is no reliable access
Al Stone 067c49
+     * to /dev/mem on this system.  Hence, we cannot retrieve a table
Al Stone 067c49
+     * by address at all and will always return AE_NOT_FOUND.
Al Stone 067c49
+     */
Al Stone 067c49
+
Al Stone 067c49
+    return AE_NOT_FOUND;
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    AcpiOsGetTableByName
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Signature       - ACPI Signature for desired table. Must be
Al Stone 067c49
+ *                                a null terminated 4-character string.
Al Stone 067c49
+ *              Instance        - Multiple table support for SSDT/UEFI (0...n)
Al Stone 067c49
+ *                                Must be 0 for other tables.
Al Stone 067c49
+ *              Table           - Where a pointer to the table is returned
Al Stone 067c49
+ *              Address         - Where the table physical address is returned
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Table buffer and physical address returned if AE_OK.
Al Stone 067c49
+ *              AE_LIMIT: Instance is beyond valid limit
Al Stone 067c49
+ *              AE_NOT_FOUND: A table with the signature was not found
Al Stone 067c49
+ *
Al Stone 067c49
+ * NOTE:        Assumes the input signature is uppercase.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+ACPI_STATUS
Al Stone 067c49
+AcpiOsGetTableByName (
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    UINT32                  Instance,
Al Stone 067c49
+    ACPI_TABLE_HEADER       **Table,
Al Stone 067c49
+    ACPI_PHYSICAL_ADDRESS   *Address)
Al Stone 067c49
+{
Al Stone 067c49
+    ACPI_STATUS             Status;
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+    /* Get main ACPI tables from memory on first invocation of this function */
Al Stone 067c49
+
Al Stone 067c49
+    Status = OslTableInitialize ();
Al Stone 067c49
+    if (ACPI_FAILURE (Status))
Al Stone 067c49
+    {
Al Stone 067c49
+        return (Status);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Attempt to get the table from the static directory */
Al Stone 067c49
+
Al Stone 067c49
+    Status = OslGetAcpiTable (STATIC_TABLE_DIR, Signature,
Al Stone 067c49
+        Instance, Table, Address);
Al Stone 067c49
+
Al Stone 067c49
+    if (ACPI_FAILURE (Status) && Status == AE_LIMIT)
Al Stone 067c49
+    {
Al Stone 067c49
+        if (Gbl_DumpDynamicTables)
Al Stone 067c49
+        {
Al Stone 067c49
+            /* Attempt to get a dynamic table */
Al Stone 067c49
+
Al Stone 067c49
+            Status = OslGetAcpiTable (DYNAMIC_TABLE_DIR, Signature,
Al Stone 067c49
+                Instance, Table, Address);
Al Stone 067c49
+        }
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    return (Status);
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    OslAddTableToList
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Signature       - Table signature
Al Stone 067c49
+ *              Instance        - Table instance
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Successfully added if AE_OK.
Al Stone 067c49
+ *              AE_NO_MEMORY: Memory allocation error
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Insert a table structure into OSL table list.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslAddTableToList (
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    UINT32                  Instance)
Al Stone 067c49
+{
Al Stone 067c49
+    OSL_TABLE_INFO          *NewInfo;
Al Stone 067c49
+    OSL_TABLE_INFO          *Next;
Al Stone 067c49
+    UINT32                  NextInstance = 0;
Al Stone 067c49
+    BOOLEAN                 Found = FALSE;
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+    NewInfo = calloc (1, sizeof (OSL_TABLE_INFO));
Al Stone 067c49
+    if (!NewInfo)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (AE_NO_MEMORY);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    ACPI_MOVE_NAME (NewInfo->Signature, Signature);
Al Stone 067c49
+
Al Stone 067c49
+    if (!Gbl_TableListHead)
Al Stone 067c49
+    {
Al Stone 067c49
+        Gbl_TableListHead = NewInfo;
Al Stone 067c49
+    }
Al Stone 067c49
+    else
Al Stone 067c49
+    {
Al Stone 067c49
+        Next = Gbl_TableListHead;
Al Stone 067c49
+        while (1)
Al Stone 067c49
+        {
Al Stone 067c49
+            if (ACPI_COMPARE_NAME (Next->Signature, Signature))
Al Stone 067c49
+            {
Al Stone 067c49
+                if (Next->Instance == Instance)
Al Stone 067c49
+                {
Al Stone 067c49
+                    Found = TRUE;
Al Stone 067c49
+                }
Al Stone 067c49
+                if (Next->Instance >= NextInstance)
Al Stone 067c49
+                {
Al Stone 067c49
+                    NextInstance = Next->Instance + 1;
Al Stone 067c49
+                }
Al Stone 067c49
+            }
Al Stone 067c49
+
Al Stone 067c49
+            if (!Next->Next)
Al Stone 067c49
+            {
Al Stone 067c49
+                break;
Al Stone 067c49
+            }
Al Stone 067c49
+            Next = Next->Next;
Al Stone 067c49
+        }
Al Stone 067c49
+        Next->Next = NewInfo;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    if (Found)
Al Stone 067c49
+    {
Al Stone 067c49
+        if (Instance)
Al Stone 067c49
+        {
Al Stone 067c49
+            fprintf (stderr,
Al Stone 067c49
+                "%4.4s: Warning unmatched table instance %d, expected %d\n",
Al Stone 067c49
+                Signature, Instance, NextInstance);
Al Stone 067c49
+        }
Al Stone 067c49
+        Instance = NextInstance;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    NewInfo->Instance = Instance;
Al Stone 067c49
+    Gbl_TableCount++;
Al Stone 067c49
+
Al Stone 067c49
+    return (AE_OK);
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    AcpiOsGetTableByIndex
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Index           - Which table to get
Al Stone 067c49
+ *              Table           - Where a pointer to the table is returned
Al Stone 067c49
+ *              Instance        - Where a pointer to the table instance no. is
Al Stone 067c49
+ *                                returned
Al Stone 067c49
+ *              Address         - Where the table physical address is returned
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Table buffer and physical address returned if AE_OK.
Al Stone 067c49
+ *              AE_LIMIT: Index is beyond valid limit
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Get an ACPI table via an index value (0 through n). Returns
Al Stone 067c49
+ *              AE_LIMIT when an invalid index is reached. Index is not
Al Stone 067c49
+ *              necessarily an index into the RSDT/XSDT.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+ACPI_STATUS
Al Stone 067c49
+AcpiOsGetTableByIndex (
Al Stone 067c49
+    UINT32                  Index,
Al Stone 067c49
+    ACPI_TABLE_HEADER       **Table,
Al Stone 067c49
+    UINT32                  *Instance,
Al Stone 067c49
+    ACPI_PHYSICAL_ADDRESS   *Address)
Al Stone 067c49
+{
Al Stone 067c49
+    OSL_TABLE_INFO          *Info;
Al Stone 067c49
+    ACPI_STATUS             Status;
Al Stone 067c49
+    UINT32                  i;
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+    /* Get main ACPI tables from memory on first invocation of this function */
Al Stone 067c49
+
Al Stone 067c49
+    Status = OslTableInitialize ();
Al Stone 067c49
+    if (ACPI_FAILURE (Status))
Al Stone 067c49
+    {
Al Stone 067c49
+        return (Status);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Validate Index */
Al Stone 067c49
+
Al Stone 067c49
+    if (Index >= Gbl_TableCount)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (AE_LIMIT);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Point to the table list entry specified by the Index argument */
Al Stone 067c49
+
Al Stone 067c49
+    Info = Gbl_TableListHead;
Al Stone 067c49
+    for (i = 0; i < Index; i++)
Al Stone 067c49
+    {
Al Stone 067c49
+        Info = Info->Next;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Now we can just get the table via the signature */
Al Stone 067c49
+
Al Stone 067c49
+    Status = AcpiOsGetTableByName (Info->Signature, Info->Instance,
Al Stone 067c49
+        Table, Address);
Al Stone 067c49
+
Al Stone 067c49
+    if (ACPI_SUCCESS (Status))
Al Stone 067c49
+    {
Al Stone 067c49
+        *Instance = Info->Instance;
Al Stone 067c49
+    }
Al Stone 067c49
+    return (Status);
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    OslTableInitialize
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  None
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Initialize ACPI table data. Get and store main ACPI tables to
Al Stone 067c49
+ *              local variables. Main ACPI tables include RSDT, FADT, RSDT,
Al Stone 067c49
+ *              and/or XSDT.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslTableInitialize (
Al Stone 067c49
+    void)
Al Stone 067c49
+{
Al Stone 067c49
+    ACPI_STATUS             Status;
Al Stone 067c49
+
Al Stone 067c49
+    if (Gbl_TableListInitialized)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (AE_OK);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Add all tables found in the static directory */
Al Stone 067c49
+
Al Stone 067c49
+    Status = OslListAcpiTables (STATIC_TABLE_DIR);
Al Stone 067c49
+    if (ACPI_FAILURE (Status))
Al Stone 067c49
+    {
Al Stone 067c49
+        return (Status);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    if (Gbl_DumpDynamicTables)
Al Stone 067c49
+    {
Al Stone 067c49
+        /* Add all dynamically loaded tables in the dynamic directory */
Al Stone 067c49
+
Al Stone 067c49
+        Status = OslListAcpiTables (DYNAMIC_TABLE_DIR);
Al Stone 067c49
+        if (ACPI_FAILURE (Status))
Al Stone 067c49
+        {
Al Stone 067c49
+            return (Status);
Al Stone 067c49
+        }
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    Gbl_TableListInitialized = TRUE;
Al Stone 067c49
+    return (AE_OK);
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    OslListAcpiTables
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Directory           - Directory that contains the tables
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Table list is initialized if AE_OK.
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Add ACPI tables to the table list from a directory.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslListAcpiTables (
Al Stone 067c49
+    char                    *Directory)
Al Stone 067c49
+{
Al Stone 067c49
+    void                    *TableDir;
Al Stone 067c49
+    UINT32                  Instance;
Al Stone 067c49
+    char                    TempName[ACPI_NAME_SIZE];
Al Stone 067c49
+    char                    *Filename;
Al Stone 067c49
+    ACPI_STATUS             Status = AE_OK;
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+    /* Open the requested directory */
Al Stone 067c49
+
Al Stone 067c49
+    TableDir = AcpiOsOpenDirectory (Directory, "*", REQUEST_FILE_ONLY);
Al Stone 067c49
+    if (!TableDir)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (OslGetLastStatus (AE_NOT_FOUND));
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Examine all entries in this directory */
Al Stone 067c49
+
Al Stone 067c49
+    while ((Filename = AcpiOsGetNextFilename (TableDir)))
Al Stone 067c49
+    {
Al Stone 067c49
+        /* Extract table name and instance number */
Al Stone 067c49
+
Al Stone 067c49
+        Status = OslTableNameFromFile (Filename, TempName, &Instance);
Al Stone 067c49
+
Al Stone 067c49
+        /* Ignore meaningless files */
Al Stone 067c49
+
Al Stone 067c49
+        if (ACPI_FAILURE (Status))
Al Stone 067c49
+        {
Al Stone 067c49
+            continue;
Al Stone 067c49
+        }
Al Stone 067c49
+
Al Stone 067c49
+        /* Add new info node to global table list */
Al Stone 067c49
+
Al Stone 067c49
+        Status = OslAddTableToList (TempName, Instance);
Al Stone 067c49
+        if (ACPI_FAILURE (Status))
Al Stone 067c49
+        {
Al Stone 067c49
+            break;
Al Stone 067c49
+        }
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    AcpiOsCloseDirectory (TableDir);
Al Stone 067c49
+    return (Status);
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    OslTableNameFromFile
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Filename            - File that contains the desired table
Al Stone 067c49
+ *              Signature           - Pointer to 4-character buffer to store
Al Stone 067c49
+ *                                    extracted table signature.
Al Stone 067c49
+ *              Instance            - Pointer to integer to store extracted
Al Stone 067c49
+ *                                    table instance number.
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Table name is extracted if AE_OK.
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Extract table signature and instance number from a table file
Al Stone 067c49
+ *              name.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslTableNameFromFile (
Al Stone 067c49
+    char                    *Filename,
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    UINT32                  *Instance)
Al Stone 067c49
+{
Al Stone 067c49
+
Al Stone 067c49
+    /* Ignore meaningless files */
Al Stone 067c49
+
Al Stone 067c49
+    if (strlen (Filename) < ACPI_NAME_SIZE)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (AE_BAD_SIGNATURE);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Extract instance number */
Al Stone 067c49
+
Al Stone 067c49
+    if (isdigit ((int) Filename[ACPI_NAME_SIZE]))
Al Stone 067c49
+    {
Al Stone 067c49
+        sscanf (&Filename[ACPI_NAME_SIZE], "%u", Instance);
Al Stone 067c49
+    }
Al Stone 067c49
+    else if (strlen (Filename) != ACPI_NAME_SIZE)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (AE_BAD_SIGNATURE);
Al Stone 067c49
+    }
Al Stone 067c49
+    else
Al Stone 067c49
+    {
Al Stone 067c49
+        *Instance = 0;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Extract signature */
Al Stone 067c49
+
Al Stone 067c49
+    ACPI_MOVE_NAME (Signature, Filename);
Al Stone 067c49
+    return (AE_OK);
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    OslReadTableFromFile
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Filename            - File that contains the desired table
Al Stone 067c49
+ *              FileOffset          - Offset of the table in file
Al Stone 067c49
+ *              Signature           - Optional ACPI Signature for desired table.
Al Stone 067c49
+ *                                    A null terminated 4-character string.
Al Stone 067c49
+ *              Table               - Where a pointer to the table is returned
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Table buffer is returned if AE_OK.
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Read a ACPI table from a file.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslReadTableFromFile (
Al Stone 067c49
+    char                    *Filename,
Al Stone 067c49
+    ACPI_SIZE               FileOffset,
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    ACPI_TABLE_HEADER       **Table)
Al Stone 067c49
+{
Al Stone 067c49
+    FILE                    *TableFile;
Al Stone 067c49
+    ACPI_TABLE_HEADER       Header;
Al Stone 067c49
+    ACPI_TABLE_HEADER       *LocalTable = NULL;
Al Stone 067c49
+    UINT32                  TableLength;
Al Stone 067c49
+    INT32                   Count;
Al Stone 067c49
+    ACPI_STATUS             Status = AE_OK;
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+    /* Open the file */
Al Stone 067c49
+
Al Stone 067c49
+    TableFile = fopen (Filename, "rb");
Al Stone 067c49
+    if (TableFile == NULL)
Al Stone 067c49
+    {
Al Stone 067c49
+        fprintf (stderr, "Could not open table file: %s\n", Filename);
Al Stone 067c49
+        return (OslGetLastStatus (AE_NOT_FOUND));
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    fseek (TableFile, FileOffset, SEEK_SET);
Al Stone 067c49
+
Al Stone 067c49
+    /* Read the Table header to get the table length */
Al Stone 067c49
+
Al Stone 067c49
+    Count = fread (&Header, 1, sizeof (ACPI_TABLE_HEADER), TableFile);
Al Stone 067c49
+    if (Count != sizeof (ACPI_TABLE_HEADER))
Al Stone 067c49
+    {
Al Stone 067c49
+        fprintf (stderr, "Could not read table header: %s\n", Filename);
Al Stone 067c49
+        Status = AE_BAD_HEADER;
Al Stone 067c49
+        goto Exit;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* If signature is specified, it must match the table */
Al Stone 067c49
+
Al Stone 067c49
+    if (Signature)
Al Stone 067c49
+    {
Al Stone 067c49
+        if (ACPI_VALIDATE_RSDP_SIG (Signature))
Al Stone 067c49
+        {
Al Stone 067c49
+            if (!ACPI_VALIDATE_RSDP_SIG (Header.Signature)) {
Al Stone 067c49
+                fprintf (stderr, "Incorrect RSDP signature: found %8.8s\n",
Al Stone 067c49
+                    Header.Signature);
Al Stone 067c49
+                Status = AE_BAD_SIGNATURE;
Al Stone 067c49
+                goto Exit;
Al Stone 067c49
+            }
Al Stone 067c49
+        }
Al Stone 067c49
+        else if (!ACPI_COMPARE_NAME (Signature, Header.Signature))
Al Stone 067c49
+        {
Al Stone 067c49
+            fprintf (stderr, "Incorrect signature: Expecting %4.4s, found %4.4s\n",
Al Stone 067c49
+                Signature, Header.Signature);
Al Stone 067c49
+            Status = AE_BAD_SIGNATURE;
Al Stone 067c49
+            goto Exit;
Al Stone 067c49
+        }
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    TableLength = ApGetTableLength (&Header);
Al Stone 067c49
+    if (TableLength == 0)
Al Stone 067c49
+    {
Al Stone 067c49
+        Status = AE_BAD_HEADER;
Al Stone 067c49
+        goto Exit;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Read the entire table into a local buffer */
Al Stone 067c49
+
Al Stone 067c49
+    LocalTable = calloc (1, TableLength);
Al Stone 067c49
+    if (!LocalTable)
Al Stone 067c49
+    {
Al Stone 067c49
+        fprintf (stderr,
Al Stone 067c49
+            "%4.4s: Could not allocate buffer for table of length %X\n",
Al Stone 067c49
+            Header.Signature, TableLength);
Al Stone 067c49
+        Status = AE_NO_MEMORY;
Al Stone 067c49
+        goto Exit;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    fseek (TableFile, FileOffset, SEEK_SET);
Al Stone 067c49
+
Al Stone 067c49
+    Count = fread (LocalTable, 1, TableLength, TableFile);
Al Stone 067c49
+    if (Count != TableLength)
Al Stone 067c49
+    {
Al Stone 067c49
+        fprintf (stderr, "%4.4s: Could not read table content\n",
Al Stone 067c49
+            Header.Signature);
Al Stone 067c49
+        Status = AE_INVALID_TABLE_LENGTH;
Al Stone 067c49
+        goto Exit;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Validate checksum */
Al Stone 067c49
+
Al Stone 067c49
+    (void) ApIsValidChecksum (LocalTable);
Al Stone 067c49
+
Al Stone 067c49
+Exit:
Al Stone 067c49
+    fclose (TableFile);
Al Stone 067c49
+    *Table = LocalTable;
Al Stone 067c49
+    return (Status);
Al Stone 067c49
+}
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+/******************************************************************************
Al Stone 067c49
+ *
Al Stone 067c49
+ * FUNCTION:    OslGetAcpiTable
Al Stone 067c49
+ *
Al Stone 067c49
+ * PARAMETERS:  Pathname        - Directory to find Linux ACPI table
Al Stone 067c49
+ *              Signature       - ACPI Signature for desired table. Must be
Al Stone 067c49
+ *                                a null terminated 4-character string.
Al Stone 067c49
+ *              Instance        - Multiple table support for SSDT/UEFI (0...n)
Al Stone 067c49
+ *                                Must be 0 for other tables.
Al Stone 067c49
+ *              Table           - Where a pointer to the table is returned
Al Stone 067c49
+ *              Address         - Where the table physical address is returned
Al Stone 067c49
+ *
Al Stone 067c49
+ * RETURN:      Status; Table buffer is returned if AE_OK.
Al Stone 067c49
+ *              AE_LIMIT: Instance is beyond valid limit
Al Stone 067c49
+ *              AE_NOT_FOUND: A table with the signature was not found
Al Stone 067c49
+ *
Al Stone 067c49
+ * DESCRIPTION: Get an OS ACPI table.
Al Stone 067c49
+ *
Al Stone 067c49
+ *****************************************************************************/
Al Stone 067c49
+
Al Stone 067c49
+static ACPI_STATUS
Al Stone 067c49
+OslGetAcpiTable (
Al Stone 067c49
+    char                    *Pathname,
Al Stone 067c49
+    char                    *Signature,
Al Stone 067c49
+    UINT32                  Instance,
Al Stone 067c49
+    ACPI_TABLE_HEADER       **Table,
Al Stone 067c49
+    ACPI_PHYSICAL_ADDRESS   *Address)
Al Stone 067c49
+{
Al Stone 067c49
+    void                    *TableDir;
Al Stone 067c49
+    UINT32                  CurrentInstance = 0;
Al Stone 067c49
+    char                    TempName[ACPI_NAME_SIZE];
Al Stone 067c49
+    char                    TableFilename[PATH_MAX];
Al Stone 067c49
+    char                    *Filename;
Al Stone 067c49
+    ACPI_STATUS             Status;
Al Stone 067c49
+
Al Stone 067c49
+
Al Stone 067c49
+    /* Open the directory for ACPI tables */
Al Stone 067c49
+
Al Stone 067c49
+    TableDir = AcpiOsOpenDirectory (Pathname, "*", REQUEST_FILE_ONLY);
Al Stone 067c49
+    if (!TableDir)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (OslGetLastStatus (AE_NOT_FOUND));
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* Attempt to find the table in the directory */
Al Stone 067c49
+
Al Stone 067c49
+    while ((Filename = AcpiOsGetNextFilename (TableDir)))
Al Stone 067c49
+    {
Al Stone 067c49
+        /* Ignore meaningless files */
Al Stone 067c49
+
Al Stone 067c49
+        if (!ACPI_COMPARE_NAME (Filename, Signature))
Al Stone 067c49
+        {
Al Stone 067c49
+            continue;
Al Stone 067c49
+        }
Al Stone 067c49
+
Al Stone 067c49
+        /* Extract table name and instance number */
Al Stone 067c49
+
Al Stone 067c49
+        Status = OslTableNameFromFile (Filename, TempName, &CurrentInstance);
Al Stone 067c49
+
Al Stone 067c49
+        /* Ignore meaningless files */
Al Stone 067c49
+
Al Stone 067c49
+        if (ACPI_FAILURE (Status) || CurrentInstance != Instance)
Al Stone 067c49
+        {
Al Stone 067c49
+            continue;
Al Stone 067c49
+        }
Al Stone 067c49
+
Al Stone 067c49
+        /* Create the table pathname */
Al Stone 067c49
+
Al Stone 067c49
+        if (Instance != 0)
Al Stone 067c49
+        {
Al Stone 067c49
+            sprintf (TableFilename, "%s/%4.4s%d", Pathname, TempName, Instance);
Al Stone 067c49
+        }
Al Stone 067c49
+        else
Al Stone 067c49
+        {
Al Stone 067c49
+            sprintf (TableFilename, "%s/%4.4s", Pathname, TempName);
Al Stone 067c49
+        }
Al Stone 067c49
+        break;
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    AcpiOsCloseDirectory (TableDir);
Al Stone 067c49
+
Al Stone 067c49
+    if (!Filename)
Al Stone 067c49
+    {
Al Stone 067c49
+        return (AE_LIMIT);
Al Stone 067c49
+    }
Al Stone 067c49
+
Al Stone 067c49
+    /* There is no physical address saved for ACPI tables, use zero */
Al Stone 067c49
+
Al Stone 067c49
+    *Address = 0;
Al Stone 067c49
+    Status = OslReadTableFromFile (TableFilename, 0, NULL, Table);
Al Stone 067c49
+
Al Stone 067c49
+    return (Status);
Al Stone 067c49
+}