acpica-tools/0001-Add-in-basic-infrastructure-for-big-endian-support.patch

373 lines
13 KiB
Diff
Raw Normal View History

From bb45113bc9aed952a499cd1c53988dc81f597582 Mon Sep 17 00:00:00 2001
From: Al Stone <ahs3@redhat.com>
Date: Thu, 15 Oct 2020 11:53:33 -0600
Subject: [PATCH 01/40] Add in basic infrastructure for big-endian support
This adds in some basic functions -- AcpiUtReadUint32(), for example,
to read a UINT32 value in little-endian form and return it in host-native
format -- along with AcpiUtWriteUint() that writes out an integer in
host-native format as a little-endian value.
But, to do that, I'm adding the functions in a new file: utendian.c. So,
the header files need fixing, and the makefiles need to be sure to compile
the new code.
However, this sets things up for the future, where endian-aware code can
be added as the need is uncovered. For now, these functions cover all of
the cases I know about.
Signed-off-by: Al Stone <ahs3@redhat.com>
---
generate/unix/acpibin/Makefile | 1 +
generate/unix/acpidump/Makefile | 1 +
generate/unix/acpiexamples/Makefile | 1 +
generate/unix/acpiexec/Makefile | 1 +
generate/unix/acpihelp/Makefile | 1 +
generate/unix/iasl/Makefile | 1 +
source/components/utilities/utendian.c | 205 +++++++++++++++++++++++++
source/include/acutils.h | 26 ++++
source/include/platform/aclinux.h | 5 +
9 files changed, 242 insertions(+)
create mode 100644 source/components/utilities/utendian.c
Index: acpica-unix2-20200925/generate/unix/acpibin/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpibin/Makefile
+++ acpica-unix2-20200925/generate/unix/acpibin/Makefile
@@ -37,6 +37,7 @@ OBJECTS = \
$(OBJDIR)/utcache.o\
$(OBJDIR)/utdebug.o\
$(OBJDIR)/utdecode.o\
+ $(OBJDIR)/utendian.o\
$(OBJDIR)/utexcep.o\
$(OBJDIR)/utglobal.o\
$(OBJDIR)/utlock.o\
Index: acpica-unix2-20200925/generate/unix/acpidump/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpidump/Makefile
+++ acpica-unix2-20200925/generate/unix/acpidump/Makefile
@@ -36,6 +36,7 @@ OBJECTS = \
$(OBJDIR)/osunixdir.o\
$(OBJDIR)/osunixmap.o\
$(OBJDIR)/osunixxf.o\
+ $(OBJDIR)/utendian.o\
$(OBJDIR)/tbprint.o\
$(OBJDIR)/tbxfroot.o\
$(OBJDIR)/utascii.o\
Index: acpica-unix2-20200925/generate/unix/acpiexamples/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpiexamples/Makefile
+++ acpica-unix2-20200925/generate/unix/acpiexamples/Makefile
@@ -139,6 +139,7 @@ OBJECTS = \
$(OBJDIR)/utdebug.o\
$(OBJDIR)/utdecode.o\
$(OBJDIR)/utdelete.o\
+ $(OBJDIR)/utendian.o\
$(OBJDIR)/uterror.o\
$(OBJDIR)/uteval.o\
$(OBJDIR)/utexcep.o\
Index: acpica-unix2-20200925/generate/unix/acpiexec/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpiexec/Makefile
+++ acpica-unix2-20200925/generate/unix/acpiexec/Makefile
@@ -214,6 +214,7 @@ OBJECTS = \
$(OBJDIR)/utdebug.o\
$(OBJDIR)/utdecode.o\
$(OBJDIR)/utdelete.o\
+ $(OBJDIR)/utendian.o\
$(OBJDIR)/uterror.o\
$(OBJDIR)/uteval.o\
$(OBJDIR)/utexcep.o\
Index: acpica-unix2-20200925/generate/unix/acpihelp/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpihelp/Makefile
+++ acpica-unix2-20200925/generate/unix/acpihelp/Makefile
@@ -43,6 +43,7 @@ OBJECTS = \
$(OBJDIR)/getopt.o\
$(OBJDIR)/osunixxf.o\
$(OBJDIR)/utdebug.o\
+ $(OBJDIR)/utendian.o\
$(OBJDIR)/utexcep.o\
$(OBJDIR)/utglobal.o\
$(OBJDIR)/uthex.o\
Index: acpica-unix2-20200925/generate/unix/iasl/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/iasl/Makefile
+++ acpica-unix2-20200925/generate/unix/iasl/Makefile
@@ -225,6 +225,7 @@ OBJECTS = \
$(OBJDIR)/utdebug.o\
$(OBJDIR)/utdecode.o\
$(OBJDIR)/utdelete.o\
+ $(OBJDIR)/utendian.o\
$(OBJDIR)/uterror.o\
$(OBJDIR)/utexcep.o\
$(OBJDIR)/utglobal.o\
Index: acpica-unix2-20200925/source/components/utilities/utendian.c
===================================================================
--- /dev/null
+++ acpica-unix2-20200925/source/components/utilities/utendian.c
@@ -0,0 +1,205 @@
+/******************************************************************************
+ *
+ * Module Name: utendian -- byte swapping support for other-endianness
+ *
+ *****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Copyright (c) 2020, Al Stone <ahs3@redhat.com>
+ *
+ * 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.
+ *
+ * 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 MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * 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 DAMAGE.
+ *
+ * Alternatively, you may choose to be licensed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ *****************************************************************************/
+
+#include "acpi.h"
+#include "accommon.h"
+
+#define _COMPONENT ACPI_COMPILER
+ ACPI_MODULE_NAME ("utendian")
+
+
+/*
+ * Endianness support functions.
+ *
+ * Ultimately, everything in ACPI tables or AML must be in little-endian
+ * format. However, we sometimes find it necessary to run on a big-endian
+ * machine and create or read those little-endian values. This is a small
+ * libary of functions to make that easier, and more visible.
+ *
+ */
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtReadUint16
+ *
+ * PARAMETERS: Src - location containing the little-endian
+ * value
+ *
+ * RETURN: UINT16 value in host-native form
+ *
+ * DESCRIPTION: Read a UINT16 little-endian value from a given location
+ * and return it in host-native form
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+UINT16 AcpiUtReadUint16 (void *SrcPtr)
+{
+ UINT16 Result = 0;
+ UINT8 *Dst = (UINT8 *)&Result;
+ UINT8 *Src = (UINT8 *)SrcPtr;
+
+ Dst[0] = Src[1];
+ Dst[1] = Src[0];
+
+ return Result;
+}
+#else
+UINT16 AcpiUtReadUint16 (void *SrcPtr) { return *(UINT16 *)SrcPtr; }
+#endif
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtReadUint32
+ *
+ * PARAMETERS: Src - location containing the little-endian
+ * value
+ *
+ * RETURN: UINT32 value in host-native form
+ *
+ * DESCRIPTION: Read a UINT32 little-endian value from a given location
+ * and return it in host-native form
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+UINT32 AcpiUtReadUint32 (void *SrcPtr)
+{
+ UINT32 Result = 0;
+ UINT8 *Dst = (UINT8 *)&Result;
+ UINT8 *Src = (UINT8 *)SrcPtr;
+
+ Dst[0] = Src[3];
+ Dst[1] = Src[2];
+ Dst[2] = Src[1];
+ Dst[3] = Src[0];
+
+ return Result;
+}
+#else
+UINT32 AcpiUtReadUint32 (void *SrcPtr) { return *(UINT32 *)SrcPtr; }
+#endif
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtReadUint64
+ *
+ * PARAMETERS: Src - location containing the little-endian
+ * value
+ *
+ * RETURN: UINT64 value in host-native form
+ *
+ * DESCRIPTION: Read a UINT64 little-endian value from a given location
+ * and return it in host-native form
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+UINT64 AcpiUtReadUint64 (void *SrcPtr)
+{
+ UINT64 Result = 0;
+ UINT8 *Dst = (UINT8 *)&Result;
+ UINT8 *Src = (UINT8 *)SrcPtr;
+
+ Dst[0] = Src[7];
+ Dst[1] = Src[6];
+ Dst[2] = Src[5];
+ Dst[3] = Src[4];
+ Dst[4] = Src[3];
+ Dst[5] = Src[2];
+ Dst[6] = Src[1];
+ Dst[7] = Src[0];
+
+ return Result;
+}
+#else
+UINT64 AcpiUtReadUint64 (void *SrcPtr) { return *(UINT64 *)SrcPtr; }
+#endif
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiUtWriteUint
+ *
+ * PARAMETERS: DstPtr - where to place the retrieved value
+ * DstLength - space in bytes for this int type
+ * SrcPtr - where the little-endian value lives
+ * SrcLength - space in bytes for this int type
+ *
+ * RETURN: None.
+ *
+ * DESCRIPTION: Write a host-native integer value of the given size, and
+ * store it in the location specified in little-endian form.
+ * Given the amount of integer type casting done, this general
+ * version seems the most useful (vs 32->32, 32->16, 16->32,
+ * ad infinitum)
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+void AcpiUtWriteUint (void *DstPtr, int DstLength,
+ const void *SrcPtr, const int SrcLength)
+{
+ UINT8 *Dst = (UINT8 *)DstPtr;
+ UINT8 *Src = (UINT8 *)SrcPtr;
+ int Length;
+ int ii;
+
+ Length = SrcLength >= DstLength ? DstLength : SrcLength;
+ for (ii = 0; ii < Length; ii++)
+ Dst[ii] = Src[SrcLength - ii - 1];
+
+}
+#else
+void AcpiUtWriteUint (void *DstPtr, int DstLength,
+ const void *SrcPtr, const int SrcLength)
+{
+ UINT8 *Dst = (UINT8 *)DstPtr;
+ UINT8 *Src = (UINT8 *)SrcPtr;
+ uint Length;
+
+ Length = SrcLength > DstLength ? DstLength : SrcLength;
+ memcpy(Dst, Src, Length);
+}
+#endif
+
Index: acpica-unix2-20200925/source/include/acutils.h
===================================================================
--- acpica-unix2-20200925.orig/source/include/acutils.h
+++ acpica-unix2-20200925/source/include/acutils.h
@@ -1161,4 +1161,30 @@ AcpiUtConvertStringToUuid (
UINT8 *UuidBuffer);
#endif
+/*
+ * utendian -- byte-swapping for big-endian support
+ */
+#if defined(ACPI_ASL_COMPILER) || defined(ACPI_EXEC_APP) || \
+ defined(ACPI_HELP_APP) || defined(ACPI_DUMP_APP) || \
+ defined(ACPI_EXAMPLE_APP) || defined(ACPI_BIN_APP)
+UINT32
+AcpiUtReadUint32 (
+ void *SrcPtr);
+
+UINT16
+AcpiUtReadUint16 (
+ void *SrcPtr);
+
+UINT64
+AcpiUtReadUint64 (
+ void *SrcPtr);
+
+void
+AcpiUtWriteUint (
+ void *DstPtr,
+ int DstLength,
+ const void *SrcPtr,
+ const int SrcLength);
+#endif
+
#endif /* _ACUTILS_H */
Index: acpica-unix2-20200925/source/include/platform/aclinux.h
===================================================================
--- acpica-unix2-20200925.orig/source/include/platform/aclinux.h
+++ acpica-unix2-20200925/source/include/platform/aclinux.h
@@ -198,6 +198,7 @@
#ifdef ACPI_USE_STANDARD_HEADERS
#include <unistd.h>
+#include <endian.h>
#endif
/* Define/disable kernel-specific declarators */
@@ -233,6 +234,10 @@
#define __cdecl
#endif
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define ACPI_BIG_ENDIAN
+#endif
+
#endif /* __KERNEL__ */
#endif /* __ACLINUX_H__ */