openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

lkm.h (4635B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  */
      7 
      8 #ifndef __COMMON_LINUX_KRN_LKM_H__
      9 #define __COMMON_LINUX_KRN_LKM_H__
     10 
     11 #ifndef __KERNEL__
     12 #  define __KERNEL__
     13 #endif
     14 #ifndef MODULE
     15 #  define MODULE
     16 #endif
     17 
     18 #include <linux/init.h>
     19 #include <linux/version.h>
     20 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
     21 #include <linux/config.h>
     22 #endif
     23 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0)
     24 #include <linux/kconfig.h>
     25 #endif
     26 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
     27 #include <linux/slab.h>
     28 #endif
     29 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
     30 #include <linux/smp_lock.h>
     31 #endif
     32 #include <linux/module.h>
     33 
     34 /* Helper defines for multi-version kernel  support */
     35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
     36 #define LKM_2_4
     37 #else
     38 #define LKM_2_6
     39 #endif
     40 
     41 #include <linux/kernel.h>   /* printk() */
     42 #include <linux/fs.h>       /* everything... */
     43 #include <linux/errno.h>    /* error codes */
     44 #include <linux/types.h>    /* size_t */
     45 #include <linux/proc_fs.h>
     46 #include <linux/fcntl.h>    /* O_ACCMODE */
     47 #include <linux/pci.h>
     48 #include <linux/interrupt.h>
     49 #include <linux/stat.h>
     50 #include <linux/sched.h>
     51 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
     52 #include <linux/sched/signal.h>
     53 #endif
     54 #include <linux/delay.h>
     55 
     56 #include <asm/io.h>
     57 #include <asm/hardirq.h>
     58 #include <asm/uaccess.h>
     59 
     60 #ifdef CONFIG_DEVFS_FS
     61 #include <linux/devfs_fs_kernel.h>
     62 #endif
     63 
     64 #define PROC_INTERFACE_KERN_VER_3_10 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
     65 
     66 /* Compatibility Macros */
     67 
     68 #ifdef LKM_2_4
     69 
     70 #include <linux/compatmac.h>
     71 #include <linux/wrapper.h>
     72 #define LKM_MOD_PARAM(n,ot,nt,d) MODULE_PARM(n,ot)
     73 #define LKM_MOD_PARAM_ARRAY(n,ot,nt,c,d) MODULE_PARM(n,ot)
     74 #define LKM_EXPORT_SYM(s)
     75 #define _free_netdev kfree
     76 
     77 #else /* LKM_2_6 */
     78 
     79 #define LKM_MOD_PARAM(n,ot,nt,d) module_param(n,nt,d)
     80 #define LKM_MOD_PARAM_ARRAY(n,ot,nt,c,d) module_param_array(n,nt,c,d)
     81 #define LKM_EXPORT_SYM(s) EXPORT_SYMBOL(s)
     82 #define _free_netdev free_netdev
     83 
     84 #endif /* LKM_2_x */
     85 
     86 #ifndef list_for_each_safe
     87 #define list_for_each_safe(l,t,i) t = 0; list_for_each((l),(i))
     88 #endif
     89 
     90 #ifndef reparent_to_init
     91 #define reparent_to_init()
     92 #endif
     93 
     94 #ifndef MODULE_LICENSE
     95 #define MODULE_LICENSE(str)
     96 #endif
     97 
     98 #ifndef EXPORT_NO_SYMBOLS
     99 #define EXPORT_NO_SYMBOLS
    100 #endif
    101 
    102 #ifndef DEFINE_SPINLOCK
    103 #define DEFINE_SPINLOCK(_lock) spinlock_t _lock = SPIN_LOCK_UNLOCKED
    104 #endif
    105 
    106 #ifndef __SPIN_LOCK_UNLOCKED
    107 #define __SPIN_LOCK_UNLOCKED(_lock) SPIN_LOCK_UNLOCKED
    108 #endif
    109 
    110 #ifndef lock_kernel
    111 #ifdef preempt_disable
    112 #define lock_kernel() preempt_disable()
    113 #else
    114 #define lock_kernel()
    115 #endif
    116 #endif
    117 
    118 #ifndef unlock_kernel
    119 #ifdef preempt_enable
    120 #define unlock_kernel() preempt_enable()
    121 #else
    122 #define unlock_kernel()
    123 #endif
    124 #endif
    125 
    126 #ifndef init_MUTEX_LOCKED
    127 #define init_MUTEX_LOCKED(_sem) sema_init(_sem, 0)
    128 #endif
    129 
    130 #ifdef CONFIG_BCM98245
    131 #define CONFIG_BMW
    132 #endif
    133 
    134 #if PROC_INTERFACE_KERN_VER_3_10
    135 #define PROC_CREATE(_entry, _name, _acc, _path, _fops)                  \
    136     do {                                                                \
    137         _entry = proc_create(_name, _acc, _path, _fops);                \
    138     } while (0)
    139 
    140 #define PROC_CREATE_DATA(_entry, _name, _acc, _path, _fops, _data)      \
    141     do {                                                                \
    142         _entry = proc_create_data(_name, _acc, _path, _fops, _data);    \
    143     } while (0)
    144 
    145 #define PROC_PDE_DATA(_node) PDE_DATA(_node)
    146 
    147 #else
    148 #define PROC_CREATE(_entry, _name, _acc, _path, _fops)                  \
    149     do {                                                                \
    150         _entry = create_proc_entry(_name, _acc, _path);                 \
    151         if (_entry) {                                                   \
    152             _entry->proc_fops = _fops;                                  \
    153         }                                                               \
    154     } while (0)
    155 
    156 #define PROC_CREATE_DATA(_entry, _name, _acc, _path, _fops, _data)      \
    157     do {                                                                \
    158         _entry = create_proc_entry(_name, _acc, _path);                 \
    159         if (_entry) {                                                   \
    160             _entry->proc_fops = _fops;                                  \
    161             _entry->data=_data;                                         \
    162         }                                                               \
    163     } while (0)
    164 
    165 #define PROC_PDE_DATA(_node) PROC_I(_node)->pde->data
    166 #endif
    167 
    168 #endif /* __COMMON_LINUX_KRN_LKM_H__ */