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/param.h> 32 #include <sys/firmware.h> 33 #include <sys/kernel.h> 34 #include <sys/linker.h> 35 #include <sys/module.h> 36 #include <sys/systm.h> 37 38 #if defined(ISP_ALL) || !defined(KLD_MODULE) 39 #define ISP_2400 1 40 #define ISP_2500 1 41 #endif 42 43 #ifndef MODULE_NAME 44 #define MODULE_NAME "ispfw" 45 #endif 46 47 #if defined(ISP_2400) 48 #include <dev/ispfw/asm_2400.h> 49 #endif 50 #if defined(ISP_2500) 51 #include <dev/ispfw/asm_2500.h> 52 #endif 53 54 #if defined(ISP_2400) 55 static int isp_2400_loaded; 56 #endif 57 #if defined(ISP_2500) 58 static int isp_2500_loaded; 59 #endif 60 61 #define ISPFW_VERSION 1 62 63 #define RMACRO(token) do { \ 64 if (token##_loaded) \ 65 break; \ 66 if (firmware_register(#token, token##_risc_code, \ 67 token##_risc_code[3] * sizeof(token##_risc_code[3]), \ 68 ISPFW_VERSION, NULL) == NULL) \ 69 break; \ 70 token##_loaded++; \ 71 } while (0) 72 73 #define UMACRO(token) do { \ 74 if (!token##_loaded) \ 75 break; \ 76 if (firmware_unregister(#token) != 0) { \ 77 error = EBUSY; \ 78 break; \ 79 } \ 80 token##_loaded--; \ 81 } while (0) 82 83 static int 84 do_load_fw(void) 85 { 86 87 #if defined(ISP_2400) 88 RMACRO(isp_2400); 89 #endif 90 #if defined(ISP_2500) 91 RMACRO(isp_2500); 92 #endif 93 return (0); 94 } 95 96 static int 97 do_unload_fw(void) 98 { 99 int error = 0; 100 101 #if defined(ISP_2400) 102 UMACRO(isp_2400); 103 #endif 104 #if defined(ISP_2500) 105 UMACRO(isp_2500); 106 #endif 107 return (error); 108 } 109 110 static int 111 module_handler(module_t mod, int what, void *arg) 112 { 113 114 switch (what) { 115 case MOD_LOAD: 116 return (do_load_fw()); 117 case MOD_UNLOAD: 118 return (do_unload_fw()); 119 } 120 return (EOPNOTSUPP); 121 } 122 static moduledata_t ispfw_mod = { 123 MODULE_NAME, module_handler, NULL 124 }; 125 #if defined(ISP_ALL) || !defined(KLD_MODULE) 126 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 127 #elif defined(ISP_2400) 128 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 129 #elif defined(ISP_2500) 130 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); 131 #else 132 #error "firmware not specified" 133 #endif 134