检查映射的内存是否支持写合并 [英] check if the mapped memory supports write combining

查看:119
本文介绍了检查映射的内存是否支持写合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个内核驱动程序,将我的I/O设备暴露给用户空间. 使用mmap,应用程序将获取虚拟地址以写入设备. 由于我希望应用程序写入使用大PCIe事务,因此驱动程序将此内存映射为写入合并. 根据内存类型(写合并或非缓存),应用程序将采用最佳方法来与设备一起使用.

但是,某些体系结构不支持写合并,或者可能仅支持部分存储空间. 因此,重要的是,内核驱动程序应告知应用程序是否成功将内存映射为要进行写合并.

我需要一种通用的方法来检查内核驱动程序是否映射(或将要映射)的内存是写合并的. 我该怎么做?

这是我的代码的一部分:

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);

解决方案

首先,您可以使用宏ARCH_HAS_IOREMAP_WC来确定体系结构是否支持在编译时进行写合并.例如,请参见此处.

在运行时,您可以从 ioremap_wc set_memory_wc 和朋友成功与否.

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);

解决方案

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.

这篇关于检查映射的内存是否支持写合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