2 * Copyright (c) 2012 ARM Limited
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.
14 * Copyright (c) 2001-2005 The Regents of The University of Michigan
15 * All rights reserved.
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.
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.
40 * Authors: Ron Dreslinski
46 * AbstractMemory declaration
49 #ifndef __ABSTRACT_MEMORY_HH__
50 #define __ABSTRACT_MEMORY_HH__
52 #include "mem/mem_object.hh"
53 #include "params/AbstractMemory.hh"
54 #include "sim/stats.hh"
60 * An abstract memory represents a contiguous block of physical
61 * memory, with an associated address range, and also provides basic
62 * functionality for reading and writing this memory without any
63 * timing information. It is a MemObject since any subclass must have
64 * at least one slave port.
66 class AbstractMemory : public MemObject
70 // Address range of this memory
73 // Pointer to host memory used to implement this memory
76 // Enable specific memories to be reported to the configuration table
77 bool confTableReported;
79 // Should the memory appear in the global address map
85 // on alpha, minimum LL/SC granularity is 16 bytes, so lower
86 // bits need to masked off.
87 static const Addr Addr_Mask = 0xf;
89 static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
91 Addr addr; // locked address
92 int contextId; // locking hw context
94 // check for matching execution context
95 bool matchesContext(Request *req)
97 return (contextId == req->contextId());
100 LockedAddr(Request *req) : addr(mask(req->getPaddr())),
101 contextId(req->contextId())
104 // constructor for unserialization use
105 LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
110 std::list<LockedAddr> lockedAddrList;
112 // helper function for checkLockedAddrs(): we really want to
113 // inline a quick check for an empty locked addr list (hopefully
114 // the common case), and do the full list search (if necessary) in
115 // this out-of-line function
116 bool checkLockedAddrList(PacketPtr pkt);
118 // Record the address of a load-locked operation so that we can
119 // clear the execution context's lock flag if a matching store is
121 void trackLoadLocked(PacketPtr pkt);
123 // Compare a store address with any locked addresses so we can
124 // clear the lock flag appropriately. Return value set to 'false'
125 // if store operation should be suppressed (because it was a
126 // conditional store and the address was no longer locked by the
127 // requesting execution context), 'true' otherwise. Note that
128 // this method must be called on *all* stores since even
129 // non-conditional stores must clear any matching lock addresses.
130 bool writeOK(PacketPtr pkt) {
131 Request *req = pkt->req;
132 if (lockedAddrList.empty()) {
133 // no locked addrs: nothing to check, store_conditional fails
134 bool isLLSC = pkt->isLLSC();
136 req->setExtraData(0);
138 return !isLLSC; // only do write if not an sc
140 // iterate over list...
141 return checkLockedAddrList(pkt);
145 /** Number of total bytes read from this memory */
146 Stats::Vector bytesRead;
147 /** Number of instruction bytes read from this memory */
148 Stats::Vector bytesInstRead;
149 /** Number of bytes written to this memory */
150 Stats::Vector bytesWritten;
151 /** Number of read requests */
152 Stats::Vector numReads;
153 /** Number of write requests */
154 Stats::Vector numWrites;
155 /** Number of other requests */
156 Stats::Vector numOther;
157 /** Read bandwidth from this memory */
158 Stats::Formula bwRead;
159 /** Read bandwidth from this memory */
160 Stats::Formula bwInstRead;
161 /** Write bandwidth from this memory */
162 Stats::Formula bwWrite;
163 /** Total bandwidth from this memory */
164 Stats::Formula bwTotal;
166 /** Pointor to the System object.
167 * This is used for getting the number of masters in the system which is
168 * needed when registering stats
176 AbstractMemory(const AbstractMemory&);
178 // Prevent assignment
179 AbstractMemory& operator=(const AbstractMemory&);
183 typedef AbstractMemoryParams Params;
185 AbstractMemory(const Params* p);
186 virtual ~AbstractMemory();
188 /** read the system pointer
189 * Implemented for completeness with the setter
190 * @return pointer to the system object */
191 System* system() const { return _system; }
193 /** Set the system pointer on this memory
194 * This can't be done via a python parameter because the system needs
195 * pointers to all the memories and the reverse would create a cycle in the
196 * object graph. An init() this is set.
197 * @param sys system pointer to set
199 void system(System *sys) { _system = sys; }
204 return dynamic_cast<const Params *>(_params);
208 * Get the address range
210 * @return a single contigous address range
212 Range<Addr> getAddrRange() const;
215 * Get the memory size.
217 * @return the size of the memory
219 uint64_t size() const { return range.size(); }
222 * Get the start address.
224 * @return the start address of the memory
226 Addr start() const { return range.start; }
229 * Should this memory be passed to the kernel and part of the OS
230 * physical memory layout.
232 * @return if this memory is reported
234 bool isConfReported() const { return confTableReported; }
237 * Some memories are used as shadow memories or should for other
238 * reasons not be part of the global address map.
240 * @return if this memory is part of the address map
242 bool isInAddrMap() const { return inAddrMap; }
245 * Perform an untimed memory access and update all the state
246 * (e.g. locked addresses) and statistics accordingly. The packet
247 * is turned into a response if required.
249 * @param pkt Packet performing the access
251 void access(PacketPtr pkt);
254 * Perform an untimed memory read or write without changing
255 * anything but the memory itself. No stats are affected by this
256 * access. In addition to normal accesses this also facilitates
259 * @param pkt Packet performing the access
261 void functionalAccess(PacketPtr pkt);
264 * Register Statistics
266 virtual void regStats();
268 virtual void serialize(std::ostream &os);
269 virtual void unserialize(Checkpoint *cp, const std::string §ion);
273 #endif //__ABSTRACT_MEMORY_HH__