sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
sio2regs.h
Go to the documentation of this file.
1
5#ifndef SIO2REGS_H
6#define SIO2REGS_H
7
8
9// SIO2 registers:
10
11#define SIO2_REL_BASE 0x1F808000
12#define SIO2_SEG 0xA0000000 // Uncached
13#define SIO2_BASE (SIO2_REL_BASE + SIO2_SEG)
14
15#define SIO2_REG_BASE (SIO2_BASE + 0x200)
16#define SIO2_REG_PORT0_CTRL1 (SIO2_BASE + 0x240)
17#define SIO2_REG_PORT0_CTRL2 (SIO2_BASE + 0x244)
18#define SIO2_REG_DATA_OUT (SIO2_BASE + 0x260)
19#define SIO2_REG_DATA_IN (SIO2_BASE + 0x264)
20#define SIO2_REG_CTRL (SIO2_BASE + 0x268)
21#define SIO2_REG_STAT6C (SIO2_BASE + 0x26C)
22#define SIO2_REG_STAT70 (SIO2_BASE + 0x270)
23#define SIO2_REG_STAT74 (SIO2_BASE + 0x274)
24#define SIO2_REG_UNKN78 (SIO2_BASE + 0x278)
25#define SIO2_REG_UNKN7C (SIO2_BASE + 0x27C)
26#define SIO2_REG_STAT (SIO2_BASE + 0x280)
27
28#define SIO2_A_QUEUE (SIO2_BASE + 0x200)
29#define SIO2_A_PORT0_CTRL1 (SIO2_BASE + 0x240)
30#define SIO2_A_PORT0_CTRL2 (SIO2_BASE + 0x244)
31#define SIO2_A_DATA_OUT (SIO2_BASE + 0x260)
32#define SIO2_A_DATA_IN (SIO2_BASE + 0x264)
33#define SIO2_A_CTRL (SIO2_BASE + 0x268)
34#define SIO2_A_STAT6C (SIO2_BASE + 0x26C)
35#define SIO2_A_CONN_STAT70 (SIO2_BASE + 0x270)
36#define SIO2_A_FIFO_STAT74 (SIO2_BASE + 0x274)
37#define SIO2_A_TX_FIFO_PT (SIO2_BASE + 0x278)
38#define SIO2_A_RX_FIFO_PT (SIO2_BASE + 0x27C)
39#define SIO2_A_INTR_STAT (SIO2_BASE + 0x280)
40
41// Bit-field definitions:
42
43#define PCTRL0_ATT_LOW_PER(x) ((((u32)(x)) << 0) & 0xFF)
44#define PCTRL0_ATT_MIN_HIGH_PER(x) ((((u32)(x)) << 8) & 0xFF00)
45#define PCTRL0_BAUD0_DIV(x) ((((u32)(x)) << 16) & 0xFF0000)
46#define PCTRL0_BAUD1_DIV(x) ((((u32)(x)) << 24) & 0xFF000000)
47
48#define PCTRL1_ACK_TIMEOUT_PER(x) ((((u32)(x)) << 0) & 0xFFFF)
49#define PCTRL1_INTER_BYTE_PER(x) ((((u32)(x)) << 16) & 0xFF0000)
50#define PCTRL1_UNK24(x) ((((u32)(x))&1) << 24)
51#define PCTRL1_IF_MODE_SPI_DIFF(x) ((((u32)(x))&1) << 25)
52
53#define TR_CTRL_PORT_NR(x) ((((u32)(x))&0x3) << 0)
54#define TR_CTRL_PAUSE(x) ((((u32)(x))&1) << 2)
55#define TR_CTRL_UNK03(x) ((((u32)(x))&1) << 3)
56// Each of the folowing is 0 for PIO transfer in the given direction. to select DMA, set to 1.
57#define TR_CTRL_TX_MODE_PIO_DMA(x) ((((u32)(x))&1) << 4)
58#define TR_CTRL_RX_MODE_PIO_DMA(x) ((((u32)(x))&1) << 5)
59/*
60normal special
610 0 no transfer done(???)
621 0 normal transfer - usually used
630 1 "special" transfer (not known to have been ever used by anything, no known difference from normal).
641 1 no transfer takes place
65*/
66#define TR_CTRL_NORMAL_TR(x) (((u32)((x))&1) << 6)
67#define TR_CTRL_SPECIAL_TR(x) (((u32)((x))&1) << 7)
68// In bytes 0 - 0x100:
69#define TR_CTRL_TX_DATA_SZ(x) ((((u32)(x))&0x1FF) << 8)
70#define TR_CTRL_UNK17(x) ((((u32)(x))&1) << 17)
71#define TR_CTRL_RX_DATA_SZ(x) ((((u32)(x))&0x1FF) << 18)
72#define TR_CTRL_UNK27(x) ((((u32)(x))&1) << 27)
73// 28 and 29 can't be set
74#define TR_CTRL_UNK28(x) ((((u32)(x))&1) << 28)
75#define TR_CTRL_UNK29(x) ((((u32)(x))&1) << 29)
76// selects between baud rate divisors 0 and 1
77#define TR_CTRL_BAUD_DIV(x) ((((u32)(x))&1) << 30)
78#define TR_CTRL_WAIT_ACK_FOREVER(x) ((((u32)(x))&1) << 31)
79
80// 8268 SIO2 (main) CTRL register.
81#define CTRL_TR_START(x) ((((u32)(x))&1) << 0)
82#define CTRL_TR_RESUME_PAUSED(x) ((((u32)(x))&1) << 1)
83#define CTRL_RESET_STATE(x) ((((u32)(x))&1) << 2)
84#define CTRL_RESET_FIFOS(x) ((((u32)(x))&1) << 3)
85#define CTRL_USE_ACK_WAIT_TIMEOUT(x) ((((u32)(x))&1) << 4)
86#define CTRL_NO_MISSING_ACK_ERR(x) ((((u32)(x))&1) << 5)
87// bit6 unknonw r/o, 0
88#define CTRL_UNK06(x) ((((u32)(x))&1) << 6)
89// bit7 unknonw r/w, usually set to 1 by software
90#define CTRL_UNK07(x) ((((u32)(x))&1) << 7)
91#define CTRL_ERROR_INTR_EN(x) ((((u32)(x))&1) << 8)
92#define CTRL_TR_COMP_INTR_EN(x) ((((u32)(x))&1) << 9)
93// bits 10, 11 unknonw r/w, usually set to 0 by software
94#define CTRL_UNK10(x) ((((u32)(x))&1) << 10)
95#define CTRL_UNK11(x) ((((u32)(x))&1) << 11)
96// Unknown r/o, 0:
97#define CTRL_UNK2912(x) ((((u32)(x))&0x3FFFF) << 12)
98#define CTRL_PS1_MODE_EN(x) ((((u32)(x))&1) << 30)
99#define CTRL_SLAVE_MODE_EN(x) ((((u32)(x))&1) << 31)
100
101// 826C SIO2 (main) STAT register. (read-only)
102#define STAT_UNK0300(x) ((((u32)(x)) >> 0) & 0xF)
103// Needs more data through DMA to complete transfer:
104#define STAT_NEED_DMA_DATA_TX(x) ((((u32)(x)) >> 4) & 1)
105#define STAT_NEED_DMA_DATA_RX(x) ((((u32)(x)) >> 5) & 1)
106#define STAT_UNK0706(x) ((((u32)(x)) >> 6) & 3)
107// Queue slot number that is going to be processed next (0-15):
108#define STAT_QUEUE_SLOT_PROC(x) ((((u32)(x)) >> 8) & 0xF)
109// Kept clear only while tranfer is running, and set while idle. 1 can also signify transfer completion:
110#define STAT_TR_IDLE(x) ((((u32)(x)) >> 12) & 1)
111// FIFO underflow / overflow errors: (I am not sure if they really correspond to the TX and RX FIFOs)
112#define STAT_ERR_TX_FIFO_UOFLOW(x) ((((u32)(x)) >> 13) & 1)
113#define STAT_ERR_RX_FIFO_UOFLOW(x) ((((u32)(x)) >> 14) & 1)
114#define STAT_ERR_ACK_MISSING(x) ((((u32)(x)) >> 15) & 1)
115// Flags used to determine the transfers of which queue slots triggered erroirs. Slot = 0 - 15:
116#define STAT_ERR_QUEUE_SLOT(x, slot) ((((u32)(x)) >> (slot + 16)) & 1)
117
118// 8270 SIO2 Device connected detection status register. (read-only)
119// For ports 0-3. Only SAS0 and SAS1 are actually connected to the physical port and only on early PS2 models (~ SCPH-30000).
120#define CONN_STAT_CDC0(x) ((((u32)(x)) >> 0) & 1)
121#define CONN_STAT_CDC1(x) ((((u32)(x)) >> 1) & 1)
122#define CONN_STAT_CDC2(x) ((((u32)(x)) >> 2) & 1)
123#define CONN_STAT_CDC3(x) ((((u32)(x)) >> 3) & 1)
124#define CONN_STAT_SAS0(x) ((((u32)(x)) >> 4) & 1)
125#define CONN_STAT_SAS1(x) ((((u32)(x)) >> 5) & 1)
126#define CONN_STAT_SAS2(x) ((((u32)(x)) >> 6) & 1)
127#define CONN_STAT_SAS3(x) ((((u32)(x)) >> 7) & 1)
128
129// 8274 SIO2 FIFO status register. (read-only)
130// values 0 - 0x100 bytes:
131#define FSTAT_TX_SZ(x) ((((u32)(x)) >> 0) & 0x1FF)
132#define FSTAT_TX_UNK09(x) ((((u32)(x)) >> 9) & 1)
133#define FSTAT_TX_OVERFLOW(x) ((((u32)(x)) >> 10) & 1)
134#define FSTAT_TX_UNDERFLOW(x) ((((u32)(x)) >> 11) & 1)
135#define FSTAT_UNK1512(x) ((((u32)(x)) >> 12) & 0xF)
136#define FSTAT_RX_SZ(x) ((((u32)(x)) >> 16) & 0x1FF)
137#define FSTAT_RX_UNK09(x) ((((u32)(x)) >> 25) & 1)
138#define FSTAT_RX_OVERFLOW(x) ((((u32)(x)) >> 26) & 1)
139#define FSTAT_RX_UNDERFLOW(x) ((((u32)(x)) >> 27) & 1)
140#define FSTAT_UNK3128(x) ((((u32)(x)) >> 28) & 0xF)
141
142// 8278 SIO2_REG_UNKN78 TX FIFO pointers. (read/write)
143// #define GET_TXFPNTS_HEAD(x) ((((u32)(x)) >> 0) & 0xFF)
144// #define SET_TXFPNTS_HEAD(x) ((((u32)(x)) >> 0) & 0xFF)
145//...
146// Better not add the FIFO pointers, as to change only one of them would require more complex macros.
147// 827C SIO2_REG_UNKN7C RX FIFO pointers.
148
149// 8280 SIO2_REG_STAT u32 Interrupt status. Writing 1 to an interrupt flag clears it.
150#define GET_ISTAT_TR_COMP(x) ((((u32)(x)) >> 0) & 1)
151// Any error:
152#define GET_ISTAT_TR_ERR(x) ((((u32)(x)) >> 1) & 1)
153
154// Inline (faster) versions of sio2_* functions
155/* 04 */ static inline void inl_sio2_ctrl_set(u32 val) { _sw(val, SIO2_REG_CTRL); }
156/* 05 */ static inline u32 inl_sio2_ctrl_get() { return _lw(SIO2_REG_CTRL); }
157/* 06 */ static inline u32 inl_sio2_stat6c_get() { return _lw(SIO2_REG_STAT6C); }
158/* 07 */ static inline void inl_sio2_portN_ctrl1_set(int N, u32 val) { _sw(val, SIO2_REG_PORT0_CTRL1 + (N * 8)); }
159/* 08 */ static inline u32 inl_sio2_portN_ctrl1_get(int N) { return _lw(SIO2_REG_PORT0_CTRL1 + (N * 8)); }
160/* 09 */ static inline void inl_sio2_portN_ctrl2_set(int N, u32 val) { _sw(val, SIO2_REG_PORT0_CTRL2 + (N * 8)); }
161/* 10 */ static inline u32 inl_sio2_portN_ctrl2_get(int N) { return _lw(SIO2_REG_PORT0_CTRL2 + (N * 8)); }
162/* 11 */ static inline u32 inl_sio2_stat70_get() { return _lw(SIO2_REG_STAT70); }
163/* 12 */ static inline void inl_sio2_regN_set(int N, u32 val) { _sw(val, SIO2_REG_BASE + (N * 4)); }
164/* 13 */ static inline u32 inl_sio2_regN_get(int N) { return _lw(SIO2_REG_BASE + (N * 4)); }
165/* 14 */ static inline u32 inl_sio2_stat74_get() { return _lw(SIO2_REG_STAT74); }
166/* 15 */ static inline void inl_sio2_unkn78_set(u32 val) { _sw(val, SIO2_REG_UNKN78); }
167/* 16 */ static inline u32 inl_sio2_unkn78_get() { return _lw(SIO2_REG_UNKN78); }
168/* 17 */ static inline void inl_sio2_unkn7c_set(u32 val) { _sw(val, SIO2_REG_UNKN7C); }
169/* 18 */ static inline u32 inl_sio2_unkn7c_get() { return _lw(SIO2_REG_UNKN7C); }
170/* 19 */ static inline void inl_sio2_data_out(u8 val) { _sb(val, SIO2_REG_DATA_OUT); }
171/* 20 */ static inline u8 inl_sio2_data_in() { return _lb(SIO2_REG_DATA_IN); }
172/* 21 */ static inline void inl_sio2_stat_set(u32 val) { _sw(val, SIO2_REG_STAT); }
173/* 22 */ static inline u32 inl_sio2_stat_get() { return _lw(SIO2_REG_STAT); }
174
175static inline u16 inl_sio2_data_inh() { return _lh(SIO2_REG_DATA_IN); }
176static inline u32 inl_sio2_data_inw() { return _lw(SIO2_REG_DATA_IN); }
177
178#endif