util: Make the device file name used by map_m5_mem overridable.
authorGabe Black <gabeblack@google.com>
Sun, 5 Apr 2020 09:39:33 +0000 (02:39 -0700)
committerGabe Black <gabeblack@google.com>
Fri, 24 Jul 2020 03:59:41 +0000 (03:59 +0000)
The name this function uses is now exposed as a global variable called
m5_mmap_dev which can be changed at run time.

This would be useful if using a non-standard location for /dev/mem, or
for testing where we might want to use a totally different device.

Change-Id: I5e7ac106c3e4e0555c99af2a7a0aca8171534451
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27556
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Pouya Fotouhi <pfotouhi@ucdavis.edu>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
util/m5/src/m5_mmap.c
util/m5/src/m5_mmap.h

index 4a5aa0f559fa9fac6e3cc6a2cdcea9cffe7553cd..d3413031d4aa431b6f2a3431afca180458dab497 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -54,21 +56,23 @@ void *m5_mem = NULL;
 #endif
 uint64_t m5op_addr = M5OP_ADDR;
 
+const char *m5_mmap_dev = "/dev/mem";
+
 void
 map_m5_mem()
 {
     int fd;
 
-    fd = open("/dev/mem", O_RDWR | O_SYNC);
+    fd = open(m5_mmap_dev, O_RDWR | O_SYNC);
     if (fd == -1) {
-        perror("Can't open /dev/mem");
+        fprintf(stderr, "Can't open %s: %s\n", m5_mmap_dev, strerror(errno));
         exit(1);
     }
 
     m5_mem = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
                   m5op_addr);
     if (!m5_mem) {
-        perror("Can't mmap /dev/mem");
+        fprintf(stderr, "Can't map %s: %s\n", m5_mmap_dev, strerror(errno));
         exit(1);
     }
 }
index d7fe19b3dcfa6f442e1ff96b7eb0ba7761483c6c..09cddb29c66384f2edd0fb93bb101b2891253bba 100644 (file)
@@ -49,7 +49,7 @@ extern "C" {
 
 extern void *m5_mem;
 extern uint64_t m5op_addr;
-
+extern const char *m5_mmap_dev;
 void map_m5_mem();
 
 #ifdef __cplusplus