Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 1 | #ifndef _LINUX_COMPAT_H_ |
| 2 | #define _LINUX_COMPAT_H_ |
| 3 | |
Heiko Schocher | 4f7a9a3 | 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 | 9851f52 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 7 | #include <linux/kernel.h> |
Heiko Schocher | 4f7a9a3 | 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 | 9e74eb5 | 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 | ba6babf | 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 | 317a382 | 2016-06-04 22:27:22 +0200 | [diff] [blame] | 43 | #define dev_warn(dev, fmt, args...) \ |
| 44 | printf(fmt, ##args) |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 45 | |
Bin Meng | 5efc2c4 | 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 | 7b5ec7e | 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 | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 72 | void *kmalloc(size_t size, int flags); |
Masahiro Yamada | 7b5ec7e | 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 | 9851f52 | 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 | 4f7a9a3 | 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 | c537347 | 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 | 9851f52 | 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 | 4f7a9a3 | 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 | 9851f52 | 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 | } |
Stefan Roese | e0860d4 | 2009-05-12 14:29:39 +0200 | [diff] [blame] | 119 | |
| 120 | #define DECLARE_WAITQUEUE(...) do { } while (0) |
| 121 | #define add_wait_queue(...) do { } while (0) |
| 122 | #define remove_wait_queue(...) do { } while (0) |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 123 | |
Stefan Roese | e0860d4 | 2009-05-12 14:29:39 +0200 | [diff] [blame] | 124 | #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 125 | |
Simon Glass | fb6f482 | 2020-02-03 07:36:17 -0700 | [diff] [blame] | 126 | /* This is also defined in ARMv8's mmu.h */ |
| 127 | #ifndef PAGE_SIZE |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 128 | #define PAGE_SIZE 4096 |
Simon Glass | fb6f482 | 2020-02-03 07:36:17 -0700 | [diff] [blame] | 129 | #endif |
Lijun Pan | 036f66d | 2014-06-20 12:17:29 -0500 | [diff] [blame] | 130 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 131 | /* drivers/char/random.c */ |
| 132 | #define get_random_bytes(...) |
| 133 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 134 | /* include/linux/leds.h */ |
| 135 | struct led_trigger {}; |
| 136 | |
| 137 | #define DEFINE_LED_TRIGGER(x) static struct led_trigger *x; |
| 138 | enum led_brightness { |
| 139 | LED_OFF = 0, |
| 140 | LED_HALF = 127, |
| 141 | LED_FULL = 255, |
| 142 | }; |
| 143 | |
| 144 | static inline void led_trigger_register_simple(const char *name, |
| 145 | struct led_trigger **trigger) {} |
| 146 | static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {} |
| 147 | static inline void led_trigger_event(struct led_trigger *trigger, |
| 148 | enum led_brightness event) {} |
| 149 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 150 | /* uapi/linux/limits.h */ |
| 151 | #define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ |
| 152 | |
| 153 | /** |
| 154 | * The type used for indexing onto a disc or disc partition. |
| 155 | * |
| 156 | * Linux always considers sectors to be 512 bytes long independently |
| 157 | * of the devices real block size. |
| 158 | * |
| 159 | * blkcnt_t is the type of the inode's block count. |
| 160 | */ |
| 161 | #ifdef CONFIG_LBDAF |
| 162 | typedef u64 sector_t; |
| 163 | typedef u64 blkcnt_t; |
| 164 | #else |
| 165 | typedef unsigned long sector_t; |
| 166 | typedef unsigned long blkcnt_t; |
| 167 | #endif |
| 168 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 169 | /* module */ |
| 170 | #define THIS_MODULE 0 |
| 171 | #define try_module_get(...) 1 |
| 172 | #define module_put(...) do { } while (0) |
| 173 | #define module_init(...) |
| 174 | #define module_exit(...) |
| 175 | #define EXPORT_SYMBOL(...) |
| 176 | #define EXPORT_SYMBOL_GPL(...) |
| 177 | #define module_param(...) |
| 178 | #define module_param_call(...) |
| 179 | #define MODULE_PARM_DESC(...) |
| 180 | #define MODULE_VERSION(...) |
| 181 | #define MODULE_DESCRIPTION(...) |
| 182 | #define MODULE_AUTHOR(...) |
| 183 | #define MODULE_LICENSE(...) |
| 184 | #define MODULE_ALIAS(...) |
| 185 | #define __module_get(...) |
| 186 | |
| 187 | /* character device */ |
| 188 | #define MKDEV(...) 0 |
| 189 | #define MAJOR(dev) 0 |
| 190 | #define MINOR(dev) 0 |
| 191 | |
| 192 | #define alloc_chrdev_region(...) 0 |
| 193 | #define unregister_chrdev_region(...) |
| 194 | |
| 195 | #define class_create(...) __builtin_return_address(0) |
| 196 | #define class_create_file(...) 0 |
Heiko Schocher | 9851f52 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 197 | #define class_register(...) 0 |
| 198 | #define class_unregister(...) |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 199 | #define class_remove_file(...) |
| 200 | #define class_destroy(...) |
| 201 | #define misc_register(...) 0 |
| 202 | #define misc_deregister(...) |
| 203 | |
| 204 | #define blocking_notifier_call_chain(...) 0 |
| 205 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 206 | #define __initdata |
| 207 | #define late_initcall(...) |
| 208 | |
| 209 | #define dev_set_name(...) do { } while (0) |
| 210 | #define device_register(...) 0 |
Heiko Schocher | 9851f52 | 2015-10-22 06:19:20 +0200 | [diff] [blame] | 211 | #define device_unregister(...) |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 212 | #define volume_sysfs_init(...) 0 |
| 213 | #define volume_sysfs_close(...) do { } while (0) |
| 214 | |
| 215 | #define init_waitqueue_head(...) do { } while (0) |
| 216 | #define wait_event_interruptible(...) 0 |
| 217 | #define wake_up_interruptible(...) do { } while (0) |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 218 | #define dump_stack(...) do { } while (0) |
| 219 | |
| 220 | #define task_pid_nr(x) 0 |
| 221 | #define set_freezable(...) do { } while (0) |
| 222 | #define try_to_freeze(...) 0 |
| 223 | #define set_current_state(...) do { } while (0) |
| 224 | #define kthread_should_stop(...) 0 |
| 225 | #define schedule() do { } while (0) |
| 226 | |
| 227 | #define setup_timer(timer, func, data) do {} while (0) |
| 228 | #define del_timer_sync(timer) do {} while (0) |
| 229 | #define schedule_work(work) do {} while (0) |
| 230 | #define INIT_WORK(work, fun) do {} while (0) |
| 231 | |
| 232 | struct work_struct {}; |
| 233 | |
| 234 | unsigned long copy_from_user(void *dest, const void *src, |
| 235 | unsigned long count); |
| 236 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 237 | typedef unused_t spinlock_t; |
| 238 | typedef int wait_queue_head_t; |
| 239 | |
| 240 | #define spin_lock_init(lock) do {} while (0) |
| 241 | #define spin_lock(lock) do {} while (0) |
| 242 | #define spin_unlock(lock) do {} while (0) |
| 243 | #define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0) |
| 244 | #define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0) |
| 245 | |
| 246 | #define DEFINE_MUTEX(...) |
| 247 | #define mutex_init(...) |
| 248 | #define mutex_lock(...) |
| 249 | #define mutex_unlock(...) |
| 250 | |
| 251 | #define init_rwsem(...) do { } while (0) |
| 252 | #define down_read(...) do { } while (0) |
| 253 | #define down_write(...) do { } while (0) |
| 254 | #define down_write_trylock(...) 1 |
| 255 | #define up_read(...) do { } while (0) |
| 256 | #define up_write(...) do { } while (0) |
| 257 | |
| 258 | #define cond_resched() do { } while (0) |
| 259 | #define yield() do { } while (0) |
| 260 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 261 | #define __init |
| 262 | #define __exit |
| 263 | #define __devinit |
| 264 | #define __devinitdata |
| 265 | #define __devinitconst |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 266 | |
| 267 | #define kthread_create(...) __builtin_return_address(0) |
| 268 | #define kthread_stop(...) do { } while (0) |
| 269 | #define wake_up_process(...) do { } while (0) |
| 270 | |
| 271 | struct rw_semaphore { int i; }; |
| 272 | #define down_write(...) do { } while (0) |
| 273 | #define up_write(...) do { } while (0) |
| 274 | #define down_read(...) do { } while (0) |
| 275 | #define up_read(...) do { } while (0) |
| 276 | struct device { |
| 277 | struct device *parent; |
| 278 | struct class *class; |
| 279 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
| 280 | void (*release)(struct device *dev); |
| 281 | /* This is used from drivers/usb/musb-new subsystem only */ |
| 282 | void *driver_data; /* data private to the driver */ |
| 283 | void *device_data; /* data private to the device */ |
| 284 | }; |
| 285 | struct mutex { int i; }; |
| 286 | struct kernel_param { int i; }; |
| 287 | |
| 288 | struct cdev { |
| 289 | int owner; |
| 290 | dev_t dev; |
| 291 | }; |
| 292 | #define cdev_init(...) do { } while (0) |
| 293 | #define cdev_add(...) 0 |
| 294 | #define cdev_del(...) do { } while (0) |
| 295 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 296 | #define prandom_u32(...) 0 |
| 297 | |
| 298 | typedef struct { |
| 299 | uid_t val; |
| 300 | } kuid_t; |
| 301 | |
| 302 | typedef struct { |
| 303 | gid_t val; |
| 304 | } kgid_t; |
| 305 | |
| 306 | /* from include/linux/types.h */ |
| 307 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 308 | /** |
| 309 | * struct callback_head - callback structure for use with RCU and task_work |
| 310 | * @next: next update requests in a list |
| 311 | * @func: actual update function to call after the grace period. |
| 312 | */ |
| 313 | struct callback_head { |
| 314 | struct callback_head *next; |
| 315 | void (*func)(struct callback_head *head); |
| 316 | }; |
| 317 | #define rcu_head callback_head |
| 318 | enum writeback_sync_modes { |
| 319 | WB_SYNC_NONE, /* Don't wait on anything */ |
| 320 | WB_SYNC_ALL, /* Wait on every mapping */ |
| 321 | }; |
| 322 | |
| 323 | /* from include/linux/writeback.h */ |
| 324 | /* |
| 325 | * A control structure which tells the writeback code what to do. These are |
| 326 | * always on the stack, and hence need no locking. They are always initialised |
| 327 | * in a manner such that unspecified fields are set to zero. |
| 328 | */ |
| 329 | struct writeback_control { |
| 330 | long nr_to_write; /* Write this many pages, and decrement |
| 331 | this for each page written */ |
| 332 | long pages_skipped; /* Pages which were not written */ |
| 333 | |
| 334 | /* |
| 335 | * For a_ops->writepages(): if start or end are non-zero then this is |
| 336 | * a hint that the filesystem need only write out the pages inside that |
| 337 | * byterange. The byte at `end' is included in the writeout request. |
| 338 | */ |
| 339 | loff_t range_start; |
| 340 | loff_t range_end; |
| 341 | |
| 342 | enum writeback_sync_modes sync_mode; |
| 343 | |
| 344 | unsigned for_kupdate:1; /* A kupdate writeback */ |
| 345 | unsigned for_background:1; /* A background writeback */ |
| 346 | unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */ |
| 347 | unsigned for_reclaim:1; /* Invoked from the page allocator */ |
| 348 | unsigned range_cyclic:1; /* range_start is cyclic */ |
| 349 | unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ |
| 350 | }; |
| 351 | |
| 352 | void *kmemdup(const void *src, size_t len, gfp_t gfp); |
| 353 | |
| 354 | typedef int irqreturn_t; |
| 355 | |
| 356 | struct timer_list {}; |
| 357 | struct notifier_block {}; |
| 358 | |
| 359 | typedef unsigned long dmaaddr_t; |
| 360 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 361 | #define pm_runtime_get_sync(dev) do {} while (0) |
| 362 | #define pm_runtime_put(dev) do {} while (0) |
| 363 | #define pm_runtime_put_sync(dev) do {} while (0) |
| 364 | #define pm_runtime_use_autosuspend(dev) do {} while (0) |
| 365 | #define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0) |
| 366 | #define pm_runtime_enable(dev) do {} while (0) |
| 367 | |
| 368 | #define IRQ_NONE 0 |
| 369 | #define IRQ_HANDLED 1 |
Kishon Vijay Abraham I | 35ffd28 | 2015-02-23 18:39:58 +0530 | [diff] [blame] | 370 | #define IRQ_WAKE_THREAD 2 |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 371 | |
| 372 | #define dev_set_drvdata(dev, data) do {} while (0) |
| 373 | |
| 374 | #define enable_irq(...) |
| 375 | #define disable_irq(...) |
| 376 | #define disable_irq_wake(irq) do {} while (0) |
| 377 | #define enable_irq_wake(irq) -EINVAL |
| 378 | #define free_irq(irq, data) do {} while (0) |
| 379 | #define request_irq(nr, f, flags, nm, data) 0 |
| 380 | |
Wolfgang Denk | 2f9b7e4 | 2005-08-17 12:55:25 +0200 | [diff] [blame] | 381 | #endif |