Custom interrupt handler for the NMI hardware button
1
vote
0
answers
600
views
I'm trying to create a custom interrupt handler for the NMI hardware button which exists on my motherboard.
To test this functionality I've created this simple module:
#include
#include
#include
#include
static int nmi_custom_handler(unsigned int val, struct pt_regs* regs)
{
pr_info("My custom NMI: 0x%x\n", val);
return NMI_HANDLED;
}
static int __init nmi_handler_init(void) {
pr_info("nmi_handler_init\n");
register_nmi_handler(NMI_UNKNOWN, nmi_custom_handler, 0, "my_custom_nmi");
return 0;
}
static void __exit nmi_handler_exit(void) {
pr_info("nmi_handler_exit\n");
unregister_nmi_handler(NMI_UNKNOWN, "my_custom_nmi");
}
module_init(nmi_handler_init);
module_exit(nmi_handler_exit);
MODULE_AUTHOR("Konstantin Aladyshev ");
MODULE_LICENSE("GPL");
If I load this module and press NMI button one time, there will be "My custom NMI" message for every CPU core in my system. The same can be seen in the "/proc/interrupt" interface. NMI interrupt count increases from 0 to 1 for every CPU.
But for some reason this works only once. Next button presses don't get logged by my module or the /proc interface.
Why? What should I change to be able to use NMI hardware interrupt again?
Asked by kostr22
(216 rep)
Jan 14, 2020, 06:28 PM