io_device.cc revision 2384
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "dev/io_device.hh" 30#include "sim/builder.hh" 31 32void 33PioPort::SendEvent::process() 34{ 35 if (port->sendTiming(packet) == Success) 36 return; 37 38 port->transmitList.push_back(&packet); 39} 40 41PioDevice::PioDevice(const std::string &name, Platform *p) 42 : SimObject(name), platform(p) 43{ 44 pioPort = new PioPort(this); 45} 46 47 48bool 49PioDevice::recvTiming(Packet &pkt) 50{ 51 device->recvAtomic(pkt); 52 sendTiming(pkt, pkt.responseTime-pkt.requestTime); 53 return Success; 54} 55 56PioDevice::~PioDevice() 57{ 58 if (pioPort) 59 delete pioInterface; 60} 61 62void 63DmaPort::sendDma(Packet &pkt) 64{ 65 device->platform->system->memoryMode() 66 { 67 case MemAtomic: 68 } 69} 70 71DmaDevice::DmaDevice(const std::string &name, Platform *p) 72 : PioDevice(name, p) 73{ 74 dmaPort = new dmaPort(this); 75} 76 77void 78DmaPort::dmaAction(Memory::Command cmd, DmaPort port, Addr addr, int size, 79 Event *event, uint8_t *data = NULL) 80{ 81 82 assert(event); 83 84 int prevSize = 0; 85 Packet basePkt; 86 Request baseReq; 87 88 basePkt.flags = 0; 89 basePkt.coherence = NULL; 90 basePkt.senderState = NULL; 91 basePkt.src = 0; 92 basePkt.dest = 0; 93 basePkt.cmd = cmd; 94 basePkt.result = Unknown; 95 basePkt.request = NULL; 96 baseReq.nicReq = true; 97 baseReq.time = curTick; 98 99 completionEvent = event; 100 101 for (ChunkGenerator gen(addr, size, sendBlockSizeQuery()); !gen.done(); gen.next()) { 102 Packet *pkt = new Packet(basePkt); 103 Request *req = new Request(baseReq); 104 pkt->addr = gen.addr(); 105 pkt->size = gen.size(); 106 pkt->req = req; 107 pkt->req->paddr = pkt->addr; 108 pkt->req->size = pkt->size; 109 // Increment the data pointer on a write 110 pkt->data = data ? data + prevSize : NULL ; 111 prevSize = pkt->size; 112 113 sendDma(*pkt); 114 } 115} 116 117 118void 119DmaPort::sendDma(Packet &pkt) 120{ 121 // some kind of selction between access methods 122 // more work is going to have to be done to make 123 // switching actually work 124 MemState state = device->platform->system->memState; 125 126 if (state == Timing) { 127 if (sendTiming(pkt) == Failure) 128 transmitList.push_back(&packet); 129 } else if (state == Atomic) { 130 sendAtomic(pkt); 131 completionEvent->schedule(pkt.responseTime - pkt.requestTime); 132 completionEvent == NULL; 133 } else if (state == Functional) { 134 sendFunctional(pkt); 135 // Is this correct??? 136 completionEvent->schedule(pkt.responseTime - pkt.requestTime); 137 completionEvent == NULL; 138 } else 139 panic("Unknown memory command state."); 140 141} 142 143DmaDevice::~DmaDevice() 144{ 145 if (dmaInterface) 146 delete dmaInterface; 147} 148 149 150