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