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