powerpc: Convert power off logic to pm_power_off
The generic Linux framework to power off the machine is a function pointer called pm_power_off. The trick about this pointer is that device drivers can potentially implement it rather than board files. Today on powerpc we set pm_power_off to invoke our generic full machine power off logic which then calls ppc_md.power_off to invoke machine specific power off. However, when we want to add a power off GPIO via the "gpio-poweroff" driver, this card house falls apart. That driver only registers itself if pm_power_off is NULL to ensure it doesn't override board specific logic. However, since we always set pm_power_off to the generic power off logic (which will just not power off the machine if no ppc_md.power_off call is implemented), we can't implement power off via the generic GPIO power off driver. To fix this up, let's get rid of the ppc_md.power_off logic and just always use pm_power_off as was intended. Then individual drivers such as the GPIO power off driver can implement power off logic via that function pointer. With this patch set applied and a few patches on top of QEMU that implement a power off GPIO on the virt e500 machine, I can successfully turn off my virtual machine after halt. Signed-off-by: Alexander Graf <agraf@suse.de> [mpe: Squash into one patch and update changelog based on cover letter] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:

committed by
Michael Ellerman

parent
0df1f2487d
commit
9178ba294b
@@ -659,6 +659,34 @@ static void __init pSeries_init_early(void)
|
||||
pr_debug(" <- pSeries_init_early()\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* pseries_power_off - tell firmware about how to power off the system.
|
||||
*
|
||||
* This function calls either the power-off rtas token in normal cases
|
||||
* or the ibm,power-off-ups token (if present & requested) in case of
|
||||
* a power failure. If power-off token is used, power on will only be
|
||||
* possible with power button press. If ibm,power-off-ups token is used
|
||||
* it will allow auto poweron after power is restored.
|
||||
*/
|
||||
static void pseries_power_off(void)
|
||||
{
|
||||
int rc;
|
||||
int rtas_poweroff_ups_token = rtas_token("ibm,power-off-ups");
|
||||
|
||||
if (rtas_flash_term_hook)
|
||||
rtas_flash_term_hook(SYS_POWER_OFF);
|
||||
|
||||
if (rtas_poweron_auto == 0 ||
|
||||
rtas_poweroff_ups_token == RTAS_UNKNOWN_SERVICE) {
|
||||
rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
|
||||
printk(KERN_INFO "RTAS power-off returned %d\n", rc);
|
||||
} else {
|
||||
rc = rtas_call(rtas_poweroff_ups_token, 0, 1, NULL);
|
||||
printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
|
||||
}
|
||||
for (;;);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called very early, MMU is off, device-tree isn't unflattened
|
||||
*/
|
||||
@@ -741,6 +769,8 @@ static int __init pSeries_probe(void)
|
||||
else
|
||||
hpte_init_native();
|
||||
|
||||
pm_power_off = pseries_power_off;
|
||||
|
||||
pr_debug("Machine is%s LPAR !\n",
|
||||
(powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");
|
||||
|
||||
@@ -754,34 +784,6 @@ static int pSeries_pci_probe_mode(struct pci_bus *bus)
|
||||
return PCI_PROBE_NORMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* pSeries_power_off - tell firmware about how to power off the system.
|
||||
*
|
||||
* This function calls either the power-off rtas token in normal cases
|
||||
* or the ibm,power-off-ups token (if present & requested) in case of
|
||||
* a power failure. If power-off token is used, power on will only be
|
||||
* possible with power button press. If ibm,power-off-ups token is used
|
||||
* it will allow auto poweron after power is restored.
|
||||
*/
|
||||
static void pSeries_power_off(void)
|
||||
{
|
||||
int rc;
|
||||
int rtas_poweroff_ups_token = rtas_token("ibm,power-off-ups");
|
||||
|
||||
if (rtas_flash_term_hook)
|
||||
rtas_flash_term_hook(SYS_POWER_OFF);
|
||||
|
||||
if (rtas_poweron_auto == 0 ||
|
||||
rtas_poweroff_ups_token == RTAS_UNKNOWN_SERVICE) {
|
||||
rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
|
||||
printk(KERN_INFO "RTAS power-off returned %d\n", rc);
|
||||
} else {
|
||||
rc = rtas_call(rtas_poweroff_ups_token, 0, 1, NULL);
|
||||
printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
|
||||
}
|
||||
for (;;);
|
||||
}
|
||||
|
||||
#ifndef CONFIG_PCI
|
||||
void pSeries_final_fixup(void) { }
|
||||
#endif
|
||||
@@ -796,7 +798,6 @@ define_machine(pseries) {
|
||||
.pcibios_fixup = pSeries_final_fixup,
|
||||
.pci_probe_mode = pSeries_pci_probe_mode,
|
||||
.restart = rtas_restart,
|
||||
.power_off = pSeries_power_off,
|
||||
.halt = rtas_halt,
|
||||
.panic = rtas_os_term,
|
||||
.get_boot_time = rtas_get_boot_time,
|
||||
|
Reference in New Issue
Block a user