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