copy_engine.hh revision 13784:1941dc118243
112853Sgabeblack@google.com/* 212853Sgabeblack@google.com * Copyright (c) 2012 ARM Limited 312853Sgabeblack@google.com * All rights reserved 412853Sgabeblack@google.com * 512853Sgabeblack@google.com * The license below extends only to copyright in the software and shall 612853Sgabeblack@google.com * not be construed as granting a license to any other intellectual 712853Sgabeblack@google.com * property including but not limited to intellectual property relating 812853Sgabeblack@google.com * to a hardware implementation of the functionality of the software 912853Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1012853Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1112853Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1212853Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1312853Sgabeblack@google.com * 1412853Sgabeblack@google.com * Copyright (c) 2008 The Regents of The University of Michigan 1512853Sgabeblack@google.com * All rights reserved. 1612853Sgabeblack@google.com * 1712853Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1812853Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1912853Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 2012853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 2112853Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 2212853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2312853Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2412853Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2512853Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2612853Sgabeblack@google.com * this software without specific prior written permission. 2712853Sgabeblack@google.com * 2812853Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2912853Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3012853Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3112853Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3212853Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3312853Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3412853Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3512853Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3612853Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3712853Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3812853Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3912853Sgabeblack@google.com * 4012853Sgabeblack@google.com * Authors: Ali Saidi 4112853Sgabeblack@google.com */ 4212853Sgabeblack@google.com 4312853Sgabeblack@google.com/* @file 4412853Sgabeblack@google.com * Device model for Intel's I/O Acceleration Technology (I/OAT). 4512853Sgabeblack@google.com * A DMA asyncronous copy engine 4612853Sgabeblack@google.com */ 4712853Sgabeblack@google.com 4812853Sgabeblack@google.com#ifndef __DEV_PCI_COPY_ENGINE_HH__ 4912853Sgabeblack@google.com#define __DEV_PCI_COPY_ENGINE_HH__ 5012853Sgabeblack@google.com 5112853Sgabeblack@google.com#include <vector> 5212853Sgabeblack@google.com 5312853Sgabeblack@google.com#include "base/cp_annotate.hh" 5412853Sgabeblack@google.com#include "base/statistics.hh" 5512853Sgabeblack@google.com#include "dev/pci/copy_engine_defs.hh" 5612853Sgabeblack@google.com#include "dev/pci/device.hh" 5712853Sgabeblack@google.com#include "params/CopyEngine.hh" 5812853Sgabeblack@google.com#include "sim/drain.hh" 5912853Sgabeblack@google.com#include "sim/eventq.hh" 6012853Sgabeblack@google.com 6112853Sgabeblack@google.comclass CopyEngine : public PciDevice 6212853Sgabeblack@google.com{ 6312853Sgabeblack@google.com class CopyEngineChannel : public Drainable, public Serializable 6412853Sgabeblack@google.com { 6512853Sgabeblack@google.com private: 6612853Sgabeblack@google.com DmaPort cePort; 6712853Sgabeblack@google.com CopyEngine *ce; 6812853Sgabeblack@google.com CopyEngineReg::ChanRegs cr; 6912853Sgabeblack@google.com int channelId; 7012853Sgabeblack@google.com CopyEngineReg::DmaDesc *curDmaDesc; 7112853Sgabeblack@google.com uint8_t *copyBuffer; 7212853Sgabeblack@google.com 7312853Sgabeblack@google.com bool busy; 7412853Sgabeblack@google.com bool underReset; 7512853Sgabeblack@google.com bool refreshNext; 7612853Sgabeblack@google.com Addr lastDescriptorAddr; 7712853Sgabeblack@google.com Addr fetchAddress; 7812853Sgabeblack@google.com 7912853Sgabeblack@google.com Tick latBeforeBegin; 8012853Sgabeblack@google.com Tick latAfterCompletion; 8112853Sgabeblack@google.com 8212853Sgabeblack@google.com uint64_t completionDataReg; 8312853Sgabeblack@google.com 8412853Sgabeblack@google.com enum ChannelState { 8512853Sgabeblack@google.com Idle, 8612853Sgabeblack@google.com AddressFetch, 8712853Sgabeblack@google.com DescriptorFetch, 8812853Sgabeblack@google.com DMARead, 8912853Sgabeblack@google.com DMAWrite, 9012853Sgabeblack@google.com CompletionWrite 9112853Sgabeblack@google.com }; 9212853Sgabeblack@google.com 9312853Sgabeblack@google.com ChannelState nextState; 9412853Sgabeblack@google.com 9512853Sgabeblack@google.com public: 9612853Sgabeblack@google.com CopyEngineChannel(CopyEngine *_ce, int cid); 9712853Sgabeblack@google.com virtual ~CopyEngineChannel(); 9812853Sgabeblack@google.com Port &getPort(); 9912853Sgabeblack@google.com 10012853Sgabeblack@google.com std::string name() { assert(ce); return ce->name() + csprintf("-chan%d", channelId); } 10112853Sgabeblack@google.com virtual Tick read(PacketPtr pkt) 10212853Sgabeblack@google.com { panic("CopyEngineChannel has no I/O access\n");} 10312853Sgabeblack@google.com virtual Tick write(PacketPtr pkt) 10412853Sgabeblack@google.com { panic("CopyEngineChannel has no I/O access\n"); } 10512853Sgabeblack@google.com 10612853Sgabeblack@google.com void channelRead(PacketPtr pkt, Addr daddr, int size); 10712853Sgabeblack@google.com void channelWrite(PacketPtr pkt, Addr daddr, int size); 10812853Sgabeblack@google.com 10912853Sgabeblack@google.com DrainState drain() override; 11012853Sgabeblack@google.com void drainResume() override; 11112853Sgabeblack@google.com 11212853Sgabeblack@google.com void serialize(CheckpointOut &cp) const override; 11312853Sgabeblack@google.com void unserialize(CheckpointIn &cp) override; 11412853Sgabeblack@google.com 11512853Sgabeblack@google.com private: 11612853Sgabeblack@google.com void fetchDescriptor(Addr address); 11712853Sgabeblack@google.com void fetchDescComplete(); 11812853Sgabeblack@google.com EventFunctionWrapper fetchCompleteEvent; 11912853Sgabeblack@google.com 12012853Sgabeblack@google.com void fetchNextAddr(Addr address); 12112853Sgabeblack@google.com void fetchAddrComplete(); 12212853Sgabeblack@google.com EventFunctionWrapper addrCompleteEvent; 12312853Sgabeblack@google.com 12412853Sgabeblack@google.com void readCopyBytes(); 12512853Sgabeblack@google.com void readCopyBytesComplete(); 12612853Sgabeblack@google.com EventFunctionWrapper readCompleteEvent; 12712853Sgabeblack@google.com 12812853Sgabeblack@google.com void writeCopyBytes(); 12912853Sgabeblack@google.com void writeCopyBytesComplete(); 13012853Sgabeblack@google.com EventFunctionWrapper writeCompleteEvent; 13112853Sgabeblack@google.com 13212853Sgabeblack@google.com void writeCompletionStatus(); 13312853Sgabeblack@google.com void writeStatusComplete(); 13412853Sgabeblack@google.com EventFunctionWrapper statusCompleteEvent; 13512853Sgabeblack@google.com 13612853Sgabeblack@google.com 13712853Sgabeblack@google.com void continueProcessing(); 13812853Sgabeblack@google.com void recvCommand(); 13912853Sgabeblack@google.com bool inDrain(); 14012853Sgabeblack@google.com void restartStateMachine(); 14112853Sgabeblack@google.com inline void anBegin(const char *s) 14212853Sgabeblack@google.com { 14312853Sgabeblack@google.com CPA::cpa()->hwBegin(CPA::FL_NONE, ce->sys, 14412853Sgabeblack@google.com channelId, "CopyEngine", s); 14512853Sgabeblack@google.com } 14612853Sgabeblack@google.com 14712853Sgabeblack@google.com inline void anWait() 14812853Sgabeblack@google.com { 14912853Sgabeblack@google.com CPA::cpa()->hwWe(CPA::FL_NONE, ce->sys, 15012853Sgabeblack@google.com channelId, "CopyEngine", "DMAUnusedDescQ", channelId); 15112853Sgabeblack@google.com } 15212853Sgabeblack@google.com 15312853Sgabeblack@google.com inline void anDq() 15412853Sgabeblack@google.com { 15512853Sgabeblack@google.com CPA::cpa()->hwDq(CPA::FL_NONE, ce->sys, 15612853Sgabeblack@google.com channelId, "CopyEngine", "DMAUnusedDescQ", channelId); 15712853Sgabeblack@google.com } 15812853Sgabeblack@google.com 15912853Sgabeblack@google.com inline void anPq() 16012853Sgabeblack@google.com { 16112853Sgabeblack@google.com CPA::cpa()->hwDq(CPA::FL_NONE, ce->sys, 16212853Sgabeblack@google.com channelId, "CopyEngine", "DMAUnusedDescQ", channelId); 16312853Sgabeblack@google.com } 16412853Sgabeblack@google.com 16512853Sgabeblack@google.com inline void anQ(const char * s, uint64_t id, int size = 1) 16612853Sgabeblack@google.com { 16712853Sgabeblack@google.com CPA::cpa()->hwQ(CPA::FL_NONE, ce->sys, channelId, 16812853Sgabeblack@google.com "CopyEngine", s, id, NULL, size); 16912853Sgabeblack@google.com } 17012853Sgabeblack@google.com 17112853Sgabeblack@google.com }; 17212853Sgabeblack@google.com 17312853Sgabeblack@google.com private: 17412853Sgabeblack@google.com 17512853Sgabeblack@google.com Stats::Vector bytesCopied; 17612853Sgabeblack@google.com Stats::Vector copiesProcessed; 17712853Sgabeblack@google.com 17812853Sgabeblack@google.com // device registers 17912853Sgabeblack@google.com CopyEngineReg::Regs regs; 18012853Sgabeblack@google.com 18112853Sgabeblack@google.com // Array of channels each one with regs/dma port/etc 18212853Sgabeblack@google.com std::vector<CopyEngineChannel*> chan; 18312853Sgabeblack@google.com 18412853Sgabeblack@google.com public: 18512853Sgabeblack@google.com typedef CopyEngineParams Params; 18612853Sgabeblack@google.com const Params * 18712853Sgabeblack@google.com params() const 18812853Sgabeblack@google.com { 18912853Sgabeblack@google.com return dynamic_cast<const Params *>(_params); 19012853Sgabeblack@google.com } 19112853Sgabeblack@google.com CopyEngine(const Params *params); 19212853Sgabeblack@google.com ~CopyEngine(); 19312853Sgabeblack@google.com 19412853Sgabeblack@google.com void regStats() override; 19512853Sgabeblack@google.com 19612853Sgabeblack@google.com Port &getPort(const std::string &if_name, 19712853Sgabeblack@google.com PortID idx = InvalidPortID) override; 19812853Sgabeblack@google.com 19912853Sgabeblack@google.com Tick read(PacketPtr pkt) override; 20012853Sgabeblack@google.com Tick write(PacketPtr pkt) override; 20112853Sgabeblack@google.com 20212853Sgabeblack@google.com void serialize(CheckpointOut &cp) const override; 20312853Sgabeblack@google.com void unserialize(CheckpointIn &cp) override; 20412853Sgabeblack@google.com}; 20512853Sgabeblack@google.com 20612853Sgabeblack@google.com#endif //__DEV_PCI_COPY_ENGINE_HH__ 20712853Sgabeblack@google.com 20812853Sgabeblack@google.com