130d1eefeSKip Macy /****************************************************************************** 2*40e1d9d4SElliott Mitchell * SPDX-License-Identifier: MIT OR GPL-2.0-only 3*40e1d9d4SElliott Mitchell * 430d1eefeSKip Macy * gnttab.h 530d1eefeSKip Macy * 630d1eefeSKip Macy * Two sets of functionality: 730d1eefeSKip Macy * 1. Granting foreign access to our memory reservation. 830d1eefeSKip Macy * 2. Accessing others' memory reservations via grant references. 930d1eefeSKip Macy * (i.e., mechanisms for both sender and recipient of grant references) 1030d1eefeSKip Macy * 1130d1eefeSKip Macy * Copyright (c) 2004-2005, K A Fraser 1230d1eefeSKip Macy * Copyright (c) 2005, Christopher Clark 1330d1eefeSKip Macy * 1430d1eefeSKip Macy * This program is free software; you can redistribute it and/or 1530d1eefeSKip Macy * modify it under the terms of the GNU General Public License version 2 1630d1eefeSKip Macy * as published by the Free Software Foundation; or, when distributed 1730d1eefeSKip Macy * separately from the Linux kernel or incorporated into other 1830d1eefeSKip Macy * software packages, subject to the following license: 1930d1eefeSKip Macy * 2030d1eefeSKip Macy * Permission is hereby granted, free of charge, to any person obtaining a copy 2130d1eefeSKip Macy * of this source file (the "Software"), to deal in the Software without 2230d1eefeSKip Macy * restriction, including without limitation the rights to use, copy, modify, 2330d1eefeSKip Macy * merge, publish, distribute, sublicense, and/or sell copies of the Software, 2430d1eefeSKip Macy * and to permit persons to whom the Software is furnished to do so, subject to 2530d1eefeSKip Macy * the following conditions: 2630d1eefeSKip Macy * 2730d1eefeSKip Macy * The above copyright notice and this permission notice shall be included in 2830d1eefeSKip Macy * all copies or substantial portions of the Software. 2930d1eefeSKip Macy * 3030d1eefeSKip Macy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 3130d1eefeSKip Macy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 3230d1eefeSKip Macy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 3330d1eefeSKip Macy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 3430d1eefeSKip Macy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 3530d1eefeSKip Macy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 3630d1eefeSKip Macy * IN THE SOFTWARE. 3730d1eefeSKip Macy */ 3830d1eefeSKip Macy 3930d1eefeSKip Macy #ifndef __ASM_GNTTAB_H__ 4071da5f7aSRoger Pau Monné #define __ASM_GNTTAB_H__ 4130d1eefeSKip Macy 4276acc41fSJustin T. Gibbs #include <xen/xen-os.h> 433a6d1fcfSKip Macy #include <xen/hypervisor.h> 4412678024SDoug Rabson #include <xen/features.h> 4530d1eefeSKip Macy 46ad7dd514SElliott Mitchell #include <contrib/xen/grant_table.h> 4776acc41fSJustin T. Gibbs 48ff662b5cSJustin T. Gibbs #define GNTTAB_LIST_END GRANT_REF_INVALID 49ff662b5cSJustin T. Gibbs 5030d1eefeSKip Macy struct gnttab_free_callback { 5130d1eefeSKip Macy struct gnttab_free_callback *next; 5230d1eefeSKip Macy void (*fn)(void *); 5330d1eefeSKip Macy void *arg; 5430d1eefeSKip Macy uint16_t count; 5530d1eefeSKip Macy }; 5630d1eefeSKip Macy 5712678024SDoug Rabson /* 5812678024SDoug Rabson * Allocate a grant table reference and return it in *result. Returns 5912678024SDoug Rabson * zero on success or errno on error. 6012678024SDoug Rabson */ 6130d1eefeSKip Macy int gnttab_grant_foreign_access(domid_t domid, unsigned long frame, 623a6d1fcfSKip Macy int flags, grant_ref_t *result); 6330d1eefeSKip Macy 6430d1eefeSKip Macy /* 6530d1eefeSKip Macy * End access through the given grant reference, iff the grant entry is no 6630d1eefeSKip Macy * longer in use. Return 1 if the grant entry was freed, 0 if it is still in 6730d1eefeSKip Macy * use. 6830d1eefeSKip Macy */ 69a972cc52SKip Macy int gnttab_end_foreign_access_ref(grant_ref_t ref); 7030d1eefeSKip Macy 7130d1eefeSKip Macy /* 7230d1eefeSKip Macy * Eventually end access through the given grant reference, and once that 7330d1eefeSKip Macy * access has been ended, free the given page too. Access will be ended 7430d1eefeSKip Macy * immediately iff the grant entry is not in use, otherwise it will happen 7530d1eefeSKip Macy * some time later. page may be 0, in which case no freeing will occur. 7630d1eefeSKip Macy */ 77920ba15bSKip Macy void gnttab_end_foreign_access(grant_ref_t ref, void *page); 7830d1eefeSKip Macy 79ff662b5cSJustin T. Gibbs /* 80ff662b5cSJustin T. Gibbs * Eventually end access through the given array of grant references. 81ff662b5cSJustin T. Gibbs * Access will be ended immediately iff the grant entry is not in use, 82ff662b5cSJustin T. Gibbs * otherwise it will happen some time later 83ff662b5cSJustin T. Gibbs */ 84ff662b5cSJustin T. Gibbs void gnttab_end_foreign_access_references(u_int count, grant_ref_t *refs); 85ff662b5cSJustin T. Gibbs 8612678024SDoug Rabson int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn, grant_ref_t *result); 8730d1eefeSKip Macy 8830d1eefeSKip Macy unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref); 8930d1eefeSKip Macy unsigned long gnttab_end_foreign_transfer(grant_ref_t ref); 9030d1eefeSKip Macy 9130d1eefeSKip Macy int gnttab_query_foreign_access(grant_ref_t ref); 9230d1eefeSKip Macy 9330d1eefeSKip Macy /* 9430d1eefeSKip Macy * operations on reserved batches of grant references 9530d1eefeSKip Macy */ 9630d1eefeSKip Macy int gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head); 9730d1eefeSKip Macy 9830d1eefeSKip Macy void gnttab_free_grant_reference(grant_ref_t ref); 9930d1eefeSKip Macy 10030d1eefeSKip Macy void gnttab_free_grant_references(grant_ref_t head); 10130d1eefeSKip Macy 10230d1eefeSKip Macy int gnttab_empty_grant_references(const grant_ref_t *pprivate_head); 10330d1eefeSKip Macy 10430d1eefeSKip Macy int gnttab_claim_grant_reference(grant_ref_t *pprivate_head); 10530d1eefeSKip Macy 10630d1eefeSKip Macy void gnttab_release_grant_reference(grant_ref_t *private_head, 10730d1eefeSKip Macy grant_ref_t release); 10830d1eefeSKip Macy 10930d1eefeSKip Macy void gnttab_request_free_callback(struct gnttab_free_callback *callback, 11030d1eefeSKip Macy void (*fn)(void *), void *arg, uint16_t count); 11130d1eefeSKip Macy void gnttab_cancel_free_callback(struct gnttab_free_callback *callback); 11230d1eefeSKip Macy 11330d1eefeSKip Macy void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 114a972cc52SKip Macy unsigned long frame, int flags); 11530d1eefeSKip Macy 11630d1eefeSKip Macy void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, 11730d1eefeSKip Macy unsigned long pfn); 11830d1eefeSKip Macy 11930d1eefeSKip Macy int gnttab_suspend(void); 120a8f2f559SRoger Pau Monné int gnttab_resume(device_t); 12130d1eefeSKip Macy 12230d1eefeSKip Macy #endif /* __ASM_GNTTAB_H__ */ 123