gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pktfifo.cc
Go to the documentation of this file.
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  * Authors: Nathan Binkert
29  */
30 
31 #include "dev/net/pktfifo.hh"
32 
33 #include "base/misc.hh"
34 
35 using namespace std;
36 
37 bool
38 PacketFifo::copyout(void *dest, unsigned offset, unsigned len)
39 {
40  char *data = (char *)dest;
41  if (offset + len >= size())
42  return false;
43 
44  iterator i = fifo.begin();
45  iterator end = fifo.end();
46  while (len > 0) {
47  EthPacketPtr &pkt = i->packet;
48  while (offset >= pkt->length) {
49  offset -= pkt->length;
50  ++i;
51  }
52 
53  if (i == end)
54  panic("invalid fifo");
55 
56  unsigned size = min(pkt->length - offset, len);
57  memcpy(data, pkt->data, size);
58  offset = 0;
59  len -= size;
60  data += size;
61  ++i;
62  }
63 
64  return true;
65 }
66 
67 
68 void
70 {
71  packet->serialize(base + ".packet", cp);
72  paramOut(cp, base + ".slack", slack);
73  paramOut(cp, base + ".number", number);
74  paramOut(cp, base + ".priv", priv);
75 }
76 
77 void
79 {
80  packet = make_shared<EthPacketData>();
81  packet->unserialize(base + ".packet", cp);
82  paramIn(cp, base + ".slack", slack);
83  paramIn(cp, base + ".number", number);
84  paramIn(cp, base + ".priv", priv);
85 }
86 
87 void
88 PacketFifo::serialize(const string &base, CheckpointOut &cp) const
89 {
90  paramOut(cp, base + ".size", _size);
91  paramOut(cp, base + ".maxsize", _maxsize);
92  paramOut(cp, base + ".reserved", _reserved);
93  paramOut(cp, base + ".packets", fifo.size());
94 
95  int i = 0;
96  for (const auto &entry : fifo)
97  entry.serialize(csprintf("%s.entry%d", base, i++), cp);
98 }
99 
100 void
102 {
103  paramIn(cp, base + ".size", _size);
104 // paramIn(cp, base + ".maxsize", _maxsize);
105  paramIn(cp, base + ".reserved", _reserved);
106  int fifosize;
107  paramIn(cp, base + ".packets", fifosize);
108 
109  fifo.clear();
110 
111  for (int i = 0; i < fifosize; ++i) {
112  PacketFifoEntry entry;
113  entry.unserialize(csprintf("%s.entry%d", base, i), cp);
114  fifo.push_back(entry);
115  }
116 }
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: pktfifo.cc:101
Bitfield< 7 > i
Definition: miscregs.hh:1378
#define panic(...)
Definition: misc.hh:153
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: pktfifo.cc:78
Bitfield< 23, 0 > offset
Definition: types.hh:149
void serialize(const std::string &base, CheckpointOut &cp) const
Serialization stuff.
Definition: pktfifo.cc:88
const char data[]
Definition: circlebuf.cc:43
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
Definition: types.cc:40
Bitfield< 51, 12 > base
Definition: pagetable.hh:85
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
void serialize(const std::string &base, CheckpointOut &cp) const
Definition: pktfifo.cc:69
int size()
Definition: pagetable.hh:146
std::ostream CheckpointOut
Definition: serialize.hh:67
fifo_list::iterator iterator
Definition: pktfifo.hh:83
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
Bitfield< 2 > priv
Definition: miscregs.hh:129
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
Definition: types.cc:71
bool copyout(void *dest, unsigned offset, unsigned len)
Definition: pktfifo.cc:38

Generated on Fri Jun 9 2017 13:03:46 for gem5 by doxygen 1.8.6