diff options
-rw-r--r-- | sys/dev/ispfw/ispfw.c | 150 |
1 files changed, 109 insertions, 41 deletions
diff --git a/sys/dev/ispfw/ispfw.c b/sys/dev/ispfw/ispfw.c index eb19cba..143aad8 100644 --- a/sys/dev/ispfw/ispfw.c +++ b/sys/dev/ispfw/ispfw.c @@ -30,14 +30,16 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> +#include <sys/firmware.h> #include <sys/kernel.h> +#include <sys/linker.h> #include <sys/module.h> -#include <sys/param.h> #include <sys/systm.h> -#include <sys/linker.h> -#include <sys/firmware.h> #if defined(ISP_ALL) || !defined(KLD_MODULE) +#ifdef __sparc64__ +#define ISP_1000 1 +#endif #define ISP_1040 1 #define ISP_1040_IT 1 #define ISP_1080 1 @@ -49,12 +51,19 @@ __FBSDID("$FreeBSD$"); #define ISP_2300 1 #define ISP_2322 1 #define ISP_2400 1 -#ifdef __sparc64__ -#define ISP_1000 1 #endif + +#ifndef MODULE_NAME #define MODULE_NAME "ispfw" #endif +#if defined(ISP_1000) +#ifdef __sparc64__ +#include <dev/ispfw/asm_1000.h> +#else +#error "firmware not compatible with this platform" +#endif +#endif #if defined(ISP_1040) || defined(ISP_1040_IT) #include <dev/ispfw/asm_1040.h> #endif @@ -79,27 +88,75 @@ __FBSDID("$FreeBSD$"); #if defined(ISP_2400) #include <dev/ispfw/asm_2400.h> #endif + #if defined(ISP_1000) -#include <dev/ispfw/asm_1000.h> +static int isp_1000_loaded; +#endif +#if defined(ISP_1040) +static int isp_1040_loaded; +#endif +#if defined(ISP_1040_IT) +static int isp_1040_it_loaded; +#endif +#if defined(ISP_1080) +static int isp_1080_loaded; +#endif +#if defined(ISP_1080_IT) +static int isp_1080_it_loaded; +#endif +#if defined(ISP_12160) +static int isp_12160_loaded; +#endif +#if defined(ISP_12160_IT) +static int isp_12160_it_loaded; +#endif +#if defined(ISP_2100) +static int isp_2100_loaded; +#endif +#if defined(ISP_2200) +static int isp_2200_loaded; +#endif +#if defined(ISP_2300) +static int isp_2300_loaded; +#endif +#if defined(ISP_2322) +static int isp_2322_loaded; +#endif +#if defined(ISP_2400) +static int isp_2400_loaded; #endif #define ISPFW_VERSION 1 -#define RMACRO(token) \ +#define RMACRO(token) do { \ + if (token##_loaded) \ + break; \ if (firmware_register(#token, token##_risc_code, \ - token##_risc_code [3] * sizeof token##_risc_code [3], \ + token##_risc_code[3] * sizeof(token##_risc_code[3]), \ ISPFW_VERSION, NULL) == NULL) { \ - printf("unable to register firmware '%s'\n", #token); \ - } else { \ - printf("registered firmware set <%s>\n", #token); \ - } + printf("%s: unable to register firmware <%s>\n", \ + MODULE_NAME, #token); \ + break; \ + } \ + token##_loaded++; \ + printf("%s: registered firmware <%s>\n", MODULE_NAME, #token); \ +} while (0) -#define UMACRO(token) \ - firmware_unregister(#token); \ - printf("unregistered firmware set <%s>\n", #token); +#define UMACRO(token) do { \ + if (!token##_loaded) \ + break; \ + if (firmware_unregister(#token) != 0) { \ + printf("%s: unable to unregister firmware <%s>\n", \ + MODULE_NAME, #token); \ + break; \ + } \ + token##_loaded--; \ + printf("%s: unregistered firmware <%s>\n", MODULE_NAME, #token);\ +} while (0) -static int +static void do_load_fw(void) { + #if defined(ISP_1000) RMACRO(isp_1000); #endif @@ -136,64 +193,74 @@ do_load_fw(void) #if defined(ISP_2400) RMACRO(isp_2400); #endif - return (0); } -static int +static void do_unload_fw(void) { + #if defined(ISP_1000) UMACRO(isp_1000); -#elif defined(ISP_1040) +#endif +#if defined(ISP_1040) UMACRO(isp_1040); -#elif defined(ISP_1040_IT) +#endif +#if defined(ISP_1040_IT) UMACRO(isp_1040_it); -#elif defined(ISP_1080) +#endif +#if defined(ISP_1080) UMACRO(isp_1080); -#elif defined(ISP_1080_IT) +#endif +#if defined(ISP_1080_IT) UMACRO(isp_1080_it); -#elif defined(ISP_12160) +#endif +#if defined(ISP_12160) UMACRO(isp_12160); -#elif defined(ISP_12160_IT) +#endif +#if defined(ISP_12160_IT) UMACRO(isp_12160_it); -#elif defined(ISP_2100) +#endif +#if defined(ISP_2100) UMACRO(isp_2100); -#elif defined(ISP_2200) +#endif +#if defined(ISP_2200) UMACRO(isp_2200); -#elif defined(ISP_2300) +#endif +#if defined(ISP_2300) UMACRO(isp_2300); -#elif defined(ISP_2322) +#endif +#if defined(ISP_2322) UMACRO(isp_2322); -#elif defined(ISP_2400) +#endif +#if defined(ISP_2400) UMACRO(isp_2400); #endif - return (0); } static int module_handler(module_t mod, int what, void *arg) { - int r; + switch (what) { case MOD_LOAD: - r = do_load_fw(); + do_load_fw(); break; case MOD_UNLOAD: - r = do_unload_fw(); + do_unload_fw(); break; - default: - r = EOPNOTSUPP; + case MOD_SHUTDOWN: break; + default: + return (EOPNOTSUPP); } - return (r); + return (0); } static moduledata_t ispfw_mod = { MODULE_NAME, module_handler, NULL }; -#ifndef KLD_MODULE -DECLARE_MODULE(isp, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); -#else -#if defined(ISP_1000) +#if defined(ISP_ALL) || !defined(KLD_MODULE) +DECLARE_MODULE(ispfw, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); +#elif defined(ISP_1000) DECLARE_MODULE(isp_1000, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); #elif defined(ISP_1040) DECLARE_MODULE(isp_1040, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); @@ -217,5 +284,6 @@ DECLARE_MODULE(isp_2300, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); DECLARE_MODULE(isp_2322, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); #elif defined(ISP_2400) DECLARE_MODULE(isp_2400, ispfw_mod, SI_SUB_DRIVERS, SI_ORDER_THIRD); -#endif +#else +#error "firmware not specified" #endif |