summaryrefslogtreecommitdiff
path: root/lib/ultralib/src/io/dpsetnextbuf.c
blob: cbf3a6f2ee79e61ce4cdbdc3ce881e6ac004ac64 (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
37
38
39
#include "PR/os_internal.h"
#include "PR/ultraerror.h"
#include "PR/rcp.h"
#include "PRinternal/osint.h"

// TODO: this comes from a header
#ident "$Revision: 1.17 $"

s32 osDpSetNextBuffer(void* bufPtr, u64 size) {
    register u32 stat;

#ifdef _DEBUG
    if ((u32)bufPtr & 0x7) {
        __osError(ERR_OSDPSETNEXTBUFFER_ADDR, 1, bufPtr);
        return -1;
    }
    if (size & 0x7) {
        __osError(ERR_OSDPSETNEXTBUFFER_SIZE, 1, size);
        return -1;
    }
#endif

    if (__osDpDeviceBusy()) {
        return -1;
    }

    IO_WRITE(DPC_STATUS_REG, DPC_CLR_XBUS_DMEM_DMA);

    while (TRUE) {
        stat = IO_READ(DPC_STATUS_REG);
        if ((stat & DPC_STATUS_XBUS_DMEM_DMA) == 0) {
            break;
        }
    }

    IO_WRITE(DPC_START_REG, osVirtualToPhysical(bufPtr));
    IO_WRITE(DPC_END_REG, osVirtualToPhysical(bufPtr) + size);
    return 0;
}