rogue
Loading...
Searching...
No Matches
AxiStreamDma.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_HARDWARE_AXI_AXI_STREAM_DMA_H__
18#define __ROGUE_HARDWARE_AXI_AXI_STREAM_DMA_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <map>
24#include <memory>
25#include <string>
26#include <thread>
27
28#include "rogue/Logging.h"
31
32namespace rogue {
33namespace hardware {
34namespace axi {
35
40 public:
45 explicit AxiStreamDmaShared(std::string path);
46
47 // Shared driver file descriptor used for DMA buffer mapping.
48 int32_t fd;
49
50 // Device path.
51 std::string path;
52
53 // Number of active AxiStreamDma instances using this descriptor.
54 int32_t openCount;
55
56 // Pointer array to mapped DMA buffers for zero-copy mode.
57 void** rawBuff;
58
59 // Number of mapped DMA buffers.
60 uint32_t bCount;
61
62 // DMA buffer size in bytes.
63 uint32_t bSize;
64
65 // Zero-copy mode enabled for this path.
66 bool zCopyEn;
67};
68
70typedef std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> AxiStreamDmaSharedPtr;
71
94 // Shared mapped-buffer descriptor cache by device path.
95 static std::map<std::string, std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> > sharedBuffers_;
96
97 // Maximum number of buffers to receive in one DMA call.
98 static const uint32_t RxBufferCount = 100;
99
100 // Shared descriptor state for this path.
101 std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> desc_;
102
103 // Process-local descriptor for TX/RX operations and dest mask programming.
104 int32_t fd_;
105
106 // Destination selector used when transmitting frames.
107 uint32_t dest_;
108
109 // TX/alloc select timeout.
110 struct timeval timeout_;
111
112 // SSI flag handling enable.
113 bool enSsi_;
114
115 // RX worker thread control.
116 std::thread* thread_;
117 bool threadEn_;
118
119 // Logger instance.
120 std::shared_ptr<rogue::Logging> log_;
121
122 // RX worker thread entry point.
123 void runThread(std::weak_ptr<int>);
124
125 // Deferred DMA buffer return queue.
126 rogue::Queue<uint32_t> retQueue_;
127
128 // Threshold for draining return queue.
129 uint32_t retThold_;
130
131 // Opens/reuses shared DMA mapping state for a device path.
132 static std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> openShared(std::string path,
133 std::shared_ptr<rogue::Logging> log);
134
135 // Closes shared DMA mapping state when last user exits.
136 static void closeShared(std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared>);
137
138 public:
155 static std::shared_ptr<rogue::hardware::axi::AxiStreamDma> create(std::string path, uint32_t dest, bool ssiEnable);
156
171 static void zeroCopyDisable(std::string path);
172
176 static void setup_python();
177
198 AxiStreamDma(std::string path, uint32_t dest, bool ssiEnable);
199
202
204 void stop();
205
217 void setTimeout(uint32_t timeout);
218
230 void setDriverDebug(uint32_t level);
231
239 void dmaAck();
240
254 std::shared_ptr<rogue::interfaces::stream::Frame> acceptReq(uint32_t size, bool zeroCopyEn);
255
266 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
267
274 void retBuffer(uint8_t* data, uint32_t meta, uint32_t rawSize);
275
280 std::string getGitVersion();
281
286 uint32_t getApiVersion();
287
292 uint32_t getBuffSize();
293
298 uint32_t getRxBuffCount();
299
304 uint32_t getRxBuffinUserCount();
305
310 uint32_t getRxBuffinHwCount();
311
316 uint32_t getRxBuffinPreHwQCount();
317
322 uint32_t getRxBuffinSwQCount();
323
328 uint32_t getRxBuffMissCount();
329
334 uint32_t getTxBuffCount();
335
340 uint32_t getTxBuffinUserCount();
341
346 uint32_t getTxBuffinHwCount();
347
352 uint32_t getTxBuffinPreHwQCount();
353
358 uint32_t getTxBuffinSwQCount();
359
364 uint32_t getTxBuffMissCount();
365};
366
368typedef std::shared_ptr<rogue::hardware::axi::AxiStreamDma> AxiStreamDmaPtr;
369
370} // namespace axi
371} // namespace hardware
372}; // namespace rogue
373
374#endif
Thread-safe bounded queue with optional busy threshold.
Definition Queue.h:38
Bridge between Rogue stream interfaces and AXI Stream DMA drivers.
uint32_t getTxBuffMissCount()
Gets TX buffer missing count.
void dmaAck()
Sends an ACK strobe through driver-specific DMA control path.
uint32_t getRxBuffMissCount()
Gets RX buffer missing count.
uint32_t getTxBuffinUserCount()
Gets TX buffers currently held by user space.
void retBuffer(uint8_t *data, uint32_t meta, uint32_t rawSize)
Returns DMA-backed buffer memory after frame release.
void setDriverDebug(uint32_t level)
Sets DMA driver debug level.
static void setup_python()
Registers Python bindings for this class.
std::shared_ptr< rogue::interfaces::stream::Frame > acceptReq(uint32_t size, bool zeroCopyEn)
Allocates a frame for upstream writers.
uint32_t getBuffSize()
Gets DMA buffer size.
uint32_t getRxBuffinUserCount()
Gets RX buffers currently held by user space.
void acceptFrame(std::shared_ptr< rogue::interfaces::stream::Frame > frame)
Accepts a frame for DMA transmit.
uint32_t getTxBuffinSwQCount()
Gets TX buffers queued in software.
uint32_t getTxBuffinHwCount()
Gets TX buffers currently held by hardware.
uint32_t getRxBuffinPreHwQCount()
Gets RX buffers queued before hardware.
~AxiStreamDma()
Destroys the interface and stops background activity.
uint32_t getRxBuffinSwQCount()
Gets RX buffers queued in software.
std::string getGitVersion()
Gets DMA driver Git version string.
void stop()
Stops RX thread and closes DMA file descriptors.
void setTimeout(uint32_t timeout)
Sets TX/alloc wait timeout.
uint32_t getApiVersion()
Gets DMA driver API version.
uint32_t getTxBuffinPreHwQCount()
Gets TX buffers queued before hardware.
uint32_t getRxBuffinHwCount()
Gets RX buffers currently held by hardware.
uint32_t getTxBuffCount()
Gets TX DMA buffer count.
static void zeroCopyDisable(std::string path)
Disables zero-copy mode for a device path.
uint32_t getRxBuffCount()
Gets RX DMA buffer count.
Stream master endpoint.
Definition Master.h:65
static std::shared_ptr< rogue::interfaces::stream::Master > create()
Creates a stream master.
Definition Master.cpp:40
Stream slave endpoint and default frame pool.
Definition Slave.h:72
std::shared_ptr< rogue::hardware::axi::AxiStreamDma > AxiStreamDmaPtr
std::shared_ptr< rogue::hardware::axi::AxiStreamDmaShared > AxiStreamDmaSharedPtr