gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
abstract_mem.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2019 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2001-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
46 #ifndef __MEM_ABSTRACT_MEMORY_HH__
47 #define __MEM_ABSTRACT_MEMORY_HH__
48 
49 #include "mem/backdoor.hh"
50 #include "mem/port.hh"
51 #include "params/AbstractMemory.hh"
52 #include "sim/clocked_object.hh"
53 #include "sim/stats.hh"
54 
55 namespace gem5
56 {
57 
58 class System;
59 
60 namespace memory
61 {
62 
68 {
69 
70  private:
71 
72  // on alpha, minimum LL/SC granularity is 16 bytes, so lower
73  // bits need to masked off.
74  static const Addr Addr_Mask = 0xf;
75 
76  public:
77 
78  // locked address
80 
81  // locking hw context
83 
84  static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
85 
86  // check for matching execution context
87  bool matchesContext(const RequestPtr &req) const
88  {
89  assert(contextId != InvalidContextID);
90  assert(req->hasContextId());
91  return (contextId == req->contextId());
92  }
93 
94  LockedAddr(const RequestPtr &req) : addr(mask(req->getPaddr())),
95  contextId(req->contextId())
96  {}
97 
98  // constructor for unserialization use
99  LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
100  {}
101 };
102 
111 {
112  protected:
113 
114  // Address range of this memory
116 
117  // Pointer to host memory used to implement this memory
118  uint8_t* pmemAddr;
119 
120  // Backdoor to access this memory.
122 
123  // Enable specific memories to be reported to the configuration table
124  const bool confTableReported;
125 
126  // Should the memory appear in the global address map
127  const bool inAddrMap;
128 
129  // Should KVM map this memory for the guest
130  const bool kvmMap;
131 
132  // Are writes allowed to this memory
133  const bool writeable;
134 
136 
137  // helper function for checkLockedAddrs(): we really want to
138  // inline a quick check for an empty locked addr list (hopefully
139  // the common case), and do the full list search (if necessary) in
140  // this out-of-line function
141  bool checkLockedAddrList(PacketPtr pkt);
142 
143  // Record the address of a load-locked operation so that we can
144  // clear the execution context's lock flag if a matching store is
145  // performed
146  void trackLoadLocked(PacketPtr pkt);
147 
148  // Compare a store address with any locked addresses so we can
149  // clear the lock flag appropriately. Return value set to 'false'
150  // if store operation should be suppressed (because it was a
151  // conditional store and the address was no longer locked by the
152  // requesting execution context), 'true' otherwise. Note that
153  // this method must be called on *all* stores since even
154  // non-conditional stores must clear any matching lock addresses.
155  bool
157  {
158  const RequestPtr &req = pkt->req;
159  if (!writeable)
160  return false;
161  if (lockedAddrList.empty()) {
162  // no locked addrs: nothing to check, store_conditional fails
163  bool isLLSC = pkt->isLLSC();
164  if (isLLSC) {
165  req->setExtraData(0);
166  }
167  return !isLLSC; // only do write if not an sc
168  } else {
169  // iterate over list...
170  return checkLockedAddrList(pkt);
171  }
172  }
173 
179 
180  struct MemStats : public statistics::Group
181  {
183 
184  void regStats() override;
185 
187 
208  } stats;
209 
210 
211  private:
212 
213  // Prevent copying
215 
216  // Prevent assignment
218 
219  public:
220 
222 
223  AbstractMemory(const Params &p);
224  virtual ~AbstractMemory() {}
225 
226  void initState() override;
227 
234  bool isNull() const { return params().null; }
235 
242  void setBackingStore(uint8_t* pmem_addr);
243 
244  void
246  {
247  if (lockedAddrList.empty() && backdoor.ptr())
248  bd_ptr = &backdoor;
249  }
250 
254  const std::list<LockedAddr> &
256  {
257  return lockedAddrList;
258  }
259 
263  void
265  {
267  lockedAddrList.push_back(addr);
268  }
269 
273  System* system() const { return _system; }
274 
281  void system(System *sys) { _system = sys; }
282 
288  AddrRange getAddrRange() const;
289 
297  inline uint8_t *
299  {
300  return pmemAddr + addr - range.start();
301  }
302 
308  uint64_t size() const { return range.size(); }
309 
315  Addr start() const { return range.start(); }
316 
323  bool isConfReported() const { return confTableReported; }
324 
331  bool isInAddrMap() const { return inAddrMap; }
332 
339  bool isKvmMap() const { return kvmMap; }
340 
348  void access(PacketPtr pkt);
349 
358  void functionalAccess(PacketPtr pkt);
359 };
360 
361 } // namespace memory
362 } // namespace gem5
363 
364 #endif //__MEM_ABSTRACT_MEMORY_HH__
gem5::memory::AbstractMemory::isInAddrMap
bool isInAddrMap() const
Some memories are used as shadow memories or should for other reasons not be part of the global addre...
Definition: abstract_mem.hh:331
gem5::memory::LockedAddr::LockedAddr
LockedAddr(const RequestPtr &req)
Definition: abstract_mem.hh:94
gem5::memory::AbstractMemory::~AbstractMemory
virtual ~AbstractMemory()
Definition: abstract_mem.hh:224
gem5::memory::AbstractMemory::MemStats::bytesWritten
statistics::Vector bytesWritten
Number of bytes written to this memory.
Definition: abstract_mem.hh:193
gem5::memory::AbstractMemory::MemStats::MemStats
MemStats(AbstractMemory &mem)
Definition: abstract_mem.cc:118
gem5::AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:343
gem5::memory::AbstractMemory::MemStats::mem
const AbstractMemory & mem
Definition: abstract_mem.hh:186
gem5::memory::AbstractMemory::writeable
const bool writeable
Definition: abstract_mem.hh:133
gem5::memory::AbstractMemory::MemStats::numOther
statistics::Vector numOther
Number of other requests.
Definition: abstract_mem.hh:199
memory
Definition: mem.h:38
gem5::memory::AbstractMemory::MemStats::numWrites
statistics::Vector numWrites
Number of write requests.
Definition: abstract_mem.hh:197
gem5::memory::AbstractMemory::getAddrRange
AddrRange getAddrRange() const
Get the address range.
Definition: abstract_mem.cc:250
gem5::memory::AbstractMemory::lockedAddrList
std::list< LockedAddr > lockedAddrList
Definition: abstract_mem.hh:135
gem5::Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:377
gem5::InvalidContextID
const ContextID InvalidContextID
Definition: types.hh:240
gem5::memory::AbstractMemory::getLockedAddrList
const std::list< LockedAddr > & getLockedAddrList() const
Get the list of locked addresses to allow checkpointing.
Definition: abstract_mem.hh:255
gem5::MemBackdoor::invalidate
void invalidate()
Definition: backdoor.hh:113
gem5::statistics::Vector
A vector of scalar stats.
Definition: statistics.hh:2005
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2538
backdoor.hh
gem5::memory::AbstractMemory::system
void system(System *sys)
Set the system pointer on this memory This can't be done via a python parameter because the system ne...
Definition: abstract_mem.hh:281
gem5::memory::AbstractMemory::confTableReported
const bool confTableReported
Definition: abstract_mem.hh:124
gem5::memory::AbstractMemory::MemStats::bwInstRead
statistics::Formula bwInstRead
Read bandwidth from this memory.
Definition: abstract_mem.hh:203
gem5::memory::AbstractMemory::isKvmMap
bool isKvmMap() const
When shadow memories are in use, KVM may want to make one or the other, but cannot map both into the ...
Definition: abstract_mem.hh:339
gem5::memory::AbstractMemory::MemStats::numReads
statistics::Vector numReads
Number of read requests.
Definition: abstract_mem.hh:195
gem5::memory::AbstractMemory::isConfReported
bool isConfReported() const
Should this memory be passed to the kernel and part of the OS physical memory layout.
Definition: abstract_mem.hh:323
gem5::memory::AbstractMemory::stats
gem5::memory::AbstractMemory::MemStats stats
gem5::memory::AbstractMemory::_system
System * _system
Pointer to the System object.
Definition: abstract_mem.hh:178
stats.hh
gem5::memory::AbstractMemory::addLockedAddr
void addLockedAddr(LockedAddr addr)
Add a locked address to allow for checkpointing.
Definition: abstract_mem.hh:264
gem5::System
Definition: system.hh:74
gem5::memory::AbstractMemory::start
Addr start() const
Get the start address.
Definition: abstract_mem.hh:315
gem5::memory::AbstractMemory::MemStats::bytesInstRead
statistics::Vector bytesInstRead
Number of instruction bytes read from this memory.
Definition: abstract_mem.hh:191
gem5::memory::AbstractMemory::functionalAccess
void functionalAccess(PacketPtr pkt)
Perform an untimed memory read or write without changing anything but the memory itself.
Definition: abstract_mem.cc:482
gem5::memory::AbstractMemory::setBackingStore
void setBackingStore(uint8_t *pmem_addr)
Set the host memory backing store to be used by this memory controller.
Definition: abstract_mem.cc:106
gem5::memory::AbstractMemory::writeOK
bool writeOK(PacketPtr pkt)
Definition: abstract_mem.hh:156
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
gem5::memory::LockedAddr::matchesContext
bool matchesContext(const RequestPtr &req) const
Definition: abstract_mem.hh:87
gem5::memory::AbstractMemory::checkLockedAddrList
bool checkLockedAddrList(PacketPtr pkt)
Definition: abstract_mem.cc:290
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::memory::AbstractMemory::AbstractMemory
AbstractMemory(const AbstractMemory &)
gem5::memory::LockedAddr::contextId
const ContextID contextId
Definition: abstract_mem.hh:82
gem5::memory::AbstractMemory::toHostAddr
uint8_t * toHostAddr(Addr addr) const
Transform a gem5 address space address into its physical counterpart in the host address space.
Definition: abstract_mem.hh:298
gem5::memory::AbstractMemory
An abstract memory represents a contiguous block of physical memory, with an associated address range...
Definition: abstract_mem.hh:110
gem5::RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
port.hh
gem5::Packet::isLLSC
bool isLLSC() const
Definition: packet.hh:620
gem5::AddrRange::size
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:326
gem5::memory::LockedAddr::Addr_Mask
static const Addr Addr_Mask
Definition: abstract_mem.hh:74
gem5::memory::AbstractMemory::range
AddrRange range
Definition: abstract_mem.hh:115
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::memory::LockedAddr::addr
Addr addr
Definition: abstract_mem.hh:79
gem5::MemBackdoor
Definition: backdoor.hh:41
gem5::memory::AbstractMemory::PARAMS
PARAMS(AbstractMemory)
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::memory::AbstractMemory::getBackdoor
void getBackdoor(MemBackdoorPtr &bd_ptr)
Definition: abstract_mem.hh:245
gem5::memory::AbstractMemory::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: abstract_mem.cc:75
gem5::memory::AbstractMemory::operator=
AbstractMemory & operator=(const AbstractMemory &)
gem5::memory::AbstractMemory::size
uint64_t size() const
Get the memory size.
Definition: abstract_mem.hh:308
gem5::memory::AbstractMemory::MemStats::bwRead
statistics::Formula bwRead
Read bandwidth from this memory.
Definition: abstract_mem.hh:201
gem5::memory::LockedAddr::LockedAddr
LockedAddr(Addr _addr, int _cid)
Definition: abstract_mem.hh:99
gem5::memory::AbstractMemory::MemStats::regStats
void regStats() override
Callback to set stat parameters.
Definition: abstract_mem.cc:149
gem5::MemBackdoor::ptr
uint8_t * ptr() const
Definition: backdoor.hh:62
gem5::memory::AbstractMemory::MemStats::bytesRead
statistics::Vector bytesRead
Number of total bytes read from this memory.
Definition: abstract_mem.hh:189
gem5::memory::AbstractMemory::backdoor
MemBackdoor backdoor
Definition: abstract_mem.hh:121
gem5::memory::AbstractMemory::system
System * system() const
read the system pointer Implemented for completeness with the setter
Definition: abstract_mem.hh:273
clocked_object.hh
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
gem5::statistics::Group
Statistics container.
Definition: group.hh:92
gem5::memory::LockedAddr
Locked address class that represents a physical address and a context id.
Definition: abstract_mem.hh:67
gem5::memory::AbstractMemory::inAddrMap
const bool inAddrMap
Definition: abstract_mem.hh:127
gem5::memory::AbstractMemory::MemStats::bwTotal
statistics::Formula bwTotal
Total bandwidth from this memory.
Definition: abstract_mem.hh:207
gem5::ClockedObject::Params
ClockedObjectParams Params
Parameters of ClockedObject.
Definition: clocked_object.hh:240
gem5::AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:81
std::list
STL list class.
Definition: stl.hh:51
gem5::memory::AbstractMemory::kvmMap
const bool kvmMap
Definition: abstract_mem.hh:130
gem5::memory::LockedAddr::mask
static Addr mask(Addr paddr)
Definition: abstract_mem.hh:84
gem5::memory::AbstractMemory::access
void access(PacketPtr pkt)
Perform an untimed memory access and update all the state (e.g.
Definition: abstract_mem.cc:380
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::memory::AbstractMemory::isNull
bool isNull() const
See if this is a null memory that should never store data and always return zero.
Definition: abstract_mem.hh:234
gem5::memory::AbstractMemory::trackLoadLocked
void trackLoadLocked(PacketPtr pkt)
Definition: abstract_mem.cc:258
gem5::memory::AbstractMemory::MemStats::bwWrite
statistics::Formula bwWrite
Write bandwidth from this memory.
Definition: abstract_mem.hh:205
gem5::memory::AbstractMemory::MemStats
Definition: abstract_mem.hh:180
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::memory::AbstractMemory::pmemAddr
uint8_t * pmemAddr
Definition: abstract_mem.hh:118

Generated on Sun Jul 30 2023 01:56:57 for gem5 by doxygen 1.8.17