From efbd87cac189786e259802543718cf0ecb4f7de1 Mon Sep 17 00:00:00 2001 From: kyleburnette Date: Wed, 3 Nov 2021 08:57:15 -0700 Subject: [PATCH] epirawdma OK (#391) * epirawdma OK * Made tharo's suggestions * Fixed epirawwrite --- include/ultra64/hardware.h | 2 +- src/libultra/io/epirawdma.c | 69 ++++++++++++++++++++++++++++++++++- src/libultra/io/epirawwrite.c | 2 +- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/include/ultra64/hardware.h b/include/ultra64/hardware.h index 30e2b898b0..a420bb5915 100644 --- a/include/ultra64/hardware.h +++ b/include/ultra64/hardware.h @@ -70,7 +70,7 @@ #define PI_STATUS_BUSY (1 << 0) #define PI_STATUS_IOBUSY (1 << 1) -#define PI_STATUS_ERROR (PI_STATUS_BUSY | PI_STATUS_IOBUSY) +#define PI_STATUS_ERROR (1 << 2) #define PI_STATUS_RESET_CONTROLLER (1 << 0) #define PI_STATUS_CLEAR_INTR (1 << 1) diff --git a/src/libultra/io/epirawdma.c b/src/libultra/io/epirawdma.c index f9e2e0f970..cbe43ce822 100644 --- a/src/libultra/io/epirawdma.c +++ b/src/libultra/io/epirawdma.c @@ -1,3 +1,70 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/epirawdma/__osEPiRawStartDma.s") +s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, u32 cartAddr, void* dramAddr, size_t size) { + s32 status; + OSPiHandle* curHandle; + + while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) { + ; + } + + if (__osCurrentHandle[handle->domain]->type != handle->type) { + curHandle = __osCurrentHandle[handle->domain]; + + if (handle->domain == 0) { + if (curHandle->latency != handle->latency) { + HW_REG(PI_BSD_DOM1_LAT_REG, u32) = handle->latency; + } + + if (curHandle->pageSize != handle->pageSize) { + HW_REG(PI_BSD_DOM1_PGS_REG, u32) = handle->pageSize; + } + + if (curHandle->relDuration != handle->relDuration) { + HW_REG(PI_BSD_DOM1_RLS_REG, u32) = handle->relDuration; + } + + if (curHandle->pulse != handle->pulse) { + HW_REG(PI_BSD_DOM1_PWD_REG, u32) = handle->pulse; + } + } else { + if (curHandle->latency != handle->latency) { + HW_REG(PI_BSD_DOM2_LAT_REG, u32) = handle->latency; + } + + if (curHandle->pageSize != handle->pageSize) { + HW_REG(PI_BSD_DOM2_PGS_REG, u32) = handle->pageSize; + } + + if (curHandle->relDuration != handle->relDuration) { + HW_REG(PI_BSD_DOM2_RLS_REG, u32) = handle->relDuration; + } + + if (curHandle->pulse != handle->pulse) { + HW_REG(PI_BSD_DOM2_PWD_REG, u32) = handle->pulse; + } + } + + curHandle->type = handle->type; + curHandle->latency = handle->latency; + curHandle->pageSize = handle->pageSize; + curHandle->relDuration = handle->relDuration; + curHandle->pulse = handle->pulse; + } + + HW_REG(PI_DRAM_ADDR_REG, void*) = (void*)osVirtualToPhysical(dramAddr); + HW_REG(PI_CART_ADDR_REG, void*) = (void*)((handle->baseAddress | cartAddr) & 0x1fffffff); + + switch (direction) { + case OS_READ: + HW_REG(PI_WR_LEN_REG, u32) = size - 1; + break; + case OS_WRITE: + HW_REG(PI_RD_LEN_REG, u32) = size - 1; + break; + default: + return -1; + } + + return 0; +} diff --git a/src/libultra/io/epirawwrite.c b/src/libultra/io/epirawwrite.c index 7c5701e0d1..dc169ecf71 100644 --- a/src/libultra/io/epirawwrite.c +++ b/src/libultra/io/epirawwrite.c @@ -4,7 +4,7 @@ s32 __osEPiRawWriteIo(OSPiHandle* handle, u32 devAddr, u32 data) { s32 status; OSPiHandle* curHandle; - while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY | PI_STATUS_ERROR)) { + while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) { ; }