summaryrefslogtreecommitdiff
path: root/include/PR/os_pi.h
blob: 42a45d24407e500c204da5e4ae1dc33365b16d15 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef PR_OS_PI_H
#define PR_OS_PI_H

#include "ultratypes.h"
#include "os_message.h"
#include "stddef.h"
#include "stdint.h"


typedef struct {
    /* 0x00 */ u32 errStatus;
    /* 0x04 */ void* dramAddr;
    /* 0x08 */ void* C2Addr;
    /* 0x0C */ u32 sectorSize;
    /* 0x10 */ u32 C1ErrNum;
    /* 0x14 */ u32 C1ErrSector[4];
} __OSBlockInfo; // size = 0x24

typedef struct {
    /* 0x00 */ u32 cmdType;
    /* 0x04 */ u16 transferMode;
    /* 0x06 */ u16 blockNum;
    /* 0x08 */ s32 sectorNum;
    /* 0x0C */ uintptr_t devAddr;
    /* 0x10 */ u32 bmCtlShadow;
    /* 0x14 */ u32 seqCtlShadow;
    /* 0x18 */ __OSBlockInfo block[2];
} __OSTranxInfo; // size = 0x60

typedef struct OSPiHandle {
    /* 0x00 */ struct OSPiHandle* next;
    /* 0x04 */ u8 type;
    /* 0x05 */ u8 latency;
    /* 0x06 */ u8 pageSize;
    /* 0x07 */ u8 relDuration;
    /* 0x08 */ u8 pulse;
    /* 0x09 */ u8 domain;
    /* 0x0C */ uintptr_t baseAddress;
    /* 0x10 */ u32 speed;
    /* 0x14 */ __OSTranxInfo transferInfo;
} OSPiHandle; // size = 0x74

typedef struct {
    /* 0x0 */ u8 type;
    /* 0x4 */ uintptr_t address;
} OSPiInfo; // size = 0x8

typedef struct {
    /* 0x0 */ u16 type;
    /* 0x2 */ u8 pri;
    /* 0x3 */ u8 status;
    /* 0x4 */ OSMesgQueue* retQueue;
} OSIoMesgHdr; // size = 0x8

typedef struct {
    /* 0x00 */ OSIoMesgHdr hdr;
    /* 0x08 */ void* dramAddr;
    /* 0x0C */ uintptr_t devAddr;
    /* 0x10 */ size_t size;
    /* 0x14 */ OSPiHandle* piHandle;
} OSIoMesg; // size = 0x88

typedef struct OSDevMgr {
    /* 0x00 */ s32 active;
    /* 0x04 */ OSThread* thread;
    /* 0x08 */ OSMesgQueue* cmdQueue;
    /* 0x0C */ OSMesgQueue* evtQueue;
    /* 0x10 */ OSMesgQueue* acsQueue;
    /* 0x14 */ s32 (*piDmaCallback)(s32, uintptr_t, void*, size_t);
    /* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, uintptr_t, void*, size_t);
} OSDevMgr; // size = 0x1C



#define OS_READ     0
#define OS_WRITE    1

/*
 * I/O message types
 */
#define OS_MESG_TYPE_BASE        10
#define OS_MESG_TYPE_LOOPBACK    (OS_MESG_TYPE_BASE+0)
#define OS_MESG_TYPE_DMAREAD     (OS_MESG_TYPE_BASE+1)
#define OS_MESG_TYPE_DMAWRITE    (OS_MESG_TYPE_BASE+2)
#define OS_MESG_TYPE_VRETRACE    (OS_MESG_TYPE_BASE+3)
#define OS_MESG_TYPE_COUNTER     (OS_MESG_TYPE_BASE+4)
#define OS_MESG_TYPE_EDMAREAD    (OS_MESG_TYPE_BASE+5)
#define OS_MESG_TYPE_EDMAWRITE   (OS_MESG_TYPE_BASE+6)

/*
 * I/O message priority
 */
#define OS_MESG_PRI_NORMAL    0
#define OS_MESG_PRI_HIGH      1

/*
 * PI/EPI
 */
#define PI_DOMAIN1  0
#define PI_DOMAIN2  1

extern OSPiHandle* __osPiTable;

void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt);

OSPiHandle* osCartRomInit(void);

s32 osEPiWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data);
s32 osEPiReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data);
s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction);
s32 osEPiLinkHandle(OSPiHandle* handle);

#endif