How to trigger a function in kernel module interrupt

痞子三分冷 提交于 2019-12-08 13:36:54

问题


I'm trying to write a linux kernel module which waits for a hardware trigger and then moves some data to an external memory via DMA.

I've got the hardware trigger recognized in my kernel module, now I need to make it perform the DMA. The problem is that the function that performs the DMA involves a point where it sleeps until the DMA is completed. This isn't allowed in interrupts, so I can't call the function directly in my interrupt service routine.

Is there a way I can set some kind of signal so that my kernel module knows to call the DMA function the next chance it gets, but doesn't do so in the interrupt context?


回答1:


Would suggest you to use bottom halves by registering a callback. Linux works this way, top half/bottom half.

top half services the interrupt and clear interrupt control register, and queuing the registered callback that is your bottom half, it can sleep.

Would suggest you have a read about it in a book by robert love. it is very good place to start.

https://doc.lagout.org/operating%20system%20/linux/Linux%20Kernel%20Development%2C%203rd%20Edition.pdf

Check any i2c client driver on linuxkernel org source for reference.

https://elixir.bootlin.com/linux/latest/source/drivers/misc/fsa9480.c#L394

register your callback for DMA post data processing there.

this is just gist on how bottom halves can help you with developing drivers. hope it can be of any help to you.



来源:https://stackoverflow.com/questions/49158406/how-to-trigger-a-function-in-kernel-module-interrupt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!