Gabe Black has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/18571 )

Change subject: mem, arm: Replace the pointer type in PortProxy with void *.
......................................................................

mem, arm: Replace the pointer type in PortProxy with void *.

The void * type is for pointers which point to an unknown type. We
should use that when handling anonymous buffers in the PortProxy
functions, instead of uint8_t * which points to bytes.

Importantly, C/C++ doesn't require you to do any casting to turn an
arbitrary pointer type into a void *. This will get rid of lots of
tedious, verbose casting throughout the code base.

Change-Id: Id1adecc283c866d8e24524efd64f37b079088bd9
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18571
Tested-by: kokoro <[email protected]>
Reviewed-by: Andreas Sandberg <[email protected]>
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
---
M src/mem/fs_translating_port_proxy.cc
M src/mem/fs_translating_port_proxy.hh
M src/mem/port_proxy.cc
M src/mem/port_proxy.hh
M src/mem/se_translating_port_proxy.cc
M src/mem/se_translating_port_proxy.hh
M src/mem/secure_port_proxy.cc
M src/mem/secure_port_proxy.hh
8 files changed, 35 insertions(+), 34 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  Andreas Sandberg: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/mem/fs_translating_port_proxy.cc b/src/mem/fs_translating_port_proxy.cc
index a21d328..2e17cbf 100644
--- a/src/mem/fs_translating_port_proxy.cc
+++ b/src/mem/fs_translating_port_proxy.cc
@@ -67,7 +67,7 @@
 }

 bool
-FSTranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const
+FSTranslatingPortProxy::tryReadBlob(Addr addr, void *p, int size) const
 {
     Addr paddr;
     for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done();
@@ -79,14 +79,14 @@
             paddr = TheISA::vtophys(gen.addr());

         PortProxy::readBlobPhys(paddr, 0, p, gen.size());
-        p += gen.size();
+        p = static_cast<uint8_t *>(p) + gen.size();
     }
     return true;
 }

 bool
 FSTranslatingPortProxy::tryWriteBlob(
-        Addr addr, const uint8_t *p, int size) const
+        Addr addr, const void *p, int size) const
 {
     Addr paddr;
     for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done();
@@ -98,7 +98,7 @@
             paddr = TheISA::vtophys(gen.addr());

         PortProxy::writeBlobPhys(paddr, 0, p, gen.size());
-        p += gen.size();
+        p = static_cast<const uint8_t *>(p) + gen.size();
     }
     return true;
 }
diff --git a/src/mem/fs_translating_port_proxy.hh b/src/mem/fs_translating_port_proxy.hh
index 5ae8700..78adf1a 100644
--- a/src/mem/fs_translating_port_proxy.hh
+++ b/src/mem/fs_translating_port_proxy.hh
@@ -85,11 +85,11 @@

     /** Version of tryReadblob that translates virt->phys and deals
       * with page boundries. */
-    bool tryReadBlob(Addr addr, uint8_t *p, int size) const override;
+    bool tryReadBlob(Addr addr, void *p, int size) const override;

     /** Version of tryWriteBlob that translates virt->phys and deals
       * with page boundries. */
- bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override;
+    bool tryWriteBlob(Addr addr, const void *p, int size) const override;

     /**
      * Fill size bytes starting at addr with byte value val.
diff --git a/src/mem/port_proxy.cc b/src/mem/port_proxy.cc
index 97eb67e..f56bfeb 100644
--- a/src/mem/port_proxy.cc
+++ b/src/mem/port_proxy.cc
@@ -43,7 +43,7 @@

 void
 PortProxy::readBlobPhys(Addr addr, Request::Flags flags,
-                        uint8_t *p, int size) const
+                        void *p, int size) const
 {
     for (ChunkGenerator gen(addr, size, _cacheLineSize); !gen.done();
          gen.next()) {
@@ -52,15 +52,15 @@
             gen.addr(), gen.size(), flags, Request::funcMasterId);

         Packet pkt(req, MemCmd::ReadReq);
-        pkt.dataStatic(p);
+        pkt.dataStatic(static_cast<uint8_t *>(p));
         _port.sendFunctional(&pkt);
-        p += gen.size();
+        p = static_cast<uint8_t *>(p) + gen.size();
     }
 }

 void
 PortProxy::writeBlobPhys(Addr addr, Request::Flags flags,
-                         const uint8_t *p, int size) const
+                         const void *p, int size) const
 {
     for (ChunkGenerator gen(addr, size, _cacheLineSize); !gen.done();
          gen.next()) {
@@ -69,9 +69,9 @@
             gen.addr(), gen.size(), flags, Request::funcMasterId);

         Packet pkt(req, MemCmd::WriteReq);
-        pkt.dataStaticConst(p);
+        pkt.dataStaticConst(static_cast<const uint8_t *>(p));
         _port.sendFunctional(&pkt);
-        p += gen.size();
+        p = static_cast<const uint8_t *>(p) + gen.size();
     }
 }

@@ -92,7 +92,7 @@
 PortProxy::tryWriteString(Addr addr, const char *str) const
 {
     do {
-        if (!tryWriteBlob(addr++, (uint8_t *)str, 1))
+        if (!tryWriteBlob(addr++, str, 1))
             return false;
     } while (*str++);
     return true;
diff --git a/src/mem/port_proxy.hh b/src/mem/port_proxy.hh
index dcc1905..096f826 100644
--- a/src/mem/port_proxy.hh
+++ b/src/mem/port_proxy.hh
@@ -100,13 +100,13 @@
      * Read size bytes memory at physical address and store in p.
      */
     void readBlobPhys(Addr addr, Request::Flags flags,
-                      uint8_t* p, int size) const;
+                      void *p, int size) const;

     /**
      * Write size bytes from p to physical address.
      */
     void writeBlobPhys(Addr addr, Request::Flags flags,
-                       const uint8_t* p, int size) const;
+                       const void *p, int size) const;

     /**
      * Fill size bytes starting at physical addr with byte value val.
@@ -123,7 +123,7 @@
      * Returns true on success and false on failure.
      */
     virtual bool
