sinic.hh revision 1939
110515SN/A/* 210515SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 310515SN/A * All rights reserved. 410515SN/A * 511570SCurtis.Dunham@arm.com * Redistribution and use in source and binary forms, with or without 610515SN/A * modification, are permitted provided that the following conditions are 711014Sandreas.sandberg@arm.com * met: redistributions of source code must retain the above copyright 810515SN/A * notice, this list of conditions and the following disclaimer; 910515SN/A * redistributions in binary form must reproduce the above copyright 1010515SN/A * notice, this list of conditions and the following disclaimer in the 1110515SN/A * 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#ifndef __DEV_SINIC_HH__ 30#define __DEV_SINIC_HH__ 31 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" 42 43namespace Sinic { 44 45class Interface; 46class Base : public PciDev 47{ 48 protected: 49 bool rxEnable; 50 bool txEnable; 51 Tick clock; 52 inline Tick cycles(int numCycles) const { return numCycles * clock; } 53 54 protected: 55 Tick intrDelay; 56 Tick intrTick; 57 bool cpuIntrEnable; 58 bool cpuPendingIntr; 59 void cpuIntrPost(Tick when); 60 void cpuInterrupt(); 61 void cpuIntrClear(); 62 63 typedef EventWrapper<Base, &Base::cpuInterrupt> IntrEvent; 64 friend void IntrEvent::process(); 65 IntrEvent *intrEvent; 66 Interface *interface; 67 68 bool cpuIntrPending() const; 69 void cpuIntrAck() { cpuIntrClear(); } 70 71/** 72 * Serialization stuff 73 */ 74 public: 75 virtual void serialize(std::ostream &os); 76 virtual void unserialize(Checkpoint *cp, const std::string §ion); 77 78/** 79 * Construction/Destruction/Parameters 80 */ 81 public: 82 struct Params : public PciDev::Params 83 { 84 Tick clock; 85 Tick intr_delay; 86 }; 87 88 Base(Params *p); 89}; 90 91class Device : public Base 92{ 93 protected: 94 Platform *plat; 95 PhysicalMemory *physmem; 96 97 protected: 98 /** Receive State Machine States */ 99 enum RxState { 100 rxIdle, 101 rxFifoBlock, 102 rxBeginCopy, 103 rxCopy, 104 rxCopyDone 105 }; 106 107 /** Transmit State Machine states */ 108 enum TxState { 109 txIdle, 110 txFifoBlock, 111 txBeginCopy, 112 txCopy, 113 txCopyDone 114 }; 115 116 /** device register file */ 117 struct { 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 137 } regs; 138 139 uint8_t ®Data8(Addr daddr) { return *((uint8_t *)®s + daddr); } 140 uint32_t ®Data32(Addr daddr) { return *(uint32_t *)®Data8(daddr); } 141 uint64_t ®Data64(Addr daddr) { return *(uint64_t *)®Data8(daddr); } 142 143 private: 144 Addr addr; 145 static const Addr size = Regs::Size; 146 147 protected: 148 RxState rxState; 149 PacketFifo rxFifo; 150 bool rxEmpty; 151 PacketPtr rxPacket; 152 uint8_t *rxPacketBufPtr; 153 int rxPktBytes; 154 uint64_t rxDoneData; 155 Addr rxDmaAddr; 156 uint8_t *rxDmaData; 157 int rxDmaLen; 158 159 TxState txState; 160 PacketFifo txFifo; 161 bool txFull; 162 PacketPtr txPacket; 163 uint8_t *txPacketBufPtr; 164 int txPktBytes; 165 Addr txDmaAddr; 166 uint8_t *txDmaData; 167 int txDmaLen; 168 169 protected: 170 void reset(); 171 172 void rxKick(); 173 Tick rxKickTick; 174 typedef EventWrapper<Device, &Device::rxKick> RxKickEvent; 175 friend void RxKickEvent::process(); 176 177 void txKick(); 178 Tick txKickTick; 179 typedef EventWrapper<Device, &Device::txKick> TxKickEvent; 180 friend void TxKickEvent::process(); 181 182 /** 183 * Retransmit event 184 */ 185 void transmit(); 186 void txEventTransmit() 187 { 188 transmit(); 189 if (txState == txFifoBlock) 190 txKick(); 191 } 192 typedef EventWrapper<Device, &Device::txEventTransmit> TxEvent; 193 friend void TxEvent::process(); 194 TxEvent txEvent; 195 196 void txDump() const; 197 void rxDump() const; 198 199 /** 200 * receive address filter 201 */ 202 bool rxFilter(const PacketPtr &packet); 203 204/** 205 * device configuration 206 */ 207 void changeConfig(uint32_t newconfig); 208 void command(uint32_t command); 209 210/** 211 * device ethernet interface 212 */ 213 public: 214 bool recvPacket(PacketPtr packet); 215 void transferDone(); 216 void setInterface(Interface *i) { assert(!interface); interface = i; } 217 218/** 219 * DMA parameters 220 */ 221 protected: 222 void rxDmaCopy(); 223 void rxDmaDone(); 224 friend class EventWrapper<Device, &Device::rxDmaDone>; 225 EventWrapper<Device, &Device::rxDmaDone> rxDmaEvent; 226 227 void txDmaCopy(); 228 void txDmaDone(); 229 friend class EventWrapper<Device, &Device::txDmaDone>; 230 EventWrapper<Device, &Device::txDmaDone> txDmaEvent; 231 232 Tick dmaReadDelay; 233 Tick dmaReadFactor; 234 Tick dmaWriteDelay; 235 Tick dmaWriteFactor; 236 237/** 238 * PIO parameters 239 */ 240 protected: 241 MemReqPtr rxPioRequest; 242 MemReqPtr txPioRequest; 243 244/** 245 * Interrupt management 246 */ 247 protected: 248 void devIntrPost(uint32_t interrupts); 249 void devIntrClear(uint32_t interrupts = Regs::Intr_All); 250 void devIntrChangeMask(uint32_t newmask); 251 252/** 253 * PCI Configuration interface 254 */ 255 public: 256 virtual void writeConfig(int offset, int size, const uint8_t *data); 257 258/** 259 * Memory Interface 260 */ 261 public: 262 void prepareRead(); 263 Fault iprRead(Addr daddr, uint64_t &result); 264 virtual Fault read(MemReqPtr &req, uint8_t *data); 265 virtual Fault write(MemReqPtr &req, const uint8_t *data); 266 Tick cacheAccess(MemReqPtr &req); 267 268/** 269 * Statistics 270 */ 271 private: 272 Stats::Scalar<> rxBytes; 273 Stats::Formula rxBandwidth; 274 Stats::Scalar<> rxPackets; 275 Stats::Formula rxPacketRate; 276 Stats::Scalar<> rxIpPackets; 277 Stats::Scalar<> rxTcpPackets; 278 Stats::Scalar<> rxUdpPackets; 279 Stats::Scalar<> rxIpChecksums; 280 Stats::Scalar<> rxTcpChecksums; 281 Stats::Scalar<> rxUdpChecksums; 282 283 Stats::Scalar<> txBytes; 284 Stats::Formula txBandwidth; 285 Stats::Formula totBandwidth; 286 Stats::Formula totPackets; 287 Stats::Formula totBytes; 288 Stats::Formula totPacketRate; 289 Stats::Scalar<> txPackets; 290 Stats::Formula txPacketRate; 291 Stats::Scalar<> txIpPackets; 292 Stats::Scalar<> txTcpPackets; 293 Stats::Scalar<> txUdpPackets; 294 Stats::Scalar<> txIpChecksums; 295 Stats::Scalar<> txTcpChecksums; 296 Stats::Scalar<> txUdpChecksums; 297 298 public: 299 virtual void regStats(); 300 301/** 302 * Serialization stuff 303 */ 304 public: 305 virtual void serialize(std::ostream &os); 306 virtual void unserialize(Checkpoint *cp, const std::string §ion); 307 308/** 309 * Construction/Destruction/Parameters 310 */ 311 public: 312 struct Params : public Base::Params 313 { 314 IntrControl *i; 315 PhysicalMemory *pmem; 316 Tick tx_delay; 317 Tick rx_delay; 318 HierParams *hier; 319 Bus *io_bus; 320 Bus *payload_bus; 321 Tick pio_latency; 322 PhysicalMemory *physmem; 323 IntrControl *intctrl; 324 bool rx_filter; 325 Net::EthAddr eaddr; 326 uint32_t rx_max_copy; 327 uint32_t tx_max_copy; 328 uint32_t rx_max_intr; 329 uint32_t rx_fifo_size; 330 uint32_t tx_fifo_size; 331 uint32_t rx_fifo_threshold; 332 uint32_t tx_fifo_threshold; 333 Tick dma_read_delay; 334 Tick dma_read_factor; 335 Tick dma_write_delay; 336 Tick dma_write_factor; 337 bool dma_no_allocate; 338 bool dedicated; 339 }; 340 341 protected: 342 const Params *params() const { return (const Params *)_params; } 343 344 public: 345 Device(Params *params); 346 ~Device(); 347}; 348 349/* 350 * Ethernet Interface for an Ethernet Device 351 */ 352class Interface : public EtherInt 353{ 354 private: 355 Device *dev; 356 357 public: 358 Interface(const std::string &name, Device *d) 359 : EtherInt(name), dev(d) { dev->setInterface(this); } 360 361 virtual bool recvPacket(PacketPtr pkt) { return dev->recvPacket(pkt); } 362 virtual void sendDone() { dev->transferDone(); } 363}; 364 365/* namespace Sinic */ } 366 367#endif // __DEV_SINIC_HH__ 368