Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 1 | #ifndef _LINUX_COMPAT_H_ |
| 2 | #define _LINUX_COMPAT_H_ |
| 3 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 4 | #include <malloc.h> |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/err.h> |
Heiko Schocher | 5219db8 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 7 | #include <linux/kernel.h> |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 8 | |
| 9 | struct unused {}; |
| 10 | typedef struct unused unused_t; |
| 11 | |
| 12 | struct p_current{ |
| 13 | int pid; |
| 14 | }; |
| 15 | |
| 16 | extern struct p_current *current; |
| 17 | |
Masahiro Yamada | c898cba | 2017-09-26 11:58:29 +0900 | [diff] [blame] | 18 | /* avoid conflict with <dm/device.h> */ |
| 19 | #ifdef dev_dbg |
| 20 | #undef dev_dbg |
| 21 | #endif |
| 22 | #ifdef dev_vdbg |
| 23 | #undef dev_vdbg |
| 24 | #endif |
| 25 | #ifdef dev_info |
| 26 | #undef dev_info |
| 27 | #endif |
| 28 | #ifdef dev_err |
| 29 | #undef dev_err |
| 30 | #endif |
| 31 | #ifdef dev_warn |
| 32 | #undef dev_warn |
| 33 | #endif |
| 34 | |
Wu, Josh | 2f96b06 | 2013-07-03 11:11:47 +0800 | [diff] [blame] | 35 | #define dev_dbg(dev, fmt, args...) \ |
| 36 | debug(fmt, ##args) |
| 37 | #define dev_vdbg(dev, fmt, args...) \ |
| 38 | debug(fmt, ##args) |
| 39 | #define dev_info(dev, fmt, args...) \ |
| 40 | printf(fmt, ##args) |
| 41 | #define dev_err(dev, fmt, args...) \ |
| 42 | printf(fmt, ##args) |
Andreas Bießmann | 88a7fff | 2016-06-04 22:27:22 +0200 | [diff] [blame] | 43 | #define dev_warn(dev, fmt, args...) \ |
| 44 | printf(fmt, ##args) |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 45 | |
Bin Meng | b06d76f | 2018-07-26 03:15:58 -0700 | [diff] [blame] | 46 | #define netdev_emerg(dev, fmt, args...) \ |
| 47 | printf(fmt, ##args) |
| 48 | #define netdev_alert(dev, fmt, args...) \ |
| 49 | printf(fmt, ##args) |
| 50 | #define netdev_crit(dev, fmt, args...) \ |
| 51 | printf(fmt, ##args) |
| 52 | #define netdev_err(dev, fmt, args...) \ |
| 53 | printf(fmt, ##args) |
| 54 | #define netdev_warn(dev, fmt, args...) \ |
| 55 | printf(fmt, ##args) |
| 56 | #define netdev_notice(dev, fmt, args...) \ |
| 57 | printf(fmt, ##args) |
| 58 | #define netdev_info(dev, fmt, args...) \ |
| 59 | printf(fmt, ##args) |
| 60 | #define netdev_dbg(dev, fmt, args...) \ |
| 61 | debug(fmt, ##args) |
| 62 | #define netdev_vdbg(dev, fmt, args...) \ |
| 63 | debug(fmt, ##args) |
| 64 | |
Masahiro Yamada | 6b9f9ea | 2015-07-13 13:17:07 +0900 | [diff] [blame] | 65 | #define GFP_ATOMIC ((gfp_t) 0) |
| 66 | #define GFP_KERNEL ((gfp_t) 0) |
| 67 | #define GFP_NOFS ((gfp_t) 0) |
| 68 | #define GFP_USER ((gfp_t) 0) |
| 69 | #define __GFP_NOWARN ((gfp_t) 0) |
| 70 | #define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */ |
| 71 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 72 | void *kmalloc(size_t size, int flags); |
Masahiro Yamada | 6b9f9ea | 2015-07-13 13:17:07 +0900 | [diff] [blame] | 73 | |
| 74 | static inline void *kzalloc(size_t size, gfp_t flags) |
| 75 | { |
| 76 | return kmalloc(size, flags | __GFP_ZERO); |
| 77 | } |
Heiko Schocher | 5219db8 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 78 | |
| 79 | static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) |
| 80 | { |
| 81 | if (size != 0 && n > SIZE_MAX / size) |
| 82 | return NULL; |
| 83 | return kmalloc(n * size, flags | __GFP_ZERO); |
| 84 | } |
| 85 | |
| 86 | static inline void *kcalloc(size_t n, size_t size, gfp_t flags) |
| 87 | { |
| 88 | return kmalloc_array(n, size, flags | __GFP_ZERO); |
| 89 | } |
| 90 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 91 | #define vmalloc(size) kmalloc(size, 0) |
| 92 | #define __vmalloc(size, flags, pgsz) kmalloc(size, flags) |
Masahiro Yamada | ebc3328 | 2015-07-13 13:17:06 +0900 | [diff] [blame] | 93 | static inline void *vzalloc(unsigned long size) |
| 94 | { |
| 95 | return kzalloc(size, 0); |
| 96 | } |
Heiko Schocher | 5219db8 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 97 | static inline void kfree(const void *block) |
| 98 | { |
| 99 | free((void *)block); |
| 100 | } |
| 101 | static inline void vfree(const void *addr) |
| 102 | { |
| 103 | free((void *)addr); |
| 104 | } |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 105 | |
| 106 | struct kmem_cache { int sz; }; |
| 107 | |
| 108 | struct kmem_cache *get_mem(int element_sz); |
| 109 | #define kmem_cache_create(a, sz, c, d, e) get_mem(sz) |
| 110 | void *kmem_cache_alloc(struct kmem_cache *obj, int flag); |
Heiko Schocher | 5219db8 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 111 | static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj) |
| 112 | { |
| 113 | free(obj); |
| 114 | } |
| 115 | static inline void kmem_cache_destroy(struct kmem_cache *cachep) |
| 116 | { |
| 117 | free(cachep); |
| 118 | } |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 119 | |
Stefan Roese | 0a57265 | 2009-05-12 14:29:39 +0200 | [diff] [blame] | 120 | #define DECLARE_WAITQUEUE(...) do { } while (0) |
| 121 | #define add_wait_queue(...) do { } while (0) |
| 122 | #define remove_wait_queue(...) do { } while (0) |
| 123 | |
| 124 | #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 125 | |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 126 | #define PAGE_SIZE 4096 |
Lijun Pan | 8f2df5d | 2014-06-20 12:17:29 -0500 | [diff] [blame] | 127 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 128 | /* drivers/char/random.c */ |
| 129 | #define get_random_bytes(...) |
| 130 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 131 | /* include/linux/leds.h */ |
| 132 | struct led_trigger {}; |
| 133 | |
| 134 | #define DEFINE_LED_TRIGGER(x) static struct led_trigger *x; |
| 135 | enum led_brightness { |
| 136 | LED_OFF = 0, |
| 137 | LED_HALF = 127, |
| 138 | LED_FULL = 255, |
| 139 | }; |
| 140 | |
| 141 | static inline void led_trigger_register_simple(const char *name, |
| 142 | struct led_trigger **trigger) {} |
| 143 | static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {} |
| 144 | static inline void led_trigger_event(struct led_trigger *trigger, |
| 145 | enum led_brightness event) {} |
| 146 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 147 | /* uapi/linux/limits.h */ |
| 148 | #define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ |
| 149 | |
| 150 | /** |
| 151 | * The type used for indexing onto a disc or disc partition. |
| 152 | * |
| 153 | * Linux always considers sectors to be 512 bytes long independently |
| 154 | * of the devices real block size. |
| 155 | * |
| 156 | * blkcnt_t is the type of the inode's block count. |
| 157 | */ |
| 158 | #ifdef CONFIG_LBDAF |
| 159 | typedef u64 sector_t; |
| 160 | typedef u64 blkcnt_t; |
| 161 | #else |
| 162 | typedef unsigned long sector_t; |
| 163 | typedef unsigned long blkcnt_t; |
| 164 | #endif |
| 165 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 166 | /* module */ |
| 167 | #define THIS_MODULE 0 |
| 168 | #define try_module_get(...) 1 |
| 169 | #define module_put(...) do { } while (0) |
| 170 | #define module_init(...) |
| 171 | #define module_exit(...) |
| 172 | #define EXPORT_SYMBOL(...) |
| 173 | #define EXPORT_SYMBOL_GPL(...) |
| 174 | #define module_param(...) |
| 175 | #define module_param_call(...) |
| 176 | #define MODULE_PARM_DESC(...) |
| 177 | #define MODULE_VERSION(...) |
| 178 | #define MODULE_DESCRIPTION(...) |
| 179 | #define MODULE_AUTHOR(...) |
| 180 | #define MODULE_LICENSE(...) |
| 181 | #define MODULE_ALIAS(...) |
| 182 | #define __module_get(...) |
| 183 | |
| 184 | /* character device */ |
| 185 | #define MKDEV(...) 0 |
| 186 | #define MAJOR(dev) 0 |
| 187 | #define MINOR(dev) 0 |
| 188 | |
| 189 | #define alloc_chrdev_region(...) 0 |
| 190 | #define unregister_chrdev_region(...) |
| 191 | |
| 192 | #define class_create(...) __builtin_return_address(0) |
| 193 | #define class_create_file(...) 0 |
Heiko Schocher | 5219db8 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 194 | #define class_register(...) 0 |
| 195 | #define class_unregister(...) |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 196 | #define class_remove_file(...) |
| 197 | #define class_destroy(...) |
| 198 | #define misc_register(...) 0 |
| 199 | #define misc_deregister(...) |
| 200 | |
| 201 | #define blocking_notifier_call_chain(...) 0 |
| 202 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 203 | #define __initdata |
| 204 | #define late_initcall(...) |
| 205 | |
| 206 | #define dev_set_name(...) do { } while (0) |
| 207 | #define device_register(...) 0 |
Heiko Schocher | 5219db8 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 208 | #define device_unregister(...) |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 209 | #define volume_sysfs_init(...) 0 |
| 210 | #define volume_sysfs_close(...) do { } while (0) |
| 211 | |
| 212 | #define init_waitqueue_head(...) do { } while (0) |
| 213 | #define wait_event_interruptible(...) 0 |
| 214 | #define wake_up_interruptible(...) do { } while (0) |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 215 | #define dump_stack(...) do { } while (0) |
| 216 | |
| 217 | #define task_pid_nr(x) 0 |
| 218 | #define set_freezable(...) do { } while (0) |
| 219 | #define try_to_freeze(...) 0 |
| 220 | #define set_current_state(...) do { } while (0) |
| 221 | #define kthread_should_stop(...) 0 |
| 222 | #define schedule() do { } while (0) |
| 223 | |
| 224 | #define setup_timer(timer, func, data) do {} while (0) |
| 225 | #define del_timer_sync(timer) do {} while (0) |
| 226 | #define schedule_work(work) do {} while (0) |
| 227 | #define INIT_WORK(work, fun) do {} while (0) |
| 228 | |
| 229 | struct work_struct {}; |
| 230 | |
| 231 | unsigned long copy_from_user(void *dest, const void *src, |
| 232 | unsigned long count); |
| 233 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 234 | typedef unused_t spinlock_t; |
| 235 | typedef int wait_queue_head_t; |
| 236 | |
| 237 | #define spin_lock_init(lock) do {} while (0) |
| 238 | #define spin_lock(lock) do {} while (0) |
| 239 | #define spin_unlock(lock) do {} while (0) |
| 240 | #define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0) |
| 241 | #define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0) |
| 242 | |
| 243 | #define DEFINE_MUTEX(...) |
| 244 | #define mutex_init(...) |
| 245 | #define mutex_lock(...) |
| 246 | #define mutex_unlock(...) |
| 247 | |
| 248 | #define init_rwsem(...) do { } while (0) |
| 249 | #define down_read(...) do { } while (0) |
| 250 | #define down_write(...) do { } while (0) |
| 251 | #define down_write_trylock(...) 1 |
| 252 | #define up_read(...) do { } while (0) |
| 253 | #define up_write(...) do { } while (0) |
| 254 | |
| 255 | #define cond_resched() do { } while (0) |
| 256 | #define yield() do { } while (0) |
| 257 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 258 | #define __init |
| 259 | #define __exit |
| 260 | #define __devinit |
| 261 | #define __devinitdata |
| 262 | #define __devinitconst |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 263 | |
| 264 | #define kthread_create(...) __builtin_return_address(0) |
| 265 | #define kthread_stop(...) do { } while (0) |
| 266 | #define wake_up_process(...) do { } while (0) |
| 267 | |
| 268 | struct rw_semaphore { int i; }; |
| 269 | #define down_write(...) do { } while (0) |
| 270 | #define up_write(...) do { } while (0) |
| 271 | #define down_read(...) do { } while (0) |
| 272 | #define up_read(...) do { } while (0) |
| 273 | struct device { |
| 274 | struct device *parent; |
| 275 | struct class *class; |
| 276 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
| 277 | void (*release)(struct device *dev); |
| 278 | /* This is used from drivers/usb/musb-new subsystem only */ |
| 279 | void *driver_data; /* data private to the driver */ |
| 280 | void *device_data; /* data private to the device */ |
| 281 | }; |
| 282 | struct mutex { int i; }; |
| 283 | struct kernel_param { int i; }; |
| 284 | |
| 285 | struct cdev { |
| 286 | int owner; |
| 287 | dev_t dev; |
| 288 | }; |
| 289 | #define cdev_init(...) do { } while (0) |
| 290 | #define cdev_add(...) 0 |
| 291 | #define cdev_del(...) do { } while (0) |
| 292 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 293 | #define prandom_u32(...) 0 |
| 294 | |
| 295 | typedef struct { |
| 296 | uid_t val; |
| 297 | } kuid_t; |
| 298 | |
| 299 | typedef struct { |
| 300 | gid_t val; |
| 301 | } kgid_t; |
| 302 | |
| 303 | /* from include/linux/types.h */ |
| 304 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 305 | /** |
| 306 | * struct callback_head - callback structure for use with RCU and task_work |
| 307 | * @next: next update requests in a list |
| 308 | * @func: actual update function to call after the grace period. |
| 309 | */ |
| 310 | struct callback_head { |
| 311 | struct callback_head *next; |
| 312 | void (*func)(struct callback_head *head); |
| 313 | }; |
| 314 | #define rcu_head callback_head |
| 315 | enum writeback_sync_modes { |
| 316 | WB_SYNC_NONE, /* Don't wait on anything */ |
| 317 | WB_SYNC_ALL, /* Wait on every mapping */ |
| 318 | }; |
| 319 | |
| 320 | /* from include/linux/writeback.h */ |
| 321 | /* |
| 322 | * A control structure which tells the writeback code what to do. These are |
| 323 | * always on the stack, and hence need no locking. They are always initialised |
| 324 | * in a manner such that unspecified fields are set to zero. |
| 325 | */ |
| 326 | struct writeback_control { |
| 327 | long nr_to_write; /* Write this many pages, and decrement |
| 328 | this for each page written */ |
| 329 | long pages_skipped; /* Pages which were not written */ |
| 330 | |
| 331 | /* |
| 332 | * For a_ops->writepages(): if start or end are non-zero then this is |
| 333 | * a hint that the filesystem need only write out the pages inside that |
| 334 | * byterange. The byte at `end' is included in the writeout request. |
| 335 | */ |
| 336 | loff_t range_start; |
| 337 | loff_t range_end; |
| 338 | |
| 339 | enum writeback_sync_modes sync_mode; |
| 340 | |
| 341 | unsigned for_kupdate:1; /* A kupdate writeback */ |
| 342 | unsigned for_background:1; /* A background writeback */ |
| 343 | unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */ |
| 344 | unsigned for_reclaim:1; /* Invoked from the page allocator */ |
| 345 | unsigned range_cyclic:1; /* range_start is cyclic */ |
| 346 | unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ |
| 347 | }; |
| 348 | |
| 349 | void *kmemdup(const void *src, size_t len, gfp_t gfp); |
| 350 | |
| 351 | typedef int irqreturn_t; |
| 352 | |
| 353 | struct timer_list {}; |
| 354 | struct notifier_block {}; |
| 355 | |
| 356 | typedef unsigned long dmaaddr_t; |
| 357 | |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 358 | #define pm_runtime_get_sync(dev) do {} while (0) |
| 359 | #define pm_runtime_put(dev) do {} while (0) |
| 360 | #define pm_runtime_put_sync(dev) do {} while (0) |
| 361 | #define pm_runtime_use_autosuspend(dev) do {} while (0) |
| 362 | #define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0) |
| 363 | #define pm_runtime_enable(dev) do {} while (0) |
| 364 | |
| 365 | #define IRQ_NONE 0 |
| 366 | #define IRQ_HANDLED 1 |
Kishon Vijay Abraham I | 747a0a5 | 2015-02-23 18:39:58 +0530 | [diff] [blame] | 367 | #define IRQ_WAKE_THREAD 2 |
Heiko Schocher | 0c06db5 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 368 | |
| 369 | #define dev_set_drvdata(dev, data) do {} while (0) |
| 370 | |
| 371 | #define enable_irq(...) |
| 372 | #define disable_irq(...) |
| 373 | #define disable_irq_wake(irq) do {} while (0) |
| 374 | #define enable_irq_wake(irq) -EINVAL |
| 375 | #define free_irq(irq, data) do {} while (0) |
| 376 | #define request_irq(nr, f, flags, nm, data) 0 |
| 377 | |
Wolfgang Denk | 932394a | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 378 | #endif |