1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 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 #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 #define ISP_2400 1 41 #define ISP_2500 1 42 #define ISP_2600 1 43 #define ISP_2700 1 44 #define ISP_2800 1 45 #endif 46 47 #ifndef MODULE_NAME 48 #define MODULE_NAME "ispfw" 49 #endif 50 51 #if defined(ISP_2400) 52 #include <dev/ispfw/asm_2400.h> 53 #endif 54 #if defined(ISP_2500) 55 #include <dev/ispfw/asm_2500.h> 56 #endif 57 #if defined(ISP_2600) 58 #include <dev/ispfw/asm_2600.h> 59 #endif 60 #if defined(ISP_2700) 61 #include <dev/ispfw/asm_2700.h> 62 #endif 63 #if defined(ISP_2800) 64 #include <dev/ispfw/asm_2800.h> 65 #endif 66 67 #if defined(ISP_2400) 68 static int isp_2400_loaded; 69 #endif 70 #if defined(ISP_2500) 71 static int isp_2500_loaded; 72 #endif 73 #if defined(ISP_2600) 74 static int isp_2600_loaded; 75 #endif 76 #if defined(ISP_2700) 77 static int isp_2700_loaded; 78 #endif 79 #if defined(ISP_2800) 80 static int isp_2800_loaded; 81 #endif 82 83 #define ISPFW_VERSION 1 84 85 #define RMACRO(token) do { \ 86 if (token##_loaded) \ 87 break; \ 88 if (firmware_register(#token, token##_risc_code, \ 89 token##_risc_code[3] * sizeof(token##_risc_code[3]), \ 90 ISPFW_VERSION, NULL) == NULL) \ 91 break; \ 92 token##_loaded++; \ 93 } while (0) 94 95 #define UMACRO(token) do { \ 96 if (!token##_loaded) \ 97 break; \ 98 if (firmware_unregister(#token) != 0) { \ 99 error = EBUSY; \ 100 break; \ 101 } \ 102 token##_loaded--; \ 103 } while (0) 104 105 static int 106 do_load_fw(void) 107 { 108 109 #if defined(ISP_2400) 110 RMACRO(isp_2400); 111 #endif 112 #if defined(ISP_2500) 113 RMACRO(isp_2500); 114 #endif 115 #if defined(ISP_2600) 116 RMACRO(isp_2600); 117 #endif 118 #if defined(ISP_2700) 119 RMACRO(isp_2700); 120 #endif 121 #if defined(ISP_2800) 122 RMACRO(isp_2800); 123 #endif 124 return (0); 125 } 126 127 static int 128 do_unload_fw(void) 129 { 130 int error = 0; 131 132 #if defined(ISP_2400) 133 UMACRO(isp_2400); 134 #endif 135 #if defined(ISP_2500) 136 UMACRO(isp_2500); 137 #endif 138 #if defined(ISP_2600) 139 UMACRO(isp_2600); 140 #endif 141 #if defined(ISP_2700) 142 UMACRO(isp_2700); 143 #endif 144 #if defined(ISP_2800) 145 UMACRO(isp_2800); 146 #endif 147 return (error); 148 } 149 150 static int 151 module_handler(module_t mod, int what, void *arg) 152 { 153 154 switch (what) { 155 case MOD_LOAD: 156 return (do_load_fw()); 157 case MOD_UNLOAD: 158 return (do_unload_fw()); 159 } 160 return (EOPNOTSUPP); 161 } 162 static moduledata_t ispfw_mod = { 163 MODULE_NAME, module_handler, NULL 164 }; 165 #if defined(ISP_ALL) || !defined(KLD_MODULE) 166 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 167 #elif defined(ISP_2400) 168 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 169 #elif defined(ISP_2500) 170 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 171 #elif defined(ISP_2600) 172 DECLARE_MODULE(isp_2600, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 173 #elif defined(ISP_2700) 174 DECLARE_MODULE(isp_2700, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 175 #elif defined(ISP_2800) 176 DECLARE_MODULE(isp_2800, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 177 #else 178 #error "firmware not specified" 179 #endif 180