1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * ISP Firmware Modules for FreeBSD 5 * 6 * Copyright (c) 2000, 2001, 2006 by Matthew Jacob 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice immediately at the beginning of the file, without modification, 14 * this list of conditions, and the following disclaimer. 15 * 2. 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 AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #include <sys/cdefs.h> 32 __FBSDID("$FreeBSD$"); 33 34 #include <sys/param.h> 35 #include <sys/firmware.h> 36 #include <sys/kernel.h> 37 #include <sys/linker.h> 38 #include <sys/module.h> 39 #include <sys/systm.h> 40 41 #if defined(ISP_ALL) || !defined(KLD_MODULE) 42 #define ISP_1040 1 43 #define ISP_1040_IT 1 44 #define ISP_1080 1 45 #define ISP_1080_IT 1 46 #define ISP_12160 1 47 #define ISP_12160_IT 1 48 #define ISP_2100 1 49 #define ISP_2200 1 50 #define ISP_2300 1 51 #define ISP_2322 1 52 #define ISP_2400 1 53 #define ISP_2500 1 54 #endif 55 56 #ifndef MODULE_NAME 57 #define MODULE_NAME "ispfw" 58 #endif 59 60 #if defined(ISP_1040) || defined(ISP_1040_IT) 61 #include <dev/ispfw/asm_1040.h> 62 #endif 63 #if defined(ISP_1080) || defined(ISP_1080_IT) 64 #include <dev/ispfw/asm_1080.h> 65 #endif 66 #if defined(ISP_12160) || defined(ISP_12160_IT) 67 #include <dev/ispfw/asm_12160.h> 68 #endif 69 #if defined(ISP_2100) 70 #include <dev/ispfw/asm_2100.h> 71 #endif 72 #if defined(ISP_2200) 73 #include <dev/ispfw/asm_2200.h> 74 #endif 75 #if defined(ISP_2300) 76 #include <dev/ispfw/asm_2300.h> 77 #endif 78 #if defined(ISP_2322) 79 #include <dev/ispfw/asm_2322.h> 80 #endif 81 #if defined(ISP_2400) 82 #include <dev/ispfw/asm_2400.h> 83 #endif 84 #if defined(ISP_2500) 85 #include <dev/ispfw/asm_2500.h> 86 #endif 87 88 #if defined(ISP_1040) 89 static int isp_1040_loaded; 90 #endif 91 #if defined(ISP_1080) 92 static int isp_1080_loaded; 93 #endif 94 #if defined(ISP_12160) 95 static int isp_12160_loaded; 96 #endif 97 #if defined(ISP_2100) 98 static int isp_2100_loaded; 99 #endif 100 #if defined(ISP_2200) 101 static int isp_2200_loaded; 102 #endif 103 #if defined(ISP_2300) 104 static int isp_2300_loaded; 105 #endif 106 #if defined(ISP_2322) 107 static int isp_2322_loaded; 108 #endif 109 #if defined(ISP_2400) 110 static int isp_2400_loaded; 111 #endif 112 #if defined(ISP_2500) 113 static int isp_2500_loaded; 114 #endif 115 116 #define ISPFW_VERSION 1 117 118 #define RMACRO(token) do { \ 119 if (token##_loaded) \ 120 break; \ 121 if (firmware_register(#token, token##_risc_code, \ 122 token##_risc_code[3] * sizeof(token##_risc_code[3]), \ 123 ISPFW_VERSION, NULL) == NULL) \ 124 break; \ 125 token##_loaded++; \ 126 } while (0) 127 128 #define UMACRO(token) do { \ 129 if (!token##_loaded) \ 130 break; \ 131 if (firmware_unregister(#token) != 0) { \ 132 error = EBUSY; \ 133 break; \ 134 } \ 135 token##_loaded--; \ 136 } while (0) 137 138 static int 139 do_load_fw(void) 140 { 141 142 #if defined(ISP_1040) 143 RMACRO(isp_1040); 144 #endif 145 #if defined(ISP_1080) 146 RMACRO(isp_1080); 147 #endif 148 #if defined(ISP_12160) 149 RMACRO(isp_12160); 150 #endif 151 #if defined(ISP_2100) 152 RMACRO(isp_2100); 153 #endif 154 #if defined(ISP_2200) 155 RMACRO(isp_2200); 156 #endif 157 #if defined(ISP_2300) 158 RMACRO(isp_2300); 159 #endif 160 #if defined(ISP_2322) 161 RMACRO(isp_2322); 162 #endif 163 #if defined(ISP_2400) 164 RMACRO(isp_2400); 165 #endif 166 #if defined(ISP_2500) 167 RMACRO(isp_2500); 168 #endif 169 return (0); 170 } 171 172 static int 173 do_unload_fw(void) 174 { 175 int error = 0; 176 177 #if defined(ISP_1040) 178 UMACRO(isp_1040); 179 #endif 180 #if defined(ISP_1080) 181 UMACRO(isp_1080); 182 #endif 183 #if defined(ISP_12160) 184 UMACRO(isp_12160); 185 #endif 186 #if defined(ISP_2100) 187 UMACRO(isp_2100); 188 #endif 189 #if defined(ISP_2200) 190 UMACRO(isp_2200); 191 #endif 192 #if defined(ISP_2300) 193 UMACRO(isp_2300); 194 #endif 195 #if defined(ISP_2322) 196 UMACRO(isp_2322); 197 #endif 198 #if defined(ISP_2400) 199 UMACRO(isp_2400); 200 #endif 201 #if defined(ISP_2500) 202 UMACRO(isp_2500); 203 #endif 204 return (error); 205 } 206 207 static int 208 module_handler(module_t mod, int what, void *arg) 209 { 210 211 switch (what) { 212 case MOD_LOAD: 213 return (do_load_fw()); 214 case MOD_UNLOAD: 215 return (do_unload_fw()); 216 } 217 return (EOPNOTSUPP); 218 } 219 static moduledata_t ispfw_mod = { 220 MODULE_NAME, module_handler, NULL 221 }; 222 #if defined(ISP_ALL) || !defined(KLD_MODULE) 223 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 224 #elif defined(ISP_1040) 225 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 226 #elif defined(ISP_1080) 227 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 228 #elif defined(ISP_12160) 229 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 230 #elif defined(ISP_2100) 231 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 232 #elif defined(ISP_2200) 233 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 234 #elif defined(ISP_2300) 235 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 236 #elif defined(ISP_2322) 237 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 238 #elif defined(ISP_2400) 239 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 240 #elif defined(ISP_2500) 241 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 242 #else 243 #error "firmware not specified" 244 #endif 245