arch/arm/xen/mm.c
Source file repositories/reference/linux-study-clean/arch/arm/xen/mm.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm/xen/mm.c- Extension
.c- Size
- 3872 bytes
- Lines
- 142
- Domain
- Architecture Layer
- Bucket
- arch/arm
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpu.hlinux/dma-direct.hlinux/dma-map-ops.hlinux/gfp.hlinux/highmem.hlinux/export.hlinux/memblock.hlinux/of_address.hlinux/slab.hlinux/types.hlinux/vmalloc.hlinux/swiotlb.hxen/xen.hxen/interface/grant_table.hxen/interface/memory.hxen/page.hxen/xen-ops.hxen/swiotlb-xen.hasm/cacheflush.hasm/xen/hypercall.hasm/xen/interface.h
Detected Declarations
function xen_swiotlb_gfpfunction for_each_mem_rangefunction dma_cache_maintfunction xen_dma_sync_for_cpufunction xen_dma_sync_for_devicefunction xen_arch_need_swiotlbfunction xen_mm_init
Annotated Snippet
if (base < (phys_addr_t)0xffffffff) {
if (IS_ENABLED(CONFIG_ZONE_DMA32))
return __GFP_DMA32;
return __GFP_DMA;
}
}
return GFP_KERNEL;
}
static bool hypercall_cflush = false;
/* buffers in highmem or foreign pages cannot cross page boundaries */
static void dma_cache_maint(struct device *dev, dma_addr_t handle,
size_t size, u32 op)
{
struct gnttab_cache_flush cflush;
cflush.offset = xen_offset_in_page(handle);
cflush.op = op;
handle &= XEN_PAGE_MASK;
do {
cflush.a.dev_bus_addr = dma_to_phys(dev, handle);
if (size + cflush.offset > XEN_PAGE_SIZE)
cflush.length = XEN_PAGE_SIZE - cflush.offset;
else
cflush.length = size;
HYPERVISOR_grant_table_op(GNTTABOP_cache_flush, &cflush, 1);
cflush.offset = 0;
handle += cflush.length;
size -= cflush.length;
} while (size);
}
/*
* Dom0 is mapped 1:1, and while the Linux page can span across multiple Xen
* pages, it is not possible for it to contain a mix of local and foreign Xen
* pages. Calling pfn_valid on a foreign mfn will always return false, so if
* pfn_valid returns true the pages is local and we can use the native
* dma-direct functions, otherwise we call the Xen specific version.
*/
void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle,
size_t size, enum dma_data_direction dir)
{
if (dir != DMA_TO_DEVICE)
dma_cache_maint(dev, handle, size, GNTTAB_CACHE_INVAL);
}
void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle,
size_t size, enum dma_data_direction dir)
{
if (dir == DMA_FROM_DEVICE)
dma_cache_maint(dev, handle, size, GNTTAB_CACHE_INVAL);
else
dma_cache_maint(dev, handle, size, GNTTAB_CACHE_CLEAN);
}
bool xen_arch_need_swiotlb(struct device *dev,
phys_addr_t phys,
dma_addr_t dev_addr)
{
unsigned int xen_pfn = XEN_PFN_DOWN(phys);
unsigned int bfn = XEN_PFN_DOWN(dma_to_phys(dev, dev_addr));
/*
* The swiotlb buffer should be used if
* - Xen doesn't have the cache flush hypercall
* - The Linux page refers to foreign memory
* - The device doesn't support coherent DMA request
*
* The Linux page may be spanned acrros multiple Xen page, although
* it's not possible to have a mix of local and foreign Xen page.
* Furthermore, range_straddles_page_boundary is already checking
* if buffer is physically contiguous in the host RAM.
*
* Therefore we only need to check the first Xen page to know if we
* require a bounce buffer because the device doesn't support coherent
* memory and we are not able to flush the cache.
*/
return (!hypercall_cflush && (xen_pfn != bfn) &&
!dev_is_dma_coherent(dev));
}
static int __init xen_mm_init(void)
{
struct gnttab_cache_flush cflush;
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/dma-direct.h`, `linux/dma-map-ops.h`, `linux/gfp.h`, `linux/highmem.h`, `linux/export.h`, `linux/memblock.h`, `linux/of_address.h`.
- Detected declarations: `function xen_swiotlb_gfp`, `function for_each_mem_range`, `function dma_cache_maint`, `function xen_dma_sync_for_cpu`, `function xen_dma_sync_for_device`, `function xen_arch_need_swiotlb`, `function xen_mm_init`.
- Atlas domain: Architecture Layer / arch/arm.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.