Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Fetch bus_dma tags when acpi devnodes are creat...



details:   https://anonhg.NetBSD.org/src/rev/56422dac2d03
branches:  trunk
changeset: 968003:56422dac2d03
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Dec 31 12:27:50 2019 +0000

description:
Fetch bus_dma tags when acpi devnodes are created. They do not change
and this allows MD code to create more complex tags without being
concerned with the tag being destroyed later. While here, capture
translations offsets for address32/address64 resources.

diffstat:

 sys/dev/acpi/acpi.c          |  49 ++++++++++++++++++++++++++-----------------
 sys/dev/acpi/acpi_resource.c |  24 +++++++++++++--------
 sys/dev/acpi/acpivar.h       |   7 ++++-
 3 files changed, 49 insertions(+), 31 deletions(-)

diffs (233 lines):

diff -r affca55dc7c4 -r 56422dac2d03 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c       Tue Dec 31 11:49:08 2019 +0000
+++ b/sys/dev/acpi/acpi.c       Tue Dec 31 12:27:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $      */
+/*     $NetBSD: acpi.c,v 1.282 2019/12/31 12:27:50 jmcneill Exp $      */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.282 2019/12/31 12:27:50 jmcneill Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -200,6 +200,7 @@
 
 static void            acpi_build_tree(struct acpi_softc *);
 static void            acpi_config_tree(struct acpi_softc *);
