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/kernel.h> 34 #include <sys/module.h> 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/linker.h> 38 #include <sys/firmware.h> 39 40 #if defined(ISP_ALL) || !defined(KLD_MODULE) 41 #define ISP_1040 1 42 #define ISP_1040_IT 1 43 #define ISP_1080 1 44 #define ISP_1080_IT 1 45 #define ISP_12160 1 46 #define ISP_12160_IT 1 47 #define ISP_2100 1 48 #define ISP_2200 1 49 #define ISP_2300 1 50 #define ISP_2322 1 51 #define ISP_2400 1 52 #ifdef __sparc64__ 53 #define ISP_1000 1 54 #endif 55 #define MODULE_NAME "ispfw" 56 #endif 57 58 #if defined(ISP_1040) || defined(ISP_1040_IT) 59 #include <dev/ispfw/asm_1040.h> 60 #endif 61 #if defined(ISP_1080) || defined(ISP_1080_IT) 62 #include <dev/ispfw/asm_1080.h> 63 #endif 64 #if defined(ISP_12160) || defined(ISP_12160_IT) 65 #include <dev/ispfw/asm_12160.h> 66 #endif 67 #if defined(ISP_2100) 68 #include <dev/ispfw/asm_2100.h> 69 #endif 70 #if defined(ISP_2200) 71 #include <dev/ispfw/asm_2200.h> 72 #endif 73 #if defined(ISP_2300) 74 #include <dev/ispfw/asm_2300.h> 75 #endif 76 #if defined(ISP_2322) 77 #include <dev/ispfw/asm_2322.h> 78 #endif 79 #if defined(ISP_2400) 80 #include <dev/ispfw/asm_2400.h> 81 #endif 82 #if defined(ISP_1000) 83 #include <dev/ispfw/asm_1000.h> 84 #endif 85 86 #define ISPFW_VERSION 1 87 #define RMACRO(token) \ 88 if (firmware_register(#token, token##_risc_code, \ 89 token##_risc_code [3] * sizeof token##_risc_code [3], \ 90 ISPFW_VERSION, NULL) == NULL) { \ 91 printf("unable to register firmware '%s'\n", #token); \ 92 } else { \ 93 printf("registered firmware set <%s>\n", #token); \ 94 } 95 96 #define UMACRO(token) \ 97 firmware_unregister(#token); \ 98 printf("unregistered firmware set <%s>\n", #token); 99 100 static int 101 do_load_fw(void) 102 { 103 #if defined(ISP_1000) 104 RMACRO(isp_1000); 105 #endif 106 #if defined(ISP_1040) 107 RMACRO(isp_1040); 108 #endif 109 #if defined(ISP_1040_IT) 110 RMACRO(isp_1040_it); 111 #endif 112 #if defined(ISP_1080) 113 RMACRO(isp_1080); 114 #endif 115 #if defined(ISP_1080_IT) 116 RMACRO(isp_1080_it); 117 #endif 118 #if defined(ISP_12160) 119 RMACRO(isp_12160); 120 #endif 121 #if defined(ISP_12160_IT) 122 RMACRO(isp_12160_it); 123 #endif 124 #if defined(ISP_2100) 125 RMACRO(isp_2100); 126 #endif 127 #if defined(ISP_2200) 128 RMACRO(isp_2200); 129 #endif 130 #if defined(ISP_2300) 131 RMACRO(isp_2300); 132 #endif 133 #if defined(ISP_2322) 134 RMACRO(isp_2322); 135 #endif 136 #if defined(ISP_2400) 137 RMACRO(isp_2400); 138 #endif 139 return (0); 140 } 141 142 static int 143 do_unload_fw(void) 144 { 145 #if defined(ISP_1000) 146 UMACRO(isp_1000); 147 #elif defined(ISP_1040) 148 UMACRO(isp_1040); 149 #elif defined(ISP_1040_IT) 150 UMACRO(isp_1040_it); 151 #elif defined(ISP_1080) 152 UMACRO(isp_1080); 153 #elif defined(ISP_1080_IT) 154 UMACRO(isp_1080_it); 155 #elif defined(ISP_12160) 156 UMACRO(isp_12160); 157 #elif defined(ISP_12160_IT) 158 UMACRO(isp_12160_it); 159 #elif defined(ISP_2100) 160 UMACRO(isp_2100); 161 #elif defined(ISP_2200) 162 UMACRO(isp_2200); 163 #elif defined(ISP_2300) 164 UMACRO(isp_2300); 165 #elif defined(ISP_2322) 166 UMACRO(isp_2322); 167 #elif defined(ISP_2400) 168 UMACRO(isp_2400); 169 #endif 170 return (0); 171 } 172 173 static int 174 module_handler(module_t mod, int what, void *arg) 175 { 176 int r; 177 switch (what) { 178 case MOD_LOAD: 179 r = do_load_fw(); 180 break; 181 case MOD_UNLOAD: 182 r = do_unload_fw(); 183 break; 184 default: 185 r = EOPNOTSUPP; 186 break; 187 } 188 return (r); 189 } 190 static moduledata_t ispfw_mod = { 191 MODULE_NAME, module_handler, NULL 192 }; 193 #ifndef KLD_MODULE 194 DECLARE_MODULE(isp, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 195 #else 196 #if defined(ISP_1000) 197 DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 198 #elif defined(ISP_1040) 199 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 200 #elif defined(ISP_1040_IT) 201 DECLARE_MODULE(isp_1040_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 202 #elif defined(ISP_1080) 203 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 204 #elif defined(ISP_1080_IT) 205 DECLARE_MODULE(isp_1080_it, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 206 #elif defined(ISP_12160) 207 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 208 #elif defined(ISP_12160_IT) 209 DECLARE_MODULE(isp_12160_IT, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 210 #elif defined(ISP_2100) 211 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 212 #elif defined(ISP_2200) 213 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 214 #elif defined(ISP_2300) 215 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 216 #elif defined(ISP_2322) 217 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 218 #elif defined(ISP_2400) 219 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 220 #endif 221 #endif 222