Blame 0001-Add-in-basic-infrastructure-for-big-endian-support.patch

edb6c78
From bb45113bc9aed952a499cd1c53988dc81f597582 Mon Sep 17 00:00:00 2001
edb6c78
From: Al Stone <ahs3@redhat.com>
edb6c78
Date: Thu, 15 Oct 2020 11:53:33 -0600
edb6c78
Subject: [PATCH 01/40] Add in basic infrastructure for big-endian support
edb6c78
edb6c78
This adds in some basic functions -- AcpiUtReadUint32(), for example,
edb6c78
to read a UINT32 value in little-endian form and return it in host-native
edb6c78
format -- along with AcpiUtWriteUint() that writes out an integer in
edb6c78
host-native format as a little-endian value.
edb6c78
edb6c78
But, to do that, I'm adding the functions in a new file: utendian.c.  So,
edb6c78
the header files need fixing, and the makefiles need to be sure to compile
edb6c78
the new code.
edb6c78
edb6c78
However, this sets things up for the future, where endian-aware code can
edb6c78
be added as the need is uncovered.  For now, these functions cover all of
edb6c78
the cases I know about.
edb6c78
edb6c78
Signed-off-by: Al Stone <ahs3@redhat.com>
edb6c78
---
edb6c78
 generate/unix/acpibin/Makefile         |   1 +
edb6c78
 generate/unix/acpidump/Makefile        |   1 +
edb6c78
 generate/unix/acpiexamples/Makefile    |   1 +
edb6c78
 generate/unix/acpiexec/Makefile        |   1 +
edb6c78
 generate/unix/acpihelp/Makefile        |   1 +
edb6c78
 generate/unix/iasl/Makefile            |   1 +
edb6c78
 source/components/utilities/utendian.c | 205 +++++++++++++++++++++++++
edb6c78
 source/include/acutils.h               |  26 ++++
edb6c78
 source/include/platform/aclinux.h      |   5 +
edb6c78
 9 files changed, 242 insertions(+)
edb6c78
 create mode 100644 source/components/utilities/utendian.c
edb6c78
edb6c78
Index: acpica-unix2-20200925/generate/unix/acpibin/Makefile
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/generate/unix/acpibin/Makefile
edb6c78
+++ acpica-unix2-20200925/generate/unix/acpibin/Makefile
edb6c78
@@ -37,6 +37,7 @@ OBJECTS = \
edb6c78
 	$(OBJDIR)/utcache.o\
edb6c78
 	$(OBJDIR)/utdebug.o\
edb6c78
 	$(OBJDIR)/utdecode.o\
edb6c78
+	$(OBJDIR)/utendian.o\
edb6c78
 	$(OBJDIR)/utexcep.o\
edb6c78
 	$(OBJDIR)/utglobal.o\
edb6c78
 	$(OBJDIR)/utlock.o\
edb6c78
Index: acpica-unix2-20200925/generate/unix/acpidump/Makefile
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/generate/unix/acpidump/Makefile
edb6c78
+++ acpica-unix2-20200925/generate/unix/acpidump/Makefile
edb6c78
@@ -36,6 +36,7 @@ OBJECTS = \
edb6c78
 	$(OBJDIR)/osunixdir.o\
edb6c78
 	$(OBJDIR)/osunixmap.o\
edb6c78
 	$(OBJDIR)/osunixxf.o\
edb6c78
+	$(OBJDIR)/utendian.o\
edb6c78
 	$(OBJDIR)/tbprint.o\
edb6c78
 	$(OBJDIR)/tbxfroot.o\
edb6c78
 	$(OBJDIR)/utascii.o\
edb6c78
Index: acpica-unix2-20200925/generate/unix/acpiexamples/Makefile
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/generate/unix/acpiexamples/Makefile
edb6c78
+++ acpica-unix2-20200925/generate/unix/acpiexamples/Makefile
edb6c78
@@ -139,6 +139,7 @@ OBJECTS = \
edb6c78
 	$(OBJDIR)/utdebug.o\
