summaryrefslogtreecommitdiffstats
path: root/sys/contrib/dev/acpica/os_specific
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2015-04-04 10:17:51 +0000
committerdim <dim@FreeBSD.org>2015-04-04 10:17:51 +0000
commit441da571d47ec226c5c1799fe6e9dad14931a813 (patch)
tree03ae73b5fa8cee569039a08677ba8f5db4c7032b /sys/contrib/dev/acpica/os_specific
parenta66c38928305566ab81042d4242432a649ec767f (diff)
downloadFreeBSD-src-441da571d47ec226c5c1799fe6e9dad14931a813.zip
FreeBSD-src-441da571d47ec226c5c1799fe6e9dad14931a813.tar.gz
MFC r272444 (by jkim):
Merge ACPICA 20140926. MFC r278970 (by jkim): Merge ACPICA 20141107 and 20150204. Approved by: jkim Relnotes: yes
Diffstat (limited to 'sys/contrib/dev/acpica/os_specific')
-rw-r--r--sys/contrib/dev/acpica/os_specific/service_layers/oslibcfs.c255
-rw-r--r--sys/contrib/dev/acpica/os_specific/service_layers/osunixxf.c236
2 files changed, 464 insertions, 27 deletions
diff --git a/sys/contrib/dev/acpica/os_specific/service_layers/oslibcfs.c b/sys/contrib/dev/acpica/os_specific/service_layers/oslibcfs.c
new file mode 100644
index 0000000..c24cca4
--- /dev/null
+++ b/sys/contrib/dev/acpica/os_specific/service_layers/oslibcfs.c
@@ -0,0 +1,255 @@
+/******************************************************************************
+ *
+ * Module Name: oslibcfs - C library OSL for file I/O
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, Intel Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ * of any contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <contrib/dev/acpica/include/acpi.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#define _COMPONENT ACPI_OS_SERVICES
+ ACPI_MODULE_NAME ("oslibcfs")
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiOsOpenFile
+ *
+ * PARAMETERS: Path - File path
+ * Modes - File operation type
+ *
+ * RETURN: File descriptor.
+ *
+ * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing
+ * (ACPI_FILE_WRITING).
+ *
+ ******************************************************************************/
+
+ACPI_FILE
+AcpiOsOpenFile (
+ const char *Path,
+ UINT8 Modes)
+{
+ ACPI_FILE File;
+ UINT32 i = 0;
+ char ModesStr[4];
+
+
+ if (Modes & ACPI_FILE_READING)
+ {
+ ModesStr[i++] = 'r';
+ }
+ if (Modes & ACPI_FILE_WRITING)
+ {
+ ModesStr[i++] = 'w';
+ }
+ if (Modes & ACPI_FILE_BINARY)
+ {
+ ModesStr[i++] = 'b';
+ }
+
+ ModesStr[i++] = '\0';
+
+ File = fopen (Path, ModesStr);
+ if (!File)
+ {
+ perror ("Could not open file");
+ }
+
+ return (File);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiOsCloseFile
+ *
+ * PARAMETERS: File - An open file descriptor
+ *
+ * RETURN: None.
+ *
+ * DESCRIPTION: Close a file opened via AcpiOsOpenFile.
+ *
+ ******************************************************************************/
+
+void
+AcpiOsCloseFile (
+ ACPI_FILE File)
+{
+ fclose (File);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiOsReadFile
+ *
+ * PARAMETERS: File - An open file descriptor
+ * Buffer - Data buffer
+ * Size - Data block size
+ * Count - Number of data blocks
+ *
+ * RETURN: Number of bytes actually read.
+ *
+ * DESCRIPTION: Read from a file.
+ *
+ ******************************************************************************/
+
+int
+AcpiOsReadFile (
+ ACPI_FILE File,
+ void *Buffer,
+ ACPI_SIZE Size,
+ ACPI_SIZE Count)
+{
+ int Length;
+
+
+ Length = fread (Buffer, Size, Count, File);
+ if (Length < 0)
+ {
+ perror ("Error reading file");
+ }
+
+ return (Length);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiOsWriteFile
+ *
+ * PARAMETERS: File - An open file descriptor
+ * Buffer - Data buffer
+ * Size - Data block size
+ * Count - Number of data blocks
+ *
+ * RETURN: Number of bytes actually written.
+ *
+ * DESCRIPTION: Write to a file.
+ *
+ ******************************************************************************/
+
+int
+AcpiOsWriteFile (
+ ACPI_FILE File,
+ void *Buffer,
+ ACPI_SIZE Size,
+ ACPI_SIZE Count)
+{
+ int Length;
+
+
+ Length = fwrite (Buffer, Size, Count, File);
+ if (Length < 0)
+ {
+ perror ("Error writing file");
+ }
+
+ return (Length);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiOsGetFileOffset
+ *
+ * PARAMETERS: File - An open file descriptor
+ *
+ * RETURN: Current file pointer position.
+ *
+ * DESCRIPTION: Get current file offset.
+ *
+ ******************************************************************************/
+
+long
+AcpiOsGetFileOffset (
+ ACPI_FILE File)
+{
+ long Offset;
+
+
+ Offset = ftell (File);
+ return (Offset);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiOsSetFileOffset
+ *
+ * PARAMETERS: File - An open file descriptor
+ * Offset - New file offset
+ * From - From begin/end of file
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Set current file offset.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiOsSetFileOffset (
+ ACPI_FILE File,
+ long Offset,
+ UINT8 From)
+{
+ int Ret = 0;
+
+
+ if (From == ACPI_FILE_BEGIN)
+ {
+ Ret = fseek (File, Offset, SEEK_SET);
+ }
+ if (From == ACPI_FILE_END)
+ {
+ Ret = fseek (File, Offset, SEEK_END);
+ }
+
+ if (Ret < 0)
+ {
+ return (AE_ERROR);
+ }
+ else
+ {
+ return (AE_OK);
+ }
+}
diff --git a/sys/contrib/dev/acpica/os_specific/service_layers/osunixxf.c b/sys/contrib/dev/acpica/os_specific/service_layers/osunixxf.c
index 31bb471..fcd5fbc 100644
--- a/sys/contrib/dev/acpica/os_specific/service_layers/osunixxf.c
+++ b/sys/contrib/dev/acpica/os_specific/service_layers/osunixxf.c
@@ -5,7 +5,7 @@
*****************************************************************************/
/*
- * Copyright (C) 2000 - 2013, Intel Corp.
+ * Copyright (C) 2000 - 2015, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,6 @@
* POSSIBILITY OF SUCH DAMAGES.
*/
-
/*
* These interfaces are required in order to compile the ASL compiler and the
* various ACPICA tools under Linux or other Unix-like system.
@@ -65,16 +64,11 @@
ACPI_MODULE_NAME ("osunixxf")
-extern FILE *AcpiGbl_DebugFile;
-FILE *AcpiGbl_OutputFile;
+BOOLEAN AcpiGbl_DebugTimeout = FALSE;
/* Upcalls to AcpiExec */
-ACPI_PHYSICAL_ADDRESS
-AeLocalGetRootPointer (
- void);
-
void
AeTableOverride (
ACPI_TABLE_HEADER *ExistingTable,
@@ -84,7 +78,127 @@ typedef void* (*PTHREAD_CALLBACK) (void *);
/* Buffer used by AcpiOsVprintf */
-#define ACPI_VPRINTF_BUFFER_SIZE 512
+#define ACPI_VPRINTF_BUFFER_SIZE 512
+#define _ASCII_NEWLINE '\n'
+
+/* Terminal support for AcpiExec only */
+
+#ifdef ACPI_EXEC_APP
+#include <termios.h>
+
+struct termios OriginalTermAttributes;
+int TermAttributesWereSet = 0;
+
+ACPI_STATUS
+AcpiUtReadLine (
+ char *Buffer,
+ UINT32 BufferLength,
+ UINT32 *BytesRead);
+
+static void
+OsEnterLineEditMode (
+ void);
+
+static void
+OsExitLineEditMode (
+ void);
+
+
+/******************************************************************************
+ *
+ * FUNCTION: OsEnterLineEditMode, OsExitLineEditMode
+ *
+ * PARAMETERS: None
+ *
+ * RETURN: None
+ *
+ * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
+ *
+ * Interactive line-editing support for the AML debugger. Used with the
+ * common/acgetline module.
+ *
+ * readline() is not used because of non-portability. It is not available
+ * on all systems, and if it is, often the package must be manually installed.
+ *
+ * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
+ * editing that we need in AcpiOsGetLine.
+ *
+ * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
+ * calls will also work:
+ * For OsEnterLineEditMode: system ("stty cbreak -echo")
+ * For OsExitLineEditMode: system ("stty cooked echo")
+ *
+ *****************************************************************************/
+
+static void
+OsEnterLineEditMode (
+ void)
+{
+ struct termios LocalTermAttributes;
+
+
+ TermAttributesWereSet = 0;
+
+ /* STDIN must be a terminal */
+
+ if (!isatty (STDIN_FILENO))
+ {
+ return;
+ }
+
+ /* Get and keep the original attributes */
+
+ if (tcgetattr (STDIN_FILENO, &OriginalTermAttributes))
+ {
+ fprintf (stderr, "Could not get terminal attributes!\n");
+ return;
+ }
+
+ /* Set the new attributes to enable raw character input */
+
+ memcpy (&LocalTermAttributes, &OriginalTermAttributes,
+ sizeof (struct termios));
+
+ LocalTermAttributes.c_lflag &= ~(ICANON | ECHO);
+ LocalTermAttributes.c_cc[VMIN] = 1;
+ LocalTermAttributes.c_cc[VTIME] = 0;
+
+ if (tcsetattr (STDIN_FILENO, TCSANOW, &LocalTermAttributes))
+ {
+ fprintf (stderr, "Could not set terminal attributes!\n");
+ return;
+ }
+
+ TermAttributesWereSet = 1;
+}
+
+
+static void
+OsExitLineEditMode (
+ void)
+{
+
+ if (!TermAttributesWereSet)
+ {
+ return;
+ }
+
+ /* Set terminal attributes back to the original values */
+
+ if (tcsetattr (STDIN_FILENO, TCSANOW, &OriginalTermAttributes))
+ {
+ fprintf (stderr, "Could not restore terminal attributes!\n");
+ }
+}
+
+
+#else
+
+/* These functions are not needed for other ACPICA utilities */
+
+#define OsEnterLineEditMode()
+#define OsExitLineEditMode()
+#endif
/******************************************************************************
@@ -95,7 +209,7 @@ typedef void* (*PTHREAD_CALLBACK) (void *);
*
* RETURN: Status
*
- * DESCRIPTION: Init and terminate. Nothing to do.
+ * DESCRIPTION: Initialize and terminate this module.
*
*****************************************************************************/
@@ -103,21 +217,33 @@ ACPI_STATUS
AcpiOsInitialize (
void)
{
+ ACPI_STATUS Status;
+
AcpiGbl_OutputFile = stdout;
+
+ OsEnterLineEditMode ();
+
+ Status = AcpiOsCreateLock (&AcpiGbl_PrintLock);
+ if (ACPI_FAILURE (Status))
+ {
+ return (Status);
+ }
+
return (AE_OK);
}
-
ACPI_STATUS
AcpiOsTerminate (
void)
{
+ OsExitLineEditMode ();
return (AE_OK);
}
+#ifndef ACPI_USE_NATIVE_RSDP_POINTER
/******************************************************************************
*
* FUNCTION: AcpiOsGetRootPointer
@@ -135,8 +261,9 @@ AcpiOsGetRootPointer (
void)
{
- return (AeLocalGetRootPointer ());
+ return (0);
}
+#endif
/******************************************************************************
@@ -370,6 +497,7 @@ AcpiOsVprintf (
}
+#ifndef ACPI_EXEC_APP
/******************************************************************************
*
* FUNCTION: AcpiOsGetLine
@@ -380,7 +508,9 @@ AcpiOsVprintf (
*
* RETURN: Status and actual bytes read
*
- * DESCRIPTION: Formatted input with argument list pointer
+ * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
+ * AcpiExec utility, we use the acgetline module instead to
+ * provide line-editing and history support.
*
*****************************************************************************/
@@ -390,44 +520,49 @@ AcpiOsGetLine (
UINT32 BufferLength,
UINT32 *BytesRead)
{
- int Temp;
- UINT32 i;
+ int InputChar;
+ UINT32 EndOfLine;
+
+ /* Standard AcpiOsGetLine for all utilities except AcpiExec */
- for (i = 0; ; i++)
+ for (EndOfLine = 0; ; EndOfLine++)
{
- if (i >= BufferLength)
+ if (EndOfLine >= BufferLength)
{
return (AE_BUFFER_OVERFLOW);
}
- if ((Temp = getchar ()) == EOF)
+ if ((InputChar = getchar ()) == EOF)
{
return (AE_ERROR);
}
- if (!Temp || Temp == '\n')
+ if (!InputChar || InputChar == _ASCII_NEWLINE)
{
break;
}
- Buffer [i] = (char) Temp;
+ Buffer[EndOfLine] = (char) InputChar;
}
/* Null terminate the buffer */
- Buffer [i] = 0;
+ Buffer[EndOfLine] = 0;
/* Return the number of bytes in the string */
if (BytesRead)
{
- *BytesRead = i;
+ *BytesRead = EndOfLine;
}
+
return (AE_OK);
}
+#endif
+#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
/******************************************************************************
*
* FUNCTION: AcpiOsMapMemory
@@ -473,6 +608,7 @@ AcpiOsUnmapMemory (
return;
}
+#endif
/******************************************************************************
@@ -499,6 +635,32 @@ AcpiOsAllocate (
}
+#ifdef USE_NATIVE_ALLOCATE_ZEROED
+/******************************************************************************
+ *
+ * FUNCTION: AcpiOsAllocateZeroed
+ *
+ * PARAMETERS: Size - Amount to allocate, in bytes
+ *
+ * RETURN: Pointer to the new allocation. Null on error.
+ *
+ * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
+ *
+ *****************************************************************************/
+
+void *
+AcpiOsAllocateZeroed (
+ ACPI_SIZE size)
+{
+ void *Mem;
+
+
+ Mem = (void *) calloc (1, (size_t) size);
+ return (Mem);
+}
+#endif
+
+
/******************************************************************************
*
* FUNCTION: AcpiOsFree
@@ -1005,7 +1167,7 @@ AcpiOsGetTimer (
* FUNCTION: AcpiOsReadPciConfiguration
*
* PARAMETERS: PciId - Seg/Bus/Dev
- * Register - Device Register
+ * PciRegister - Device Register
* Value - Buffer where value is placed
* Width - Number of bits
*
@@ -1018,7 +1180,7 @@ AcpiOsGetTimer (
ACPI_STATUS
AcpiOsReadPciConfiguration (
ACPI_PCI_ID *PciId,
- UINT32 Register,
+ UINT32 PciRegister,
UINT64 *Value,
UINT32 Width)
{
@@ -1033,7 +1195,7 @@ AcpiOsReadPciConfiguration (
* FUNCTION: AcpiOsWritePciConfiguration
*
* PARAMETERS: PciId - Seg/Bus/Dev
- * Register - Device Register
+ * PciRegister - Device Register
* Value - Value to be written
* Width - Number of bits
*
@@ -1046,7 +1208,7 @@ AcpiOsReadPciConfiguration (
ACPI_STATUS
AcpiOsWritePciConfiguration (
ACPI_PCI_ID *PciId,
- UINT32 Register,
+ UINT32 PciRegister,
UINT64 Value,
UINT32 Width)
{
@@ -1242,7 +1404,7 @@ AcpiOsWritable (
*
* FUNCTION: AcpiOsSignal
*
- * PARAMETERS: Function - ACPI CA signal function code
+ * PARAMETERS: Function - ACPI A signal function code
* Info - Pointer to function-dependent structure
*
* RETURN: Status
@@ -1334,6 +1496,26 @@ AcpiOsExecute (
return (0);
}
+#else /* ACPI_SINGLE_THREADED */
+ACPI_THREAD_ID
+AcpiOsGetThreadId (
+ void)
+{
+ return (1);
+}
+
+ACPI_STATUS
+AcpiOsExecute (
+ ACPI_EXECUTE_TYPE Type,
+ ACPI_OSD_EXEC_CALLBACK Function,
+ void *Context)
+{
+
+ Function (Context);
+
+ return (AE_OK);
+}
+
#endif /* ACPI_SINGLE_THREADED */
OpenPOWER on IntegriCloud