iopreg.h revision 1.3 1 /* $NetBSD: iopreg.h,v 1.3 2000/02/21 02:04:49 scottr Exp $ */
2
3 /*
4 * Freely contributed to The NetBSD Foundation.
5 * XXX - Do paperwork and put a proper copyright here.
6 */
7
8 #define IOP1_BASE 0x00004000
9
10 #define SCC_IOP 0
11 #define ISM_IOP 1
12
13 #define IOP_CS_BYPASS 0x01
14 #define IOP_CS_AUTOINC 0x02
15 #define IOP_CS_RUN 0x04
16 #define IOP_CS_IRQ 0x08
17 #define IOP_CS_INT0 0x10
18 #define IOP_CS_INT1 0x20
19 #define IOP_CS_HWINT 0x40
20 #define IOP_CS_DMAINACT 0x80
21
22 #define IOP_RESET (IOP_CS_DMAINACT | IOP_CS_AUTOINC)
23 #define IOP_BYPASS \
24 (IOP_CS_BYPASS | IOP_CS_AUTOINC | IOP_CS_RUN | IOP_CS_DMAINACT)
25 #define IOP_INTERRUPT (IOP_CS_INT0 | IOP_CS_INT1)
26
27 #define OSS_INTLEVEL_OFFSET 0x0001A006
28
29 typedef struct {
30 volatile u_char ram_hi;
31 u_char pad0;
32 volatile u_char ram_lo;
33 u_char pad1;
34 volatile u_char control_status;
35 u_char pad2[3];
36 volatile u_char data;
37 u_char pad3[23];
38 union {
39 struct {
40 volatile u_char sccb_cmd;
41 u_char pad0;
42 volatile u_char scca_cmd;
43 u_char pad1;
44 volatile u_char sccb_data;
45 u_char pad2;
46 volatile u_char scca_data;
47 u_char pad3;
48 } scc;
49 struct {
50 volatile u_char wdata;
51 u_char pad0;
52 /* etc... */
53 } iwm;
54 } bypass;
55 } IOPHW;
56
57 #define IOP_MAXCHAN 7
58 #define IOP_MAXMSG 8
59 #define IOP_MSGLEN 32
60 #define IOP_MSGBUFLEN (IOP_MSGLEN * IOP_MAXCHAN)
61
62 #define IOP_MSG_IDLE 0 /* idle */
63 #define IOP_MSG_NEW 1 /* new message sent */
64 #define IOP_MSG_RECEIVED 2 /* message received; processing */
65 #define IOP_MSG_COMPLETE 3 /* message processing complete */
66
67 #define IOP_ADDR_MAX_SEND_CHAN 0x200
68 #define IOP_ADDR_SEND_STATE 0x201
69 #define IOP_ADDR_PATCH_CTRL 0x21F
70 #define IOP_ADDR_SEND_MSG 0x220
71 #define IOP_ADDR_MAX_RECV_CHAN 0x300
72 #define IOP_ADDR_RECV_STATE 0x301
73 #define IOP_ADDR_ALIVE 0x31F
74 #define IOP_ADDR_RECV_MSG 0x320
75
76 typedef struct {
77 u_char pad1[0x200];
78 u_char max_send_chan; /* maximum send channel # */
79 u_char send_state[IOP_MAXCHAN]; /* send channel states */
80 u_char pad2[23];
81 u_char patch_ctrl; /* patch control flag */
82 u_char send_msg[IOP_MSGBUFLEN]; /* send channel message data */
83 u_char max_recv_chan; /* max. receive channel # */
84 u_char recv_state[IOP_MAXCHAN]; /* receive channel states */
85 u_char pad3[23];
86 u_char alive; /* IOP alive flag */
87 u_char recv_msg[IOP_MSGBUFLEN]; /* receive channel msg data */
88 } IOPK;
89
90 struct iop_msg;
91 struct _s_IOP;
92
93 typedef void (*iop_msg_handler)(struct _s_IOP *iop, struct iop_msg *);
94
95 struct iop_msg {
96 SIMPLEQ_ENTRY(iop_msg) iopm;
97 int channel;
98 int status;
99 u_char msg[IOP_MSGLEN];
100
101 /* The routine that will handle the message */
102 iop_msg_handler handler;
103 void *user_data;
104 };
105
106 #define IOP_MSGSTAT_IDLE 0 /* Message unused (invalid) */
107 #define IOP_MSGSTAT_QUEUED 1 /* Message queued for send */
108 #define IOP_MSGSTAT_SENDING 2 /* Message on IOP */
109 #define IOP_MSGSTAT_SENT 3 /* Message complete */
110 #define IOP_MSGSTAT_RECEIVING 4 /* Top of receive queue */
111 #define IOP_MSGSTAT_RECEIVED 5 /* Msg received */
112 #define IOP_MSGSTAT_UNEXPECTED 6 /* Unexpected msg received */
113
114 typedef struct _s_IOP {
115 IOPHW *iop;
116 struct pool pool;
117 SIMPLEQ_HEAD(, iop_msg) sendq[IOP_MAXCHAN];
118 SIMPLEQ_HEAD(, iop_msg) recvq[IOP_MAXCHAN];
119 iop_msg_handler listeners[IOP_MAXCHAN];
120 void *listener_data[IOP_MAXCHAN];
121 struct iop_msg unsolicited_msg;
122 } IOP;
123
124 #define IOP_LOADADDR(ioph,addr) (ioph->ram_lo = addr & 0xff, \
125 ioph->ram_hi = (addr >> 8) & 0xff)
126
127 void iop_init __P((int fullinit));
128 void iop_upload __P((int iop, u_char *mem, u_long nb, u_long iopbase));
129 void iop_download __P((int iop, u_char *mem, u_long nb, u_long iopbase));
130 int iop_send_msg __P((int iopn, int chan, u_char *msg, int msglen,
131 iop_msg_handler handler, void *udata));
132 int iop_queue_receipt __P((int iopn, int chan, iop_msg_handler handler,
133 void *user_data));
134 int iop_register_listener __P((int iopn, int chan, iop_msg_handler handler,
135 void *user_data));
136
137 /* ADB support */
138 #define IOP_CHAN_ADB 2
139
140 #define IOP_ADB_FL_EXPLICIT 0x80 /* Non-zero if explicit command */
141 #define IOP_ADB_FL_AUTOPOLL 0x40 /* Auto/SRQ polling enabled */
142 #define IOP_ADB_FL_SRQ 0x04 /* SRQ detected */
143 #define IOP_ADB_FL_TIMEOUT 0x02 /* Non-zero if timeout */
144
145 /*
146 * The structure of an ADB packet to/from the IOP is:
147 * Flag byte (values above)
148 * Count of bytes in data
149 * Command byte
150 * Data (optional)
151 */
152