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