xen/mm: Factor out the pdx compression logic in ma/va converters

This patch factors out the pdx compression logic hardcoded in both ports
for the maddr<->vaddr conversion functions.

Touches both x86 and arm ports.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
Alejandro Vallejo authored and Andrew Cooper committed 2023-09-22 18:26:04 +01:00
1 parent 95a8a2c123
commit bc2cda8c59
3 files changed
+38 -17

No files matched your search

+1 -2
View File
@@ -319,8 +319,7 @@ static inline void *maddr_to_virt(paddr_t ma)
(DIRECTMAP_SIZE >> PAGE_SHIFT));
return (void *)(XENHEAP_VIRT_START -
(directmap_base_pdx << PAGE_SHIFT) +
((ma & ma_va_bottom_mask) |
((ma & ma_top_mask) >> pfn_pdx_hole_shift)));
maddr_to_directmapoff(ma));
}
#endif
+12 -15
View File
@@ -36,26 +36,23 @@ static inline unsigned long __virt_to_maddr(unsigned long va)
{
ASSERT(va < DIRECTMAP_VIRT_END);
if ( va >= DIRECTMAP_VIRT_START )
va -= DIRECTMAP_VIRT_START;
else
{
BUILD_BUG_ON(XEN_VIRT_END - XEN_VIRT_START != GB(1));
/* Signed, so ((long)XEN_VIRT_START >> 30) fits in an imm32. */
ASSERT(((long)va >> (PAGE_ORDER_1G + PAGE_SHIFT)) ==
((long)XEN_VIRT_START >> (PAGE_ORDER_1G + PAGE_SHIFT)));
return directmapoff_to_maddr(va - DIRECTMAP_VIRT_START);
va += xen_phys_start - XEN_VIRT_START;
}
return (va & ma_va_bottom_mask) |
((va << pfn_pdx_hole_shift) & ma_top_mask);
BUILD_BUG_ON(XEN_VIRT_END - XEN_VIRT_START != GB(1));
/* Signed, so ((long)XEN_VIRT_START >> 30) fits in an imm32. */
ASSERT(((long)va >> (PAGE_ORDER_1G + PAGE_SHIFT)) ==
((long)XEN_VIRT_START >> (PAGE_ORDER_1G + PAGE_SHIFT)));
return xen_phys_start + va - XEN_VIRT_START;
}
static inline void *__maddr_to_virt(unsigned long ma)
{
ASSERT(pfn_to_pdx(ma >> PAGE_SHIFT) < (DIRECTMAP_SIZE >> PAGE_SHIFT));
return (void *)(DIRECTMAP_VIRT_START +
((ma & ma_va_bottom_mask) |
((ma & ma_top_mask) >> pfn_pdx_hole_shift)));
/* Offset in the direct map, accounting for pdx compression */
unsigned long va_offset = maddr_to_directmapoff(ma);
ASSERT(va_offset < DIRECTMAP_SIZE);
return (void *)(DIRECTMAP_VIRT_START + va_offset);
}
/* read access (should only be used for debug printk's) */
+25
View File
@@ -160,6 +160,31 @@ static inline unsigned long pdx_to_pfn(unsigned long pdx)
#define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn))
#define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx))
/**
* Computes the offset into the direct map of an maddr
*
* @param ma Machine address
* @return Offset on the direct map where that
* machine address can be accessed
*/
static inline unsigned long maddr_to_directmapoff(paddr_t ma)
{
return (((ma & ma_top_mask) >> pfn_pdx_hole_shift) |
(ma & ma_va_bottom_mask));
}
/**
* Computes a machine address given a direct map offset
*
* @param offset Offset into the direct map
* @return Corresponding machine address of that virtual location
*/
static inline paddr_t directmapoff_to_maddr(unsigned long offset)
{
return ((((paddr_t)offset << pfn_pdx_hole_shift) & ma_top_mask) |
(offset & ma_va_bottom_mask));
}
/**
* Initializes global variables with information about the compressible
* range of the current memory regions.
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.