Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Rely on 32/64-bit overflow to calculate transla...



details:   https://anonhg.NetBSD.org/src/rev/acaa0be2255f
branches:  trunk
changeset: 968012:acaa0be2255f
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Dec 31 17:26:04 2019 +0000

description:
Rely on 32/64-bit overflow to calculate translation offsets. Store this
as a separate ar_xbase field in acpi_mem instead of having separate
ar_offset and ar_decode fields.

diffstat:

 sys/arch/arm/acpi/acpi_machdep.c |  15 ++++++---------
 sys/dev/acpi/acpi_resource.c     |  25 ++++++++++++-------------
 sys/dev/acpi/acpivar.h           |   8 +++-----
 3 files changed, 21 insertions(+), 27 deletions(-)

diffs (167 lines):

diff -r ab4a366ac828 -r acaa0be2255f sys/arch/arm/acpi/acpi_machdep.c
--- a/sys/arch/arm/acpi/acpi_machdep.c  Tue Dec 31 15:07:22 2019 +0000
+++ b/sys/arch/arm/acpi/acpi_machdep.c  Tue Dec 31 17:26:04 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_machdep.c,v 1.17 2019/12/31 13:54:22 jmcneill Exp $ */
+/* $NetBSD: acpi_machdep.c,v 1.18 2019/12/31 17:26:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "pci.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.17 2019/12/31 13:54:22 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.18 2019/12/31 17:26:04 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -438,20 +438,17 @@
        for (n = 0; n < res.ar_nmem; n++) {
                mem = acpi_res_mem(&res, n);
                dmat->_ranges[n].dr_busbase = mem->ar_base;
-               dmat->_ranges[n].dr_sysbase = mem->ar_base;
-               if (mem->ar_decode == ACPI_POS_DECODE)
-                       dmat->_ranges[n].dr_sysbase += mem->ar_offset;
-               else
-                       dmat->_ranges[n].dr_sysbase -= mem->ar_offset;
+               dmat->_ranges[n].dr_sysbase = mem->ar_xbase;
                dmat->_ranges[n].dr_len = mem->ar_length;
                dmat->_ranges[n].dr_flags = flags;
 
                aprint_debug_dev(sc->sc_dev,
-                   "%s: DMA sysbase %#lx busbase %#lx len %#lx%s\n",
+                   "%s: DMA sys %#lx-%#lx bus %#lx-%#lx%s\n",
                    acpi_name(ad->ad_handle),
                    dmat->_ranges[n].dr_sysbase,
+                   dmat->_ranges[n].dr_sysbase + dmat->_ranges[n].dr_len - 1,
                    dmat->_ranges[n].dr_busbase,
-                   dmat->_ranges[n].dr_len,
+                   dmat->_ranges[n].dr_busbase + dmat->_ranges[n].dr_len - 1,
                    flags ? " (coherent)" : "");
        }
 
diff -r ab4a366ac828 -r acaa0be2255f sys/dev/acpi/acpi_resource.c
--- a/sys/dev/acpi/acpi_resource.c      Tue Dec 31 15:07:22 2019 +0000
+++ b/sys/dev/acpi/acpi_resource.c      Tue Dec 31 17:26:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_resource.c,v 1.40 2019/12/31 13:39:15 jmcneill Exp $      */
+/*     $NetBSD: acpi_resource.c,v 1.41 2019/12/31 17:26:04 jmcneill Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.40 2019/12/31 13:39:15 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.41 2019/12/31 17:26:04 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -148,7 +148,7 @@
                        (*ops->memory)(arg->dev, arg->context,
                            res->Data.FixedMemory32.Address,
                            res->Data.FixedMemory32.AddressLength,
-                           0, 0);
+                           res->Data.FixedMemory32.Address);
                break;
 
        case ACPI_RESOURCE_TYPE_MEMORY32:
@@ -162,7 +162,7 @@
                                (*ops->memory)(arg->dev, arg->context,
                                    res->Data.Memory32.Minimum,
                                    res->Data.Memory32.AddressLength,
-                                   0, 0);
+                                   res->Data.Memory32.Minimum);
                } else {
                        ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
                                             "Memory32 0x%x-0x%x/%u\n",
@@ -189,7 +189,7 @@
                                (*ops->memory)(arg->dev, arg->context,
                                    res->Data.Memory24.Minimum,
                                    res->Data.Memory24.AddressLength,
-                                   0, 0);
+                                   res->Data.Memory24.Minimum);
                } else {
                        ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
                                             "Memory24 0x%x-0x%x/%u\n",
@@ -259,8 +259,8 @@
                                        (*ops->memory)(arg->dev, arg->context,
                                            res->Data.Address32.Address.Minimum,
                                            res->Data.Address32.Address.AddressLength,
-                                           res->Data.Address32.Address.TranslationOffset,
-                                           res->Data.Address32.Decode);
+                                           res->Data.Address32.Address.Minimum +
+                                               res->Data.Address32.Address.TranslationOffset);
                        } else {
                                if (ops->memrange)
                                        (*ops->memrange)(arg->dev, arg->context,
@@ -314,8 +314,8 @@
                                        (*ops->memory)(arg->dev, arg->context,
                                            res->Data.Address64.Address.Minimum,
                                            res->Data.Address64.Address.AddressLength,
-                                           res->Data.Address64.Address.TranslationOffset,
-                                           res->Data.Address64.Decode);
+                                           res->Data.Address64.Address.Minimum +
+                                               res->Data.Address64.Address.TranslationOffset);
                        } else {
                                if (ops->memrange)
                                        (*ops->memrange)(arg->dev, arg->context,
@@ -654,7 +654,7 @@
                    uint32_t, uint32_t, uint32_t);
 
 static void    acpi_res_parse_memory(device_t, void *, uint64_t,
-                   uint64_t, uint64_t, uint8_t);
+                   uint64_t, uint64_t);
 static void    acpi_res_parse_memrange(device_t, void *, uint64_t,
                    uint64_t, uint64_t, uint64_t);
 
@@ -804,7 +804,7 @@
 
 static void
 acpi_res_parse_memory(device_t dev, void *context, uint64_t base,
-    uint64_t length, uint64_t offset, uint8_t decode)
+    uint64_t length, uint64_t xbase)
 {
        struct acpi_resources *res = context;
        struct acpi_mem *ar;
@@ -820,8 +820,7 @@
        ar->ar_index = res->ar_nmem++;
        ar->ar_base = base;
        ar->ar_length = length;
-       ar->ar_offset = offset;
-       ar->ar_decode = decode;
+       ar->ar_xbase = xbase;
 
        SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
 }
diff -r ab4a366ac828 -r acaa0be2255f sys/dev/acpi/acpivar.h
--- a/sys/dev/acpi/acpivar.h    Tue Dec 31 15:07:22 2019 +0000
+++ b/sys/dev/acpi/acpivar.h    Tue Dec 31 17:26:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpivar.h,v 1.80 2019/12/31 13:39:15 jmcneill Exp $    */
+/*     $NetBSD: acpivar.h,v 1.81 2019/12/31 17:26:04 jmcneill Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -226,8 +226,7 @@
        int             ar_index;
        bus_addr_t      ar_base;
        bus_size_t      ar_length;
-       bus_addr_t      ar_offset;
-       uint8_t         ar_decode;
+       bus_addr_t      ar_xbase;       /* translated base address */
 };
 
 struct acpi_memrange {
@@ -286,8 +285,7 @@
        void    (*iorange)(device_t, void *, uint32_t, uint32_t,
                    uint32_t, uint32_t);
 
-       void    (*memory)(device_t, void *, uint64_t, uint64_t,
-                   uint64_t, uint8_t);
+       void    (*memory)(device_t, void *, uint64_t, uint64_t, uint64_t);
        void    (*memrange)(device_t, void *, uint64_t, uint64_t,
                    uint64_t, uint64_t);
 



Home | Main Index | Thread Index | Old Index