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