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