blob: e561ee311a09cd546794524bd91896eb47688084 [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
Wolfgang Denk932394a2005-08-17 12:55:25 +020018#define ndelay(x) udelay(1)
19
Wu, Josh2f96b062013-07-03 11:11:47 +080020#define dev_dbg(dev, fmt, args...) \
21 debug(fmt, ##args)
22#define dev_vdbg(dev, fmt, args...) \
23 debug(fmt, ##args)
24#define dev_info(dev, fmt, args...) \
25 printf(fmt, ##args)
26#define dev_err(dev, fmt, args...) \
27 printf(fmt, ##args)
Wolfgang Denk932394a2005-08-17 12:55:25 +020028#define printk printf
Heiko Schocher0c06db52014-06-24 10:10:03 +020029#define printk_once printf
Wolfgang Denk932394a2005-08-17 12:55:25 +020030
31#define KERN_EMERG
32#define KERN_ALERT
33#define KERN_CRIT
34#define KERN_ERR
35#define KERN_WARNING
36#define KERN_NOTICE
37#define KERN_INFO
38#define KERN_DEBUG
39
Masahiro Yamada6b9f9ea2015-07-13 13:17:07 +090040#define GFP_ATOMIC ((gfp_t) 0)
41#define GFP_KERNEL ((gfp_t) 0)
42#define GFP_NOFS ((gfp_t) 0)
43#define GFP_USER ((gfp_t) 0)
44#define __GFP_NOWARN ((gfp_t) 0)
45#define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */
46
Heiko Schocher0c06db52014-06-24 10:10:03 +020047void *kmalloc(size_t size, int flags);
Masahiro Yamada6b9f9ea2015-07-13 13:17:07 +090048
49static inline void *kzalloc(size_t size, gfp_t flags)
50{
51 return kmalloc(size, flags | __GFP_ZERO);
52}
Heiko Schocher5219db82015-10-22 06:19:20 +020053
54static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
55{
56 if (size != 0 && n > SIZE_MAX / size)
57 return NULL;
58 return kmalloc(n * size, flags | __GFP_ZERO);
59}
60
61static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
62{
63 return kmalloc_array(n, size, flags | __GFP_ZERO);
64}
65
Heiko Schocher0c06db52014-06-24 10:10:03 +020066#define vmalloc(size) kmalloc(size, 0)
67#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
Masahiro Yamadaebc33282015-07-13 13:17:06 +090068static inline void *vzalloc(unsigned long size)
69{
70 return kzalloc(size, 0);
71}
Heiko Schocher5219db82015-10-22 06:19:20 +020072static inline void kfree(const void *block)
73{
74 free((void *)block);
75}
76static inline void vfree(const void *addr)
77{
78 free((void *)addr);
79}
Heiko Schocher0c06db52014-06-24 10:10:03 +020080
81struct kmem_cache { int sz; };
82
83struct kmem_cache *get_mem(int element_sz);
84#define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
85void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
Heiko Schocher5219db82015-10-22 06:19:20 +020086static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
87{
88 free(obj);
89}
90static inline void kmem_cache_destroy(struct kmem_cache *cachep)
91{
92 free(cachep);
93}
William Juulcfa460a2007-10-31 13:53:06 +010094
Stefan Roese0a572652009-05-12 14:29:39 +020095#define DECLARE_WAITQUEUE(...) do { } while (0)
96#define add_wait_queue(...) do { } while (0)
97#define remove_wait_queue(...) do { } while (0)
98
99#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
Wolfgang Denk932394a2005-08-17 12:55:25 +0200100
Stefan Roese887e2ec2006-09-07 11:51:23 +0200101#ifndef BUG
Wolfgang Denk932394a2005-08-17 12:55:25 +0200102#define BUG() do { \
103 printf("U-Boot BUG at %s:%d!\n", __FILE__, __LINE__); \
104} while (0)
105
106#define BUG_ON(condition) do { if (condition) BUG(); } while(0)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200107#endif /* BUG */
Wolfgang Denk932394a2005-08-17 12:55:25 +0200108
Mike Frysinger6777a3c2012-04-26 02:34:44 +0000109#define WARN_ON(x) if (x) {printf("WARNING in %s line %d\n" \
110 , __FILE__, __LINE__); }
111
Wolfgang Denk932394a2005-08-17 12:55:25 +0200112#define PAGE_SIZE 4096
Lijun Pan8f2df5d2014-06-20 12:17:29 -0500113
Heiko Schocher0c06db52014-06-24 10:10:03 +0200114/* drivers/char/random.c */
115#define get_random_bytes(...)
116
Heiko Schocher0c06db52014-06-24 10:10:03 +0200117/* include/linux/leds.h */
118struct led_trigger {};
119
120#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
121enum led_brightness {
122 LED_OFF = 0,
123 LED_HALF = 127,
124 LED_FULL = 255,
125};
126
127static inline void led_trigger_register_simple(const char *name,
128 struct led_trigger **trigger) {}
129static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
130static inline void led_trigger_event(struct led_trigger *trigger,
131 enum led_brightness event) {}
132
Heiko Schocher0c06db52014-06-24 10:10:03 +0200133/* uapi/linux/limits.h */
134#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
135
136/**
137 * The type used for indexing onto a disc or disc partition.
138 *
139 * Linux always considers sectors to be 512 bytes long independently
140 * of the devices real block size.
141 *
142 * blkcnt_t is the type of the inode's block count.
143 */
144#ifdef CONFIG_LBDAF
145typedef u64 sector_t;
146typedef u64 blkcnt_t;
147#else
148typedef unsigned long sector_t;
149typedef unsigned long blkcnt_t;
150#endif
151
152#define ENOTSUPP 524 /* Operation is not supported */
153
Heiko Schocher0c06db52014-06-24 10:10:03 +0200154/* module */
155#define THIS_MODULE 0
156#define try_module_get(...) 1
157#define module_put(...) do { } while (0)
158#define module_init(...)
159#define module_exit(...)
160#define EXPORT_SYMBOL(...)
161#define EXPORT_SYMBOL_GPL(...)
162#define module_param(...)
163#define module_param_call(...)
164#define MODULE_PARM_DESC(...)
165#define MODULE_VERSION(...)
166#define MODULE_DESCRIPTION(...)
167#define MODULE_AUTHOR(...)
168#define MODULE_LICENSE(...)
169#define MODULE_ALIAS(...)
170#define __module_get(...)
171
172/* character device */
173#define MKDEV(...) 0
174#define MAJOR(dev) 0
175#define MINOR(dev) 0
176
177#define alloc_chrdev_region(...) 0
178#define unregister_chrdev_region(...)
179
180#define class_create(...) __builtin_return_address(0)
181#define class_create_file(...) 0
Heiko Schocher5219db82015-10-22 06:19:20 +0200182#define class_register(...) 0
183#define class_unregister(...)
Heiko Schocher0c06db52014-06-24 10:10:03 +0200184#define class_remove_file(...)
185#define class_destroy(...)
186#define misc_register(...) 0
187#define misc_deregister(...)
188
189#define blocking_notifier_call_chain(...) 0
190
Heiko Schocher0c06db52014-06-24 10:10:03 +0200191#define __initdata
192#define late_initcall(...)
193
194#define dev_set_name(...) do { } while (0)
195#define device_register(...) 0
Heiko Schocher5219db82015-10-22 06:19:20 +0200196#define device_unregister(...)
Heiko Schocher0c06db52014-06-24 10:10:03 +0200197#define volume_sysfs_init(...) 0
198#define volume_sysfs_close(...) do { } while (0)
199
200#define init_waitqueue_head(...) do { } while (0)
201#define wait_event_interruptible(...) 0
202#define wake_up_interruptible(...) do { } while (0)
203#define print_hex_dump(...) do { } while (0)
204#define dump_stack(...) do { } while (0)
205
206#define task_pid_nr(x) 0
207#define set_freezable(...) do { } while (0)
208#define try_to_freeze(...) 0
209#define set_current_state(...) do { } while (0)
210#define kthread_should_stop(...) 0
211#define schedule() do { } while (0)
212
213#define setup_timer(timer, func, data) do {} while (0)
214#define del_timer_sync(timer) do {} while (0)
215#define schedule_work(work) do {} while (0)
216#define INIT_WORK(work, fun) do {} while (0)
217
218struct work_struct {};
219
220unsigned long copy_from_user(void *dest, const void *src,
221 unsigned long count);
222
Heiko Schocher0c06db52014-06-24 10:10:03 +0200223typedef unused_t spinlock_t;
224typedef int wait_queue_head_t;
225
226#define spin_lock_init(lock) do {} while (0)
227#define spin_lock(lock) do {} while (0)
228#define spin_unlock(lock) do {} while (0)
229#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
230#define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
231
232#define DEFINE_MUTEX(...)
233#define mutex_init(...)
234#define mutex_lock(...)
235#define mutex_unlock(...)
236
237#define init_rwsem(...) do { } while (0)
238#define down_read(...) do { } while (0)
239#define down_write(...) do { } while (0)
240#define down_write_trylock(...) 1
241#define up_read(...) do { } while (0)
242#define up_write(...) do { } while (0)
243
244#define cond_resched() do { } while (0)
245#define yield() do { } while (0)
246
Heiko Schocher0c06db52014-06-24 10:10:03 +0200247#define __init
248#define __exit
249#define __devinit
250#define __devinitdata
251#define __devinitconst
Heiko Schocher0c06db52014-06-24 10:10:03 +0200252
253#define kthread_create(...) __builtin_return_address(0)
254#define kthread_stop(...) do { } while (0)
255#define wake_up_process(...) do { } while (0)
256
257struct rw_semaphore { int i; };
258#define down_write(...) do { } while (0)
259#define up_write(...) do { } while (0)
260#define down_read(...) do { } while (0)
261#define up_read(...) do { } while (0)
262struct device {
263 struct device *parent;
264 struct class *class;
265 dev_t devt; /* dev_t, creates the sysfs "dev" */
266 void (*release)(struct device *dev);
267 /* This is used from drivers/usb/musb-new subsystem only */
268 void *driver_data; /* data private to the driver */
269 void *device_data; /* data private to the device */
270};
271struct mutex { int i; };
272struct kernel_param { int i; };
273
274struct cdev {
275 int owner;
276 dev_t dev;
277};
278#define cdev_init(...) do { } while (0)
279#define cdev_add(...) 0
280#define cdev_del(...) do { } while (0)
281
Heiko Schocher0c06db52014-06-24 10:10:03 +0200282#define prandom_u32(...) 0
283
284typedef struct {
285 uid_t val;
286} kuid_t;
287
288typedef struct {
289 gid_t val;
290} kgid_t;
291
292/* from include/linux/types.h */
293
Heiko Schocher0c06db52014-06-24 10:10:03 +0200294/**
295 * struct callback_head - callback structure for use with RCU and task_work
296 * @next: next update requests in a list
297 * @func: actual update function to call after the grace period.
298 */
299struct callback_head {
300 struct callback_head *next;
301 void (*func)(struct callback_head *head);
302};
303#define rcu_head callback_head
304enum writeback_sync_modes {
305 WB_SYNC_NONE, /* Don't wait on anything */
306 WB_SYNC_ALL, /* Wait on every mapping */
307};
308
309/* from include/linux/writeback.h */
310/*
311 * A control structure which tells the writeback code what to do. These are
312 * always on the stack, and hence need no locking. They are always initialised
313 * in a manner such that unspecified fields are set to zero.
314 */
315struct writeback_control {
316 long nr_to_write; /* Write this many pages, and decrement
317 this for each page written */
318 long pages_skipped; /* Pages which were not written */
319
320 /*
321 * For a_ops->writepages(): if start or end are non-zero then this is
322 * a hint that the filesystem need only write out the pages inside that
323 * byterange. The byte at `end' is included in the writeout request.
324 */
325 loff_t range_start;
326 loff_t range_end;
327
328 enum writeback_sync_modes sync_mode;
329
330 unsigned for_kupdate:1; /* A kupdate writeback */
331 unsigned for_background:1; /* A background writeback */
332 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
333 unsigned for_reclaim:1; /* Invoked from the page allocator */
334 unsigned range_cyclic:1; /* range_start is cyclic */
335 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
336};
337
338void *kmemdup(const void *src, size_t len, gfp_t gfp);
339
340typedef int irqreturn_t;
341
342struct timer_list {};
343struct notifier_block {};
344
345typedef unsigned long dmaaddr_t;
346
Heiko Schocher0c06db52014-06-24 10:10:03 +0200347#define pm_runtime_get_sync(dev) do {} while (0)
348#define pm_runtime_put(dev) do {} while (0)
349#define pm_runtime_put_sync(dev) do {} while (0)
350#define pm_runtime_use_autosuspend(dev) do {} while (0)
351#define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
352#define pm_runtime_enable(dev) do {} while (0)
353
354#define IRQ_NONE 0
355#define IRQ_HANDLED 1
Kishon Vijay Abraham I747a0a52015-02-23 18:39:58 +0530356#define IRQ_WAKE_THREAD 2
Heiko Schocher0c06db52014-06-24 10:10:03 +0200357
358#define dev_set_drvdata(dev, data) do {} while (0)
359
360#define enable_irq(...)
361#define disable_irq(...)
362#define disable_irq_wake(irq) do {} while (0)
363#define enable_irq_wake(irq) -EINVAL
364#define free_irq(irq, data) do {} while (0)
365#define request_irq(nr, f, flags, nm, data) 0
366
Wolfgang Denk932394a2005-08-17 12:55:25 +0200367#endif