PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
iLink_internal.h
1// #define DEBUG_TTY_FEEDBACK /* Comment out to disable generation of debug TTY messages */
2
3#ifdef DEBUG_TTY_FEEDBACK
4#define DEBUG_PRINTF(args...) printf("ILINKMAN: "args)
5#define iDEBUG_PRINTF(args...) Kprintf("ILINKMAN: "args)
6#else
7#define DEBUG_PRINTF(args...) \
8 do { \
9 } while (0)
10#define iDEBUG_PRINTF(args...) \
11 do { \
12 } while (0)
13#endif
14
15#define REQ_CHECK_MEM_BOUNDARIES /* Define this to enable memory address boundary checking for incoming requests. */
16#define REQ_CHECK_CONSOLE_VERSION /* Define this to enable version checks on the Playstation 2 console. */
17// #define REQ_CHECK_DMAC_STAT /* Define this to enable memory DMAC status checking. */
18// #define REQ_CHECK_ERRORS /* Define this to enable checking for HdrErr and SntBsyAck interrupts. Serves no purpose except for debugging. */
19
20#define iLink_INTR0_DRFR 0x00000001
21#define iLink_INTR0_DRFO 0x00000002
22#define iLink_INTR0_TxStk 0x00000040
23#define iLink_INTR0_FmtE 0x00000080
24#define iLink_INTR0_UResp 0x00000100
25#define iLink_INTR0_PBCntR 0x00000200
26#define iLink_INTR0_STO 0x00000400
27#define iLink_INTR0_RetEx 0x00000800
28#define iLink_INTR0_InvAck 0x00001000
29#define iLink_INTR0_AckMiss 0x00002000
30#define iLink_INTR0_AckRcvd 0x00004000
31#define iLink_INTR0_CycArbFl 0x00008000
32#define iLink_INTR0_CycLost 0x00010000
33#define iLink_INTR0_CycSt 0x00080000
34#define iLink_INTR0_CycTL 0x00200000
35#define iLink_INTR0_URx 0x00400000
36#define iLink_INTR0_SubActGap 0x00800000
37#define iLink_INTR0_TCErr 0x01000000
38#define iLink_INTR0_HdrErr 0x02000000
39#define iLink_INTR0_SntBsyAck 0x04000000
40#define iLink_INTR0_CmdRst 0x08000000
41#define iLink_INTR0_ArbRstGap 0x10000000
42#define iLink_INTR0_PhyRst 0x20000000
43#define iLink_INTR0_PhyRRx 0x40000000
44#define iLink_INTR0_PhyInt 0x80000000
45
46#define iLink_INTR1_DTFO 0x00000001
47#define iLink_INTR1_UTD 0x00000002
48
49#define iLink_CTRL0_URcvM 0x00000010
50#define iLink_CTRL0_RSP0 0x00000020
51#define iLink_CTRL0_RetLim(x) (x << 12)
52#define iLink_CTRL0_LooseTightIso 0x00010000
53#define iLink_CTRL0_STardy 0x00020000
54#define iLink_CTRL0_BRDE 0x00040000
55#define iLink_CTRL0_Root 0x00080000
56#define iLink_CTRL0_ExtCyc 0x00100000
57#define iLink_CTRL0_CycTmrEn 0x00200000
58#define iLink_CTRL0_CMstr 0x00400000
59#define iLink_CTRL0_BusIDRst 0x00800000
60#define iLink_CTRL0_RxRst 0x01000000
61#define iLink_CTRL0_TxRst 0x02000000
62#define iLink_CTRL0_RxEn 0x04000000
63#define iLink_CTRL0_TxEn 0x08000000
64#define iLink_CTRL0_DELim(x) (x << 28)
65#define iLink_CTRL0_SIDF 0x40000000
66#define iLink_CTRL0_RcvSelfID 0x80000000
67
68#define iLink_CTRL2_LPSRst 0x00000001
69#define iLink_CTRL2_LPSEn 0x00000002
70#define iLink_CTRL2_SRst 0x00000004
71#define iLink_CTRL2_SOK 0x00000008
72
73#define iLinkDMA_CTRL_SR_DWidth(x) (x << 17)
74#define iLinkDMA_CTRL_SR_DEn 0x080000
75#define iLinkDMA_CTRL_SR_RActl 0x010000
76#define iLinkDMA_CTRL_SR_LFirst 0x100000
77
78#define PHT_CTRL_ST_PRBR 0x00000200
79#define PHT_CTRL_ST_PStk 0x00000400
80#define PHT_CTRL_ST_EnDMAS 0x00001000
81#define PHT_CTRL_ST_EBCNT 0x00008000
82#define PHT_CTRL_ST_EWREQ 0x00010000
83#define PHT_CTRL_ST_ERREQ 0x00020000
84#define PHT_CTRL_ST_EPCNT 0x00100000
85#define PHT_CTRL_ST_PHTRst 0x00200000
86#define PHT_CTRL_ST_IHdr 0x00400000
87#define PHT_CTRL_ST_EHdr 0x02000000
88
89#define DBUF_FIFO_RESET_TX 0x00008000
90#define DBUF_FIFO_RESET_RX 0x80000000
91
92#define PACKET_TCODE (((x) >> 4) & 0xF)
93
94/* PHY configuration packet data */
95#define PHY_CONFIG_PACKET 0xE0
96#define PHY_CONFIG_GAP_CNT(x) (((x) >> 16) & 0x3F)
97#define PHY_CONFIG_T(x) (((x) >> 22) & 0x01)
98#define PHY_CONFIG_R(x) (((x) >> 23) & 0x01)
99#define PHY_CONFIG_ROOT_ID(x) (((x) >> 24) & 0x3F)
100
101/* SELF-ID packet data */
102#define PHY_SELF_ID_PACKET 0xE1
103#define PHY_SELF_ID_PKT_SIG 0x2 /* 10b */
104#define SELF_ID_SIGNATURE(x) (((x) >> 30) & 0x03)
105#define SELF_ID_NODEID(x) (((x) >> 24) & 0x3F)
106#define SELF_ID_L(x) (((x) >> 22) & 0x01)
107#define SELF_ID_GAP_CNT(x) (((x) >> 16) & 0x3F)
108#define SELF_ID_SPEED(x) (((x) >> 14) & 0x03)
109#define SELF_ID_POWER(x) (((x) >> 8) & 0x07)
110#define SELF_ID_M(x) ((x)&0x01)
111
112/* PHY Register bits. */
113#define REG01_IBR 0x40
114#define REG01_RHB 0x80
115#define REG04_LCTRL 0x80
116#define REG05_ISBR 0x40
117#define REG05_EN_ACCL 0x02
118#define REG05_EN_MULTI 0x01
119
120/* Event flag bits. */
121#define iLinkEventInterrupt 0x00000001
122#define iLinkEventBusReady 0x00000002
123#define iLinkEventGotSELFIDs 0x00000004
124#define iLinkEventDataSent 0x00000008
125#define iLinkEventDataReceived 0x00000010
126#define iLinkEventDMATransEnd 0x00000020
127#define iLinkEventBusReset 0x00000040
128#define iLinkEventURx 0x00000080
129#define iLinkEventError 0x80000000
130
131/* Structures. */
132#define IEEE1394_TCODE_WRITEQ 0
133#define IEEE1394_TCODE_WRITEB 1
134#define IEEE1394_TCODE_WRITE_RESPONSE 2
135#define IEEE1394_TCODE_READQ 4
136#define IEEE1394_TCODE_READB 5
137#define IEEE1394_TCODE_READQ_RESPONSE 6
138#define IEEE1394_TCODE_READB_RESPONSE 7
139
141{
142 unsigned int header;
143 unsigned int offset_high;
144 unsigned int offset_low;
145 unsigned int misc;
146};
147
149{
150 unsigned int header;
151 unsigned int header2;
152 unsigned int reserved;
153 unsigned int LastField;
154};
155
156#define ILINK_REGISTER_BASE 0xBF808400
157
159{
160 volatile unsigned int NodeID; /* 0x00 */
161 volatile unsigned int CycleTime; /* 0x04 */
162
163 volatile unsigned int ctrl0; /* 0x08 */
164 volatile unsigned int ctrl1; /* 0x0C */
165 volatile unsigned int ctrl2; /* 0x10 */
166
167 volatile unsigned int PHYAccess; /* 0x14 */
168
169 volatile unsigned int UnknownRegister18; /* 0x18 */
170 volatile unsigned int UnknownRegister1C; /* 0x1C */
171
172 volatile unsigned int intr0; /* 0x20 */
173 volatile unsigned int intr0Mask; /* 0x24 */
174
175 volatile unsigned int intr1; /* 0x28 */
176 volatile unsigned int intr1Mask; /* 0x2C */
177
178 volatile unsigned int intr2; /* 0x30 */
179 volatile unsigned int intr2Mask; /* 0x34 */
180
181 volatile unsigned int dmar; /* 0x38 */
182 volatile unsigned int ack_status; /* 0x3C */
183 volatile unsigned int ubufTransmitNext; /* 0x40 */
184 volatile unsigned int ubufTransmitLast; /* 0x44 */
185 volatile unsigned int ubufTransmitClear; /* 0x48 */
186 volatile unsigned int ubufReceiveClear; /* 0x4C */
187 volatile unsigned int ubufReceive; /* 0x50 */
188 volatile unsigned int ubufReceiveLevel; /* 0x54 */
189
190 volatile unsigned int unmapped1[0x06]; /* Registers 0x58-0x6C are unmapped. */
191
192 volatile unsigned int UnknownRegister70; /* 0x70 */
193 volatile unsigned int UnknownRegister74; /* 0x74 */
194 volatile unsigned int UnknownRegister78; /* 0x78 */
195 volatile unsigned int UnknownRegister7C; /* 0x7C */
196
197 volatile unsigned int PHT_ctrl_ST_R0; /* 0x80 */
198 volatile unsigned int PHT_split_TO_R0; /* 0x84 */
199 volatile unsigned int PHT_ReqResHdr0_R0; /* 0x88 */
200 volatile unsigned int PHT_ReqResHdr1_R0; /* 0x8C */
201 volatile unsigned int PHT_ReqResHdr2_R0; /* 0x90 */
202
203 volatile unsigned int STRxNIDSel0_R0; /* 0x94 */
204 volatile unsigned int STRxNIDSel1_R0; /* 0x98 */
205
206 volatile unsigned int STRxHDR_R0; /* 0x9C */
207 volatile unsigned int STTxHDR_R0; /* 0xA0 */
208
209 volatile unsigned int DTransCTRL0; /* 0xA4 */
210 volatile unsigned int CIPHdrTx0_R0; /* 0xA8 */
211 volatile unsigned int CIPHdrTx1_R0; /* 0xAC */
212
213 volatile unsigned int padding4; /* 0xB0 */
214 volatile unsigned int STTxTimeStampOffs_R0; /* 0xB4 */
215
216 volatile unsigned int dmaCtrlSR0; /* 0xB8 */
217 volatile unsigned int dmaTransTRSH0; /* 0xBC */
218 volatile unsigned int dbufFIFO_lvlR0; /* 0xC0 */
219 volatile unsigned int dbufTxDataR0; /* 0xC4 */
220 volatile unsigned int dbufRxDataR0; /* 0xC8 */
221
222 volatile unsigned int dbufWatermarksR0; /* 0xCC (Unmapped) */
223 volatile unsigned int dbufFIFOSzR0; /* 0xD0 (Unmapped) */
224
225 volatile unsigned int unmapped2[0x0B]; /* Unmapped. */
226
227 volatile unsigned int PHT_ctrl_ST_R1; /* 0x100 */
228 volatile unsigned int PHT_split_TO_R1; /* 0x104 */
229 volatile unsigned int PHT_ReqResHdr0_R1; /* 0x108 */
230 volatile unsigned int PHT_ReqResHdr1_R1; /* 0x10C */
231 volatile unsigned int PHT_ReqResHdr2_R1; /* 0x110 */
232
233 volatile unsigned int STRxNIDSel0_R1; /* 0x114 */
234 volatile unsigned int STRxNIDSel1_R1; /* 0x118 */
235
236 volatile unsigned int STRxHDR_R1; /* 0x11C */
237 volatile unsigned int STTxHDR_R1; /* 0x120 */
238
239 volatile unsigned int DTransCTRL1; /* 0x124 */
240 volatile unsigned int CIPHdrTx0_R1; /* 0x128 */
241 volatile unsigned int CIPHdrTx1_R1; /* 0x12C */
242
243 volatile unsigned int padding5; /* 0x130 */
244 volatile unsigned int STTxTimeStampOffs_R1; /* 0x134 */
245
246 volatile unsigned int dmaCtrlSR1; /* 0x138 */
247 volatile unsigned int dmaTransTRSH1; /* 0x13C */
248 volatile unsigned int dbufFIFO_lvlR1; /* 0x140 */
249 volatile unsigned int dbufTxDataR1; /* 0x144 */
250 volatile unsigned int dbufRxDataR1; /* 0x148 */
251
252 volatile unsigned int dbufWatermarksR1; /* 0x14C (Unmapped) */
253 volatile unsigned int dbufFIFOSzR1; /* 0x150 (Unmapped) */
254};
255
256#define ILINK_DMAC_REGISTER_BASE 0xBF801580
257
259{ /* The PS2 has 3 of these register blocks for DMAC #3 */
260 volatile unsigned int madr;
261 volatile unsigned int dlen;
262 volatile unsigned int slice;
263 volatile unsigned int chcr;
264 volatile unsigned int rtar;
265 volatile unsigned int DmarReadStart;
266 volatile unsigned int DmarReadEnd;
267
268 volatile unsigned int unused; /* This region contains either unmapped memory locations or registers that aren't for specific DMA channel control. */
269};
270
271#define ILINK_DMAC_DMAR_CTRL_BASE 0xBF8015DC
272
274{
275 volatile unsigned int DmarWriteStart;
276 volatile unsigned int DmarWriteEnd;
277};
278
279#define MAX_CONCURRENT_TRANSACTIONS 10
280
281#define DMAC_CHCR_AR (1 << 31) /* Automatic Response. */
282#define DMAC_CHCR_11 (1 << 11) /* I don't know what this does, but it appears to be a bit that means something to the DMAC. */
283
285{
286 int GenerationNumber;
287 unsigned short int NodeID;
288 unsigned char IsConnected;
289 unsigned char speed;
290};
291
292/* Function prototypes. */
293extern void UBUFThread(void *arg);
294extern int GetConsoleIDs(u64 *guid, char *ModelName);
295extern void iLinkDisableIntr(void);
296extern int iLinkResetHW(void);
297extern void iLinkShutdownHW(void);
298extern void iLinkHWInitialize(void);
299extern void iLinkEnableCMaster(void);
300extern void iLinkBusEnable(void);
301extern void *malloc(unsigned int nBytes);
302extern void free(void *buffer);
303
304extern void InitializeConfigurationROM(void);
305
306extern unsigned char iLinkReadPhy(unsigned char address);
307extern void iLinkWritePhy(unsigned char address, unsigned char data);
308extern void iLinkPHY_SetRootBit(int isRoot);
309extern void iLinkPHY_SetGapCount(unsigned char GapCount);
310extern void iLinkPHY_SetLCTRL(int LCTRL_status);
311extern void iLinkPHYBusReset(void);
312
313extern int iLinkIntrHandler(void *arg);
314extern void iLinkIntrRegister0Handler(void *arg);
315
316extern void SendResponse(unsigned short int NodeID, unsigned short RcvdBusID, unsigned char rcode, unsigned char tLabel, unsigned char tCode, unsigned char speed, unsigned int *buffer, unsigned int nQuads);
317extern int iLinkReadReq(struct TransactionContextData *trContext, unsigned short int offset_high, unsigned int offset_low, void *buffer, unsigned int nBytes);
318extern int iLinkWriteReq(struct TransactionContextData *trContext, unsigned short int offset_high, unsigned int offset_low, void *buffer, unsigned int nBytes);
319
320extern void iLinkInitPHT(void);
321extern void PHTSendResponse(unsigned short int NodeID, unsigned short RcvdBusID, unsigned char rcode, unsigned char tLabel, unsigned char tCode, unsigned char speed, unsigned int *buffer, unsigned int nQuads);
322extern int iLinkReadPHTReq(struct TransactionContextData *trContext, unsigned short int offset_high, unsigned int offset_low, void *buffer, unsigned int nBytes);
323extern int iLinkWritePHTReq(struct TransactionContextData *trContext, unsigned short int offset_high, unsigned int offset_low, void *buffer, unsigned int nBytes);