如何从cdev获取设备 [英] How to get device from cdev

查看:94
本文介绍了如何从cdev获取设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个内核模块,该模块将分配一些一致的内存并返回相应的虚拟和物理地址.

I am writing a kernel module that will allocate some coherent memory and return the corresponding virtual and physical addresses.

我正在将模块注册为cdev,并使用dma_alloc_coherent()分配空间,并且我想使用dma_common_mmap()映射它.

I am registering the module as cdev, allocating space with dma_alloc_coherent() and I wanted to mmap it using dma_common_mmap().

dma_common_mmap()需要指向struct device的指针:我如何获得它?

dma_common_mmap() requires a pointer to struct device: how could I obtain it?

推荐答案

void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, int flag);

此函数处理缓冲区的分配和映射.前两个参数是设备结构和所需缓冲区的大小. 该函数在两个地方返回DMA映射的结果.该函数的返回值是缓冲区的内核虚拟地址,驱动程序可以使用该地址. 同时,相关的总线地址在dma_handle中返回.

This function handles both the allocation and the mapping of the buffer. The first two arguments are the device structure and the size of the buffer needed. The function returns the result of the DMA mapping in two places. The return value from the function is a kernel virtual address for the buffer, which may be used by the driver. The associated bus address, meanwhile, is returned in dma_handle.

这篇关于如何从cdev获取设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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