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