blob: 171188a76f0c1d670472050f060ff0947ca696f5 [file] [log] [blame]
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +02001#ifndef _LINUX_COMPAT_H_
2#define _LINUX_COMPAT_H_
3
Heiko Schocher4f7a9a32014-06-24 10:10:03 +02004#include <malloc.h>
5#include <linux/types.h>
6#include <linux/err.h>
Heiko Schocher9851f522015-10-22 06:19:20 +02007#include <linux/kernel.h>
Heiko Schocher4f7a9a32014-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 Yamada9e74eb52017-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, Joshba6babf2013-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ßmann317a3822016-06-04 22:27:22 +020043#define dev_warn(dev, fmt, args...) \
44 printf(fmt, ##args)
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020045
Bin Meng5efc2c42018-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 Yamada7b5ec7e2015-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 Schocher4f7a9a32014-06-24 10:10:03 +020072void *kmalloc(size_t size, int flags);
Masahiro Yamada7b5ec7e2015-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 Schocher9851f522015-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 Schocher4f7a9a32014-06-24 10:10:03 +020091#define vmalloc(size) kmalloc(size, 0)
92#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadac5373472015-07-13 13:17:06 +090093static inline void *vzalloc(unsigned long size)
94{
95 return kzalloc(size, 0);
96}
Heiko Schocher9851f522015-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 Schocher4f7a9a32014-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 Schocher9851f522015-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}
Stefan Roesee0860d42009-05-12 14:29:39 +0200119
120#define DECLARE_WAITQUEUE(...) do { } while (0)
121#define add_wait_queue(...) do { } while (0)
122#define remove_wait_queue(...) do { } while (0)
William Juul52c07962007-10-31 13:53:06 +0100123
Stefan Roesee0860d42009-05-12 14:29:39 +0200124#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200125
Simon Glassfb6f4822020-02-03 07:36:17 -0700126/* This is also defined in ARMv8's mmu.h */
127#ifndef PAGE_SIZE
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200128#define PAGE_SIZE 4096
Simon Glassfb6f4822020-02-03 07:36:17 -0700129#endif
Lijun Pan036f66d2014-06-20 12:17:29 -0500130
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200131/* drivers/char/random.c */
132#define get_random_bytes(...)
133
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200134/* include/linux/leds.h */
135struct led_trigger {};
136
137#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
138enum led_brightness {
139 LED_OFF = 0,
140 LED_HALF = 127,
141 LED_FULL = 255,
142};
143
144static inline void led_trigger_register_simple(const char *name,
145 struct led_trigger **trigger) {}
146static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
147static inline void led_trigger_event(struct led_trigger *trigger,
148 enum led_brightness event) {}
149
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200150/* 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
162typedef u64 sector_t;
163typedef u64 blkcnt_t;
164#else
165typedef unsigned long sector_t;
166typedef unsigned long blkcnt_t;
167#endif
168
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200169/* 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 Schocher9851f522015-10-22 06:19:20 +0200197#define class_register(...) 0
198#define class_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200199#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 Schocher4f7a9a32014-06-24 10:10:03 +0200206#define __initdata
207#define late_initcall(...)
208
209#define dev_set_name(...) do { } while (0)
210#define device_register(...) 0
Heiko Schocher9851f522015-10-22 06:19:20 +0200211#define device_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200212#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 Schocher4f7a9a32014-06-24 10:10:03 +0200218#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
232struct work_struct {};
233
234unsigned long copy_from_user(void *dest, const void *src,
235 unsigned long count);
236
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200237typedef unused_t spinlock_t;
238typedef 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 Schocher4f7a9a32014-06-24 10:10:03 +0200261#define __init
262#define __exit
263#define __devinit
264#define __devinitdata
265#define __devinitconst
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200266
267#define kthread_create(...) __builtin_return_address(0)
268#define kthread_stop(...) do { } while (0)
269#define wake_up_process(...) do { } while (0)
270
271struct 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)
276struct 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};
285struct mutex { int i; };
286struct kernel_param { int i; };
287
288struct 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 Schocher4f7a9a32014-06-24 10:10:03 +0200296#define prandom_u32(...) 0
297
298typedef struct {
299 uid_t val;
300} kuid_t;
301
302typedef struct {
303 gid_t val;
304} kgid_t;
305
306/* from include/linux/types.h */
307
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200308/**
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 */
313struct callback_head {
314 struct callback_head *next;
315 void (*func)(struct callback_head *head);
316};
317#define rcu_head callback_head
318enum 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 */
329struct 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
352void *kmemdup(const void *src, size_t len, gfp_t gfp);
353
354typedef int irqreturn_t;
355
356struct timer_list {};
357struct notifier_block {};
358
359typedef unsigned long dmaaddr_t;
360
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200361#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 I35ffd282015-02-23 18:39:58 +0530370#define IRQ_WAKE_THREAD 2
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200371
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 Denk2f9b7e42005-08-17 12:55:25 +0200381#endif