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