gnttab.h revision 183375
1181624Skmacy/****************************************************************************** 2181624Skmacy * gnttab.h 3181624Skmacy * 4181624Skmacy * Two sets of functionality: 5181624Skmacy * 1. Granting foreign access to our memory reservation. 6181624Skmacy * 2. Accessing others' memory reservations via grant references. 7181624Skmacy * (i.e., mechanisms for both sender and recipient of grant references) 8181624Skmacy * 9181624Skmacy * Copyright (c) 2004-2005, K A Fraser 10181624Skmacy * Copyright (c) 2005, Christopher Clark 11181624Skmacy * 12181624Skmacy * This program is free software; you can redistribute it and/or 13181624Skmacy * modify it under the terms of the GNU General Public License version 2 14181624Skmacy * as published by the Free Software Foundation; or, when distributed 15181624Skmacy * separately from the Linux kernel or incorporated into other 16181624Skmacy * software packages, subject to the following license: 17181624Skmacy * 18181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy 19181624Skmacy * of this source file (the "Software"), to deal in the Software without 20181624Skmacy * restriction, including without limitation the rights to use, copy, modify, 21181624Skmacy * merge, publish, distribute, sublicense, and/or sell copies of the Software, 22181624Skmacy * and to permit persons to whom the Software is furnished to do so, subject to 23181624Skmacy * the following conditions: 24181624Skmacy * 25181624Skmacy * The above copyright notice and this permission notice shall be included in 26181624Skmacy * all copies or substantial portions of the Software. 27181624Skmacy * 28181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 34181624Skmacy * IN THE SOFTWARE. 35181624Skmacy */ 36181624Skmacy 37181624Skmacy#ifndef __ASM_GNTTAB_H__ 38181624Skmacy 39181624Skmacy#include <machine/xen/hypervisor.h> 40181624Skmacy#include <xen/interface/grant_table.h> 41181624Skmacy#include <machine/xen/xen-os.h> 42181624Skmacy#include <machine/xen/hypervisor.h> 43181624Skmacy#include <machine/xen/features.h> 44181624Skmacy 45181624Skmacystruct gnttab_free_callback { 46181624Skmacy struct gnttab_free_callback *next; 47181624Skmacy void (*fn)(void *); 48181624Skmacy void *arg; 49181624Skmacy uint16_t count; 50181624Skmacy}; 51181624Skmacy 52181624Skmacyint gnttab_grant_foreign_access(domid_t domid, unsigned long frame, 53183340Skmacy int flags); 54181624Skmacy 55181624Skmacy/* 56181624Skmacy * End access through the given grant reference, iff the grant entry is no 57181624Skmacy * longer in use. Return 1 if the grant entry was freed, 0 if it is still in 58181624Skmacy * use. 59181624Skmacy */ 60183340Skmacyint gnttab_end_foreign_access_ref(grant_ref_t ref); 61181624Skmacy 62181624Skmacy/* 63181624Skmacy * Eventually end access through the given grant reference, and once that 64181624Skmacy * access has been ended, free the given page too. Access will be ended 65181624Skmacy * immediately iff the grant entry is not in use, otherwise it will happen 66181624Skmacy * some time later. page may be 0, in which case no freeing will occur. 67181624Skmacy */ 68183375Skmacyvoid gnttab_end_foreign_access(grant_ref_t ref, void *page); 69181624Skmacy 70181624Skmacyint gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn); 71181624Skmacy 72181624Skmacyunsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref); 73181624Skmacyunsigned long gnttab_end_foreign_transfer(grant_ref_t ref); 74181624Skmacy 75181624Skmacyint gnttab_query_foreign_access(grant_ref_t ref); 76181624Skmacy 77181624Skmacy/* 78181624Skmacy * operations on reserved batches of grant references 79181624Skmacy */ 80181624Skmacyint gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head); 81181624Skmacy 82181624Skmacyvoid gnttab_free_grant_reference(grant_ref_t ref); 83181624Skmacy 84181624Skmacyvoid gnttab_free_grant_references(grant_ref_t head); 85181624Skmacy 86181624Skmacyint gnttab_empty_grant_references(const grant_ref_t *pprivate_head); 87181624Skmacy 88181624Skmacyint gnttab_claim_grant_reference(grant_ref_t *pprivate_head); 89181624Skmacy 90181624Skmacyvoid gnttab_release_grant_reference(grant_ref_t *private_head, 91181624Skmacy grant_ref_t release); 92181624Skmacy 93181624Skmacyvoid gnttab_request_free_callback(struct gnttab_free_callback *callback, 94181624Skmacy void (*fn)(void *), void *arg, uint16_t count); 95181624Skmacyvoid gnttab_cancel_free_callback(struct gnttab_free_callback *callback); 96181624Skmacy 97181624Skmacyvoid gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 98183340Skmacy unsigned long frame, int flags); 99181624Skmacy 100181624Skmacyvoid gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, 101181624Skmacy unsigned long pfn); 102181624Skmacy 103181624Skmacyint gnttab_suspend(void); 104181624Skmacyint gnttab_resume(void); 105181624Skmacy 106181624Skmacystatic inline void 107181624Skmacygnttab_set_map_op(struct gnttab_map_grant_ref *map, vm_paddr_t addr, 108181624Skmacy uint32_t flags, grant_ref_t ref, domid_t domid) 109181624Skmacy{ 110181624Skmacy if (flags & GNTMAP_contains_pte) 111181624Skmacy map->host_addr = addr; 112181624Skmacy else if (xen_feature(XENFEAT_auto_translated_physmap)) 113181624Skmacy map->host_addr = vtophys(addr); 114181624Skmacy else 115181624Skmacy map->host_addr = addr; 116181624Skmacy 117181624Skmacy map->flags = flags; 118181624Skmacy map->ref = ref; 119181624Skmacy map->dom = domid; 120181624Skmacy} 121181624Skmacy 122181624Skmacystatic inline void 123181624Skmacygnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, vm_paddr_t addr, 124181624Skmacy uint32_t flags, grant_handle_t handle) 125181624Skmacy{ 126181624Skmacy if (flags & GNTMAP_contains_pte) 127181624Skmacy unmap->host_addr = addr; 128181624Skmacy else if (xen_feature(XENFEAT_auto_translated_physmap)) 129181624Skmacy unmap->host_addr = vtophys(addr); 130181624Skmacy else 131181624Skmacy unmap->host_addr = addr; 132181624Skmacy 133181624Skmacy unmap->handle = handle; 134181624Skmacy unmap->dev_bus_addr = 0; 135181624Skmacy} 136181624Skmacy 137183340Skmacystatic inline void 138183375Skmacygnttab_set_replace_op(struct gnttab_unmap_and_replace *unmap, vm_paddr_t addr, 139183375Skmacy vm_paddr_t new_addr, grant_handle_t handle) 140183340Skmacy{ 141183340Skmacy if (xen_feature(XENFEAT_auto_translated_physmap)) { 142183375Skmacy unmap->host_addr = vtophys(addr); 143183375Skmacy unmap->new_addr = vtophys(new_addr); 144183340Skmacy } else { 145183340Skmacy unmap->host_addr = addr; 146183340Skmacy unmap->new_addr = new_addr; 147183340Skmacy } 148183340Skmacy 149183340Skmacy unmap->handle = handle; 150183340Skmacy} 151183340Skmacy 152181624Skmacy#endif /* __ASM_GNTTAB_H__ */ 153