Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/acpi Make Arm MD ACPI code big endian friendly.



details:   https://anonhg.NetBSD.org/src/rev/4a0d24df133b
branches:  trunk
changeset: 954946:4a0d24df133b
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Sep 13 21:41:17 2020 +0000

description:
Make Arm MD ACPI code big endian friendly.

diffstat:

 sys/arch/arm/acpi/acpi_iort.c      |  40 +++++++++++++++++++-------------------
 sys/arch/arm/acpi/acpi_pci_n1sdp.c |   6 ++--
 sys/arch/arm/acpi/acpi_platform.c  |  24 +++++++++++-----------
 sys/arch/arm/acpi/acpi_table.c     |  16 ++++++++------
 4 files changed, 44 insertions(+), 42 deletions(-)

diffs (293 lines):

diff -r 73a00419e037 -r 4a0d24df133b sys/arch/arm/acpi/acpi_iort.c
--- a/sys/arch/arm/acpi/acpi_iort.c     Sun Sep 13 21:21:04 2020 +0000
+++ b/sys/arch/arm/acpi/acpi_iort.c     Sun Sep 13 21:41:17 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_iort.c,v 1.3 2020/02/13 00:02:21 jmcneill Exp $ */
+/* $NetBSD: acpi_iort.c,v 1.4 2020/09/13 21:41:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_iort.c,v 1.3 2020/02/13 00:02:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_iort.c,v 1.4 2020/09/13 21:41:17 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -47,15 +47,15 @@
        ACPI_IORT_ID_MAPPING *map;
        uint32_t offset, n;
 
-       offset = node->MappingOffset;
-       for (n = 0; n < node->MappingCount; n++) {
+       offset = le32toh(node->MappingOffset);
+       for (n = 0; n < le32toh(node->MappingCount); n++) {
                map = ACPI_ADD_PTR(ACPI_IORT_ID_MAPPING, node, offset);
-               if (map->Flags & ACPI_IORT_ID_SINGLE_MAPPING) {
-                       *id = map->OutputBase;
+               if (le32toh(map->Flags) & ACPI_IORT_ID_SINGLE_MAPPING) {
+                       *id = le32toh(map->OutputBase);
                        return map;
                }
-               if (*id >= map->InputBase && *id <= map->InputBase + map->IdCount) {
-                       *id = *id - map->InputBase + map->OutputBase;
+               if (*id >= le32toh(map->InputBase) && *id <= le32toh(map->InputBase) + le32toh(map->IdCount)) {
+                       *id = *id - le32toh(map->InputBase) + le32toh(map->OutputBase);
                        return map;
                }
                offset += sizeof(ACPI_IORT_ID_MAPPING);
@@ -73,7 +73,7 @@
        if (map == NULL)
                return NULL;
 
-       return ACPI_ADD_PTR(ACPI_IORT_NODE, iort, map->OutputReference);
+       return ACPI_ADD_PTR(ACPI_IORT_NODE, iort, le32toh(map->OutputReference));
 }
 
 uint32_t
@@ -89,12 +89,12 @@
        if (ACPI_FAILURE(rv))
                return devid;
 
-       offset = iort->NodeOffset;
-       for (n = 0; n < iort->NodeCount; n++) {
+       offset = le32toh(iort->NodeOffset);
+       for (n = 0; n < le32toh(iort->NodeCount); n++) {
                node = ACPI_ADD_PTR(ACPI_IORT_NODE, iort, offset);
                if (node->Type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
                        root = (ACPI_IORT_ROOT_COMPLEX *)node->NodeData;
-                       if (root->PciSegmentNumber == seg) {
+                       if (le32toh(root->PciSegmentNumber) == seg) {
                                const uint32_t odevid = devid;
                                do {
                                        node = acpi_iort_find_ref(iort, node, &devid);
@@ -103,7 +103,7 @@
                                return devid;
                        }
                }
-               offset += node->Length;
+               offset += le16toh(node->Length);
        }
 
        return devid;
@@ -123,28 +123,28 @@
        if (ACPI_FAILURE(rv))
                return 0;
 
-       offset = iort->NodeOffset;
-       for (n = 0; n < iort->NodeCount; n++) {
+       offset = le32toh(iort->NodeOffset);
+       for (n = 0; n < le32toh(iort->NodeCount); n++) {
                node = ACPI_ADD_PTR(ACPI_IORT_NODE, iort, offset);
                if (node->Type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
                        root = (ACPI_IORT_ROOT_COMPLEX *)node->NodeData;
-                       if (root->PciSegmentNumber == seg) {
+                       if (le32toh(root->PciSegmentNumber) == seg) {
                                const uint32_t odevid = devid;
                                do {
                                        node = acpi_iort_find_ref(iort, node, &devid);
                                        if (node != NULL && node->Type == ACPI_IORT_NODE_ITS_GROUP) {
                                                its_group = (ACPI_IORT_ITS_GROUP *)node->NodeData;
-                                               if (its_group->ItsCount == 0)
+                                               if (le32toh(its_group->ItsCount) == 0)
                                                        return 0;
                                                aprint_debug("ACPI: IORT mapped devid %#x -> ITS %#x\n",
-                                                   odevid, its_group->Identifiers[0]);
-                                               return its_group->Identifiers[0];
+                                                   odevid, le32toh(its_group->Identifiers[0]));
+                                               return le32toh(its_group->Identifiers[0]);
                                        }
                                } while (node != NULL);
                                return 0;
                        }
                }
-               offset += node->Length;
+               offset += le16toh(node->Length);
        }
 
        return 0;
diff -r 73a00419e037 -r 4a0d24df133b sys/arch/arm/acpi/acpi_pci_n1sdp.c
--- a/sys/arch/arm/acpi/acpi_pci_n1sdp.c        Sun Sep 13 21:21:04 2020 +0000
+++ b/sys/arch/arm/acpi/acpi_pci_n1sdp.c        Sun Sep 13 21:41:17 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci_n1sdp.c,v 1.4 2020/06/17 06:45:09 thorpej Exp $ */
+/* $NetBSD: acpi_pci_n1sdp.c,v 1.5 2020/09/13 21:41:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_n1sdp.c,v 1.4 2020/06/17 06:45:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_n1sdp.c,v 1.5 2020/09/13 21:41:17 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -173,7 +173,7 @@
                aprint_debug_dev(ap->ap_dev, "N1SDP: RC @ 0x%08x, %d devices\n",
                    n1sdp_data[ap->ap_seg]->rc_base_addr, n1sdp_data[ap->ap_seg]->nr_bdfs);
                for (n = 0; n < n1sdp_data[ap->ap_seg]->nr_bdfs; n++) {
-                       const uint32_t bdf = n1sdp_data[ap->ap_seg]->valid_bdfs[n];
+                       const uint32_t bdf = le32toh(n1sdp_data[ap->ap_seg]->valid_bdfs[n]);
                        const int b = (bdf >> N1SDP_BUS_SHIFT) & 0xff;
                        const int d = (bdf >> N1SDP_DEV_SHIFT) & 0x1f;
                        const int f = (bdf >> N1SDP_FUNC_SHIFT) & 0x7;
diff -r 73a00419e037 -r 4a0d24df133b sys/arch/arm/acpi/acpi_platform.c
--- a/sys/arch/arm/acpi/acpi_platform.c Sun Sep 13 21:21:04 2020 +0000
+++ b/sys/arch/arm/acpi/acpi_platform.c Sun Sep 13 21:41:17 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_platform.c,v 1.18 2019/09/22 18:31:59 jmcneill Exp $ */
+/* $NetBSD: acpi_platform.c,v 1.19 2020/09/13 21:41:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.18 2019/09/22 18:31:59 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.19 2020/09/13 21:41:17 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -163,7 +163,7 @@
                }
 
                if (spcr->SerialPort.SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY &&
-                   spcr->SerialPort.Address != 0) {
+                   le64toh(spcr->SerialPort.Address) != 0) {
                        switch (spcr->InterfaceType) {
 #if NPLCOM > 0
                        case ACPI_DBG2_ARM_PL011:
@@ -171,7 +171,7 @@
                        case ACPI_DBG2_ARM_SBSA_GENERIC:
                                plcom_console.pi_type = PLCOM_TYPE_PL011;
                                plcom_console.pi_iot = &arm_generic_bs_tag;
-                               plcom_console.pi_iobase = spcr->SerialPort.Address;
+                               plcom_console.pi_iobase = le64toh(spcr->SerialPort.Address);
                                plcom_console.pi_size = PL011COM_UART_SIZE;
                                plcom_console.pi_flags = PLC_FLAG_32BIT_ACCESS;
 
@@ -182,15 +182,15 @@
                        case ACPI_DBG2_16550_COMPATIBLE:
                        case ACPI_DBG2_16550_SUBSET:
                                if (ACPI_ACCESS_BIT_WIDTH(spcr->SerialPort.AccessWidth) == 8) {
-                                       comcnattach(&arm_generic_bs_tag, spcr->SerialPort.Address, baud_rate, -1,
+                                       comcnattach(&arm_generic_bs_tag, le64toh(spcr->SerialPort.Address), baud_rate, -1,
                                            COM_TYPE_NORMAL, TTYDEF_CFLAG);
                                } else {
-                                       comcnattach(&arm_generic_a4x_bs_tag, spcr->SerialPort.Address, baud_rate, -1,
+                                       comcnattach(&arm_generic_a4x_bs_tag, le64toh(spcr->SerialPort.Address), baud_rate, -1,
                                            COM_TYPE_NORMAL, TTYDEF_CFLAG);
                                }
                                break;
                        case ACPI_DBG2_BCM2835:
-                               comcnattach(&arm_generic_a4x_bs_tag, spcr->SerialPort.Address + 0x40, baud_rate, -1,
+                               comcnattach(&arm_generic_a4x_bs_tag, le64toh(spcr->SerialPort.Address) + 0x40, baud_rate, -1,
                                    COM_TYPE_BCMAUXUART, TTYDEF_CFLAG);
                                cn_set_magic("+++++");
                                break;
@@ -207,8 +207,8 @@
         * Initialize PSCI 0.2+ if implemented
         */
        if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_FADT, (void **)&fadt))) {
-               if (fadt->ArmBootFlags & ACPI_FADT_PSCI_COMPLIANT) {
-                       if (fadt->ArmBootFlags & ACPI_FADT_PSCI_USE_HVC) {
+               if (le16toh(fadt->ArmBootFlags) & ACPI_FADT_PSCI_COMPLIANT) {
+                       if (le16toh(fadt->ArmBootFlags) & ACPI_FADT_PSCI_USE_HVC) {
                                psci_init(psci_call_hvc);
                        } else {
                                psci_init(psci_call_smc);
@@ -222,7 +222,7 @@
         * Count CPUs
         */
        if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_MADT, (void **)&madt))) {
-               char *end = (char *)madt + madt->Header.Length;
+               char *end = (char *)madt + le32toh(madt->Header.Length);
                char *where = (char *)madt + sizeof(ACPI_TABLE_MADT);
                while (where < end) {
                        ACPI_SUBTABLE_HEADER *subtable = (ACPI_SUBTABLE_HEADER *)where;
@@ -269,7 +269,7 @@
 
                if (spcr->SerialPort.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
                        goto spcr_unmap;
-               if (spcr->SerialPort.Address == 0)
+               if (le64toh(spcr->SerialPort.Address) == 0)
                        goto spcr_unmap;
                if (spcr->InterfaceType != ACPI_DBG2_16550_COMPATIBLE &&
                    spcr->InterfaceType != ACPI_DBG2_16550_SUBSET)
@@ -300,7 +300,7 @@
                        if (mem == NULL)
                                goto crs_cleanup;
 
-                       if (mem->ar_base == spcr->SerialPort.Address)
+                       if (mem->ar_base == le64toh(spcr->SerialPort.Address))
                                prop_dictionary_set_bool(prop, "force_console", true);
 
 crs_cleanup:
diff -r 73a00419e037 -r 4a0d24df133b sys/arch/arm/acpi/acpi_table.c
--- a/sys/arch/arm/acpi/acpi_table.c    Sun Sep 13 21:21:04 2020 +0000
+++ b/sys/arch/arm/acpi/acpi_table.c    Sun Sep 13 21:41:17 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_table.c,v 1.1 2018/10/12 22:15:04 jmcneill Exp $ */
+/* $NetBSD: acpi_table.c,v 1.2 2020/09/13 21:41:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_table.c,v 1.1 2018/10/12 22:15:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_table.c,v 1.2 2020/09/13 21:41:17 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -61,7 +61,8 @@
        rv = acpi_md_OsMapMemory(pa, sizeof(*header), (void **)&header);
        if (ACPI_FAILURE(rv))
                return rv;
-       length = header->Length;
+       length = le32toh(header->Length);
+
        acpi_md_OsUnmapMemory(header, sizeof(*header));
 
        return acpi_md_OsMapMemory(pa, length, hdrp);
@@ -70,7 +71,7 @@
 void
 acpi_table_unmap(ACPI_TABLE_HEADER *hdrp)
 {
-       acpi_md_OsUnmapMemory(hdrp, hdrp->Length);
+       acpi_md_OsUnmapMemory(hdrp, le32toh(hdrp->Length));
 }
 
 ACPI_STATUS
@@ -88,7 +89,7 @@
        if (ACPI_FAILURE(rv))
                return rv;
        if (memcmp(rsdp->Signature, ACPI_SIG_RSDP, sizeof(rsdp->Signature)) == 0)
-               pa = rsdp->XsdtPhysicalAddress;
+               pa = le64toh(rsdp->XsdtPhysicalAddress);
        acpi_md_OsUnmapMemory(rsdp, sizeof(*rsdp));
        if (pa == 0)
                return AE_NOT_FOUND;
@@ -97,13 +98,14 @@
        rv = acpi_table_map(pa, (void **)&xsdt);
        if (ACPI_FAILURE(rv))
                return rv;
-       const u_int entries = (xsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) / ACPI_XSDT_ENTRY_SIZE;
+       const u_int entries = (le32toh(xsdt->Header.Length) - sizeof(ACPI_TABLE_HEADER)) / ACPI_XSDT_ENTRY_SIZE;
        for (u_int n = 0; n < entries; n++) {
-               rv = acpi_table_map(xsdt->TableOffsetEntry[n], (void **)&header);
+               rv = acpi_table_map(le64toh(xsdt->TableOffsetEntry[n]), (void **)&header);
                if (ACPI_FAILURE(rv))
                        continue;
                if (memcmp(header->Signature, sig, sizeof(header->Signature)) == 0) {
                        acpi_table_unmap((ACPI_TABLE_HEADER *)xsdt);
+
                        *hdrp = header;
                        return AE_OK;
                }



Home | Main Index | Thread Index | Old Index