如何在内核模块中断中触发函数 [英] How to trigger a function in kernel module interrupt

查看:221
本文介绍了如何在内核模块中断中触发函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个Linux内核模块,该模块等待硬件触发,然后通过DMA将一些数据移至外部存储器.

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.

我已经在内核模块中识别了硬件触发器,现在我需要使其执行DMA.问题在于执行DMA的功能涉及一个休眠点,直到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.

有没有一种方法可以设置某种信号,以便内核模块知道在下一次机会调用DMA函数,但是在中断上下文中不这样做?

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?

推荐答案

建议您通过注册回调来使用下半部分. Linux以这种方式工作,上半部/下半部.

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.

建议您在罗伯特·洛夫(robert love)的书中对此进行阅读.这是一个很好的起点.

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

检查linuxkernel org源上的任何i2c客户端驱动程序以供参考.

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

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

在其中注册您的回调以进行DMA发布数据处理.

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.

这篇关于如何在内核模块中断中触发函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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