blob: 8711fe2b48c46256fd1a7cd1b7535e77a7d0bd29 [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
Masahiro Yamada6b9f9ea2015-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 Schocher0c06db52014-06-24 10:10:03 +020053void *kmalloc(size_t size, int flags);
Masahiro Yamada6b9f9ea2015-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 Schocher5219db82015-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 Schocher0c06db52014-06-24 10:10:03 +020072#define vmalloc(size) kmalloc(size, 0)
73#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadaebc33282015-07-13 13:17:06 +090074static inline void *vzalloc(unsigned long size)
75{
76 return kzalloc(size, 0);
77}
Heiko Schocher5219db82015-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 Schocher0c06db52014-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 Schocher5219db82015-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}
William Juulcfa460a2007-10-31 13:53:06 +0100100
Stefan Roese0a572652009-05-12 14:29:39 +0200101#define DECLARE_WAITQUEUE(...) do { } while (0)
102#define add_wait_queue(...) do { } while (0)
103#define remove_wait_queue(...) do { } while (0)
104
105#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
Wolfgang Denk932394a2005-08-17 12:55:25 +0200106
Wolfgang Denk932394a2005-08-17 12:55:25 +0200107#define PAGE_SIZE 4096
Lijun Pan8f2df5d2014-06-20 12:17:29 -0500108
Heiko Schocher0c06db52014-06-24 10:10:03 +0200109/* drivers/char/random.c */
110#define get_random_bytes(...)
111
Heiko Schocher0c06db52014-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 Schocher0c06db52014-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 Schocher0c06db52014-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 Schocher5219db82015-10-22 06:19:20 +0200175#define class_register(...) 0
176#define class_unregister(...)
Heiko Schocher0c06db52014-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 Schocher0c06db52014-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 Schocher5219db82015-10-22 06:19:20 +0200189#define device_unregister(...)
Heiko Schocher0c06db52014-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)
196#define print_hex_dump(...) do { } while (0)
197#define dump_stack(...) do { } while (0)
198
199#define task_pid_nr(x) 0
200#define set_freezable(...) do { } while (0)
201#define try_to_freeze(...) 0
202#define set_current_state(...) do { } while (0)
203#define kthread_should_stop(...) 0
204#define schedule() do { } while (0)
205
206#define setup_timer(timer, func, data) do {} while (0)
207#define del_timer_sync(timer) do {} while (0)
208#define schedule_work(work) do {} while (0)
209#define INIT_WORK(work, fun) do {} while (0)
210
211struct work_struct {};
212
213unsigned long copy_from_user(void *dest, const void *src,
214 unsigned long count);
215
Heiko Schocher0c06db52014-06-24 10:10:03 +0200216typedef unused_t spinlock_t;
217typedef int wait_queue_head_t;
218
219#define spin_lock_init(lock) do {} while (0)
220#define spin_lock(lock) do {} while (0)
221#define spin_unlock(lock) do {} while (0)
222#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
223#define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
224
225#define DEFINE_MUTEX(...)
226#define mutex_init(...)
227#define mutex_lock(...)
228#define mutex_unlock(...)
229
230#define init_rwsem(...) do { } while (0)
231#define down_read(...) do { } while (0)
232#define down_write(...) do { } while (0)
233#define down_write_trylock(...) 1
234#define up_read(...) do { } while (0)
235#define up_write(...) do { } while (0)
236
237#define cond_resched() do { } while (0)
238#define yield() do { } while (0)
239
Heiko Schocher0c06db52014-06-24 10:10:03 +0200240#define __init
241#define __exit
242#define __devinit
243#define __devinitdata
244#define __devinitconst
Heiko Schocher0c06db52014-06-24 10:10:03 +0200245
246#define kthread_create(...) __builtin_return_address(0)
247#define kthread_stop(...) do { } while (0)
248#define wake_up_process(...) do { } while (0)
249
250struct rw_semaphore { int i; };
251#define down_write(...) do { } while (0)
252#define up_write(...) do { } while (0)
253#define down_read(...) do { } while (0)
254#define up_read(...) do { } while (0)
255struct device {
256 struct device *parent;
257 struct class *class;
258 dev_t devt; /* dev_t, creates the sysfs "dev" */
259 void (*release)(struct device *dev);
260 /* This is used from drivers/usb/musb-new subsystem only */
261 void *driver_data; /* data private to the driver */
262 void *device_data; /* data private to the device */
263};
264struct mutex { int i; };
265struct kernel_param { int i; };
266
267struct cdev {
268 int owner;
269 dev_t dev;
270};
271#define cdev_init(...) do { } while (0)
272#define cdev_add(...) 0
273#define cdev_del(...) do { } while (0)
274
Heiko Schocher0c06db52014-06-24 10:10:03 +0200275#define prandom_u32(...) 0
276
277typedef struct {
278 uid_t val;
279} kuid_t;
280
281typedef struct {
282 gid_t val;
283} kgid_t;
284
285/* from include/linux/types.h */
286
Heiko Schocher0c06db52014-06-24 10:10:03 +0200287/**
288 * struct callback_head - callback structure for use with RCU and task_work
289 * @next: next update requests in a list
290 * @func: actual update function to call after the grace period.
291 */
292struct callback_head {
293 struct callback_head *next;
294 void (*func)(struct callback_head *head);
295};
296#define rcu_head callback_head
297enum writeback_sync_modes {
298 WB_SYNC_NONE, /* Don't wait on anything */
299 WB_SYNC_ALL, /* Wait on every mapping */
300};
301
302/* from include/linux/writeback.h */
303/*
304 * A control structure which tells the writeback code what to do. These are
305 * always on the stack, and hence need no locking. They are always initialised
306 * in a manner such that unspecified fields are set to zero.
307 */
308struct writeback_control {
309 long nr_to_write; /* Write this many pages, and decrement
310 this for each page written */
311 long pages_skipped; /* Pages which were not written */
312
313 /*
314 * For a_ops->writepages(): if start or end are non-zero then this is
315 * a hint that the filesystem need only write out the pages inside that
316 * byterange. The byte at `end' is included in the writeout request.
317 */
318 loff_t range_start;
319 loff_t range_end;
320
321 enum writeback_sync_modes sync_mode;
322
323 unsigned for_kupdate:1; /* A kupdate writeback */
324 unsigned for_background:1; /* A background writeback */
325 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
326 unsigned for_reclaim:1; /* Invoked from the page allocator */
327 unsigned range_cyclic:1; /* range_start is cyclic */
328 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
329};
330
331void *kmemdup(const void *src, size_t len, gfp_t gfp);
332
333typedef int irqreturn_t;
334
335struct timer_list {};
336struct notifier_block {};
337
338typedef unsigned long dmaaddr_t;
339
Heiko Schocher0c06db52014-06-24 10:10:03 +0200340#define pm_runtime_get_sync(dev) do {} while (0)
341#define pm_runtime_put(dev) do {} while (0)
342#define pm_runtime_put_sync(dev) do {} while (0)
343#define pm_runtime_use_autosuspend(dev) do {} while (0)
344#define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
345#define pm_runtime_enable(dev) do {} while (0)
346
347#define IRQ_NONE 0
348#define IRQ_HANDLED 1
Kishon Vijay Abraham I747a0a52015-02-23 18:39:58 +0530349#define IRQ_WAKE_THREAD 2
Heiko Schocher0c06db52014-06-24 10:10:03 +0200350
351#define dev_set_drvdata(dev, data) do {} while (0)
352
353#define enable_irq(...)
354#define disable_irq(...)
355#define disable_irq_wake(irq) do {} while (0)
356#define enable_irq_wake(irq) -EINVAL
357#define free_irq(irq, data) do {} while (0)
358#define request_irq(nr, f, flags, nm, data) 0
359
Wolfgang Denk932394a2005-08-17 12:55:25 +0200360#endif