xref: /titanic_51/usr/src/uts/common/xen/sys/gnttab.h (revision a576ab5b6e08c47732b3dedca9eaa8a8cbb85720)
1551bc2a6Smrj /*
2551bc2a6Smrj  * CDDL HEADER START
3551bc2a6Smrj  *
4551bc2a6Smrj  * The contents of this file are subject to the terms of the
5551bc2a6Smrj  * Common Development and Distribution License (the "License").
6551bc2a6Smrj  * You may not use this file except in compliance with the License.
7551bc2a6Smrj  *
8551bc2a6Smrj  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9551bc2a6Smrj  * or http://www.opensolaris.org/os/licensing.
10551bc2a6Smrj  * See the License for the specific language governing permissions
11551bc2a6Smrj  * and limitations under the License.
12551bc2a6Smrj  *
13551bc2a6Smrj  * When distributing Covered Code, include this CDDL HEADER in each
14551bc2a6Smrj  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15551bc2a6Smrj  * If applicable, add the following below this CDDL HEADER, with the
16551bc2a6Smrj  * fields enclosed by brackets "[]" replaced with your own identifying
17551bc2a6Smrj  * information: Portions Copyright [yyyy] [name of copyright owner]
18551bc2a6Smrj  *
19551bc2a6Smrj  * CDDL HEADER END
20551bc2a6Smrj  */
21551bc2a6Smrj 
22551bc2a6Smrj /*
23*a576ab5bSrab  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24551bc2a6Smrj  * Use is subject to license terms.
25551bc2a6Smrj  */
26551bc2a6Smrj 
27551bc2a6Smrj #ifndef	_SYS_GNTTAB_H
28551bc2a6Smrj #define	_SYS_GNTTAB_H
29551bc2a6Smrj 
30551bc2a6Smrj #pragma ident	"%Z%%M%	%I%	%E% SMI"
31551bc2a6Smrj 
32551bc2a6Smrj /*
33551bc2a6Smrj  * gnttab.h
34551bc2a6Smrj  *
35551bc2a6Smrj  * Two sets of functionality:
36551bc2a6Smrj  * 1. Granting foreign access to our memory reservation.
37551bc2a6Smrj  * 2. Accessing others' memory reservations via grant references.
38551bc2a6Smrj  * (i.e., mechanisms for both sender and recipient of grant references)
39551bc2a6Smrj  *
40551bc2a6Smrj  * Copyright (c) 2004-2005, K A Fraser
41551bc2a6Smrj  * Copyright (c) 2005, Christopher Clark
42551bc2a6Smrj  *
43*a576ab5bSrab  * This program is free software; you can redistribute it and/or
44*a576ab5bSrab  * modify it under the terms of the GNU General Public License version 2
45*a576ab5bSrab  * as published by the Free Software Foundation; or, when distributed
46*a576ab5bSrab  * separately from the Linux kernel or incorporated into other
47*a576ab5bSrab  * software packages, subject to the following license:
48551bc2a6Smrj  *
49551bc2a6Smrj  * Permission is hereby granted, free of charge, to any person obtaining a copy
50551bc2a6Smrj  * of this source file (the "Software"), to deal in the Software without
51551bc2a6Smrj  * restriction, including without limitation the rights to use, copy, modify,
52551bc2a6Smrj  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
53551bc2a6Smrj  * and to permit persons to whom the Software is furnished to do so, subject to
54551bc2a6Smrj  * the following conditions:
55551bc2a6Smrj  *
56551bc2a6Smrj  * The above copyright notice and this permission notice shall be included in
57551bc2a6Smrj  * all copies or substantial portions of the Software.
58551bc2a6Smrj  *
59551bc2a6Smrj  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60551bc2a6Smrj  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61551bc2a6Smrj  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62551bc2a6Smrj  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63551bc2a6Smrj  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
64551bc2a6Smrj  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
65551bc2a6Smrj  * IN THE SOFTWARE.
66551bc2a6Smrj  */
67551bc2a6Smrj 
68551bc2a6Smrj #include <sys/hypervisor.h>
69551bc2a6Smrj #include <xen/public/grant_table.h>
70*a576ab5bSrab #include <xen/public/features.h>
71551bc2a6Smrj 
72551bc2a6Smrj #ifdef __cplusplus
73551bc2a6Smrj extern "C" {
74551bc2a6Smrj #endif
75551bc2a6Smrj 
76551bc2a6Smrj struct gnttab_free_callback {
77551bc2a6Smrj 	struct gnttab_free_callback *next;
78551bc2a6Smrj 	void (*fn)(void *);
79551bc2a6Smrj 	void *arg;
80551bc2a6Smrj 	uint16_t count;
81551bc2a6Smrj };
82551bc2a6Smrj 
83551bc2a6Smrj /*
84551bc2a6Smrj  * For i86xpv the "frames" in grant table terminology are really MFNs.
85551bc2a6Smrj  */
86551bc2a6Smrj typedef mfn_t gnttab_frame_t;
87551bc2a6Smrj #define	FRAME_TO_MA(f)	((maddr_t)(f) << PAGESHIFT)
88551bc2a6Smrj 
89551bc2a6Smrj int gnttab_grant_foreign_access(domid_t, gnttab_frame_t, int readonly);
90551bc2a6Smrj 
91551bc2a6Smrj /*
92551bc2a6Smrj  * End access through the given grant reference, iff the grant entry is no
93551bc2a6Smrj  * longer in use.  Return 1 if the grant entry was freed, 0 if it is still in
94551bc2a6Smrj  * use.
95551bc2a6Smrj  */
96551bc2a6Smrj int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly);
97551bc2a6Smrj 
98551bc2a6Smrj /*
99551bc2a6Smrj  * Eventually end access through the given grant reference, and once that
100551bc2a6Smrj  * access has been ended, free the given page too.  Access will be ended
101551bc2a6Smrj  * immediately iff the grant entry is not in use, otherwise it will happen
102551bc2a6Smrj  * some time later.  page may be 0, in which case no freeing will occur.
103551bc2a6Smrj  */
104551bc2a6Smrj void gnttab_end_foreign_access(grant_ref_t ref, int readonly,
105551bc2a6Smrj 	gnttab_frame_t page);
106551bc2a6Smrj 
107*a576ab5bSrab int gnttab_grant_foreign_transfer(domid_t domid, pfn_t pfn);
108551bc2a6Smrj 
109551bc2a6Smrj gnttab_frame_t gnttab_end_foreign_transfer_ref(grant_ref_t ref);
110551bc2a6Smrj gnttab_frame_t gnttab_end_foreign_transfer(grant_ref_t ref);
111551bc2a6Smrj 
112551bc2a6Smrj int gnttab_query_foreign_access(grant_ref_t ref);
113551bc2a6Smrj 
114551bc2a6Smrj /*
115551bc2a6Smrj  * operations on reserved batches of grant references
116551bc2a6Smrj  */
117551bc2a6Smrj int gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head);
118551bc2a6Smrj 
119551bc2a6Smrj void gnttab_free_grant_reference(grant_ref_t ref);
120551bc2a6Smrj 
121551bc2a6Smrj void gnttab_free_grant_references(grant_ref_t head);
122551bc2a6Smrj 
123*a576ab5bSrab int gnttab_empty_grant_references(const grant_ref_t *pprivate_head);
124*a576ab5bSrab 
125551bc2a6Smrj int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
126551bc2a6Smrj 
127551bc2a6Smrj void gnttab_release_grant_reference(grant_ref_t *private_head,
128551bc2a6Smrj 	grant_ref_t release);
129551bc2a6Smrj 
130551bc2a6Smrj void gnttab_request_free_callback(struct gnttab_free_callback *callback,
131551bc2a6Smrj 	void (*fn)(void *), void *arg, uint16_t count);
132551bc2a6Smrj 
133*a576ab5bSrab void gnttab_cancel_free_callback(struct gnttab_free_callback *callback);
134*a576ab5bSrab 
135551bc2a6Smrj void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
136551bc2a6Smrj 	gnttab_frame_t frame, int readonly);
137551bc2a6Smrj 
138*a576ab5bSrab void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid,
139*a576ab5bSrab 	pfn_t pfn);
140551bc2a6Smrj 
141551bc2a6Smrj #define	gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
142551bc2a6Smrj 
143551bc2a6Smrj /*
144551bc2a6Smrj  * framework
145551bc2a6Smrj  */
146551bc2a6Smrj void gnttab_init(void);
147551bc2a6Smrj void gnttab_suspend(void);
148551bc2a6Smrj void gnttab_resume(void);
149551bc2a6Smrj 
150551bc2a6Smrj #ifdef	__cplusplus
151551bc2a6Smrj }
152551bc2a6Smrj #endif
153551bc2a6Smrj 
154551bc2a6Smrj #endif /* _SYS_GNTTAB_H */
155