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 2008 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 /* 31 * gnttab.h 32 * 33 * Two sets of functionality: 34 * 1. Granting foreign access to our memory reservation. 35 * 2. Accessing others' memory reservations via grant references. 36 * (i.e., mechanisms for both sender and recipient of grant references) 37 * 38 * Copyright (c) 2004-2005, K A Fraser 39 * Copyright (c) 2005, Christopher Clark 40 * 41 * This program is free software; you can redistribute it and/or 42 * modify it under the terms of the GNU General Public License version 2 43 * as published by the Free Software Foundation; or, when distributed 44 * separately from the Linux kernel or incorporated into other 45 * software packages, subject to the following license: 46 * 47 * Permission is hereby granted, free of charge, to any person obtaining a copy 48 * of this source file (the "Software"), to deal in the Software without 49 * restriction, including without limitation the rights to use, copy, modify, 50 * merge, publish, distribute, sublicense, and/or sell copies of the Software, 51 * and to permit persons to whom the Software is furnished to do so, subject to 52 * the following conditions: 53 * 54 * The above copyright notice and this permission notice shall be included in 55 * all copies or substantial portions of the Software. 56 * 57 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 58 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 59 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 60 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 61 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 62 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 63 * IN THE SOFTWARE. 64 */ 65 66 #include <sys/hypervisor.h> 67 #include <xen/public/grant_table.h> 68 #include <xen/public/features.h> 69 70 #ifdef __cplusplus 71 extern "C" { 72 #endif 73 74 struct gnttab_free_callback { 75 struct gnttab_free_callback *next; 76 void (*fn)(void *); 77 void *arg; 78 uint16_t count; 79 }; 80 81 /* 82 * For i86xpv the "frames" in grant table terminology are really MFNs. 83 */ 84 typedef mfn_t gnttab_frame_t; 85 #define FRAME_TO_MA(f) ((maddr_t)(f) << PAGESHIFT) 86 87 int gnttab_grant_foreign_access(domid_t, gnttab_frame_t, int readonly); 88 89 /* 90 * End access through the given grant reference, iff the grant entry is no 91 * longer in use. Return 1 if the grant entry was freed, 0 if it is still in 92 * use. 93 */ 94 int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly); 95 96 /* 97 * Eventually end access through the given grant reference, and once that 98 * access has been ended, free the given page too. Access will be ended 99 * immediately iff the grant entry is not in use, otherwise it will happen 100 * some time later. page may be 0, in which case no freeing will occur. 101 */ 102 void gnttab_end_foreign_access(grant_ref_t ref, int readonly, 103 gnttab_frame_t page); 104 105 int gnttab_grant_foreign_transfer(domid_t domid, pfn_t pfn); 106 107 gnttab_frame_t gnttab_end_foreign_transfer_ref(grant_ref_t ref); 108 gnttab_frame_t gnttab_end_foreign_transfer(grant_ref_t ref); 109 110 int gnttab_query_foreign_access(grant_ref_t ref); 111 112 /* 113 * operations on reserved batches of grant references 114 */ 115 int gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head); 116 117 void gnttab_free_grant_reference(grant_ref_t ref); 118 119 void gnttab_free_grant_references(grant_ref_t head); 120 121 int gnttab_empty_grant_references(const grant_ref_t *pprivate_head); 122 123 int gnttab_claim_grant_reference(grant_ref_t *pprivate_head); 124 125 void gnttab_release_grant_reference(grant_ref_t *private_head, 126 grant_ref_t release); 127 128 void gnttab_request_free_callback(struct gnttab_free_callback *callback, 129 void (*fn)(void *), void *arg, uint16_t count); 130 131 void gnttab_cancel_free_callback(struct gnttab_free_callback *callback); 132 133 void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 134 gnttab_frame_t frame, int readonly); 135 136 void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, 137 pfn_t pfn); 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