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__ 38301194Sroyger#define __ASM_GNTTAB_H__ 39181624Skmacy 40255040Sgibbs#include <xen/xen-os.h> 41186557Skmacy#include <xen/hypervisor.h> 42189699Sdfr#include <xen/features.h> 43181624Skmacy 44255040Sgibbs#include <xen/interface/grant_table.h> 45255040Sgibbs 46214077Sgibbs#define GNTTAB_LIST_END GRANT_REF_INVALID 47214077Sgibbs 48181624Skmacystruct gnttab_free_callback { 49181624Skmacy struct gnttab_free_callback *next; 50181624Skmacy void (*fn)(void *); 51181624Skmacy void *arg; 52181624Skmacy uint16_t count; 53181624Skmacy}; 54181624Skmacy 55189699Sdfr/* 56189699Sdfr * Allocate a grant table reference and return it in *result. Returns 57189699Sdfr * zero on success or errno on error. 58189699Sdfr */ 59181624Skmacyint gnttab_grant_foreign_access(domid_t domid, unsigned long frame, 60186557Skmacy int flags, grant_ref_t *result); 61181624Skmacy 62181624Skmacy/* 63181624Skmacy * End access through the given grant reference, iff the grant entry is no 64181624Skmacy * longer in use. Return 1 if the grant entry was freed, 0 if it is still in 65181624Skmacy * use. 66181624Skmacy */ 67183340Skmacyint gnttab_end_foreign_access_ref(grant_ref_t ref); 68181624Skmacy 69181624Skmacy/* 70181624Skmacy * Eventually end access through the given grant reference, and once that 71181624Skmacy * access has been ended, free the given page too. Access will be ended 72181624Skmacy * immediately iff the grant entry is not in use, otherwise it will happen 73181624Skmacy * some time later. page may be 0, in which case no freeing will occur. 74181624Skmacy */ 75183375Skmacyvoid gnttab_end_foreign_access(grant_ref_t ref, void *page); 76181624Skmacy 77214077Sgibbs/* 78214077Sgibbs * Eventually end access through the given array of grant references. 79214077Sgibbs * Access will be ended immediately iff the grant entry is not in use, 80214077Sgibbs * otherwise it will happen some time later 81214077Sgibbs */ 82214077Sgibbsvoid gnttab_end_foreign_access_references(u_int count, grant_ref_t *refs); 83214077Sgibbs 84189699Sdfrint gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn, grant_ref_t *result); 85181624Skmacy 86181624Skmacyunsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref); 87181624Skmacyunsigned long gnttab_end_foreign_transfer(grant_ref_t ref); 88181624Skmacy 89181624Skmacyint gnttab_query_foreign_access(grant_ref_t ref); 90181624Skmacy 91181624Skmacy/* 92181624Skmacy * operations on reserved batches of grant references 93181624Skmacy */ 94181624Skmacyint gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head); 95181624Skmacy 96181624Skmacyvoid gnttab_free_grant_reference(grant_ref_t ref); 97181624Skmacy 98181624Skmacyvoid gnttab_free_grant_references(grant_ref_t head); 99181624Skmacy 100181624Skmacyint gnttab_empty_grant_references(const grant_ref_t *pprivate_head); 101181624Skmacy 102181624Skmacyint gnttab_claim_grant_reference(grant_ref_t *pprivate_head); 103181624Skmacy 104181624Skmacyvoid gnttab_release_grant_reference(grant_ref_t *private_head, 105181624Skmacy grant_ref_t release); 106181624Skmacy 107181624Skmacyvoid gnttab_request_free_callback(struct gnttab_free_callback *callback, 108181624Skmacy void (*fn)(void *), void *arg, uint16_t count); 109181624Skmacyvoid gnttab_cancel_free_callback(struct gnttab_free_callback *callback); 110181624Skmacy 111181624Skmacyvoid gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 112183340Skmacy unsigned long frame, int flags); 113181624Skmacy 114181624Skmacyvoid gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, 115181624Skmacy unsigned long pfn); 116181624Skmacy 117181624Skmacyint gnttab_suspend(void); 118267534Sroygerint gnttab_resume(device_t); 119181624Skmacy 120189699Sdfr#if 0 121189699Sdfr 122189699Sdfr#include <xen/features.h> 123189699Sdfr 124181624Skmacystatic inline void 125181624Skmacygnttab_set_map_op(struct gnttab_map_grant_ref *map, vm_paddr_t addr, 126181624Skmacy uint32_t flags, grant_ref_t ref, domid_t domid) 127181624Skmacy{ 128181624Skmacy if (flags & GNTMAP_contains_pte) 129181624Skmacy map->host_addr = addr; 130286786Sjhb else 131181624Skmacy map->host_addr = vtophys(addr); 132181624Skmacy 133181624Skmacy map->flags = flags; 134181624Skmacy map->ref = ref; 135181624Skmacy map->dom = domid; 136181624Skmacy} 137181624Skmacy 138181624Skmacystatic inline void 139181624Skmacygnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, vm_paddr_t addr, 140181624Skmacy uint32_t flags, grant_handle_t handle) 141181624Skmacy{ 142181624Skmacy if (flags & GNTMAP_contains_pte) 143181624Skmacy unmap->host_addr = addr; 144286786Sjhb else 145181624Skmacy unmap->host_addr = vtophys(addr); 146181624Skmacy 147181624Skmacy unmap->handle = handle; 148181624Skmacy unmap->dev_bus_addr = 0; 149181624Skmacy} 150181624Skmacy 151183340Skmacystatic inline void 152183375Skmacygnttab_set_replace_op(struct gnttab_unmap_and_replace *unmap, vm_paddr_t addr, 153183375Skmacy vm_paddr_t new_addr, grant_handle_t handle) 154183340Skmacy{ 155286786Sjhb unmap->host_addr = vtophys(addr); 156286786Sjhb unmap->new_addr = vtophys(new_addr); 157183340Skmacy 158183340Skmacy unmap->handle = handle; 159183340Skmacy} 160189699Sdfr#endif 161183340Skmacy 162181624Skmacy#endif /* __ASM_GNTTAB_H__ */ 163