Skip to content

Commit 6be3ffa

Browse files
committed
tools/virtio: add dma stubs
Fixes build after recent IOMMU-related changes, mustly by adding more stubs. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 446374d commit 6be3ffa

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

tools/virtio/linux/dma-mapping.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,20 @@ enum dma_data_direction {
1414
DMA_NONE = 3,
1515
};
1616

17+
#define dma_alloc_coherent(d, s, hp, f) ({ \
18+
void *__dma_alloc_coherent_p = kmalloc((s), (f)); \
19+
*(hp) = (unsigned long)__dma_alloc_coherent_p; \
20+
__dma_alloc_coherent_p; \
21+
})
22+
23+
#define dma_free_coherent(d, s, p, h) kfree(p)
24+
25+
#define dma_map_page(d, p, o, s, dir) (page_to_phys(p) + (o))
26+
27+
#define dma_map_single(d, p, s, dir) (virt_to_phys(p))
28+
#define dma_mapping_error(...) (0)
29+
30+
#define dma_unmap_single(...) do { } while (0)
31+
#define dma_unmap_page(...) do { } while (0)
32+
1733
#endif

tools/virtio/linux/kernel.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
#define PAGE_SIZE getpagesize()
2222
#define PAGE_MASK (~(PAGE_SIZE-1))
23+
#define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
2324

25+
typedef unsigned long long phys_addr_t;
2426
typedef unsigned long long dma_addr_t;
2527
typedef size_t __kernel_size_t;
2628
typedef unsigned int __wsum;
@@ -57,13 +59,23 @@ static inline void *kzalloc(size_t s, gfp_t gfp)
5759
return p;
5860
}
5961

62+
static inline void *alloc_pages_exact(size_t s, gfp_t gfp)
63+
{
64+
return kmalloc(s, gfp);
65+
}
66+
6067
static inline void kfree(void *p)
6168
{
6269
if (p >= __kfree_ignore_start && p < __kfree_ignore_end)
6370
return;
6471
free(p);
6572
}
6673

74+
static inline void free_pages_exact(void *p, size_t s)
75+
{
76+
kfree(p);
77+
}
78+
6779
static inline void *krealloc(void *p, size_t s, gfp_t gfp)
6880
{
6981
return realloc(p, s);
@@ -105,6 +117,8 @@ static inline void free_page(unsigned long addr)
105117
#define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
106118
#define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
107119

120+
#define WARN_ON_ONCE(cond) ((cond) && fprintf (stderr, "WARNING\n"))
121+
108122
#define min(x, y) ({ \
109123
typeof(x) _min1 = (x); \
110124
typeof(y) _min2 = (y); \

tools/virtio/linux/slab.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
#ifndef LINUX_SLAB_H
2+
#define GFP_KERNEL 0
3+
#define GFP_ATOMIC 0
4+
#define __GFP_NOWARN 0
5+
#define __GFP_ZERO 0
26
#endif

tools/virtio/linux/virtio.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
#include <linux/scatterlist.h>
44
#include <linux/kernel.h>
55

6+
struct device {
7+
void *parent;
8+
};
9+
610
struct virtio_device {
7-
void *dev;
11+
struct device dev;
812
u64 features;
913
};
1014

tools/virtio/linux/virtio_config.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ static inline void __virtio_clear_bit(struct virtio_device *vdev,
4040
#define virtio_has_feature(dev, feature) \
4141
(__virtio_test_bit((dev), feature))
4242

43+
/**
44+
* virtio_has_iommu_quirk - determine whether this device has the iommu quirk
45+
* @vdev: the device
46+
*/
47+
static inline bool virtio_has_iommu_quirk(const struct virtio_device *vdev)
48+
{
49+
/*
50+
* Note the reverse polarity of the quirk feature (compared to most
51+
* other features), this is for compatibility with legacy systems.
52+
*/
53+
return !virtio_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
54+
}
55+
4356
static inline bool virtio_is_little_endian(struct virtio_device *vdev)
4457
{
4558
return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) ||

0 commit comments

Comments
 (0)