2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
29 #ifndef __DEV_SINIC_HH__
30 #define __DEV_SINIC_HH__
32 #include "base/inet.hh"
33 #include "base/statistics.hh"
34 #include "dev/etherint.hh"
35 #include "dev/etherpkt.hh"
36 #include "dev/io_device.hh"
37 #include "dev/pcidev.hh"
38 #include "dev/pktfifo.hh"
39 #include "dev/sinicreg.hh"
40 #include "mem/bus/bus.hh"
41 #include "sim/eventq.hh"
46 class Base : public PciDev
52 inline Tick cycles(int numCycles) const { return numCycles * clock; }
59 void cpuIntrPost(Tick when);
63 typedef EventWrapper<Base, &Base::cpuInterrupt> IntrEvent;
64 friend void IntrEvent::process();
68 bool cpuIntrPending() const;
69 void cpuIntrAck() { cpuIntrClear(); }
75 virtual void serialize(std::ostream &os);
76 virtual void unserialize(Checkpoint *cp, const std::string §ion);
79 * Construction/Destruction/Parameters
82 struct Params : public PciDev::Params
91 class Device : public Base
95 PhysicalMemory *physmem;
98 /** Receive State Machine States */
107 /** Transmit State Machine states */
116 /** device register file */
118 uint32_t Config; // 0x00
119 uint32_t Command; // 0x04
120 uint32_t IntrStatus; // 0x08
121 uint32_t IntrMask; // 0x0c
122 uint32_t RxMaxCopy; // 0x10
123 uint32_t TxMaxCopy; // 0x14
124 uint32_t RxMaxIntr; // 0x18
125 uint32_t Reserved0; // 0x1c
126 uint32_t RxFifoSize; // 0x20
127 uint32_t TxFifoSize; // 0x24
128 uint32_t RxFifoMark; // 0x28
129 uint32_t TxFifoMark; // 0x2c
130 uint64_t RxData; // 0x30
131 uint64_t RxDone; // 0x38
132 uint64_t RxWait; // 0x40
133 uint64_t TxData; // 0x48
134 uint64_t TxDone; // 0x50
135 uint64_t TxWait; // 0x58
136 uint64_t HwAddr; // 0x60
145 PacketFifo::iterator rxPacket;
151 : RxData(0), RxDone(0), TxData(0), TxDone(0),
152 rxPacketOffset(0), rxPacketBytes(0), rxDoneData(0)
155 typedef std::vector<VirtualReg> VirtualRegs;
156 typedef std::list<int> VirtualList;
157 VirtualRegs virtualRegs;
161 uint8_t ®Data8(Addr daddr) { return *((uint8_t *)®s + daddr); }
162 uint32_t ®Data32(Addr daddr) { return *(uint32_t *)®Data8(daddr); }
163 uint64_t ®Data64(Addr daddr) { return *(uint64_t *)®Data8(daddr); }
167 static const Addr size = Regs::Size;
172 PacketFifo::iterator rxFifoPtr;
193 typedef EventWrapper<Device, &Device::rxKick> RxKickEvent;
194 friend void RxKickEvent::process();
198 typedef EventWrapper<Device, &Device::txKick> TxKickEvent;
199 friend void TxKickEvent::process();
205 void txEventTransmit()
208 if (txState == txFifoBlock)
211 typedef EventWrapper<Device, &Device::txEventTransmit> TxEvent;
212 friend void TxEvent::process();
219 * receive address filter
221 bool rxFilter(const PacketPtr &packet);
224 * device configuration
226 void changeConfig(uint32_t newconfig);
227 void command(uint32_t command);
230 * device ethernet interface
233 bool recvPacket(PacketPtr packet);
235 void setInterface(Interface *i) { assert(!interface); interface = i; }
243 friend class EventWrapper<Device, &Device::rxDmaDone>;
244 EventWrapper<Device, &Device::rxDmaDone> rxDmaEvent;
248 friend class EventWrapper<Device, &Device::txDmaDone>;
249 EventWrapper<Device, &Device::txDmaDone> txDmaEvent;
257 * Interrupt management
260 void devIntrPost(uint32_t interrupts);
261 void devIntrClear(uint32_t interrupts = Regs::Intr_All);
262 void devIntrChangeMask(uint32_t newmask);
265 * PCI Configuration interface
268 virtual void writeConfig(int offset, int size, const uint8_t *data);
274 virtual Fault * read(MemReqPtr &req, uint8_t *data);
275 virtual Fault * write(MemReqPtr &req, const uint8_t *data);
277 void prepareIO(int cpu, int index);
278 void prepareRead(int cpu, int index);
279 void prepareWrite(int cpu, int index);
280 Fault * iprRead(Addr daddr, int cpu, uint64_t &result);
281 Fault * readBar0(MemReqPtr &req, Addr daddr, uint8_t *data);
282 Fault * writeBar0(MemReqPtr &req, Addr daddr, const uint8_t *data);
283 void regWrite(Addr daddr, int cpu, const uint8_t *data);
284 Tick cacheAccess(MemReqPtr &req);
287 struct RegWriteData {
290 RegWriteData(Addr da, uint64_t val) : daddr(da), value(val) {}
293 std::vector<std::list<RegWriteData> > writeQueue;
301 Stats::Scalar<> rxBytes;
302 Stats::Formula rxBandwidth;
303 Stats::Scalar<> rxPackets;
304 Stats::Formula rxPacketRate;
305 Stats::Scalar<> rxIpPackets;
306 Stats::Scalar<> rxTcpPackets;
307 Stats::Scalar<> rxUdpPackets;
308 Stats::Scalar<> rxIpChecksums;
309 Stats::Scalar<> rxTcpChecksums;
310 Stats::Scalar<> rxUdpChecksums;
312 Stats::Scalar<> txBytes;
313 Stats::Formula txBandwidth;
314 Stats::Formula totBandwidth;
315 Stats::Formula totPackets;
316 Stats::Formula totBytes;
317 Stats::Formula totPacketRate;
318 Stats::Scalar<> txPackets;
319 Stats::Formula txPacketRate;
320 Stats::Scalar<> txIpPackets;
321 Stats::Scalar<> txTcpPackets;
322 Stats::Scalar<> txUdpPackets;
323 Stats::Scalar<> txIpChecksums;
324 Stats::Scalar<> txTcpChecksums;
325 Stats::Scalar<> txUdpChecksums;
328 virtual void regStats();
331 * Serialization stuff
334 virtual void serialize(std::ostream &os);
335 virtual void unserialize(Checkpoint *cp, const std::string §ion);
338 * Construction/Destruction/Parameters
341 struct Params : public Base::Params
344 PhysicalMemory *pmem;
352 bool pio_delay_write;
353 PhysicalMemory *physmem;
354 IntrControl *intctrl;
357 uint32_t rx_max_copy;
358 uint32_t tx_max_copy;
359 uint32_t rx_max_intr;
360 uint32_t rx_fifo_size;
361 uint32_t tx_fifo_size;
362 uint32_t rx_fifo_threshold;
363 uint32_t tx_fifo_threshold;
365 Tick dma_read_factor;
366 Tick dma_write_delay;
367 Tick dma_write_factor;
368 bool dma_no_allocate;
374 const Params *params() const { return (const Params *)_params; }
377 Device(Params *params);
382 * Ethernet Interface for an Ethernet Device
384 class Interface : public EtherInt
390 Interface(const std::string &name, Device *d)
391 : EtherInt(name), dev(d) { dev->setInterface(this); }
393 virtual bool recvPacket(PacketPtr pkt) { return dev->recvPacket(pkt); }
394 virtual void sendDone() { dev->transferDone(); }
397 /* namespace Sinic */ }
399 #endif // __DEV_SINIC_HH__