I need to execute a few machine instructions just before kernel "halts".

Reason is I need to inform a board controller it can actually remove power.

Question is: what is the best-practice to achieve this?

In an old (3.18) kernel for the same board I hacked .../arch/mips/ralink/reset.c to add some register settings in static void ralink_halt(void) but that function seems gone together with static int __init mips_reboot_setup(void), so i guess structure changed a lot since then.

What is the correct hook to use in modern kernels?

  • My PC (and I imagine almost every ones), does this. I would hope that it is not in the kernel. I would hope that it is in user mode. There still needs to be a kernel driver. But I would hope that this is triggered by the user mode shutdown. Jul 25, 2020 at 23:53
  • 1
    @ctrl-alt-delor: perhaps I was not clear. I am not dealing with a "PC", but with a custom, embedded board where I must handle everything, including telling my "master" I'm actually dead and he can shut down also (cutting my mains). Of course all this is lready handled on "standard hardware", but i didn't find the right hook used to do it properly.
    – ZioByte
    Jul 26, 2020 at 7:02
  • Sorry it was me that was not clear. I realise that you are developing an embedded system. I was drawing an analogy. They are fundamentally the same. However on your system you have to write the code yourself. My comment was an exploration (a case study), of what already exist. It is incomplete, hence I did not submit it as an answer. Have you looked at the code for shutdown and to see what power-supply control drivers already exist? Jul 26, 2020 at 9:55
  • This may be related stackoverflow.com/questions/41596661/… Jul 26, 2020 at 10:06
  • @ctrl-alt-delor: Thanks, I already saw (and upvoted) that question. I also have a tentative solution, but I would like to understand which is the "right way" to handle this.
    – ZioByte
    Jul 26, 2020 at 10:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.