From 87cf5a99ee686dc947cf21d08b2655d3b70437ee Mon Sep 17 00:00:00 2001
From: Gabe Black <gabeblack@google.com>
Date: Sat, 7 Mar 2020 15:51:50 -0800
Subject: [PATCH] mem: Remove a check that the memory size is a multiple of the
 page size.

There are a few problems with this check.

1. Many ISAs support multiple page sizes.
2. Memories (particularly small ROMs) may not actually be in multiples
   of the page size.
3. In a heterogenous environment, there won't be a single page size even
   if each ISA picks a canonical page size.
4. Other than catching some egregious configuration mistakes, there's
   nothing functionally wrong/different about a memory that isn't evenly
   coverable in pages, especially in systems or configurations that
   don't even use paging.

Change-Id: I3cd241657318d2e3fd5a1226cb54fdebbf172788
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26423
Maintainer: Gabe Black <gabeblack@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: Gem5 Cloud Project GCB service account <345032938727@cloudbuild.gserviceaccount.com>
---
 src/mem/abstract_mem.cc | 12 +++---------
 src/mem/abstract_mem.hh |  5 -----
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/src/mem/abstract_mem.cc b/src/mem/abstract_mem.cc
index 927fd0245..b5412badf 100644
--- a/src/mem/abstract_mem.cc
+++ b/src/mem/abstract_mem.cc
@@ -61,15 +61,9 @@ AbstractMemory::AbstractMemory(const Params *p) :
     kvmMap(p->kvm_map), _system(NULL),
     stats(*this)
 {
-}
-
-void
-AbstractMemory::init()
-{
-    assert(system());
-
-    if (size() % _system->getPageBytes() != 0)
-        panic("Memory Size not divisible by page size\n");
+    panic_if(!range.valid() || !range.size(),
+             "Memory range %s must be valid with non-zero size.",
+             range.to_string());
 }
 
 void
diff --git a/src/mem/abstract_mem.hh b/src/mem/abstract_mem.hh
index c8aef702d..b1d54fdeb 100644
--- a/src/mem/abstract_mem.hh
+++ b/src/mem/abstract_mem.hh
@@ -209,11 +209,6 @@ class AbstractMemory : public ClockedObject
     AbstractMemory(const Params* p);
     virtual ~AbstractMemory() {}
 
-    /**
-     * Initialise this memory.
-     */
-    void init() override;
-
     /**
      * See if this is a null memory that should never store data and
      * always return zero.
-- 
2.30.2