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 39255040Sgibbs#include <xen/xen-os.h> 40186557Skmacy#include <xen/hypervisor.h> 41189699Sdfr#include <xen/features.h> 42181624Skmacy 43255040Sgibbs#include <xen/interface/grant_table.h> 44255040Sgibbs 45214077Sgibbs#define GNTTAB_LIST_END GRANT_REF_INVALID 46214077Sgibbs 47181624Skmacystruct gnttab_free_callback { 48181624Skmacy struct gnttab_free_callback *next; 49181624Skmacy void (*fn)(void *); 50181624Skmacy void *arg; 51181624Skmacy uint16_t count; 52181624Skmacy}; 53181624Skmacy 54185605Skmacyint gnttab_init(void); 55185605Skmacy 56189699Sdfr/* 57189699Sdfr * Allocate a grant table reference and return it in *result. Returns 58189699Sdfr * zero on success or errno on error. 59189699Sdfr */ 60181624Skmacyint gnttab_grant_foreign_access(domid_t domid, unsigned long frame, 61186557Skmacy int flags, grant_ref_t *result); 62181624Skmacy 63181624Skmacy/* 64181624Skmacy * End access through the given grant reference, iff the grant entry is no 65181624Skmacy * longer in use. Return 1 if the grant entry was freed, 0 if it is still in 66181624Skmacy * use. 67181624Skmacy */ 68183340Skmacyint gnttab_end_foreign_access_ref(grant_ref_t ref); 69181624Skmacy 70181624Skmacy/* 71181624Skmacy * Eventually end access through the given grant reference, and once that 72181624Skmacy * access has been ended, free the given page too. Access will be ended 73181624Skmacy * immediately iff the grant entry is not in use, otherwise it will happen 74181624Skmacy * some time later. page may be 0, in which case no freeing will occur. 75181624Skmacy */ 76183375Skmacyvoid gnttab_end_foreign_access(grant_ref_t ref, void *page); 77181624Skmacy 78214077Sgibbs/* 79214077Sgibbs * Eventually end access through the given array of grant references. 80214077Sgibbs * Access will be ended immediately iff the grant entry is not in use, 81214077Sgibbs * otherwise it will happen some time later 82214077Sgibbs */ 83214077Sgibbsvoid gnttab_end_foreign_access_references(u_int count, grant_ref_t *refs); 84214077Sgibbs 85189699Sdfrint gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn, grant_ref_t *result); 86181624Skmacy 87181624Skmacyunsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref); 88181624Skmacyunsigned long gnttab_end_foreign_transfer(grant_ref_t ref); 89181624Skmacy 90181624Skmacyint gnttab_query_foreign_access(grant_ref_t ref); 91181624Skmacy 92181624Skmacy/* 93181624Skmacy * operations on reserved batches of grant references 94181624Skmacy */ 95181624Skmacyint gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head); 96181624Skmacy 97181624Skmacyvoid gnttab_free_grant_reference(grant_ref_t ref); 98181624Skmacy 99181624Skmacyvoid gnttab_free_grant_references(grant_ref_t head); 100181624Skmacy 101181624Skmacyint gnttab_empty_grant_references(const grant_ref_t *pprivate_head); 102181624Skmacy 103181624Skmacyint gnttab_claim_grant_reference(grant_ref_t *pprivate_head); 104181624Skmacy 105181624Skmacyvoid gnttab_release_grant_reference(grant_ref_t *private_head, 106181624Skmacy grant_ref_t release); 107181624Skmacy 108181624Skmacyvoid gnttab_request_free_callback(struct gnttab_free_callback *callback, 109181624Skmacy void (*fn)(void *), void *arg, uint16_t count); 110181624Skmacyvoid gnttab_cancel_free_callback(struct gnttab_free_callback *callback); 111181624Skmacy 112181624Skmacyvoid gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 113183340Skmacy unsigned long frame, int flags); 114181624Skmacy 115181624Skmacyvoid gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, 116181624Skmacy unsigned long pfn); 117181624Skmacy 118181624Skmacyint gnttab_suspend(void); 119181624Skmacyint gnttab_resume(void); 120181624Skmacy 121189699Sdfr#if 0 122189699Sdfr 123189699Sdfr#include <xen/features.h> 124189699Sdfr 125181624Skmacystatic inline void 126181624Skmacygnttab_set_map_op(struct gnttab_map_grant_ref *map, vm_paddr_t addr, 127181624Skmacy uint32_t flags, grant_ref_t ref, domid_t domid) 128181624Skmacy{ 129181624Skmacy if (flags & GNTMAP_contains_pte) 130181624Skmacy map->host_addr = addr; 131181624Skmacy else if (xen_feature(XENFEAT_auto_translated_physmap)) 132181624Skmacy map->host_addr = vtophys(addr); 133181624Skmacy else 134181624Skmacy map->host_addr = addr; 135181624Skmacy 136181624Skmacy map->flags = flags; 137181624Skmacy map->ref = ref; 138181624Skmacy map->dom = domid; 139181624Skmacy} 140181624Skmacy 141181624Skmacystatic inline void 142181624Skmacygnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, vm_paddr_t addr, 143181624Skmacy uint32_t flags, grant_handle_t handle) 144181624Skmacy{ 145181624Skmacy if (flags & GNTMAP_contains_pte) 146181624Skmacy unmap->host_addr = addr; 147181624Skmacy else if (xen_feature(XENFEAT_auto_translated_physmap)) 148181624Skmacy unmap->host_addr = vtophys(addr); 149181624Skmacy else 150181624Skmacy unmap->host_addr = addr; 151181624Skmacy 152181624Skmacy unmap->handle = handle; 153181624Skmacy unmap->dev_bus_addr = 0; 154181624Skmacy} 155181624Skmacy 156183340Skmacystatic inline void 157183375Skmacygnttab_set_replace_op(struct gnttab_unmap_and_replace *unmap, vm_paddr_t addr, 158183375Skmacy vm_paddr_t new_addr, grant_handle_t handle) 159183340Skmacy{ 160183340Skmacy if (xen_feature(XENFEAT_auto_translated_physmap)) { 161183375Skmacy unmap->host_addr = vtophys(addr); 162183375Skmacy unmap->new_addr = vtophys(new_addr); 163183340Skmacy } else { 164183340Skmacy unmap->host_addr = addr; 165183340Skmacy unmap->new_addr = new_addr; 166183340Skmacy } 167183340Skmacy 168183340Skmacy unmap->handle = handle; 169183340Skmacy} 170189699Sdfr#endif 171183340Skmacy 172181624Skmacy#endif /* __ASM_GNTTAB_H__ */ 173