[haiku-commits] haiku: hrev56205 - src/libs/compat/freebsd_network

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 21 Jun 2022 16:24:37 +0000 (UTC)

hrev56205 adds 2 changesets to branch 'master'
old head: e866d6e941e9412832f1a03e55a0363483371ad5
new head: c27c987075417a7d197bd74f80d7d97a3b79d421
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=c27c98707541+%5Ee866d6e941e9

----------------------------------------------------------------------------

2c81f8808506: freebsd_network: Clean up bus_dma restrictions implementation.
  
   * Remove support for filters (again): they are deprecated in FreeBSD
     and no driver we have uses them. This allows the loop in the
     _validate_address function to be dropped entirely.
  
   * Clean up parent tag handling logic.

c27c98707541: freebsd_network: Fix address restriction computation in bus_dma.
  
  The min/max usage was reversd from what it should be. This
  would have led to the least restrictive restrictions being the
  ones that were checked, instead of the most restrictive.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

1 file changed, 19 insertions(+), 33 deletions(-)
src/libs/compat/freebsd_network/bus_dma.cpp | 52 +++++++++----------------

############################################################################

Commit:      2c81f8808506893f38db4c8730d6c13a195421a8
URL:         https://git.haiku-os.org/haiku/commit/?id=2c81f8808506
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Tue Jun 21 16:22:18 2022 UTC

freebsd_network: Clean up bus_dma restrictions implementation.

 * Remove support for filters (again): they are deprecated in FreeBSD
   and no driver we have uses them. This allows the loop in the
   _validate_address function to be dropped entirely.

 * Clean up parent tag handling logic.

----------------------------------------------------------------------------

diff --git a/src/libs/compat/freebsd_network/bus_dma.cpp 
b/src/libs/compat/freebsd_network/bus_dma.cpp
index a65fbcd793..34f39d0da0 100644
--- a/src/libs/compat/freebsd_network/bus_dma.cpp
+++ b/src/libs/compat/freebsd_network/bus_dma.cpp
@@ -36,9 +36,6 @@ struct bus_dma_tag {
        phys_addr_t             lowaddr;
        phys_addr_t             highaddr;
 
-       bus_dma_filter_t* filter;
-       void*                   filterarg;
-
        phys_size_t             maxsize;
        uint32                  maxsegments;
        phys_size_t             maxsegsz;
@@ -96,23 +93,25 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t 
alignment, bus_addr_t bounda
        void* filterarg, bus_size_t maxsize, int nsegments, bus_size_t maxsegsz,
        int flags, bus_dma_lock_t* lockfunc, void* lockfuncarg, bus_dma_tag_t* 
dmat)
 {
-       if (boundary != 0 && boundary < maxsegsz)
-               maxsegsz = boundary;
-
-       *dmat = NULL;
+       if (maxsegsz == 0)
+               return EINVAL;
+       if (filter != NULL) {
+               panic("bus_dma_tag_create: error: filters not supported!");
+               return EOPNOTSUPP;
+       }
 
        bus_dma_tag_t newtag = (bus_dma_tag_t)kernel_malloc(sizeof(*newtag),
                M_DEVBUF, M_ZERO | M_NOWAIT);
        if (newtag == NULL)
                return ENOMEM;
 
-       newtag->parent = parent;
+       if (boundary != 0 && boundary < maxsegsz)
+               maxsegsz = boundary;
+
        newtag->alignment = alignment;
        newtag->boundary = boundary;
        newtag->lowaddr = lowaddr;
        newtag->highaddr = highaddr;
-       newtag->filter = filter;
-       newtag->filterarg = filterarg;
        newtag->maxsize = maxsize;
        newtag->maxsegments = nsegments;
        newtag->maxsegsz = maxsegsz;
@@ -122,7 +121,8 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t 
alignment, bus_addr_t bounda
 
        // lockfunc is only needed if callbacks will be invoked asynchronously.
 
-       if (newtag->parent != NULL) {
+       if (parent != NULL) {
+               newtag->parent = parent;
                atomic_add(&parent->ref_count, 1);
 
                newtag->lowaddr = max_c(parent->lowaddr, newtag->lowaddr);
@@ -132,12 +132,7 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t 
alignment, bus_addr_t bounda
                if (newtag->boundary == 0) {
                        newtag->boundary = parent->boundary;
                } else if (parent->boundary != 0) {
-                       newtag->boundary = min_c(parent->boundary, 
newtag->boundary);
-               }
-
-               if (newtag->filter == NULL) {
-                       newtag->filter = parent->filter;
-                       newtag->filterarg = parent->filterarg;
+                       newtag->boundary = MIN(parent->boundary, 
newtag->boundary);
                }
        }
 
@@ -312,19 +307,10 @@ bus_dmamem_free(bus_dma_tag_t dmat, void* vaddr, 
bus_dmamap_t map)
 static bool
 _validate_address(bus_dma_tag_t dmat, bus_addr_t paddr, bool 
validate_alignment = true)
 {
-       do {
-               if (dmat->filter != NULL) {
-                       if ((*dmat->filter)(dmat->filterarg, paddr) != 0)
-                               return false;
-               } else {
-                       if (paddr > dmat->lowaddr && paddr <= dmat->highaddr)
-                               return false;
-                       if (validate_alignment && !vm_addr_align_ok(paddr, 
dmat->alignment))
-                               return false;
-               }
-
-               dmat = dmat->parent;
-       } while (dmat != NULL);
+       if (paddr > dmat->lowaddr && paddr <= dmat->highaddr)
+               return false;
+       if (validate_alignment && !vm_addr_align_ok(paddr, dmat->alignment))
+               return false;
 
        return true;
 }

############################################################################

Revision:    hrev56205
Commit:      c27c987075417a7d197bd74f80d7d97a3b79d421
URL:         https://git.haiku-os.org/haiku/commit/?id=c27c98707541
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Tue Jun 21 16:23:07 2022 UTC

freebsd_network: Fix address restriction computation in bus_dma.

The min/max usage was reversd from what it should be. This
would have led to the least restrictive restrictions being the
ones that were checked, instead of the most restrictive.

----------------------------------------------------------------------------

diff --git a/src/libs/compat/freebsd_network/bus_dma.cpp 
b/src/libs/compat/freebsd_network/bus_dma.cpp
index 34f39d0da0..0aedf9b4cc 100644
--- a/src/libs/compat/freebsd_network/bus_dma.cpp
+++ b/src/libs/compat/freebsd_network/bus_dma.cpp
@@ -125,9 +125,9 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t 
alignment, bus_addr_t bounda
                newtag->parent = parent;
                atomic_add(&parent->ref_count, 1);
 
-               newtag->lowaddr = max_c(parent->lowaddr, newtag->lowaddr);
-               newtag->highaddr = min_c(parent->highaddr, newtag->highaddr);
-               newtag->alignment = max_c(parent->alignment, newtag->alignment);
+               newtag->lowaddr = MIN(parent->lowaddr, newtag->lowaddr);
+               newtag->highaddr = MAX(parent->highaddr, newtag->highaddr);
+               newtag->alignment = MAX(parent->alignment, newtag->alignment);
 
                if (newtag->boundary == 0) {
                        newtag->boundary = parent->boundary;


Other related posts:

  • » [haiku-commits] haiku: hrev56205 - src/libs/compat/freebsd_network - waddlesplash