mirror of
https://github.com/saymrwulf/pulp-runtime.git
synced 2026-06-03 23:49:50 +00:00
fixup: tests: add MR review feedback
This commit is contained in:
parent
3970cf67bf
commit
755cdc9d1a
1 changed files with 70 additions and 75 deletions
|
|
@ -55,7 +55,7 @@ typedef unsigned int dma_loc_t;
|
|||
\param ext2loc If 1, the transfer is loading data from external memory and storing to cluster memory. If 0, it is the contrary
|
||||
\return The identifier of the transfer. This can be used with plp_dma_wait to wait for the completion of this transfer.
|
||||
*/
|
||||
static inline int plp_dma_memcpy(unsigned int const id, dma_ext_t ext, unsigned int loc, unsigned int size, int ext2loc);
|
||||
static inline int plp_dma_memcpy(unsigned int base, dma_ext_t ext, unsigned int loc, unsigned int size, int ext2loc);
|
||||
|
||||
/** Cluster memory to external memory transfer with event-based completion.
|
||||
*
|
||||
|
|
@ -85,7 +85,7 @@ static inline int plp_dma_extToL1(unsigned int loc, dma_ext_t ext, unsigned shor
|
|||
\param ext2loc If 1, the transfer is loading data from external memory and storing to cluster memory. If 0, it is the contrary
|
||||
\return The identifier of the transfer. This can be used with plp_dma_wait to wait for the completion of this transfer.
|
||||
*/
|
||||
static inline int plp_dma_memcpy_2d(unsigned int const id, dma_ext_t ext, unsigned int loc, unsigned int size, unsigned int stride, unsigned int length, int ext2loc);
|
||||
static inline int plp_dma_memcpy_2d(unsigned int base, dma_ext_t ext, unsigned int loc, unsigned int size, unsigned int stride, unsigned int length, int ext2loc);
|
||||
|
||||
/** Cluster memory to external memory 2-dimensional transfer with event-based completion.
|
||||
*
|
||||
|
|
@ -117,14 +117,14 @@ static inline int plp_dma_extToL1_2d(unsigned int loc, dma_ext_t ext, unsigned s
|
|||
/** DMA barrier.
|
||||
* This blocks the core until no transfer is on-going in the DMA.
|
||||
*/
|
||||
static inline void plp_dma_barrier();
|
||||
static inline void plp_dma_barrier(unsigned int base);
|
||||
|
||||
/** DMA wait.
|
||||
* This blocks the core until the specified transfer is finished.
|
||||
*
|
||||
\param counter The counter ID identifying the transfer. This has been returned from an enqueued transfer (e.g. plp_dma_extToL1_2d)
|
||||
*/
|
||||
static inline void plp_dma_wait(unsigned int const id, unsigned int dma_tx_id);
|
||||
static inline void plp_dma_wait(unsigned int base, unsigned int dma_tx_id);
|
||||
|
||||
//!@}
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ static inline unsigned int pulp_idma_get_conf(unsigned int decouple, unsigned in
|
|||
\param dma_tx_id The dma transfer identifier
|
||||
\return transfer status. 1 if complete, 0 if still ongoing or waiting.
|
||||
*/
|
||||
static inline unsigned int pulp_idma_tx_cplt(unsigned int const id, unsigned int dma_tx_id);
|
||||
static inline unsigned int pulp_idma_tx_cplt(unsigned int base, unsigned int dma_tx_id);
|
||||
|
||||
/**
|
||||
* iDMA memory transfer
|
||||
|
|
@ -166,7 +166,7 @@ static inline unsigned int pulp_idma_tx_cplt(unsigned int const id, unsigned int
|
|||
\param num_bytes The number bytes
|
||||
\return The dma transfer identifier
|
||||
*/
|
||||
static inline unsigned int pulp_idma_memcpy(unsigned int const id, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes);
|
||||
static inline unsigned int pulp_idma_memcpy(unsigned int base, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes);
|
||||
|
||||
/**
|
||||
* iDMA 2D memory transfer
|
||||
|
|
@ -180,7 +180,7 @@ static inline unsigned int pulp_idma_memcpy(unsigned int const id, unsigned int
|
|||
\param num_reps The number of repetitions
|
||||
\return The dma transfer identifier
|
||||
*/
|
||||
static inline unsigned int pulp_idma_memcpy_2d(unsigned int const id, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps);
|
||||
static inline unsigned int pulp_idma_memcpy_2d(unsigned int base, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps);
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -203,13 +203,13 @@ static inline unsigned int pulp_idma_memcpy_2d(unsigned int const id, unsigned i
|
|||
\param num_reps if 2D, the number of repetitions
|
||||
\return The dma trasfer identifier
|
||||
*/
|
||||
static inline unsigned int pulp_idma_memcpy_advanced(unsigned int const id, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int decouple, unsigned int deburst, unsigned int serialize, unsigned int twod, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps);
|
||||
static inline unsigned int pulp_idma_memcpy_advanced(unsigned int base, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int decouple, unsigned int deburst, unsigned int serialize, unsigned int twod, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps);
|
||||
|
||||
/** Return the DMA status.
|
||||
*
|
||||
\return DMA status. 1 means there are still on-going transfers, 0 means nothing is on-going.
|
||||
*/
|
||||
static inline unsigned int plp_dma_status();
|
||||
static inline unsigned int plp_dma_status(unsigned int base);
|
||||
|
||||
|
||||
//!@}
|
||||
|
|
@ -225,37 +225,28 @@ static inline unsigned int plp_dma_status();
|
|||
|
||||
#define DMA_ADDR_FC ARCHI_SDMA_ADDR
|
||||
|
||||
unsigned int inline get_dma_base_addr(unsigned int const id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
typedef enum{
|
||||
DMA_FC = 0,
|
||||
DMA_CL = 1
|
||||
} dma_e;
|
||||
|
||||
unsigned int inline get_dma_base_addr(dma_e dma_loc) {
|
||||
switch (dma_loc) {
|
||||
case DMA_FC:
|
||||
return DMA_ADDR_FC;
|
||||
case 1:
|
||||
case DMA_CL:
|
||||
return DMA_ADDR_CL;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t inline DMA_WRITE(unsigned int const id, unsigned int value, unsigned offset) {
|
||||
unsigned int base = get_dma_base_addr(id);
|
||||
uint32_t inline pulp_idma_write(unsigned int base, unsigned int value, unsigned offset) {
|
||||
pulp_write32((base) + (offset), (value));
|
||||
}
|
||||
|
||||
uint32_t inline DMA_READ(unsigned int const id, unsigned int offset) {
|
||||
uint32_t base = get_dma_base_addr(id);
|
||||
uint32_t inline pulp_idma_read(unsigned int base, unsigned int offset) {
|
||||
pulp_read32((base) + (offset));
|
||||
}
|
||||
|
||||
/*
|
||||
#define DMA_WRITE(id, value, offset) { \
|
||||
uint32_t base = get_dma_base_addr(id); \
|
||||
pulp_write32((base) + (offset), (value)); \
|
||||
}
|
||||
|
||||
#define DMA_READ(id, offset) { \
|
||||
uint32_t base = get_dma_base_addr(id); \
|
||||
pulp_read32((base) + (offset)); \
|
||||
}
|
||||
*/
|
||||
|
||||
static inline unsigned int pulp_idma_get_conf(unsigned int decouple, unsigned int deburst, unsigned int serialize, unsigned int twod) {
|
||||
unsigned int conf;
|
||||
#if defined(__riscv__)
|
||||
|
|
@ -269,8 +260,8 @@ static inline unsigned int pulp_idma_get_conf(unsigned int decouple, unsigned in
|
|||
return conf;
|
||||
}
|
||||
|
||||
static inline unsigned int pulp_idma_tx_cplt(unsigned int id, unsigned int dma_tx_id) {
|
||||
unsigned int done_id = DMA_READ(id, IDMA_REG32_2D_FRONTEND_DONE_REG_OFFSET);
|
||||
static inline unsigned int pulp_idma_tx_cplt(unsigned int base, unsigned int dma_tx_id) {
|
||||
unsigned int done_id = pulp_idma_read(base, IDMA_REG32_2D_FRONTEND_DONE_REG_OFFSET);
|
||||
unsigned int my_id = dma_tx_id & IDMA_ID_MASK;
|
||||
if (done_id >> (IDMA_ID_COUNTER_WIDTH-1) == my_id >> (IDMA_ID_COUNTER_WIDTH-1)) {
|
||||
return my_id <= done_id;
|
||||
|
|
@ -280,104 +271,108 @@ static inline unsigned int pulp_idma_tx_cplt(unsigned int id, unsigned int dma_t
|
|||
}
|
||||
|
||||
|
||||
static inline unsigned int pulp_idma_memcpy(unsigned int id, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes) {
|
||||
DMA_WRITE(id, src_addr, IDMA_REG32_2D_FRONTEND_SRC_ADDR_REG_OFFSET);
|
||||
DMA_WRITE(id, dst_addr, IDMA_REG32_2D_FRONTEND_DST_ADDR_REG_OFFSET);
|
||||
DMA_WRITE(id, num_bytes, IDMA_REG32_2D_FRONTEND_NUM_BYTES_REG_OFFSET);
|
||||
DMA_WRITE(id, IDMA_DEFAULT_CONFIG, IDMA_REG32_2D_FRONTEND_CONF_REG_OFFSET);
|
||||
static inline unsigned int pulp_idma_memcpy(unsigned int base, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes) {
|
||||
pulp_idma_write(base, src_addr, IDMA_REG32_2D_FRONTEND_SRC_ADDR_REG_OFFSET);
|
||||
pulp_idma_write(base, dst_addr, IDMA_REG32_2D_FRONTEND_DST_ADDR_REG_OFFSET);
|
||||
pulp_idma_write(base, num_bytes, IDMA_REG32_2D_FRONTEND_NUM_BYTES_REG_OFFSET);
|
||||
pulp_idma_write(base, IDMA_DEFAULT_CONFIG, IDMA_REG32_2D_FRONTEND_CONF_REG_OFFSET);
|
||||
asm volatile("" : : : "memory");
|
||||
|
||||
// Launch TX
|
||||
unsigned int dma_tx_id = DMA_READ(id, IDMA_REG32_2D_FRONTEND_NEXT_ID_REG_OFFSET);
|
||||
unsigned int dma_tx_id = pulp_idma_read(base, IDMA_REG32_2D_FRONTEND_NEXT_ID_REG_OFFSET);
|
||||
|
||||
return dma_tx_id;
|
||||
}
|
||||
|
||||
static inline unsigned int pulp_idma_memcpy_2d(unsigned int id, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps) {
|
||||
DMA_WRITE(id, src_addr, IDMA_REG32_2D_FRONTEND_SRC_ADDR_REG_OFFSET);
|
||||
DMA_WRITE(id, dst_addr, IDMA_REG32_2D_FRONTEND_DST_ADDR_REG_OFFSET);
|
||||
DMA_WRITE(id, num_bytes, IDMA_REG32_2D_FRONTEND_NUM_BYTES_REG_OFFSET);
|
||||
DMA_WRITE(id, IDMA_DEFAULT_CONFIG_2D, IDMA_REG32_2D_FRONTEND_CONF_REG_OFFSET);
|
||||
DMA_WRITE(id, src_stride, IDMA_REG32_2D_FRONTEND_STRIDE_SRC_REG_OFFSET);
|
||||
DMA_WRITE(id, dst_stride, IDMA_REG32_2D_FRONTEND_STRIDE_DST_REG_OFFSET);
|
||||
DMA_WRITE(id, num_reps, IDMA_REG32_2D_FRONTEND_NUM_REPETITIONS_REG_OFFSET);
|
||||
static inline unsigned int pulp_idma_memcpy_2d(unsigned int base, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps) {
|
||||
pulp_idma_write(base, src_addr, IDMA_REG32_2D_FRONTEND_SRC_ADDR_REG_OFFSET);
|
||||
pulp_idma_write(base, dst_addr, IDMA_REG32_2D_FRONTEND_DST_ADDR_REG_OFFSET);
|
||||
pulp_idma_write(base, num_bytes, IDMA_REG32_2D_FRONTEND_NUM_BYTES_REG_OFFSET);
|
||||
pulp_idma_write(base, IDMA_DEFAULT_CONFIG_2D, IDMA_REG32_2D_FRONTEND_CONF_REG_OFFSET);
|
||||
pulp_idma_write(base, src_stride, IDMA_REG32_2D_FRONTEND_STRIDE_SRC_REG_OFFSET);
|
||||
pulp_idma_write(base, dst_stride, IDMA_REG32_2D_FRONTEND_STRIDE_DST_REG_OFFSET);
|
||||
pulp_idma_write(base, num_reps, IDMA_REG32_2D_FRONTEND_NUM_REPETITIONS_REG_OFFSET);
|
||||
asm volatile("" : : : "memory");
|
||||
|
||||
// Launch TX
|
||||
unsigned int dma_tx_id = DMA_READ(id, IDMA_REG32_2D_FRONTEND_NEXT_ID_REG_OFFSET);
|
||||
unsigned int dma_tx_id = pulp_idma_read(base, IDMA_REG32_2D_FRONTEND_NEXT_ID_REG_OFFSET);
|
||||
|
||||
return dma_tx_id;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned int pulp_idma_memcpy_advanced(unsigned int const id, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int decouple, unsigned int deburst, unsigned int serialize, unsigned int twod, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps) {
|
||||
DMA_WRITE(id, src_addr, IDMA_REG32_2D_FRONTEND_SRC_ADDR_REG_OFFSET);
|
||||
DMA_WRITE(id, dst_addr, IDMA_REG32_2D_FRONTEND_DST_ADDR_REG_OFFSET);
|
||||
DMA_WRITE(id, num_bytes, IDMA_REG32_2D_FRONTEND_NUM_BYTES_REG_OFFSET);
|
||||
static inline unsigned int pulp_idma_memcpy_advanced(unsigned int base, unsigned int const dst_addr, unsigned int const src_addr, unsigned int num_bytes, unsigned int decouple, unsigned int deburst, unsigned int serialize, unsigned int twod, unsigned int dst_stride, unsigned int src_stride, unsigned int num_reps) {
|
||||
pulp_idma_write(base, src_addr, IDMA_REG32_2D_FRONTEND_SRC_ADDR_REG_OFFSET);
|
||||
pulp_idma_write(base, dst_addr, IDMA_REG32_2D_FRONTEND_DST_ADDR_REG_OFFSET);
|
||||
pulp_idma_write(base, num_bytes, IDMA_REG32_2D_FRONTEND_NUM_BYTES_REG_OFFSET);
|
||||
unsigned int conf = pulp_idma_get_conf(decouple, deburst, serialize, twod);
|
||||
DMA_WRITE(id, conf, IDMA_REG32_2D_FRONTEND_CONF_REG_OFFSET);
|
||||
pulp_idma_write(base, conf, IDMA_REG32_2D_FRONTEND_CONF_REG_OFFSET);
|
||||
if (twod) {
|
||||
DMA_WRITE(id, src_stride, IDMA_REG32_2D_FRONTEND_STRIDE_SRC_REG_OFFSET);
|
||||
DMA_WRITE(id, dst_stride, IDMA_REG32_2D_FRONTEND_STRIDE_DST_REG_OFFSET);
|
||||
DMA_WRITE(id, num_reps, IDMA_REG32_2D_FRONTEND_NUM_REPETITIONS_REG_OFFSET);
|
||||
pulp_idma_write(base, src_stride, IDMA_REG32_2D_FRONTEND_STRIDE_SRC_REG_OFFSET);
|
||||
pulp_idma_write(base, dst_stride, IDMA_REG32_2D_FRONTEND_STRIDE_DST_REG_OFFSET);
|
||||
pulp_idma_write(base, num_reps, IDMA_REG32_2D_FRONTEND_NUM_REPETITIONS_REG_OFFSET);
|
||||
}
|
||||
asm volatile("" : : : "memory");
|
||||
|
||||
// Launch TX
|
||||
unsigned int dma_tx_id = DMA_READ(id, IDMA_REG32_2D_FRONTEND_NEXT_ID_REG_OFFSET);
|
||||
unsigned int dma_tx_id = pulp_idma_read(base, IDMA_REG32_2D_FRONTEND_NEXT_ID_REG_OFFSET);
|
||||
|
||||
return dma_tx_id;
|
||||
}
|
||||
|
||||
static inline unsigned int plp_dma_status(unsigned int const id) {
|
||||
return DMA_READ(id, IDMA_REG32_2D_FRONTEND_STATUS_REG_OFFSET);
|
||||
static inline unsigned int plp_dma_status(unsigned int base) {
|
||||
return pulp_idma_read(base, IDMA_REG32_2D_FRONTEND_STATUS_REG_OFFSET);
|
||||
}
|
||||
|
||||
static inline void plp_dma_wait(unsigned int const id, unsigned int dma_tx_id) {
|
||||
while(!pulp_idma_tx_cplt(id, dma_tx_id)) {
|
||||
static inline void plp_dma_wait(unsigned int base, unsigned int dma_tx_id) {
|
||||
while(!pulp_idma_tx_cplt(base, dma_tx_id)) {
|
||||
eu_evt_maskWaitAndClr(1 << IDMA_EVENT);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static inline int plp_dma_memcpy(unsigned int const id, dma_ext_t ext, unsigned int loc, unsigned int size, int ext2loc) {
|
||||
static inline int plp_dma_memcpy(unsigned int base, dma_ext_t ext, unsigned int loc, unsigned int size, int ext2loc) {
|
||||
if (ext2loc) {
|
||||
return pulp_idma_memcpy(id, loc, ext, size);
|
||||
return pulp_idma_memcpy(base, loc, ext, size);
|
||||
} else {
|
||||
return pulp_idma_memcpy(id, ext, loc, size);
|
||||
return pulp_idma_memcpy(base, ext, loc, size);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int plp_dma_l1ToExt(dma_ext_t ext, unsigned int loc, unsigned short size) {
|
||||
uint32_t id = 1; // cluster idma
|
||||
return pulp_idma_memcpy(id, ext, loc, size);
|
||||
dma_e dma_loc = DMA_CL;
|
||||
unsigned int base = get_dma_base_addr(dma_loc);
|
||||
return pulp_idma_memcpy(base, ext, loc, size);
|
||||
}
|
||||
|
||||
static inline int plp_dma_extToL1(unsigned int loc, dma_ext_t ext, unsigned short size) {
|
||||
uint32_t id = 1; // cluster idma
|
||||
return pulp_idma_memcpy(id, loc, ext, size);
|
||||
dma_e dma_loc = DMA_CL;
|
||||
unsigned int base = get_dma_base_addr(dma_loc);
|
||||
return pulp_idma_memcpy(base, loc, ext, size);
|
||||
}
|
||||
|
||||
static inline int plp_dma_memcpy_2d(unsigned int const id, dma_ext_t ext, unsigned int loc, unsigned int size, unsigned int stride, unsigned int length, int ext2loc) {
|
||||
static inline int plp_dma_memcpy_2d(unsigned int base, dma_ext_t ext, unsigned int loc, unsigned int size, unsigned int stride, unsigned int length, int ext2loc) {
|
||||
if (ext2loc) {
|
||||
return pulp_idma_memcpy_2d(id, loc, ext, length, length, stride, size/length);
|
||||
return pulp_idma_memcpy_2d(base, loc, ext, length, length, stride, size/length);
|
||||
} else {
|
||||
return pulp_idma_memcpy_2d(id, ext, loc, length, stride, length, size/length);
|
||||
return pulp_idma_memcpy_2d(base, ext, loc, length, stride, length, size/length);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int plp_dma_l1ToExt_2d(dma_ext_t ext, unsigned int loc, unsigned short size, unsigned short stride, unsigned short length) {
|
||||
uint32_t id = 1; // cluster idma
|
||||
return pulp_idma_memcpy_2d(id, ext, loc, length, stride, length, size/length);
|
||||
dma_e dma_loc = DMA_CL;
|
||||
unsigned int base = get_dma_base_addr(dma_loc);
|
||||
return pulp_idma_memcpy_2d(base, ext, loc, length, stride, length, size/length);
|
||||
}
|
||||
|
||||
static inline int plp_dma_extToL1_2d(unsigned int loc, dma_ext_t ext, unsigned short size, unsigned short stride, unsigned short length) {
|
||||
uint32_t id = 1; // cluster idma
|
||||
return pulp_idma_memcpy_2d(id, loc, ext, length, length, stride, size/length);
|
||||
dma_e dma_loc = DMA_CL;
|
||||
unsigned int base = get_dma_base_addr(dma_loc);
|
||||
return pulp_idma_memcpy_2d(base, loc, ext, length, length, stride, size/length);
|
||||
}
|
||||
|
||||
static inline void plp_dma_barrier(uint32_t id) {
|
||||
while(plp_dma_status(id)) {
|
||||
static inline void plp_dma_barrier(unsigned int base) {
|
||||
while(plp_dma_status(base)) {
|
||||
eu_evt_maskWaitAndClr(1 << IDMA_EVENT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue