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 print_hex_dump(...) do { } while (0) 197 #define dump_stack(...) do { } while (0) 198 199 #define task_pid_nr(x) 0 200 #define set_freezable(...) do { } while (0) 201 #define try_to_freeze(...) 0 202 #define set_current_state(...) do { } while (0) 203 #define kthread_should_stop(...) 0 204 #define schedule() do { } while (0) 205 206 #define setup_timer(timer, func, data) do {} while (0) 207 #define del_timer_sync(timer) do {} while (0) 208 #define schedule_work(work) do {} while (0) 209 #define INIT_WORK(work, fun) do {} while (0) 210 211 struct work_struct {}; 212 213 unsigned long copy_from_user(void *dest, const void *src, 214 unsigned long count); 215 216 typedef unused_t spinlock_t; 217 typedef int wait_queue_head_t; 218 219 #define spin_lock_init(lock) do {} while (0) 220 #define spin_lock(lock) do {} while (0) 221 #define spin_unlock(lock) do {} while (0) 222 #define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0) 223 #define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0) 224 225 #define DEFINE_MUTEX(...) 226 #define mutex_init(...) 227 #define mutex_lock(...) 228 #define mutex_unlock(...) 229 230 #define init_rwsem(...) do { } while (0) 231 #define down_read(...) do { } while (0) 232 #define down_write(...) do { } while (0) 233 #define down_write_trylock(...) 1 234 #define up_read(...) do { } while (0) 235 #define up_write(...) do { } while (0) 236 237 #define cond_resched() do { } while (0) 238 #define yield() do { } while (0) 239 240 #define __init 241 #define __exit 242 #define __devinit 243 #define __devinitdata 244 #define __devinitconst 245 246 #define kthread_create(...) __builtin_return_address(0) 247 #define kthread_stop(...) do { } while (0) 248 #define wake_up_process(...) do { } while (0) 249 250 struct rw_semaphore { int i; }; 251 #define down_write(...) do { } while (0) 252 #define up_write(...) do { } while (0) 253 #define down_read(...) do { } while (0) 254 #define up_read(...) do { } while (0) 255 struct device { 256 struct device *parent; 257 struct class *class; 258 dev_t devt; /* dev_t, creates the sysfs "dev" */ 259 void (*release)(struct device *dev); 260 /* This is used from drivers/usb/musb-new subsystem only */ 261 void *driver_data; /* data private to the driver */ 262 void *device_data; /* data private to the device */ 263 }; 264 struct mutex { int i; }; 265 struct kernel_param { int i; }; 266 267 struct cdev { 268 int owner; 269 dev_t dev; 270 }; 271 #define cdev_init(...) do { } while (0) 272 #define cdev_add(...) 0 273 #define cdev_del(...) do { } while (0) 274 275 #define prandom_u32(...) 0 276 277 typedef struct { 278 uid_t val; 279 } kuid_t; 280 281 typedef struct { 282 gid_t val; 283 } kgid_t; 284 285 /* from include/linux/types.h */ 286 287 /** 288 * struct callback_head - callback structure for use with RCU and task_work 289 * @next: next update requests in a list 290 * @func: actual update function to call after the grace period. 291 */ 292 struct callback_head { 293 struct callback_head *next; 294 void (*func)(struct callback_head *head); 295 }; 296 #define rcu_head callback_head 297 enum writeback_sync_modes { 298 WB_SYNC_NONE, /* Don't wait on anything */ 299 WB_SYNC_ALL, /* Wait on every mapping */ 300 }; 301 302 /* from include/linux/writeback.h */ 303 /* 304 * A control structure which tells the writeback code what to do. These are 305 * always on the stack, and hence need no locking. They are always initialised 306 * in a manner such that unspecified fields are set to zero. 307 */ 308 struct writeback_control { 309 long nr_to_write; /* Write this many pages, and decrement 310 this for each page written */ 311 long pages_skipped; /* Pages which were not written */ 312 313 /* 314 * For a_ops->writepages(): if start or end are non-zero then this is 315 * a hint that the filesystem need only write out the pages inside that 316 * byterange. The byte at `end' is included in the writeout request. 317 */ 318 loff_t range_start; 319 loff_t range_end; 320 321 enum writeback_sync_modes sync_mode; 322 323 unsigned for_kupdate:1; /* A kupdate writeback */ 324 unsigned for_background:1; /* A background writeback */ 325 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */ 326 unsigned for_reclaim:1; /* Invoked from the page allocator */ 327 unsigned range_cyclic:1; /* range_start is cyclic */ 328 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ 329 }; 330 331 void *kmemdup(const void *src, size_t len, gfp_t gfp); 332 333 typedef int irqreturn_t; 334 335 struct timer_list {}; 336 struct notifier_block {}; 337 338 typedef unsigned long dmaaddr_t; 339 340 #define pm_runtime_get_sync(dev) do {} while (0) 341 #define pm_runtime_put(dev) do {} while (0) 342 #define pm_runtime_put_sync(dev) do {} while (0) 343 #define pm_runtime_use_autosuspend(dev) do {} while (0) 344 #define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0) 345 #define pm_runtime_enable(dev) do {} while (0) 346 347 #define IRQ_NONE 0 348 #define IRQ_HANDLED 1 349 #define IRQ_WAKE_THREAD 2 350 351 #define dev_set_drvdata(dev, data) do {} while (0) 352 353 #define enable_irq(...) 354 #define disable_irq(...) 355 #define disable_irq_wake(irq) do {} while (0) 356 #define enable_irq_wake(irq) -EINVAL 357 #define free_irq(irq, data) do {} while (0) 358 #define request_irq(nr, f, flags, nm, data) 0 359 360 #endif 361