abstract_mem.hh revision 9235
12292SN/A/* 22329SN/A * Copyright (c) 2012 ARM Limited 32292SN/A * All rights reserved 42292SN/A * 52292SN/A * The license below extends only to copyright in the software and shall 62292SN/A * not be construed as granting a license to any other intellectual 72292SN/A * property including but not limited to intellectual property relating 82292SN/A * to a hardware implementation of the functionality of the software 92292SN/A * licensed hereunder. You may use the software subject to the license 102292SN/A * terms below provided that you ensure that this notice is replicated 112292SN/A * unmodified and in its entirety in all distributions of the software, 122292SN/A * modified or unmodified, in source code or in binary form. 132292SN/A * 142292SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 152292SN/A * All rights reserved. 162292SN/A * 172292SN/A * Redistribution and use in source and binary forms, with or without 182292SN/A * modification, are permitted provided that the following conditions are 192292SN/A * met: redistributions of source code must retain the above copyright 202292SN/A * notice, this list of conditions and the following disclaimer; 212292SN/A * redistributions in binary form must reproduce the above copyright 222292SN/A * notice, this list of conditions and the following disclaimer in the 232292SN/A * documentation and/or other materials provided with the distribution; 242292SN/A * neither the name of the copyright holders nor the names of its 252292SN/A * contributors may be used to endorse or promote products derived from 262292SN/A * this software without specific prior written permission. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292689Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352329SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392329SN/A * 402292SN/A * Authors: Ron Dreslinski 412292SN/A * Andreas Hansson 422292SN/A */ 432669Sktlim@umich.edu 442669Sktlim@umich.edu/** 452292SN/A * @file 462292SN/A * AbstractMemory declaration 472329SN/A */ 482329SN/A 492329SN/A#ifndef __ABSTRACT_MEMORY_HH__ 502329SN/A#define __ABSTRACT_MEMORY_HH__ 512329SN/A 522329SN/A#include "mem/mem_object.hh" 532329SN/A#include "params/AbstractMemory.hh" 542329SN/A#include "sim/stats.hh" 552329SN/A 562329SN/A 572292SN/Aclass System; 582292SN/A 592292SN/A/** 602292SN/A * An abstract memory represents a contiguous block of physical 612292SN/A * memory, with an associated address range, and also provides basic 622292SN/A * functionality for reading and writing this memory without any 632292SN/A * timing information. It is a MemObject since any subclass must have 642733Sktlim@umich.edu * at least one slave port. 652292SN/A */ 662292SN/Aclass AbstractMemory : public MemObject 672292SN/A{ 682292SN/A protected: 692292SN/A 702292SN/A // Address range of this memory 712292SN/A AddrRange range; 722292SN/A 732292SN/A // Pointer to host memory used to implement this memory 742292SN/A uint8_t* pmemAddr; 752292SN/A 762292SN/A // Enable specific memories to be reported to the configuration table 772292SN/A bool confTableReported; 782292SN/A 792292SN/A // Should the memory appear in the global address map 802727Sktlim@umich.edu bool inAddrMap; 812727Sktlim@umich.edu 822727Sktlim@umich.edu class LockedAddr { 832292SN/A 842733Sktlim@umich.edu public: 852292SN/A // on alpha, minimum LL/SC granularity is 16 bytes, so lower 862292SN/A // bits need to masked off. 872292SN/A static const Addr Addr_Mask = 0xf; 882292SN/A 892292SN/A static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); } 902348SN/A 912307SN/A Addr addr; // locked address 922307SN/A int contextId; // locking hw context 932348SN/A 942307SN/A // check for matching execution context 952307SN/A bool matchesContext(Request *req) 962348SN/A { 972307SN/A return (contextId == req->contextId()); 982307SN/A } 992292SN/A 1002292SN/A LockedAddr(Request *req) : addr(mask(req->getPaddr())), 1012292SN/A contextId(req->contextId()) 1022292SN/A { 1032292SN/A } 1042292SN/A // constructor for unserialization use 1052292SN/A LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid) 1062292SN/A { 1072292SN/A } 1082292SN/A }; 1092292SN/A 1102292SN/A std::list<LockedAddr> lockedAddrList; 1112292SN/A 1122292SN/A // helper function for checkLockedAddrs(): we really want to 1132292SN/A // inline a quick check for an empty locked addr list (hopefully 1142292SN/A // the common case), and do the full list search (if necessary) in 1152292SN/A // this out-of-line function 1162329SN/A bool checkLockedAddrList(PacketPtr pkt); 1172292SN/A 1182292SN/A // Record the address of a load-locked operation so that we can 1192292SN/A // clear the execution context's lock flag if a matching store is 1202292SN/A // performed 1212292SN/A void trackLoadLocked(PacketPtr pkt); 1222292SN/A 1232292SN/A // Compare a store address with any locked addresses so we can 1242292SN/A // clear the lock flag appropriately. Return value set to 'false' 1252292SN/A // if store operation should be suppressed (because it was a 1262292SN/A // conditional store and the address was no longer locked by the 1272292SN/A // requesting execution context), 'true' otherwise. Note that 1282292SN/A // this method must be called on *all* stores since even 1292292SN/A // non-conditional stores must clear any matching lock addresses. 1302292SN/A bool writeOK(PacketPtr pkt) { 1312790Sktlim@umich.edu Request *req = pkt->req; 1322790Sktlim@umich.edu if (lockedAddrList.empty()) { 1332669Sktlim@umich.edu // no locked addrs: nothing to check, store_conditional fails 1342669Sktlim@umich.edu bool isLLSC = pkt->isLLSC(); 1352292SN/A if (isLLSC) { 1362292SN/A req->setExtraData(0); 1372292SN/A } 1382292SN/A return !isLLSC; // only do write if not an sc 1392292SN/A } else { 1402292SN/A // iterate over list... 1412292SN/A return checkLockedAddrList(pkt); 1422292SN/A } 1432292SN/A } 1442292SN/A 1452292SN/A /** Number of total bytes read from this memory */ 1462292SN/A Stats::Vector bytesRead; 1472292SN/A /** Number of instruction bytes read from this memory */ 1482292SN/A Stats::Vector bytesInstRead; 1492292SN/A /** Number of bytes written to this memory */ 1502292SN/A Stats::Vector bytesWritten; 1512292SN/A /** Number of read requests */ 1522292SN/A Stats::Vector numReads; 1532292SN/A /** Number of write requests */ 1542292SN/A Stats::Vector numWrites; 1552292SN/A /** Number of other requests */ 1562292SN/A Stats::Vector numOther; 1572292SN/A /** Read bandwidth from this memory */ 1582329SN/A Stats::Formula bwRead; 1592292SN/A /** Read bandwidth from this memory */ 1602292SN/A Stats::Formula bwInstRead; 1612292SN/A /** Write bandwidth from this memory */ 1622348SN/A Stats::Formula bwWrite; 1632292SN/A /** Total bandwidth from this memory */ 1642292SN/A Stats::Formula bwTotal; 1652292SN/A 1662348SN/A /** Pointor to the System object. 1672292SN/A * This is used for getting the number of masters in the system which is 1682292SN/A * needed when registering stats 1692292SN/A */ 1702348SN/A System *_system; 1712292SN/A 1722292SN/A 1732292SN/A private: 1742292SN/A 1752292SN/A // Prevent copying 1762292SN/A AbstractMemory(const AbstractMemory&); 1772292SN/A 1782292SN/A // Prevent assignment 1792292SN/A AbstractMemory& operator=(const AbstractMemory&); 1802292SN/A 1812292SN/A public: 1822292SN/A 1832292SN/A typedef AbstractMemoryParams Params; 1842292SN/A 1852292SN/A AbstractMemory(const Params* p); 1862292SN/A virtual ~AbstractMemory(); 1872292SN/A 1882292SN/A /** read the system pointer 1892292SN/A * Implemented for completeness with the setter 1902292SN/A * @return pointer to the system object */ 1912292SN/A System* system() const { return _system; } 1922292SN/A 1932292SN/A /** Set the system pointer on this memory 1942292SN/A * This can't be done via a python parameter because the system needs 1952292SN/A * pointers to all the memories and the reverse would create a cycle in the 1962292SN/A * object graph. An init() this is set. 1972292SN/A * @param sys system pointer to set 1982292SN/A */ 1992292SN/A void system(System *sys) { _system = sys; } 2002292SN/A 2012292SN/A const Params * 2022292SN/A params() const 2032292SN/A { 2042292SN/A return dynamic_cast<const Params *>(_params); 2052292SN/A } 2062678Sktlim@umich.edu 2072678Sktlim@umich.edu /** 2082292SN/A * Get the address range 2092292SN/A * 2102698Sktlim@umich.edu * @return a single contigous address range 2112678Sktlim@umich.edu */ 2122678Sktlim@umich.edu AddrRange getAddrRange() const; 2132698Sktlim@umich.edu 2142693Sktlim@umich.edu /** 2152693Sktlim@umich.edu * Get the memory size. 2162292SN/A * 2172292SN/A * @return the size of the memory 2182292SN/A */ 2192693Sktlim@umich.edu uint64_t size() const { return range.size(); } 2202693Sktlim@umich.edu 2212693Sktlim@umich.edu /** 2222292SN/A * Get the start address. 2232292SN/A * 2242292SN/A * @return the start address of the memory 2252292SN/A */ 2262292SN/A Addr start() const { return range.start; } 2272292SN/A 2282292SN/A /** 2292292SN/A * Should this memory be passed to the kernel and part of the OS 2302292SN/A * physical memory layout. 2312329SN/A * 2322329SN/A * @return if this memory is reported 2332329SN/A */ 2342329SN/A bool isConfReported() const { return confTableReported; } 2352292SN/A 2362292SN/A /** 2372733Sktlim@umich.edu * Some memories are used as shadow memories or should for other 2382292SN/A * reasons not be part of the global address map. 2392292SN/A * 2402292SN/A * @return if this memory is part of the address map 2412292SN/A */ 2422698Sktlim@umich.edu bool isInAddrMap() const { return inAddrMap; } 2432669Sktlim@umich.edu 2442669Sktlim@umich.edu /** 2452698Sktlim@umich.edu * Perform an untimed memory access and update all the state 2462698Sktlim@umich.edu * (e.g. locked addresses) and statistics accordingly. The packet 2472698Sktlim@umich.edu * is turned into a response if required. 2482698Sktlim@umich.edu * 2492698Sktlim@umich.edu * @param pkt Packet performing the access 2502669Sktlim@umich.edu */ 2512669Sktlim@umich.edu void access(PacketPtr pkt); 2522669Sktlim@umich.edu 2532698Sktlim@umich.edu /** 2542733Sktlim@umich.edu * Perform an untimed memory read or write without changing 2552698Sktlim@umich.edu * anything but the memory itself. No stats are affected by this 2562669Sktlim@umich.edu * access. In addition to normal accesses this also facilitates 2572669Sktlim@umich.edu * print requests. 2582669Sktlim@umich.edu * 2592698Sktlim@umich.edu * @param pkt Packet performing the access 2602733Sktlim@umich.edu */ 2612669Sktlim@umich.edu void functionalAccess(PacketPtr pkt); 2622669Sktlim@umich.edu 2632669Sktlim@umich.edu /** 2642669Sktlim@umich.edu * Register Statistics 2652698Sktlim@umich.edu */ 2662669Sktlim@umich.edu virtual void regStats(); 2672669Sktlim@umich.edu 2682698Sktlim@umich.edu virtual void serialize(std::ostream &os); 2692669Sktlim@umich.edu virtual void unserialize(Checkpoint *cp, const std::string §ion); 2702669Sktlim@umich.edu 2712698Sktlim@umich.edu}; 2722669Sktlim@umich.edu 2732669Sktlim@umich.edu#endif //__ABSTRACT_MEMORY_HH__ 2742698Sktlim@umich.edu