Merge tag 'u-boot-atmel-fixes-2021.01-b' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / include / linux / compat.h
index da1420f..3d0acbd 100644 (file)
@@ -1,9 +1,19 @@
 #ifndef _LINUX_COMPAT_H_
 #define _LINUX_COMPAT_H_
 
+#include <console.h>
+#include <log.h>
 #include <malloc.h>
+
+#include <asm/processor.h>
+
 #include <linux/types.h>
 #include <linux/err.h>
+#include <linux/kernel.h>
+
+#ifdef CONFIG_XEN
+#include <xen/events.h>
+#endif
 
 struct unused {};
 typedef struct unused unused_t;
@@ -14,72 +24,121 @@ struct p_current{
 
 extern struct p_current *current;
 
-#define ndelay(x)      udelay(1)
-
-#define dev_dbg(dev, fmt, args...)             \
-       debug(fmt, ##args)
-#define dev_vdbg(dev, fmt, args...)            \
-       debug(fmt, ##args)
-#define dev_info(dev, fmt, args...)            \
-       printf(fmt, ##args)
-#define dev_err(dev, fmt, args...)             \
-       printf(fmt, ##args)
-#define printk printf
-#define printk_once    printf
-
-#define KERN_EMERG
-#define KERN_ALERT
-#define KERN_CRIT
-#define KERN_ERR
-#define KERN_WARNING
-#define KERN_NOTICE
-#define KERN_INFO
-#define KERN_DEBUG
+#define GFP_ATOMIC ((gfp_t) 0)
+#define GFP_KERNEL ((gfp_t) 0)
+#define GFP_NOFS ((gfp_t) 0)
+#define GFP_USER ((gfp_t) 0)
+#define __GFP_NOWARN ((gfp_t) 0)
+#define __GFP_ZERO     ((__force gfp_t)0x8000u)        /* Return zeroed page on success */
 
 void *kmalloc(size_t size, int flags);
-void *kzalloc(size_t size, int flags);
+
+static inline void *kzalloc(size_t size, gfp_t flags)
+{
+       return kmalloc(size, flags | __GFP_ZERO);
+}
+
+static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+       if (size != 0 && n > SIZE_MAX / size)
+               return NULL;
+       return kmalloc(n * size, flags | __GFP_ZERO);
+}
+
+static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
+{
+       return kmalloc_array(n, size, flags | __GFP_ZERO);
+}
+
 #define vmalloc(size)  kmalloc(size, 0)
 #define __vmalloc(size, flags, pgsz)   kmalloc(size, flags)
-#define kfree(ptr)     free(ptr)
-#define vfree(ptr)     free(ptr)
+static inline void *vzalloc(unsigned long size)
+{
+       return kzalloc(size, 0);
+}
+static inline void kfree(const void *block)
+{
+       free((void *)block);
+}
+static inline void vfree(const void *addr)
+{
+       free((void *)addr);
+}
 
 struct kmem_cache { int sz; };
 
 struct kmem_cache *get_mem(int element_sz);
 #define kmem_cache_create(a, sz, c, d, e)      get_mem(sz)
 void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
-#define kmem_cache_free(obj, size)     free(size)
-#define kmem_cache_destroy(obj)                free(obj)
+static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
+{
+       free(obj);
+}
+static inline void kmem_cache_destroy(struct kmem_cache *cachep)
+{
+       free(cachep);
+}
 
 #define DECLARE_WAITQUEUE(...) do { } while (0)
 #define add_wait_queue(...)    do { } while (0)
 #define remove_wait_queue(...) do { } while (0)
 
-#define KERNEL_VERSION(a,b,c)  (((a) << 16) + ((b) << 8) + (c))
+#ifndef CONFIG_XEN
+#define eventchn_poll()
+#endif
 
-#ifndef BUG
-#define BUG() do { \
-       printf("U-Boot BUG at %s:%d!\n", __FILE__, __LINE__); \
-} while (0)
+#define __wait_event_timeout(condition, timeout, ret)          \
+({                                                             \
+       ulong __ret = ret; /* explicit shadow */                \
+       ulong start = get_timer(0);                             \
+       for (;;) {                                              \
+               eventchn_poll();                                \
+               if (condition) {                                \
+                       __ret = 1;                              \
+                       break;                                  \
+       }                                                       \
+       if ((get_timer(start) > timeout) || ctrlc()) {          \
+               __ret = 0;                                      \
+               break;                                          \
+       }                                                       \
+       cpu_relax();                                            \
+       }                                                       \
+       __ret;                                                  \
+})
 
-#define BUG_ON(condition) do { if (condition) BUG(); } while(0)
-#endif /* BUG */
+/**
+ * wait_event_timeout() - Wait until the event occurs before the timeout.
+ * @wr_head: The wait queue to wait on.
+ * @condition: Expression for the event to wait for.
+ * @timeout: Maximum waiting time.
+ *
+ * We wait until the @condition evaluates to %true (succeed) or
+ * %false (@timeout elapsed).
+ *
+ * Return:
+ * 0 - if the @condition evaluated to %false after the @timeout elapsed
+ * 1 - if the @condition evaluated to %true
+ */
+#define wait_event_timeout(wq_head, condition, timeout)                        \
+({                                                                     \
+       ulong __ret;                                                    \
+       if (condition)                                                  \
+               __ret = 1;                                              \
+       else                                                            \
+               __ret = __wait_event_timeout(condition, timeout, __ret);\
+       __ret;                                                          \
+})
 
-#define WARN_ON(x) if (x) {printf("WARNING in %s line %d\n" \
-                                 , __FILE__, __LINE__); }
+#define KERNEL_VERSION(a,b,c)  (((a) << 16) + ((b) << 8) + (c))
 
+/* This is also defined in ARMv8's mmu.h */
+#ifndef PAGE_SIZE
 #define PAGE_SIZE      4096
+#endif
 
 /* drivers/char/random.c */
 #define get_random_bytes(...)
 
-/* idr.c */
-#define GFP_ATOMIC ((gfp_t) 0)
-#define GFP_KERNEL ((gfp_t) 0)
-#define GFP_NOFS ((gfp_t) 0)
-#define GFP_USER ((gfp_t) 0)
-#define __GFP_NOWARN ((gfp_t) 0)
-
 /* include/linux/leds.h */
 struct led_trigger {};
 
@@ -96,12 +155,6 @@ static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
 static inline void led_trigger_event(struct led_trigger *trigger,
                                        enum led_brightness event) {}
 
-/* include/linux/log2.h */
-static inline int is_power_of_2(unsigned long n)
-{
-       return (n != 0 && ((n & (n - 1)) == 0));
-}
-
 /* uapi/linux/limits.h */
 #define XATTR_LIST_MAX 65536   /* size of extended attribute namelist (64k) */
 
@@ -121,8 +174,6 @@ typedef unsigned long sector_t;
 typedef unsigned long blkcnt_t;
 #endif
 
-#define ENOTSUPP       524     /* Operation is not supported */
-
 /* module */
 #define THIS_MODULE            0
 #define try_module_get(...)    1
@@ -151,6 +202,8 @@ typedef unsigned long blkcnt_t;
 
 #define class_create(...)              __builtin_return_address(0)
 #define class_create_file(...)         0
+#define class_register(...)            0
+#define class_unregister(...)
 #define class_remove_file(...)
 #define class_destroy(...)
 #define misc_register(...)             0
@@ -163,13 +216,13 @@ typedef unsigned long blkcnt_t;
 
 #define dev_set_name(...)              do { } while (0)
 #define device_register(...)           0
+#define device_unregister(...)
 #define volume_sysfs_init(...)         0
 #define volume_sysfs_close(...)                do { } while (0)
 
 #define init_waitqueue_head(...)       do { } while (0)
 #define wait_event_interruptible(...)  0
 #define wake_up_interruptible(...)     do { } while (0)
-#define print_hex_dump(...)            do { } while (0)
 #define dump_stack(...)                        do { } while (0)
 
 #define task_pid_nr(x)                 0
@@ -189,15 +242,13 @@ struct work_struct {};
 unsigned long copy_from_user(void *dest, const void *src,
                             unsigned long count);
 
-void *vzalloc(unsigned long size);
-
 typedef unused_t spinlock_t;
 typedef int    wait_queue_head_t;
 
 #define spin_lock_init(lock) do {} while (0)
 #define spin_lock(lock) do {} while (0)
 #define spin_unlock(lock) do {} while (0)
-#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
+#define spin_lock_irqsave(lock, flags) do {} while (0)
 #define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
 
 #define DEFINE_MUTEX(...)