copy_engine.hh revision 5809
112866Sgabeblack@google.com/*
212866Sgabeblack@google.com * Copyright (c) 2008 The Regents of The University of Michigan
312866Sgabeblack@google.com * All rights reserved.
412866Sgabeblack@google.com *
512866Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612866Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712866Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812866Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912866Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012866Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112866Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212866Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312866Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412866Sgabeblack@google.com * this software without specific prior written permission.
1512866Sgabeblack@google.com *
1612866Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712866Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812866Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912866Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012866Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112866Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212866Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312866Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412866Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512866Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612866Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712866Sgabeblack@google.com *
2812866Sgabeblack@google.com * Authors: Ali Saidi
2912866Sgabeblack@google.com */
3012866Sgabeblack@google.com
3112866Sgabeblack@google.com/* @file
3212866Sgabeblack@google.com * Device model for Intel's I/O Acceleration Technology (I/OAT).
3312866Sgabeblack@google.com * A DMA asyncronous copy engine
3412866Sgabeblack@google.com */
3512866Sgabeblack@google.com
3612866Sgabeblack@google.com#ifndef __DEV_COPY_ENGINE_HH__
3712866Sgabeblack@google.com#define __DEV_COPY_ENGINE_HH__
3812866Sgabeblack@google.com
3912866Sgabeblack@google.com#include <vector>
4012866Sgabeblack@google.com
4112866Sgabeblack@google.com#include "base/statistics.hh"
4212866Sgabeblack@google.com#include "dev/copy_engine_defs.hh"
4312866Sgabeblack@google.com#include "dev/pcidev.hh"
4412866Sgabeblack@google.com#include "params/CopyEngine.hh"
4512866Sgabeblack@google.com#include "sim/eventq.hh"
4612866Sgabeblack@google.com
4712866Sgabeblack@google.comclass CopyEngine : public PciDev
4812866Sgabeblack@google.com{
4912866Sgabeblack@google.com    class CopyEngineChannel
5012866Sgabeblack@google.com    {
5112866Sgabeblack@google.com      private:
5212866Sgabeblack@google.com        DmaPort *cePort;
5312866Sgabeblack@google.com        CopyEngine *ce;
5412866Sgabeblack@google.com        CopyEngineReg::ChanRegs  cr;
5512866Sgabeblack@google.com        int channelId;
5612866Sgabeblack@google.com        CopyEngineReg::DmaDesc *curDmaDesc;
5712866Sgabeblack@google.com        uint8_t *copyBuffer;
5812866Sgabeblack@google.com
5912866Sgabeblack@google.com        bool busy;
6012866Sgabeblack@google.com        bool underReset;
6112866Sgabeblack@google.com        bool refreshNext;
6212866Sgabeblack@google.com        Addr lastDescriptorAddr;
6312866Sgabeblack@google.com        Addr fetchAddress;
6412866Sgabeblack@google.com
6512869Sgabeblack@google.com        Tick latBeforeBegin;
6612866Sgabeblack@google.com        Tick latAfterCompletion;
6712869Sgabeblack@google.com
6812866Sgabeblack@google.com        uint64_t completionDataReg;
6912866Sgabeblack@google.com
7012866Sgabeblack@google.com        enum ChannelState {
7112866Sgabeblack@google.com            Idle,
7212866Sgabeblack@google.com            AddressFetch,
7312866Sgabeblack@google.com            DescriptorFetch,
7412866Sgabeblack@google.com            DMARead,
7512866Sgabeblack@google.com            DMAWrite,
7612866Sgabeblack@google.com            CompletionWrite
7712866Sgabeblack@google.com        };
7812866Sgabeblack@google.com
7912866Sgabeblack@google.com        ChannelState nextState;
8012866Sgabeblack@google.com
8112866Sgabeblack@google.com        Event *drainEvent;
8212869Sgabeblack@google.com      public:
8312869Sgabeblack@google.com        CopyEngineChannel(CopyEngine *_ce, int cid);
8412869Sgabeblack@google.com        virtual ~CopyEngineChannel();
8512869Sgabeblack@google.com        void init();
8612869Sgabeblack@google.com
8712869Sgabeblack@google.com        std::string name() { assert(ce); return ce->name() + csprintf("-chan%d", channelId); }
8812869Sgabeblack@google.com        virtual void addressRanges(AddrRangeList &range_list) { range_list.clear(); }
8912869Sgabeblack@google.com        virtual Tick read(PacketPtr pkt)
9012866Sgabeblack@google.com                        { panic("CopyEngineChannel has no I/O access\n");}
9112866Sgabeblack@google.com        virtual Tick write(PacketPtr pkt)
9212866Sgabeblack@google.com                        { panic("CopyEngineChannel has no I/O access\n"); }
9312866Sgabeblack@google.com
9412866Sgabeblack@google.com        void channelRead(PacketPtr pkt, Addr daddr, int size);
9512866Sgabeblack@google.com        void channelWrite(PacketPtr pkt, Addr daddr, int size);
9612866Sgabeblack@google.com
9712866Sgabeblack@google.com        unsigned int drain(Event *de);
9812866Sgabeblack@google.com        void resume();
9912866Sgabeblack@google.com        void serialize(std::ostream &os);
10012866Sgabeblack@google.com        void unserialize(Checkpoint *cp, const std::string &section);
10112866Sgabeblack@google.com
10212866Sgabeblack@google.com      private:
10312866Sgabeblack@google.com        void fetchDescriptor(Addr address);
10412866Sgabeblack@google.com        void fetchDescComplete();
10512866Sgabeblack@google.com        EventWrapper<CopyEngineChannel, &CopyEngineChannel::fetchDescComplete>
10612866Sgabeblack@google.com            fetchCompleteEvent;
10712866Sgabeblack@google.com
10812866Sgabeblack@google.com        void fetchNextAddr(Addr address);
10912866Sgabeblack@google.com        void fetchAddrComplete();
11012866Sgabeblack@google.com        EventWrapper<CopyEngineChannel, &CopyEngineChannel::fetchAddrComplete>
11112866Sgabeblack@google.com            addrCompleteEvent;
11212866Sgabeblack@google.com
11312866Sgabeblack@google.com        void readCopyBytes();
11412866Sgabeblack@google.com        void readCopyBytesComplete();
11512866Sgabeblack@google.com        EventWrapper<CopyEngineChannel, &CopyEngineChannel::readCopyBytesComplete>
11612866Sgabeblack@google.com            readCompleteEvent;
11712866Sgabeblack@google.com
11812866Sgabeblack@google.com        void writeCopyBytes();
11912866Sgabeblack@google.com        void writeCopyBytesComplete();
12012866Sgabeblack@google.com        EventWrapper <CopyEngineChannel, &CopyEngineChannel::writeCopyBytesComplete>
12112866Sgabeblack@google.com            writeCompleteEvent;
12212866Sgabeblack@google.com
12312866Sgabeblack@google.com        void writeCompletionStatus();
12412866Sgabeblack@google.com        void writeStatusComplete();
12512866Sgabeblack@google.com        EventWrapper <CopyEngineChannel, &CopyEngineChannel::writeStatusComplete>
12612866Sgabeblack@google.com            statusCompleteEvent;
12712866Sgabeblack@google.com
12812866Sgabeblack@google.com
12912866Sgabeblack@google.com        void continueProcessing();
13012866Sgabeblack@google.com        void recvCommand();
13112866Sgabeblack@google.com        bool inDrain();
13212866Sgabeblack@google.com        void restartStateMachine();
13312866Sgabeblack@google.com    };
13412866Sgabeblack@google.com
13512866Sgabeblack@google.com  private:
13612866Sgabeblack@google.com
13712866Sgabeblack@google.com    Stats::Vector<> bytesCopied;
13812866Sgabeblack@google.com    Stats::Vector<> copiesProcessed;
13912866Sgabeblack@google.com
14012866Sgabeblack@google.com    // device registers
14112866Sgabeblack@google.com    CopyEngineReg::Regs regs;
14212866Sgabeblack@google.com
14312866Sgabeblack@google.com    // Array of channels each one with regs/dma port/etc
14412866Sgabeblack@google.com    std::vector<CopyEngineChannel*> chan;
14512866Sgabeblack@google.com
14612866Sgabeblack@google.com  public:
14712866Sgabeblack@google.com    typedef CopyEngineParams Params;
14812866Sgabeblack@google.com    const Params *
14912866Sgabeblack@google.com    params() const
15012866Sgabeblack@google.com    {
15112866Sgabeblack@google.com        return dynamic_cast<const Params *>(_params);
15212866Sgabeblack@google.com    }
15312866Sgabeblack@google.com    CopyEngine(const Params *params);
15412866Sgabeblack@google.com    ~CopyEngine();
15512866Sgabeblack@google.com
15612866Sgabeblack@google.com    void regStats();
15712866Sgabeblack@google.com    void init();
15812866Sgabeblack@google.com
15912866Sgabeblack@google.com    virtual Tick read(PacketPtr pkt);
16012866Sgabeblack@google.com    virtual Tick write(PacketPtr pkt);
16112866Sgabeblack@google.com
162    virtual void serialize(std::ostream &os);
163    virtual void unserialize(Checkpoint *cp, const std::string &section);
164    virtual unsigned int drain(Event *de);
165    virtual void resume();
166};
167
168#endif //__DEV_COPY_ENGINE_HH__
169
170