summaryrefslogtreecommitdiff
path: root/src/os/osEPiRawStartDma.c
blob: 0f8c449e7232493c6eb1bc3d9b106d2859db994c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "libultra_internal.h"
#include "hardware.h"
#include "new_func.h"
#include <PR/R4300.h>
//! @todo This define is from piint.h, but including that causes problems...
#define UPDATE_REG(reg, var)           \
    if (cHandle->var != pihandle->var) \
        IO_WRITE(reg, pihandle->var);
//! @todo This define is from os.h, but including that causes problems...
#define PI_DOMAIN1 0
//! @todo These defines are from PR/rcp.h, but including that causes problems...
#define IO_WRITE(addr, data) (*(vu32*) PHYS_TO_K1(addr) = (u32) (data))

s32 osEPiRawStartDma(OSPiHandle* pihandle, s32 dir, u32 cart_addr, void* dram_addr, u32 size) {
    register int status;

    status = HW_REG(PI_STATUS_REG, u32);
    while (status & PI_STATUS_ERROR) {
        status = HW_REG(PI_STATUS_REG, u32);
    }

    HW_REG(PI_DRAM_ADDR_REG, void*) = (void*) osVirtualToPhysical(dram_addr);
    HW_REG(PI_CART_ADDR_REG, void*) = (void*) (((uintptr_t) pihandle->baseAddress | cart_addr) & 0x1fffffff);

    switch (dir) {
        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;
}