SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Macros | Functions | Variables
sys-dma.c File Reference

System DMA (Direct Memory Access) driver for Allwinner (sunxi) platforms. More...

#include <io.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>
#include <log.h>
#include <sys-dma.h>
Include dependency graph for sys-dma.c:

Macros

#define SUNXI_DMA_MAX   4
 Maximum number of DMA channels supported.
 

Functions

static sunxi_dma_desc_t dma_channel_desc[SUNXI_DMA_MAX__attribute__ ((aligned(64)))
 Array of DMA descriptor structures.
 
void sunxi_dma_clk_init (sunxi_dma_t *dma)
 Initialize DMA clock.
 
void sunxi_dma_init (sunxi_dma_t *dma)
 Initialize the DMA controller.
 
void sunxi_dma_exit (sunxi_dma_t *dma)
 Exit and clean up DMA resources.
 
uint32_t sunxi_dma_request_from_last (uint32_t dmatype)
 Request a DMA channel starting from the last available.
 
uint32_t sunxi_dma_request (uint32_t dmatype)
 Request a DMA channel.
 
int sunxi_dma_release (uint32_t dma_fd)
 Release a DMA channel.
 
int sunxi_dma_setting (uint32_t dma_fd, sunxi_dma_set_t *cfg)
 Configure DMA channel settings.
 
int sunxi_dma_start (uint32_t dma_fd, uint32_t saddr, uint32_t daddr, uint32_t bytes)
 Start a DMA transfer.
 
int sunxi_dma_stop (uint32_t dma_fd)
 Stop a DMA transfer.
 
int sunxi_dma_querystatus (uint32_t dma_fd)
 Query DMA transfer status.
 
int sunxi_dma_install_int (uint32_t dma_fd, void *p)
 Install interrupt handler for DMA channel.
 
int sunxi_dma_enable_int (uint32_t dma_fd)
 Enable interrupts for a DMA channel.
 
int sunxi_dma_disable_int (uint32_t dma_fd)
 Disable interrupts for a DMA channel.
 
int sunxi_dma_free_int (uint32_t dma_fd)
 Free interrupt handler for a DMA channel.
 
int sunxi_dma_test (uint32_t *src_addr, uint32_t *dst_addr, uint32_t len)
 Test DMA functionality.
 

Variables

static int dma_int_cnt = 0
 Interrupt count tracking variable.
 
static int dma_init_ok = -1
 DMA initialization status.
 
static sunxi_dma_source_t dma_channel_source [SUNXI_DMA_MAX]
 Array of DMA channel source structures.
 
static uint32_t DMA_REG_BASE = 0x0
 Base address of DMA registers.
 

Detailed Description

System DMA (Direct Memory Access) driver for Allwinner (sunxi) platforms.

This file implements DMA functionality for transferring data between memory and peripherals without CPU intervention, supporting multiple channels, interrupt handling, and various DMA operations.

Macro Definition Documentation

◆ SUNXI_DMA_MAX

#define SUNXI_DMA_MAX   4

Maximum number of DMA channels supported.

Define the maximum number of DMA channels available in the system. Defaults to 4 if not already defined.

Function Documentation

◆ __attribute__()

static sunxi_dma_desc_t dma_channel_desc[SUNXI_DMA_MAX] __attribute__ ( (aligned(64))  )
static

Array of DMA descriptor structures.

Stores DMA transfer descriptors for each channel, aligned to 64 bytes

◆ sunxi_dma_clk_init()

void sunxi_dma_clk_init ( sunxi_dma_t dma)

Initialize DMA clock.

Configures the clock settings for the DMA controller, including bus clock gating, DMA reset, and DMA clock gating.

Parameters
dmaPointer to DMA configuration structure containing clock register information

◆ sunxi_dma_disable_int()

int sunxi_dma_disable_int ( uint32_t  dma_fd)

Disable interrupts for a DMA channel.

Disables interrupts for the specified DMA.

Disables interrupts for a specific DMA channel.

Parameters
dma_fdHandle to the DMA channel
Returns
0 on success, -1 if channel is not in use

◆ sunxi_dma_enable_int()

int sunxi_dma_enable_int ( uint32_t  dma_fd)

Enable interrupts for a DMA channel.

Enables interrupts for the specified DMA.

Enables interrupts for a specific DMA channel, specifically package end interrupts.

Parameters
dma_fdHandle to the DMA channel
Returns
0 on success, -1 if channel is not in use

◆ sunxi_dma_exit()

void sunxi_dma_exit ( sunxi_dma_t dma)

Exit and clean up DMA resources.

Clean up and exit the DMA subsystem.

Releases all DMA channels, disables interrupts, and shuts down the DMA controller.

Parameters
dmaPointer to DMA configuration structure

◆ sunxi_dma_free_int()

int sunxi_dma_free_int ( uint32_t  dma_fd)

Free interrupt handler for a DMA channel.

Frees the interrupt resources for the specified DMA.

Releases the interrupt handler associated with a DMA channel and clears pending interrupts.

Parameters
dma_fdHandle to the DMA channel
Returns
0 on success, -1 if channel is not in use or interrupt handler was not set

◆ sunxi_dma_init()

void sunxi_dma_init ( sunxi_dma_t dma)

Initialize the DMA controller.

Initialize the DMA subsystem.

Initializes the DMA controller by setting up registers, clearing interrupts, configuring auto clock gating, and initializing channel structures.

Parameters
dmaPointer to DMA configuration structure containing base addresses and settings

◆ sunxi_dma_install_int()

int sunxi_dma_install_int ( uint32_t  dma_fd,
void *  p 
)

Install interrupt handler for DMA channel.

Installs an interrupt handler for the DMA.

Sets up an interrupt handler for a DMA channel and clears any pending interrupts.

Parameters
dma_fdHandle to the DMA channel
pUser data to associate with the interrupt handler
Returns
0 on success, -1 if channel is not in use

◆ sunxi_dma_querystatus()

int sunxi_dma_querystatus ( uint32_t  dma_fd)

Query DMA transfer status.

Query the status of a DMA transfer.

Checks whether a DMA transfer is still in progress on the specified channel.

Parameters
dma_fdHandle to the DMA channel to query
Returns
1 if transfer is in progress, 0 if completed, -1 if channel is not in use

◆ sunxi_dma_release()

int sunxi_dma_release ( uint32_t  dma_fd)

Release a DMA channel.

Release a previously requested DMA channel.

Releases a previously requested DMA channel, disabling its interrupts.

Parameters
dma_fdHandle to the DMA channel to release
Returns
0 on success, -1 if the channel was not in use

◆ sunxi_dma_request()

uint32_t sunxi_dma_request ( uint32_t  dmatype)

Request a DMA channel.

Request a DMA channel of the specified type.

Searches for an available DMA channel starting from channel 0.

Parameters
dmatypeType of DMA channel to request (currently unused)
Returns
Handle to the requested DMA channel, or 0 if no channels are available

◆ sunxi_dma_request_from_last()

uint32_t sunxi_dma_request_from_last ( uint32_t  dmatype)

Request a DMA channel starting from the last available.

Request a DMA channel from the last allocated channel of the specified type.

Searches for an available DMA channel starting from the highest-numbered channel.

Parameters
dmatypeType of DMA channel to request (currently unused)
Returns
Handle to the requested DMA channel, or 0 if no channels are available

◆ sunxi_dma_setting()

int sunxi_dma_setting ( uint32_t  dma_fd,
sunxi_dma_set_t cfg 
)

Configure DMA channel settings.

Configure the settings of a DMA channel.

Sets up a DMA channel with specified configuration parameters like loop mode, wait cycles, and data block size.

Parameters
dma_fdHandle to the DMA channel to configure
cfgPointer to configuration structure containing DMA settings
Returns
0 on success, -1 if the channel is not in use

◆ sunxi_dma_start()

int sunxi_dma_start ( uint32_t  dma_fd,
uint32_t  saddr,
uint32_t  daddr,
uint32_t  bytes 
)

Start a DMA transfer.

Initiates a DMA data transfer from source to destination address with specified size.

Parameters
dma_fdHandle to the DMA channel to use
saddrSource address for the DMA transfer
daddrDestination address for the DMA transfer
bytesNumber of bytes to transfer
Returns
0 on success, -1 if the channel is not in use

◆ sunxi_dma_stop()

int sunxi_dma_stop ( uint32_t  dma_fd)

Stop a DMA transfer.

Stop a currently running DMA transfer.

Halts an ongoing DMA transfer on the specified channel.

Parameters
dma_fdHandle to the DMA channel to stop
Returns
0 on success, -1 if the channel is not in use

◆ sunxi_dma_test()

int sunxi_dma_test ( uint32_t src_addr,
uint32_t dst_addr,
uint32_t  len 
)

Test DMA functionality.

Perform a test DMA transfer between the specified source and destination addresses.

Performs a DMA transfer test between two memory regions, verifies data integrity, and reports transfer performance.

Parameters
src_addrSource memory address for test transfer
dst_addrDestination memory address for test transfer
lenLength of data to transfer in bytes
Returns
0 on success, -1 if channel request failed, -2 if transfer timed out

Variable Documentation

◆ dma_channel_source

sunxi_dma_source_t dma_channel_source[SUNXI_DMA_MAX]
static

Array of DMA channel source structures.

Stores information about each DMA channel's state and configuration

◆ dma_init_ok

int dma_init_ok = -1
static

DMA initialization status.

Tracks whether DMA has been initialized (-1 = not initialized, >=0 = initialized)

◆ dma_int_cnt

int dma_int_cnt = 0
static

Interrupt count tracking variable.

Tracks the number of active DMA interrupts

◆ DMA_REG_BASE

uint32_t DMA_REG_BASE = 0x0
static

Base address of DMA registers.

Stores the base address of the DMA controller registers