summaryrefslogtreecommitdiff
path: root/tools/testing/scatterlist/linux/mm.h
blob: 6f9ac14aa80076920ca5cc0a66b463a468382899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef _LINUX_MM_H
#define _LINUX_MM_H

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>

typedef unsigned long dma_addr_t;

#define unlikely

#define BUG_ON(x) assert(!(x))

#define WARN_ON(condition) ({                                           \
	int __ret_warn_on = !!(condition);                              \
	unlikely(__ret_warn_on);                                        \
})

#define WARN_ON_ONCE(condition) ({                              \
	int __ret_warn_on = !!(condition);                      \
	if (unlikely(__ret_warn_on))                            \
		assert(0);                                      \
	unlikely(__ret_warn_on);                                \
})

#define PAGE_SIZE	(4096)
#define PAGE_SHIFT	(12)
#define PAGE_MASK	(~(PAGE_SIZE-1))

#define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
#define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
#define ALIGN(x, a)			__ALIGN_KERNEL((x), (a))

#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)

#define offset_in_page(p)	((unsigned long)(p) & ~PAGE_MASK)

#define virt_to_page(x)	((void *)x)
#define page_address(x)	((void *)x)

static inline unsigned long page_to_phys(struct page *page)
{
	assert(0);

	return 0;
}

#define page_to_pfn(page) ((unsigned long)(page) / PAGE_SIZE)
#define pfn_to_page(pfn) (void *)((pfn) * PAGE_SIZE)
#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))

#define __min(t1, t2, min1, min2, x, y) ({              \
	t1 min1 = (x);                                  \
	t2 min2 = (y);                                  \
	(void) (&min1 == &min2);                        \
	min1 < min2 ? min1 : min2; })

#define ___PASTE(a,b) a##b
#define __PASTE(a,b) ___PASTE(a,b)

#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)

#define min(x, y)                                       \
	__min(typeof(x), typeof(y),                     \
	      __UNIQUE_ID(min1_), __UNIQUE_ID(min2_),   \
	      x, y)

#define min_t(type, x, y)                               \
	__min(type, type,                               \
	      __UNIQUE_ID(min1_), __UNIQUE_ID(min2_),   \
	      x, y)

#define preemptible() (1)

static inline void *kmap(struct page *page)
{
	assert(0);

	return NULL;
}

static inline void *kmap_atomic(struct page *page)
{
	assert(0);

	return NULL;
}

static inline void kunmap(void *addr)
{
	assert(0);
}

static inline void kunmap_atomic(void *addr)
{
	assert(0);
}

static inline unsigned long __get_free_page(unsigned int flags)
{
	return (unsigned long)malloc(PAGE_SIZE);
}

static inline void free_page(unsigned long page)
{
	free((void *)page);
}

static inline void *kmalloc(unsigned int size, unsigned int flags)
{
	return malloc(size);
}

#define kfree(x) free(x)

#define kmemleak_alloc(a, b, c, d)
#define kmemleak_free(a)

#define PageSlab(p) (0)
#define flush_kernel_dcache_page(p)

#endif