15741Smrj /* 25741Smrj * CDDL HEADER START 35741Smrj * 45741Smrj * The contents of this file are subject to the terms of the 55741Smrj * Common Development and Distribution License (the "License"). 65741Smrj * You may not use this file except in compliance with the License. 75741Smrj * 85741Smrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95741Smrj * or http://www.opensolaris.org/os/licensing. 105741Smrj * See the License for the specific language governing permissions 115741Smrj * and limitations under the License. 125741Smrj * 135741Smrj * When distributing Covered Code, include this CDDL HEADER in each 145741Smrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155741Smrj * If applicable, add the following below this CDDL HEADER, with the 165741Smrj * fields enclosed by brackets "[]" replaced with your own identifying 175741Smrj * information: Portions Copyright [yyyy] [name of copyright owner] 185741Smrj * 195741Smrj * CDDL HEADER END 205741Smrj */ 215741Smrj 225741Smrj /* 23*6144Srab * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 245741Smrj * Use is subject to license terms. 255741Smrj */ 265741Smrj 275741Smrj #ifndef _SYS_GNTTAB_H 285741Smrj #define _SYS_GNTTAB_H 295741Smrj 305741Smrj #pragma ident "%Z%%M% %I% %E% SMI" 315741Smrj 325741Smrj /* 335741Smrj * gnttab.h 345741Smrj * 355741Smrj * Two sets of functionality: 365741Smrj * 1. Granting foreign access to our memory reservation. 375741Smrj * 2. Accessing others' memory reservations via grant references. 385741Smrj * (i.e., mechanisms for both sender and recipient of grant references) 395741Smrj * 405741Smrj * Copyright (c) 2004-2005, K A Fraser 415741Smrj * Copyright (c) 2005, Christopher Clark 425741Smrj * 43*6144Srab * This program is free software; you can redistribute it and/or 44*6144Srab * modify it under the terms of the GNU General Public License version 2 45*6144Srab * as published by the Free Software Foundation; or, when distributed 46*6144Srab * separately from the Linux kernel or incorporated into other 47*6144Srab * software packages, subject to the following license: 485741Smrj * 495741Smrj * Permission is hereby granted, free of charge, to any person obtaining a copy 505741Smrj * of this source file (the "Software"), to deal in the Software without 515741Smrj * restriction, including without limitation the rights to use, copy, modify, 525741Smrj * merge, publish, distribute, sublicense, and/or sell copies of the Software, 535741Smrj * and to permit persons to whom the Software is furnished to do so, subject to 545741Smrj * the following conditions: 555741Smrj * 565741Smrj * The above copyright notice and this permission notice shall be included in 575741Smrj * all copies or substantial portions of the Software. 585741Smrj * 595741Smrj * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 605741Smrj * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 615741Smrj * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 625741Smrj * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 635741Smrj * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 645741Smrj * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 655741Smrj * IN THE SOFTWARE. 665741Smrj */ 675741Smrj 685741Smrj #include <sys/hypervisor.h> 695741Smrj #include <xen/public/grant_table.h> 70*6144Srab #include <xen/public/features.h> 715741Smrj 725741Smrj #ifdef __cplusplus 735741Smrj extern "C" { 745741Smrj #endif 755741Smrj 765741Smrj struct gnttab_free_callback { 775741Smrj struct gnttab_free_callback *next; 785741Smrj void (*fn)(void *); 795741Smrj void *arg; 805741Smrj uint16_t count; 815741Smrj }; 825741Smrj 835741Smrj /* 845741Smrj * For i86xpv the "frames" in grant table terminology are really MFNs. 855741Smrj */ 865741Smrj typedef mfn_t gnttab_frame_t; 875741Smrj #define FRAME_TO_MA(f) ((maddr_t)(f) << PAGESHIFT) 885741Smrj 895741Smrj int gnttab_grant_foreign_access(domid_t, gnttab_frame_t, int readonly); 905741Smrj 915741Smrj /* 925741Smrj * End access through the given grant reference, iff the grant entry is no 935741Smrj * longer in use. Return 1 if the grant entry was freed, 0 if it is still in 945741Smrj * use. 955741Smrj */ 965741Smrj int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly); 975741Smrj 985741Smrj /* 995741Smrj * Eventually end access through the given grant reference, and once that 1005741Smrj * access has been ended, free the given page too. Access will be ended 1015741Smrj * immediately iff the grant entry is not in use, otherwise it will happen 1025741Smrj * some time later. page may be 0, in which case no freeing will occur. 1035741Smrj */ 1045741Smrj void gnttab_end_foreign_access(grant_ref_t ref, int readonly, 1055741Smrj gnttab_frame_t page); 1065741Smrj 107*6144Srab int gnttab_grant_foreign_transfer(domid_t domid, pfn_t pfn); 1085741Smrj 1095741Smrj gnttab_frame_t gnttab_end_foreign_transfer_ref(grant_ref_t ref); 1105741Smrj gnttab_frame_t gnttab_end_foreign_transfer(grant_ref_t ref); 1115741Smrj 1125741Smrj int gnttab_query_foreign_access(grant_ref_t ref); 1135741Smrj 1145741Smrj /* 1155741Smrj * operations on reserved batches of grant references 1165741Smrj */ 1175741Smrj int gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head); 1185741Smrj 1195741Smrj void gnttab_free_grant_reference(grant_ref_t ref); 1205741Smrj 1215741Smrj void gnttab_free_grant_references(grant_ref_t head); 1225741Smrj 123*6144Srab int gnttab_empty_grant_references(const grant_ref_t *pprivate_head); 124*6144Srab 1255741Smrj int gnttab_claim_grant_reference(grant_ref_t *pprivate_head); 1265741Smrj 1275741Smrj void gnttab_release_grant_reference(grant_ref_t *private_head, 1285741Smrj grant_ref_t release); 1295741Smrj 1305741Smrj void gnttab_request_free_callback(struct gnttab_free_callback *callback, 1315741Smrj void (*fn)(void *), void *arg, uint16_t count); 1325741Smrj 133*6144Srab void gnttab_cancel_free_callback(struct gnttab_free_callback *callback); 134*6144Srab 1355741Smrj void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 1365741Smrj gnttab_frame_t frame, int readonly); 1375741Smrj 138*6144Srab void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, 139*6144Srab pfn_t pfn); 1405741Smrj 1415741Smrj #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr)) 1425741Smrj 1435741Smrj /* 1445741Smrj * framework 1455741Smrj */ 1465741Smrj void gnttab_init(void); 1475741Smrj void gnttab_suspend(void); 1485741Smrj void gnttab_resume(void); 1495741Smrj 1505741Smrj #ifdef __cplusplus 1515741Smrj } 1525741Smrj #endif 1535741Smrj 1545741Smrj #endif /* _SYS_GNTTAB_H */ 155