gnttab.h revision 183375
143725Syokota/******************************************************************************
243725Syokota * gnttab.h
343725Syokota *
443725Syokota * Two sets of functionality:
543725Syokota * 1. Granting foreign access to our memory reservation.
643725Syokota * 2. Accessing others' memory reservations via grant references.
743725Syokota * (i.e., mechanisms for both sender and recipient of grant references)
843725Syokota *
943725Syokota * Copyright (c) 2004-2005, K A Fraser
1043725Syokota * Copyright (c) 2005, Christopher Clark
1143725Syokota *
1243725Syokota * This program is free software; you can redistribute it and/or
1343725Syokota * modify it under the terms of the GNU General Public License version 2
1443725Syokota * as published by the Free Software Foundation; or, when distributed
1543725Syokota * separately from the Linux kernel or incorporated into other
1643725Syokota * software packages, subject to the following license:
1743725Syokota *
1843725Syokota * Permission is hereby granted, free of charge, to any person obtaining a copy
1943725Syokota * of this source file (the "Software"), to deal in the Software without
2043725Syokota * restriction, including without limitation the rights to use, copy, modify,
2143725Syokota * merge, publish, distribute, sublicense, and/or sell copies of the Software,
2243725Syokota * and to permit persons to whom the Software is furnished to do so, subject to
2343725Syokota * the following conditions:
2443725Syokota *
2543725Syokota * The above copyright notice and this permission notice shall be included in
2643725Syokota * all copies or substantial portions of the Software.
2750476Speter *
2843725Syokota * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29293034Sdes * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3053200Sphantom * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3165013Ssheldonh * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3243725Syokota * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3343725Syokota * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
3465013Ssheldonh * IN THE SOFTWARE.
3543725Syokota */
3676175Sschweikh
3743725Syokota#ifndef __ASM_GNTTAB_H__
3843725Syokota
3943725Syokota#include <machine/xen/hypervisor.h>
4076175Sschweikh#include <xen/interface/grant_table.h>
4143725Syokota#include <machine/xen/xen-os.h>
4243725Syokota#include <machine/xen/hypervisor.h>
4343725Syokota#include <machine/xen/features.h>
4465013Ssheldonh
4562978Sdannyboystruct gnttab_free_callback {
4665009Ssheldonh	struct gnttab_free_callback *next;
4765009Ssheldonh	void (*fn)(void *);
4865009Ssheldonh	void *arg;
4965013Ssheldonh	uint16_t count;
5076175Sschweikh};
5165009Ssheldonh
5265009Ssheldonhint gnttab_grant_foreign_access(domid_t domid, unsigned long frame,
5365009Ssheldonh				int flags);
5443725Syokota
5576175Sschweikh/*
5643725Syokota * End access through the given grant reference, iff the grant entry is no
5743725Syokota * longer in use.  Return 1 if the grant entry was freed, 0 if it is still in
5843725Syokota * use.
5962978Sdannyboy */
6057676Ssheldonhint gnttab_end_foreign_access_ref(grant_ref_t ref);
6143844Syokota
6243725Syokota/*
6343844Syokota * Eventually end access through the given grant reference, and once that
6443844Syokota * access has been ended, free the given page too.  Access will be ended
6555268Shoek * immediately iff the grant entry is not in use, otherwise it will happen
6643725Syokota * some time later.  page may be 0, in which case no freeing will occur.
6743844Syokota */
6843844Syokotavoid gnttab_end_foreign_access(grant_ref_t ref, void *page);
69274749Semaste
7043844Syokotaint gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn);
7165009Ssheldonh
7265009Ssheldonhunsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref);
7345628Sdesunsigned long gnttab_end_foreign_transfer(grant_ref_t ref);
7445628Sdes
7545628Sdesint gnttab_query_foreign_access(grant_ref_t ref);
7645628Sdes
77228445Seadler/*
78228445Seadler * operations on reserved batches of grant references
79228445Seadler */
80228445Seadlerint gnttab_alloc_grant_references(uint16_t count, grant_ref_t *pprivate_head);
81228445Seadler
82228445Seadlervoid gnttab_free_grant_reference(grant_ref_t ref);
83228445Seadler
84228445Seadlervoid gnttab_free_grant_references(grant_ref_t head);
8543725Syokota
8643725Syokotaint gnttab_empty_grant_references(const grant_ref_t *pprivate_head);
8743725Syokota
8843725Syokotaint gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
8943725Syokota
9043725Syokotavoid gnttab_release_grant_reference(grant_ref_t *private_head,
9143844Syokota				    grant_ref_t release);
9243844Syokota
9343725Syokotavoid gnttab_request_free_callback(struct gnttab_free_callback *callback,
9443725Syokota				  void (*fn)(void *), void *arg, uint16_t count);
9581251Sruvoid gnttab_cancel_free_callback(struct gnttab_free_callback *callback);
9681251Sru
9743844Syokotavoid gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
9843844Syokota				     unsigned long frame, int flags);
9965013Ssheldonh
10081449Sruvoid gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid,
10143844Syokota				       unsigned long pfn);
10265009Ssheldonh
10365009Ssheldonhint gnttab_suspend(void);
10465009Ssheldonhint gnttab_resume(void);
10565009Ssheldonh
10643725Syokotastatic inline void
10743844Syokotagnttab_set_map_op(struct gnttab_map_grant_ref *map, vm_paddr_t addr,
10843844Syokota		  uint32_t flags, grant_ref_t ref, domid_t domid)
10943725Syokota{
110206374Sjkim	if (flags & GNTMAP_contains_pte)
111206374Sjkim		map->host_addr = addr;
112206374Sjkim	else if (xen_feature(XENFEAT_auto_translated_physmap))
113206374Sjkim		map->host_addr = vtophys(addr);
11443844Syokota	else
11581622Sru		map->host_addr = addr;
11681622Sru
11781622Sru	map->flags = flags;
118206374Sjkim	map->ref = ref;
119206374Sjkim	map->dom = domid;
12043844Syokota}
12143725Syokota
122154398Sbruefferstatic inline void
123154398Sbrueffergnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, vm_paddr_t addr,
12443844Syokota		    uint32_t flags, grant_handle_t handle)
125216065Sdougb{
126216065Sdougb	if (flags & GNTMAP_contains_pte)
127216065Sdougb		unmap->host_addr = addr;
128216065Sdougb	else if (xen_feature(XENFEAT_auto_translated_physmap))
12943844Syokota		unmap->host_addr = vtophys(addr);
13081622Sru	else
131206374Sjkim		unmap->host_addr = addr;
132206374Sjkim
133293034Sdes	unmap->handle = handle;
134293034Sdes	unmap->dev_bus_addr = 0;
13543844Syokota}
13662978Sdannyboy
13743844Syokotastatic inline void
13843725Syokotagnttab_set_replace_op(struct gnttab_unmap_and_replace *unmap, vm_paddr_t addr,
13943844Syokota		      vm_paddr_t new_addr, grant_handle_t handle)
14043725Syokota{
14143844Syokota	if (xen_feature(XENFEAT_auto_translated_physmap)) {
14243725Syokota		unmap->host_addr = vtophys(addr);
14343725Syokota		unmap->new_addr = vtophys(new_addr);
14443725Syokota	} else {
14576175Sschweikh		unmap->host_addr = addr;
14649792Schris		unmap->new_addr = new_addr;
14743725Syokota	}
14843725Syokota
14943725Syokota	unmap->handle = handle;
15043844Syokota}
15143725Syokota
15243844Syokota#endif /* __ASM_GNTTAB_H__ */
15343725Syokota