linux下platform_device中的dma_mask与coherent_dma_mask
来源:互联网 发布:seo标签优化 编辑:程序博客网 时间:2024/05/24 01:00
一:dma_mask与coherent_dma_mask的定义
在linux内核中,引入了platform_device与platform_driver,这样就很方便了平台的设备与驱动。在include\linux\platform_device.h下:
struct platform_device {
const char * name;
int id;
struct device dev;
u32 num_resources;
struct resource * resource;
const struct platform_device_id *id_entry;
/* arch specific additions */
struct pdev_archdata archdata;
};
而struct device dev,在include\linux\device.h中:
struct device {
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */
struct device_type *type;
struct mutex mutex; /* mutex to synchronize calls to
* its driver.
*/
struct bus_type *bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this
device */
void *platform_data; /* Platform specific data, device
core doesn't touch it */
struct dev_pm_info power;
#ifdef CONFIG_NUMA
int numa_node; /* NUMA node this device is close to */
#endif
u64 *dma_mask; /* dma mask (if dma'able device) */
u64 coherent_dma_mask;/* Like dma_mask, but for
alloc_coherent mappings as
not all hardware supports
64 bit addresses for consistent
allocations such descriptors. */
struct device_dma_parameters *dma_parms;
struct list_head dma_pools; /* dma pools (if dma'ble) */
struct dma_coherent_mem *dma_mem; /* internal for coherent mem
override */
/* arch specific additions */
struct dev_archdata archdata;
#ifdef CONFIG_OF
struct device_node *of_node;
#endif
dev_t devt; /* dev_t, creates the sysfs "dev" */
spinlock_t devres_lock;
struct list_head devres_head;
struct klist_node knode_class;
struct class *class;
const struct attribute_group **groups; /* optional groups */
void (*release)(struct device *dev);
};
dma_mask与coherent_dma_mask这两个参数表示它能寻址的物理地址的范围,内核通过这两个参数分配合适的物理内存给 device。其中dma_coherent_mask则作用于申请一致性DMA缓冲区。因为不是所有的硬件都能够支持64bit的地址宽度。如果 addr_phy 是一个物理地址,且 (u64)addr_phy <= *dev->dma_mask,那么 该 device 就可以寻址该物理地址。如果 device 只能寻址32位地址,那么 mask 应为 0xffffffff。依此类推。
例如,在linux2.6.38中:
/* USB EHCI Host Controller */
static u64 nuc900_device_usb_ehci_dmamask = 0xffffffffUL;
static struct platform_device nuc900_device_ehci = {
.name = "nuc900-ehci",
.id = -1,
.num_resources = ARRAY_SIZE(nuc900_ehci_resource),
.resource = nuc900_ehci_resource,
.dev = {
.dma_mask = &nuc900_device_usb_ehci_dmamask,
.coherent_dma_mask = 0xffffffffUL
}
};
二:sample code
这段代码摘录自 arch\arm\mm\dma-mapping.c
u64 limit;
/*
* Sanity check the allocation size.
*/
size = PAGE_ALIGN(size);
//这个 limit 就是通过 mask 计算得到的设备最大寻址范围。
limit = (mask + 1) & ~mask;
//当 size 超出 limit 时,说明分配的地址超出了设备的最大寻址能力,这时返回错误。
if ((limit && size >= limit) ||
size >= (CONSISTENT_END - CONSISTENT_BASE)) {
printk(KERN_WARNING "coherent allocation too big "
"(requested %#x mask %#llx)\n", size, mask);
goto no_page;
}
- linux下platform_device中的dma_mask与coherent_dma_mask
- linux下platform_device中的dma_mask与coherent_dma_mask
- platform dma_mask coherent_dma_mask
- DMA_ZONE、dma_mask、coherent_dma_mask和dma bounce相关问题的澄清
- DMA_ZONE、dma_mask、coherent_dma_mask和dma bounce相关问题的澄清
- DMA_ZONE、dma_mask、coherent_dma_mask和dma bounce相关问题的澄清
- 用中的linux驱动 platform_device
- 应用中的linux驱动 platform_device
- linux驱动学习(六) 应用中的linux驱动 platform_device
- linux驱动学习(六) 应用中的linux驱动 platform_device
- linux驱动学习(六) 应用中的linux驱动 platform_device
- linux驱动学习(六) 应用中的linux驱动 platform_device
- Linux 2.6下的新的驱动管理机制:Platform_device
- linux驱动 platform_device
- platform_device与platform_driver
- platform_device与platform_driver
- platform_device与platform_driver 转
- platform_device与platform_driver
- 关于回调函数,讲的很浅,但很好懂
- Tomcat常见内存错误的处理
- Sprint源码学习之StringUtils类
- ftp文件上传
- linux中fork浅解
- linux下platform_device中的dma_mask与coherent_dma_mask
- c++线程的创建
- 虚拟化技术应用现状
- 让IE支持HTML5元素作为CSS选择器
- MAC地址
- C++类模板 实现顺序表 从《数据结构》(C++版) 北京科海摘抄
- 搭建SSH框架 简单示例
- Windows 声音处理编程(基于winmm.dll)(1)
- 算法——计算的灵魂(《算法》一本写了近40年的书)