edb6c78
 	$(OBJDIR)/utdecode.o\
edb6c78
 	$(OBJDIR)/utdelete.o\
edb6c78
+	$(OBJDIR)/utendian.o\
edb6c78
 	$(OBJDIR)/uterror.o\
edb6c78
 	$(OBJDIR)/uteval.o\
edb6c78
 	$(OBJDIR)/utexcep.o\
edb6c78
Index: acpica-unix2-20200925/generate/unix/acpiexec/Makefile
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/generate/unix/acpiexec/Makefile
edb6c78
+++ acpica-unix2-20200925/generate/unix/acpiexec/Makefile
edb6c78
@@ -214,6 +214,7 @@ OBJECTS = \
edb6c78
 	$(OBJDIR)/utdebug.o\
edb6c78
 	$(OBJDIR)/utdecode.o\
edb6c78
 	$(OBJDIR)/utdelete.o\
edb6c78
+	$(OBJDIR)/utendian.o\
edb6c78
 	$(OBJDIR)/uterror.o\
edb6c78
 	$(OBJDIR)/uteval.o\
edb6c78
 	$(OBJDIR)/utexcep.o\
edb6c78
Index: acpica-unix2-20200925/generate/unix/acpihelp/Makefile
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/generate/unix/acpihelp/Makefile
edb6c78
+++ acpica-unix2-20200925/generate/unix/acpihelp/Makefile
edb6c78
@@ -43,6 +43,7 @@ OBJECTS = \
edb6c78
 	$(OBJDIR)/getopt.o\
edb6c78
 	$(OBJDIR)/osunixxf.o\
edb6c78
 	$(OBJDIR)/utdebug.o\
edb6c78
+	$(OBJDIR)/utendian.o\
edb6c78
 	$(OBJDIR)/utexcep.o\
edb6c78
 	$(OBJDIR)/utglobal.o\
edb6c78
 	$(OBJDIR)/uthex.o\
edb6c78
Index: acpica-unix2-20200925/generate/unix/iasl/Makefile
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/generate/unix/iasl/Makefile
edb6c78
+++ acpica-unix2-20200925/generate/unix/iasl/Makefile
edb6c78
@@ -225,6 +225,7 @@ OBJECTS = \
edb6c78
 	$(OBJDIR)/utdebug.o\
edb6c78
 	$(OBJDIR)/utdecode.o\
edb6c78
 	$(OBJDIR)/utdelete.o\
edb6c78
+	$(OBJDIR)/utendian.o\
edb6c78
 	$(OBJDIR)/uterror.o\
edb6c78
 	$(OBJDIR)/utexcep.o\
edb6c78
 	$(OBJDIR)/utglobal.o\
