Xen Test Framework
arch
x86
grant_table.c
Go to the documentation of this file.
1
6
#include <
xtf/grant_table.h
>
7
#include <
xtf/hypercall.h
>
8
#include <
xtf/lib.h
>
9
10
#include <
arch/pagetable.h
>
11
#include <
arch/symbolic-const.h
>
12
13
int
arch_map_gnttab
(
void
)
14
{
15
unsigned
int
i;
16
int
rc = 0;
17
18
/* Ensure gnttab_raw[] is a whole number of pages. */
19
BUILD_BUG_ON
(
sizeof
(
gnttab_raw
) %
PAGE_SIZE
);
20
21
if
(
IS_DEFINED
(CONFIG_PV) )
22
{
23
unsigned
long
gnttab_gfns[
sizeof
(
gnttab_raw
) /
PAGE_SIZE
] = {};
24
struct
gnttab_setup_table
setup = {
25
.
dom
=
DOMID_SELF
,
26
.nr_frames =
ARRAY_SIZE
(gnttab_gfns),
27
.frame_list = gnttab_gfns,
28
};
29
30
rc =
hypercall_grant_table_op
(
GNTTABOP_setup_table
, &setup, 1);
31
if
( rc || setup.
status
)
32
{
33
printk
(
"%s() GNTTABOP_setup_table failed: rc %d, status %d: %s\n"
,
34
__func__, rc, setup.
status
,
gntst_strerror
(setup.
status
));
35
return
-
EIO
;
36
}
37
38
for
( i = 0; !rc && i <
ARRAY_SIZE
(gnttab_gfns); ++i )
39
rc =
hypercall_update_va_mapping
(
40
_u
(&
gnttab_raw
[i *
PAGE_SIZE
]),
41
pte_from_gfn
(gnttab_gfns[i],
PF_SYM
(AD, RW, P)),
UVMF_INVLPG
);
42
}
43
else
/* HVM */
44
{
45
struct
xen_add_to_physmap
xatp = {
46
.
domid
=
DOMID_SELF
,
47
.space =
XENMAPSPACE_grant_table
,
48
.idx = 0,
49
.gfn =
virt_to_gfn
(
gnttab_raw
),
50
};
51
52
for
( i = 0; !rc && i < (
sizeof
(
gnttab_raw
) /
PAGE_SIZE
);
53
++i, ++xatp.
idx
, ++xatp.
gfn
)
54
rc =
hypercall_memory_op
(
XENMEM_add_to_physmap
, &xatp);
55
}
56
57
if
( rc )
58
{
59
printk
(
"%s() Failed to map gnttab[%u]: %d\n"
, __func__, i, rc);
60
return
-
EIO
;
61
}
62
63
return
0;
64
}
65
66
/*
67
* Local variables:
68
* mode: C
69
* c-file-style: "BSD"
70
* c-basic-offset: 4
71
* tab-width: 4
72
* indent-tabs-mode: nil
73
* End:
74
*/
arch_map_gnttab
int arch_map_gnttab(void)
Map the domains grant table under gnttab_raw[].
Definition:
grant_table.c:13
gntst_strerror
const char * gntst_strerror(int err)
Convert a grant status error value to a string.
Definition:
grant_table.c:13
gnttab_raw
uint8_t gnttab_raw[]
Raw grant table mapping from Xen.
Definition:
grant_table.c:9
printk
void printk(const char *fmt,...)
Definition:
console.c:134
EIO
#define EIO
Definition:
errno.h:19
hypercall.h
hypercall_update_va_mapping
static long hypercall_update_va_mapping(unsigned long linear, uint64_t npte, enum XEN_UVMF flags)
Definition:
hypercall.h:115
hypercall_memory_op
static long hypercall_memory_op(unsigned int cmd, void *arg)
Definition:
hypercall.h:100
hypercall_grant_table_op
static long hypercall_grant_table_op(unsigned int cmd, void *args, unsigned int count)
Definition:
hypercall.h:131
lib.h
ARRAY_SIZE
#define ARRAY_SIZE(a)
Definition:
lib.h:8
BUILD_BUG_ON
#define BUILD_BUG_ON(cond)
Definition:
lib.h:24
IS_DEFINED
#define IS_DEFINED(x)
Evalute whether the CONFIG_ token x is defined.
Definition:
macro_magic.h:67
XENMEM_add_to_physmap
#define XENMEM_add_to_physmap
Definition:
memory.h:22
XENMAPSPACE_grant_table
#define XENMAPSPACE_grant_table
Definition:
memory.h:29
virt_to_gfn
static unsigned long virt_to_gfn(const void *va)
Definition:
mm.h:100
_u
#define _u(v)
Express an arbitrary value v as unsigned long.
Definition:
numbers.h:53
PAGE_SIZE
#define PAGE_SIZE
Definition:
page.h:11
pagetable.h
pte_from_gfn
intpte_t pte_from_gfn(unsigned long gfn, uint64_t flags)
gnttab_setup_table
Definition:
grant_table.h:268
gnttab_setup_table::status
int16_t status
Definition:
grant_table.h:273
gnttab_setup_table::dom
domid_t dom
Definition:
grant_table.h:270
xen_add_to_physmap
Definition:
memory.h:24
xen_add_to_physmap::gfn
unsigned long gfn
Definition:
memory.h:37
xen_add_to_physmap::domid
domid_t domid
Definition:
memory.h:25
xen_add_to_physmap::idx
unsigned long idx
Definition:
memory.h:36
symbolic-const.h
Macros for creating constants using mnemonics.
PF_SYM
#define PF_SYM(...)
Create pagetable entry flags based on mnemonics.
Definition:
symbolic-const.h:108
GNTTABOP_setup_table
#define GNTTABOP_setup_table
Definition:
grant_table.h:266
DOMID_SELF
#define DOMID_SELF
Definition:
xen.h:70
UVMF_INVLPG
@ UVMF_INVLPG
Definition:
xen.h:383
grant_table.h
A driver for the Xen Grant Table interface.
Generated by
1.9.4