mem-cache: Create an address aware TempCacheBlk
[gem5.git] / src / mem / abstract_mem.hh
index 42ad08e5c46a8d6b644a62d23f023018878b5d72..b57f73b4a53e7cb01aa128cbe5e2edf20df35d5a 100644 (file)
  * AbstractMemory declaration
  */
 
-#ifndef __ABSTRACT_MEMORY_HH__
-#define __ABSTRACT_MEMORY_HH__
+#ifndef __MEM_ABSTRACT_MEMORY_HH__
+#define __MEM_ABSTRACT_MEMORY_HH__
 
 #include "mem/mem_object.hh"
 #include "params/AbstractMemory.hh"
 #include "sim/stats.hh"
 
+
+class System;
+
+/**
+ * Locked address class that represents a physical address and a
+ * context id.
+ */
+class LockedAddr {
+
+  private:
+
+    // on alpha, minimum LL/SC granularity is 16 bytes, so lower
+    // bits need to masked off.
+    static const Addr Addr_Mask = 0xf;
+
+  public:
+
+    // locked address
+    Addr addr;
+
+    // locking hw context
+    const ContextID contextId;
+
+    static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
+
+    // check for matching execution context
+    bool matchesContext(Request *req) const
+    {
+        return (contextId == req->contextId());
+    }
+
+    LockedAddr(Request *req) : addr(mask(req->getPaddr())),
+                               contextId(req->contextId())
+    {}
+
+    // constructor for unserialization use
+    LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
+    {}
+};
+
 /**
  * An abstract memory represents a contiguous block of physical
  * memory, with an associated address range, and also provides basic
@@ -65,44 +105,19 @@ class AbstractMemory : public MemObject
   protected:
 
     // Address range of this memory
-    Range<Addr> range;
+    AddrRange range;
 
     // Pointer to host memory used to implement this memory
     uint8_t* pmemAddr;
 
     // Enable specific memories to be reported to the configuration table
-    bool confTableReported;
+    const bool confTableReported;
 
     // Should the memory appear in the global address map
-    bool inAddrMap;
-
-    class LockedAddr {
-
-      public:
-        // on alpha, minimum LL/SC granularity is 16 bytes, so lower
-        // bits need to masked off.
-        static const Addr Addr_Mask = 0xf;
+    const bool inAddrMap;
 
-        static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
-
-        Addr addr;      // locked address
-        int contextId;     // locking hw context
-
-        // check for matching execution context
-        bool matchesContext(Request *req)
-        {
-            return (contextId == req->contextId());
-        }
-
-        LockedAddr(Request *req) : addr(mask(req->getPaddr())),
-                                   contextId(req->contextId())
-        {
-        }
-        // constructor for unserialization use
-        LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
-        {
-        }
-    };
+    // Should KVM map this memory for the guest
+    const bool kvmMap;
 
     std::list<LockedAddr> lockedAddrList;
 
@@ -140,17 +155,17 @@ class AbstractMemory : public MemObject
     }
 
     /** Number of total bytes read from this memory */
-    Stats::Scalar bytesRead;
+    Stats::Vector bytesRead;
     /** Number of instruction bytes read from this memory */
-    Stats::Scalar bytesInstRead;
+    Stats::Vector bytesInstRead;
     /** Number of bytes written to this memory */
-    Stats::Scalar bytesWritten;
+    Stats::Vector bytesWritten;
     /** Number of read requests */
-    Stats::Scalar numReads;
+    Stats::Vector numReads;
     /** Number of write requests */
-    Stats::Scalar numWrites;
+    Stats::Vector numWrites;
     /** Number of other requests */
-    Stats::Scalar numOther;
+    Stats::Vector numOther;
     /** Read bandwidth from this memory */
     Stats::Formula bwRead;
     /** Read bandwidth from this memory */
@@ -160,6 +175,13 @@ class AbstractMemory : public MemObject
     /** Total bandwidth from this memory */
     Stats::Formula bwTotal;
 
+    /** Pointor to the System object.
+     * This is used for getting the number of masters in the system which is
+     * needed when registering stats
+     */
+    System *_system;
+
+
   private:
 
     // Prevent copying
@@ -173,7 +195,52 @@ class AbstractMemory : public MemObject
     typedef AbstractMemoryParams Params;
 
     AbstractMemory(const Params* p);
-    virtual ~AbstractMemory();
+    virtual ~AbstractMemory() {}
+
+    /**
+     * Initialise this memory.
+     */
+    void init() override;
+
+    /**
+     * See if this is a null memory that should never store data and
+     * always return zero.
+     *
+     * @return true if null
+     */
+    bool isNull() const { return params()->null; }
+
+    /**
+     * Set the host memory backing store to be used by this memory
+     * controller.
+     *
+     * @param pmem_addr Pointer to a segment of host memory
+     */
+    void setBackingStore(uint8_t* pmem_addr);
+
+    /**
+     * Get the list of locked addresses to allow checkpointing.
+     */
+    const std::list<LockedAddr>& getLockedAddrList() const
+    { return lockedAddrList; }
+
+    /**
+     * Add a locked address to allow for checkpointing.
+     */
+    void addLockedAddr(LockedAddr addr) { lockedAddrList.push_back(addr); }
+
+    /** read the system pointer
+     * Implemented for completeness with the setter
+     * @return pointer to the system object */
+    System* system() const { return _system; }
+
+    /** Set the system pointer on this memory
+     * This can't be done via a python parameter because the system needs
+     * pointers to all the memories and the reverse would create a cycle in the
+     * object graph. An init() this is set.
+     * @param sys system pointer to set
+     */
+    void system(System *sys) { _system = sys; }
 
     const Params *
     params() const
@@ -186,21 +253,21 @@ class AbstractMemory : public MemObject
      *
      * @return a single contigous address range
      */
-    Range<Addr> getAddrRange();
+    AddrRange getAddrRange() const;
 
     /**
      * Get the memory size.
      *
      * @return the size of the memory
      */
-    uint64_t size() { return range.size(); }
+    uint64_t size() const { return range.size(); }
 
     /**
      * Get the start address.
      *
      * @return the start address of the memory
      */
-    Addr start() { return range.start; }
+    Addr start() const { return range.start(); }
 
     /**
      *  Should this memory be passed to the kernel and part of the OS
@@ -218,6 +285,14 @@ class AbstractMemory : public MemObject
      */
     bool isInAddrMap() const { return inAddrMap; }
 
+    /**
+     * When shadow memories are in use, KVM may want to make one or the other,
+     * but cannot map both into the guest address space.
+     *
+     * @return if this memory should be mapped into the KVM guest address space
+     */
+    bool isKvmMap() const { return kvmMap; }
+
     /**
      * Perform an untimed memory access and update all the state
      * (e.g. locked addresses) and statistics accordingly. The packet
@@ -240,11 +315,8 @@ class AbstractMemory : public MemObject
     /**
      * Register Statistics
      */
-    virtual void regStats();
-
-    virtual void serialize(std::ostream &os);
-    virtual void unserialize(Checkpoint *cp, const std::string &section);
+    void regStats() override;
 
 };
 
-#endif //__ABSTRACT_MEMORY_HH__
+#endif //__MEM_ABSTRACT_MEMORY_HH__