1 /******************************************************************************
4 * Two sets of functionality:
5 * 1. Granting foreign access to our memory reservation.
6 * 2. Accessing others' memory reservations via grant references.
7 * (i.e., mechanisms for both sender and recipient of grant references)
9 * Copyright (c) 2004-2005, K A Fraser
10 * Copyright (c) 2005, Christopher Clark
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation; or, when distributed
15 * separately from the Linux kernel or incorporated into other
16 * software packages, subject to the following license:
18 * Permission is hereby granted, free of charge, to any person obtaining a copy
19 * of this source file (the "Software"), to deal in the Software without
20 * restriction, including without limitation the rights to use, copy, modify,
21 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
22 * and to permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
25 * The above copyright notice and this permission notice shall be included in
26 * all copies or substantial portions of the Software.
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
37 #ifndef __ASM_GNTTAB_H__
38 #define __ASM_GNTTAB_H__
40 #include <asm/hypervisor.h>
41 #include <asm/maddr.h> /* maddr_t */
43 #include <linux/delay.h>
44 #include <xen/interface/grant_table.h>
45 #include <xen/features.h>
47 #define GRANT_INVALID_REF 0
49 struct gnttab_free_callback {
50 struct gnttab_free_callback *next;
57 int gnttab_grant_foreign_access(domid_t domid, unsigned long frame,
61 * End access through the given grant reference, iff the grant entry is no
62 * longer in use. Return 1 if the grant entry was freed, 0 if it is still in
65 int gnttab_end_foreign_access_ref(grant_ref_t ref);
68 * Eventually end access through the given grant reference, and once that
69 * access has been ended, free the given page too. Access will be ended
70 * immediately iff the grant entry is not in use, otherwise it will happen
71 * some time later. page may be 0, in which case no freeing will occur.
73 void gnttab_end_foreign_access(grant_ref_t ref, unsigned long page);
75 int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn);
77 unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref);
78 unsigned long gnttab_end_foreign_transfer(grant_ref_t ref);
80 int gnttab_query_foreign_access(grant_ref_t ref);
83 * operations on reserved batches of grant references
85 int gnttab_alloc_grant_references(u16 count, grant_ref_t *pprivate_head);
87 void gnttab_free_grant_reference(grant_ref_t ref);
89 void gnttab_free_grant_references(grant_ref_t head);
91 int gnttab_empty_grant_references(const grant_ref_t *pprivate_head);
93 int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
95 void gnttab_release_grant_reference(grant_ref_t *private_head,
98 void gnttab_request_free_callback(struct gnttab_free_callback *callback,
99 void (*fn)(void *), void *arg, u16 count);
100 void gnttab_cancel_free_callback(struct gnttab_free_callback *callback);
102 void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
103 unsigned long frame, int flags);
105 void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid,
108 int gnttab_copy_grant_page(grant_ref_t ref, struct page **pagep);
109 #if defined(CONFIG_XEN_BACKEND) || defined(CONFIG_XEN_BACKEND_MODULE)
110 void __gnttab_dma_map_page(struct page *page);
112 #define __gnttab_dma_map_page __gnttab_dma_unmap_page
114 static inline void __gnttab_dma_unmap_page(struct page *page)
118 void gnttab_reset_grant_page(struct page *page);
121 int gnttab_resume(void);
124 void *arch_gnttab_alloc_shared(unsigned long *frames);
127 gnttab_set_map_op(struct gnttab_map_grant_ref *map, maddr_t addr,
128 uint32_t flags, grant_ref_t ref, domid_t domid)
130 if (flags & GNTMAP_contains_pte)
131 map->host_addr = addr;
132 else if (xen_feature(XENFEAT_auto_translated_physmap))
133 map->host_addr = __pa(addr);
135 map->host_addr = addr;
143 gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, maddr_t addr,
144 uint32_t flags, grant_handle_t handle)
146 if (flags & GNTMAP_contains_pte)
147 unmap->host_addr = addr;
148 else if (xen_feature(XENFEAT_auto_translated_physmap))
149 unmap->host_addr = __pa(addr);
151 unmap->host_addr = addr;
153 unmap->handle = handle;
154 unmap->dev_bus_addr = 0;
158 gnttab_set_replace_op(struct gnttab_unmap_and_replace *unmap, maddr_t addr,
159 maddr_t new_addr, grant_handle_t handle)
161 if (xen_feature(XENFEAT_auto_translated_physmap)) {
162 unmap->host_addr = __pa(addr);
163 unmap->new_addr = __pa(new_addr);
165 unmap->host_addr = addr;
166 unmap->new_addr = new_addr;
169 unmap->handle = handle;
172 #define gnttab_check_GNTST_eagain_while(__HCop, __HCarg_p) \
176 while (unlikely((__HCarg_p)->status == GNTST_eagain && __hc_delay)) { \
177 msleep(__hc_delay++); \
178 __ret = HYPERVISOR_grant_table_op(__HCop, (__HCarg_p), 1); \
181 if (__hc_delay == 0) { \
182 pr_err("%s: %s gnt busy\n", __func__, current->comm); \
183 (__HCarg_p)->status = GNTST_bad_page; \
185 if ((__HCarg_p)->status != GNTST_okay) \
186 pr_err("%s: %s gnt status %x\n", \
187 __func__, current->comm, (__HCarg_p)->status); \
190 #define gnttab_check_GNTST_eagain_do_while(__HCop, __HCarg_p) \
195 __ret = HYPERVISOR_grant_table_op(__HCop, (__HCarg_p), 1); \
197 if ((__HCarg_p)->status == GNTST_eagain) \
198 msleep(__hc_delay++); \
199 } while ((__HCarg_p)->status == GNTST_eagain && __hc_delay); \
200 if (__hc_delay == 0) { \
201 pr_err("%s: %s gnt busy\n", __func__, current->comm); \
202 (__HCarg_p)->status = GNTST_bad_page; \
204 if ((__HCarg_p)->status != GNTST_okay) \
205 pr_err("%s: %s gnt status %x\n", \
206 __func__, current->comm, (__HCarg_p)->status); \
209 #endif /* __ASM_GNTTAB_H__ */