]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - sim/bfin/dv-bfin_dma.c
gdb/doc: use POD2MAN5 when appropriate
[thirdparty/binutils-gdb.git] / sim / bfin / dv-bfin_dma.c
index 1af528b53edd95e4084bb177c8b9363348af5455..2978ae72697ce261c1f1cbc87bd7cf03a113fb23 100644 (file)
@@ -1,6 +1,6 @@
 /* Blackfin Direct Memory Access (DMA) Channel model.
 
-   Copyright (C) 2010-2011 Free Software Foundation, Inc.
+   Copyright (C) 2010-2024 Free Software Foundation, Inc.
    Contributed by Analog Devices, Inc.
 
    This file is part of simulators.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
+#include <stdlib.h>
 
 #include "sim-main.h"
 #include "devices.h"
@@ -135,17 +138,17 @@ bfin_dma_process_desc (struct hw *me, struct bfin_dma *dma)
     case DMAFLOW_ARRAY:
       if (ndsize == 0 || ndsize > 7)
        hw_abort (me, "DMA config error: DMAFLOW_ARRAY requires NDSIZE 1...7");
-      sim_read (hw_system (me), dma->curr_desc_ptr, (void *)flows, ndsize * 2);
+      sim_read (hw_system (me), dma->curr_desc_ptr, flows, ndsize * 2);
       break;
     case DMAFLOW_SMALL:
       if (ndsize == 0 || ndsize > 8)
        hw_abort (me, "DMA config error: DMAFLOW_SMALL requires NDSIZE 1...8");
-      sim_read (hw_system (me), dma->next_desc_ptr, (void *)flows, ndsize * 2);
+      sim_read (hw_system (me), dma->next_desc_ptr, flows, ndsize * 2);
       break;
     case DMAFLOW_LARGE:
       if (ndsize == 0 || ndsize > 9)
        hw_abort (me, "DMA config error: DMAFLOW_LARGE requires NDSIZE 1...9");
-      sim_read (hw_system (me), dma->next_desc_ptr, (void *)flows, ndsize * 2);
+      sim_read (hw_system (me), dma->next_desc_ptr, flows, ndsize * 2);
       break;
     default:
       hw_abort (me, "DMA config error: invalid DMAFLOW %#x", dma->config);
@@ -170,6 +173,7 @@ bfin_dma_process_desc (struct hw *me, struct bfin_dma *dma)
          dma->ndph = _flows[1];
          --ndsize;
          ++flows;
+         ATTRIBUTE_FALLTHROUGH;
        case DMAFLOW_SMALL:
          dma->ndpl = _flows[0];
          --ndsize;
@@ -255,7 +259,7 @@ bfin_dma_hw_event_callback (struct hw *me, void *data)
     /* XXX: This sucks performance wise.  */
     nr_bytes = dma->ele_size;
   else
-    nr_bytes = MIN (sizeof (buf), dma->curr_x_count * dma->ele_size);
+    nr_bytes = min (sizeof (buf), dma->curr_x_count * dma->ele_size);
 
   /* Pumping a chunk!  */
   bfin_peer->dma_master = me;
@@ -318,13 +322,17 @@ bfin_dma_io_write_buffer (struct hw *me, const void *source, int space,
   bu32 *value32p;
   void *valuep;
 
+  /* Invalid access mode is higher priority than missing register.  */
+  if (!dv_bfin_mmr_require_16_32 (me, addr, nr_bytes, true))
+    return 0;
+
   if (nr_bytes == 4)
     value = dv_load_4 (source);
   else
     value = dv_load_2 (source);
 
   mmr_off = addr % dma->base;
-  valuep = (void *)((unsigned long)dma + mmr_base() + mmr_off);
+  valuep = (void *)((uintptr_t)dma + mmr_base() + mmr_off);
   value16p = valuep;
   value32p = valuep;
 
@@ -345,7 +353,7 @@ bfin_dma_io_write_buffer (struct hw *me, const void *source, int space,
          if (nr_bytes == 4)
            *value32p = value;
          else
-          *value16p = value;
+           *value16p = value;
        }
       else
        HW_TRACE ((me, "discarding write while dma running"));
@@ -401,7 +409,7 @@ bfin_dma_io_write_buffer (struct hw *me, const void *source, int space,
     default:
       /* XXX: The HW lets the pad regions be read/written ...  */
       dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
-      break;
+      return 0;
     }
 
   return nr_bytes;
@@ -417,8 +425,12 @@ bfin_dma_io_read_buffer (struct hw *me, void *dest, int space,
   bu32 *value32p;
   void *valuep;
 
+  /* Invalid access mode is higher priority than missing register.  */
+  if (!dv_bfin_mmr_require_16_32 (me, addr, nr_bytes, false))
+    return 0;
+
   mmr_off = addr % dma->base;
-  valuep = (void *)((unsigned long)dma + mmr_base() + mmr_off);
+  valuep = (void *)((uintptr_t)dma + mmr_base() + mmr_off);
   value16p = valuep;
   value32p = valuep;