simple_memobj.hh revision 12338
112338Sjason@lowepower.com/* 212338Sjason@lowepower.com * Copyright (c) 2017 Jason Lowe-Power 312338Sjason@lowepower.com * All rights reserved. 412338Sjason@lowepower.com * 512338Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without 612338Sjason@lowepower.com * modification, are permitted provided that the following conditions are 712338Sjason@lowepower.com * met: redistributions of source code must retain the above copyright 812338Sjason@lowepower.com * notice, this list of conditions and the following disclaimer; 912338Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright 1012338Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the 1112338Sjason@lowepower.com * documentation and/or other materials provided with the distribution; 1212338Sjason@lowepower.com * neither the name of the copyright holders nor the names of its 1312338Sjason@lowepower.com * contributors may be used to endorse or promote products derived from 1412338Sjason@lowepower.com * this software without specific prior written permission. 1512338Sjason@lowepower.com * 1612338Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712338Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812338Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912338Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012338Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112338Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212338Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312338Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412338Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512338Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612338Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712338Sjason@lowepower.com * 2812338Sjason@lowepower.com * Authors: Jason Lowe-Power 2912338Sjason@lowepower.com */ 3012338Sjason@lowepower.com 3112338Sjason@lowepower.com#ifndef __LEARNING_GEM5_PART2_SIMPLE_MEMOBJ_HH__ 3212338Sjason@lowepower.com#define __LEARNING_GEM5_PART2_SIMPLE_MEMOBJ_HH__ 3312338Sjason@lowepower.com 3412338Sjason@lowepower.com#include "mem/mem_object.hh" 3512338Sjason@lowepower.com#include "params/SimpleMemobj.hh" 3612338Sjason@lowepower.com 3712338Sjason@lowepower.com/** 3812338Sjason@lowepower.com * A very simple memory object. Current implementation doesn't even cache 3912338Sjason@lowepower.com * anything it just forwards requests and responses. 4012338Sjason@lowepower.com * This memobj is fully blocking (not non-blocking). Only a single request can 4112338Sjason@lowepower.com * be outstanding at a time. 4212338Sjason@lowepower.com */ 4312338Sjason@lowepower.comclass SimpleMemobj : public MemObject 4412338Sjason@lowepower.com{ 4512338Sjason@lowepower.com private: 4612338Sjason@lowepower.com 4712338Sjason@lowepower.com /** 4812338Sjason@lowepower.com * Port on the CPU-side that receives requests. 4912338Sjason@lowepower.com * Mostly just forwards requests to the owner. 5012338Sjason@lowepower.com * Part of a vector of ports. One for each CPU port (e.g., data, inst) 5112338Sjason@lowepower.com */ 5212338Sjason@lowepower.com class CPUSidePort : public SlavePort 5312338Sjason@lowepower.com { 5412338Sjason@lowepower.com private: 5512338Sjason@lowepower.com /// The object that owns this object (SimpleMemobj) 5612338Sjason@lowepower.com SimpleMemobj *owner; 5712338Sjason@lowepower.com 5812338Sjason@lowepower.com /// True if the port needs to send a retry req. 5912338Sjason@lowepower.com bool needRetry; 6012338Sjason@lowepower.com 6112338Sjason@lowepower.com /// If we tried to send a packet and it was blocked, store it here 6212338Sjason@lowepower.com PacketPtr blockedPacket; 6312338Sjason@lowepower.com 6412338Sjason@lowepower.com public: 6512338Sjason@lowepower.com /** 6612338Sjason@lowepower.com * Constructor. Just calls the superclass constructor. 6712338Sjason@lowepower.com */ 6812338Sjason@lowepower.com CPUSidePort(const std::string& name, SimpleMemobj *owner) : 6912338Sjason@lowepower.com SlavePort(name, owner), owner(owner), needRetry(false), 7012338Sjason@lowepower.com blockedPacket(nullptr) 7112338Sjason@lowepower.com { } 7212338Sjason@lowepower.com 7312338Sjason@lowepower.com /** 7412338Sjason@lowepower.com * Send a packet across this port. This is called by the owner and 7512338Sjason@lowepower.com * all of the flow control is hanled in this function. 7612338Sjason@lowepower.com * 7712338Sjason@lowepower.com * @param packet to send. 7812338Sjason@lowepower.com */ 7912338Sjason@lowepower.com void sendPacket(PacketPtr pkt); 8012338Sjason@lowepower.com 8112338Sjason@lowepower.com /** 8212338Sjason@lowepower.com * Get a list of the non-overlapping address ranges the owner is 8312338Sjason@lowepower.com * responsible for. All slave ports must override this function 8412338Sjason@lowepower.com * and return a populated list with at least one item. 8512338Sjason@lowepower.com * 8612338Sjason@lowepower.com * @return a list of ranges responded to 8712338Sjason@lowepower.com */ 8812338Sjason@lowepower.com AddrRangeList getAddrRanges() const override; 8912338Sjason@lowepower.com 9012338Sjason@lowepower.com /** 9112338Sjason@lowepower.com * Send a retry to the peer port only if it is needed. This is called 9212338Sjason@lowepower.com * from the SimpleMemobj whenever it is unblocked. 9312338Sjason@lowepower.com */ 9412338Sjason@lowepower.com void trySendRetry(); 9512338Sjason@lowepower.com 9612338Sjason@lowepower.com protected: 9712338Sjason@lowepower.com /** 9812338Sjason@lowepower.com * Receive an atomic request packet from the master port. 9912338Sjason@lowepower.com * No need to implement in this simple memobj. 10012338Sjason@lowepower.com */ 10112338Sjason@lowepower.com Tick recvAtomic(PacketPtr pkt) override 10212338Sjason@lowepower.com { panic("recvAtomic unimpl."); } 10312338Sjason@lowepower.com 10412338Sjason@lowepower.com /** 10512338Sjason@lowepower.com * Receive a functional request packet from the master port. 10612338Sjason@lowepower.com * Performs a "debug" access updating/reading the data in place. 10712338Sjason@lowepower.com * 10812338Sjason@lowepower.com * @param packet the requestor sent. 10912338Sjason@lowepower.com */ 11012338Sjason@lowepower.com void recvFunctional(PacketPtr pkt) override; 11112338Sjason@lowepower.com 11212338Sjason@lowepower.com /** 11312338Sjason@lowepower.com * Receive a timing request from the master port. 11412338Sjason@lowepower.com * 11512338Sjason@lowepower.com * @param the packet that the requestor sent 11612338Sjason@lowepower.com * @return whether this object can consume the packet. If false, we 11712338Sjason@lowepower.com * will call sendRetry() when we can try to receive this 11812338Sjason@lowepower.com * request again. 11912338Sjason@lowepower.com */ 12012338Sjason@lowepower.com bool recvTimingReq(PacketPtr pkt) override; 12112338Sjason@lowepower.com 12212338Sjason@lowepower.com /** 12312338Sjason@lowepower.com * Called by the master port if sendTimingResp was called on this 12412338Sjason@lowepower.com * slave port (causing recvTimingResp to be called on the master 12512338Sjason@lowepower.com * port) and was unsuccesful. 12612338Sjason@lowepower.com */ 12712338Sjason@lowepower.com void recvRespRetry() override; 12812338Sjason@lowepower.com }; 12912338Sjason@lowepower.com 13012338Sjason@lowepower.com /** 13112338Sjason@lowepower.com * Port on the memory-side that receives responses. 13212338Sjason@lowepower.com * Mostly just forwards requests to the owner 13312338Sjason@lowepower.com */ 13412338Sjason@lowepower.com class MemSidePort : public MasterPort 13512338Sjason@lowepower.com { 13612338Sjason@lowepower.com private: 13712338Sjason@lowepower.com /// The object that owns this object (SimpleMemobj) 13812338Sjason@lowepower.com SimpleMemobj *owner; 13912338Sjason@lowepower.com 14012338Sjason@lowepower.com /// If we tried to send a packet and it was blocked, store it here 14112338Sjason@lowepower.com PacketPtr blockedPacket; 14212338Sjason@lowepower.com 14312338Sjason@lowepower.com public: 14412338Sjason@lowepower.com /** 14512338Sjason@lowepower.com * Constructor. Just calls the superclass constructor. 14612338Sjason@lowepower.com */ 14712338Sjason@lowepower.com MemSidePort(const std::string& name, SimpleMemobj *owner) : 14812338Sjason@lowepower.com MasterPort(name, owner), owner(owner), blockedPacket(nullptr) 14912338Sjason@lowepower.com { } 15012338Sjason@lowepower.com 15112338Sjason@lowepower.com /** 15212338Sjason@lowepower.com * Send a packet across this port. This is called by the owner and 15312338Sjason@lowepower.com * all of the flow control is hanled in this function. 15412338Sjason@lowepower.com * 15512338Sjason@lowepower.com * @param packet to send. 15612338Sjason@lowepower.com */ 15712338Sjason@lowepower.com void sendPacket(PacketPtr pkt); 15812338Sjason@lowepower.com 15912338Sjason@lowepower.com protected: 16012338Sjason@lowepower.com /** 16112338Sjason@lowepower.com * Receive a timing response from the slave port. 16212338Sjason@lowepower.com */ 16312338Sjason@lowepower.com bool recvTimingResp(PacketPtr pkt) override; 16412338Sjason@lowepower.com 16512338Sjason@lowepower.com /** 16612338Sjason@lowepower.com * Called by the slave port if sendTimingReq was called on this 16712338Sjason@lowepower.com * master port (causing recvTimingReq to be called on the slave 16812338Sjason@lowepower.com * port) and was unsuccesful. 16912338Sjason@lowepower.com */ 17012338Sjason@lowepower.com void recvReqRetry() override; 17112338Sjason@lowepower.com 17212338Sjason@lowepower.com /** 17312338Sjason@lowepower.com * Called to receive an address range change from the peer slave 17412338Sjason@lowepower.com * port. The default implementation ignores the change and does 17512338Sjason@lowepower.com * nothing. Override this function in a derived class if the owner 17612338Sjason@lowepower.com * needs to be aware of the address ranges, e.g. in an 17712338Sjason@lowepower.com * interconnect component like a bus. 17812338Sjason@lowepower.com */ 17912338Sjason@lowepower.com void recvRangeChange() override; 18012338Sjason@lowepower.com }; 18112338Sjason@lowepower.com 18212338Sjason@lowepower.com /** 18312338Sjason@lowepower.com * Handle the request from the CPU side 18412338Sjason@lowepower.com * 18512338Sjason@lowepower.com * @param requesting packet 18612338Sjason@lowepower.com * @return true if we can handle the request this cycle, false if the 18712338Sjason@lowepower.com * requestor needs to retry later 18812338Sjason@lowepower.com */ 18912338Sjason@lowepower.com bool handleRequest(PacketPtr pkt); 19012338Sjason@lowepower.com 19112338Sjason@lowepower.com /** 19212338Sjason@lowepower.com * Handle the respone from the memory side 19312338Sjason@lowepower.com * 19412338Sjason@lowepower.com * @param responding packet 19512338Sjason@lowepower.com * @return true if we can handle the response this cycle, false if the 19612338Sjason@lowepower.com * responder needs to retry later 19712338Sjason@lowepower.com */ 19812338Sjason@lowepower.com bool handleResponse(PacketPtr pkt); 19912338Sjason@lowepower.com 20012338Sjason@lowepower.com /** 20112338Sjason@lowepower.com * Handle a packet functionally. Update the data on a write and get the 20212338Sjason@lowepower.com * data on a read. 20312338Sjason@lowepower.com * 20412338Sjason@lowepower.com * @param packet to functionally handle 20512338Sjason@lowepower.com */ 20612338Sjason@lowepower.com void handleFunctional(PacketPtr pkt); 20712338Sjason@lowepower.com 20812338Sjason@lowepower.com /** 20912338Sjason@lowepower.com * Return the address ranges this memobj is responsible for. Just use the 21012338Sjason@lowepower.com * same as the next upper level of the hierarchy. 21112338Sjason@lowepower.com * 21212338Sjason@lowepower.com * @return the address ranges this memobj is responsible for 21312338Sjason@lowepower.com */ 21412338Sjason@lowepower.com AddrRangeList getAddrRanges() const; 21512338Sjason@lowepower.com 21612338Sjason@lowepower.com /** 21712338Sjason@lowepower.com * Tell the CPU side to ask for our memory ranges. 21812338Sjason@lowepower.com */ 21912338Sjason@lowepower.com void sendRangeChange(); 22012338Sjason@lowepower.com 22112338Sjason@lowepower.com /// Instantiation of the CPU-side ports 22212338Sjason@lowepower.com CPUSidePort instPort; 22312338Sjason@lowepower.com CPUSidePort dataPort; 22412338Sjason@lowepower.com 22512338Sjason@lowepower.com /// Instantiation of the memory-side port 22612338Sjason@lowepower.com MemSidePort memPort; 22712338Sjason@lowepower.com 22812338Sjason@lowepower.com /// True if this is currently blocked waiting for a response. 22912338Sjason@lowepower.com bool blocked; 23012338Sjason@lowepower.com 23112338Sjason@lowepower.com public: 23212338Sjason@lowepower.com 23312338Sjason@lowepower.com /** constructor 23412338Sjason@lowepower.com */ 23512338Sjason@lowepower.com SimpleMemobj(SimpleMemobjParams *params); 23612338Sjason@lowepower.com 23712338Sjason@lowepower.com /** 23812338Sjason@lowepower.com * Get a master port with a given name and index. This is used at 23912338Sjason@lowepower.com * binding time and returns a reference to a protocol-agnostic 24012338Sjason@lowepower.com * base master port. 24112338Sjason@lowepower.com * 24212338Sjason@lowepower.com * @param if_name Port name 24312338Sjason@lowepower.com * @param idx Index in the case of a VectorPort 24412338Sjason@lowepower.com * 24512338Sjason@lowepower.com * @return A reference to the given port 24612338Sjason@lowepower.com */ 24712338Sjason@lowepower.com BaseMasterPort& getMasterPort(const std::string& if_name, 24812338Sjason@lowepower.com PortID idx = InvalidPortID) override; 24912338Sjason@lowepower.com 25012338Sjason@lowepower.com /** 25112338Sjason@lowepower.com * Get a slave port with a given name and index. This is used at 25212338Sjason@lowepower.com * binding time and returns a reference to a protocol-agnostic 25312338Sjason@lowepower.com * base master port. 25412338Sjason@lowepower.com * 25512338Sjason@lowepower.com * @param if_name Port name 25612338Sjason@lowepower.com * @param idx Index in the case of a VectorPort 25712338Sjason@lowepower.com * 25812338Sjason@lowepower.com * @return A reference to the given port 25912338Sjason@lowepower.com */ 26012338Sjason@lowepower.com BaseSlavePort& getSlavePort(const std::string& if_name, 26112338Sjason@lowepower.com PortID idx = InvalidPortID) override; 26212338Sjason@lowepower.com}; 26312338Sjason@lowepower.com 26412338Sjason@lowepower.com 26512338Sjason@lowepower.com#endif // __LEARNING_GEM5_PART2_SIMPLE_MEMOBJ_HH__ 266