blob: 6e3feb64d2d5702dd41e0b36f2cd214cb523207e [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
Masahiro Yamada7b5ec7e2015-07-13 13:17:07 +090046#define GFP_ATOMIC ((gfp_t) 0)
47#define GFP_KERNEL ((gfp_t) 0)
48#define GFP_NOFS ((gfp_t) 0)
49#define GFP_USER ((gfp_t) 0)
50#define __GFP_NOWARN ((gfp_t) 0)
51#define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */
52
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020053void *kmalloc(size_t size, int flags);
Masahiro Yamada7b5ec7e2015-07-13 13:17:07 +090054
55static inline void *kzalloc(size_t size, gfp_t flags)
56{
57 return kmalloc(size, flags | __GFP_ZERO);
58}
Heiko Schocher9851f522015-10-22 06:19:20 +020059
60static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
61{
62 if (size != 0 && n > SIZE_MAX / size)
63 return NULL;
64 return kmalloc(n * size, flags | __GFP_ZERO);
65}
66
67static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
68{
69 return kmalloc_array(n, size, flags | __GFP_ZERO);
70}
71
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020072#define vmalloc(size) kmalloc(size, 0)
73#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadac5373472015-07-13 13:17:06 +090074static inline void *vzalloc(unsigned long size)
75{
76 return kzalloc(size, 0);
77}
Heiko Schocher9851f522015-10-22 06:19:20 +020078static inline void kfree(const void *block)
79{
80 free((void *)block);
81}
82static inline void vfree(const void *addr)
83{
84 free((void *)addr);
85}
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020086
87struct kmem_cache { int sz; };
88
89struct kmem_cache *get_mem(int element_sz);
90#define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
91void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
Heiko Schocher9851f522015-10-22 06:19:20 +020092static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
93{
94 free(obj);
95}
96static inline void kmem_cache_destroy(struct kmem_cache *cachep)
97{
98 free(cachep);
99}
Stefan Roesee0860d42009-05-12 14:29:39 +0200100
101#define DECLARE_WAITQUEUE(...) do { } while (0)
102#define add_wait_queue(...) do { } while (0)
103#define remove_wait_queue(...) do { } while (0)
William Juul52c07962007-10-31 13:53:06 +0100104
Stefan Roesee0860d42009-05-12 14:29:39 +0200105#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200106
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200107#define PAGE_SIZE 4096
Lijun Pan036f66d2014-06-20 12:17:29 -0500108
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200109/* drivers/char/random.c */
110#define get_random_bytes(...)
111
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200112/* include/linux/leds.h */
113struct led_trigger {};
114
115#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
116enum led_brightness {
117 LED_OFF = 0,
118 LED_HALF = 127,
119 LED_FULL = 255,
120};
121
122static inline void led_trigger_register_simple(const char *name,
123 struct led_trigger **trigger) {}
124static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
125static inline void led_trigger_event(struct led_trigger *trigger,
126 enum led_brightness event) {}
127
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200128/* uapi/linux/limits.h */
129#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
130
131/**
132 * The type used for indexing onto a disc or disc partition.
133 *
134 * Linux always considers sectors to be 512 bytes long independently
135 * of the devices real block size.
136 *
137 * blkcnt_t is the type of the inode's block count.
138 */
139#ifdef CONFIG_LBDAF
140typedef u64 sector_t;
141typedef u64 blkcnt_t;
142#else
143typedef unsigned long sector_t;
144typedef unsigned long blkcnt_t;
145#endif
146
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200147/* module */
148#define THIS_MODULE 0
149#define try_module_get(...) 1
150#define module_put(...) do { } while (0)
151#define module_init(...)
152#define module_exit(...)
153#define EXPORT_SYMBOL(...)
154#define EXPORT_SYMBOL_GPL(...)
155#define module_param(...)
156#define module_param_call(...)
157#define MODULE_PARM_DESC(...)
158#define MODULE_VERSION(...)
159#define MODULE_DESCRIPTION(...)
160#define MODULE_AUTHOR(...)
161#define MODULE_LICENSE(...)
162#define MODULE_ALIAS(...)
163#define __module_get(...)
164
165/* character device */
166#define MKDEV(...) 0
167#define MAJOR(dev) 0
168#define MINOR(dev) 0
169
170#define alloc_chrdev_region(...) 0
171#define unregister_chrdev_region(...)
172
173#define class_create(...) __builtin_return_address(0)
174#define class_create_file(...) 0
Heiko Schocher9851f522015-10-22 06:19:20 +0200175#define class_register(...) 0
176#define class_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200177#define class_remove_file(...)
178#define class_destroy(...)
179#define misc_register(...) 0
180#define misc_deregister(...)
181
182#define blocking_notifier_call_chain(...) 0
183
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200184#define __initdata
185#define late_initcall(...)
186
187#define dev_set_name(...) do { } while (0)
188#define device_register(...) 0
Heiko Schocher9851f522015-10-22 06:19:20 +0200189#define device_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200190#define volume_sysfs_init(...) 0
191#define volume_sysfs_close(...) do { } while (0)
192
193#define init_waitqueue_head(...) do { } while (0)
194#define wait_event_interruptible(...) 0
195#define wake_up_interruptible(...) do { } while (0)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200196#define dump_stack(...) do { } while (0)
197
198#define task_pid_nr(x) 0
199#define set_freezable(...) do { } while (0)
200#define try_to_freeze(...) 0
201#define set_current_state(...) do { } while (0)
202#define kthread_should_stop(...) 0
203#define schedule() do { } while (0)
204
205#define setup_timer(timer, func, data) do {} while (0)
206#define del_timer_sync(timer) do {} while (0)
207#define schedule_work(work) do {} while (0)
208#define INIT_WORK(work, fun) do {} while (0)
209
210struct work_struct {};
211
212unsigned long copy_from_user(void *dest, const void *src,
213 unsigned long count);
214
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200215typedef unused_t spinlock_t;
216typedef int wait_queue_head_t;
217
218#define spin_lock_init(lock) do {} while (0)
219#define spin_lock(lock) do {} while (0)
220#define spin_unlock(lock) do {} while (0)
221#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
222#define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
223
224#define DEFINE_MUTEX(...)
225#define mutex_init(...)
226#define mutex_lock(...)
227#define mutex_unlock(...)
228
229#define init_rwsem(...) do { } while (0)
230#define down_read(...) do { } while (0)
231#define down_write(...) do { } while (0)
232#define down_write_trylock(...) 1
233#define up_read(...) do { } while (0)
234#define up_write(...) do { } while (0)
235
236#define cond_resched() do { } while (0)
237#define yield() do { } while (0)
238
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200239#define __init
240#define __exit
241#define __devinit
242#define __devinitdata
243#define __devinitconst
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200244
245#define kthread_create(...) __builtin_return_address(0)
246#define kthread_stop(...) do { } while (0)
247#define wake_up_process(...) do { } while (0)
248
249struct rw_semaphore { int i; };
250#define down_write(...) do { } while (0)
251#define up_write(...) do { } while (0)
252#define down_read(...) do { } while (0)
253#define up_read(...) do { } while (0)
254struct device {
255 struct device *parent;
256 struct class *class;
257 dev_t devt; /* dev_t, creates the sysfs "dev" */
258 void (*release)(struct device *dev);
259 /* This is used from drivers/usb/musb-new subsystem only */
260 void *driver_data; /* data private to the driver */
261 void *device_data; /* data private to the device */
262};
263struct mutex { int i; };
264struct kernel_param { int i; };
265
266struct cdev {
267 int owner;
268 dev_t dev;
269};
270#define cdev_init(...) do { } while (0)
271#define cdev_add(...) 0
272#define cdev_del(...) do { } while (0)
273
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200274#define prandom_u32(...) 0
275
276typedef struct {
277 uid_t val;
278} kuid_t;
279
280typedef struct {
281 gid_t val;
282} kgid_t;
283
284/* from include/linux/types.h */
285
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200286/**
287 * struct callback_head - callback structure for use with RCU and task_work
288 * @next: next update requests in a list
289 * @func: actual update function to call after the grace period.
290 */
291struct callback_head {
292 struct callback_head *next;
293 void (*func)(struct callback_head *head);
294};
295#define rcu_head callback_head
296enum writeback_sync_modes {
297 WB_SYNC_NONE, /* Don't wait on anything */
298 WB_SYNC_ALL, /* Wait on every mapping */
299};
300
301/* from include/linux/writeback.h */
302/*
303 * A control structure which tells the writeback code what to do. These are
304 * always on the stack, and hence need no locking. They are always initialised
305 * in a manner such that unspecified fields are set to zero.
306 */
307struct writeback_control {
308 long nr_to_write; /* Write this many pages, and decrement
309 this for each page written */
310 long pages_skipped; /* Pages which were not written */
311
312 /*
313 * For a_ops->writepages(): if start or end are non-zero then this is
314 * a hint that the filesystem need only write out the pages inside that
315 * byterange. The byte at `end' is included in the writeout request.
316 */
317 loff_t range_start;
318 loff_t range_end;
319
320 enum writeback_sync_modes sync_mode;
321
322 unsigned for_kupdate:1; /* A kupdate writeback */
323 unsigned for_background:1; /* A background writeback */
324 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
325 unsigned for_reclaim:1; /* Invoked from the page allocator */
326 unsigned range_cyclic:1; /* range_start is cyclic */
327 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
328};
329
330void *kmemdup(const void *src, size_t len, gfp_t gfp);
331
332typedef int irqreturn_t;
333
334struct timer_list {};
335struct notifier_block {};
336
337typedef unsigned long dmaaddr_t;
338
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200339#define pm_runtime_get_sync(dev) do {} while (0)
340#define pm_runtime_put(dev) do {} while (0)
341#define pm_runtime_put_sync(dev) do {} while (0)
342#define pm_runtime_use_autosuspend(dev) do {} while (0)
343#define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
344#define pm_runtime_enable(dev) do {} while (0)
345
346#define IRQ_NONE 0
347#define IRQ_HANDLED 1
Kishon Vijay Abraham I35ffd282015-02-23 18:39:58 +0530348#define IRQ_WAKE_THREAD 2
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200349
350#define dev_set_drvdata(dev, data) do {} while (0)
351
352#define enable_irq(...)
353#define disable_irq(...)
354#define disable_irq_wake(irq) do {} while (0)
355#define enable_irq_wake(irq) -EINVAL
356#define free_irq(irq, data) do {} while (0)
357#define request_irq(nr, f, flags, nm, data) 0
358
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200359#endif