-    tryReadBlob(Addr addr, uint8_t *p, int size) const
+    tryReadBlob(Addr addr, void *p, int size) const
     {
         readBlobPhys(addr, 0, p, size);
         return true;
@@ -134,7 +134,7 @@
      * Returns true on success and false on failure.
      */
     virtual bool
-    tryWriteBlob(Addr addr, const uint8_t *p, int size) const
+    tryWriteBlob(Addr addr, const void *p, int size) const
     {
         writeBlobPhys(addr, 0, p, size);
         return true;
@@ -159,7 +159,7 @@
      * Same as tryReadBlob, but insists on success.
      */
     void
-    readBlob(Addr addr, uint8_t* p, int size) const
+    readBlob(Addr addr, void *p, int size) const
     {
         if (!tryReadBlob(addr, p, size))
             fatal("readBlob(%#x, ...) failed", addr);
@@ -169,7 +169,7 @@
      * Same as tryWriteBlob, but insists on success.
      */
     void
-    writeBlob(Addr addr, const uint8_t* p, int size) const
+    writeBlob(Addr addr, const void *p, int size) const
     {
         if (!tryWriteBlob(addr, p, size))
             fatal("writeBlob(%#x, ...) failed", addr);
@@ -250,7 +250,7 @@
 PortProxy::read(Addr address) const
 {
     T data;
-    readBlob(address, (uint8_t*)&data, sizeof(T));
+    readBlob(address, &data, sizeof(T));
     return data;
 }

@@ -258,7 +258,7 @@
 void
 PortProxy::write(Addr address, T data) const
 {
-    writeBlob(address, (uint8_t*)&data, sizeof(T));
+    writeBlob(address, &data, sizeof(T));
 }

 template <typename T>
@@ -266,7 +266,7 @@
 PortProxy::read(Addr address, ByteOrder byte_order) const
 {
     T data;
-    readBlob(address, (uint8_t*)&data, sizeof(T));
+    readBlob(address, &data, sizeof(T));
     return gtoh(data, byte_order);
 }

@@ -275,7 +275,7 @@
 PortProxy::write(Addr address, T data, ByteOrder byte_order) const
 {
     data = htog(data, byte_order);
-    writeBlob(address, (uint8_t*)&data, sizeof(T));
+    writeBlob(address, &data, sizeof(T));
 }

 #endif // __MEM_PORT_PROXY_HH__
diff --git a/src/mem/se_translating_port_proxy.cc b/src/mem/se_translating_port_proxy.cc
index de5335a..c5f38f1 100644
--- a/src/mem/se_translating_port_proxy.cc
+++ b/src/mem/se_translating_port_proxy.cc
@@ -62,9 +62,10 @@
 { }

 bool
-SETranslatingPortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const
+SETranslatingPortProxy::tryReadBlob(Addr addr, void *p, int size) const
 {
     int prevSize = 0;
+    auto *bytes = static_cast<uint8_t *>(p);

for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
         Addr paddr;
@@ -72,7 +73,7 @@
         if (!pTable->translate(gen.addr(),paddr))
             return false;

-        PortProxy::readBlobPhys(paddr, 0, p + prevSize, gen.size());
+        PortProxy::readBlobPhys(paddr, 0, bytes + prevSize, gen.size());
         prevSize += gen.size();
     }

@@ -81,10 +82,10 @@


 bool
-SETranslatingPortProxy::tryWriteBlob(Addr addr, const uint8_t *p,
-                                     int size) const
+SETranslatingPortProxy::tryWriteBlob(Addr addr, const void *p, int size) const
 {
     int prevSize = 0;
+    auto *bytes = static_cast<const uint8_t *>(p);

for (ChunkGenerator gen(addr, size, PageBytes); !gen.done(); gen.next()) {
         Addr paddr;
@@ -104,7 +105,7 @@
             pTable->translate(gen.addr(), paddr);
         }

-        PortProxy::writeBlobPhys(paddr, 0, p + prevSize, gen.size());
+        PortProxy::writeBlobPhys(paddr, 0, bytes + prevSize, gen.size());
         prevSize += gen.size();
     }

diff --git a/src/mem/se_translating_port_proxy.hh b/src/mem/se_translating_port_proxy.hh
index 1c8828b..718e44a 100644
--- a/src/mem/se_translating_port_proxy.hh
+++ b/src/mem/se_translating_port_proxy.hh
@@ -85,8 +85,8 @@

     void setPageTable(EmulationPageTable *p) { pTable = p; }
     void setProcess(Process *p) { process = p; }
-    bool tryReadBlob(Addr addr, uint8_t *p, int size) const override;
- bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override;
+    bool tryReadBlob(Addr addr, void *p, int size) const override;
+    bool tryWriteBlob(Addr addr, const void *p, int size) const override;
     bool tryMemsetBlob(Addr addr, uint8_t val, int size) const override;
 };

diff --git a/src/mem/secure_port_proxy.cc b/src/mem/secure_port_proxy.cc
index 645baa9..01195f4 100644
--- a/src/mem/secure_port_proxy.cc
+++ b/src/mem/secure_port_proxy.cc
@@ -40,14 +40,14 @@
 #include "mem/secure_port_proxy.hh"

 bool
-SecurePortProxy::tryReadBlob(Addr addr, uint8_t *p, int size) const
+SecurePortProxy::tryReadBlob(Addr addr, void *p, int size) const
 {
     readBlobPhys(addr, Request::SECURE, p, size);
     return true;
 }

 bool
-SecurePortProxy::tryWriteBlob(Addr addr, const uint8_t *p, int size) const
+SecurePortProxy::tryWriteBlob(Addr addr, const void *p, int size) const
 {
     writeBlobPhys(addr, Request::SECURE, p, size);
     return true;
diff --git a/src/mem/secure_port_proxy.hh b/src/mem/secure_port_proxy.hh
index 0323312..9a2200c 100644
--- a/src/mem/secure_port_proxy.hh
+++ b/src/mem/secure_port_proxy.hh
@@ -73,8 +73,8 @@
     SecurePortProxy(MasterPort &port, unsigned int cache_line_size)
         : PortProxy(port, cache_line_size) {}

-    bool tryReadBlob(Addr addr, uint8_t *p, int size) const override;
- bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const override;
+    bool tryReadBlob(Addr addr, void *p, int size) const override;
+    bool tryWriteBlob(Addr addr, const void *p, int size) const override;
     bool tryMemsetBlob(Addr addr, uint8_t val, int size) const override;
 };


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/18571
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Id1adecc283c866d8e24524efd64f37b079088bd9
Gerrit-Change-Number: 18571
Gerrit-PatchSet: 6
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Anthony Gutierrez <[email protected]>
Gerrit-Reviewer: Brandon Potter <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to