2018-08-28 00:40:15 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
2017-04-04 05:48:17 -07:00
|
|
|
#include <linux/pfn.h>
|
|
|
|
#include <asm/xen/page.h>
|
|
|
|
#include <asm/xen/hypercall.h>
|
|
|
|
#include <xen/interface/memory.h>
|
2015-07-16 21:51:35 -07:00
|
|
|
|
2024-07-10 02:37:18 -07:00
|
|
|
#include "xen-ops.h"
|
2015-07-16 21:51:35 -07:00
|
|
|
|
2017-04-04 05:48:17 -07:00
|
|
|
unsigned long arbitrary_virt_to_mfn(void *vaddr)
|
2015-07-16 21:51:35 -07:00
|
|
|
{
|
2017-04-04 05:48:17 -07:00
|
|
|
xmaddr_t maddr = arbitrary_virt_to_machine(vaddr);
|
2015-07-16 21:51:35 -07:00
|
|
|
|
2017-04-04 05:48:17 -07:00
|
|
|
return PFN_DOWN(maddr.maddr);
|
2015-07-16 21:51:35 -07:00
|
|
|
}
|
|
|
|
|
2017-04-04 05:48:17 -07:00
|
|
|
xmaddr_t arbitrary_virt_to_machine(void *vaddr)
|
2010-11-24 05:09:41 -07:00
|
|
|
{
|
2017-04-04 05:48:17 -07:00
|
|
|
unsigned long address = (unsigned long)vaddr;
|
|
|
|
unsigned int level;
|
|
|
|
pte_t *pte;
|
|
|
|
unsigned offset;
|
2010-11-24 05:09:41 -07:00
|
|
|
|
|
|
|
/*
|
2017-04-04 05:48:17 -07: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 05:09:41 -07:00
|
|
|
*/
|
2017-04-04 05:48:17 -07:00
|
|
|
if (virt_addr_valid(vaddr))
|
|
|
|
return virt_to_machine(vaddr);
|
2015-12-12 17:25:55 -07:00
|
|
|
|
2017-04-04 05:48:17 -07:00
|
|
|
/* otherwise we have to do a (slower) full page-table walk */
|
2010-03-26 15:37:50 -07:00
|
|
|
|
2017-04-04 05:48:17 -07: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 05:30:02 -07:00
|
|
|
}
|
2017-04-04 05:48:17 -07:00
|
|
|
EXPORT_SYMBOL_GPL(arbitrary_virt_to_machine);
|
2009-01-28 15:35:01 -07:00
|
|
|
|
2012-10-17 13:37:49 -07:00
|
|
|
/* Returns: 0 success */
|
2015-08-07 09:34:41 -07:00
|
|
|
int xen_unmap_domain_gfn_range(struct vm_area_struct *vma,
|
2017-11-03 10:04:11 -07:00
|
|
|
int nr, struct page **pages)
|
2012-10-17 13:37:49 -07:00
|
|
|
{
|
2017-11-03 10:04:11 -07:00
|
|
|
if (xen_feature(XENFEAT_auto_translated_physmap))
|
|
|
|
return xen_xlate_unmap_gfn_range(vma, nr, pages);
|
|
|
|
|
|
|
|
if (!pages)
|
2012-10-17 13:37:49 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-08-07 09:34:41 -07:00
|
|
|
EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range);
|