gem5  v21.1.0.2
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 
133 
134  // helper function for checkLockedAddrs(): we really want to
135  // inline a quick check for an empty locked addr list (hopefully
136  // the common case), and do the full list search (if necessary) in
137  // this out-of-line function
138  bool checkLockedAddrList(PacketPtr pkt);
139 
140  // Record the address of a load-locked operation so that we can
141  // clear the execution context's lock flag if a matching store is
142  // performed
143  void trackLoadLocked(PacketPtr pkt);
144 
145  // Compare a store address with any locked addresses so we can
146  // clear the lock flag appropriately. Return value set to 'false'
147  // if store operation should be suppressed (because it was a
148  // conditional store and the address was no longer locked by the
149  // requesting execution context), 'true' otherwise. Note that
150  // this method must be called on *all* stores since even
151  // non-conditional stores must clear any matching lock addresses.
152  bool writeOK(PacketPtr pkt) {
153  const RequestPtr &req = pkt->req;
154  if (lockedAddrList.empty()) {
155  // no locked addrs: nothing to check, store_conditional fails
156  bool isLLSC = pkt->isLLSC();
157  if (isLLSC) {
158  req->setExtraData(0);
159  }
160  return !isLLSC; // only do write if not an sc
161  } else {
162  // iterate over list...
163  return checkLockedAddrList(pkt);
164  }
165  }
166 
172 
173  struct MemStats : public statistics::Group
174  {
176 
177  void regStats() override;
178 
180 
201  } stats;
202 
203 
204  private:
205 
206  // Prevent copying
208 
209  // Prevent assignment
211 
212  public:
213 
215 
216  AbstractMemory(const Params &p);
217  virtual ~AbstractMemory() {}
218 
219  void initState() override;
220 
227  bool isNull() const { return params().null; }
228 
235  void setBackingStore(uint8_t* pmem_addr);
236 
237  void
239  {
240  if (lockedAddrList.empty() && backdoor.ptr())
241  bd_ptr = &backdoor;
242  }
243 
247  const std::list<LockedAddr> &
249  {
250  return lockedAddrList;
251  }
252 
256  void
258  {
260  lockedAddrList.push_back(addr);
261  }
262 
266  System* system() const { return _system; }
267 
274  void system(System *sys) { _system = sys; }
275 
281  AddrRange getAddrRange() const;
282 
290  inline uint8_t *
292  {
293  return pmemAddr + addr - range.start();
294  }
295 
301  uint64_t size() const { return range.size(); }
302 
308  Addr start() const { return range.start(); }
309 
316  bool isConfReported() const { return confTableReported; }
317 
324  bool isInAddrMap() const { return inAddrMap; }
325 
332  bool isKvmMap() const { return kvmMap; }
333 
341  void access(PacketPtr pkt);
342 
351  void functionalAccess(PacketPtr pkt);
352 };
353 
354 } // namespace memory
355 } // namespace gem5
356 
357 #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:324
gem5::memory::LockedAddr::LockedAddr
LockedAddr(const RequestPtr &req)
Definition: abstract_mem.hh:94
gem5::memory::AbstractMemory::~AbstractMemory
virtual ~AbstractMemory()
Definition: abstract_mem.hh:217
gem5::memory::AbstractMemory::MemStats::bytesWritten
statistics::Vector bytesWritten
Number of bytes written to this memory.
Definition: abstract_mem.hh:186
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:317
gem5::memory::AbstractMemory::MemStats::mem
const AbstractMemory & mem
Definition: abstract_mem.hh:179
gem5::memory::AbstractMemory::MemStats::numOther
statistics::Vector numOther
Number of other requests.
Definition: abstract_mem.hh:192
memory
Definition: mem.h:38
gem5::memory::AbstractMemory::MemStats::numWrites
statistics::Vector numWrites
Number of write requests.
Definition: abstract_mem.hh:190
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:132
gem5::Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:366
gem5::InvalidContextID
const ContextID InvalidContextID
Definition: types.hh:247
gem5::memory::AbstractMemory::getLockedAddrList
const std::list< LockedAddr > & getLockedAddrList() const
Get the list of locked addresses to allow checkpointing.
Definition: abstract_mem.hh:248
gem5::MemBackdoor::invalidate
void invalidate()
Definition: backdoor.hh:113
gem5::statistics::Vector
A vector of scalar stats.
Definition: statistics.hh:2003
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2536
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:274
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:196
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:332
gem5::memory::AbstractMemory::MemStats::numReads
statistics::Vector numReads
Number of read requests.
Definition: abstract_mem.hh:188
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:316
gem5::memory::AbstractMemory::stats
gem5::memory::AbstractMemory::MemStats stats
gem5::memory::AbstractMemory::_system
System * _system
Pointer to the System object.
Definition: abstract_mem.hh:171
stats.hh
gem5::memory::AbstractMemory::addLockedAddr
void addLockedAddr(LockedAddr addr)
Add a locked address to allow for checkpointing.
Definition: abstract_mem.hh:257
gem5::System
Definition: system.hh:77
gem5::memory::AbstractMemory::start
Addr start() const
Get the start address.
Definition: abstract_mem.hh:308
gem5::memory::AbstractMemory::MemStats::bytesInstRead
statistics::Vector bytesInstRead
Number of instruction bytes read from this memory.
Definition: abstract_mem.hh:184
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:152
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:283
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:291
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
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:609
gem5::AddrRange::size
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:300
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:238
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:301
gem5::memory::AbstractMemory::MemStats::bwRead
statistics::Formula bwRead
Read bandwidth from this memory.
Definition: abstract_mem.hh:194
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:182
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:266
clocked_object.hh
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:246
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
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:200
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:71
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: decoder.cc:40
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:227
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:198
gem5::memory::AbstractMemory::MemStats
Definition: abstract_mem.hh:173
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::memory::AbstractMemory::pmemAddr
uint8_t * pmemAddr
Definition: abstract_mem.hh:118

Generated on Tue Sep 21 2021 12:25:26 for gem5 by doxygen 1.8.17