physical.hh revision 5714:76abee886def
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2001-2005 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com * 2812855Sgabeblack@google.com * Authors: Ron Dreslinski 2912855Sgabeblack@google.com */ 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com/* @file 3212855Sgabeblack@google.com */ 3312855Sgabeblack@google.com 3412855Sgabeblack@google.com#ifndef __PHYSICAL_MEMORY_HH__ 3512855Sgabeblack@google.com#define __PHYSICAL_MEMORY_HH__ 3612855Sgabeblack@google.com 3712855Sgabeblack@google.com#include <map> 3812855Sgabeblack@google.com#include <string> 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com#include "base/range.hh" 4112855Sgabeblack@google.com#include "mem/mem_object.hh" 4212855Sgabeblack@google.com#include "mem/packet.hh" 4312855Sgabeblack@google.com#include "mem/tport.hh" 4412855Sgabeblack@google.com#include "params/PhysicalMemory.hh" 4512855Sgabeblack@google.com#include "sim/eventq.hh" 4612855Sgabeblack@google.com 4712855Sgabeblack@google.com// 4812855Sgabeblack@google.com// Functional model for a contiguous block of physical memory. (i.e. RAM) 4912855Sgabeblack@google.com// 5012855Sgabeblack@google.comclass PhysicalMemory : public MemObject 5112855Sgabeblack@google.com{ 5212855Sgabeblack@google.com class MemoryPort : public SimpleTimingPort 5312855Sgabeblack@google.com { 5412855Sgabeblack@google.com PhysicalMemory *memory; 5512855Sgabeblack@google.com 5612855Sgabeblack@google.com public: 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com MemoryPort(const std::string &_name, PhysicalMemory *_memory); 5912855Sgabeblack@google.com 6012855Sgabeblack@google.com protected: 6112855Sgabeblack@google.com 6212855Sgabeblack@google.com virtual Tick recvAtomic(PacketPtr pkt); 6312855Sgabeblack@google.com 6412855Sgabeblack@google.com virtual void recvFunctional(PacketPtr pkt); 6512855Sgabeblack@google.com 6612855Sgabeblack@google.com virtual void recvStatusChange(Status status); 6712855Sgabeblack@google.com 68 virtual void getDeviceAddressRanges(AddrRangeList &resp, 69 bool &snoop); 70 71 virtual int deviceBlockSize(); 72 }; 73 74 int numPorts; 75 76 77 private: 78 // prevent copying of a MainMemory object 79 PhysicalMemory(const PhysicalMemory &specmem); 80 const PhysicalMemory &operator=(const PhysicalMemory &specmem); 81 82 protected: 83 84 class LockedAddr { 85 public: 86 // on alpha, minimum LL/SC granularity is 16 bytes, so lower 87 // bits need to masked off. 88 static const Addr Addr_Mask = 0xf; 89 90 static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); } 91 92 Addr addr; // locked address 93 int contextId; // locking hw context 94 95 // check for matching execution context 96 bool matchesContext(Request *req) 97 { 98 return (contextId == req->contextId()); 99 } 100 101 LockedAddr(Request *req) 102 : addr(mask(req->getPaddr())), 103 contextId(req->contextId()) 104 { 105 } 106 }; 107 108 std::list<LockedAddr> lockedAddrList; 109 110 // helper function for checkLockedAddrs(): we really want to 111 // inline a quick check for an empty locked addr list (hopefully 112 // the common case), and do the full list search (if necessary) in 113 // this out-of-line function 114 bool checkLockedAddrList(PacketPtr pkt); 115 116 // Record the address of a load-locked operation so that we can 117 // clear the execution context's lock flag if a matching store is 118 // performed 119 void trackLoadLocked(PacketPtr pkt); 120 121 // Compare a store address with any locked addresses so we can 122 // clear the lock flag appropriately. Return value set to 'false' 123 // if store operation should be suppressed (because it was a 124 // conditional store and the address was no longer locked by the 125 // requesting execution context), 'true' otherwise. Note that 126 // this method must be called on *all* stores since even 127 // non-conditional stores must clear any matching lock addresses. 128 bool writeOK(PacketPtr pkt) { 129 Request *req = pkt->req; 130 if (lockedAddrList.empty()) { 131 // no locked addrs: nothing to check, store_conditional fails 132 bool isLocked = pkt->isLocked(); 133 if (isLocked) { 134 req->setExtraData(0); 135 } 136 return !isLocked; // only do write if not an sc 137 } else { 138 // iterate over list... 139 return checkLockedAddrList(pkt); 140 } 141 } 142 143 uint8_t *pmemAddr; 144 int pagePtr; 145 Tick lat; 146 Tick lat_var; 147 std::vector<MemoryPort*> ports; 148 typedef std::vector<MemoryPort*>::iterator PortIterator; 149 150 uint64_t cachedSize; 151 uint64_t cachedStart; 152 public: 153 Addr new_page(); 154 uint64_t size() { return cachedSize; } 155 uint64_t start() { return cachedStart; } 156 157 public: 158 typedef PhysicalMemoryParams Params; 159 PhysicalMemory(const Params *p); 160 virtual ~PhysicalMemory(); 161 162 const Params * 163 params() const 164 { 165 return dynamic_cast<const Params *>(_params); 166 } 167 168 public: 169 int deviceBlockSize(); 170 void getAddressRanges(AddrRangeList &resp, bool &snoop); 171 virtual Port *getPort(const std::string &if_name, int idx = -1); 172 void virtual init(); 173 unsigned int drain(Event *de); 174 175 protected: 176 Tick doAtomicAccess(PacketPtr pkt); 177 void doFunctionalAccess(PacketPtr pkt); 178 virtual Tick calculateLatency(PacketPtr pkt); 179 void recvStatusChange(Port::Status status); 180 181 public: 182 virtual void serialize(std::ostream &os); 183 virtual void unserialize(Checkpoint *cp, const std::string §ion); 184 185}; 186 187#endif //__PHYSICAL_MEMORY_HH__ 188