Xen Test Framework
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. */
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 
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 )
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 )
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  */
domid_t domid
Definition: memory.h:23
#define IS_DEFINED(x)
Evalute whether the CONFIG_ token x is defined.
Definition: macro_magic.h:67
Macros for creating constants using mnemonics.
static long hypercall_update_va_mapping(unsigned long linear, uint64_t npte, enum XEN_UVMF flags)
Definition: hypercall.h:115
#define ARRAY_SIZE(a)
Definition: lib.h:8
#define GNTTABOP_setup_table
Definition: grant_table.h:266
uint8_t gnttab_raw[]
Raw grant table mapping from Xen.
Definition: grant_table.c:9
#define _u(v)
Express an arbitrary value v as unsigned long.
Definition: numbers.h:53
void printk(const char *fmt,...)
Definition: console.c:134
intpte_t pte_from_gfn(unsigned long gfn, uint64_t flags)
#define PF_SYM(...)
Create pagetable entry flags based on mnemonics.
#define XENMEM_add_to_physmap
Definition: memory.h:20
#define EIO
Definition: errno.h:19
#define XENMAPSPACE_grant_table
Definition: memory.h:27
static unsigned long virt_to_gfn(const void *va)
Definition: mm.h:100
int arch_map_gnttab(void)
Map the domains grant table under gnttab_raw[].
Definition: grant_table.c:13
const char * gntst_strerror(int err)
Convert a grant status error value to a string.
Definition: grant_table.c:13
unsigned long gfn
Definition: memory.h:35
#define PAGE_SIZE
Definition: page.h:11
static long hypercall_grant_table_op(unsigned int cmd, void *args, unsigned int count)
Definition: hypercall.h:131
#define BUILD_BUG_ON(cond)
Definition: lib.h:24
#define DOMID_SELF
Definition: xen.h:70
A driver for the Xen Grant Table interface.
static long hypercall_memory_op(unsigned int cmd, void *arg)
Definition: hypercall.h:100
unsigned long idx
Definition: memory.h:34