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 <string>
27#include <thread>
28
29#include "rogue/Logging.h"
32
33namespace rogue {
34namespace hardware {
35namespace axi {
36
41 public:
46 explicit AxiStreamDmaShared(std::string path);
47
48 // Shared driver file descriptor used for DMA buffer mapping.
49 int32_t fd;
50
51 // Device path.
52 std::string path;
53
54 // Number of active AxiStreamDma instances using this descriptor.
55 int32_t openCount;
56
57 // Pointer array to mapped DMA buffers for zero-copy mode.
58 void** rawBuff;
59
60 // Number of mapped DMA buffers.
61 uint32_t bCount;
62
63 // DMA buffer size in bytes.
64 uint32_t bSize;
65
66 // Zero-copy mode enabled for this path.
67 bool zCopyEn;
68};
69
71typedef std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> AxiStreamDmaSharedPtr;
72
95 // Shared mapped-buffer descriptor cache by device path.
96 static std::map<std::string, std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> > sharedBuffers_;
97
98 // Maximum number of buffers to receive in one DMA call.
99 static const uint32_t RxBufferCount = 100;
100
101 // Shared descriptor state for this path.
102 std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> desc_;
103
104 // Process-local descriptor for TX/RX operations and dest mask programming.
105 int32_t fd_;
106
107 // Destination selector used when transmitting frames.
108 uint32_t dest_;
109
110 // TX/alloc select timeout.
111 struct timeval timeout_;
112
113 // SSI flag handling enable.
114 bool enSsi_;
115
117 protected:
118 std::unique_ptr<std::thread> thread_;
119 std::atomic<bool> threadEn_{false};
121
122 private:
123 // Logger instance.
124 std::shared_ptr<rogue::Logging> log_;
125
126 // RX worker thread entry point.
127 void runThread(std::weak_ptr<int>);
128
129 // Deferred DMA buffer return queue.
130 rogue::Queue<uint32_t> retQueue_;
131
132 // Threshold for draining return queue.
133 uint32_t retThold_;
134
135 // Opens/reuses shared DMA mapping state for a device path.
136 static std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared> openShared(std::string path,
137 std::shared_ptr<rogue::Logging> log);
138
139 // Closes shared DMA mapping state when last user exits.
140 static void closeShared(std::shared_ptr<rogue::hardware::axi::AxiStreamDmaShared>);
141
142 public:
159 static std::shared_ptr<rogue::hardware::axi::AxiStreamDma> create(std::string path, uint32_t dest, bool ssiEnable);
160
175 static void zeroCopyDisable(std::string path);
176
180 static void setup_python();
181
202 AxiStreamDma(std::string path, uint32_t dest, bool ssiEnable);
203
206
208 void stop();
209
221 void setTimeout(uint32_t timeout);
222
234 void setDriverDebug(uint32_t level);
235
243 void dmaAck();
244
258 std::shared_ptr<rogue::interfaces::stream::Frame> acceptReq(uint32_t size, bool zeroCopyEn);
259
270 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
271
278 void retBuffer(uint8_t* data, uint32_t meta, uint32_t rawSize);
279
284 std::string getGitVersion();
285
290 uint32_t getApiVersion();
291
296 uint32_t getBuffSize();
297
302 uint32_t getRxBuffCount();
303
308 uint32_t getRxBuffinUserCount();
309
314 uint32_t getRxBuffinHwCount();
315
320 uint32_t getRxBuffinPreHwQCount();
321
326 uint32_t getRxBuffinSwQCount();
327
332 uint32_t getRxBuffMissCount();
333
338 uint32_t getTxBuffCount();
339
344 uint32_t getTxBuffinUserCount();
345
350 uint32_t getTxBuffinHwCount();
351
356 uint32_t getTxBuffinPreHwQCount();
357
362 uint32_t getTxBuffinSwQCount();
363
368 uint32_t getTxBuffMissCount();
369};
370
372typedef std::shared_ptr<rogue::hardware::axi::AxiStreamDma> AxiStreamDmaPtr;
373
374} // namespace axi
375} // namespace hardware
376}; // namespace rogue
377
378#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 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