BEST PCIe driver
 All Data Structures Files Functions Variables Macros Pages
BEST_dma_device.c File Reference

Char driver for mSGDMA. More...

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/device.h>
#include <linux/string.h>
#include <asm/uaccess.h>
#include <linux/pci.h>
#include "BEST_PCIe.h"
#include "BEST_PCIe_internal.h"
#include "BEST_dma_device.h"
#include "msgdma/descriptor_regs.h"
#include "msgdma/csr_regs.h"

Macros

#define debug_print(fmt, args...)   do { if (DEBUG_DMA_PRINT) printk( KERN_DEBUG fmt, ##args); } while (0)
 
#define ceil(x, y)   ({ unsigned long __x = (x), __y = (y); (__x + __y - 1) / __y; })
 

Functions

 MODULE_LICENSE ("GPL")
 
void dma_read (struct dma_dev_struct *dev, uint64_t read_addr, uint64_t write_addr, uint32_t len)
 Reads from DMA. More...
 
void dma_enable_int (struct dma_dev_struct *dev)
 Enables DMA interrupt. More...
 
void dma_disable_int (struct dma_dev_struct *dev)
 Disables DMA interrupt. More...
 
void dma_reset (struct dma_dev_struct *dev)
 Resets DMA. More...
 
int dma_char_open (struct inode *inode, struct file *file)
 Opens char device (stores dev struct in pirvate data) More...
 
ssize_t dma_char_read (struct file *file, char __user *buf, size_t count, loff_t *pos)
 Reads from char device. More...
 
void dma_advance_buf (struct dma_dev_struct *dev)
 Advacnes to next buffer, returns pointer to it. More...
 
int dma_dev_create (struct dma_dev_struct *dev, struct class *best_class)
 Creates new DMA char device. More...
 
void dma_dev_remove (struct dma_dev_struct *dev, struct class *best_class)
 Removes DMA char device. More...
 
int dma_dev_allocate_buffers (struct pci_dev *dev, struct dma_dev_struct *dma)
 Allocates DMA buffers. More...
 
void dma_dev_free_buffers (struct pci_dev *dev, struct dma_dev_struct *dma)
 Frees DMA buffers. More...
 

Variables

static const struct file_operations dma_char_fops
 

Detailed Description

Char driver for mSGDMA.

Author
Jan Marjanovic (j.mar.nosp@m.jano.nosp@m.vic@c.nosp@m.aene.nosp@m.ls.co.nosp@m.m)
Date
June 2014

Function Documentation

void dma_advance_buf ( struct dma_dev_struct dev)

Advacnes to next buffer, returns pointer to it.

Parameters
devDMA structure
buf_to_writeReturns address of a buffer to write to
int dma_char_open ( struct inode *  inode,
struct file *  file 
)

Opens char device (stores dev struct in pirvate data)

Parameters
inodeIndex node structure
fileFile structure
Returns
0 on success, negative number on fail
ssize_t dma_char_read ( struct file *  file,
char __user *  buf,
size_t  count,
loff_t *  pos 
)

Reads from char device.

Parameters
fileFile structure (path, ...)
bufBuffer to read to
countNumber of bytes to read
pos
Returns
Numbers of bytes successfully read
int dma_dev_allocate_buffers ( struct pci_dev *  dev,
struct dma_dev_struct dma 
)

Allocates DMA buffers.

Parameters
devPCI device
dmaDMA strucutre to allocate memory

Fields buf_number and buf_len must have valid values

int dma_dev_create ( struct dma_dev_struct dev,
struct class *  best_class 
)

Creates new DMA char device.

Parameters
devStructure with DMA info
best_classClass which this device will be part of

Creates new char device, which represents FPGA mSGDMA Allowed operation on device is read(), which returns most recent data from buffers

void dma_dev_free_buffers ( struct pci_dev *  dev,
struct dma_dev_struct dma 
)

Frees DMA buffers.

Parameters
devPCI device
dmaDMA strucutre to allocate memory
void dma_dev_remove ( struct dma_dev_struct dev,
struct class *  best_class 
)

Removes DMA char device.

Parameters
devStructure with DMA info
best_classClass which this device will be part of
void dma_disable_int ( struct dma_dev_struct dev)

Disables DMA interrupt.

Parameters
boardPointer to structure with board specific data
void dma_enable_int ( struct dma_dev_struct dev)

Enables DMA interrupt.

Parameters
boardPointer to structure with board specific data
void dma_read ( struct dma_dev_struct dev,
uint64_t  read_addr,
uint64_t  write_addr,
uint32_t  len 
)

Reads from DMA.

Parameters
boardPointer to structure with board specific data
read_addrAddress to read from (Avalon MM for this application)
write_addrAddress to write to (should be in DMA space, physical)
lenNumber of bytes to transfer
void dma_reset ( struct dma_dev_struct dev)

Resets DMA.

Parameters
boardPointer to structure with board specific data

Variable Documentation

const struct file_operations dma_char_fops
static
Initial value:
= {
.owner = THIS_MODULE,
.open = dma_char_open,
.read = dma_char_read,
}
ssize_t dma_char_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
Reads from char device.
Definition: BEST_dma_device.c:157
int dma_char_open(struct inode *inode, struct file *file)
Opens char device (stores dev struct in pirvate data)
Definition: BEST_dma_device.c:130