module.h revision 289644
1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5270710Shselasky * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. 6219820Sjeff * All rights reserved. 7219820Sjeff * 8219820Sjeff * Redistribution and use in source and binary forms, with or without 9219820Sjeff * modification, are permitted provided that the following conditions 10219820Sjeff * are met: 11219820Sjeff * 1. Redistributions of source code must retain the above copyright 12219820Sjeff * notice unmodified, this list of conditions, and the following 13219820Sjeff * disclaimer. 14219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15219820Sjeff * notice, this list of conditions and the following disclaimer in the 16219820Sjeff * documentation and/or other materials provided with the distribution. 17219820Sjeff * 18219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28289644Shselasky * 29289644Shselasky * $FreeBSD: head/sys/ofed/include/linux/module.h 289644 2015-10-20 19:08:26Z hselasky $ 30219820Sjeff */ 31219820Sjeff#ifndef _LINUX_MODULE_H_ 32219820Sjeff#define _LINUX_MODULE_H_ 33219820Sjeff 34277402Shselasky#include <sys/cdefs.h> 35277402Shselasky#include <sys/types.h> 36277402Shselasky#include <sys/module.h> 37277402Shselasky 38219820Sjeff#include <linux/list.h> 39219820Sjeff#include <linux/compiler.h> 40219820Sjeff#include <linux/kobject.h> 41219820Sjeff#include <linux/moduleparam.h> 42219820Sjeff#include <linux/slab.h> 43219820Sjeff 44219820Sjeff#define MODULE_AUTHOR(name) 45219820Sjeff#define MODULE_DESCRIPTION(name) 46219820Sjeff#define MODULE_LICENSE(name) 47219820Sjeff 48219820Sjeff#define THIS_MODULE ((struct module *)0) 49219820Sjeff 50219820Sjeff#define EXPORT_SYMBOL(name) 51219820Sjeff#define EXPORT_SYMBOL_GPL(name) 52219820Sjeff 53268316Shselasky/* OFED pre-module initialization */ 54275636Shselasky#define SI_SUB_OFED_PREINIT (SI_SUB_ROOT_CONF - 2) 55268316Shselasky/* OFED default module initialization */ 56275636Shselasky#define SI_SUB_OFED_MODINIT (SI_SUB_ROOT_CONF - 1) 57268316Shselasky 58219820Sjeff#include <sys/linker.h> 59219820Sjeff 60219820Sjeffstatic inline void 61219820Sjeff_module_run(void *arg) 62219820Sjeff{ 63219820Sjeff void (*fn)(void); 64219820Sjeff#ifdef OFED_DEBUG_INIT 65219820Sjeff char name[1024]; 66219820Sjeff caddr_t pc; 67219820Sjeff long offset; 68219820Sjeff 69219820Sjeff pc = (caddr_t)arg; 70219820Sjeff if (linker_search_symbol_name(pc, name, sizeof(name), &offset) != 0) 71219820Sjeff printf("Running ??? (%p)\n", pc); 72219820Sjeff else 73219820Sjeff printf("Running %s (%p)\n", name, pc); 74219820Sjeff#endif 75219820Sjeff fn = arg; 76219820Sjeff DROP_GIANT(); 77219820Sjeff fn(); 78219820Sjeff PICKUP_GIANT(); 79219820Sjeff} 80219820Sjeff 81219820Sjeff#define module_init(fn) \ 82268316Shselasky SYSINIT(fn, SI_SUB_OFED_MODINIT, SI_ORDER_FIRST, _module_run, (fn)) 83219820Sjeff 84270710Shselasky#define module_exit(fn) \ 85270710Shselasky SYSUNINIT(fn, SI_SUB_OFED_MODINIT, SI_ORDER_SECOND, _module_run, (fn)) 86270710Shselasky 87219820Sjeff/* 88270710Shselasky * The following two macros are a workaround for not having a module 89270710Shselasky * load and unload order resolver: 90219820Sjeff */ 91219820Sjeff#define module_init_order(fn, order) \ 92268316Shselasky SYSINIT(fn, SI_SUB_OFED_MODINIT, (order), _module_run, (fn)) 93219820Sjeff 94270710Shselasky#define module_exit_order(fn, order) \ 95270710Shselasky SYSUNINIT(fn, SI_SUB_OFED_MODINIT, (order), _module_run, (fn)) 96219820Sjeff 97219820Sjeff#define module_get(module) 98219820Sjeff#define module_put(module) 99219820Sjeff#define try_module_get(module) 1 100219820Sjeff 101219820Sjeff#endif /* _LINUX_MODULE_H_ */ 102