dma

Linux kernel device driver to DMA from a device into user-space memory

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to get data from a DMA enabled, PCIe hardware device into user-space as quickly as possible. Q: How do I combine "direct I/O to user-space with/and/via a DMA transfer" Reading through LDD3, it seems that I need to perform a few different types of IO operations!? dma_alloc_coherent gives me the physical address that I can pass to the hardware device. But would need to have setup get_user_pages and perform a copy_to_user type call when the transfer completes. This seems a waste, asking the Device to DMA into kernel memory

What does the distance attribute in DMatches mean?

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a short question: When I do feature-matching in OpenCV, what does the distance attribute mean of DMatches in MatOfMatches ? I know that I have to filter matches with bigger distance because they aren't as good as them with lower distance. But what is the meaning of this attribute? Is it a kind of deviation? 回答1: In this context, a feature is a point of interest on the image. In order to compare features, you "describe" them using a feature detector . Each feature is then associated to a descriptor . When you match features,

Receiving data from 2 UARTs, STM32F4-Discovery, HAL drivers

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 回答1: Wrong DMA Stream/Channel DMA1_Stream1 DMA_CHANNEL_5 is assigned to UART7_TX . The stream/channel for UART5_RX should be DMA1_Stream0 DMA_CHANNEL_4 . See Reference Manual RM0090 page 308 文章来源: Receiving data from 2 UARTs, STM32F4-Discovery, HAL drivers

scatter/gather I/O

匿名 (未验证) 提交于 2019-12-03 00:38:01
发散/汇聚映射 int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction); 各参数含义如下: dev:设备数据结构指针 sg:缓冲区列表的第一个缓冲区的指针 nets:sg中有多少个缓冲区 direction:数据流动方向 该函数的返回值是成功映射了多少个缓冲区。如果在分散/汇聚列表中一些缓冲的物理地址或虚拟地址相邻的,且IOMMU可以将它们映射成单个内存块,则返回值可能比输入值nents小。 数据结构scatterlist包含了每个缓冲区的信息,其定义如下: struct scatterlist { #ifdef CONFIG_DEBUG_SG unsigned long sg_magic; #endif unsigned long page_link; unsigned int offset; unsigned int length; dma_addr_t dma_address; #ifdef CONFIG_NEED_SG_DMA_LENGTH unsigned int dma_length; #endif }; 注意如果sg已经映射过了,则不能再对其进行映射,再次映射会损坏sg中的信息。对于sg中的每个缓冲,该函数会正确的为

windows驱动开发-Altera PCIe DMA

匿名 (未验证) 提交于 2019-12-03 00:34:01
DMA Descriptor Controller Registers DMA控制器读写均支持最多128个描述符,读写操作是以FPGA视角来看,读操作是从PCIe地址空间到FPGA Avalon-MM地址空间,写操作是从FPGA Avalon-MM地址空间到PCIe地址空间。 在DMA控制器寄存器里设置描述符表位于在PCIe地址空间里的地址和大小,DMA控制器用Read Data Mover首先将描述符复制到自己内部的FIFO中,然后在根据描述符来开始DMA传输。描述符在RC内的地址必须是32字节对齐的。 DMA控制器有寄存器指示读写描述符的完成状态,读和写分别有自己的状态寄存器表,每个表有128个连续的DWORD项,对应128个描述符。状态字占用512字节,位置在RC Read Status and Descriptor Base指定的地址偏移0处,而实际的描述符在0x200偏移处,DMA控制器项状态字的done位写1表示传输成功,DMA控制器在完成最后一个描述符后会发送一个MSI中断,在接收到中断之后,主机host软件可以轮询done位来判断描述符状态,但是DMA控制器不会设置done位或者发送MSI在每一个描述符完成的时候,它根据RD_DMA_LAST PTR和WR_DMA_LAST_PTR寄存器存储的描述符ID来操作,由于描述符支持PCIe完成包的乱序传输

Where to start learning about linux DMA / device drivers / memory allocation

こ雲淡風輕ζ 提交于 2019-12-03 00:33:47
I'm porting / debugging a device driver (that is used by another kernel module) and facing a dead end because dma_sync_single_for_device() fails with an kernel oops. I have no clue what that function is supposed to do and googling does not really help, so I probably need to learn more about this stuff in total. The question is, where to start? Oh yeah, in case it is relevant, the code is supposed to run on a PowerPC (and the linux is OpenWRT) EDIT: On-line resources preferrable (books take a few days to be delivered :) On-line: Anatomy of the Linux slab allocator Understanding the Linux

[现代操作系统] I/O之硬件原理

匿名 (未验证) 提交于 2019-12-03 00:28:02
I/O 硬件原理 把信息存储在固定大小的块中, 每个块都有自己的地址. 每个块可以独立于其他块读写. 如 硬盘, CD-ROM , USB 盘 … 字符设备以字符为单位发送或接收一个字符流, 而不考虑任何块结构. 它是不可寻址的. 如打印机, 网络接口, 鼠标 (用作指点设备)… I/O 设备一般由两部分组成: 机械部分和电子部分. 电子部分就是设备控制器. 常以插入 (PCI) 扩展槽中的印刷电路板的形式出现. 控制器与设备之间的接口是很低层次的接口. 它的任务就是把串行的位流转换为字节块, 并进行必要的错误校正. 每个控制器有几个寄存器, OS 可以读写来了解, 更改设备的状态信息. 控制器还有 OS 可以读写的 数据缓冲区 . 问题来了: CPU 如何与设备的控制寄存器和数据缓冲区通信. 方法一: 每个控制寄存器被分配一个 I/O 端口 (所有端口形成端口空间, 受保护不被普通用户访问). 然后可以设置指令来读写, 如 IN REG, PORT 将读取控制器寄存器 PORT 中的内容到 CPU 寄存器 REG 方法二: 内存映射 I/O. 将所有控制寄存器映射到内存空间, 都被分配唯一的地址, 且这些内存地址不会再分配. CPU 读入一个字时, 不论是从内存还是 I/O 端口, 都将目的地址放在总线的地址线上, 总线控制线置 READ 信号看. 还要用一条线表明是 I/O

PCI常用接口函数

匿名 (未验证) 提交于 2019-12-02 23:52:01
pci_enable_device(pdev); pci_set_master(pdev); pci_find_capability(pdev, PCI_CAP_ID_MSI); pci_alloc_irq_vector()pdev,1,32,PCI_IRQ_MSI); //pci_enable_msi(); 读,写,abort 地址写配置空间偏移0x54的地址(64位,高32位一般为0) 还有就是 dma_set_mask(&(pdev->dev, DMA_BIT_MASK(64)); request_irq(pdev->irq + i , msi_handle_function, IRQF_SHARED, "edma_msi_irq", (void*) var); pci_alloc_consistent(pdev,mpara_dma_size,&dma_addr);//dma_addr 是物理地址 返回值是虚拟地址 文章来源: https://blog.csdn.net/weixin_38987932/article/details/98111607

