Skip to content

Commit 66e71aa

Browse files
committed
[fw-isoldr] Added abort to DMAC.
Also added dma_is_running() and change flush to purge cache.
1 parent 6df717b commit 66e71aa

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

firmware/isoldr/loader/kos/arch/dmac.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
#ifndef __ARCH_DMAC_H
1818
#define __ARCH_DMAC_H
1919

20-
#include <sys/cdefs.h>
20+
#include <kos/cdefs.h>
2121
__BEGIN_DECLS
2222

2323
#include <stdint.h>
24+
#include <stdbool.h>
2425

2526
/** \defgroup dmac DMA Controller API
2627
\brief API to use the SH4's DMA Controller
@@ -139,7 +140,7 @@ typedef struct dma_config {
139140
dma_addrmode_t src_mode, dst_mode; /**< Source/destination address mode. */
140141
dma_transmitmode_t transmit_mode; /**< DMA Transfer transmit mode. */
141142
dma_callback_t callback; /**< Optional callback function for
142-
end-of-transfer notification. */
143+
end-of-transfer notification. */
143144
} dma_config_t;
144145

145146
/** \brief DMA address.
@@ -227,6 +228,17 @@ int dma_transfer(const dma_config_t *cfg, dma_addr_t dst, dma_addr_t src,
227228
*/
228229
void dma_wait_complete(dma_channel_t channel);
229230

231+
/** \brief Check if a DMA transfer is running
232+
\ingroup dmac
233+
234+
This function will return true if a DMA transfer is running for the given
235+
DMA channel.
236+
237+
\param channel The DMA channel to check.
238+
\return True if a DMA transfer is running, false otherwise.
239+
*/
240+
bool dma_is_running(dma_channel_t channel);
241+
230242
/** \brief Get the remaining size of a DMA transfer
231243
\ingroup dmac
232244
@@ -239,6 +251,15 @@ void dma_wait_complete(dma_channel_t channel);
239251
*/
240252
size_t dma_transfer_get_remaining(dma_channel_t channel);
241253

254+
/** \brief Abort a DMA transfer
255+
\ingroup dmac
256+
257+
This function will abort a DMA transfer for the given DMA channel.
258+
259+
\param channel The DMA channel to abort.
260+
*/
261+
void dma_transfer_abort(dma_channel_t channel);
262+
242263
/** @} */
243264

244265
__END_DECLS

firmware/isoldr/loader/kos/src/dmac.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static dma_addr_t dma_map_src_dst(uintptr_t addr, size_t len, bool is_dst) {
6767
if(is_dst)
6868
dcache_inval_range(addr, len);
6969
else
70-
dcache_flush_range(addr, len);
70+
dcache_purge_range(addr, len);
7171
break;
7272

7373
default:
@@ -106,7 +106,7 @@ static const unsigned char dma_unit_size[] = {
106106
// channels_cfg[channel]->callback(d);
107107
// }
108108

109-
uint32_t dma_is_running(dma_channel_t channel) {
109+
bool dma_is_running(dma_channel_t channel) {
110110
uint32_t chcr = dmac_read(channel, DMA_REG_CHCR);
111111

112112
return (chcr & (REG_CHCR_TRANSFER_END | REG_CHCR_DMAC_EN)) == REG_CHCR_DMAC_EN;
@@ -125,6 +125,13 @@ void dma_wait_complete(dma_channel_t channel) {
125125
}
126126
}
127127

128+
void dma_transfer_abort(dma_channel_t channel) {
129+
// irq_disable_scoped();
130+
131+
dmac_write(channel, DMA_REG_CHCR, 0);
132+
// genwait_wake_all((void *)&channels_cfg[channel]);
133+
}
134+
128135
int dma_transfer(const dma_config_t *cfg, dma_addr_t dst, dma_addr_t src,
129136
size_t len, void *cb_data) {
130137
unsigned int transfer_size = dma_unit_size[cfg->unit_size];

0 commit comments

Comments
 (0)