1 /* SPDX-License-Identifier: GPL-2.0 */
12 #include <linux/compiler.h>
13 #include <linux/types.h>
14 #include <linux/printk.h>
15 #include <linux/bug.h>
18 #include <asm/barrier.h>
22 #define PAGE_SIZE getpagesize()
23 #define PAGE_MASK (~(PAGE_SIZE-1))
24 #define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
26 typedef unsigned long long phys_addr_t
;
27 typedef unsigned long long dma_addr_t
;
28 typedef size_t __kernel_size_t
;
29 typedef unsigned int __wsum
;
32 unsigned long long dummy
;
35 /* Physical == Virtual */
36 #define virt_to_phys(p) ((unsigned long)p)
37 #define phys_to_virt(a) ((void *)(unsigned long)(a))
38 /* Page address: Virtual / 4K */
39 #define page_to_phys(p) ((dma_addr_t)(unsigned long)(p))
40 #define virt_to_page(p) ((struct page *)((unsigned long)p & PAGE_MASK))
42 #define offset_in_page(p) (((unsigned long)p) % PAGE_SIZE)
44 #define __printf(a,b) __attribute__((format(printf,a,b)))
46 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
48 extern void *__kmalloc_fake
, *__kfree_ignore_start
, *__kfree_ignore_end
;
49 static inline void *kmalloc(size_t s
, gfp_t gfp
)
52 return __kmalloc_fake
;
55 static inline void *kzalloc(size_t s
, gfp_t gfp
)
57 void *p
= kmalloc(s
, gfp
);
63 static inline void *alloc_pages_exact(size_t s
, gfp_t gfp
)
65 return kmalloc(s
, gfp
);
68 static inline void kfree(void *p
)
70 if (p
>= __kfree_ignore_start
&& p
< __kfree_ignore_end
)
75 static inline void free_pages_exact(void *p
, size_t s
)
80 static inline void *krealloc(void *p
, size_t s
, gfp_t gfp
)
86 static inline unsigned long __get_free_page(gfp_t gfp
)
90 posix_memalign(&p
, PAGE_SIZE
, PAGE_SIZE
);
91 return (unsigned long)p
;
94 static inline void free_page(unsigned long addr
)
99 #define container_of(ptr, type, member) ({ \
100 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
101 (type *)( (char *)__mptr - offsetof(type,member) );})
103 #define uninitialized_var(x) x = x
106 # define likely(x) (__builtin_expect(!!(x), 1))
109 # define unlikely(x) (__builtin_expect(!!(x), 0))
112 #define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
114 #define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
116 #define pr_debug(format, ...) do {} while (0)
118 #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
119 #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
121 #define WARN_ON_ONCE(cond) ((cond) ? fprintf (stderr, "WARNING\n") : 0)
123 #define min(x, y) ({ \
124 typeof(x) _min1 = (x); \
125 typeof(y) _min2 = (y); \
126 (void) (&_min1 == &_min2); \
127 _min1 < _min2 ? _min1 : _min2; })
129 /* TODO: empty stubs for now. Broken but enough for virtio_ring.c */
130 #define list_add_tail(a, b) do {} while (0)
131 #define list_del(a) do {} while (0)
132 #define list_for_each_entry(a, b, c) while (0)
135 #endif /* KERNEL_H */