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