xref: /titanic_52/usr/src/uts/common/xen/sys/gnttab.h (revision 29493bd8e037cbaea9095b34172305abb589cb6b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_GNTTAB_H
28 #define	_SYS_GNTTAB_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * gnttab.h
34  *
35  * Two sets of functionality:
36  * 1. Granting foreign access to our memory reservation.
37  * 2. Accessing others' memory reservations via grant references.
38  * (i.e., mechanisms for both sender and recipient of grant references)
39  *
40  * Copyright (c) 2004-2005, K A Fraser
41  * Copyright (c) 2005, Christopher Clark
42  *
43  * This file may be distributed separately from the Linux kernel, or
44  * incorporated into other software packages, subject to the following license:
45  *
46  * Permission is hereby granted, free of charge, to any person obtaining a copy
47  * of this source file (the "Software"), to deal in the Software without
48  * restriction, including without limitation the rights to use, copy, modify,
49  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
50  * and to permit persons to whom the Software is furnished to do so, subject to
51  * the following conditions:
52  *
53  * The above copyright notice and this permission notice shall be included in
54  * all copies or substantial portions of the Software.
55  *
56  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
61  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
62  * IN THE SOFTWARE.
63  */
64 
65 #include <sys/hypervisor.h>
66 #include <xen/public/grant_table.h>
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
73 #ifdef __ia64__
74 #define	NR_GRANT_FRAMES 1
75 #else
76 #define	NR_GRANT_FRAMES 4
77 #endif
78 
79 struct gnttab_free_callback {
80 	struct gnttab_free_callback *next;
81 	void (*fn)(void *);
82 	void *arg;
83 	uint16_t count;
84 };
85 
86 /*
87  * For i86xpv the "frames" in grant table terminology are really MFNs.
88  */
89 typedef mfn_t gnttab_frame_t;
90 #define	FRAME_TO_MA(f)	((maddr_t)(f) << PAGESHIFT)
91 
92 int gnttab_grant_foreign_access(domid_t, gnttab_frame_t, int readonly);
93 
94 /*
95  * End access through the given grant reference, iff the grant entry is no
96  * longer in use.  Return 1 if the grant entry was freed, 0 if it is still in
97  * use.
98  */
99 int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly);
100 
101 /*
102  * Eventually end access through the given grant reference, and once that
103  * access has been ended, free the given page too.  Access will be ended
104  * immediately iff the grant entry is not in use, otherwise it will happen
105  * some time later.  page may be 0, in which case no freeing will occur.
106  */
107 void gnttab_end_foreign_access(grant_ref_t ref, int readonly,
108 	gnttab_frame_t page);
109 
110 int gnttab_grant_foreign_transfer(domid_t domid);
111 
112 gnttab_frame_t gnttab_end_foreign_transfer_ref(grant_ref_t ref);
113 gnttab_frame_t gnttab_end_foreign_transfer(grant_ref_t ref);
114 
115 int gnttab_query_foreign_access(grant_ref_t ref);
116 
117 /*
118  * operations on reserved batches of grant references
119  */
120 int gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head);
121 
122 void gnttab_free_grant_reference(grant_ref_t ref);
123 
124 void gnttab_free_grant_references(grant_ref_t head);
125 
126 int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
127 
128 void gnttab_release_grant_reference(grant_ref_t *private_head,
129 	grant_ref_t release);
130 
131 void gnttab_request_free_callback(struct gnttab_free_callback *callback,
132 	void (*fn)(void *), void *arg, uint16_t count);
133 
134 void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
135 	gnttab_frame_t frame, int readonly);
136 
137 void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid);
138 
139 #define	gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
140 
141 /*
142  * framework
143  */
144 void gnttab_init(void);
145 void gnttab_suspend(void);
146 void gnttab_resume(void);
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif /* _SYS_GNTTAB_H */
153