+static void            acpi_config_dma(struct acpi_softc *);
 static ACPI_STATUS     acpi_make_devnode(ACPI_HANDLE, uint32_t,
                                          void *, void **);
 static ACPI_STATUS     acpi_make_devnode_post(ACPI_HANDLE, uint32_t,
@@ -687,6 +688,10 @@
 static void
 acpi_config_tree(struct acpi_softc *sc)
 {
+       /*
+        * Assign bus_dma resources
+        */
+       acpi_config_dma(sc);
 
        /*
         * Configure all everything found "at acpi?".
@@ -707,6 +712,24 @@
        (void)config_defer(sc->sc_dev, acpi_rescan_capabilities);
 }
 
+static void
+acpi_config_dma(struct acpi_softc *sc)
+{
+       struct acpi_devnode *ad;
+
+       SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
+
+               if (ad->ad_device != NULL)
+                       continue;
+
+               if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
+                       continue;
+
+               ad->ad_dmat = acpi_get_dma_tag(sc, ad);
+               ad->ad_dmat64 = acpi_get_dma64_tag(sc, ad);
+       }
+}
+
 static ACPI_STATUS
 acpi_make_devnode(ACPI_HANDLE handle, uint32_t level,
     void *context, void **status)
@@ -895,18 +918,11 @@
                aa.aa_pc = sc->sc_pc;
                aa.aa_pciflags = sc->sc_pciflags;
                aa.aa_ic = sc->sc_ic;
-               aa.aa_dmat = acpi_get_dma_tag(sc, ad);
-               aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
+               aa.aa_dmat = ad->ad_dmat;
+               aa.aa_dmat64 = ad->ad_dmat64;
 
                ad->ad_device = config_found_ia(sc->sc_dev,
                    "acpinodebus", &aa, acpi_print);
-
-               if (ad->ad_device == NULL) {
-                       if (aa.aa_dmat != NULL)
-                               bus_dmatag_destroy(aa.aa_dmat);
-                       if (aa.aa_dmat64 != NULL)
-                               bus_dmatag_destroy(aa.aa_dmat64);
-               }
        }
 }
 
@@ -964,18 +980,11 @@
                aa.aa_pc = sc->sc_pc;
                aa.aa_pciflags = sc->sc_pciflags;
                aa.aa_ic = sc->sc_ic;
-               aa.aa_dmat = acpi_get_dma_tag(sc, ad);
-               aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
+               aa.aa_dmat = ad->ad_dmat;
+               aa.aa_dmat64 = ad->ad_dmat64;
 
                ad->ad_device = config_found_ia(sc->sc_dev,
                    "acpinodebus", &aa, acpi_print);
-
-               if (ad->ad_device == NULL) {
-                       if (aa.aa_dmat != NULL)
-                               bus_dmatag_destroy(aa.aa_dmat);
-                       if (aa.aa_dmat64 != NULL)
-                               bus_dmatag_destroy(aa.aa_dmat64);
-               }
        }
 }
 
diff -r affca55dc7c4 -r 56422dac2d03 sys/dev/acpi/acpi_resource.c
--- a/sys/dev/acpi/acpi_resource.c      Tue Dec 31 11:49:08 2019 +0000
+++ b/sys/dev/acpi/acpi_resource.c      Tue Dec 31 12:27:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $      */
+/*     $NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -147,7 +147,8 @@
                if (ops->memory)
                        (*ops->memory)(arg->dev, arg->context,
                            res->Data.FixedMemory32.Address,
-                           res->Data.FixedMemory32.AddressLength);
+                           res->Data.FixedMemory32.AddressLength,
+                           0);
                break;
 
        case ACPI_RESOURCE_TYPE_MEMORY32:
@@ -160,7 +161,8 @@
                        if (ops->memory)
                                (*ops->memory)(arg->dev, arg->context,
                                    res->Data.Memory32.Minimum,
-                                   res->Data.Memory32.AddressLength);
+                                   res->Data.Memory32.AddressLength,
+                                   0);
                } else {
                        ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
                                             "Memory32 0x%x-0x%x/%u\n",
@@ -186,7 +188,8 @@
                        if (ops->memory)
                                (*ops->memory)(arg->dev, arg->context,
                                    res->Data.Memory24.Minimum,
-                                   res->Data.Memory24.AddressLength);
+                                   res->Data.Memory24.AddressLength,
+                                   0);
                } else {
                        ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
                                             "Memory24 0x%x-0x%x/%u\n",
@@ -255,7 +258,8 @@
                                if (ops->memory)
                                        (*ops->memory)(arg->dev, arg->context,
                                            res->Data.Address32.Address.Minimum,
-                                           res->Data.Address32.Address.AddressLength);
+                                           res->Data.Address32.Address.AddressLength,
+                                           res->Data.Address32.Address.TranslationOffset);
                        } else {
                                if (ops->memrange)
                                        (*ops->memrange)(arg->dev, arg->context,
@@ -308,7 +312,8 @@
                                if (ops->memory)
                                        (*ops->memory)(arg->dev, arg->context,
                                            res->Data.Address64.Address.Minimum,
-                                           res->Data.Address64.Address.AddressLength);
+                                           res->Data.Address64.Address.AddressLength,
+                                           res->Data.Address64.Address.TranslationOffset);
                        } else {
                                if (ops->memrange)
                                        (*ops->memrange)(arg->dev, arg->context,
@@ -647,7 +652,7 @@
                    uint32_t, uint32_t, uint32_t);
 
 static void    acpi_res_parse_memory(device_t, void *, uint64_t,
-                   uint64_t);
+                   uint64_t, uint64_t);
 static void    acpi_res_parse_memrange(device_t, void *, uint64_t,
                    uint64_t, uint64_t, uint64_t);
 
@@ -797,7 +802,7 @@
 
 static void
 acpi_res_parse_memory(device_t dev, void *context, uint64_t base,
-    uint64_t length)
+    uint64_t length, uint64_t offset)
 {
        struct acpi_resources *res = context;
        struct acpi_mem *ar;
@@ -813,6 +818,7 @@
        ar->ar_index = res->ar_nmem++;
        ar->ar_base = base;
        ar->ar_length = length;
+       ar->ar_offset = offset;
 
        SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
 }
diff -r affca55dc7c4 -r 56422dac2d03 sys/dev/acpi/acpivar.h
--- a/sys/dev/acpi/acpivar.h    Tue Dec 31 11:49:08 2019 +0000
+++ b/sys/dev/acpi/acpivar.h    Tue Dec 31 12:27:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpivar.h,v 1.78 2019/12/29 23:47:56 jmcneill Exp $    */
+/*     $NetBSD: acpivar.h,v 1.79 2019/12/31 12:27:50 jmcneill Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -131,6 +131,8 @@
        uint32_t                 ad_flags;      /* Device flags */
        uint32_t                 ad_type;       /* Device type */
        int                      ad_state;      /* Device power state */
+       bus_dma_tag_t            ad_dmat;       /* Bus DMA tag for device */
+       bus_dma_tag_t            ad_dmat64;     /* Bus DMA tag for device (64-bit) */
 
        SIMPLEQ_ENTRY(acpi_devnode)     ad_list;
        SIMPLEQ_ENTRY(acpi_devnode)     ad_child_list;
@@ -224,6 +226,7 @@
        int             ar_index;
        bus_addr_t      ar_base;
        bus_size_t      ar_length;
+       bus_addr_t      ar_offset;
 };
 
 struct acpi_memrange {
@@ -282,7 +285,7 @@
        void    (*iorange)(device_t, void *, uint32_t, uint32_t,
                    uint32_t, uint32_t);
 
-       void    (*memory)(device_t, void *, uint64_t, uint64_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