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