2018-08-28 10:40:15 +03:00
// SPDX-License-Identifier: GPL-2.0
2017-04-04 15:48:17 +03:00
# include <linux/pfn.h>
# include <asm/xen/page.h>
# include <asm/xen/hypercall.h>
# include <xen/interface/memory.h>
2015-07-17 07:51:35 +03:00
2017-04-04 15:48:17 +03:00
# include "multicalls.h"
# include "mmu.h"
2015-07-17 07:51:35 +03:00
2017-04-04 15:48:17 +03:00
unsigned long arbitrary_virt_to_mfn ( void * vaddr )
2015-07-17 07:51:35 +03:00
{
2017-04-04 15:48:17 +03:00
xmaddr_t maddr = arbitrary_virt_to_machine ( vaddr ) ;
2015-07-17 07:51:35 +03:00
2017-04-04 15:48:17 +03:00
return PFN_DOWN ( maddr . maddr ) ;
2015-07-17 07:51:35 +03:00
}
2017-04-04 15:48:17 +03:00
xmaddr_t arbitrary_virt_to_machine ( void * vaddr )
2010-11-24 15:09:41 +03:00
{
2017-04-04 15:48:17 +03:00
unsigned long address = ( unsigned long ) vaddr ;
unsigned int level ;
pte_t * pte ;
unsigned offset ;
2010-11-24 15:09:41 +03:00
/*
2017-04-04 15:48:17 +03:00
* if the PFN is in the linear mapped vaddr range , we can just use
* the ( quick ) virt_to_machine ( ) p2m lookup
2010-11-24 15:09:41 +03:00
*/
2017-04-04 15:48:17 +03:00
if ( virt_addr_valid ( vaddr ) )
return virt_to_machine ( vaddr ) ;
2015-12-13 03:25:55 +03:00
2017-04-04 15:48:17 +03:00
/* otherwise we have to do a (slower) full page-table walk */
2010-03-27 01:37:50 +03:00
2017-04-04 15:48:17 +03:00
pte = lookup_address ( address , & level ) ;
BUG_ON ( pte = = NULL ) ;
offset = address & ~ PAGE_MASK ;
return XMADDR ( ( ( phys_addr_t ) pte_mfn ( * pte ) < < PAGE_SHIFT ) + offset ) ;
2009-08-20 16:30:02 +04:00
}
2017-04-04 15:48:17 +03:00
EXPORT_SYMBOL_GPL ( arbitrary_virt_to_machine ) ;
2009-01-29 01:35:01 +03:00
2012-10-18 00:37:49 +04:00
/* Returns: 0 success */
2015-08-07 19:34:41 +03:00
int xen_unmap_domain_gfn_range ( struct vm_area_struct * vma ,
2017-11-03 20:04:11 +03:00
int nr , struct page * * pages )
2012-10-18 00:37:49 +04:00
{
2017-11-03 20:04:11 +03:00
if ( xen_feature ( XENFEAT_auto_translated_physmap ) )
return xen_xlate_unmap_gfn_range ( vma , nr , pages ) ;
if ( ! pages )
2012-10-18 00:37:49 +04:00
return 0 ;
return - EINVAL ;
}
2015-08-07 19:34:41 +03:00
EXPORT_SYMBOL_GPL ( xen_unmap_domain_gfn_range ) ;