1 /*- 2 * ISP Firmware Modules for FreeBSD 3 * 4 * Copyright (c) 2000, 2001, 2006 by Matthew Jacob 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 immediately at the beginning of the file, without modification, 12 * this list of conditions, and the following disclaimer. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 #include <sys/param.h> 33 #include <sys/firmware.h> 34 #include <sys/kernel.h> 35 #include <sys/linker.h> 36 #include <sys/module.h> 37 #include <sys/systm.h> 38 39 #if defined(ISP_ALL) || !defined(KLD_MODULE) 40 #ifdef __sparc64__ 41 #define ISP_1000 1 42 #endif 43 #define ISP_1040 1 44 #define ISP_1040_IT 1 45 #define ISP_1080 1 46 #define ISP_1080_IT 1 47 #define ISP_12160 1 48 #define ISP_12160_IT 1 49 #define ISP_2100 1 50 #define ISP_2200 1 51 #define ISP_2300 1 52 #define ISP_2322 1 53 #define ISP_2400 1 54 #define ISP_2400_MULTI 1 55 #define ISP_2500 1 56 #define ISP_2500_MULTI 1 57 #endif 58 59 #ifndef MODULE_NAME 60 #define MODULE_NAME "ispfw" 61 #endif 62 63 #if defined(ISP_1000) 64 #ifdef __sparc64__ 65 #include <dev/ispfw/asm_1000.h> 66 #else 67 #error "firmware not compatible with this platform" 68 #endif 69 #endif 70 #if defined(ISP_1040) || defined(ISP_1040_IT) 71 #include <dev/ispfw/asm_1040.h> 72 #endif 73 #if defined(ISP_1080) || defined(ISP_1080_IT) 74 #include <dev/ispfw/asm_1080.h> 75 #endif 76 #if defined(ISP_12160) || defined(ISP_12160_IT) 77 #include <dev/ispfw/asm_12160.h> 78 #endif 79 #if defined(ISP_2100) 80 #include <dev/ispfw/asm_2100.h> 81 #endif 82 #if defined(ISP_2200) 83 #include <dev/ispfw/asm_2200.h> 84 #endif 85 #if defined(ISP_2300) 86 #include <dev/ispfw/asm_2300.h> 87 #endif 88 #if defined(ISP_2322) 89 #include <dev/ispfw/asm_2322.h> 90 #endif 91 #if defined(ISP_2400) || defined(ISP_2400_MULTI) 92 #include <dev/ispfw/asm_2400.h> 93 #endif 94 #if defined(ISP_2500) || defined(ISP_2500_MULTI) 95 #include <dev/ispfw/asm_2500.h> 96 #endif 97 98 #if defined(ISP_1000) 99 static int isp_1000_loaded; 100 #endif 101 #if defined(ISP_1040) 102 static int isp_1040_loaded; 103 #endif 104 #if defined(ISP_1040_IT) 105 static int isp_1040_it_loaded; 106 #endif 107 #if defined(ISP_1080) 108 static int isp_1080_loaded; 109 #endif 110 #if defined(ISP_1080_IT) 111 static int isp_1080_it_loaded; 112 #endif 113 #if defined(ISP_12160) 114 static int isp_12160_loaded; 115 #endif 116 #if defined(ISP_12160_IT) 117 static int isp_12160_it_loaded; 118 #endif 119 #if defined(ISP_2100) 120 static int isp_2100_loaded; 121 #endif 122 #if defined(ISP_2200) 123 static int isp_2200_loaded; 124 #endif 125 #if defined(ISP_2300) 126 static int isp_2300_loaded; 127 #endif 128 #if defined(ISP_2322) 129 static int isp_2322_loaded; 130 #endif 131 #if defined(ISP_2400) 132 static int isp_2400_loaded; 133 #endif 134 #if defined(ISP_2400_MULTI) 135 static int isp_2400_multi_loaded; 136 #endif 137 #if defined(ISP_2500) 138 static int isp_2500_loaded; 139 #endif 140 #if defined(ISP_2500_MULTI) 141 static int isp_2500_multi_loaded; 142 #endif 143 144 #define ISPFW_VERSION 1 145 #define RMACRO(token) do { \ 146 if (token##_loaded) \ 147 break; \ 148 if (firmware_register(#token, token##_risc_code, \ 149 token##_risc_code[3] * sizeof(token##_risc_code[3]), \ 150 ISPFW_VERSION, NULL) == NULL) { \ 151 printf("%s: unable to register firmware <%s>\n", \ 152 MODULE_NAME, #token); \ 153 break; \ 154 } \ 155 token##_loaded++; \ 156 printf("%s: registered firmware <%s>\n", MODULE_NAME, #token); \ 157 } while (0) 158 159 #define UMACRO(token) do { \ 160 if (!token##_loaded) \ 161 break; \ 162 if (firmware_unregister(#token) != 0) { \ 163 printf("%s: unable to unregister firmware <%s>\n", \ 164 MODULE_NAME, #token); \ 165 break; \ 166 } \ 167 token##_loaded--; \ 168 printf("%s: unregistered firmware <%s>\n", MODULE_NAME, #token);\ 169 } while (0) 170 171 static void 172 do_load_fw(void) 173 { 174 175 #if defined(ISP_1000) 176 RMACRO(isp_1000); 177 #endif 178 #if defined(ISP_1040) 179 RMACRO(isp_1040); 180 #endif 181 #if defined(ISP_1040_IT) 182 RMACRO(isp_1040_it); 183 #endif 184 #if defined(ISP_1080) 185 RMACRO(isp_1080); 186 #endif 187 #if defined(ISP_1080_IT) 188 RMACRO(isp_1080_it); 189 #endif 190 #if defined(ISP_12160) 191 RMACRO(isp_12160); 192 #endif 193 #if defined(ISP_12160_IT) 194 RMACRO(isp_12160_it); 195 #endif 196 #if defined(ISP_2100) 197 RMACRO(isp_2100); 198 #endif 199 #if defined(ISP_2200) 200 RMACRO(isp_2200); 201 #endif 202 #if defined(ISP_2300) 203 RMACRO(isp_2300); 204 #endif 205 #if defined(ISP_2322) 206 RMACRO(isp_2322); 207 #endif 208 #if defined(ISP_2400) 209 RMACRO(isp_2400); 210 #endif 211 #if defined(ISP_2400_MULTI) 212 RMACRO(isp_2400_multi); 213 #endif 214 #if defined(ISP_2500) 215 RMACRO(isp_2500); 216 #endif 217 #if defined(ISP_2500_MULTI) 218 RMACRO(isp_2500_multi); 219 #endif 220 } 221 222 static void 223 do_unload_fw(void) 224 { 225 226 #if defined(ISP_1000) 227 UMACRO(isp_1000); 228 #endif 229 #if defined(ISP_1040) 230 UMACRO(isp_1040); 231 #endif 232 #if defined(ISP_1040_IT) 233 UMACRO(isp_1040_it); 234 #endif 235 #if defined(ISP_1080) 236 UMACRO(isp_1080); 237 #endif 238 #if defined(ISP_1080_IT) 239 UMACRO(isp_1080_it); 240 #endif 241 #if defined(ISP_12160) 242 UMACRO(isp_12160); 243 #endif 244 #if defined(ISP_12160_IT) 245 UMACRO(isp_12160_it); 246 #endif 247 #if defined(ISP_2100) 248 UMACRO(isp_2100); 249 #endif 250 #if defined(ISP_2200) 251 UMACRO(isp_2200); 252 #endif 253 #if defined(ISP_2300) 254 UMACRO(isp_2300); 255 #endif 256 #if defined(ISP_2322) 257 UMACRO(isp_2322); 258 #endif 259 #if defined(ISP_2400) 260 UMACRO(isp_2400); 261 #endif 262 #if defined(ISP_2400_MULTI) 263 UMACRO(isp_2400_multi); 264 #endif 265 #if defined(ISP_2500) 266 UMACRO(isp_2500); 267 #endif 268 #if defined(ISP_2500_MULTI) 269 UMACRO(isp_2500_multi); 270 #endif 271 } 272 273 static int 274 module_handler(module_t mod, int what, void *arg) 275 { 276 277 switch (what) { 278 case MOD_LOAD: 279 do_load_fw(); 280 break; 281 case MOD_UNLOAD: 282 do_unload_fw(); 283 break; 284 case MOD_SHUTDOWN: 285 break; 286 default: 287 return (EOPNOTSUPP); 288 } 289 return (0); 290 } 291 static moduledata_t ispfw_mod = { 292 MODULE_NAME, module_handler, NULL 293 }; 294 #if defined(ISP_ALL) || !defined(KLD_MODULE) 295 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 296 #elif defined(ISP_1000) 297 DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 298 #elif defined(ISP_1040) 299 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 300 #elif defined(ISP_1040_IT) 301 DECLARE_MODULE(isp_1040_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 302 #elif defined(ISP_1080) 303 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 304 #elif defined(ISP_1080_IT) 305 DECLARE_MODULE(isp_1080_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 306 #elif defined(ISP_12160) 307 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 308 #elif defined(ISP_12160_IT) 309 DECLARE_MODULE(isp_12160_IT, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 310 #elif defined(ISP_2100) 311 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 312 #elif defined(ISP_2200) 313 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 314 #elif defined(ISP_2300) 315 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 316 #elif defined(ISP_2322) 317 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 318 #elif defined(ISP_2400) 319 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 320 #elif defined(ISP_2400_MULTI) 321 DECLARE_MODULE(isp_2400_multi, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 322 #elif defined(ISP_2500) 323 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 324 #elif defined(ISP_2500_MULTI) 325 DECLARE_MODULE(isp_2500_multi, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 326 #else 327 #error "firmware not specified" 328 #endif 329