blob: d129780312281635d28930632ff743eb1d0a5091 [file] [log] [blame]
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +02001#ifndef _LINUX_COMPAT_H_
2#define _LINUX_COMPAT_H_
3
Oleksandr Andrushchenko0c09ade2020-08-06 12:42:51 +03004#include <console.h>
Simon Glass1e268642020-05-10 11:39:55 -06005#include <log.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +02006#include <malloc.h>
Oleksandr Andrushchenko0c09ade2020-08-06 12:42:51 +03007
8#include <asm/processor.h>
9
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020010#include <linux/types.h>
11#include <linux/err.h>
Heiko Schocher9851f522015-10-22 06:19:20 +020012#include <linux/kernel.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020013
Oleksandr Andrushchenko0c09ade2020-08-06 12:42:51 +030014#ifdef CONFIG_XEN
15#include <xen/events.h>
16#endif
17
Heiko Schocher4f7a9a32014-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 Yamada9e74eb52017-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, Joshba6babf2013-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ßmann317a3822016-06-04 22:27:22 +020052#define dev_warn(dev, fmt, args...) \
53 printf(fmt, ##args)
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020054
Masahiro Yamada7b5ec7e2015-07-13 13:17:07 +090055#define GFP_ATOMIC ((gfp_t) 0)
56#define GFP_KERNEL ((gfp_t) 0)
57#define GFP_NOFS ((gfp_t) 0)
58#define GFP_USER ((gfp_t) 0)
59#define __GFP_NOWARN ((gfp_t) 0)
60#define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */
61
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020062void *kmalloc(size_t size, int flags);
Masahiro Yamada7b5ec7e2015-07-13 13:17:07 +090063
64static inline void *kzalloc(size_t size, gfp_t flags)
65{
66 return kmalloc(size, flags | __GFP_ZERO);
67}
Heiko Schocher9851f522015-10-22 06:19:20 +020068
69static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70{
71 if (size != 0 && n > SIZE_MAX / size)
72 return NULL;
73 return kmalloc(n * size, flags | __GFP_ZERO);
74}
75
76static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
77{
78 return kmalloc_array(n, size, flags | __GFP_ZERO);
79}
80
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020081#define vmalloc(size) kmalloc(size, 0)
82#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadac5373472015-07-13 13:17:06 +090083static inline void *vzalloc(unsigned long size)
84{
85 return kzalloc(size, 0);
86}
Heiko Schocher9851f522015-10-22 06:19:20 +020087static inline void kfree(const void *block)
88{
89 free((void *)block);
90}
91static inline void vfree(const void *addr)
92{
93 free((void *)addr);
94}
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020095
96struct kmem_cache { int sz; };
97
98struct kmem_cache *get_mem(int element_sz);
99#define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
100void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
Heiko Schocher9851f522015-10-22 06:19:20 +0200101static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
102{
103 free(obj);
104}
105static inline void kmem_cache_destroy(struct kmem_cache *cachep)
106{
107 free(cachep);
108}
Stefan Roesee0860d42009-05-12 14:29:39 +0200109
110#define DECLARE_WAITQUEUE(...) do { } while (0)
111#define add_wait_queue(...) do { } while (0)
112#define remove_wait_queue(...) do { } while (0)
William Juul52c07962007-10-31 13:53:06 +0100113
Oleksandr Andrushchenko0c09ade2020-08-06 12:42:51 +0300114#ifndef CONFIG_XEN
115#define eventchn_poll()
116#endif
117
118#define __wait_event_timeout(condition, timeout, ret) \
119({ \
120 ulong __ret = ret; /* explicit shadow */ \
121 ulong start = get_timer(0); \
122 for (;;) { \
123 eventchn_poll(); \
124 if (condition) { \
125 __ret = 1; \
126 break; \
127 } \
128 if ((get_timer(start) > timeout) || ctrlc()) { \
129 __ret = 0; \
130 break; \
131 } \
132 cpu_relax(); \
133 } \
134 __ret; \
135})
136
137/**
138 * wait_event_timeout() - Wait until the event occurs before the timeout.
139 * @wr_head: The wait queue to wait on.
140 * @condition: Expression for the event to wait for.
141 * @timeout: Maximum waiting time.
142 *
143 * We wait until the @condition evaluates to %true (succeed) or
144 * %false (@timeout elapsed).
145 *
146 * Return:
147 * 0 - if the @condition evaluated to %false after the @timeout elapsed
148 * 1 - if the @condition evaluated to %true
149 */
150#define wait_event_timeout(wq_head, condition, timeout) \
151({ \
152 ulong __ret; \
153 if (condition) \
154 __ret = 1; \
155 else \
156 __ret = __wait_event_timeout(condition, timeout, __ret);\
157 __ret; \
158})
159
Stefan Roesee0860d42009-05-12 14:29:39 +0200160#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200161
Simon Glassfb6f4822020-02-03 07:36:17 -0700162/* This is also defined in ARMv8's mmu.h */
163#ifndef PAGE_SIZE
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200164#define PAGE_SIZE 4096
Simon Glassfb6f4822020-02-03 07:36:17 -0700165#endif
Lijun Pan036f66d2014-06-20 12:17:29 -0500166
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200167/* drivers/char/random.c */
168#define get_random_bytes(...)
169
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200170/* include/linux/leds.h */
171struct led_trigger {};
172
173#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
174enum led_brightness {
175 LED_OFF = 0,
176 LED_HALF = 127,
177 LED_FULL = 255,
178};
179
180static inline void led_trigger_register_simple(const char *name,
181 struct led_trigger **trigger) {}
182static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
183static inline void led_trigger_event(struct led_trigger *trigger,
184 enum led_brightness event) {}
185
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200186/* uapi/linux/limits.h */
187#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
188
189/**
190 * The type used for indexing onto a disc or disc partition.
191 *
192 * Linux always considers sectors to be 512 bytes long independently
193 * of the devices real block size.
194 *
195 * blkcnt_t is the type of the inode's block count.
196 */
197#ifdef CONFIG_LBDAF
198typedef u64 sector_t;
199typedef u64 blkcnt_t;
200#else
201typedef unsigned long sector_t;
202typedef unsigned long blkcnt_t;
203#endif
204
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200205/* module */
206#define THIS_MODULE 0
207#define try_module_get(...) 1
208#define module_put(...) do { } while (0)
209#define module_init(...)
210#define module_exit(...)
211#define EXPORT_SYMBOL(...)
212#define EXPORT_SYMBOL_GPL(...)
213#define module_param(...)
214#define module_param_call(...)
215#define MODULE_PARM_DESC(...)
216#define MODULE_VERSION(...)
217#define MODULE_DESCRIPTION(...)
218#define MODULE_AUTHOR(...)
219#define MODULE_LICENSE(...)
220#define MODULE_ALIAS(...)
221#define __module_get(...)
222
223/* character device */
224#define MKDEV(...) 0
225#define MAJOR(dev) 0
226#define MINOR(dev) 0
227
228#define alloc_chrdev_region(...) 0
229#define unregister_chrdev_region(...)
230
231#define class_create(...) __builtin_return_address(0)
232#define class_create_file(...) 0
Heiko Schocher9851f522015-10-22 06:19:20 +0200233#define class_register(...) 0
234#define class_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200235#define class_remove_file(...)
236#define class_destroy(...)
237#define misc_register(...) 0
238#define misc_deregister(...)
239
240#define blocking_notifier_call_chain(...) 0
241
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200242#define __initdata
243#define late_initcall(...)
244
245#define dev_set_name(...) do { } while (0)
246#define device_register(...) 0
Heiko Schocher9851f522015-10-22 06:19:20 +0200247#define device_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200248#define volume_sysfs_init(...) 0
249#define volume_sysfs_close(...) do { } while (0)
250
251#define init_waitqueue_head(...) do { } while (0)
252#define wait_event_interruptible(...) 0
253#define wake_up_interruptible(...) do { } while (0)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200254#define dump_stack(...) do { } while (0)
255
256#define task_pid_nr(x) 0
257#define set_freezable(...) do { } while (0)
258#define try_to_freeze(...) 0
259#define set_current_state(...) do { } while (0)
260#define kthread_should_stop(...) 0
261#define schedule() do { } while (0)
262
263#define setup_timer(timer, func, data) do {} while (0)
264#define del_timer_sync(timer) do {} while (0)
265#define schedule_work(work) do {} while (0)
266#define INIT_WORK(work, fun) do {} while (0)
267
268struct work_struct {};
269
270unsigned long copy_from_user(void *dest, const void *src,
271 unsigned long count);
272
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200273typedef unused_t spinlock_t;
274typedef int wait_queue_head_t;
275
276#define spin_lock_init(lock) do {} while (0)
277#define spin_lock(lock) do {} while (0)
278#define spin_unlock(lock) do {} while (0)
279#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
280#define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
281
282#define DEFINE_MUTEX(...)
283#define mutex_init(...)
284#define mutex_lock(...)
285#define mutex_unlock(...)
286
287#define init_rwsem(...) do { } while (0)
288#define down_read(...) do { } while (0)
289#define down_write(...) do { } while (0)
290#define down_write_trylock(...) 1
291#define up_read(...) do { } while (0)
292#define up_write(...) do { } while (0)
293
294#define cond_resched() do { } while (0)
295#define yield() do { } while (0)
296
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200297#define __init
298#define __exit
299#define __devinit
300#define __devinitdata
301#define __devinitconst
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200302
303#define kthread_create(...) __builtin_return_address(0)
304#define kthread_stop(...) do { } while (0)
305#define wake_up_process(...) do { } while (0)
306
307struct rw_semaphore { int i; };
308#define down_write(...) do { } while (0)
309#define up_write(...) do { } while (0)
310#define down_read(...) do { } while (0)
311#define up_read(...) do { } while (0)
312struct device {
313 struct device *parent;
314 struct class *class;
315 dev_t devt; /* dev_t, creates the sysfs "dev" */
316 void (*release)(struct device *dev);
317 /* This is used from drivers/usb/musb-new subsystem only */
318 void *driver_data; /* data private to the driver */
319 void *device_data; /* data private to the device */
320};
321struct mutex { int i; };
322struct kernel_param { int i; };
323
324struct cdev {
325 int owner;
326 dev_t dev;
327};
328#define cdev_init(...) do { } while (0)
329#define cdev_add(...) 0
330#define cdev_del(...) do { } while (0)
331
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200332#define prandom_u32(...) 0
333
334typedef struct {
335 uid_t val;
336} kuid_t;
337
338typedef struct {
339 gid_t val;
340} kgid_t;
341
342/* from include/linux/types.h */
343
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200344/**
345 * struct callback_head - callback structure for use with RCU and task_work
346 * @next: next update requests in a list
347 * @func: actual update function to call after the grace period.
348 */
349struct callback_head {
350 struct callback_head *next;
351 void (*func)(struct callback_head *head);
352};
353#define rcu_head callback_head
354enum writeback_sync_modes {
355 WB_SYNC_NONE, /* Don't wait on anything */
356 WB_SYNC_ALL, /* Wait on every mapping */
357};
358
359/* from include/linux/writeback.h */
360/*
361 * A control structure which tells the writeback code what to do. These are
362 * always on the stack, and hence need no locking. They are always initialised
363 * in a manner such that unspecified fields are set to zero.
364 */
365struct writeback_control {
366 long nr_to_write; /* Write this many pages, and decrement
367 this for each page written */
368 long pages_skipped; /* Pages which were not written */
369
370 /*
371 * For a_ops->writepages(): if start or end are non-zero then this is
372 * a hint that the filesystem need only write out the pages inside that
373 * byterange. The byte at `end' is included in the writeout request.
374 */
375 loff_t range_start;
376 loff_t range_end;
377
378 enum writeback_sync_modes sync_mode;
379
380 unsigned for_kupdate:1; /* A kupdate writeback */
381 unsigned for_background:1; /* A background writeback */
382 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
383 unsigned for_reclaim:1; /* Invoked from the page allocator */
384 unsigned range_cyclic:1; /* range_start is cyclic */
385 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
386};
387
388void *kmemdup(const void *src, size_t len, gfp_t gfp);
389
390typedef int irqreturn_t;
391
392struct timer_list {};
393struct notifier_block {};
394
395typedef unsigned long dmaaddr_t;
396
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200397#define pm_runtime_get_sync(dev) do {} while (0)
398#define pm_runtime_put(dev) do {} while (0)
399#define pm_runtime_put_sync(dev) do {} while (0)
400#define pm_runtime_use_autosuspend(dev) do {} while (0)
401#define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
402#define pm_runtime_enable(dev) do {} while (0)
403
404#define IRQ_NONE 0
405#define IRQ_HANDLED 1
Kishon Vijay Abraham I35ffd282015-02-23 18:39:58 +0530406#define IRQ_WAKE_THREAD 2
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200407
408#define dev_set_drvdata(dev, data) do {} while (0)
409
410#define enable_irq(...)
411#define disable_irq(...)
412#define disable_irq_wake(irq) do {} while (0)
413#define enable_irq_wake(irq) -EINVAL
414#define free_irq(irq, data) do {} while (0)
415#define request_irq(nr, f, flags, nm, data) 0
416
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200417#endif