edb6c78
Index: acpica-unix2-20200925/source/components/utilities/utendian.c
edb6c78
===================================================================
edb6c78
--- /dev/null
edb6c78
+++ acpica-unix2-20200925/source/components/utilities/utendian.c
edb6c78
@@ -0,0 +1,205 @@
edb6c78
+/******************************************************************************
edb6c78
+ *
edb6c78
+ * Module Name: utendian -- byte swapping support for other-endianness
edb6c78
+ *
edb6c78
+ *****************************************************************************/
edb6c78
+
edb6c78
+/*****************************************************************************
edb6c78
+ *
edb6c78
+ * Copyright (c) 2020, Al Stone <ahs3@redhat.com>
edb6c78
+ *
edb6c78
+ * Redistribution and use in source and binary forms, with or without
edb6c78
+ * modification, are permitted provided that the following conditions
edb6c78
+ * are met:
edb6c78
+ * 1. Redistributions of source code must retain the above copyright
edb6c78
+ *    notice, this list of conditions, and the following disclaimer,
edb6c78
+ *    without modification.
edb6c78
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
edb6c78
+ *    substantially similar to the "NO WARRANTY" disclaimer below
edb6c78
+ *    ("Disclaimer") and any redistribution must be conditioned upon
edb6c78
+ *    including a substantially similar Disclaimer requirement for further
edb6c78
+ *    binary redistribution.
edb6c78
+ * 3. Neither the names of the above-listed copyright holders nor the names
edb6c78
+ *    of any contributors may be used to endorse or promote products derived
edb6c78
+ *    from this software without specific prior written permission.
edb6c78
+ *
edb6c78
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
edb6c78
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
edb6c78
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
edb6c78
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
edb6c78
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
edb6c78
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
edb6c78
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
edb6c78
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
edb6c78
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
edb6c78
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
edb6c78
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
edb6c78
+ *
edb6c78
+ * Alternatively, you may choose to be licensed under the terms of the
edb6c78
+ * GNU General Public License ("GPL") version 2 as published by the Free
edb6c78
+ * Software Foundation.
edb6c78
+ *
edb6c78
+ *****************************************************************************/
edb6c78
+
edb6c78
+#include "acpi.h"
edb6c78
+#include "accommon.h"
edb6c78
+
edb6c78
+#define _COMPONENT          ACPI_COMPILER
edb6c78
+        ACPI_MODULE_NAME    ("utendian")
edb6c78
+
edb6c78
+
edb6c78
+/*
edb6c78
+ * Endianness support functions.
edb6c78
+ *
edb6c78
+ * Ultimately, everything in ACPI tables or AML must be in little-endian
edb6c78
+ * format.  However, we sometimes find it necessary to run on a big-endian
edb6c78
+ * machine and create or read those little-endian values.  This is a small
edb6c78
+ * libary of functions to make that easier, and more visible.
edb6c78
+ *
edb6c78
+ */
edb6c78
+
edb6c78
+
edb6c78
+/*******************************************************************************
edb6c78
+ *
edb6c78
+ * FUNCTION:    AcpiUtReadUint16
edb6c78
+ *
edb6c78
+ * PARAMETERS:  Src		    - location containing the little-endian
edb6c78
+ *                                    value
edb6c78
+ *
edb6c78
+ * RETURN:      UINT16 value in host-native form
edb6c78
+ *
edb6c78
+ * DESCRIPTION: Read a UINT16 little-endian value from a given location
edb6c78
+ *              and return it in host-native form
edb6c78
+ *
edb6c78
+ ******************************************************************************/
edb6c78
+
edb6c78
+#if defined(ACPI_BIG_ENDIAN)
edb6c78
+UINT16 AcpiUtReadUint16 (void *SrcPtr)
edb6c78
+{
edb6c78
+    UINT16 Result = 0;
edb6c78
+    UINT8  *Dst = (UINT8 *)&Result;
edb6c78
+    UINT8  *Src = (UINT8 *)SrcPtr;
edb6c78
+
edb6c78
+    Dst[0] = Src[1];
edb6c78
+    Dst[1] = Src[0];
edb6c78
+
edb6c78
+    return Result;
edb6c78
+}
edb6c78
+#else
edb6c78
+UINT16 AcpiUtReadUint16 (void *SrcPtr) { return *(UINT16 *)SrcPtr; }
edb6c78
+#endif
edb6c78
+
edb6c78
+/*******************************************************************************
edb6c78
+ *
edb6c78
+ * FUNCTION:    AcpiUtReadUint32
edb6c78
+ *
edb6c78
+ * PARAMETERS:  Src		    - location containing the little-endian
edb6c78
+ *                                    value
edb6c78
+ *
edb6c78
+ * RETURN:      UINT32 value in host-native form
edb6c78
+ *
edb6c78
+ * DESCRIPTION: Read a UINT32 little-endian value from a given location
edb6c78
+ *              and return it in host-native form
edb6c78
+ *
edb6c78
+ ******************************************************************************/
edb6c78
+
edb6c78
+#if defined(ACPI_BIG_ENDIAN)
edb6c78
+UINT32 AcpiUtReadUint32 (void *SrcPtr)
edb6c78
+{
edb6c78
+    UINT32 Result = 0;
edb6c78
+    UINT8  *Dst = (UINT8 *)&Result;
edb6c78
+    UINT8  *Src = (UINT8 *)SrcPtr;
edb6c78
+
edb6c78
+    Dst[0] = Src[3];
edb6c78
+    Dst[1] = Src[2];
edb6c78
+    Dst[2] = Src[1];
edb6c78
+    Dst[3] = Src[0];
edb6c78
+
edb6c78
+    return Result;
edb6c78
+}
edb6c78
+#else
edb6c78
+UINT32 AcpiUtReadUint32 (void *SrcPtr) { return *(UINT32 *)SrcPtr; }
edb6c78
+#endif
edb6c78
+
edb6c78
+/*******************************************************************************
edb6c78
+ *
edb6c78
+ * FUNCTION:    AcpiUtReadUint64
edb6c78
+ *
edb6c78
+ * PARAMETERS:  Src		    - location containing the little-endian
edb6c78
+ *                                    value
edb6c78
+ *
edb6c78
+ * RETURN:      UINT64 value in host-native form
edb6c78
+ *
edb6c78
+ * DESCRIPTION: Read a UINT64 little-endian value from a given location
edb6c78
+ *              and return it in host-native form
edb6c78
+ *
edb6c78
+ ******************************************************************************/
edb6c78
+
edb6c78
+#if defined(ACPI_BIG_ENDIAN)
edb6c78
+UINT64 AcpiUtReadUint64 (void *SrcPtr)
edb6c78
+{
edb6c78
+    UINT64 Result = 0;
edb6c78
+    UINT8  *Dst = (UINT8 *)&Result;
edb6c78
+    UINT8  *Src = (UINT8 *)SrcPtr;
edb6c78
+
edb6c78
+    Dst[0] = Src[7];
edb6c78
+    Dst[1] = Src[6];
edb6c78
+    Dst[2] = Src[5];
edb6c78
+    Dst[3] = Src[4];
edb6c78
+    Dst[4] = Src[3];
edb6c78
+    Dst[5] = Src[2];
edb6c78
+    Dst[6] = Src[1];
edb6c78
+    Dst[7] = Src[0];
edb6c78
+
edb6c78
+    return Result;
edb6c78
+}
edb6c78
+#else
edb6c78
+UINT64 AcpiUtReadUint64 (void *SrcPtr) { return *(UINT64 *)SrcPtr; }
edb6c78
+#endif
edb6c78
+
edb6c78
+/*******************************************************************************
edb6c78
+ *
edb6c78
+ * FUNCTION:    AcpiUtWriteUint
edb6c78
+ *
edb6c78
+ * PARAMETERS:  DstPtr		- where to place the retrieved value
edb6c78
+ *	        DstLength	- space in bytes for this int type
edb6c78
+ *	        SrcPtr		- where the little-endian value lives
edb6c78
+ *	        SrcLength	- space in bytes for this int type
edb6c78
+ *
edb6c78
+ * RETURN:      None.
edb6c78
+ *
edb6c78
+ * DESCRIPTION: Write a host-native integer value of the given size, and
edb6c78
+ * 	        store it in the location specified in little-endian form.
edb6c78
+ * 	        Given the amount of integer type casting done, this general
edb6c78
+ * 	        version seems the most useful (vs 32->32, 32->16, 16->32,
edb6c78
+ * 	        ad infinitum)
edb6c78
+ *
edb6c78
+ ******************************************************************************/
edb6c78
+
edb6c78
+#if defined(ACPI_BIG_ENDIAN)
edb6c78
+void AcpiUtWriteUint (void *DstPtr, int DstLength,
edb6c78
+	              const void *SrcPtr, const int SrcLength)
edb6c78
+{
edb6c78
+    UINT8 *Dst = (UINT8 *)DstPtr;
edb6c78
+    UINT8 *Src = (UINT8 *)SrcPtr;
edb6c78
+    int Length;
edb6c78
+    int ii;
edb6c78
+
edb6c78
+    Length = SrcLength >= DstLength ? DstLength : SrcLength;
edb6c78
+    for (ii = 0; ii < Length; ii++)
edb6c78
+	    Dst[ii] = Src[SrcLength - ii - 1];
edb6c78
+
edb6c78
+}
edb6c78
+#else
edb6c78
+void AcpiUtWriteUint (void *DstPtr, int DstLength,
edb6c78
+	              const void *SrcPtr, const int SrcLength)
edb6c78
+{
edb6c78
+    UINT8 *Dst = (UINT8 *)DstPtr;
edb6c78
+    UINT8 *Src = (UINT8 *)SrcPtr;
edb6c78
+    uint Length;
edb6c78
+
edb6c78
+    Length = SrcLength > DstLength ? DstLength : SrcLength;
edb6c78
+    memcpy(Dst, Src, Length);
edb6c78
+}
edb6c78
+#endif
edb6c78
+
edb6c78
Index: acpica-unix2-20200925/source/include/acutils.h
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/source/include/acutils.h
edb6c78
+++ acpica-unix2-20200925/source/include/acutils.h
edb6c78
@@ -1161,4 +1161,30 @@ AcpiUtConvertStringToUuid (
edb6c78
     UINT8                   *UuidBuffer);
