Skip to content

Commit 4890761

Browse files
pcercueiQuzarDC
authored andcommitted
dmac: Drop old DMAC interface and header
And move the code initializing DMAC on Naomi to the DMAC driver. Signed-off-by: Paul Cercueil <paul@crapouillou.net>
1 parent e4171af commit 4890761

3 files changed

Lines changed: 35 additions & 148 deletions

File tree

kernel/arch/dreamcast/hardware/dmac.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ typedef enum dma_register {
3333
#define REG_CHCR_TRANSFER_END BIT(1)
3434
#define REG_CHCR_DMAC_EN BIT(0)
3535

36+
#define REG_DMAOR_DDT BIT(15)
37+
#define REG_DMAOR_PR GENMASK(9, 8)
38+
#define REG_DMAOR_COD BIT(4)
39+
#define REG_DMAOR_AE BIT(2)
40+
#define REG_DMAOR_NMIF BIT(1)
41+
#define REG_DMAOR_DME BIT(0)
42+
43+
enum dmaor_pr_mode {
44+
DMAOR_PR_CH0123,
45+
DMAOR_PR_CH0231,
46+
DMAOR_PR_CH2013,
47+
DMAOR_PR_ROUND_ROBIN,
48+
};
49+
3650
static const dma_config_t *channels_cfg[4];
3751

3852
static const irq_t channel_to_irq[] = {
@@ -173,3 +187,22 @@ void dma_transfer_abort(dma_channel_t channel) {
173187
dmac_write(channel, DMA_REG_CHCR, 0);
174188
genwait_wake_all((void *)&channels_cfg[channel]);
175189
}
190+
191+
void dma_init(void) {
192+
/* Set default settings for DMA #2.
193+
* These are set by the bios on Dreamcast, but should be set by the OS
194+
* on Naomi. */
195+
uint32_t chcr, dmaor;
196+
197+
dmac_write(2, DMA_REG_SAR, 0);
198+
199+
chcr = FIELD_PREP(REG_CHCR_SRC_ADDRMODE, DMA_ADDRMODE_INCREMENT)
200+
| FIELD_PREP(REG_CHCR_REQUEST, DMA_REQUEST_EXTERNAL_MEM_TO_DEV)
201+
| FIELD_PREP(REG_CHCR_DMAC_EN, 1);
202+
dmac_write(2, DMA_REG_CHCR, chcr);
203+
204+
dmaor = REG_DMAOR_DDT
205+
| FIELD_PREP(REG_DMAOR_PR, DMAOR_PR_CH2013)
206+
| REG_DMAOR_DME;
207+
dmac_write(0, DMA_REG_DMAOR, dmaor);
208+
}

kernel/arch/dreamcast/include/dc/dmac.h

Lines changed: 0 additions & 140 deletions
This file was deleted.

kernel/arch/dreamcast/kernel/init.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <dc/pvr.h>
2626
#include <dc/vmufs.h>
2727
#include <dc/syscalls.h>
28-
#include <dc/dmac.h>
2928

3029
#include "initall_hdrs.h"
3130

@@ -40,6 +39,7 @@ extern uintptr_t _bss_start, end;
4039
extern void _init(void);
4140
extern void _fini(void);
4241
extern void __verify_newlib_patch();
42+
extern void dma_init(void);
4343

4444
void (*__kos_init_early_fn)(void) __attribute__((weak,section(".data"))) = NULL;
4545

@@ -280,13 +280,7 @@ void arch_main(void) {
280280
uint8 *bss_start = (uint8 *)(&_bss_start);
281281
int rv;
282282

283-
if (KOS_PLATFORM_IS_NAOMI) {
284-
/* Ugh. I'm really not sure why we have to set up these DMA registers this
285-
way on boot, but failing to do so breaks maple... */
286-
DMAC_SAR2 = 0;
287-
DMAC_CHCR2 = 0x1201;
288-
DMAC_DMAOR = 0x8201;
289-
}
283+
dma_init();
290284

291285
/* Ensure the WDT is not enabled from a previous session */
292286
wdt_disable();

0 commit comments

Comments
 (0)