simple_mem.hh revision 9349
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 * SimpleMemory declaration
472391SN/A */
482391SN/A
498931Sandreas.hansson@arm.com#ifndef __SIMPLE_MEMORY_HH__
508931Sandreas.hansson@arm.com#define __SIMPLE_MEMORY_HH__
512391SN/A
528931Sandreas.hansson@arm.com#include "mem/abstract_mem.hh"
538931Sandreas.hansson@arm.com#include "mem/tport.hh"
548931Sandreas.hansson@arm.com#include "params/SimpleMemory.hh"
554762SN/A
568931Sandreas.hansson@arm.com/**
579120Sandreas.hansson@arm.com * The simple memory is a basic single-ported memory controller with
589228Sandreas.hansson@arm.com * an configurable throughput and latency, potentially with a variance
599228Sandreas.hansson@arm.com * added to the latter. It uses a QueueSlavePort to avoid dealing with
609228Sandreas.hansson@arm.com * the flow control of sending responses.
619264Sdjordje.kovacevic@arm.com * @sa  \ref gem5MemorySystem "gem5 Memory System"
628931Sandreas.hansson@arm.com */
638931Sandreas.hansson@arm.comclass SimpleMemory : public AbstractMemory
648931Sandreas.hansson@arm.com{
652462SN/A
668931Sandreas.hansson@arm.com  private:
676107SN/A
689228Sandreas.hansson@arm.com    class MemoryPort : public QueuedSlavePort
692413SN/A    {
709228Sandreas.hansson@arm.com
719228Sandreas.hansson@arm.com      private:
729228Sandreas.hansson@arm.com
739228Sandreas.hansson@arm.com        /// Queue holding the response packets
749228Sandreas.hansson@arm.com        SlavePacketQueue queueImpl;
758931Sandreas.hansson@arm.com        SimpleMemory& memory;
762413SN/A
772413SN/A      public:
782413SN/A
798931Sandreas.hansson@arm.com        MemoryPort(const std::string& _name, SimpleMemory& _memory);
802413SN/A
812413SN/A      protected:
822413SN/A
839228Sandreas.hansson@arm.com        Tick recvAtomic(PacketPtr pkt);
842413SN/A
859228Sandreas.hansson@arm.com        void recvFunctional(PacketPtr pkt);
862413SN/A
879228Sandreas.hansson@arm.com        bool recvTimingReq(PacketPtr pkt);
889228Sandreas.hansson@arm.com
899228Sandreas.hansson@arm.com        AddrRangeList getAddrRanges() const;
902413SN/A
912413SN/A    };
922413SN/A
939120Sandreas.hansson@arm.com    MemoryPort port;
942416SN/A
952565SN/A    Tick lat;
965399SN/A    Tick lat_var;
978719SN/A
989228Sandreas.hansson@arm.com    /// Bandwidth in ticks per byte
999228Sandreas.hansson@arm.com    const double bandwidth;
1009228Sandreas.hansson@arm.com
1019228Sandreas.hansson@arm.com    /**
1029228Sandreas.hansson@arm.com     * Track the state of the memory as either idle or busy, no need
1039228Sandreas.hansson@arm.com     * for an enum with only two states.
1049228Sandreas.hansson@arm.com     */
1059228Sandreas.hansson@arm.com    bool isBusy;
1069228Sandreas.hansson@arm.com
1079228Sandreas.hansson@arm.com    /**
1089228Sandreas.hansson@arm.com     * Remember if we have to retry an outstanding request that
1099228Sandreas.hansson@arm.com     * arrived while we were busy.
1109228Sandreas.hansson@arm.com     */
1119228Sandreas.hansson@arm.com    bool retryReq;
1129228Sandreas.hansson@arm.com
1139228Sandreas.hansson@arm.com    /**
1149228Sandreas.hansson@arm.com     * Release the memory after being busy and send a retry if a
1159228Sandreas.hansson@arm.com     * request was rejected in the meanwhile.
1169228Sandreas.hansson@arm.com     */
1179228Sandreas.hansson@arm.com    void release();
1189228Sandreas.hansson@arm.com
1199228Sandreas.hansson@arm.com    EventWrapper<SimpleMemory, &SimpleMemory::release> releaseEvent;
1209228Sandreas.hansson@arm.com
1219349SAli.Saidi@ARM.com    /** @todo this is a temporary workaround until the 4-phase code is
1229349SAli.Saidi@ARM.com     * committed. upstream caches needs this packet until true is returned, so
1239349SAli.Saidi@ARM.com     * hold onto it for deletion until a subsequent call
1249349SAli.Saidi@ARM.com     */
1259349SAli.Saidi@ARM.com    std::vector<PacketPtr> pendingDelete;
1269349SAli.Saidi@ARM.com
1272391SN/A  public:
1282391SN/A
1299228Sandreas.hansson@arm.com    SimpleMemory(const SimpleMemoryParams *p);
1308931Sandreas.hansson@arm.com    virtual ~SimpleMemory() { }
1318931Sandreas.hansson@arm.com
1329342SAndreas.Sandberg@arm.com    unsigned int drain(DrainManager *dm);
1338931Sandreas.hansson@arm.com
1349294Sandreas.hansson@arm.com    virtual BaseSlavePort& getSlavePort(const std::string& if_name,
1359294Sandreas.hansson@arm.com                                        PortID idx = InvalidPortID);
1368931Sandreas.hansson@arm.com    virtual void init();
1372391SN/A
1388931Sandreas.hansson@arm.com  protected:
1392391SN/A
1404626SN/A    Tick doAtomicAccess(PacketPtr pkt);
1413349SN/A    void doFunctionalAccess(PacketPtr pkt);
1429228Sandreas.hansson@arm.com    bool recvTimingReq(PacketPtr pkt);
1439228Sandreas.hansson@arm.com    Tick calculateLatency(PacketPtr pkt);
1442391SN/A
1452391SN/A};
1462391SN/A
1478931Sandreas.hansson@arm.com#endif //__SIMPLE_MEMORY_HH__
148