edb6c78
 #endif
edb6c78
 
edb6c78
+/*
edb6c78
+ * utendian -- byte-swapping for big-endian support
edb6c78
+ */
edb6c78
+#if defined(ACPI_ASL_COMPILER) || defined(ACPI_EXEC_APP) || \
edb6c78
+    defined(ACPI_HELP_APP)     || defined(ACPI_DUMP_APP) || \
edb6c78
+    defined(ACPI_EXAMPLE_APP)  || defined(ACPI_BIN_APP)
edb6c78
+UINT32
edb6c78
+AcpiUtReadUint32 (
edb6c78
+    void                    *SrcPtr);
edb6c78
+
edb6c78
+UINT16
edb6c78
+AcpiUtReadUint16 (
edb6c78
+    void                    *SrcPtr);
edb6c78
+
edb6c78
+UINT64
edb6c78
+AcpiUtReadUint64 (
edb6c78
+    void                    *SrcPtr);
edb6c78
+
edb6c78
+void  
edb6c78
+AcpiUtWriteUint (
edb6c78
+    void                    *DstPtr,
edb6c78
+    int                     DstLength,
edb6c78
+    const void              *SrcPtr,
edb6c78
+    const int               SrcLength);
edb6c78
+#endif
edb6c78
+
edb6c78
 #endif /* _ACUTILS_H */
edb6c78
Index: acpica-unix2-20200925/source/include/platform/aclinux.h
edb6c78
===================================================================
edb6c78
--- acpica-unix2-20200925.orig/source/include/platform/aclinux.h
edb6c78
+++ acpica-unix2-20200925/source/include/platform/aclinux.h
edb6c78
@@ -198,6 +198,7 @@
edb6c78
 
edb6c78
 #ifdef ACPI_USE_STANDARD_HEADERS
edb6c78
 #include <unistd.h>
edb6c78
+#include <endian.h>
edb6c78
 #endif
edb6c78
 
edb6c78
 /* Define/disable kernel-specific declarators */
edb6c78
@@ -233,6 +234,10 @@
edb6c78
 #define __cdecl
edb6c78
 #endif
edb6c78
 
edb6c78
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
edb6c78
+#define ACPI_BIG_ENDIAN
edb6c78
+#endif
edb6c78
+
edb6c78
 #endif /* __KERNEL__ */
edb6c78
 
edb6c78
 #endif /* __ACLINUX_H__ */