lkm.h (5164B)
1 /* 2 * Copyright 2017 Broadcom 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License, version 2, as 6 * published by the Free Software Foundation (the "GPL"). 7 * 8 * This program is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * General Public License version 2 (GPLv2) for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * version 2 (GPLv2) along with this source code. 15 */ 16 /* 17 * $Id: lkm.h,v 1.22 Broadcom SDK $ 18 * $Copyright: (c) 2005 Broadcom Corp. 19 * All Rights Reserved.$ 20 */ 21 22 #ifndef __COMMON_LINUX_KRN_LKM_H__ 23 #define __COMMON_LINUX_KRN_LKM_H__ 24 25 #ifndef __KERNEL__ 26 # define __KERNEL__ 27 #endif 28 #ifndef MODULE 29 # define MODULE 30 #endif 31 32 #include <linux/init.h> 33 #include <linux/version.h> 34 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 35 #include <linux/config.h> 36 #endif 37 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0) 38 #include <linux/kconfig.h> 39 #endif 40 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) 41 #include <linux/slab.h> 42 #endif 43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) 44 #include <linux/smp_lock.h> 45 #endif 46 #include <linux/module.h> 47 48 /* Helper defines for multi-version kernel support */ 49 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 50 #define LKM_2_4 51 #else 52 #define LKM_2_6 53 #endif 54 55 #include <linux/kernel.h> /* printk() */ 56 #include <linux/fs.h> /* everything... */ 57 #include <linux/errno.h> /* error codes */ 58 #include <linux/types.h> /* size_t */ 59 #include <linux/proc_fs.h> 60 #include <linux/fcntl.h> /* O_ACCMODE */ 61 #include <linux/pci.h> 62 #include <linux/interrupt.h> 63 #include <linux/stat.h> 64 #include <linux/sched.h> 65 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0) 66 #include <linux/sched/signal.h> 67 #endif 68 #include <linux/delay.h> 69 70 #include <asm/io.h> 71 #include <asm/hardirq.h> 72 #include <asm/uaccess.h> 73 74 #ifdef CONFIG_DEVFS_FS 75 #include <linux/devfs_fs_kernel.h> 76 #endif 77 78 #define PROC_INTERFACE_KERN_VER_3_10 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)) 79 80 /* Compatibility Macros */ 81 82 #ifdef LKM_2_4 83 84 #include <linux/compatmac.h> 85 #include <linux/wrapper.h> 86 #define LKM_MOD_PARAM(n,ot,nt,d) MODULE_PARM(n,ot) 87 #define LKM_MOD_PARAM_ARRAY(n,ot,nt,c,d) MODULE_PARM(n,ot) 88 #define LKM_EXPORT_SYM(s) 89 #define _free_netdev kfree 90 91 #else /* LKM_2_6 */ 92 93 #define LKM_MOD_PARAM(n,ot,nt,d) module_param(n,nt,d) 94 #define LKM_MOD_PARAM_ARRAY(n,ot,nt,c,d) module_param_array(n,nt,c,d) 95 #define LKM_EXPORT_SYM(s) EXPORT_SYMBOL(s) 96 #define _free_netdev free_netdev 97 98 #endif /* LKM_2_x */ 99 100 #ifndef list_for_each_safe 101 #define list_for_each_safe(l,t,i) t = 0; list_for_each((l),(i)) 102 #endif 103 104 #ifndef reparent_to_init 105 #define reparent_to_init() 106 #endif 107 108 #ifndef MODULE_LICENSE 109 #define MODULE_LICENSE(str) 110 #endif 111 112 #ifndef EXPORT_NO_SYMBOLS 113 #define EXPORT_NO_SYMBOLS 114 #endif 115 116 #ifndef DEFINE_SPINLOCK 117 #define DEFINE_SPINLOCK(_lock) spinlock_t _lock = SPIN_LOCK_UNLOCKED 118 #endif 119 120 #ifndef __SPIN_LOCK_UNLOCKED 121 #define __SPIN_LOCK_UNLOCKED(_lock) SPIN_LOCK_UNLOCKED 122 #endif 123 124 #ifndef lock_kernel 125 #ifdef preempt_disable 126 #define lock_kernel() preempt_disable() 127 #else 128 #define lock_kernel() 129 #endif 130 #endif 131 132 #ifndef unlock_kernel 133 #ifdef preempt_enable 134 #define unlock_kernel() preempt_enable() 135 #else 136 #define unlock_kernel() 137 #endif 138 #endif 139 140 #ifndef init_MUTEX_LOCKED 141 #define init_MUTEX_LOCKED(_sem) sema_init(_sem, 0) 142 #endif 143 144 #ifdef CONFIG_BCM98245 145 #define CONFIG_BMW 146 #endif 147 148 #if PROC_INTERFACE_KERN_VER_3_10 149 #define PROC_CREATE(_entry, _name, _acc, _path, _fops) \ 150 do { \ 151 _entry = proc_create(_name, _acc, _path, _fops); \ 152 } while (0) 153 154 #define PROC_CREATE_DATA(_entry, _name, _acc, _path, _fops, _data) \ 155 do { \ 156 _entry = proc_create_data(_name, _acc, _path, _fops, _data); \ 157 } while (0) 158 159 #define PROC_PDE_DATA(_node) PDE_DATA(_node) 160 161 #else 162 #define PROC_CREATE(_entry, _name, _acc, _path, _fops) \ 163 do { \ 164 _entry = create_proc_entry(_name, _acc, _path); \ 165 if (_entry) { \ 166 _entry->proc_fops = _fops; \ 167 } \ 168 } while (0) 169 170 #define PROC_CREATE_DATA(_entry, _name, _acc, _path, _fops, _data) \ 171 do { \ 172 _entry = create_proc_entry(_name, _acc, _path); \ 173 if (_entry) { \ 174 _entry->proc_fops = _fops; \ 175 _entry->data=_data; \ 176 } \ 177 } while (0) 178 179 #define PROC_PDE_DATA(_node) PROC_I(_node)->pde->data 180 #endif 181 182 #endif /* __COMMON_LINUX_KRN_LKM_H__ */