abstract_mem.hh revision 8923
1360SN/A/*
210850SGiacomo.Gabrielli@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan
310796Sbrandon.potter@amd.com * All rights reserved.
410027SChris.Adeniyi-Jones@arm.com *
510027SChris.Adeniyi-Jones@arm.com * Redistribution and use in source and binary forms, with or without
610027SChris.Adeniyi-Jones@arm.com * modification, are permitted provided that the following conditions are
710027SChris.Adeniyi-Jones@arm.com * met: redistributions of source code must retain the above copyright
810027SChris.Adeniyi-Jones@arm.com * notice, this list of conditions and the following disclaimer;
910027SChris.Adeniyi-Jones@arm.com * redistributions in binary form must reproduce the above copyright
1010027SChris.Adeniyi-Jones@arm.com * notice, this list of conditions and the following disclaimer in the
1110027SChris.Adeniyi-Jones@arm.com * documentation and/or other materials provided with the distribution;
1210027SChris.Adeniyi-Jones@arm.com * neither the name of the copyright holders nor the names of its
1310027SChris.Adeniyi-Jones@arm.com * contributors may be used to endorse or promote products derived from
1410027SChris.Adeniyi-Jones@arm.com * this software without specific prior written permission.
151458SN/A *
16360SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17360SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18360SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19360SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20360SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21360SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22360SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23360SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24360SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25360SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26360SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27360SN/A *
28360SN/A * Authors: Ron Dreslinski
29360SN/A */
30360SN/A
31360SN/A/* @file
32360SN/A */
33360SN/A
34360SN/A#ifndef __PHYSICAL_MEMORY_HH__
35360SN/A#define __PHYSICAL_MEMORY_HH__
36360SN/A
37360SN/A#include <map>
38360SN/A#include <string>
39360SN/A
402665Ssaidi@eecs.umich.edu#include "base/range.hh"
412665Ssaidi@eecs.umich.edu#include "base/statistics.hh"
422665Ssaidi@eecs.umich.edu#include "mem/mem_object.hh"
43360SN/A#include "mem/packet.hh"
44360SN/A#include "mem/tport.hh"
451354SN/A#include "params/PhysicalMemory.hh"
461354SN/A#include "sim/eventq.hh"
47360SN/A#include "sim/stats.hh"
4812018Sandreas.sandberg@arm.com
4912018Sandreas.sandberg@arm.com//
5012018Sandreas.sandberg@arm.com// Functional model for a contiguous block of physical memory. (i.e. RAM)
5112018Sandreas.sandberg@arm.com//
5212018Sandreas.sandberg@arm.comclass PhysicalMemory : public MemObject
5312018Sandreas.sandberg@arm.com{
5412018Sandreas.sandberg@arm.com  protected:
552064SN/A
5612018Sandreas.sandberg@arm.com    class MemoryPort : public SimpleTimingPort
5712018Sandreas.sandberg@arm.com    {
5812018Sandreas.sandberg@arm.com        PhysicalMemory *memory;
5912018Sandreas.sandberg@arm.com
6012018Sandreas.sandberg@arm.com      public:
6112018Sandreas.sandberg@arm.com
6211799Sbrandon.potter@amd.com        MemoryPort(const std::string &_name, PhysicalMemory *_memory);
6312018Sandreas.sandberg@arm.com
6412018Sandreas.sandberg@arm.com      protected:
6512018Sandreas.sandberg@arm.com
6612018Sandreas.sandberg@arm.com        virtual Tick recvAtomic(PacketPtr pkt);
6712018Sandreas.sandberg@arm.com
6812018Sandreas.sandberg@arm.com        virtual void recvFunctional(PacketPtr pkt);
6911799Sbrandon.potter@amd.com
70360SN/A        virtual AddrRangeList getAddrRanges();
71360SN/A
72360SN/A        virtual unsigned deviceBlockSize() const;
73360SN/A    };
74360SN/A
75360SN/A    int numPorts;
761809SN/A
7711800Sbrandon.potter@amd.com
7811392Sbrandon.potter@amd.com  private:
791809SN/A    // prevent copying of a MainMemory object
8011392Sbrandon.potter@amd.com    PhysicalMemory(const PhysicalMemory &specmem);
8111383Sbrandon.potter@amd.com    const PhysicalMemory &operator=(const PhysicalMemory &specmem);
823113Sgblack@eecs.umich.edu
8311799Sbrandon.potter@amd.com  protected:
8411759Sbrandon.potter@amd.com
8511812Sbaz21@cam.ac.uk    class LockedAddr {
8611812Sbaz21@cam.ac.uk      public:
8711799Sbrandon.potter@amd.com        // on alpha, minimum LL/SC granularity is 16 bytes, so lower
888229Snate@binkert.org        // bits need to masked off.
898229Snate@binkert.org        static const Addr Addr_Mask = 0xf;
9011594Santhony.gutierrez@amd.com
917075Snate@binkert.org        static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
928229Snate@binkert.org
9311856Sbrandon.potter@amd.com        Addr addr;      // locked address
947075Snate@binkert.org        int contextId;     // locking hw context
95360SN/A
9611886Sbrandon.potter@amd.com        // check for matching execution context
9711800Sbrandon.potter@amd.com        bool matchesContext(Request *req)
9811392Sbrandon.potter@amd.com        {
9912334Sgabeblack@google.com            return (contextId == req->contextId());
1001354SN/A        }
1016216Snate@binkert.org
1026658Snate@binkert.org        LockedAddr(Request *req)
1032474SN/A            : addr(mask(req->getPaddr())),
1042680Sktlim@umich.edu              contextId(req->contextId())
1058229Snate@binkert.org        {
10611886Sbrandon.potter@amd.com        }
10710496Ssteve.reinhardt@amd.com        // constructor for unserialization use
10811911SBrandon.Potter@amd.com        LockedAddr(Addr _addr, int _cid)
1098229Snate@binkert.org            : addr(_addr), contextId(_cid)
11011794Sbrandon.potter@amd.com        {
11111886Sbrandon.potter@amd.com        }
11210497Ssteve.reinhardt@amd.com    };
11311794Sbrandon.potter@amd.com
114360SN/A    std::list<LockedAddr> lockedAddrList;
115360SN/A
116360SN/A    // helper function for checkLockedAddrs(): we really want to
117360SN/A    // inline a quick check for an empty locked addr list (hopefully
118360SN/A    // the common case), and do the full list search (if necessary) in
119360SN/A    // this out-of-line function
120360SN/A    bool checkLockedAddrList(PacketPtr pkt);
121360SN/A
122360SN/A    // Record the address of a load-locked operation so that we can
123360SN/A    // clear the execution context's lock flag if a matching store is
124378SN/A    // performed
1251706SN/A    void trackLoadLocked(PacketPtr pkt);
12611851Sbrandon.potter@amd.com
127378SN/A    // Compare a store address with any locked addresses so we can
128378SN/A    // clear the lock flag appropriately.  Return value set to 'false'
129378SN/A    // if store operation should be suppressed (because it was a
130378SN/A    // conditional store and the address was no longer locked by the
131378SN/A    // requesting execution context), 'true' otherwise.  Note that
1321706SN/A    // this method must be called on *all* stores since even
13311851Sbrandon.potter@amd.com    // non-conditional stores must clear any matching lock addresses.
134360SN/A    bool writeOK(PacketPtr pkt) {
13511760Sbrandon.potter@amd.com        Request *req = pkt->req;
13611760Sbrandon.potter@amd.com        if (lockedAddrList.empty()) {
13711851Sbrandon.potter@amd.com            // no locked addrs: nothing to check, store_conditional fails
13811760Sbrandon.potter@amd.com            bool isLLSC = pkt->isLLSC();
1396109Ssanchezd@stanford.edu            if (isLLSC) {
1401706SN/A                req->setExtraData(0);
14111851Sbrandon.potter@amd.com            }
142378SN/A            return !isLLSC; // only do write if not an sc
1436109Ssanchezd@stanford.edu        } else {
1446109Ssanchezd@stanford.edu            // iterate over list...
14511851Sbrandon.potter@amd.com            return checkLockedAddrList(pkt);
1466109Ssanchezd@stanford.edu        }
14711886Sbrandon.potter@amd.com    }
14811886Sbrandon.potter@amd.com
14911886Sbrandon.potter@amd.com    uint8_t *pmemAddr;
15011886Sbrandon.potter@amd.com    Tick lat;
151378SN/A    Tick lat_var;
1521706SN/A    std::vector<MemoryPort*> ports;
15311851Sbrandon.potter@amd.com    typedef std::vector<MemoryPort*>::iterator PortIterator;
154378SN/A
1555748SSteve.Reinhardt@amd.com    uint64_t _size;
1565748SSteve.Reinhardt@amd.com    uint64_t _start;
15711851Sbrandon.potter@amd.com
158378SN/A    /** Number of total bytes read from this memory */
159378SN/A    Stats::Scalar bytesRead;
1601706SN/A    /** Number of instruction bytes read from this memory */
16111851Sbrandon.potter@amd.com    Stats::Scalar bytesInstRead;
162378SN/A    /** Number of bytes written to this memory */
16311886Sbrandon.potter@amd.com    Stats::Scalar bytesWritten;
1641706SN/A    /** Number of read requests */
16511851Sbrandon.potter@amd.com    Stats::Scalar numReads;
166378SN/A    /** Number of write requests */
167378SN/A    Stats::Scalar numWrites;
1681706SN/A    /** Number of other requests */
16911851Sbrandon.potter@amd.com    Stats::Scalar numOther;
170378SN/A    /** Read bandwidth from this memory */
171378SN/A    Stats::Formula bwRead;
1721706SN/A    /** Read bandwidth from this memory */
17311851Sbrandon.potter@amd.com    Stats::Formula bwInstRead;
174378SN/A    /** Write bandwidth from this memory */
1754118Sgblack@eecs.umich.edu    Stats::Formula bwWrite;
1764118Sgblack@eecs.umich.edu    /** Total bandwidth from this memory */
17711851Sbrandon.potter@amd.com    Stats::Formula bwTotal;
1784118Sgblack@eecs.umich.edu
179378SN/A  public:
1801706SN/A    uint64_t size() { return _size; }
18111851Sbrandon.potter@amd.com    uint64_t start() { return _start; }
182378SN/A
183378SN/A  public:
1841706SN/A    typedef PhysicalMemoryParams Params;
18511851Sbrandon.potter@amd.com    PhysicalMemory(const Params *p);
186360SN/A    virtual ~PhysicalMemory();
1875513SMichael.Adler@intel.com
1885513SMichael.Adler@intel.com    const Params *
18911851Sbrandon.potter@amd.com    params() const
1905513SMichael.Adler@intel.com    {
19110203SAli.Saidi@ARM.com        return dynamic_cast<const Params *>(_params);
19210203SAli.Saidi@ARM.com    }
19311851Sbrandon.potter@amd.com
19410203SAli.Saidi@ARM.com  public:
1955513SMichael.Adler@intel.com    unsigned deviceBlockSize() const;
19611851Sbrandon.potter@amd.com    AddrRangeList getAddrRanges();
1975513SMichael.Adler@intel.com    virtual SlavePort &getSlavePort(const std::string &if_name, int idx = -1);
198511SN/A    void virtual init();
19910633Smichaelupton@gmail.com    unsigned int drain(Event *de);
20011851Sbrandon.potter@amd.com
20110633Smichaelupton@gmail.com    Tick doAtomicAccess(PacketPtr pkt);
2021706SN/A    void doFunctionalAccess(PacketPtr pkt);
20311851Sbrandon.potter@amd.com
204511SN/A
2055513SMichael.Adler@intel.com  protected:
2065513SMichael.Adler@intel.com    virtual Tick calculateLatency(PacketPtr pkt);
20711851Sbrandon.potter@amd.com
2085513SMichael.Adler@intel.com  public:
209511SN/A     /**
2101706SN/A     * Register Statistics
21111851Sbrandon.potter@amd.com     */
2121706SN/A    void regStats();
2131706SN/A
2141706SN/A    virtual void serialize(std::ostream &os);
2151706SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
21611851Sbrandon.potter@amd.com
2171706SN/A};
2181706SN/A
2191706SN/A#endif //__PHYSICAL_MEMORY_HH__
2201706SN/A