blob: d0f51baab407b67d8c7010f8c325bc2d81fc792e [file] [log] [blame]
Wolfgang Denk932394a2005-08-17 12:55:25 +02001#ifndef _LINUX_COMPAT_H_
2#define _LINUX_COMPAT_H_
3
Heiko Schocher0c06db52014-06-24 10:10:03 +02004#include <malloc.h>
5#include <linux/types.h>
6#include <linux/err.h>
Heiko Schocher5219db82015-10-22 06:19:20 +02007#include <linux/kernel.h>
Heiko Schocher0c06db52014-06-24 10:10:03 +02008
9struct unused {};
10typedef struct unused unused_t;
11
12struct p_current{
13 int pid;
14};
15
16extern struct p_current *current;
17
Masahiro Yamadac898cba2017-09-26 11:58:29 +090018/* 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, Josh2f96b062013-07-03 11:11:47 +080035#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ßmann88a7fff2016-06-04 22:27:22 +020043#define dev_warn(dev, fmt, args...) \
44 printf(fmt, ##args)
Wolfgang Denk932394a2005-08-17 12:55:25 +020045
Bin Mengb06d76f2018-07-26 03:15:58 -070046#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 Yamada6b9f9ea2015-07-13 13:17:07 +090065#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 Schocher0c06db52014-06-24 10:10:03 +020072void *kmalloc(size_t size, int flags);
Masahiro Yamada6b9f9ea2015-07-13 13:17:07 +090073
74static inline void *kzalloc(size_t size, gfp_t flags)
75{
76 return kmalloc(size, flags | __GFP_ZERO);
77}
Heiko Schocher5219db82015-10-22 06:19:20 +020078
79static 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
86static 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 Schocher0c06db52014-06-24 10:10:03 +020091#define vmalloc(size) kmalloc(size, 0)
92#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadaebc33282015-07-13 13:17:06 +090093static inline void *vzalloc(unsigned long size)
94{
95 return kzalloc(size, 0);
96}
Heiko Schocher5219db82015-10-22 06:19:20 +020097static inline void kfree(const void *block)
98{
99 free((void *)block);
100}
101static inline void vfree(const void *addr)
102{
103 free((void *)addr);
104}
Heiko Schocher0c06db52014-06-24 10:10:03 +0200105
106struct kmem_cache { int sz; };
107
108struct kmem_cache *get_mem(int element_sz);
109#define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
110void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
Heiko Schocher5219db82015-10-22 06:19:20 +0200111static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
112{
113 free(obj);
114}
115static inline void kmem_cache_destroy(struct kmem_cache *cachep)
116{
117 free(cachep);
118}
William Juulcfa460a2007-10-31 13:53:06 +0100119
Stefan Roese0a572652009-05-12 14:29:39 +0200120#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 Denk932394a2005-08-17 12:55:25 +0200125
Wolfgang Denk932394a2005-08-17 12:55:25 +0200126#define PAGE_SIZE 4096
Lijun Pan8f2df5d2014-06-20 12:17:29 -0500127
Heiko Schocher0c06db52014-06-24 10:10:03 +0200128/* drivers/char/random.c */
129#define get_random_bytes(...)
130
Heiko Schocher0c06db52014-06-24 10:10:03 +0200131/* include/linux/leds.h */
132struct led_trigger {};
133
134#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
135enum led_brightness {
136 LED_OFF = 0,
137 LED_HALF = 127,
138 LED_FULL = 255,
139};
140
141static inline void led_trigger_register_simple(const char *name,
142 struct led_trigger **trigger) {}
143static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
144static inline void led_trigger_event(struct led_trigger *trigger,
145 enum led_brightness event) {}
146
Heiko Schocher0c06db52014-06-24 10:10:03 +0200147/* 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
159typedef u64 sector_t;
160typedef u64 blkcnt_t;
161#else
162typedef unsigned long sector_t;
163typedef unsigned long blkcnt_t;
164#endif
165
Heiko Schocher0c06db52014-06-24 10:10:03 +0200166/* 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 Schocher5219db82015-10-22 06:19:20 +0200194#define class_register(...) 0
195#define class_unregister(...)
Heiko Schocher0c06db52014-06-24 10:10:03 +0200196#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 Schocher0c06db52014-06-24 10:10:03 +0200203#define __initdata
204#define late_initcall(...)
205
206#define dev_set_name(...) do { } while (0)
207#define device_register(...) 0
Heiko Schocher5219db82015-10-22 06:19:20 +0200208#define device_unregister(...)
Heiko Schocher0c06db52014-06-24 10:10:03 +0200209#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 Schocher0c06db52014-06-24 10:10:03 +0200215#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
229struct work_struct {};
230
231unsigned long copy_from_user(void *dest, const void *src,
232 unsigned long count);
233
Heiko Schocher0c06db52014-06-24 10:10:03 +0200234typedef unused_t spinlock_t;
235typedef 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 Schocher0c06db52014-06-24 10:10:03 +0200258#define __init
259#define __exit
260#define __devinit
261#define __devinitdata
262#define __devinitconst
Heiko Schocher0c06db52014-06-24 10:10:03 +0200263
264#define kthread_create(...) __builtin_return_address(0)
265#define kthread_stop(...) do { } while (0)
266#define wake_up_process(...) do { } while (0)
267
268struct 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)
273struct 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};
282struct mutex { int i; };
283struct kernel_param { int i; };
284
285struct 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 Schocher0c06db52014-06-24 10:10:03 +0200293#define prandom_u32(...) 0
294
295typedef struct {
296 uid_t val;
297} kuid_t;
298
299typedef struct {
300 gid_t val;
301} kgid_t;
302
303/* from include/linux/types.h */
304
Heiko Schocher0c06db52014-06-24 10:10:03 +0200305/**
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 */
310struct callback_head {
311 struct callback_head *next;
312 void (*func)(struct callback_head *head);
313};
314#define rcu_head callback_head
315enum 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 */
326struct 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
349void *kmemdup(const void *src, size_t len, gfp_t gfp);
350
351typedef int irqreturn_t;
352
353struct timer_list {};
354struct notifier_block {};
355
356typedef unsigned long dmaaddr_t;
357
Heiko Schocher0c06db52014-06-24 10:10:03 +0200358#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 I747a0a52015-02-23 18:39:58 +0530367#define IRQ_WAKE_THREAD 2
Heiko Schocher0c06db52014-06-24 10:10:03 +0200368
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 Denk932394a2005-08-17 12:55:25 +0200378#endif