1 /* $NetBSD: sifbios.h,v 1.2 2001/10/19 05:47:41 shin Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * PlayStation 2 SIF BIOS Version 2.0 define. 41 */ 42 43 /* SIF BIOS uses SIFDMA_BASE as emulated IOP physical memory base */ 44 #define SIFDMA_BASE MIPS_PHYS_TO_KSEG1(0x1c000000) 45 #define EEKV_TO_IOPPHYS(a) ((u_int32_t)(a) - SIFDMA_BASE) 46 #define IOPPHYS_TO_EEKV(a) ((u_int32_t)(a) + SIFDMA_BASE) 47 48 void sifbios_init(void); 49 50 /* 51 * System 52 */ 53 int sifbios_getver(void); 54 void sifbios_halt(int); 55 void sifbios_setdve(int); 56 void sifbios_putchar(int); 57 int sifbios_getchar(void); 58 59 /* 60 * SIFDMA 61 */ 62 struct sifdma_transfer { 63 vaddr_t src; /* (EE) 16byte align */ 64 vaddr_t dst; /* (IOP) 4byte align */ 65 vsize_t sz; /* multiple of 16 */ 66 u_int32_t mode; 67 #define SIFDMA_MODE_NOINTR 0x0 68 #define SIFDMA_MODE_INTR_SENDER 0x2 69 #define SIFDMA_MODE_INTR_RECEIVER 0x4 70 }; 71 typedef int sifdma_id_t; 72 73 int sifdma_init(void); 74 void sifdma_exit(void); 75 sifdma_id_t sifdma_queue(struct sifdma_transfer *, int); 76 int sifdma_stat(sifdma_id_t); 77 void sifdma_reset(void); 78 79 /* 80 * SIFCMD 81 */ 82 typedef u_int32_t sifcmd_sw_t; 83 typedef void (*sifcmd_callback_t)(void *, void *); 84 struct sifcmd_callback_holder { 85 sifcmd_callback_t func; 86 void *arg; 87 } __attribute__((__packed__, __aligned__(4))); 88 89 int sifcmd_init(void); 90 void sifcmd_exit(void); 91 sifdma_id_t sifcmd_queue(sifcmd_sw_t, vaddr_t, size_t, vaddr_t, vaddr_t, 92 vsize_t); 93 int sifcmd_intr(void *); 94 void sifcmd_establish(sifcmd_sw_t, struct sifcmd_callback_holder *); 95 void sifcmd_disestablish(sifcmd_sw_t); 96 struct sifcmd_callback_holder *sifcmd_handler_init( 97 struct sifcmd_callback_holder *, int); 98 99 /* 100 * SIFRPC 101 */ 102 #define SIFRPC_NOWAIT 1 103 #define SIFRPC_NOCACHEFLUSH 2 104 105 #define SIFRPC_ERROR_GETPACKET 1 106 #define SIFRPC_ERROR_SENDPACKET 2 107 108 /* RPC identifier */ 109 typedef u_int32_t sifrpc_id_t; 110 /* service # */ 111 typedef u_int32_t sifrpc_callno_t; 112 /* server service function */ 113 typedef void *(*sifrpc_rpcfunc_t)(sifrpc_callno_t, void *, size_t); 114 /* callback when RPC service done. */ 115 typedef void (*sifrpc_endfunc_t)(void *); 116 117 /* sifrpc common header */ 118 struct sifrpc_header { 119 paddr_t packet_paddr; 120 u_int32_t packet_id; 121 void *wait_channel; 122 u_int32_t call_mode; 123 } __attribute__((__packed__, __aligned__(4))); 124 125 /* receive RPC call */ 126 struct sifrpc_receive { 127 struct sifrpc_header hdr; 128 void *src; 129 void *dst; 130 size_t sz; 131 sifrpc_endfunc_t end_callback; 132 void *end_callback_arg; 133 } __attribute__((__packed__, __aligned__(4))); 134 135 /* client */ 136 struct sifrpc_server; 137 138 struct sifrpc_client { 139 struct sifrpc_header hdr; 140 u_int32_t command; 141 void *buf; 142 void *cbuf; 143 sifrpc_endfunc_t end_callback; 144 void *end_callback_arg; 145 struct sifrpc_server *server; 146 } __attribute__((__packed__, __aligned__(4))); 147 148 /* server */ 149 struct sifrpc_server_queue; 150 151 struct sifrpc_server { 152 u_int32_t command; 153 sifrpc_rpcfunc_t service_func; 154 void *buf; 155 size_t buf_sz; 156 void *cbuf; 157 size_t cbuf_sz; 158 struct sifrpc_client *client; 159 void *paddr; 160 sifrpc_callno_t callno; 161 void *recv; 162 size_t recv_sz; 163 int recv_mode; 164 u_int32_t rid; 165 struct sifrpc_server *link; 166 struct sifrpc_server *next; 167 struct sifrpc_server_receive_queue *head; 168 } __attribute__((__packed__, __aligned__(4))); 169 170 /* server request queue */ 171 struct sifrpc_server_system { 172 int active; 173 struct sifrpc_server *link; 174 struct sifrpc_server *head; 175 struct sifrpc_server *last; 176 struct sifrpc_server *next; 177 void *wait_channel; 178 sifrpc_endfunc_t end_callback; 179 void *end_callback_arg; 180 } __attribute__((__packed__, __aligned__(4))); 181 182 int sifrpc_init(void); 183 void sifrpc_exit(void); 184 /* 185 * Server side 186 */ 187 /* register/unregister receive queue to RPC system */ 188 void sifrpc_establish(struct sifrpc_server_system *, sifrpc_endfunc_t, 189 void *); 190 void sifrpc_disestablish(struct sifrpc_server_system *); 191 /* queue access */ 192 struct sifrpc_server *sifrpc_dequeue(struct sifrpc_server_system *); 193 194 /* register/unregister service function to receive queue */ 195 void sifrpc_register_service(struct sifrpc_server_system *, 196 struct sifrpc_server *, sifrpc_id_t, sifrpc_rpcfunc_t, void *, 197 sifrpc_rpcfunc_t, void *); 198 void sifrpc_unregister_service(struct sifrpc_server_system *, 199 struct sifrpc_server *); 200 /* execute service */ 201 void sifrpc_dispatch_service(struct sifrpc_server *); 202 203 /* 204 * Client side 205 */ 206 int sifrpc_bind(struct sifrpc_client *, sifrpc_id_t, u_int32_t, 207 sifrpc_endfunc_t, void *); 208 int sifrpc_call(struct sifrpc_client *, sifrpc_callno_t, u_int32_t, 209 void *, size_t, void *, size_t, sifrpc_endfunc_t, void *); 210 211 /* simple transfer API */ 212 int sifrpc_receive_buffer(struct sifrpc_receive *, void *, void *, size_t, 213 u_int32_t, sifrpc_endfunc_t, void *); 214 215 /* check DMA state */ 216 int sifrpc_stat(struct sifrpc_header *); 217 218 /* 219 * IOP memory management 220 */ 221 int iopmem_init(void); 222 paddr_t iopmem_alloc(psize_t); 223 int iopmem_free(paddr_t); 224 225