Kernel-Module
Kernel module for FPGA-Linux communication via DMA and AXI registers.
This kernel module is responsible for facilitating data exchange between an FPGA (THANNA-IP-CORE) and the Linux operating system. It initializes a DMA region that allows efficient data transfer between the two entities and provides an API to interact with the AXI slave registers through IOCTL system calls. The module also registers a character device at /dev/thanna
, which supports various operations including read
, write
, seek
, and mmap
. These operations can be accessed using the provided libthanna
library or directly through user space applications.
Key features:
DMA Region Initialization: Sets up a shared memory space between the FPGA and the Linux kernel for efficient data transfers.
AXI Register Access via IOCTL: Allows reading, writing, and updating of AXI slave registers using IOCTL calls (
READ_REG
,WRITE_REG
,UPDATE_REG_BITS
).Character Device Interface: Registers a device at
/dev/thanna
that provides standard character device operations (read
,write
,seek
,mmap
) to interact with the FPGA.
Defines
-
dbg_info(dev, fmt, args...)
Prints debug information to the kernel log.
- Parameters:
dev – The device structure.
fmt – Format string.
args – Variable arguments for the format string.
-
dbg_err(dev, fmt, args...)
Prints an error message to the kernel log.
- Parameters:
dev – The device structure.
fmt – Format string.
args – Variable arguments for the format string.
-
dbg_warn(dev, fmt, args...)
Prints a warning message to the kernel log.
- Parameters:
dev – The device structure.
fmt – Format string.
args – Variable arguments for the format string.
-
DRIVER_NAME
Name of the driver for the Thanna device.
-
THANNA_IP_CORE_S00_AXI_SLV_REG0_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG1_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG2_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG3_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG4_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG5_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG6_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG7_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IP_CORE_S00_AXI_SLV_REG8_OFFSET
Offset definition for the Thanna IP core AXI slave register.
-
THANNA_IOCTL_READ_REG
IOCTL command to read from a register.
- Parameters:
'q' – The magic number.
1 – The command number.
u32 – The type of the data passed to the command.
-
THANNA_IOCTL_WRITE_REG
IOCTL command to write to a register.
- Parameters:
'q' – The magic number.
2 – The command number.
u32 – The type of the data passed to the command.
-
THANNA_IOCTL_UPDATE_REG_BITS
IOCTL command to update specific bits in a register.
- Parameters:
'q' – The magic number.
3 – The command number.
u32 – The type of the data passed to the command.
-
THANNA_IOCTL_FLUSH_CACHE
IOCTL command to flush the cache.
- Parameters:
'q' – The magic number.
4 – The command number.
Functions
-
static ssize_t thanna_read(struct file *file, char __user *user_buffer, size_t len, loff_t *offs)
Reads data from the device.
This function is called when a user reads from the device file.
- Parameters:
file – Pointer to the file structure.
user_buffer – Pointer to the user-space buffer.
len – Length of data to read.
offs – Offset in the device file.
- Returns:
Number of bytes read on success, or negative error code on failure.
-
static ssize_t thanna_write(struct file *file, const char __user *user_buffer, size_t len, loff_t *offs)
Writes data to the device.
This function is called when a user writes to the device file.
- Parameters:
file – Pointer to the file structure.
user_buffer – Pointer to the user-space buffer.
len – Length of data to write.
offs – Offset in the device file.
- Returns:
Number of bytes written on success, or negative error code on failure.
-
static loff_t thanna_llseek(struct file *file, loff_t offset, int whence)
Changes the current file position.
This function is called when a user changes the file offset.
- Parameters:
file – Pointer to the file structure.
offset – New file offset.
whence – Seek mode.
- Returns:
New file offset on success, or negative error code on failure.
-
static int thanna_mmap(struct file *file, struct vm_area_struct *vma)
Memory-maps the device memory to user space.
This function is called when a user performs an mmap operation on the device file.
- Parameters:
file – Pointer to the file structure.
vma – Pointer to the virtual memory area structure.
- Returns:
0 on success, or negative error code on failure.
-
static long thanna_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Handles IOCTL commands for the device.
This function is called when a user performs an ioctl operation on the device file.
- Parameters:
file – Pointer to the file structure.
cmd – IOCTL command.
arg – Command argument.
- Returns:
0 on success, or negative error code on failure.
-
struct thanna_local
- #include <thanna.h>
Local data structure to store Thanna device state.
This structure stores the state of the Thanna device, including memory regions, DMA addresses, and IRQ.
Public Members
-
int irq
IRQ number for the device
-
unsigned long mem_start
Start address of the device memory region
-
unsigned long mem_end
End address of the device memory region
-
dma_addr_t dma_start
Start address of the DMA region
-
dma_addr_t dma_end
End address of the DMA region
-
void *v_dma_start
Virtual start address of the DMA region
-
void __iomem *base_addr
Base address of the memory-mapped I/O
-
int irq