blob: 2a51fcbacb6b54c2e9d4ad5a325a70e242e2b525 (
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
126
127
128
|
/******************************************************************************
* domain_page.h
*
* Allow temporary mapping of domain page frames into Xen space.
*
* Copyright (c) 2003-2006, Keir Fraser <keir@xensource.com>
*/
#ifndef __XEN_DOMAIN_PAGE_H__
#define __XEN_DOMAIN_PAGE_H__
#include <xen/config.h>
#include <xen/mm.h>
#ifdef CONFIG_DOMAIN_PAGE
/*
* Map a given page frame, returning the mapped virtual address. The page is
* then accessible within the current VCPU until a corresponding unmap call.
*/
extern void *map_domain_page(unsigned long pfn);
/*
* Pass a VA within a page previously mapped in the context of the
* currently-executing VCPU via a call to map_domain_pages().
*/
extern void unmap_domain_page(void *va);
/*
* Convert a VA (within a page previously mapped in the context of the
* currently-executing VCPU via a call to map_domain_pages()) to a machine
* address
*/
extern paddr_t mapped_domain_page_to_maddr(void *va);
/*
* Similar to the above calls, except the mapping is accessible in all
* address spaces (not just within the VCPU that created the mapping). Global
* mappings can also be unmapped from any context.
*/
extern void *map_domain_page_global(unsigned long pfn);
extern void unmap_domain_page_global(void *va);
#define DMCACHE_ENTRY_VALID 1U
#define DMCACHE_ENTRY_HELD 2U
struct domain_mmap_cache {
unsigned long pfn;
void *va;
unsigned int flags;
};
static inline void
domain_mmap_cache_init(struct domain_mmap_cache *cache)
{
ASSERT(cache != NULL);
cache->flags = 0;
cache->pfn = 0;
cache->va = NULL;
}
static inline void *
map_domain_page_with_cache(unsigned long pfn, struct domain_mmap_cache *cache)
{
ASSERT(cache != NULL);
BUG_ON(cache->flags & DMCACHE_ENTRY_HELD);
if ( likely(cache->flags & DMCACHE_ENTRY_VALID) )
{
cache->flags |= DMCACHE_ENTRY_HELD;
if ( likely(pfn == cache->pfn) )
goto done;
unmap_domain_page(cache->va);
}
cache->pfn = pfn;
cache->va = map_domain_page(pfn);
cache->flags = DMCACHE_ENTRY_HELD | DMCACHE_ENTRY_VALID;
done:
return cache->va;
}
static inline void
unmap_domain_page_with_cache(void *va, struct domain_mmap_cache *cache)
{
ASSERT(cache != NULL);
cache->flags &= ~DMCACHE_ENTRY_HELD;
}
static inline void
domain_mmap_cache_destroy(struct domain_mmap_cache *cache)
{
ASSERT(cache != NULL);
BUG_ON(cache->flags & DMCACHE_ENTRY_HELD);
if ( likely(cache->flags & DMCACHE_ENTRY_VALID) )
{
unmap_domain_page(cache->va);
cache->flags = 0;
}
}
#else /* !CONFIG_DOMAIN_PAGE */
#define map_domain_page(pfn) maddr_to_virt((pfn)<<PAGE_SHIFT)
#define unmap_domain_page(va) ((void)(va))
#define mapped_domain_page_to_maddr(va) (virt_to_maddr(va))
#define map_domain_page_global(pfn) maddr_to_virt((pfn)<<PAGE_SHIFT)
#define unmap_domain_page_global(va) ((void)(va))
struct domain_mmap_cache {
};
#define domain_mmap_cache_init(c) ((void)(c))
#define map_domain_page_with_cache(pfn,c) (map_domain_page(pfn))
#define unmap_domain_page_with_cache(va,c) ((void)(va))
#define domain_mmap_cache_destroy(c) ((void)(c))
#endif /* !CONFIG_DOMAIN_PAGE */
#define HERE_I_AM \
do { \
printk("HERE I AM: %s %s %d\n", __func__, __FILE__, __LINE__); \
} while (0)
#endif /* __XEN_DOMAIN_PAGE_H__ */
|