Blame view

include/xen/grant_table.h 6.45 KB
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
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
  /******************************************************************************
   * grant_table.h
   *
   * Two sets of functionality:
   * 1. Granting foreign access to our memory reservation.
   * 2. Accessing others' memory reservations via grant references.
   * (i.e., mechanisms for both sender and recipient of grant references)
   *
   * Copyright (c) 2004-2005, K A Fraser
   * Copyright (c) 2005, Christopher Clark
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License version 2
   * as published by the Free Software Foundation; or, when distributed
   * separately from the Linux kernel or incorporated into other
   * software packages, subject to the following license:
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this source file (the "Software"), to deal in the Software without
   * restriction, including without limitation the rights to use, copy, modify,
   * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   * and to permit persons to whom the Software is furnished to do so, subject to
   * the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   * IN THE SOFTWARE.
   */
  
  #ifndef __ASM_GNTTAB_H__
  #define __ASM_GNTTAB_H__
f07745325   Ian Campbell   xen: define gntta...
39
40
41
  #include <asm/page.h>
  
  #include <xen/interface/xen.h>
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
42
  #include <xen/interface/grant_table.h>
f07745325   Ian Campbell   xen: define gntta...
43
44
  
  #include <asm/xen/hypervisor.h>
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
45

f07745325   Ian Campbell   xen: define gntta...
46
  #include <xen/features.h>
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
47
48
49
50
51
52
53
54
55
  /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
  #define NR_GRANT_FRAMES 4
  
  struct gnttab_free_callback {
  	struct gnttab_free_callback *next;
  	void (*fn)(void *);
  	void *arg;
  	u16 count;
  };
183d03cc4   Stefano Stabellini   xen: Xen PCI plat...
56
  int gnttab_init(void);
0e91398f2   Jeremy Fitzhardinge   xen: implement sa...
57
58
  int gnttab_suspend(void);
  int gnttab_resume(void);
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
59
60
  int gnttab_grant_foreign_access(domid_t domid, unsigned long frame,
  				int readonly);
6666754b1   Annie Li   xen/granttable: S...
61
62
63
  int gnttab_grant_foreign_access_subpage(domid_t domid, unsigned long frame,
  					int flags, unsigned page_off,
  					unsigned length);
9438ce9db   Annie Li   xen/granttable: S...
64
65
66
  int gnttab_grant_foreign_access_trans(domid_t domid, int flags,
  				      domid_t trans_domid,
  				      grant_ref_t trans_gref);
6666754b1   Annie Li   xen/granttable: S...
67
68
69
70
71
72
  
  /*
   * Are sub-page grants available on this version of Xen?  Returns true if they
   * are, and false if they're not.
   */
  bool gnttab_subpage_grants_available(void);
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
73
74
  
  /*
9438ce9db   Annie Li   xen/granttable: S...
75
76
77
78
79
80
   * Are transitive grants available on this version of Xen?  Returns true if they
   * are, and false if they're not.
   */
  bool gnttab_trans_grants_available(void);
  
  /*
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
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
   * End access through the given grant reference, iff the grant entry is no
   * longer in use.  Return 1 if the grant entry was freed, 0 if it is still in
   * use.
   */
  int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly);
  
  /*
   * Eventually end access through the given grant reference, and once that
   * access has been ended, free the given page too.  Access will be ended
   * immediately iff the grant entry is not in use, otherwise it will happen
   * some time later.  page may be 0, in which case no freeing will occur.
   */
  void gnttab_end_foreign_access(grant_ref_t ref, int readonly,
  			       unsigned long page);
  
  int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn);
  
  unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref);
  unsigned long gnttab_end_foreign_transfer(grant_ref_t ref);
  
  int gnttab_query_foreign_access(grant_ref_t ref);
  
  /*
   * operations on reserved batches of grant references
   */
  int gnttab_alloc_grant_references(u16 count, grant_ref_t *pprivate_head);
  
  void gnttab_free_grant_reference(grant_ref_t ref);
  
  void gnttab_free_grant_references(grant_ref_t head);
  
  int gnttab_empty_grant_references(const grant_ref_t *pprivate_head);
  
  int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
  
  void gnttab_release_grant_reference(grant_ref_t *private_head,
  				    grant_ref_t release);
  
  void gnttab_request_free_callback(struct gnttab_free_callback *callback,
  				  void (*fn)(void *), void *arg, u16 count);
  void gnttab_cancel_free_callback(struct gnttab_free_callback *callback);
  
  void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
  				     unsigned long frame, int readonly);
