Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dma when using copy.merge #115

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rtos/pmsis/pmsis_api/include/pmsis/cluster/dma/cl_dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ static inline void pi_cl_dma_wait(void *copy);
/// @cond IMPLEM

#define CL_DMA_COMMON \
uint32_t id; \
uint32_t ext; \
uint32_t loc; \
uint32_t id; \
uint16_t size; \
pi_cl_dma_dir_e dir; \
uint8_t merge;
Expand Down
63 changes: 50 additions & 13 deletions rtos/pulpos/common/include/pos/implem/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

struct pi_cl_dma_cmd_s
{
int id;
uint32_t id;
struct pi_cl_dma_cmd_s *next;
};

Expand All @@ -44,6 +44,7 @@ static inline void __cl_dma_wait_safe(pi_cl_dma_cmd_t *copy)
}

plp_dma_counter_free(counter);
copy->id = -1;
}


Expand All @@ -60,6 +61,7 @@ static inline void __cl_dma_wait(pi_cl_dma_cmd_t *copy)
}

plp_dma_counter_free(counter);
copy->id = -1;

eu_mutex_unlock_from_id(0);
}
Expand All @@ -69,7 +71,7 @@ static inline void __cl_dma_memcpy(unsigned int ext, unsigned int loc, unsigned
{
eu_mutex_lock_from_id(0);

int id = -1;
int id = copy->id;
if (!merge) id = plp_dma_counter_alloc();
unsigned int cmd = plp_dma_getCmd(dir, size, PLP_DMA_1D, PLP_DMA_TRIG_EVT, PLP_DMA_NO_TRIG_IRQ, PLP_DMA_SHARED);
// Prevent the compiler from pushing the transfer before all previous
Expand All @@ -84,7 +86,7 @@ static inline void __cl_dma_memcpy(unsigned int ext, unsigned int loc, unsigned

static inline void __cl_dma_memcpy_safe(unsigned int ext, unsigned int loc, unsigned short size, pi_cl_dma_dir_e dir, int merge, pi_cl_dma_cmd_t *copy)
{
int id = -1;
int id = copy->id;
if (!merge) id = plp_dma_counter_alloc();
unsigned int cmd = plp_dma_getCmd(dir, size, PLP_DMA_1D, PLP_DMA_TRIG_EVT, PLP_DMA_NO_TRIG_IRQ, PLP_DMA_SHARED);
// Prevent the compiler from pushing the transfer before all previous
Expand All @@ -100,7 +102,7 @@ static inline void __cl_dma_memcpy_irq(unsigned int ext, unsigned int loc, unsig
{
eu_mutex_lock_from_id(0);

int id = -1;
int id = copy->id;
if (!merge) id = plp_dma_counter_alloc();
unsigned int cmd = plp_dma_getCmd(dir, size, PLP_DMA_1D, PLP_DMA_NO_TRIG_EVT, PLP_DMA_TRIG_IRQ, PLP_DMA_SHARED);
// Prevent the compiler from pushing the transfer before all previous
Expand Down Expand Up @@ -131,31 +133,50 @@ static inline void __cl_dma_memcpy_2d(unsigned int ext, unsigned int loc, unsign
{
eu_mutex_lock_from_id(0);

int id = -1;
int id = copy->id;
if (!merge) id = plp_dma_counter_alloc();

{
unsigned int cmd = plp_dma_getCmd(dir, size, PLP_DMA_2D, PLP_DMA_TRIG_EVT, PLP_DMA_NO_TRIG_IRQ, PLP_DMA_SHARED);
// Prevent the compiler from pushing the transfer before all previous
// stores are done
__asm__ __volatile__ ("" : : : "memory");
plp_dma_cmd_push_2d(cmd, loc, ext, stride, length);
if (!merge) copy->id = id;
}
unsigned int cmd = plp_dma_getCmd(dir, size, PLP_DMA_2D, PLP_DMA_TRIG_EVT, PLP_DMA_NO_TRIG_IRQ, PLP_DMA_SHARED);
// Prevent the compiler from pushing the transfer before all previous
// stores are done
__asm__ __volatile__ ("" : : : "memory");
plp_dma_cmd_push_2d(cmd, loc, ext, stride, length);
if (!merge) copy->id = id;

eu_mutex_unlock_from_id(0);
}

static inline void __cl_dma_memcpy_2d_safe(unsigned int ext, unsigned int loc, unsigned int size, unsigned int stride, unsigned short length, pi_cl_dma_dir_e dir, int merge, pi_cl_dma_cmd_t *copy)
{
int id = copy->id;
if (!merge) id = plp_dma_counter_alloc();

unsigned int cmd = plp_dma_getCmd(dir, size, PLP_DMA_2D, PLP_DMA_TRIG_EVT, PLP_DMA_NO_TRIG_IRQ, PLP_DMA_SHARED);
// Prevent the compiler from pushing the transfer before all previous
// stores are done
__asm__ __volatile__ ("" : : : "memory");
plp_dma_cmd_push_2d(cmd, loc, ext, stride, length);
if (!merge) copy->id = id;
}


static inline void pi_cl_dma_memcpy(pi_cl_dma_copy_t *copy)
{
#if ARCHI_HAS_DMA_DEMUX
__cl_dma_memcpy_safe(copy->ext, copy->loc, copy->size, copy->dir, copy->merge, (pi_cl_dma_cmd_t *)copy);
#else
__cl_dma_memcpy(copy->ext, copy->loc, copy->size, copy->dir, copy->merge, (pi_cl_dma_cmd_t *)copy);
#endif
}


static inline void pi_cl_dma_memcpy_2d(pi_cl_dma_copy_2d_t *copy)
{
#if ARCHI_HAS_DMA_DEMUX
__cl_dma_memcpy_2d_safe(copy->ext, copy->loc, copy->size, copy->stride, copy->length, copy->dir, copy->merge, (pi_cl_dma_cmd_t *)copy);
#else
__cl_dma_memcpy_2d(copy->ext, copy->loc, copy->size, copy->stride, copy->length, copy->dir, copy->merge, (pi_cl_dma_cmd_t *)copy);
#endif
}


Expand All @@ -167,13 +188,21 @@ static inline void pi_cl_dma_flush()

static inline void pi_cl_dma_wait(void *copy)
{
#if ARCHI_HAS_DMA_DEMUX
__cl_dma_wait_safe(copy);
#else
__cl_dma_wait(copy);
#endif
}


static inline void pi_cl_dma_cmd(uint32_t ext, uint32_t loc, uint32_t size, pi_cl_dma_dir_e dir, pi_cl_dma_cmd_t *cmd)
{
#if ARCHI_HAS_DMA_DEMUX
__cl_dma_memcpy_safe(ext, loc, size, dir, 0, (pi_cl_dma_cmd_t *)cmd);
#else
__cl_dma_memcpy(ext, loc, size, dir, 0, (pi_cl_dma_cmd_t *)cmd);
#endif
}


Expand All @@ -185,13 +214,21 @@ static inline void pi_cl_dma_cmd_safe(uint32_t ext, uint32_t loc, uint32_t size,

static inline void pi_cl_dma_cmd_2d(uint32_t ext, uint32_t loc, uint32_t size, uint32_t stride, uint32_t length, pi_cl_dma_dir_e dir, pi_cl_dma_cmd_t *cmd)
{
#if ARCHI_HAS_DMA_DEMUX
__cl_dma_memcpy_2d_safe(ext, loc, size, stride, length, dir, 0, (pi_cl_dma_cmd_t *)cmd);
#else
__cl_dma_memcpy_2d(ext, loc, size, stride, length, dir, 0, (pi_cl_dma_cmd_t *)cmd);
#endif
}


static inline void pi_cl_dma_cmd_wait(pi_cl_dma_cmd_t *cmd)
{
#if ARCHI_HAS_DMA_DEMUX
__cl_dma_wait_safe((pi_cl_dma_cmd_t *)cmd);
#else
__cl_dma_wait((pi_cl_dma_cmd_t *)cmd);
#endif
}

static inline void pi_cl_dma_cmd_wait_safe(pi_cl_dma_cmd_t *cmd)
Expand Down
2 changes: 2 additions & 0 deletions rtos/pulpos/pulp_archi/include/archi/chips/pulp/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
#endif
#define ARCHI_NB_CLUSTER 1

#define ARCHI_HAS_DMA_DEMUX 1



/*
Expand Down
13 changes: 9 additions & 4 deletions rtos/pulpos/pulp_hal/include/hal/dma/mchan_v7.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,17 @@ static inline unsigned int plp_dma_status();

/// @cond IMPLEM

#if ARCHI_HAS_DMA_DEMUX
#define DMA_ADDR ARCHI_MCHAN_DEMUX_ADDR
#else
#define DMA_ADDR ARCHI_MCHAN_EXT_ADDR
#endif
#if defined(__riscv__) && !defined(RV_ISA_RV32) && !defined(__LLVM__)
#define DMA_WRITE(value, offset) __builtin_pulp_OffsetedWrite((value), (int *)ARCHI_MCHAN_EXT_ADDR, (offset))
#define DMA_READ(offset) __builtin_pulp_OffsetedRead((int *)ARCHI_MCHAN_EXT_ADDR, (offset))
#define DMA_WRITE(value, offset) __builtin_pulp_OffsetedWrite((value), (int *)DMA_ADDR, (offset))
#define DMA_READ(offset) __builtin_pulp_OffsetedRead((int *)DMA_ADDR, (offset))
#else
#define DMA_WRITE(value, offset) pulp_write32(ARCHI_MCHAN_EXT_ADDR + (offset), (value))
#define DMA_READ(offset) pulp_read32(ARCHI_MCHAN_EXT_ADDR + (offset))
#define DMA_WRITE(value, offset) pulp_write32(DMA_ADDR + (offset), (value))
#define DMA_READ(offset) pulp_read32(DMA_ADDR + (offset))
#endif

static inline int plp_dma_counter_alloc() {
Expand Down