Skip to content

Commit

Permalink
Add SYS_IsDMAAddress
Browse files Browse the repository at this point in the history
Check if buffer is eligible for DMA
  • Loading branch information
Extrems committed Mar 19, 2024
1 parent 96fd4b8 commit b029110
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions gc/ogc/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ void SYS_Init(void);
void* SYS_AllocateFramebuffer(GXRModeObj *rmode);


bool SYS_IsDMAAddress(const void *addr);
void SYS_ProtectRange(u32 chan,void *addr,u32 bytes,u32 cntrl);
void SYS_StartPMC(u32 mcr0val,u32 mcr1val);
void SYS_DumpPMC(void);
Expand Down
6 changes: 3 additions & 3 deletions libogc/dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3172,7 +3172,7 @@ static bool __gcdvd_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)

if(sector & ~0x7fffff) return false;
if(numSectors & ~0x1fffff) return false;
if((u32)buffer & 0x1f) return false;
if(!SYS_IsDMAAddress(buffer)) return false;

if(DVD_ReadAbs(&blk, buffer, numSectors << 11, sector << 11) < 0)
return false;
Expand Down Expand Up @@ -3233,7 +3233,7 @@ static bool __gcode_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)

if((u32)sector != sector) return false;
if(numSectors & ~0x7fffff) return false;
if((u32)buffer & 0x1f) return false;
if(!SYS_IsDMAAddress(buffer)) return false;

if(DVD_GcodeRead(&blk, buffer, numSectors << 9, sector) < 0)
return false;
Expand All @@ -3247,7 +3247,7 @@ static bool __gcode_WriteSectors(sec_t sector,sec_t numSectors,const void *buffe

if((u32)sector != sector) return false;
if((u32)numSectors != numSectors) return false;
if((u32)buffer & 0x1f) return false;
if(!SYS_IsDMAAddress(buffer)) return false;

if(DVD_GcodeWrite(&blk, buffer, numSectors, sector) < 0)
return false;
Expand Down
1 change: 1 addition & 0 deletions libogc/gcsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static bool __gcsd_writeSectors(int n, sec_t sector, sec_t numSectors, const voi

if((u32)sector != sector) return false;
if((u32)numSectors != numSectors) return false;
if(!SYS_IsDMAAddress(buffer)) return false;

if(numSectors == 1)
ret = sdgecko_writeSector(n, buffer, sector);
Expand Down
12 changes: 12 additions & 0 deletions libogc/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,18 @@ void SYS_ProtectRange(u32 chan,void *addr,u32 bytes,u32 cntrl)
}
}

bool SYS_IsDMAAddress(const void *addr)
{
if((u32)addr&0x1F) return false;
if((u32)addr>=0x80000000 && (u32)addr<0x84000000) return true;
if((u32)addr>=0xC0000000 && (u32)addr<0xC4000000) return true;
#if defined(HW_RVL)
if((u32)addr>=0x90000000 && (u32)addr<0xA0000000) return true;
if((u32)addr>=0xD0000000 && (u32)addr<0xE0000000) return true;
#endif
return false;
}

void* SYS_AllocateFramebuffer(GXRModeObj *rmode)
{
return memalign(32, VIDEO_GetFrameBufferSize(rmode));
Expand Down
5 changes: 3 additions & 2 deletions libogc/wiisd.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <time.h>
#include <gcutil.h>
#include <ogc/ipc.h>
#include <ogc/system.h>
#include <unistd.h>
#include <ogc/disc_io.h>
#include <sdcard/wiisd_io.h>
Expand Down Expand Up @@ -539,7 +540,7 @@ static bool sdio_ReadSectors(sec_t sector, sec_t numSectors,void* buffer)

if((u32)sector != sector) return false;
if(numSectors & ~0x7fffff) return false;
if((u32)buffer & 0x1f) return false;
if(!SYS_IsDMAAddress(buffer)) return false;

ret = __sd0_select();
if(ret<0) return false;
Expand All @@ -558,7 +559,7 @@ static bool sdio_WriteSectors(sec_t sector, sec_t numSectors,const void* buffer)

if((u32)sector != sector) return false;
if(numSectors & ~0x7fffff) return false;
if((u32)buffer & 0x1f) return false;
if(!SYS_IsDMAAddress(buffer)) return false;

ret = __sd0_select();
if(ret<0) return false;
Expand Down

0 comments on commit b029110

Please sign in to comment.