22#ifndef __DMA_DRIVER_H__
23#define __DMA_DRIVER_H__
26 #include <linux/types.h>
34#define DMA_VERSION 0x06
37#define DMA_ERR_FIFO 0x01
38#define DMA_ERR_LEN 0x02
39#define DMA_ERR_MAX 0x04
40#define DMA_ERR_BUS 0x08
43#define DMA_Get_Buff_Count 0x1001
44#define DMA_Get_Buff_Size 0x1002
45#define DMA_Set_Debug 0x1003
46#define DMA_Set_Mask 0x1004
47#define DMA_Ret_Index 0x1005
48#define DMA_Get_Index 0x1006
49#define DMA_Read_Ready 0x1007
50#define DMA_Set_MaskBytes 0x1008
51#define DMA_Get_Version 0x1009
52#define DMA_Write_Register 0x100A
53#define DMA_Read_Register 0x100B
54#define DMA_Get_RxBuff_Count 0x100C
55#define DMA_Get_TxBuff_Count 0x100D
56#define DMA_Get_TxBuffinUser_Count 0x100F
57#define DMA_Get_TxBuffinHW_Count 0x1010
58#define DMA_Get_TxBuffinPreHWQ_Count 0x1011
59#define DMA_Get_TxBuffinSWQ_Count 0x1012
60#define DMA_Get_TxBuffMiss_Count 0x1013
61#define DMA_Get_RxBuffinUser_Count 0x1014
62#define DMA_Get_RxBuffinHW_Count 0x1015
63#define DMA_Get_RxBuffinPreHWQ_Count 0x1016
64#define DMA_Get_RxBuffinSWQ_Count 0x1017
65#define DMA_Get_RxBuffMiss_Count 0x1018
66#define DMA_Get_GITV 0x1019
69#define DMA_MASK_SIZE 512
146 #include <sys/fcntl.h>
147 #include <sys/ioctl.h>
148 #include <sys/mman.h>
149 #include <sys/signal.h>
150 #include <sys/socket.h>
169static inline ssize_t
dmaWrite(int32_t fd,
const void* buf,
size_t size, uint32_t flags, uint32_t dest) {
176 w.
is32 = (
sizeof(
void*) == 4);
177 w.
data = (uint64_t)buf;
204 w.
is32 = (
sizeof(
void*) == 4);
243 for (x = 0; x < iovlen; x++) {
246 w.
flags = (x == 0) ? begFlags : ((x == (iovlen - 1)) ? endFlags : midFlags);
247 w.
size = iov[x].iov_len;
248 w.
is32 = (
sizeof(
void*) == 4);
249 w.
data = (uint64_t)iov[x].iov_base;
295 for (x = 0; x < iovlen; x++) {
298 w.
flags = (x == 0) ? begFlags : ((x == (iovlen - 1)) ? endFlags : midFlags);
299 w.
size = iov[x].iov_len;
300 w.
is32 = (
sizeof(
void*) == 4);
301 w.
index = (uint32_t)(((uint64_t)iov[x].iov_base) & 0xFFFFFFFF);
331static inline ssize_t
dmaRead(int32_t fd,
void* buf,
size_t maxSize, uint32_t*
flags, uint32_t* error, uint32_t*
dest) {
337 r.
is32 = (
sizeof(
void*) == 4);
338 r.
data = (uint64_t)buf;
342 if (
ret <= 0)
return (
ret);
373 if (
ret <= 0)
return (
ret);
413 res = read(fd, r, count *
sizeof(
struct DmaReadData));
415 for (x = 0; x < res; ++x) {
440 return (ioctl(fd, cmd, &
index));
455static inline ssize_t
dmaRetIndexes(int32_t fd, uint32_t count, uint32_t* indexes) {
458 return (ioctl(fd, cmd, indexes));
684 return std::string(gitv);
698static inline void**
dmaMapDma(int32_t fd, uint32_t* count, uint32_t*
size) {
709 if (count != NULL) *count = bCount;
712 if ((
ret =
reinterpret_cast<void**
>(calloc(
sizeof(
void*), bCount))) == 0)
return (NULL);
716 while (gCount < bCount) {
717 offset = (off_t)bSize * (off_t)gCount;
719 if ((temp = mmap(0, bSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == MAP_FAILED)
break;
720 ret[gCount++] = temp;
724 if (gCount != bCount) {
725 while (gCount != 0) munmap(
ret[--gCount], bSize);
750 for (x = 0; x < bCount; x++) munmap(buffer[x], bSize);
783 struct sigaction act;
786 act.sa_handler = handler;
787 sigemptyset(&act.sa_mask);
790 sigaction(SIGIO, &act, NULL);
791 fcntl(fd, F_SETOWN, getpid());
792 oflags = fcntl(fd, F_GETFL);
793 fcntl(fd, F_SETFL, oflags | FASYNC);
839 mask[byte] += (1 << bit);
956 intOffset = ((off_t)bSize * bCount) + offset;
959 return mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, intOffset);
static ssize_t dmaSetMask(int32_t fd, uint32_t mask)
Set DMA mask.
static std::string dmaGetGitVersion(int32_t fd)
Get the DMA Driver's Git Version.
#define DMA_Get_Buff_Size
static ssize_t dmaGetTxBuffinPreHwQCount(int32_t fd)
Get the transmit buffer count in pre-hardware queue.
static ssize_t dmaGetTxBuffCount(int32_t fd)
Get the transmit buffer count.
static ssize_t dmaGetTxBuffMissCount(int32_t fd)
Get the transmit buffer missing count.
static ssize_t dmaGetRxBuffinHwCount(int32_t fd)
Get the receive buffer count in hardware.
#define DMA_Get_Buff_Count
#define DMA_Write_Register
#define DMA_Get_RxBuff_Count
static ssize_t dmaGetApiVersion(int32_t fd)
Get API version of the DMA driver.
static ssize_t dmaWriteIndex(int32_t fd, uint32_t index, size_t size, uint32_t flags, uint32_t dest)
Writes data to a DMA channel using an index.
#define DMA_Get_TxBuffinUser_Count
static ssize_t dmaReadRegister(int32_t fd, uint64_t address, uint32_t *data)
Read a value from a DMA register.
#define DMA_Get_RxBuffinPreHWQ_Count
#define DMA_Get_TxBuffinHW_Count
static ssize_t dmaWriteRegister(int32_t fd, uint64_t address, uint32_t data)
Write to a DMA register.
#define DMA_Get_TxBuff_Count
static void dmaInitMaskBytes(uint8_t *mask)
Initialize DMA mask byte array.
#define DMA_Get_RxBuffinHW_Count
static void dmaAddMaskBytes(uint8_t *mask, uint32_t dest)
Add a destination to the DMA mask byte array.
#define DMA_Get_TxBuffMiss_Count
#define DMA_Set_MaskBytes
static ssize_t dmaReadBulkIndex(int32_t fd, uint32_t count, int32_t *ret, uint32_t *index, uint32_t *flags, uint32_t *error, uint32_t *dest)
Receive frame and access memory-mapped buffer.
static ssize_t dmaUnMapRegister(int32_t fd, void *ptr, uint32_t size)
Unmap a DMA register space from user space.
static ssize_t dmaSetMaskBytes(int32_t fd, uint8_t *mask)
Set mask byte array to the driver.
static ssize_t dmaGetRxBuffinUserCount(int32_t fd)
Get the receive buffer count in user.
static void * dmaMapRegister(int32_t fd, off_t offset, uint32_t size)
Map a DMA register space to user space.
static ssize_t dmaGetTxBuffinHwCount(int32_t fd)
Get the transmit buffer count in hardware.
static ssize_t dmaGetBuffSize(int32_t fd)
Get the buffer size.
static ssize_t dmaGetRxBuffinSwQCount(int32_t fd)
Get the receive buffer count in software queue.
static ssize_t dmaGetRxBuffCount(int32_t fd)
Get the receive buffer count.
static int32_t dmaGetIndex(int32_t fd)
Get the current write buffer index.
static ssize_t dmaReadIndex(int32_t fd, uint32_t *index, uint32_t *flags, uint32_t *error, uint32_t *dest)
Receive Frame, access memory mapped buffer.
static ssize_t dmaGetRxBuffinPreHwQCount(int32_t fd)
Get the receive buffer count in pre-hardware queue.
#define DMA_Get_RxBuffinUser_Count
static ssize_t dmaRetIndex(int32_t fd, uint32_t index)
Post an index back to the DMA.
static ssize_t dmaWriteVector(int32_t fd, struct iovec *iov, size_t iovlen, uint32_t begFlags, uint32_t midFlags, uint32_t endFlags, uint32_t dest)
Writes an array of data frames to a DMA channel.
#define DMA_Get_TxBuffinPreHWQ_Count
static ssize_t dmaSetDebug(int32_t fd, uint32_t level)
Set debugging level for DMA operations.
static void dmaAssignHandler(int32_t fd, void(*handler)(int32_t))
Assign a signal handler for asynchronous DMA operations.
static ssize_t dmaWriteIndexVector(int32_t fd, struct iovec *iov, size_t iovlen, uint32_t begFlags, uint32_t midFlags, uint32_t endFlags, uint32_t dest)
Write Frame, memory mapped from iovector.
#define DMA_Get_RxBuffinSWQ_Count
static ssize_t dmaGetTxBuffinSwQCount(int32_t fd)
Get the transmit buffer count in software queue.
static ssize_t dmaReadReady(int32_t fd)
Check if read is ready.
static ssize_t dmaGetBuffCount(int32_t fd)
Get the buffer count.
static ssize_t dmaCheckVersion(int32_t fd)
Check API version of the DMA driver.
static void ** dmaMapDma(int32_t fd, uint32_t *count, uint32_t *size)
Map user space to DMA buffers.
static ssize_t dmaUnMapDma(int32_t fd, void **buffer)
Unmap user space from DMA buffers.
#define DMA_Get_TxBuffinSWQ_Count
#define DMA_Get_RxBuffMiss_Count
static ssize_t dmaRead(int32_t fd, void *buf, size_t maxSize, uint32_t *flags, uint32_t *error, uint32_t *dest)
Receive Frame.
static ssize_t dmaGetTxBuffinUserCount(int32_t fd)
Get the transmit buffer count in user.
static ssize_t dmaWrite(int32_t fd, const void *buf, size_t size, uint32_t flags, uint32_t dest)
Writes data to a DMA channel.
static ssize_t dmaGetRxBuffMissCount(int32_t fd)
Get the receive buffer missing count.
#define DMA_Read_Register
static ssize_t dmaRetIndexes(int32_t fd, uint32_t count, uint32_t *indexes)
Post multiple indices back to the DMA.
Structure representing a DMA read operation.
Structure representing a DMA write operation.