6666754b1   Annie Li   xen/granttable: S...
125
126
127
128
  int gnttab_grant_foreign_access_subpage_ref(grant_ref_t ref, domid_t domid,
  					    unsigned long frame, int flags,
  					    unsigned page_off,
  					    unsigned length);
9438ce9db   Annie Li   xen/granttable: S...
129
130
131
  int gnttab_grant_foreign_access_trans_ref(grant_ref_t ref, domid_t domid,
  					  int flags, domid_t trans_domid,
  					  grant_ref_t trans_gref);
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
132
133
134
  
  void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid,
  				       unsigned long pfn);
f07745325   Ian Campbell   xen: define gntta...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  static inline void
  gnttab_set_map_op(struct gnttab_map_grant_ref *map, phys_addr_t addr,
  		  uint32_t flags, grant_ref_t ref, domid_t domid)
  {
  	if (flags & GNTMAP_contains_pte)
  		map->host_addr = addr;
  	else if (xen_feature(XENFEAT_auto_translated_physmap))
  		map->host_addr = __pa(addr);
  	else
  		map->host_addr = addr;
  
  	map->flags = flags;
  	map->ref = ref;
  	map->dom = domid;
  }
  
  static inline void
  gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, phys_addr_t addr,
  		    uint32_t flags, grant_handle_t handle)
  {
  	if (flags & GNTMAP_contains_pte)
  		unmap->host_addr = addr;
  	else if (xen_feature(XENFEAT_auto_translated_physmap))
  		unmap->host_addr = __pa(addr);
  	else
  		unmap->host_addr = addr;
  
  	unmap->handle = handle;
  	unmap->dev_bus_addr = 0;
  }
8d3d2106c   Isaku Yamahata   xen: make grant t...
165
166
  int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
  			   unsigned long max_nr_gframes,
0f9f5a958   Annie Li   xen/granttable: I...
167
  			   void **__shared);
85ff6acb0   Annie Li   xen/granttable: G...
168
169
170
171
  int arch_gnttab_map_status(uint64_t *frames, unsigned long nr_gframes,
  			   unsigned long max_nr_gframes,
  			   grant_status_t **__shared);
  void arch_gnttab_unmap(void *shared, unsigned long nr_gframes);
8d3d2106c   Isaku Yamahata   xen: make grant t...
172

183d03cc4   Stefano Stabellini   xen: Xen PCI plat...
173
174
  extern unsigned long xen_hvm_resume_frames;
  unsigned int gnttab_max_grant_frames(void);
ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
175
  #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
289b777ea   Stefano Stabellini   xen: introduce gn...
176
  int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
c123799a4   Annie Li   xen/granttable: K...
177
  		    struct gnttab_map_grant_ref *kmap_ops,
289b777ea   Stefano Stabellini   xen: introduce gn...
178
179
  		    struct page **pages, unsigned int count);
  int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
7d17e84bb   Daniel De Graaf   xen/grant-table: ...
180
  		      struct page **pages, unsigned int count, bool clear_pte);
289b777ea   Stefano Stabellini   xen: introduce gn...
181

ad9a86121   Jeremy Fitzhardinge   xen: Add grant ta...
182
  #endif /* __ASM_GNTTAB_H__ */