1 /* $NetBSD: iopreg.h,v 1.4 2000/07/30 21:48:54 briggs Exp $ */ 2 3 /* 4 * Copyright (c) 2000 Allen Briggs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #define IOP1_BASE 0x00004000 31 32 #define SCC_IOP 0 33 #define ISM_IOP 1 34 35 #define IOP_CS_BYPASS 0x01 36 #define IOP_CS_AUTOINC 0x02 37 #define IOP_CS_RUN 0x04 38 #define IOP_CS_IRQ 0x08 39 #define IOP_CS_INT0 0x10 40 #define IOP_CS_INT1 0x20 41 #define IOP_CS_HWINT 0x40 42 #define IOP_CS_DMAINACT 0x80 43 44 #define IOP_RESET (IOP_CS_DMAINACT | IOP_CS_AUTOINC) 45 #define IOP_BYPASS \ 46 (IOP_CS_BYPASS | IOP_CS_AUTOINC | IOP_CS_RUN | IOP_CS_DMAINACT) 47 #define IOP_INTERRUPT (IOP_CS_INT0 | IOP_CS_INT1) 48 49 #define OSS_INTLEVEL_OFFSET 0x0001A006 50 51 typedef struct { 52 volatile u_char ram_hi; 53 u_char pad0; 54 volatile u_char ram_lo; 55 u_char pad1; 56 volatile u_char control_status; 57 u_char pad2[3]; 58 volatile u_char data; 59 u_char pad3[23]; 60 union { 61 struct { 62 volatile u_char sccb_cmd; 63 u_char pad0; 64 volatile u_char scca_cmd; 65 u_char pad1; 66 volatile u_char sccb_data; 67 u_char pad2; 68 volatile u_char scca_data; 69 u_char pad3; 70 } scc; 71 struct { 72 volatile u_char wdata; 73 u_char pad0; 74 /* etc... */ 75 } iwm; 76 } bypass; 77 } IOPHW; 78 79 #define IOP_MAXCHAN 7 80 #define IOP_MAXMSG 8 81 #define IOP_MSGLEN 32 82 #define IOP_MSGBUFLEN (IOP_MSGLEN * IOP_MAXCHAN) 83 84 #define IOP_MSG_IDLE 0 /* idle */ 85 #define IOP_MSG_NEW 1 /* new message sent */ 86 #define IOP_MSG_RECEIVED 2 /* message received; processing */ 87 #define IOP_MSG_COMPLETE 3 /* message processing complete */ 88 89 #define IOP_ADDR_MAX_SEND_CHAN 0x200 90 #define IOP_ADDR_SEND_STATE 0x201 91 #define IOP_ADDR_PATCH_CTRL 0x21F 92 #define IOP_ADDR_SEND_MSG 0x220 93 #define IOP_ADDR_MAX_RECV_CHAN 0x300 94 #define IOP_ADDR_RECV_STATE 0x301 95 #define IOP_ADDR_ALIVE 0x31F 96 #define IOP_ADDR_RECV_MSG 0x320 97 98 typedef struct { 99 u_char pad1[0x200]; 100 u_char max_send_chan; /* maximum send channel # */ 101 u_char send_state[IOP_MAXCHAN]; /* send channel states */ 102 u_char pad2[23]; 103 u_char patch_ctrl; /* patch control flag */ 104 u_char send_msg[IOP_MSGBUFLEN]; /* send channel message data */ 105 u_char max_recv_chan; /* max. receive channel # */ 106 u_char recv_state[IOP_MAXCHAN]; /* receive channel states */ 107 u_char pad3[23]; 108 u_char alive; /* IOP alive flag */ 109 u_char recv_msg[IOP_MSGBUFLEN]; /* receive channel msg data */ 110 } IOPK; 111 112 struct iop_msg; 113 struct _s_IOP; 114 115 typedef void (*iop_msg_handler)(struct _s_IOP *iop, struct iop_msg *); 116 117 struct iop_msg { 118 SIMPLEQ_ENTRY(iop_msg) iopm; 119 int channel; 120 int status; 121 u_char msg[IOP_MSGLEN]; 122 123 /* The routine that will handle the message */ 124 iop_msg_handler handler; 125 void *user_data; 126 }; 127 128 #define IOP_MSGSTAT_IDLE 0 /* Message unused (invalid) */ 129 #define IOP_MSGSTAT_QUEUED 1 /* Message queued for send */ 130 #define IOP_MSGSTAT_SENDING 2 /* Message on IOP */ 131 #define IOP_MSGSTAT_SENT 3 /* Message complete */ 132 #define IOP_MSGSTAT_RECEIVING 4 /* Top of receive queue */ 133 #define IOP_MSGSTAT_RECEIVED 5 /* Msg received */ 134 #define IOP_MSGSTAT_UNEXPECTED 6 /* Unexpected msg received */ 135 136 typedef struct _s_IOP { 137 IOPHW *iop; 138 struct pool pool; 139 SIMPLEQ_HEAD(, iop_msg) sendq[IOP_MAXCHAN]; 140 SIMPLEQ_HEAD(, iop_msg) recvq[IOP_MAXCHAN]; 141 iop_msg_handler listeners[IOP_MAXCHAN]; 142 void *listener_data[IOP_MAXCHAN]; 143 struct iop_msg unsolicited_msg; 144 } IOP; 145 146 #define IOP_LOADADDR(ioph,addr) (ioph->ram_lo = addr & 0xff, \ 147 ioph->ram_hi = (addr >> 8) & 0xff) 148 149 void iop_init __P((int fullinit)); 150 void iop_upload __P((int iop, u_char *mem, u_long nb, u_long iopbase)); 151 void iop_download __P((int iop, u_char *mem, u_long nb, u_long iopbase)); 152 int iop_send_msg __P((int iopn, int chan, u_char *msg, int msglen, 153 iop_msg_handler handler, void *udata)); 154 int iop_queue_receipt __P((int iopn, int chan, iop_msg_handler handler, 155 void *user_data)); 156 int iop_register_listener __P((int iopn, int chan, iop_msg_handler handler, 157 void *user_data)); 158 159 /* ADB support */ 160 #define IOP_CHAN_ADB 2 161 162 #define IOP_ADB_FL_EXPLICIT 0x80 /* Non-zero if explicit command */ 163 #define IOP_ADB_FL_AUTOPOLL 0x40 /* Auto/SRQ polling enabled */ 164 #define IOP_ADB_FL_SRQ 0x04 /* SRQ detected */ 165 #define IOP_ADB_FL_TIMEOUT 0x02 /* Non-zero if timeout */ 166 167 /* 168 * The structure of an ADB packet to/from the IOP is: 169 * Flag byte (values above) 170 * Count of bytes in data 171 * Command byte 172 * Data (optional) 173 */ 174