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; --- 28 unchanged lines hidden (view full) --- 37#include "mem/packet.hh" 38#include "mem/tport.hh" 39#include "params/BasicPioDevice.hh" 40#include "params/DmaDevice.hh" 41#include "params/PioDevice.hh" 42#include "sim/sim_object.hh" 43 44class Event; |
45class PioDevice; 46class DmaDevice; 47class System; 48 49/** 50 * The PioPort class is a programmed i/o port that all devices that are 51 * sensitive to an address range use. The port takes all the memory 52 * access types and roles them into one read() and write() call that the device |
53 * must respond to. The device must also provide the addressRanges() function |
54 * with which it returns the address ranges it is interested in. 55 */ 56class PioPort : public SimpleTimingPort 57{ 58 protected: 59 /** The device that this port serves. */ 60 PioDevice *device; 61 62 virtual Tick recvAtomic(PacketPtr pkt); 63 |
64 virtual void getDeviceAddressRanges(AddrRangeList &resp, 65 bool &snoop); |
66 67 public: 68 69 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport"); 70}; 71 72 73class DmaPort : public Port --- 50 unchanged lines hidden (view full) --- 124 125 /** Maximum time that device should back off for after failed sendTiming */ 126 Tick maxBackoffDelay; 127 128 /** If the port is currently waiting for a retry before it can send whatever 129 * it is that it's sending. */ 130 bool inRetry; 131 |
132 virtual bool recvTiming(PacketPtr pkt); 133 virtual Tick recvAtomic(PacketPtr pkt) |
134 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN } |
135 virtual void recvFunctional(PacketPtr pkt) |
136 { panic("dma port shouldn't be used for pio access."); } |
137 |
138 virtual void recvStatusChange(Status status) 139 { ; } |
140 |
141 virtual void recvRetry() ; 142 |
143 virtual void getDeviceAddressRanges(AddrRangeList &resp, 144 bool &snoop) 145 { resp.clear(); snoop = false; } |
146 147 void queueDma(PacketPtr pkt, bool front = false); 148 void sendDma(); 149 150 /** event to give us a kick every time we backoff time is reached. */ 151 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent; 152 153 public: |
154 DmaPort(MemObject *dev, System *s, Tick min_backoff, Tick max_backoff); |
155 156 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, 157 uint8_t *data, Tick delay, Request::Flags flag = 0); 158 159 bool dmaPending() { return pendingCount > 0; } 160 161 unsigned cacheBlockSize() const { return peerBlockSize(); } 162 unsigned int drain(Event *de); 163}; 164 165/** 166 * This device is the base class which all devices senstive to an address range 167 * inherit from. There are three pure virtual functions which all devices must |
168 * implement addressRanges(), read(), and write(). The magic do choose which |
169 * mode we are in, etc is handled by the PioPort so the device doesn't have to 170 * bother. 171 */ 172class PioDevice : public MemObject 173{ 174 protected: |
175 System *sys; 176 177 /** The pioPort that handles the requests for us and provides us requests 178 * that it sees. */ 179 PioPort *pioPort; 180 |
181 virtual void addressRanges(AddrRangeList &range_list) = 0; |
182 183 /** Pure virtual function that the device must implement. Called 184 * when a read command is recieved by the port. 185 * @param pkt Packet describing this request 186 * @return number of ticks it took to complete 187 */ 188 virtual Tick read(PacketPtr pkt) = 0; 189 --- 14 unchanged lines hidden (view full) --- 204 { 205 return dynamic_cast<const Params *>(_params); 206 } 207 208 virtual void init(); 209 210 virtual unsigned int drain(Event *de); 211 |
212 virtual Port *getPort(const std::string &if_name, int idx = -1) 213 { 214 if (if_name == "pio") { 215 if (pioPort != NULL) 216 fatal("%s: pio port already connected to %s", 217 name(), pioPort->getPeer()->name()); 218 pioPort = new PioPort(this, sys); 219 return pioPort; 220 } else 221 return NULL; 222 } |
223 friend class PioPort; 224 225}; 226 227class BasicPioDevice : public PioDevice 228{ 229 protected: 230 /** Address that the device listens to. */ --- 10 unchanged lines hidden (view full) --- 241 BasicPioDevice(const Params *p); 242 243 const Params * 244 params() const 245 { 246 return dynamic_cast<const Params *>(_params); 247 } 248 |
249 /** return the address ranges that this device responds to. 250 * @param range_list range list to populate with ranges |
251 */ |
252 void addressRanges(AddrRangeList &range_list); |
253 254}; 255 256class DmaDevice : public PioDevice 257{ 258 protected: 259 DmaPort *dmaPort; 260 --- 19 unchanged lines hidden (view full) --- 280 } 281 282 bool dmaPending() { return dmaPort->dmaPending(); } 283 284 virtual unsigned int drain(Event *de); 285 286 unsigned cacheBlockSize() const { return dmaPort->cacheBlockSize(); } 287 |
288 virtual Port *getPort(const std::string &if_name, int idx = -1) 289 { 290 if (if_name == "pio") { 291 if (pioPort != NULL) 292 fatal("%s: pio port already connected to %s", 293 name(), pioPort->getPeer()->name()); 294 pioPort = new PioPort(this, sys); 295 return pioPort; 296 } else if (if_name == "dma") { 297 if (dmaPort != NULL) 298 fatal("%s: dma port already connected to %s", 299 name(), dmaPort->getPeer()->name()); 300 dmaPort = new DmaPort(this, sys, params()->min_backoff_delay, 301 params()->max_backoff_delay); 302 return dmaPort; 303 } else 304 return NULL; 305 } |
306 307 friend class DmaPort; 308}; 309 310 311#endif // __DEV_IO_DEVICE_HH__ |