5

我已经成功地使用pm_power_off函数指针使我的自定义 Linux 板通过 i2c 调用其电源管理芯片(关闭电源)。

我也想要 Linuxhalt命令来关闭电源。

我怎样才能做到这一点?

的 (ARM) 代码machine_halt没有类似于machine_power_off's的指针pm_power_off

拱/臂/内核/reboot.c:

/*
 * Halting simply requires that the secondary CPUs stop performing any
 * activity (executing tasks, handling interrupts). smp_send_stop()
 * achieves this.
 */
void machine_halt(void)
{
    local_irq_disable();
    smp_send_stop();

    local_irq_disable();
    while (1);
}

/*
 * Power-off simply requires that the secondary CPUs stop performing any
 * activity (executing tasks, handling interrupts). smp_send_stop()
 * achieves this. When the system power is turned off, it will take all CPUs
 * with it.
 */
void machine_power_off(void)
{
    local_irq_disable();
    smp_send_stop();

    if (pm_power_off)
        pm_power_off();
}

我显然可以 hack machine_halt,但如果可能的话,我想“正确”地做到这一点。

我是否错过了一些可能导致halt命令执行“关机”的东西(可能在用户空间中)?


更新:感谢您的回答和您的所有评论,他们帮助我意识到实际问题是什么。

我的问题是:

我有一个输入边缘,可用于自定义电源管理单元。将其视为启动按钮,没有停止或重置功能。我完全控制了 PMU 代码(它是作为 i2c 从机运行的 ATMEGA)。

  1. 如果 Linux 内核正在运行,我希望忽略边缘。
  2. 如果 CPU 断电,我希望 edge 给 CPU 上电。
  3. 如果 Linux 内核停止,我希望边缘重置 CPU。

案例1很简单,没什么可做的。

案例 2 很简单,pm_power_off在我的驱动程序中定义将 i2c 消息发送到 PMU。pm_power_off幸运的是,i2c 子系统在被调用时仍处于工作状态。

案例 3 是问题 - 我正在寻找一个pm_halt定义,将 i2c 消息发送到 PMU。

也许还有另一种方式,如 0andriy 评论?

内核中是否有一个地方可以用几赫兹的 i2c 消息不断刺激 PMU,除非机器是halted?

答案在:https ://unix.stackexchange.com/a/42576/17288内容如下:

“* 如今,halt 足够聪明,可以在启用 ACPI 时自动调用 poweroff。事实上,它们现在在功能上是等效的。”

也许有一些方法可以提供或连接到 ACPI - 我将不得不阅读它。

4

2 回答 2

2

您应该使用poweroffcommand 或halt -p. 根据man 8 halthalt命令(不带参数)不能保证关闭您的机器。原因在这里描述:

halt在 ACPI 之前使用(今天将为您关闭电源)*。它将停止系统,然后打印一条消息,大意是“现在可以关闭电源”。那时有物理开/关开关,而不是现代计算机的组合 ACPI 控制电源按钮。

*这些天halt很聪明,可以在启用 ACPI 的情况下自动调用 poweroff。事实上,它们现在在功能上是等价的。

halt工具源代码中可以看出,它发出reboot()系统调用,带有cmd = RB_POWER_OFF = LINUX_REBOOT_CMD_POWER_OFF.

在内核中,该系统调用在此处实现,并且在 on 中cmd = LINUX_REBOOT_CMD_POWER_OFF,它调用:
   -> kernel_power_off()
   -> machine_power_off()
   ->pm_power_off()

于 2017-01-11T19:00:50.247 回答
1

在 Debian/Ubuntu 系统上(我不知道在其他 Linux 操作系统中是否可以使用此功能),如果您希望停止命令执行关机,您可以创建此文件:

/etc/default/halt

写下该文件的内容:

# Default behaviour of shutdown -h / halt. Set to "halt" or "poweroff".
HALT=poweroff

正如评论所说,您现在可以设置停止应该如何工作。如果将其设置为停止,它将仅关闭计算机而不关闭电源。如果您设置 poweroff,它将像poweroff命令一样在关闭所有计算机后关闭计算机。

于 2018-11-14T11:58:25.547 回答