aboutsummaryrefslogtreecommitdiffstats
path: root/tools/virtio/linux/kernel.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-02 17:14:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-02 17:14:04 -0400
commit736a2dd2571ac56b11ed95a7814d838d5311be04 (patch)
treede10d107025970c6e51d5b6faeba799ed4b9caae /tools/virtio/linux/kernel.h
parent0b2e3b6bb4a415379f16e38fc92db42379be47a1 (diff)
parent01d779a14ef800b74684d9692add4944df052461 (diff)
Merge tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull virtio & lguest updates from Rusty Russell: "Lots of virtio work which wasn't quite ready for last merge window. Plus I dived into lguest again, reworking the pagetable code so we can move the switcher page: our fixmaps sometimes take more than 2MB now..." Ugh. Annoying conflicts with the tcm_vhost -> vhost_scsi rename. Hopefully correctly resolved. * tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: (57 commits) caif_virtio: Remove bouncing email addresses lguest: improve code readability in lg_cpu_start. virtio-net: fill only rx queues which are being used lguest: map Switcher below fixmap. lguest: cache last cpu we ran on. lguest: map Switcher text whenever we allocate a new pagetable. lguest: don't share Switcher PTE pages between guests. lguest: expost switcher_pages array (as lg_switcher_pages). lguest: extract shadow PTE walking / allocating. lguest: make check_gpte et. al return bool. lguest: assume Switcher text is a single page. lguest: rename switcher_page to switcher_pages. lguest: remove RESERVE_MEM constant. lguest: check vaddr not pgd for Switcher protection. lguest: prepare to make SWITCHER_ADDR a variable. virtio: console: replace EMFILE with EBUSY for already-open port virtio-scsi: reset virtqueue affinity when doing cpu hotplug virtio-scsi: introduce multiqueue support virtio-scsi: push vq lock/unlock into virtscsi_vq_done virtio-scsi: pass struct virtio_scsi to virtqueue completion function ...
Diffstat (limited to 'tools/virtio/linux/kernel.h')
-rw-r--r--tools/virtio/linux/kernel.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h
new file mode 100644
index 000000000000..fba705963968
--- /dev/null
+++ b/tools/virtio/linux/kernel.h
@@ -0,0 +1,112 @@
1#ifndef KERNEL_H
2#define KERNEL_H
3#include <stdbool.h>
4#include <stdlib.h>
5#include <stddef.h>
6#include <stdio.h>
7#include <string.h>
8#include <assert.h>
9#include <stdarg.h>
10
11#include <linux/types.h>
12#include <linux/printk.h>
13#include <linux/bug.h>
14#include <errno.h>
15#include <unistd.h>
16#include <asm/barrier.h>
17
18#define CONFIG_SMP
19
20#define PAGE_SIZE getpagesize()
21#define PAGE_MASK (~(PAGE_SIZE-1))
22
23typedef unsigned long long dma_addr_t;
24typedef size_t __kernel_size_t;
25
26struct page {
27 unsigned long long dummy;
28};
29
30/* Physical == Virtual */
31#define virt_to_phys(p) ((unsigned long)p)
32#define phys_to_virt(a) ((void *)(unsigned long)(a))
33/* Page address: Virtual / 4K */
34#define page_to_phys(p) ((dma_addr_t)(unsigned long)(p))
35#define virt_to_page(p) ((struct page *)((unsigned long)p & PAGE_MASK))
36
37#define offset_in_page(p) (((unsigned long)p) % PAGE_SIZE)
38
39#define __printf(a,b) __attribute__((format(printf,a,b)))
40
41typedef enum {
42 GFP_KERNEL,
43 GFP_ATOMIC,
44 __GFP_HIGHMEM,
45 __GFP_HIGH
46} gfp_t;
47
48#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
49
50extern void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
51static inline void *kmalloc(size_t s, gfp_t gfp)
52{
53 if (__kmalloc_fake)
54 return __kmalloc_fake;
55 return malloc(s);
56}
57
58static inline void kfree(void *p)
59{
60 if (p >= __kfree_ignore_start && p < __kfree_ignore_end)
61 return;
62 free(p);
63}
64
65static inline void *krealloc(void *p, size_t s, gfp_t gfp)
66{
67 return realloc(p, s);
68}
69
70
71static inline unsigned long __get_free_page(gfp_t gfp)
72{
73 void *p;
74
75 posix_memalign(&p, PAGE_SIZE, PAGE_SIZE);
76 return (unsigned long)p;
77}
78
79static inline void free_page(unsigned long addr)
80{
81 free((void *)addr);
82}
83
84#define container_of(ptr, type, member) ({ \
85 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
86 (type *)( (char *)__mptr - offsetof(type,member) );})
87
88#define uninitialized_var(x) x = x
89
90# ifndef likely
91# define likely(x) (__builtin_expect(!!(x), 1))
92# endif
93# ifndef unlikely
94# define unlikely(x) (__builtin_expect(!!(x), 0))
95# endif
96
97#define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
98#ifdef DEBUG
99#define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
100#else
101#define pr_debug(format, ...) do {} while (0)
102#endif
103#define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
104#define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
105
106#define min(x, y) ({ \
107 typeof(x) _min1 = (x); \
108 typeof(y) _min2 = (y); \
109 (void) (&_min1 == &_min2); \
110 _min1 < _min2 ? _min1 : _min2; })
111
112#endif /* KERNEL_H */