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 <atomic>
24#include <map>
25#include <memory>
26#include <mutex>
27#include <string>
28#include <thread>
29
30#include "rogue/Logging.h"
33
34namespace rogue {
35namespace hardware {
36namespace axi {
37
42 public:
47 explicit AxiStreamDmaShared(std::string path);
48
49 // Shared driver file descriptor used for DMA buffer mapping.
50 int32_t fd;
51
52 // Device path.
53 std::string path;
54
55 // Number of active AxiStreamDma instances using this descriptor.
56 int32_t openCount;
57
58 // Pointer array to mapped DMA buffers for zero-copy mode.
59 void** rawBuff;
60
61 // Number of mapped DMA buffers.
62 uint32_t bCount;
63
64 // DMA buffer size in bytes.
65 uint32_t bSize;
66
67 // Zero-copy mode enabled for this path.
68 bool zCopyEn;
69};
70
72typedef std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> AxiStreamDmaSharedPtr;
73
99 // Shared mapped-buffer descriptor cache by device path.
100 static std::map<std::string, std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> > sharedBuffers_;
101
102 // Maximum number of buffers to receive in one DMA call.
103 static const uint32_t RxBufferCount = 100;
104
105 // Shared descriptor state for this path.
106 std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> desc_;
107
108 // Process-local descriptor for TX/RX operations and dest mask programming.
109 int32_t fd_;
110
111 // Serializes fd_ close against deferred zero-copy buffer returns.
112 std::mutex fdMtx_;
113
114 // Destination selector used when transmitting frames.
115 uint32_t dest_;
116
117 // TX/alloc select timeout.
118 struct timeval timeout_;
119
120 // SSI flag handling enable.
121 bool enSsi_;
122
124 protected:
125 std::unique_ptr<std::thread> thread_;
126 std::atomic<bool> threadEn_{false};
128
129 private:
130 // Logger instance.
131 std::shared_ptr<rogue::Logging> log_;
132
133 // RX worker thread entry point.
134 void runThread(std::weak_ptr<int>);
135
136 // Deferred DMA buffer return queue.
137 rogue::Queue<uint32_t> retQueue_;
138
139 // Threshold for draining return queue.
140 uint32_t retThold_;
141
142 // Opens/reuses shared DMA mapping state for a device path.
143 static std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> openShared(std::string path,
144 std::shared_ptr<rogue::Logging> log);
145
146 // Closes shared DMA mapping state when last user exits.
147 static void closeShared(std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared>);
148
149 public:
166 static std::shared_ptr<rogue::hardware::axi::AxiStreamDma> create(std::string path, uint32_t dest, bool ssiEnable);
167
182 static void zeroCopyDisable(std::string path);
183
187 static void setup_python();
188
209 AxiStreamDma(std::string path, uint32_t dest, bool ssiEnable);
210
213
227 void stop();
228
240 void setTimeout(uint32_t timeout);
241
253 void setDriverDebug(uint32_t level);
254
262 void dmaAck();
263
277 std::shared_ptr<rogue::interfaces::stream::Frame> acceptReq(uint32_t size, bool zeroCopyEn);
278
289 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
290
297 void retBuffer(uint8_t* data, uint32_t meta, uint32_t rawSize);
298
303 std::string getGitVersion();
304
309 uint32_t getApiVersion();
310
315 uint32_t getBuffSize();
316
321 uint32_t getRxBuffCount();
322
327 uint32_t getRxBuffinUserCount();
328
333 uint32_t getRxBuffinHwCount();
334
339 uint32_t getRxBuffinPreHwQCount();
340
345 uint32_t getRxBuffinSwQCount();
346
351 uint32_t getRxBuffMissCount();
352
357 uint32_t getTxBuffCount();
358
363 uint32_t getTxBuffinUserCount();
364
369 uint32_t getTxBuffinHwCount();
370
375 uint32_t getTxBuffinPreHwQCount();
376
381 uint32_t getTxBuffinSwQCount();
382
387 uint32_t getTxBuffMissCount();
388};
389
391typedef std::shared_ptr<rogue::hardware::axi::AxiStreamDma> AxiStreamDmaPtr;
392
393} // namespace axi
394} // namespace hardware
395}; // namespace rogue
396
397#endif
Thread-safe bounded queue with optional busy threshold.
Definition Queue.h:39
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 the per-instance DMA file descriptor.
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