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