1/* $NetBSD: iopreg.h,v 1.4.24.2 2005/11/10 13:57:13 skrll 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 51typedef 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 98typedef 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 112struct iop_msg; 113struct _s_IOP; 114 115typedef void (*iop_msg_handler)(struct _s_IOP *iop, struct iop_msg *); 116 117struct 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 136typedef 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 149void iop_init(int); 150void iop_upload(int, u_char *, u_long, u_long); 151void iop_download(int, u_char *, u_long, u_long); 152int iop_send_msg(int, int, u_char *, int, iop_msg_handler, void *); 153int iop_queue_receipt(int, int, iop_msg_handler, void *); 154int iop_register_listener(int, int, iop_msg_handler, void *); 155 156/* SWIM support */ 157#define IOP_CHAN_SWIM 1 158 159#define IOP_SWIM_INITIALIZE 0x01 160#define IOP_SWIM_SHUTDOWN 0x02 161#define IOP_SWIM_START_POLLING 0x03 162#define IOP_SWIM_STOP_POLLING 0x04 163#define IOP_SWIM_SET_HFS_TAG_ADDR 0x05 164#define IOP_SWIM_DRIVE_STATUS 0x06 165#define IOP_SWIM_EJECT 0x07 166#define IOP_SWIM_FORMAT 0x08 167#define IOP_SWIM_FORMAT_VERIFY 0x09 168#define IOP_SWIM_WRITE 0x0a 169#define IOP_SWIM_READ 0x0b 170#define IOP_SWIM_READ_VERIFY 0x0c 171#define IOP_SWIM_CACHE_CONTROL 0x0d 172#define IOP_SWIM_TAG_BUFFER_CONTROL 0x0e 173#define IOP_SWIM_GET_ICON 0x0f 174#define IOP_SWIM_DISK_DUP_INFO 0x10 175#define IOP_SWIM_GET_RAW_DATA 0x11 176 177/* 178 * The structure of a SWIM packet to/from the IOP is: 179 * Request kind 180 * Drive Number (if needed) 181 * Error Code 182 * Data (optional) 183 */ 184 185/* ADB support */ 186#define IOP_CHAN_ADB 2 187 188#define IOP_ADB_FL_EXPLICIT 0x80 /* Non-zero if explicit command */ 189#define IOP_ADB_FL_AUTOPOLL 0x40 /* Auto/SRQ polling enabled */ 190#define IOP_ADB_FL_POLL_UPDATE 0x20 /* Update polling bit mask */ 191#define IOP_ADB_FL_SRQ 0x04 /* SRQ detected */ 192#define IOP_ADB_FL_TIMEOUT 0x02 /* Non-zero if timeout */ 193 194/* 195 * The structure of an ADB packet to/from the IOP is: 196 * Flag byte (values above) 197 * Count of bytes in data 198 * Command byte 199 * Data (optional) 200 */ 201