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 #ifdef __sparc64__
43 #define ISP_1000 1
44 #endif
45 #define ISP_1040 1
46 #define ISP_1040_IT 1
47 #define ISP_1080 1
48 #define ISP_1080_IT 1
49 #define ISP_12160 1
50 #define ISP_12160_IT 1
51 #define ISP_2100 1
52 #define ISP_2200 1
53 #define ISP_2300 1
54 #define ISP_2322 1
55 #define ISP_2400 1
56 #define ISP_2500 1
57 #endif
58
59 #ifndef MODULE_NAME
60 #define MODULE_NAME "ispfw"
61 #endif
62
63 #if defined(ISP_1000)
64 #ifdef __sparc64__
65 #include <dev/ispfw/asm_1000.h>
66 #else
67 #error "firmware not compatible with this platform"
68 #endif
69 #endif
70 #if defined(ISP_1040) || defined(ISP_1040_IT)
71 #include <dev/ispfw/asm_1040.h>
72 #endif
73 #if defined(ISP_1080) || defined(ISP_1080_IT)
74 #include <dev/ispfw/asm_1080.h>
75 #endif
76 #if defined(ISP_12160) || defined(ISP_12160_IT)
77 #include <dev/ispfw/asm_12160.h>
78 #endif
79 #if defined(ISP_2100)
80 #include <dev/ispfw/asm_2100.h>
81 #endif
82 #if defined(ISP_2200)
83 #include <dev/ispfw/asm_2200.h>
84 #endif
85 #if defined(ISP_2300)
86 #include <dev/ispfw/asm_2300.h>
87 #endif
88 #if defined(ISP_2322)
89 #include <dev/ispfw/asm_2322.h>
90 #endif
91 #if defined(ISP_2400)
92 #include <dev/ispfw/asm_2400.h>
93 #endif
94 #if defined(ISP_2500)
95 #include <dev/ispfw/asm_2500.h>
96 #endif
97
98 #if defined(ISP_1000)
99 static int isp_1000_loaded;
100 #endif
101 #if defined(ISP_1040)
102 static int isp_1040_loaded;
103 #endif
104 #if defined(ISP_1080)
105 static int isp_1080_loaded;
106 #endif
107 #if defined(ISP_12160)
108 static int isp_12160_loaded;
109 #endif
110 #if defined(ISP_2100)
111 static int isp_2100_loaded;
112 #endif
113 #if defined(ISP_2200)
114 static int isp_2200_loaded;
115 #endif
116 #if defined(ISP_2300)
117 static int isp_2300_loaded;
118 #endif
119 #if defined(ISP_2322)
120 static int isp_2322_loaded;
121 #endif
122 #if defined(ISP_2400)
123 static int isp_2400_loaded;
124 #endif
125 #if defined(ISP_2500)
126 static int isp_2500_loaded;
127 #endif
128
129 #define ISPFW_VERSION 1
130
131 #define RMACRO(token) do { \
132 if (token##_loaded) \
133 break; \
134 if (firmware_register(#token, token##_risc_code, \
135 token##_risc_code[3] * sizeof(token##_risc_code[3]), \
136 ISPFW_VERSION, NULL) == NULL) \
137 break; \
138 token##_loaded++; \
139 } while (0)
140
141 #define UMACRO(token) do { \
142 if (!token##_loaded) \
143 break; \
144 if (firmware_unregister(#token) != 0) { \
145 error = EBUSY; \
146 break; \
147 } \
148 token##_loaded--; \
149 } while (0)
150
151 static int
do_load_fw(void)152 do_load_fw(void)
153 {
154
155 #if defined(ISP_1000)
156 RMACRO(isp_1000);
157 #endif
158 #if defined(ISP_1040)
159 RMACRO(isp_1040);
160 #endif
161 #if defined(ISP_1080)
162 RMACRO(isp_1080);
163 #endif
164 #if defined(ISP_12160)
165 RMACRO(isp_12160);
166 #endif
167 #if defined(ISP_2100)
168 RMACRO(isp_2100);
169 #endif
170 #if defined(ISP_2200)
171 RMACRO(isp_2200);
172 #endif
173 #if defined(ISP_2300)
174 RMACRO(isp_2300);
175 #endif
176 #if defined(ISP_2322)
177 RMACRO(isp_2322);
178 #endif
179 #if defined(ISP_2400)
180 RMACRO(isp_2400);
181 #endif
182 #if defined(ISP_2500)
183 RMACRO(isp_2500);
184 #endif
185 return (0);
186 }
187
188 static int
do_unload_fw(void)189 do_unload_fw(void)
190 {
191 int error = 0;
192
193 #if defined(ISP_1000)
194 UMACRO(isp_1000);
195 #endif
196 #if defined(ISP_1040)
197 UMACRO(isp_1040);
198 #endif
199 #if defined(ISP_1080)
200 UMACRO(isp_1080);
201 #endif
202 #if defined(ISP_12160)
203 UMACRO(isp_12160);
204 #endif
205 #if defined(ISP_2100)
206 UMACRO(isp_2100);
207 #endif
208 #if defined(ISP_2200)
209 UMACRO(isp_2200);
210 #endif
211 #if defined(ISP_2300)
212 UMACRO(isp_2300);
213 #endif
214 #if defined(ISP_2322)
215 UMACRO(isp_2322);
216 #endif
217 #if defined(ISP_2400)
218 UMACRO(isp_2400);
219 #endif
220 #if defined(ISP_2500)
221 UMACRO(isp_2500);
222 #endif
223 return (error);
224 }
225
226 static int
module_handler(module_t mod,int what,void * arg)227 module_handler(module_t mod, int what, void *arg)
228 {
229
230 switch (what) {
231 case MOD_LOAD:
232 return (do_load_fw());
233 case MOD_UNLOAD:
234 return (do_unload_fw());
235 }
236 return (EOPNOTSUPP);
237 }
238 static moduledata_t ispfw_mod = {
239 MODULE_NAME, module_handler, NULL
240 };
241 #if defined(ISP_ALL) || !defined(KLD_MODULE)
242 DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
243 #elif defined(ISP_1000)
244 DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
245 #elif defined(ISP_1040)
246 DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
247 #elif defined(ISP_1080)
248 DECLARE_MODULE(isp_1080, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
249 #elif defined(ISP_12160)
250 DECLARE_MODULE(isp_12160, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
251 #elif defined(ISP_2100)
252 DECLARE_MODULE(isp_2100, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
253 #elif defined(ISP_2200)
254 DECLARE_MODULE(isp_2200, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
255 #elif defined(ISP_2300)
256 DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
257 #elif defined(ISP_2322)
258 DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
259 #elif defined(ISP_2400)
260 DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
261 #elif defined(ISP_2500)
262 DECLARE_MODULE(isp_2500, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD);
263 #else
264 #error "firmware not specified"
265 #endif
266