~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/virtio/linux/kernel.h

Version: ~ [ linux-5.1-rc1 ] ~ [ linux-5.0.3 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.30 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.107 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.164 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.176 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.136 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.63 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef KERNEL_H
  3 #define KERNEL_H
  4 #include <stdbool.h>
  5 #include <stdlib.h>
  6 #include <stddef.h>
  7 #include <stdio.h>
  8 #include <string.h>
  9 #include <assert.h>
 10 #include <stdarg.h>
 11 
 12 #include <linux/compiler.h>
 13 #include <linux/types.h>
 14 #include <linux/printk.h>
 15 #include <linux/bug.h>
 16 #include <errno.h>
 17 #include <unistd.h>
 18 #include <asm/barrier.h>
 19 
 20 #define CONFIG_SMP
 21 
 22 #define PAGE_SIZE getpagesize()
 23 #define PAGE_MASK (~(PAGE_SIZE-1))
 24 #define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
 25 
 26 /* generic data direction definitions */
 27 #define READ                    0
 28 #define WRITE                   1
 29 
 30 typedef unsigned long long phys_addr_t;
 31 typedef unsigned long long dma_addr_t;
 32 typedef size_t __kernel_size_t;
 33 typedef unsigned int __wsum;
 34 
 35 struct page {
 36         unsigned long long dummy;
 37 };
 38 
 39 /* Physical == Virtual */
 40 #define virt_to_phys(p) ((unsigned long)p)
 41 #define phys_to_virt(a) ((void *)(unsigned long)(a))
 42 /* Page address: Virtual / 4K */
 43 #define page_to_phys(p) ((dma_addr_t)(unsigned long)(p))
 44 #define virt_to_page(p) ((struct page *)((unsigned long)p & PAGE_MASK))
 45 
 46 #define offset_in_page(p) (((unsigned long)p) % PAGE_SIZE)
 47 
 48 #define __printf(a,b) __attribute__((format(printf,a,b)))
 49 
 50 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 51 
 52 extern void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
 53 static inline void *kmalloc(size_t s, gfp_t gfp)
 54 {
 55         if (__kmalloc_fake)
 56                 return __kmalloc_fake;
 57         return malloc(s);
 58 }
 59 static inline void *kmalloc_array(unsigned n, size_t s, gfp_t gfp)
 60 {
 61         return kmalloc(n * s, gfp);
 62 }
 63 
 64 static inline void *kzalloc(size_t s, gfp_t gfp)
 65 {
 66         void *p = kmalloc(s, gfp);
 67 
 68         memset(p, 0, s);
 69         return p;
 70 }
 71 
 72 static inline void *alloc_pages_exact(size_t s, gfp_t gfp)
 73 {
 74         return kmalloc(s, gfp);
 75 }
 76 
 77 static inline void kfree(void *p)
 78 {
 79         if (p >= __kfree_ignore_start && p < __kfree_ignore_end)
 80                 return;
 81         free(p);
 82 }
 83 
 84 static inline void free_pages_exact(void *p, size_t s)
 85 {
 86         kfree(p);
 87 }
 88 
 89 static inline void *krealloc(void *p, size_t s, gfp_t gfp)
 90 {
 91         return realloc(p, s);
 92 }
 93 
 94 
 95 static inline unsigned long __get_free_page(gfp_t gfp)
 96 {
 97         void *p;
 98 
 99         posix_memalign(&p, PAGE_SIZE, PAGE_SIZE);
100         return (unsigned long)p;
101 }
102 
103 static inline void free_page(unsigned long addr)
104 {
105         free((void *)addr);
106 }
107 
108 #define container_of(ptr, type, member) ({                      \
109         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
110         (type *)( (char *)__mptr - offsetof(type,member) );})
111 
112 #define uninitialized_var(x) x = x
113 
114 # ifndef likely
115 #  define likely(x)     (__builtin_expect(!!(x), 1))
116 # endif
117 # ifndef unlikely
118 #  define unlikely(x)   (__builtin_expect(!!(x), 0))
119 # endif
120 
121 #define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
122 #ifdef DEBUG
123 #define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
124 #else
125 #define pr_debug(format, ...) do {} while (0)
126 #endif
127 #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
128 #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
129 
130 #define WARN_ON_ONCE(cond) ((cond) ? fprintf (stderr, "WARNING\n") : 0)
131 
132 #define min(x, y) ({                            \
133         typeof(x) _min1 = (x);                  \
134         typeof(y) _min2 = (y);                  \
135         (void) (&_min1 == &_min2);              \
136         _min1 < _min2 ? _min1 : _min2; })
137 
138 /* TODO: empty stubs for now. Broken but enough for virtio_ring.c */
139 #define list_add_tail(a, b) do {} while (0)
140 #define list_del(a) do {} while (0)
141 #define list_for_each_entry(a, b, c) while (0)
142 /* end of stubs */
143 
144 #endif /* KERNEL_H */
145 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp