blob: 712eeaef4ed915014fdb760fe09d0b545b5295c2 [file] [log] [blame]
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +02001#ifndef _LINUX_COMPAT_H_
2#define _LINUX_COMPAT_H_
3
Simon Glass1e268642020-05-10 11:39:55 -06004#include <log.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +02005#include <malloc.h>
6#include <linux/types.h>
7#include <linux/err.h>
Heiko Schocher9851f522015-10-22 06:19:20 +02008#include <linux/kernel.h>
Heiko Schocher4f7a9a32014-06-24 10:10:03 +02009
10struct unused {};
11typedef struct unused unused_t;
12
13struct p_current{
14 int pid;
15};
16
17extern struct p_current *current;
18
Masahiro Yamada9e74eb52017-09-26 11:58:29 +090019/* avoid conflict with <dm/device.h> */
20#ifdef dev_dbg
21#undef dev_dbg
22#endif
23#ifdef dev_vdbg
24#undef dev_vdbg
25#endif
26#ifdef dev_info
27#undef dev_info
28#endif
29#ifdef dev_err
30#undef dev_err
31#endif
32#ifdef dev_warn
33#undef dev_warn
34#endif
35
Wu, Joshba6babf2013-07-03 11:11:47 +080036#define dev_dbg(dev, fmt, args...) \
37 debug(fmt, ##args)
38#define dev_vdbg(dev, fmt, args...) \
39 debug(fmt, ##args)
40#define dev_info(dev, fmt, args...) \
41 printf(fmt, ##args)
42#define dev_err(dev, fmt, args...) \
43 printf(fmt, ##args)
Andreas Bießmann317a3822016-06-04 22:27:22 +020044#define dev_warn(dev, fmt, args...) \
45 printf(fmt, ##args)
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +020046
Bin Meng5efc2c42018-07-26 03:15:58 -070047#define netdev_emerg(dev, fmt, args...) \
48 printf(fmt, ##args)
49#define netdev_alert(dev, fmt, args...) \
50 printf(fmt, ##args)
51#define netdev_crit(dev, fmt, args...) \
52 printf(fmt, ##args)
53#define netdev_err(dev, fmt, args...) \
54 printf(fmt, ##args)
55#define netdev_warn(dev, fmt, args...) \
56 printf(fmt, ##args)
57#define netdev_notice(dev, fmt, args...) \
58 printf(fmt, ##args)
59#define netdev_info(dev, fmt, args...) \
60 printf(fmt, ##args)
61#define netdev_dbg(dev, fmt, args...) \
62 debug(fmt, ##args)
63#define netdev_vdbg(dev, fmt, args...) \
64 debug(fmt, ##args)
65
Masahiro Yamada7b5ec7e2015-07-13 13:17:07 +090066#define GFP_ATOMIC ((gfp_t) 0)
67#define GFP_KERNEL ((gfp_t) 0)
68#define GFP_NOFS ((gfp_t) 0)
69#define GFP_USER ((gfp_t) 0)
70#define __GFP_NOWARN ((gfp_t) 0)
71#define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */
72
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020073void *kmalloc(size_t size, int flags);
Masahiro Yamada7b5ec7e2015-07-13 13:17:07 +090074
75static inline void *kzalloc(size_t size, gfp_t flags)
76{
77 return kmalloc(size, flags | __GFP_ZERO);
78}
Heiko Schocher9851f522015-10-22 06:19:20 +020079
80static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
81{
82 if (size != 0 && n > SIZE_MAX / size)
83 return NULL;
84 return kmalloc(n * size, flags | __GFP_ZERO);
85}
86
87static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
88{
89 return kmalloc_array(n, size, flags | __GFP_ZERO);
90}
91
Heiko Schocher4f7a9a32014-06-24 10:10:03 +020092#define vmalloc(size) kmalloc(size, 0)
93#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadac5373472015-07-13 13:17:06 +090094static inline void *vzalloc(unsigned long size)
95{
96 return kzalloc(size, 0);
97}
Heiko Schocher9851f522015-10-22 06:19:20 +020098static inline void kfree(const void *block)
99{
100 free((void *)block);
101}
102static inline void vfree(const void *addr)
103{
104 free((void *)addr);
105}
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200106
107struct kmem_cache { int sz; };
108
109struct kmem_cache *get_mem(int element_sz);
110#define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
111void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
Heiko Schocher9851f522015-10-22 06:19:20 +0200112static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
113{
114 free(obj);
115}
116static inline void kmem_cache_destroy(struct kmem_cache *cachep)
117{
118 free(cachep);
119}
Stefan Roesee0860d42009-05-12 14:29:39 +0200120
121#define DECLARE_WAITQUEUE(...) do { } while (0)
122#define add_wait_queue(...) do { } while (0)
123#define remove_wait_queue(...) do { } while (0)
William Juul52c07962007-10-31 13:53:06 +0100124
Stefan Roesee0860d42009-05-12 14:29:39 +0200125#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200126
Simon Glassfb6f4822020-02-03 07:36:17 -0700127/* This is also defined in ARMv8's mmu.h */
128#ifndef PAGE_SIZE
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200129#define PAGE_SIZE 4096
Simon Glassfb6f4822020-02-03 07:36:17 -0700130#endif
Lijun Pan036f66d2014-06-20 12:17:29 -0500131
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200132/* drivers/char/random.c */
133#define get_random_bytes(...)
134
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200135/* include/linux/leds.h */
136struct led_trigger {};
137
138#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
139enum led_brightness {
140 LED_OFF = 0,
141 LED_HALF = 127,
142 LED_FULL = 255,
143};
144
145static inline void led_trigger_register_simple(const char *name,
146 struct led_trigger **trigger) {}
147static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
148static inline void led_trigger_event(struct led_trigger *trigger,
149 enum led_brightness event) {}
150
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200151/* uapi/linux/limits.h */
152#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
153
154/**
155 * The type used for indexing onto a disc or disc partition.
156 *
157 * Linux always considers sectors to be 512 bytes long independently
158 * of the devices real block size.
159 *
160 * blkcnt_t is the type of the inode's block count.
161 */
162#ifdef CONFIG_LBDAF
163typedef u64 sector_t;
164typedef u64 blkcnt_t;
165#else
166typedef unsigned long sector_t;
167typedef unsigned long blkcnt_t;
168#endif
169
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200170/* module */
171#define THIS_MODULE 0
172#define try_module_get(...) 1
173#define module_put(...) do { } while (0)
174#define module_init(...)
175#define module_exit(...)
176#define EXPORT_SYMBOL(...)
177#define EXPORT_SYMBOL_GPL(...)
178#define module_param(...)
179#define module_param_call(...)
180#define MODULE_PARM_DESC(...)
181#define MODULE_VERSION(...)
182#define MODULE_DESCRIPTION(...)
183#define MODULE_AUTHOR(...)
184#define MODULE_LICENSE(...)
185#define MODULE_ALIAS(...)
186#define __module_get(...)
187
188/* character device */
189#define MKDEV(...) 0
190#define MAJOR(dev) 0
191#define MINOR(dev) 0
192
193#define alloc_chrdev_region(...) 0
194#define unregister_chrdev_region(...)
195
196#define class_create(...) __builtin_return_address(0)
197#define class_create_file(...) 0
Heiko Schocher9851f522015-10-22 06:19:20 +0200198#define class_register(...) 0
199#define class_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200200#define class_remove_file(...)
201#define class_destroy(...)
202#define misc_register(...) 0
203#define misc_deregister(...)
204
205#define blocking_notifier_call_chain(...) 0
206
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200207#define __initdata
208#define late_initcall(...)
209
210#define dev_set_name(...) do { } while (0)
211#define device_register(...) 0
Heiko Schocher9851f522015-10-22 06:19:20 +0200212#define device_unregister(...)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200213#define volume_sysfs_init(...) 0
214#define volume_sysfs_close(...) do { } while (0)
215
216#define init_waitqueue_head(...) do { } while (0)
217#define wait_event_interruptible(...) 0
218#define wake_up_interruptible(...) do { } while (0)
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200219#define dump_stack(...) do { } while (0)
220
221#define task_pid_nr(x) 0
222#define set_freezable(...) do { } while (0)
223#define try_to_freeze(...) 0
224#define set_current_state(...) do { } while (0)
225#define kthread_should_stop(...) 0
226#define schedule() do { } while (0)
227
228#define setup_timer(timer, func, data) do {} while (0)
229#define del_timer_sync(timer) do {} while (0)
230#define schedule_work(work) do {} while (0)
231#define INIT_WORK(work, fun) do {} while (0)
232
233struct work_struct {};
234
235unsigned long copy_from_user(void *dest, const void *src,
236 unsigned long count);
237
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200238typedef unused_t spinlock_t;
239typedef int wait_queue_head_t;
240
241#define spin_lock_init(lock) do {} while (0)
242#define spin_lock(lock) do {} while (0)
243#define spin_unlock(lock) do {} while (0)
244#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
245#define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
246
247#define DEFINE_MUTEX(...)
248#define mutex_init(...)
249#define mutex_lock(...)
250#define mutex_unlock(...)
251
252#define init_rwsem(...) do { } while (0)
253#define down_read(...) do { } while (0)
254#define down_write(...) do { } while (0)
255#define down_write_trylock(...) 1
256#define up_read(...) do { } while (0)
257#define up_write(...) do { } while (0)
258
259#define cond_resched() do { } while (0)
260#define yield() do { } while (0)
261
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200262#define __init
263#define __exit
264#define __devinit
265#define __devinitdata
266#define __devinitconst
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200267
268#define kthread_create(...) __builtin_return_address(0)
269#define kthread_stop(...) do { } while (0)
270#define wake_up_process(...) do { } while (0)
271
272struct rw_semaphore { int i; };
273#define down_write(...) do { } while (0)
274#define up_write(...) do { } while (0)
275#define down_read(...) do { } while (0)
276#define up_read(...) do { } while (0)
277struct device {
278 struct device *parent;
279 struct class *class;
280 dev_t devt; /* dev_t, creates the sysfs "dev" */
281 void (*release)(struct device *dev);
282 /* This is used from drivers/usb/musb-new subsystem only */
283 void *driver_data; /* data private to the driver */
284 void *device_data; /* data private to the device */
285};
286struct mutex { int i; };
287struct kernel_param { int i; };
288
289struct cdev {
290 int owner;
291 dev_t dev;
292};
293#define cdev_init(...) do { } while (0)
294#define cdev_add(...) 0
295#define cdev_del(...) do { } while (0)
296
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200297#define prandom_u32(...) 0
298
299typedef struct {
300 uid_t val;
301} kuid_t;
302
303typedef struct {
304 gid_t val;
305} kgid_t;
306
307/* from include/linux/types.h */
308
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200309/**
310 * struct callback_head - callback structure for use with RCU and task_work
311 * @next: next update requests in a list
312 * @func: actual update function to call after the grace period.
313 */
314struct callback_head {
315 struct callback_head *next;
316 void (*func)(struct callback_head *head);
317};
318#define rcu_head callback_head
319enum writeback_sync_modes {
320 WB_SYNC_NONE, /* Don't wait on anything */
321 WB_SYNC_ALL, /* Wait on every mapping */
322};
323
324/* from include/linux/writeback.h */
325/*
326 * A control structure which tells the writeback code what to do. These are
327 * always on the stack, and hence need no locking. They are always initialised
328 * in a manner such that unspecified fields are set to zero.
329 */
330struct writeback_control {
331 long nr_to_write; /* Write this many pages, and decrement
332 this for each page written */
333 long pages_skipped; /* Pages which were not written */
334
335 /*
336 * For a_ops->writepages(): if start or end are non-zero then this is
337 * a hint that the filesystem need only write out the pages inside that
338 * byterange. The byte at `end' is included in the writeout request.
339 */
340 loff_t range_start;
341 loff_t range_end;
342
343 enum writeback_sync_modes sync_mode;
344
345 unsigned for_kupdate:1; /* A kupdate writeback */
346 unsigned for_background:1; /* A background writeback */
347 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
348 unsigned for_reclaim:1; /* Invoked from the page allocator */
349 unsigned range_cyclic:1; /* range_start is cyclic */
350 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
351};
352
353void *kmemdup(const void *src, size_t len, gfp_t gfp);
354
355typedef int irqreturn_t;
356
357struct timer_list {};
358struct notifier_block {};
359
360typedef unsigned long dmaaddr_t;
361
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200362#define pm_runtime_get_sync(dev) do {} while (0)
363#define pm_runtime_put(dev) do {} while (0)
364#define pm_runtime_put_sync(dev) do {} while (0)
365#define pm_runtime_use_autosuspend(dev) do {} while (0)
366#define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
367#define pm_runtime_enable(dev) do {} while (0)
368
369#define IRQ_NONE 0
370#define IRQ_HANDLED 1
Kishon Vijay Abraham I35ffd282015-02-23 18:39:58 +0530371#define IRQ_WAKE_THREAD 2
Heiko Schocher4f7a9a32014-06-24 10:10:03 +0200372
373#define dev_set_drvdata(dev, data) do {} while (0)
374
375#define enable_irq(...)
376#define disable_irq(...)
377#define disable_irq_wake(irq) do {} while (0)
378#define enable_irq_wake(irq) -EINVAL
379#define free_irq(irq, data) do {} while (0)
380#define request_irq(nr, f, flags, nm, data) 0
381
Wolfgang Denk2f9b7e42005-08-17 12:55:25 +0200382#endif