check if the mapped memory supports write combinin

2019-09-13 11:30发布

问题:

I write a kernel driver which exposes to the user space my I/O device. Using mmap the application gets virtual address to write into the device. Since i want the application write uses a big PCIe transaction, the driver maps this memory to be write combining. According to the memory type (write-combining or non-cached) the application applies an optimal method to work with the device.

But, some architectures do not support write-combining or may support but just for part of the memory space. Hence, it is important that the kernel driver tell to application if it succeeded to map the memory to be write-combining or not.

I need a generic way to check in the kernel driver if the memory it mapped (or going to map) is write-combining or not. How can i do it?

here is part of my code:

vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); io_remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, vma->vm_page_prot);

回答1:

First, you can find out if an architecture supports write-combining at compile time, with the macro ARCH_HAS_IOREMAP_WC. See, for instance, here.

At run-time, you can check the return values from ioremap_wc, or set_memory_wc and friends for success or not.