1 /* @file plustek-pp_sysdep.h 2 * @brief a trial to centralize changes between the different 3 * kernel-versions some stuff is maybe not relevant, but anyway... 4 * 5 * Copyright (C) 2000-2013 Gerhard Jaeger <gerhard@gjaeger.de> 6 * 7 * History: 8 * 0.30 - initial version 9 * 0.38 - added this header 10 * 0.39 - added kernel 2.4 stuff 11 * 0.40 - added slab.h/malloc.h stuff for kernel >= 2.4.17 12 * 0.41 - no changes 13 * 0.42 - added _GET_TIME 14 * - added LINUX_26 for new kernel 15 * - added _MINOR 16 * 0.43 - added class functions 17 * 0.44 - added support for kernel >= 2.6.35 and 3.x 18 * . 19 * <hr> 20 * This file is part of the SANE package. 21 * 22 * This program is free software; you can redistribute it and/or 23 * modify it under the terms of the GNU General Public License as 24 * published by the Free Software Foundation; either version 2 of the 25 * License, or (at your option) any later version. 26 * 27 * This program is distributed in the hope that it will be useful, but 28 * WITHOUT ANY WARRANTY; without even the implied warranty of 29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 30 * General Public License for more details. 31 * 32 * You should have received a copy of the GNU General Public License 33 * along with this program. If not, see <https://www.gnu.org/licenses/>. 34 * 35 * As a special exception, the authors of SANE give permission for 36 * additional uses of the libraries contained in this release of SANE. 37 * 38 * The exception is that, if you link a SANE library with other files 39 * to produce an executable, this does not by itself cause the 40 * resulting executable to be covered by the GNU General Public 41 * License. Your use of that executable is in no way restricted on 42 * account of linking the SANE library code into it. 43 * 44 * This exception does not, however, invalidate any other reasons why 45 * the executable file might be covered by the GNU General Public 46 * License. 47 * 48 * If you submit changes to SANE to the maintainers to be included in 49 * a subsequent release, you agree by submitting the changes that 50 * those changes may be distributed with this exception intact. 51 * 52 * If you write modifications of your own for SANE, it is your choice 53 * whether to permit this exception to apply to your modifications. 54 * If you do not wish that, delete this exception notice. 55 * <hr> 56 */ 57 #ifndef _SYSDEP_H_ 58 #define _SYSDEP_H_ 59 60 #ifndef LINUX_VERSION_CODE 61 # include <linux/version.h> 62 #endif 63 64 #ifndef VERSION_CODE 65 # define VERSION_CODE(vers,rel,seq) ( ((vers)<<16) | ((rel)<<8) | (seq) ) 66 #endif 67 68 /* only allow > 2.0.x */ 69 #if LINUX_VERSION_CODE < VERSION_CODE(2,0,0) 70 # error "This kernel is too old: not supported by this file" 71 #endif 72 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,0) 73 # define LINUX_20 74 #elif LINUX_VERSION_CODE < VERSION_CODE(2,4,0) 75 # define LINUX_21 76 #elif LINUX_VERSION_CODE < VERSION_CODE(2,6,0) 77 # define LINUX_24 78 #else 79 # define LINUX_24 80 # define LINUX_26 81 # include <linux/device.h> 82 # if LINUX_VERSION_CODE > VERSION_CODE(2,6,35) 83 # define NOLOCK_IOCTL 84 # define IOCTL unlocked_ioctl 85 # else 86 # define IOCTL ioctl 87 # endif 88 # if LINUX_VERSION_CODE > VERSION_CODE(3,0,0) 89 # include <linux/sched.h> 90 # endif 91 #endif 92 93 #include <linux/types.h> /* used later in this header */ 94 95 96 /* Modularization issues */ 97 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,18) 98 # define __USE_OLD_SYMTAB__ 99 # define EXPORT_NO_SYMBOLS register_symtab(NULL); 100 # define REGISTER_SYMTAB(tab) register_symtab(tab) 101 #else 102 # define REGISTER_SYMTAB(tab) /* nothing */ 103 #endif 104 105 #ifdef __USE_OLD_SYMTAB__ 106 # define __MODULE_STRING(s) /* nothing */ 107 # define MODULE_PARM(v,t) /* nothing */ 108 # define MODULE_PARM_DESC(v,t) /* nothing */ 109 # define MODULE_AUTHOR(n) /* nothing */ 110 # define MODULE_DESCRIPTION(d) /* nothing */ 111 # define MODULE_SUPPORTED_DEVICE(n) /* nothing */ 112 #endif 113 114 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,31) 115 # define CLOSETYPE void 116 # define CLOSERETURN(arg) 117 #else 118 # define CLOSETYPE int 119 # define CLOSERETURN(arg) return arg 120 #endif 121 122 /* 123 * "select" changed in 2.1.23. The implementation is twin, but this 124 * header is new 125 */ 126 #if LINUX_VERSION_CODE > VERSION_CODE(2,1,22) 127 # include <linux/poll.h> 128 #else 129 # define __USE_OLD_SELECT__ 130 #endif 131 132 /* Other change in the fops are solved using pseudo-types */ 133 #if defined(LINUX_21) || defined(LINUX_24) || defined(LINUX_26) 134 # define lseek_t long long 135 # define lseek_off_t long long 136 #else 137 # define lseek_t int 138 # define lseek_off_t off_t 139 #endif 140 141 /* changed the prototype of read/write */ 142 #if defined(LINUX_21) || defined (LINUX_24) || defined(LINUX_26) || defined(__alpha__) 143 # define count_t unsigned long 144 # define read_write_t long 145 #else 146 # define count_t int 147 # define read_write_t int 148 #endif 149 150 151 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,31) 152 # define release_t void 153 # define release_return(x) return 154 #else 155 # define release_t int 156 # define release_return(x) return (x) 157 #endif 158 159 /* 160 * access to user space: use the 2.1 functions, 161 * and implement them as macros for 2.0 162 */ 163 164 #ifdef LINUX_20 165 # include <asm/segment.h> 166 # define access_ok(t,a,sz) (verify_area((t),(a),(sz)) ? 0 : 1) 167 # define verify_area_20 verify_area 168 # define copy_to_user(t,f,n) (memcpy_tofs(t,f,n), 0) 169 # define __copy_to_user(t,f,n) copy_to_user((t),(f),(n)) 170 # define copy_to_user_ret(t,f,n,r) copy_to_user((t),(f),(n)) 171 # define copy_from_user(t,f,n) (memcpy_fromfs((t),(f),(n)), 0) 172 # define __copy_from_user(t,f,n) copy_from_user((t),(f),(n)) 173 # define copy_from_user_ret(t,f,n,r) copy_from_user((t),(f),(n)) 174 # define PUT_USER(val,add) (put_user((val),(add)), 0) 175 # define __PUT_USER(val,add) PUT_USER((val),(add)) 176 # define PUT_USER_RET(val,add,ret) PUT_USER((val),(add)) 177 # define GET_USER(dest,add) ((dest)=get_user((add)), 0) 178 # define __GET_USER(dest,add) GET_USER((dest),(add)) 179 # define GET_USER_RET(dest,add,ret) GET_USER((dest),(add)) 180 #else 181 # include <asm/uaccess.h> 182 # include <asm/io.h> 183 # define verify_area_20(t,a,sz) (0) /* == success */ 184 # define PUT_USER put_user 185 # define __PUT_USER __put_user 186 # define PUT_USER_RET put_user_ret 187 # define GET_USER get_user 188 # define __GET_USER __get_user 189 # define GET_USER_RET get_user_ret 190 191 /* starting with 2.4.0-test8, they removed the put_user_ret and get_user_ret 192 * macros, so we recode'em 193 */ 194 #if defined(LINUX_24) || defined(LINUX_26) 195 #ifndef put_user_ret 196 # define put_user_ret(x,ptr,ret) ({ if (put_user(x,ptr)) return ret; }) 197 #endif 198 199 #ifndef get_user_ret 200 # define get_user_ret(x,ptr,ret) ({ if (get_user(x,ptr)) return ret; }) 201 #endif 202 #endif 203 204 #endif 205 206 /* ioremap */ 207 #ifdef LINUX_20 208 # define ioremap vremap 209 # define iounmap vfree 210 #endif 211 212 /* The use_count of exec_domain and binfmt changed in 2.1.23 */ 213 214 #ifdef LINUX_20 215 # define INCRCOUNT(p) ((p)->module ? __MOD_INC_USE_COUNT((p)->module) : 0) 216 # define CURRCOUNT(p) ((p)->module && (p)->module->usecount) 217 # define DECRCOUNT(p) ((p)->module ? __MOD_DEC_USE_COUNT((p)->module) : 0) 218 #else 219 # define INCRCOUNT(p) ((p)->use_count++) 220 # define CURRCOUNT(p) ((p)->use_count) 221 # define DECRCOUNT(p) ((p)->use_count--) 222 #endif 223 224 /* register_dynamic no more existent -- just have 0 as inum */ 225 #if LINUX_VERSION_CODE >= VERSION_CODE(2,1,29) 226 # define proc_register_dynamic proc_register 227 #endif 228 229 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,37) 230 # define test_and_set_bit(nr,addr) test_bit((nr),(addr)) 231 # define test_and_clear_bit(nr,addr) clear_bit((nr),(addr)) 232 # define test_and_change_bit(nr,addr) change_bit((nr),(addr)) 233 #endif 234 235 /* 2.1.30 removed these functions. Let's define them, just in case */ 236 #if LINUX_VERSION_CODE > VERSION_CODE(2,1,29) 237 # define queue_task_irq queue_task 238 # define queue_task_irq_off queue_task 239 #endif 240 241 /* 2.1.10 and 2.1.43 introduced new functions. They are worth using */ 242 243 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,10) 244 245 # include <asm/byteorder.h> 246 # ifdef __LITTLE_ENDIAN 247 # define cpu_to_le16(x) (x) 248 # define cpu_to_le32(x) (x) 249 # define cpu_to_be16(x) htons((x)) 250 # define cpu_to_be32(x) htonl((x)) 251 # else 252 # define cpu_to_be16(x) (x) 253 # define cpu_to_be32(x) (x) cpu_to_le16(__u16 x)254 extern inline __u16 cpu_to_le16(__u16 x) { return (x<<8) | (x>>8);} cpu_to_le32(__u32 x)255 extern inline __u32 cpu_to_le32(__u32 x) { return((x>>24) | 256 ((x>>8)&0xff00) | ((x<<8)&0xff0000) | (x<<24));} 257 # endif 258 259 # define le16_to_cpu(x) cpu_to_le16(x) 260 # define le32_to_cpu(x) cpu_to_le32(x) 261 # define be16_to_cpu(x) cpu_to_be16(x) 262 # define be32_to_cpu(x) cpu_to_be32(x) 263 264 #endif 265 266 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,43) 267 # define cpu_to_le16p(addr) (cpu_to_le16(*(addr))) 268 # define cpu_to_le32p(addr) (cpu_to_le32(*(addr))) 269 # define cpu_to_be16p(addr) (cpu_to_be16(*(addr))) 270 # define cpu_to_be32p(addr) (cpu_to_be32(*(addr))) 271 cpu_to_le16s(__u16 * a)272 extern inline void cpu_to_le16s(__u16 *a) {*a = cpu_to_le16(*a);} cpu_to_le32s(__u16 * a)273 extern inline void cpu_to_le32s(__u16 *a) {*a = cpu_to_le32(*a);} cpu_to_be16s(__u16 * a)274 extern inline void cpu_to_be16s(__u16 *a) {*a = cpu_to_be16(*a);} cpu_to_be32s(__u16 * a)275 extern inline void cpu_to_be32s(__u16 *a) {*a = cpu_to_be32(*a);} 276 277 # define le16_to_cpup(x) cpu_to_le16p(x) 278 # define le32_to_cpup(x) cpu_to_le32p(x) 279 # define be16_to_cpup(x) cpu_to_be16p(x) 280 # define be32_to_cpup(x) cpu_to_be32p(x) 281 282 # define le16_to_cpus(x) cpu_to_le16s(x) 283 # define le32_to_cpus(x) cpu_to_le32s(x) 284 # define be16_to_cpus(x) cpu_to_be16s(x) 285 # define be32_to_cpus(x) cpu_to_be32s(x) 286 #endif 287 288 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,15) 289 # define __USE_OLD_REBUILD_HEADER__ 290 #endif 291 292 #if LINUX_VERSION_CODE < VERSION_CODE(2,1,30) 293 # define in_interrupt() (intr_count!=0) 294 #endif 295 296 /* 297 * from 2.4.17 on, they decided to use slab.h instead of malloc.h... so what... 298 * somewhere from 2.4.18-pre9 they skipped get_fast_time... 299 */ 300 #if LINUX_VERSION_CODE < VERSION_CODE(2,4,17) 301 # include "linux/malloc.h" 302 # define _GET_TIME get_fast_time 303 #else 304 # include "linux/slab.h" 305 # define _GET_TIME do_gettimeofday 306 #endif 307 308 #ifdef LINUX_26 309 # define _MINOR(p) iminor(p) 310 #else 311 # define _MINOR(p) minor(p->i_rdev) 312 #endif 313 314 /* Basic class macros */ 315 #ifdef LINUX_26 316 #if LINUX_VERSION_CODE >= VERSION_CODE(2,6,15) 317 318 typedef struct class class_t; 319 320 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) 321 #define CLASS_DEV_CREATE(class, devt, device, name) \ 322 device_create(class, device, devt, NULL, "%s", name) 323 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) 324 #define CLASS_DEV_CREATE(class, devt, device, name) \ 325 device_create(class, device, devt, name) 326 #else 327 #define CLASS_DEV_CREATE(class, devt, device, name) \ 328 class_device_create(class, NULL, devt, device, name) 329 #endif 330 331 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) 332 #define CLASS_DEV_DESTROY device_destroy 333 #else 334 #define CLASS_DEV_DESTROY class_device_destroy 335 #endif 336 337 #else /* LINUX 2.6.0 - 2.6.14 */ 338 339 #if LINUX_VERSION_CODE >= VERSION_CODE(2,6,13) /* LINUX 2.6.13 - 2.6.14 */ 340 typedef struct class class_t; 341 #define CLASS_DEVICE_CREATE class_device_create 342 #define CLASS_DEV_DESTROY(class, devt) class_device_destroy(class, devt) 343 344 #else /* LINUX 2.6.0 - 2.6.12, class_simple */ 345 346 typedef struct class_simple class_t; 347 #define CLASS_DEVICE_CREATE class_simple_device_add 348 #define CLASS_DEV_DESTROY(class, devt) class_simple_device_remove(class, devt) 349 350 #define class_create class_simple_create 351 #define class_destroy class_simple_destroy 352 #define class_device_destroy(a, b) class_simple_device_remove(b) 353 354 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) */ 355 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) */ 356 #endif 357 358 #endif /* _SYSDEP_H_ */ 359 360 /* END PLUSTEK-PP_SYSDEP.H ..................................................*/ 361