1 /* SPDX-License-Identifier: GPL-2.0 */
12 #include <linux/compiler.h>
13 #include "../../../include/linux/container_of.h"
14 #include <linux/log2.h>
15 #include <linux/types.h>
16 #include <linux/overflow.h>
17 #include <linux/list.h>
18 #include <linux/printk.h>
19 #include <linux/bug.h>
22 #include <asm/barrier.h>
26 #define PAGE_SIZE getpagesize()
27 #define PAGE_MASK (~(PAGE_SIZE-1))
28 #define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
30 /* generic data direction definitions */
34 typedef unsigned long long dma_addr_t
;
35 typedef size_t __kernel_size_t
;
36 typedef unsigned int __wsum
;
39 unsigned long long dummy
;
42 /* Physical == Virtual */
43 #define virt_to_phys(p) ((unsigned long)p)
44 #define phys_to_virt(a) ((void *)(unsigned long)(a))
45 /* Page address: Virtual / 4K */
46 #define page_to_phys(p) ((dma_addr_t)(unsigned long)(p))
47 #define virt_to_page(p) ((struct page *)((unsigned long)p & PAGE_MASK))
49 #define offset_in_page(p) (((unsigned long)p) % PAGE_SIZE)
51 #define __printf(a,b) __attribute__((format(printf,a,b)))
53 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
55 extern void *__kmalloc_fake
, *__kfree_ignore_start
, *__kfree_ignore_end
;
56 static inline void *kmalloc(size_t s
, gfp_t gfp
)
59 return __kmalloc_fake
;
62 static inline void *kmalloc_array(unsigned n
, size_t s
, gfp_t gfp
)
64 return kmalloc(n
* s
, gfp
);
67 static inline void *kzalloc(size_t s
, gfp_t gfp
)
69 void *p
= kmalloc(s
, gfp
);
75 static inline void *alloc_pages_exact(size_t s
, gfp_t gfp
)
77 return kmalloc(s
, gfp
);
80 static inline void kfree(void *p
)
82 if (p
>= __kfree_ignore_start
&& p
< __kfree_ignore_end
)
87 static inline void free_pages_exact(void *p
, size_t s
)
92 static inline void *krealloc(void *p
, size_t s
, gfp_t gfp
)
98 static inline unsigned long __get_free_page(gfp_t gfp
)
102 posix_memalign(&p
, PAGE_SIZE
, PAGE_SIZE
);
103 return (unsigned long)p
;
106 static inline void free_page(unsigned long addr
)
112 # define likely(x) (__builtin_expect(!!(x), 1))
115 # define unlikely(x) (__builtin_expect(!!(x), 0))
118 static inline void *krealloc_array(void *p
, size_t new_n
, size_t new_size
, gfp_t gfp
)
122 if (unlikely(check_mul_overflow(new_n
, new_size
, &bytes
)))
125 return krealloc(p
, bytes
, gfp
);
128 #define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
130 #define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
132 #define pr_debug(format, ...) do {} while (0)
134 #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
135 #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
136 #define dev_warn_once(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
138 #define min(x, y) ({ \
139 typeof(x) _min1 = (x); \
140 typeof(y) _min2 = (y); \
141 (void) (&_min1 == &_min2); \
142 _min1 < _min2 ? _min1 : _min2; })
144 #endif /* KERNEL_H */