pktfifo.cc revision 5483
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 2004-2005 The Regents of The University of Michigan 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org * 286145Snate@binkert.org * Authors: Nathan Binkert 296145Snate@binkert.org */ 307054Snate@binkert.org 317054Snate@binkert.org#include "base/misc.hh" 327054Snate@binkert.org#include "dev/pktfifo.hh" 337054Snate@binkert.org 346145Snate@binkert.orgusing namespace std; 356145Snate@binkert.org 367054Snate@binkert.orgbool 377054Snate@binkert.orgPacketFifo::copyout(void *dest, int offset, int len) 386145Snate@binkert.org{ 397002Snate@binkert.org char *data = (char *)dest; 408229Snate@binkert.org if (offset + len >= size()) 417454Snate@binkert.org return false; 427002Snate@binkert.org 436154Snate@binkert.org iterator i = fifo.begin(); 446145Snate@binkert.org iterator end = fifo.end(); 456145Snate@binkert.org while (len > 0) { 466145Snate@binkert.org EthPacketPtr &pkt = i->packet; 476145Snate@binkert.org while (offset >= pkt->length) { 489274Snilay@cs.wisc.edu offset -= pkt->length; 496145Snate@binkert.org ++i; 507054Snate@binkert.org } 517054Snate@binkert.org 527054Snate@binkert.org if (i == end) 537054Snate@binkert.org panic("invalid fifo"); 546145Snate@binkert.org 556145Snate@binkert.org int size = min(pkt->length - offset, len); 567054Snate@binkert.org memcpy(data, pkt->data, size); 577054Snate@binkert.org offset = 0; 587054Snate@binkert.org len -= size; 599274Snilay@cs.wisc.edu data += size; 607054Snate@binkert.org ++i; 616145Snate@binkert.org } 628054Sksewell@umich.edu 638054Sksewell@umich.edu return true; 648054Sksewell@umich.edu} 659274Snilay@cs.wisc.edu 667454Snate@binkert.org 677454Snate@binkert.orgvoid 687054Snate@binkert.orgPacketFifoEntry::serialize(const string &base, ostream &os) 697054Snate@binkert.org{ 707054Snate@binkert.org packet->serialize(base + ".packet", os); 717054Snate@binkert.org paramOut(os, base + ".slack", slack); 727054Snate@binkert.org paramOut(os, base + ".number", number); 737054Snate@binkert.org paramOut(os, base + ".priv", priv); 746145Snate@binkert.org} 757054Snate@binkert.org 767973Snilay@cs.wisc.eduvoid 776145Snate@binkert.orgPacketFifoEntry::unserialize(const string &base, Checkpoint *cp, 787054Snate@binkert.org const string §ion) 797054Snate@binkert.org{ 807054Snate@binkert.org packet = new EthPacketData(16384); 816145Snate@binkert.org packet->unserialize(base + ".packet", cp, section); 827054Snate@binkert.org paramIn(cp, section, base + ".slack", slack); 837054Snate@binkert.org paramIn(cp, section, base + ".number", number); 847054Snate@binkert.org paramIn(cp, section, base + ".priv", priv); 857054Snate@binkert.org} 866145Snate@binkert.org 877054Snate@binkert.orgvoid 886145Snate@binkert.orgPacketFifo::serialize(const string &base, ostream &os) 897054Snate@binkert.org{ 907454Snate@binkert.org paramOut(os, base + ".size", _size); 917454Snate@binkert.org paramOut(os, base + ".maxsize", _maxsize); 927454Snate@binkert.org paramOut(os, base + ".reserved", _reserved); 937454Snate@binkert.org paramOut(os, base + ".packets", fifo.size()); 949274Snilay@cs.wisc.edu 959274Snilay@cs.wisc.edu int i = 0; 967054Snate@binkert.org iterator entry = fifo.begin(); 977054Snate@binkert.org iterator end = fifo.end(); 989274Snilay@cs.wisc.edu while (entry != end) { 997054Snate@binkert.org entry->serialize(csprintf("%s.entry%d", base, i), os); 1007973Snilay@cs.wisc.edu ++entry; 1016145Snate@binkert.org ++i; 1026145Snate@binkert.org } 1037054Snate@binkert.org} 1047054Snate@binkert.org 1056145Snate@binkert.orgvoid 1067054Snate@binkert.orgPacketFifo::unserialize(const string &base, Checkpoint *cp, 1077054Snate@binkert.org const string §ion) 1087054Snate@binkert.org{ 1096145Snate@binkert.org paramIn(cp, section, base + ".size", _size); 1106145Snate@binkert.org// paramIn(cp, section, base + ".maxsize", _maxsize); 1117054Snate@binkert.org paramIn(cp, section, base + ".reserved", _reserved); 112 int fifosize; 113 paramIn(cp, section, base + ".packets", fifosize); 114 115 fifo.clear(); 116 117 for (int i = 0; i < fifosize; ++i) { 118 PacketFifoEntry entry; 119 entry.unserialize(csprintf("%s.entry%d", base, i), cp, section); 120 fifo.push_back(entry); 121 } 122} 123