Linux设备驱动程序 之 kmalloc

两盒软妹~` 提交于 2019-12-02 19:36:27
原型 kmalloc的原型如下: 1 void *kmalloc(size_t size, gfp_t flags) 第一个参数是要分配的块的大小,第二个参数是分片标志; flags标志 最常用的标志是GFP_KERNEL,表示内存分配(最终总是调用get_free_page来实现实际的分配,这就是GFP_前缀的由来)是代表在内核空间的进程执行的;换句话说,这意味着调用它的函数正代表某个进程执行系统调用;使用GFP_KERNEL允许在kmalloc在空闲内存较少的时候把当前进程转入休眠以等待一个页面;因此,使用GFP_KERNEL分配内存的函数必须是可重入的;在当前进程休眠时,内核会采取适当的行动,或者把缓冲区的内容刷到硬盘上,或者从搞一个用户进程换出内存,已获得一个内存页面; GFP_KERNEL分配标志并不是始终适用,有时kmalloc是在进程上下文之外被调用的,例如中断处理程序,tasklet以及内核定时器中调用;这种情况下current进程就不该休眠,驱动程序应该换用GFP_ATOMIC标志;内核通常会为原子性的分配预留一些空闲页面;使用GFP__ATOMIC标志时,kmalloc甚至可以用掉最后一个空闲页面;不过如果连最后一页都没有了,分配就返回失败; 除了GFP_KERNEL和GFP_ATOMIC外,还有一些其他标志可用于替换或者补充这两个标志

How to get linux kernel page size programmatically

ε祈祈猫儿з 提交于 2019-12-02 18:52:27
I am working on a Linux module for IA64. My current problem is that the driver uses the PAGE_SIZE and PAGE_SHIFT macros for dma page allocation. The problem I am having is that the machine compiling the driver is not the ones that needed to run the driver. So, if the PAGE_SIZE on the compiling machine is 2^14K and the destination machine is 2^16K then the driver fails. I don't want to turn this question into a 'best practice' issue about compiling modules on machines which are not the ones running the modules. I understand the issues about that. What I found is that people mostly uses