blob: 363b2b94255b4df77399e776e1138b007750af94 [file] [log] [blame]
Wolfgang Denk932394a2005-08-17 12:55:25 +02001#ifndef _LINUX_COMPAT_H_
2#define _LINUX_COMPAT_H_
3
Oleksandr Andrushchenko242587d2020-08-06 12:42:51 +03004#include <console.h>
Simon Glassc3dc39a2020-05-10 11:39:55 -06005#include <log.h>
Heiko Schocher0c06db52014-06-24 10:10:03 +02006#include <malloc.h>
Oleksandr Andrushchenko242587d2020-08-06 12:42:51 +03007
8#include <asm/processor.h>
9
Heiko Schocher0c06db52014-06-24 10:10:03 +020010#include <linux/types.h>
11#include <linux/err.h>
Heiko Schocher5219db82015-10-22 06:19:20 +020012#include <linux/kernel.h>
Heiko Schocher0c06db52014-06-24 10:10:03 +020013
Oleksandr Andrushchenko242587d2020-08-06 12:42:51 +030014#ifdef CONFIG_XEN
15#include <xen/events.h>
16#endif
17
Heiko Schocher0c06db52014-06-24 10:10:03 +020018struct unused {};
19typedef struct unused unused_t;
20
21struct p_current{
22 int pid;
23};
24
25extern struct p_current *current;
26
Masahiro Yamadac898cba2017-09-26 11:58:29 +090027/* avoid conflict with <dm/device.h> */
28#ifdef dev_dbg
29#undef dev_dbg
30#endif
31#ifdef dev_vdbg
32#undef dev_vdbg
33#endif
34#ifdef dev_info
35#undef dev_info
36#endif
37#ifdef dev_err
38#undef dev_err
39#endif
40#ifdef dev_warn
41#undef dev_warn
42#endif
43
Wu, Josh2f96b062013-07-03 11:11:47 +080044#define dev_dbg(dev, fmt, args...) \
45 debug(fmt, ##args)
46#define dev_vdbg(dev, fmt, args...) \
47 debug(fmt, ##args)
48#define dev_info(dev, fmt, args...) \
49 printf(fmt, ##args)
50#define dev_err(dev, fmt, args...) \
51 printf(fmt, ##args)
Andreas Bießmann88a7fff2016-06-04 22:27:22 +020052#define dev_warn(dev, fmt, args...) \
53 printf(fmt, ##args)
Wolfgang Denk932394a2005-08-17 12:55:25 +020054
Bin Mengb06d76f2018-07-26 03:15:58 -070055#define netdev_emerg(dev, fmt, args...) \
56 printf(fmt, ##args)
57#define netdev_alert(dev, fmt, args...) \
58 printf(fmt, ##args)
59#define netdev_crit(dev, fmt, args...) \
60 printf(fmt, ##args)
61#define netdev_err(dev, fmt, args...) \
62 printf(fmt, ##args)
63#define netdev_warn(dev, fmt, args...) \
64 printf(fmt, ##args)
65#define netdev_notice(dev, fmt, args...) \
66 printf(fmt, ##args)
67#define netdev_info(dev, fmt, args...) \
68 printf(fmt, ##args)
69#define netdev_dbg(dev, fmt, args...) \
70 debug(fmt, ##args)
71#define netdev_vdbg(dev, fmt, args...) \
72 debug(fmt, ##args)
73
Masahiro Yamada6b9f9ea2015-07-13 13:17:07 +090074#define GFP_ATOMIC ((gfp_t) 0)
75#define GFP_KERNEL ((gfp_t) 0)
76#define GFP_NOFS ((gfp_t) 0)
77#define GFP_USER ((gfp_t) 0)
78#define __GFP_NOWARN ((gfp_t) 0)
79#define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */
80
Heiko Schocher0c06db52014-06-24 10:10:03 +020081void *kmalloc(size_t size, int flags);
Masahiro Yamada6b9f9ea2015-07-13 13:17:07 +090082
83static inline void *kzalloc(size_t size, gfp_t flags)
84{
85 return kmalloc(size, flags | __GFP_ZERO);
86}
Heiko Schocher5219db82015-10-22 06:19:20 +020087
88static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
89{
90 if (size != 0 && n > SIZE_MAX / size)
91 return NULL;
92 return kmalloc(n * size, flags | __GFP_ZERO);
93}
94
95static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
96{
97 return kmalloc_array(n, size, flags | __GFP_ZERO);
98}
99
Heiko Schocher0c06db52014-06-24 10:10:03 +0200100#define vmalloc(size) kmalloc(size, 0)
101#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadaebc33282015-07-13 13:17:06 +0900102static inline void *vzalloc(unsigned long size)
103{
104 return kzalloc(size, 0);
105}
Heiko Schocher5219db82015-10-22 06:19:20 +0200106static inline void kfree(const void *block)
107{
108 free((void *)block);
109}
110static inline void vfree(const void *addr)
111{
112 free((void *)addr);
113}
Heiko Schocher0c06db52014-06-24 10:10:03 +0200114
115struct kmem_cache { int sz; };
116
117struct kmem_cache *get_mem(int element_sz);
118#define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
119void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
Heiko Schocher5219db82015-10-22 06:19:20 +0200120static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
121{
122 free(obj);
123}
124static inline void kmem_cache_destroy(struct kmem_cache *cachep)
125{
126 free(cachep);
127}
William Juulcfa460a2007-10-31 13:53:06 +0100128
Stefan Roese0a572652009-05-12 14:29:39 +0200129#define DECLARE_WAITQUEUE(...) do { } while (0)
130#define add_wait_queue(...) do { } while (0)
131#define remove_wait_queue(...) do { } while (0)
132
Oleksandr Andrushchenko242587d2020-08-06 12:42:51 +0300133#ifndef CONFIG_XEN
134#define eventchn_poll()
135#endif
136
137#define __wait_event_timeout(condition, timeout, ret) \
138({ \
139 ulong __ret = ret; /* explicit shadow */ \
140 ulong start = get_timer(0); \
141 for (;;) { \
142 eventchn_poll(); \
143 if (condition) { \
144 __ret = 1; \
145 break; \
146 } \
147 if ((get_timer(start) > timeout) || ctrlc()) { \
148 __ret = 0; \
149 break; \
150 } \
151 cpu_relax(); \
152 } \
153 __ret; \
154})
155
156/**
157 * wait_event_timeout() - Wait until the event occurs before the timeout.
158 * @wr_head: The wait queue to wait on.
159 * @condition: Expression for the event to wait for.
160 * @timeout: Maximum waiting time.
161 *
162 * We wait until the @condition evaluates to %true (succeed) or
163 * %false (@timeout elapsed).
164 *
165 * Return:
166 * 0 - if the @condition evaluated to %false after the @timeout elapsed
167 * 1 - if the @condition evaluated to %true
168 */
169#define wait_event_timeout(wq_head, condition, timeout) \
170({ \
171 ulong __ret; \
172 if (condition) \
173 __ret = 1; \
174 else \
175 __ret = __wait_event_timeout(condition, timeout, __ret);\
176 __ret; \
177})
178
Stefan Roese0a572652009-05-12 14:29:39 +0200179#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
Wolfgang Denk932394a2005-08-17 12:55:25 +0200180
Simon Glassf2176512020-02-03 07:36:17 -0700181/* This is also defined in ARMv8's mmu.h */
182#ifndef PAGE_SIZE
Wolfgang Denk932394a2005-08-17 12:55:25 +0200183#define PAGE_SIZE 4096
Simon Glassf2176512020-02-03 07:36:17 -0700184#endif
Lijun Pan8f2df5d2014-06-20 12:17:29 -0500185
Heiko Schocher0c06db52014-06-24 10:10:03 +0200186/* drivers/char/random.c */
187#define get_random_bytes(...)
188
Heiko Schocher0c06db52014-06-24 10:10:03 +0200189/* include/linux/leds.h */
190struct led_trigger {};
191
192#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
193enum led_brightness {
194 LED_OFF = 0,
195 LED_HALF = 127,
196 LED_FULL = 255,
197};
198
199static inline void led_trigger_register_simple(const char *name,
200 struct led_trigger **trigger) {}
201static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
202static inline void led_trigger_event(struct led_trigger *trigger,
203 enum led_brightness event) {}
204
Heiko Schocher0c06db52014-06-24 10:10:03 +0200205/* uapi/linux/limits.h */
206#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
207
208/**
209 * The type used for indexing onto a disc or disc partition.
210 *
211 * Linux always considers sectors to be 512 bytes long independently
212 * of the devices real block size.
213 *
214 * blkcnt_t is the type of the inode's block count.
215 */
216#ifdef CONFIG_LBDAF
217typedef u64 sector_t;
218typedef u64 blkcnt_t;
219#else
220typedef unsigned long sector_t;
221typedef unsigned long blkcnt_t;
222#endif
223
Heiko Schocher0c06db52014-06-24 10:10:03 +0200224/* module */
225#define THIS_MODULE 0
226#define try_module_get(...) 1
227#define module_put(...) do { } while (0)
228#define module_init(...)
229#define module_exit(...)
230#define EXPORT_SYMBOL(...)
231#define EXPORT_SYMBOL_GPL(...)
232#define module_param(...)
233#define module_param_call(...)
234#define MODULE_PARM_DESC(...)
235#define MODULE_VERSION(...)
236#define MODULE_DESCRIPTION(...)
237#define MODULE_AUTHOR(...)
238#define MODULE_LICENSE(...)
239#define MODULE_ALIAS(...)
240#define __module_get(...)
241
242/* character device */
243#define MKDEV(...) 0
244#define MAJOR(dev) 0
245#define MINOR(dev) 0
246
247#define alloc_chrdev_region(...) 0
248#define unregister_chrdev_region(...)
249
250#define class_create(...) __builtin_return_address(0)
251#define class_create_file(...) 0
Heiko Schocher5219db82015-10-22 06:19:20 +0200252#define class_register(...) 0
253#define class_unregister(...)
Heiko Schocher0c06db52014-06-24 10:10:03 +0200254#define class_remove_file(...)
255#define class_destroy(...)
256#define misc_register(...) 0
257#define misc_deregister(...)
258
259#define blocking_notifier_call_chain(...) 0
260
Heiko Schocher0c06db52014-06-24 10:10:03 +0200261#define __initdata
262#define late_initcall(...)
263
264#define dev_set_name(...) do { } while (0)
265#define device_register(...) 0
Heiko Schocher5219db82015-10-22 06:19:20 +0200266#define device_unregister(...)
Heiko Schocher0c06db52014-06-24 10:10:03 +0200267#define volume_sysfs_init(...) 0
268#define volume_sysfs_close(...) do { } while (0)
269
270#define init_waitqueue_head(...) do { } while (0)
271#define wait_event_interruptible(...) 0
272#define wake_up_interruptible(...) do { } while (0)
Heiko Schocher0c06db52014-06-24 10:10:03 +0200273#define dump_stack(...) do { } while (0)
274
275#define task_pid_nr(x) 0
276#define set_freezable(...) do { } while (0)
277#define try_to_freeze(...) 0
278#define set_current_state(...) do { } while (0)
279#define kthread_should_stop(...) 0
280#define schedule() do { } while (0)
281
282#define setup_timer(timer, func, data) do {} while (0)
283#define del_timer_sync(timer) do {} while (0)
284#define schedule_work(work) do {} while (0)
285#define INIT_WORK(work, fun) do {} while (0)
286
287struct work_struct {};
288
289unsigned long copy_from_user(void *dest, const void *src,
290 unsigned long count);
291
Heiko Schocher0c06db52014-06-24 10:10:03 +0200292typedef unused_t spinlock_t;
293typedef int wait_queue_head_t;
294
295#define spin_lock_init(lock) do {} while (0)
296#define spin_lock(lock) do {} while (0)
297#define spin_unlock(lock) do {} while (0)
298#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
299#define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
300
301#define DEFINE_MUTEX(...)
302#define mutex_init(...)
303#define mutex_lock(...)
304#define mutex_unlock(...)
305
306#define init_rwsem(...) do { } while (0)
307#define down_read(...) do { } while (0)
308#define down_write(...) do { } while (0)
309#define down_write_trylock(...) 1
310#define up_read(...) do { } while (0)
311#define up_write(...) do { } while (0)
312
313#define cond_resched() do { } while (0)
314#define yield() do { } while (0)
315
Heiko Schocher0c06db52014-06-24 10:10:03 +0200316#define __init
317#define __exit
318#define __devinit
319#define __devinitdata
320#define __devinitconst
Heiko Schocher0c06db52014-06-24 10:10:03 +0200321
322#define kthread_create(...) __builtin_return_address(0)
323#define kthread_stop(...) do { } while (0)
324#define wake_up_process(...) do { } while (0)
325
326struct rw_semaphore { int i; };
327#define down_write(...) do { } while (0)
328#define up_write(...) do { } while (0)
329#define down_read(...) do { } while (0)
330#define up_read(...) do { } while (0)
331struct device {
332 struct device *parent;
333 struct class *class;
334 dev_t devt; /* dev_t, creates the sysfs "dev" */
335 void (*release)(struct device *dev);
336 /* This is used from drivers/usb/musb-new subsystem only */
337 void *driver_data; /* data private to the driver */
338 void *device_data; /* data private to the device */
339};
340struct mutex { int i; };
341struct kernel_param { int i; };
342
343struct cdev {
344 int owner;
345 dev_t dev;
346};
347#define cdev_init(...) do { } while (0)
348#define cdev_add(...) 0
349#define cdev_del(...) do { } while (0)
350
Heiko Schocher0c06db52014-06-24 10:10:03 +0200351#define prandom_u32(...) 0
352
353typedef struct {
354 uid_t val;
355} kuid_t;
356
357typedef struct {
358 gid_t val;
359} kgid_t;
360
361/* from include/linux/types.h */
362
Heiko Schocher0c06db52014-06-24 10:10:03 +0200363/**
364 * struct callback_head - callback structure for use with RCU and task_work
365 * @next: next update requests in a list
366 * @func: actual update function to call after the grace period.
367 */
368struct callback_head {
369 struct callback_head *next;
370 void (*func)(struct callback_head *head);
371};
372#define rcu_head callback_head
373enum writeback_sync_modes {
374 WB_SYNC_NONE, /* Don't wait on anything */
375 WB_SYNC_ALL, /* Wait on every mapping */
376};
377
378/* from include/linux/writeback.h */
379/*
380 * A control structure which tells the writeback code what to do. These are
381 * always on the stack, and hence need no locking. They are always initialised
382 * in a manner such that unspecified fields are set to zero.
383 */
384struct writeback_control {
385 long nr_to_write; /* Write this many pages, and decrement
386 this for each page written */
387 long pages_skipped; /* Pages which were not written */
388
389 /*
390 * For a_ops->writepages(): if start or end are non-zero then this is
391 * a hint that the filesystem need only write out the pages inside that
392 * byterange. The byte at `end' is included in the writeout request.
393 */
394 loff_t range_start;
395 loff_t range_end;
396
397 enum writeback_sync_modes sync_mode;
398
399 unsigned for_kupdate:1; /* A kupdate writeback */
400 unsigned for_background:1; /* A background writeback */
401 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
402 unsigned for_reclaim:1; /* Invoked from the page allocator */
403 unsigned range_cyclic:1; /* range_start is cyclic */
404 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
405};
406
407void *kmemdup(const void *src, size_t len, gfp_t gfp);
408
409typedef int irqreturn_t;
410
411struct timer_list {};
412struct notifier_block {};
413
414typedef unsigned long dmaaddr_t;
415
Heiko Schocher0c06db52014-06-24 10:10:03 +0200416#define pm_runtime_get_sync(dev) do {} while (0)
417#define pm_runtime_put(dev) do {} while (0)
418#define pm_runtime_put_sync(dev) do {} while (0)
419#define pm_runtime_use_autosuspend(dev) do {} while (0)
420#define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
421#define pm_runtime_enable(dev) do {} while (0)
422
423#define IRQ_NONE 0
424#define IRQ_HANDLED 1
Kishon Vijay Abraham I747a0a52015-02-23 18:39:58 +0530425#define IRQ_WAKE_THREAD 2
Heiko Schocher0c06db52014-06-24 10:10:03 +0200426
427#define dev_set_drvdata(dev, data) do {} while (0)
428
429#define enable_irq(...)
430#define disable_irq(...)
431#define disable_irq_wake(irq) do {} while (0)
432#define enable_irq_wake(irq) -EINVAL
433#define free_irq(irq, data) do {} while (0)
434#define request_irq(nr, f, flags, nm, data) 0
435
Wolfgang Denk932394a2005-08-17 12:55:25 +0200436#endif