The evolution of driver page remapping

Two weeks ago, this page looked at the newVM_UNPAGED flag, introduced in 2.6.15-rc2 to mark virtual memory areas (VMAs) which are not made up of "normal" pages. These areas are usually created by device drivers which map special memory areas (which may or may not be device I/O memory) into user space. Your editor now humbly suggests that readers ignore that article; things have changed significantly since then.

As it turns out, Linus didn't like the VM_UNPAGED idea, so he rewrote the code for 2.6.15-rc4. TheVM_UNPAGED VMA flag is gone, replaced by VM_PFNMAP. The new flag has a very similar meaning: it marks the VMA as containing special page table entries which should not be touched by the VM subsystem. In particular, it states that there is no page structure associated with any page in that VMA, so the VM subsystem should not go looking for one. Even in cases where that structure does exist (such as remappings of real memory), the VM code will pretend that it does not.

The advantage of the reworked code is that it takes out a number of special cases; theVM_PFNMAP VMAs can be treated just like normal VMAs in more places. Things quickly got a bit more complicated, however. The initialVM_PFNMAP code assumed that a linear range of addresses was being mapped into user space. In fact, some drivers piece together memory in more complicated ways.

So a subsequent patch added explicit support for "incomplete" VMAs, marked with yet another flag:VM_INCOMPLETE. When the kernel detects that a driver is creating something other than a straightforward, linear mapping, it sets that flag and emits a warning. It also requires, in this case, that the pages being remapped carry thePG_reserved flag - even though this flag is being phased out. Remapping RAM in this way always required that flag in the past, so this requirement is not a change as far as drivers are concerned.

The patch adding VM_INCOMPLETE notes that "In the long run we almost certainly want to export a totally different interface for that, though." In this case, "in the long run" meant about one day, when yet another patch was merged adding a new function:

    int vm_insert_page(struct vm_area_struct *vma, 
                       unsigned long address,
                       struct page *page);

This function inserts the given page into vma, mapped at the givenaddress. It does not put out warnings, and does not require that PG_reserved be set. What itdoes require is that the page be an order-zero allocation obtained for this purpose; it is not possible to remap arbitrary RAM pages withvm_insert_page(). Since a page structure is required, the new function is also unsuitable for remapping I/O memory. But it is useful for drivers which wish to map a set of pages into a user-space address range.

Just which driver might want to do something like that became clear when another patch was merged for 2.6.15-rc5. It removed the GPL-only export forvm_insert_page() and included this commit message:

Make vm_insert_page() available to NVidia module. It used to use remap_pfn_range(), which wasn't GPL-only either, and the new interface is actually simpler and does more checking, so we shouldn't unnecessarily discourage people from switching over.

Some developers objected to this change, seeing it as an explicit endorsement of the proprietary NVidia drivers. Others, however, saw it as a simple attempt to avoid breaking drivers without a good reason. The kernel developers may well be working toward taking a stronger stand against proprietary modules, but this particular interface will not be the place where that battle is fought.

`IO remapping`,即输入输出重映射,在电子系统设计和硬件编程中是一个重要的概念。它涉及到将设备或模块的物理引脚(Input/Output pins)与它们在逻辑电路中的功能重新分配的过程。 ### 为什么需要IO Remapping? 1. **资源优化**:在一些嵌入式系统或微处理器中,为了更高效地利用有限的I/O资源,可能需要通过重映射来调整I/O端口的功能。 2. **灵活性增加**:对于可配置的硬件,例如FPGA、SoC等,通过IO remapping可以提供更多的接口选择和更高的定制化程度。 3. **兼容性增强**:当不同类型的设备或外设需要接入同一系统时,可能会存在不兼容的问题,通过重映射可以解决这种兼容性问题。 4. **简化连接**:在复杂的系统设计中,通过合理安排IO的连接方式,可以减少线缆数量或布线复杂度,从而降低成本并提高系统的整体效率。 ### 如何实现IO Remapping? 在实际应用中,IO remapping通常可以通过以下几个步骤实现: - **定义需求**:首先明确系统对I/O资源的需求,包括哪些功能需要通过特定的引脚实现。 - **查找文档**:查阅相关芯片的数据手册,了解每个引脚的原始功能及其可用选项。 - **配置软件/硬件参数**:根据需求调整芯片或系统的配置文件,更改I/O引脚的映射关系。 - **验证测试**:完成配置后,进行必要的测试以确保所有功能正常工作且没有冲突产生。 ### 应用场景示例 - 在FPGA项目中,开发者可以通过编程修改I/O端口的功能,将其从数字信号处理转换为模拟控制信号输出。 - 在嵌入式系统设计中,通过重映射可以将USB控制器的端口用于其他通信协议(如SPI),以节省额外的物理引脚资源。 - 对于某些单片机系统,可以通过改变GPIO的映射来复用其功能,比如将一个GPIO从普通输入输出改为主控定时器的中断源。 总之,IO remapping是电子工程领域中一项常见的技术实践,能够帮助工程师们更灵活、有效地管理硬件资源,适应不同的设计需求和环境变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值