abstract_mem.hh revision 9053
12391SN/A/*
28931Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited
38931Sandreas.hansson@arm.com * All rights reserved
48931Sandreas.hansson@arm.com *
58931Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68931Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78931Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88931Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98931Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108931Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118931Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128931Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138931Sandreas.hansson@arm.com *
142391SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
152391SN/A * All rights reserved.
162391SN/A *
172391SN/A * Redistribution and use in source and binary forms, with or without
182391SN/A * modification, are permitted provided that the following conditions are
192391SN/A * met: redistributions of source code must retain the above copyright
202391SN/A * notice, this list of conditions and the following disclaimer;
212391SN/A * redistributions in binary form must reproduce the above copyright
222391SN/A * notice, this list of conditions and the following disclaimer in the
232391SN/A * documentation and/or other materials provided with the distribution;
242391SN/A * neither the name of the copyright holders nor the names of its
252391SN/A * contributors may be used to endorse or promote products derived from
262391SN/A * this software without specific prior written permission.
272391SN/A *
282391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665SN/A *
402665SN/A * Authors: Ron Dreslinski
418931Sandreas.hansson@arm.com *          Andreas Hansson
422391SN/A */
432391SN/A
448931Sandreas.hansson@arm.com/**
458931Sandreas.hansson@arm.com * @file
468931Sandreas.hansson@arm.com * AbstractMemory declaration
472391SN/A */
482391SN/A
498931Sandreas.hansson@arm.com#ifndef __ABSTRACT_MEMORY_HH__
508931Sandreas.hansson@arm.com#define __ABSTRACT_MEMORY_HH__
512391SN/A
522462SN/A#include "mem/mem_object.hh"
538931Sandreas.hansson@arm.com#include "params/AbstractMemory.hh"
548719SN/A#include "sim/stats.hh"
552462SN/A
569053Sdam.sunwoo@arm.com
579053Sdam.sunwoo@arm.comclass System;
589053Sdam.sunwoo@arm.com
598931Sandreas.hansson@arm.com/**
608931Sandreas.hansson@arm.com * An abstract memory represents a contiguous block of physical
618931Sandreas.hansson@arm.com * memory, with an associated address range, and also provides basic
628931Sandreas.hansson@arm.com * functionality for reading and writing this memory without any
638931Sandreas.hansson@arm.com * timing information. It is a MemObject since any subclass must have
648931Sandreas.hansson@arm.com * at least one slave port.
658931Sandreas.hansson@arm.com */
668931Sandreas.hansson@arm.comclass AbstractMemory : public MemObject
672391SN/A{
686107SN/A  protected:
696107SN/A
708931Sandreas.hansson@arm.com    // Address range of this memory
718931Sandreas.hansson@arm.com    Range<Addr> range;
722413SN/A
738931Sandreas.hansson@arm.com    // Pointer to host memory used to implement this memory
748931Sandreas.hansson@arm.com    uint8_t* pmemAddr;
752413SN/A
768931Sandreas.hansson@arm.com    // Enable specific memories to be reported to the configuration table
778931Sandreas.hansson@arm.com    bool confTableReported;
782413SN/A
798931Sandreas.hansson@arm.com    // Should the memory appear in the global address map
808931Sandreas.hansson@arm.com    bool inAddrMap;
813170SN/A
823170SN/A    class LockedAddr {
838931Sandreas.hansson@arm.com
843170SN/A      public:
853170SN/A        // on alpha, minimum LL/SC granularity is 16 bytes, so lower
863170SN/A        // bits need to masked off.
873170SN/A        static const Addr Addr_Mask = 0xf;
883170SN/A
893170SN/A        static Addr mask(Addr paddr) { return (paddr & ~Addr_Mask); }
903170SN/A
915543SN/A        Addr addr;      // locked address
925714SN/A        int contextId;     // locking hw context
933170SN/A
943170SN/A        // check for matching execution context
953170SN/A        bool matchesContext(Request *req)
963170SN/A        {
975714SN/A            return (contextId == req->contextId());
983170SN/A        }
993170SN/A
1008931Sandreas.hansson@arm.com        LockedAddr(Request *req) : addr(mask(req->getPaddr())),
1018931Sandreas.hansson@arm.com                                   contextId(req->contextId())
1023170SN/A        {
1033170SN/A        }
1047733SN/A        // constructor for unserialization use
1058931Sandreas.hansson@arm.com        LockedAddr(Addr _addr, int _cid) : addr(_addr), contextId(_cid)
1067733SN/A        {
1077733SN/A        }
1083170SN/A    };
1093170SN/A
1103170SN/A    std::list<LockedAddr> lockedAddrList;
1113170SN/A
1123170SN/A    // helper function for checkLockedAddrs(): we really want to
1133170SN/A    // inline a quick check for an empty locked addr list (hopefully
1143170SN/A    // the common case), and do the full list search (if necessary) in
1153170SN/A    // this out-of-line function
1164626SN/A    bool checkLockedAddrList(PacketPtr pkt);
1173170SN/A
1183170SN/A    // Record the address of a load-locked operation so that we can
1193170SN/A    // clear the execution context's lock flag if a matching store is
1203170SN/A    // performed
1214626SN/A    void trackLoadLocked(PacketPtr pkt);
1223170SN/A
1233170SN/A    // Compare a store address with any locked addresses so we can
1243170SN/A    // clear the lock flag appropriately.  Return value set to 'false'
1253170SN/A    // if store operation should be suppressed (because it was a
1263170SN/A    // conditional store and the address was no longer locked by the
1273170SN/A    // requesting execution context), 'true' otherwise.  Note that
1283170SN/A    // this method must be called on *all* stores since even
1293170SN/A    // non-conditional stores must clear any matching lock addresses.
1304626SN/A    bool writeOK(PacketPtr pkt) {
1314626SN/A        Request *req = pkt->req;
1323170SN/A        if (lockedAddrList.empty()) {
1333170SN/A            // no locked addrs: nothing to check, store_conditional fails
1346102SN/A            bool isLLSC = pkt->isLLSC();
1356102SN/A            if (isLLSC) {
1364040SN/A                req->setExtraData(0);
1373170SN/A            }
1386102SN/A            return !isLLSC; // only do write if not an sc
1393170SN/A        } else {
1403170SN/A            // iterate over list...
1414626SN/A            return checkLockedAddrList(pkt);
1423170SN/A        }
1433170SN/A    }
1443170SN/A
1458719SN/A    /** Number of total bytes read from this memory */
1469053Sdam.sunwoo@arm.com    Stats::Vector bytesRead;
1478719SN/A    /** Number of instruction bytes read from this memory */
1489053Sdam.sunwoo@arm.com    Stats::Vector bytesInstRead;
1498719SN/A    /** Number of bytes written to this memory */
1509053Sdam.sunwoo@arm.com    Stats::Vector bytesWritten;
1518719SN/A    /** Number of read requests */
1529053Sdam.sunwoo@arm.com    Stats::Vector numReads;
1538719SN/A    /** Number of write requests */
1549053Sdam.sunwoo@arm.com    Stats::Vector numWrites;
1558719SN/A    /** Number of other requests */
1569053Sdam.sunwoo@arm.com    Stats::Vector numOther;
1578719SN/A    /** Read bandwidth from this memory */
1588719SN/A    Stats::Formula bwRead;
1598719SN/A    /** Read bandwidth from this memory */
1608719SN/A    Stats::Formula bwInstRead;
1618719SN/A    /** Write bandwidth from this memory */
1628719SN/A    Stats::Formula bwWrite;
1638719SN/A    /** Total bandwidth from this memory */
1648719SN/A    Stats::Formula bwTotal;
1658719SN/A
1669053Sdam.sunwoo@arm.com    /** Pointor to the System object.
1679053Sdam.sunwoo@arm.com     * This is used for getting the number of masters in the system which is
1689053Sdam.sunwoo@arm.com     * needed when registering stats
1699053Sdam.sunwoo@arm.com     */
1709053Sdam.sunwoo@arm.com    System *_system;
1719053Sdam.sunwoo@arm.com
1729053Sdam.sunwoo@arm.com
1738931Sandreas.hansson@arm.com  private:
1748931Sandreas.hansson@arm.com
1758931Sandreas.hansson@arm.com    // Prevent copying
1768931Sandreas.hansson@arm.com    AbstractMemory(const AbstractMemory&);
1778931Sandreas.hansson@arm.com
1788931Sandreas.hansson@arm.com    // Prevent assignment
1798931Sandreas.hansson@arm.com    AbstractMemory& operator=(const AbstractMemory&);
1802391SN/A
1812391SN/A  public:
1828931Sandreas.hansson@arm.com
1838931Sandreas.hansson@arm.com    typedef AbstractMemoryParams Params;
1848931Sandreas.hansson@arm.com
1858931Sandreas.hansson@arm.com    AbstractMemory(const Params* p);
1868931Sandreas.hansson@arm.com    virtual ~AbstractMemory();
1872391SN/A
1889053Sdam.sunwoo@arm.com    /** read the system pointer
1899053Sdam.sunwoo@arm.com     * Implemented for completeness with the setter
1909053Sdam.sunwoo@arm.com     * @return pointer to the system object */
1919053Sdam.sunwoo@arm.com    System* system() const { return _system; }
1929053Sdam.sunwoo@arm.com
1939053Sdam.sunwoo@arm.com    /** Set the system pointer on this memory
1949053Sdam.sunwoo@arm.com     * This can't be done via a python parameter because the system needs
1959053Sdam.sunwoo@arm.com     * pointers to all the memories and the reverse would create a cycle in the
1969053Sdam.sunwoo@arm.com     * object graph. An init() this is set.
1979053Sdam.sunwoo@arm.com     * @param sys system pointer to set
1989053Sdam.sunwoo@arm.com     */
1999053Sdam.sunwoo@arm.com    void system(System *sys) { _system = sys; }
2009053Sdam.sunwoo@arm.com
2014762SN/A    const Params *
2024762SN/A    params() const
2034762SN/A    {
2044762SN/A        return dynamic_cast<const Params *>(_params);
2054762SN/A    }
2064762SN/A
2078931Sandreas.hansson@arm.com    /**
2088931Sandreas.hansson@arm.com     * Get the address range
2098931Sandreas.hansson@arm.com     *
2108931Sandreas.hansson@arm.com     * @return a single contigous address range
2118931Sandreas.hansson@arm.com     */
2128931Sandreas.hansson@arm.com    Range<Addr> getAddrRange();
2132391SN/A
2148931Sandreas.hansson@arm.com    /**
2158931Sandreas.hansson@arm.com     * Get the memory size.
2168931Sandreas.hansson@arm.com     *
2178931Sandreas.hansson@arm.com     * @return the size of the memory
2188931Sandreas.hansson@arm.com     */
2198931Sandreas.hansson@arm.com    uint64_t size() { return range.size(); }
2208923SN/A
2218931Sandreas.hansson@arm.com    /**
2228931Sandreas.hansson@arm.com     * Get the start address.
2238931Sandreas.hansson@arm.com     *
2248931Sandreas.hansson@arm.com     * @return the start address of the memory
2258931Sandreas.hansson@arm.com     */
2268931Sandreas.hansson@arm.com    Addr start() { return range.start; }
2278923SN/A
2288931Sandreas.hansson@arm.com    /**
2298931Sandreas.hansson@arm.com     *  Should this memory be passed to the kernel and part of the OS
2308931Sandreas.hansson@arm.com     *  physical memory layout.
2318931Sandreas.hansson@arm.com     *
2328931Sandreas.hansson@arm.com     * @return if this memory is reported
2338931Sandreas.hansson@arm.com     */
2348931Sandreas.hansson@arm.com    bool isConfReported() const { return confTableReported; }
2352391SN/A
2368931Sandreas.hansson@arm.com    /**
2378931Sandreas.hansson@arm.com     * Some memories are used as shadow memories or should for other
2388931Sandreas.hansson@arm.com     * reasons not be part of the global address map.
2398931Sandreas.hansson@arm.com     *
2408931Sandreas.hansson@arm.com     * @return if this memory is part of the address map
2418931Sandreas.hansson@arm.com     */
2428931Sandreas.hansson@arm.com    bool isInAddrMap() const { return inAddrMap; }
2438931Sandreas.hansson@arm.com
2448931Sandreas.hansson@arm.com    /**
2458931Sandreas.hansson@arm.com     * Perform an untimed memory access and update all the state
2468931Sandreas.hansson@arm.com     * (e.g. locked addresses) and statistics accordingly. The packet
2478931Sandreas.hansson@arm.com     * is turned into a response if required.
2488931Sandreas.hansson@arm.com     *
2498931Sandreas.hansson@arm.com     * @param pkt Packet performing the access
2508931Sandreas.hansson@arm.com     */
2518931Sandreas.hansson@arm.com    void access(PacketPtr pkt);
2528931Sandreas.hansson@arm.com
2538931Sandreas.hansson@arm.com    /**
2548931Sandreas.hansson@arm.com     * Perform an untimed memory read or write without changing
2558931Sandreas.hansson@arm.com     * anything but the memory itself. No stats are affected by this
2568931Sandreas.hansson@arm.com     * access. In addition to normal accesses this also facilitates
2578931Sandreas.hansson@arm.com     * print requests.
2588931Sandreas.hansson@arm.com     *
2598931Sandreas.hansson@arm.com     * @param pkt Packet performing the access
2608931Sandreas.hansson@arm.com     */
2618931Sandreas.hansson@arm.com    void functionalAccess(PacketPtr pkt);
2628931Sandreas.hansson@arm.com
2638931Sandreas.hansson@arm.com    /**
2648719SN/A     * Register Statistics
2658719SN/A     */
2668931Sandreas.hansson@arm.com    virtual void regStats();
2678719SN/A
2682391SN/A    virtual void serialize(std::ostream &os);
2692391SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
2702497SN/A
2712391SN/A};
2722391SN/A
2738931Sandreas.hansson@arm.com#endif //__ABSTRACT_MEMORY_HH__
274