Skip to contentSkip to conversation

powerpc: Convert power off logic to pm_power_off

PATCH In review Alexander Graf 2 participants 23 messages Oct 13, 2014

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

v2 cover 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.

Michael / Ben, you can find this patch set as a git branch at the URL below. When applying it, please use that one to ensure that Guenter can easily merge his work with my work.

git://github.com/agraf/linux-2.6.git pm_power_off-v2

Alex

---

v1 -> v2:

- fix typo in 47x
- put ppc_md static replacement setters into probe function

Alexander Graf (20):
powerpc: Support override of pm_power_off
powerpc/xmon: Support either ppc_md.power_off or pm_power_off powerpc/47x: Use pm_power_off rather than ppc_md.power_off powerpc/52xx/efika: Use pm_power_off rather than ppc_md.power_off powerpc/mpc8349emitx: Use pm_power_off rather than ppc_md.power_off powerpc/corenet: Use pm_power_off rather than ppc_md.power_off powerpc/85xx/sgy_cts1000: Use pm_power_off rather than
ppc_md.power_off
powerpc/celleb: Use pm_power_off rather than ppc_md.power_off powerpc/cell/qpace: Use pm_power_off rather than ppc_md.power_off powerpc/cell: Use pm_power_off rather than ppc_md.power_off powerpc/chrp: Use pm_power_off rather than ppc_md.power_off powerpc/6xx/gamecube: Use pm_power_off rather than ppc_md.power_off powerpc/6xx/linkstation: Use pm_power_off rather than ppc_md.power_off powerpc/6xx/wii: Use pm_power_off rather than ppc_md.power_off powerpc/maple: Use pm_power_off rather than ppc_md.power_off powerpc/powermac: Use pm_power_off rather than ppc_md.power_off powerpc/powernv: Use pm_power_off rather than ppc_md.power_off powerpc/ps3: Use pm_power_off rather than ppc_md.power_off powerpc/pseries: Use pm_power_off rather than ppc_md.power_off
powerpc: Remove ppc_md.power_off

 arch/powerpc/include/asm/machdep.h               |   1 -
 arch/powerpc/kernel/setup-common.c               |   6 +-
 arch/powerpc/platforms/44x/ppc476.c              |   2 +-
 arch/powerpc/platforms/52xx/efika.c              |   3 +-
 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c   |   8 +-
 arch/powerpc/platforms/85xx/corenet_generic.c    |   2 +-
 arch/powerpc/platforms/85xx/sgy_cts1000.c        |   4 +-
 arch/powerpc/platforms/cell/celleb_setup.c       |   4 +-
 arch/powerpc/platforms/cell/qpace_setup.c        |   2 +-
 arch/powerpc/platforms/cell/setup.c              |   2 +-
 arch/powerpc/platforms/chrp/setup.c              |   3 +-
 arch/powerpc/platforms/embedded6xx/gamecube.c    |   3 +-
 arch/powerpc/platforms/embedded6xx/linkstation.c |   4 +-
 arch/powerpc/platforms/embedded6xx/wii.c         |   3 +-
 arch/powerpc/platforms/maple/setup.c             |   4 +-
 arch/powerpc/platforms/powermac/setup.c          | 147 ++++++++++++-----------
 arch/powerpc/platforms/powernv/setup.c           |   4 +-
 arch/powerpc/platforms/ps3/setup.c               |   2 +-
 arch/powerpc/platforms/pseries/setup.c           |  59 ++++-----
 arch/powerpc/sysdev/fsl_soc.c                    |   2 +-
 arch/powerpc/xmon/xmon.c                         |   3 +-
 21 files changed, 138 insertions(+), 130 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v2 1/20 powerpc: Support override of pm_power_off

The pm_power_off callback is what drivers are supposed to modify when they implement power off support for the system.

Support a modified callback on powerpc. That way power off support code can now either override ppc_md.power_off or pm_power_off.

---
 arch/powerpc/kernel/setup-common.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/kernel/setup-common.c +2 -0
index 1362cd6..6398239 100644
@@ -141,6 +141,8 @@ void machine_power_off(void)
 	machine_shutdown();
 	if (ppc_md.power_off)
 		ppc_md.power_off();
+	if (pm_power_off != machine_power_off)
+		pm_power_off();
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v2 2/20 powerpc/xmon: Support either ppc_md.power_off or pm_power_off

In reply to Alexander Graf

Xmon can manually turn off the machine. We now have 2 code paths for this:

1) ppc_md.power_off
2) pm_power_off

This patch allows xmon to support both and makes sure it graciously allows a path to not be implemented.

---
 arch/powerpc/xmon/xmon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/xmon/xmon.c +4 -1
index b988b5a..531f649 100644
@@ -981,7 +981,10 @@ static void bootcmds(void)
 	else if (cmd == 'h')
 		ppc_md.halt();
 	else if (cmd == 'p')
-		ppc_md.power_off();
+		if (ppc_md.power_off)
+			ppc_md.power_off();
+		if (pm_power_off)
+			pm_power_off();
 }
 
 static int cpu_cmd(void)
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH v2 3/20 powerpc/47x: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- fix typo

---
 arch/powerpc/platforms/44x/ppc476.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/44x/ppc476.c +1 -1
index 58db9d0..c11ce65 100644
@@ -94,7 +94,7 @@ static int avr_probe(struct i2c_client *client,
 {
 	avr_i2c_client = client;
 	ppc_md.restart = avr_reset_system;
-	ppc_md.power_off = avr_power_off_system;
+	pm_power_off = avr_power_off_system;
 	return 0;
 }
 
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH v2 4/20 powerpc/52xx/efika: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/52xx/efika.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/52xx/efika.c +2 -1
index 3feffde..6af651e 100644
@@ -212,6 +212,8 @@ static int __init efika_probe(void)
 	DMA_MODE_READ = 0x44;
 	DMA_MODE_WRITE = 0x48;
 
+	pm_power_off = rtas_power_off;
+
 	return 1;
 }
 
@@ -225,7 +227,6 @@ define_machine(efika)
 	.init_IRQ		= mpc52xx_init_irq,
 	.get_irq		= mpc52xx_get_irq,
 	.restart		= rtas_restart,
-	.power_off		= rtas_power_off,
 	.halt			= rtas_halt,
 	.set_rtc_time		= rtas_set_rtc_time,
 	.get_rtc_time		= rtas_get_rtc_time,
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH v2 5/20 powerpc/mpc8349emitx: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---
 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +4 -4
index 463fa91e..15e8021 100644
@@ -167,10 +167,10 @@ static int mcu_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	if (ret)
 		goto err;
 
-	/* XXX: this is potentially racy, but there is no lock for ppc_md */
-	if (!ppc_md.power_off) {
+	/* XXX: this is potentially racy, but there is no lock for pm_power_off */
+	if (!pm_power_off) {
 		glob_mcu = mcu;
-		ppc_md.power_off = mcu_power_off;
+		pm_power_off = mcu_power_off;
 		dev_info(&client->dev, "will provide power-off service\n");
 	}
 
@@ -197,7 +197,7 @@ static int mcu_remove(struct i2c_client *client)
 	device_remove_file(&client->dev, &dev_attr_status);
 
 	if (glob_mcu == mcu) {
-		ppc_md.power_off = NULL;
+		pm_power_off = NULL;
 		glob_mcu = NULL;
 	}
 
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH v2 6/20 powerpc/corenet: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---
 arch/powerpc/platforms/85xx/corenet_generic.c | 2 +-
 arch/powerpc/sysdev/fsl_soc.c                 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/85xx/corenet_generic.c +1 -1
index e56b89a..1f309cc 100644
@@ -170,7 +170,7 @@ static int __init corenet_generic_probe(void)
 
 			ppc_md.get_irq = ehv_pic_get_irq;
 			ppc_md.restart = fsl_hv_restart;
-			ppc_md.power_off = fsl_hv_halt;
+			pm_power_off = fsl_hv_halt;
 			ppc_md.halt = fsl_hv_halt;
 #ifdef CONFIG_SMP
 			/*
arch/powerpc/sysdev/fsl_soc.c +1 -1
index ffd1169..1e04568 100644
@@ -238,7 +238,7 @@ void fsl_hv_restart(char *cmd)
 /*
  * Halt the current partition
  *
- * This function should be assigned to the ppc_md.power_off and ppc_md.halt
+ * This function should be assigned to the pm_power_off and ppc_md.halt
  * function pointers, to shut down the partition when we're running under
  * the Freescale hypervisor.
  */
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH v2 7/20 powerpc/85xx/sgy_cts1000: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---
 arch/powerpc/platforms/85xx/sgy_cts1000.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/85xx/sgy_cts1000.c +2 -2
index 8162b04..e149c9e 100644
@@ -120,7 +120,7 @@ static int gpio_halt_probe(struct platform_device *pdev)
 
 	/* Register our halt function */
 	ppc_md.halt = gpio_halt_cb;
-	ppc_md.power_off = gpio_halt_cb;
+	pm_power_off = gpio_halt_cb;
 
 	printk(KERN_INFO "gpio-halt: registered GPIO %d (%d trigger, %d"
 	       " irq).\n", gpio, trigger, irq);
@@ -137,7 +137,7 @@ static int gpio_halt_remove(struct platform_device *pdev)
 		free_irq(irq, halt_node);
 
 		ppc_md.halt = NULL;
-		ppc_md.power_off = NULL;
+		pm_power_off = NULL;
 
 		gpio_free(gpio);
 
Signature · 1 line
1.8.1.4
#8 lore raw

PATCH v2 8/20 powerpc/celleb: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/cell/celleb_setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/cell/celleb_setup.c +2 -2
index 34e8ce2..90be8ec 100644
@@ -142,6 +142,7 @@ static int __init celleb_probe_beat(void)
 	powerpc_firmware_features |= FW_FEATURE_CELLEB_ALWAYS
 		| FW_FEATURE_BEAT | FW_FEATURE_LPAR;
 	hpte_init_beat_v3();
+	pm_power_off = beat_power_off;
 
 	return 1;
 }
@@ -190,6 +191,7 @@ static int __init celleb_probe_native(void)
 
 	powerpc_firmware_features |= FW_FEATURE_CELLEB_ALWAYS;
 	hpte_init_native();
+	pm_power_off = rtas_power_off;
 
 	return 1;
 }
@@ -204,7 +206,6 @@ define_machine(celleb_beat) {
 	.setup_arch		= celleb_setup_arch_beat,
 	.show_cpuinfo		= celleb_show_cpuinfo,
 	.restart		= beat_restart,
-	.power_off		= beat_power_off,
 	.halt			= beat_halt,
 	.get_rtc_time		= beat_get_rtc_time,
 	.set_rtc_time		= beat_set_rtc_time,
@@ -230,7 +231,6 @@ define_machine(celleb_native) {
 	.setup_arch		= celleb_setup_arch_native,
 	.show_cpuinfo		= celleb_show_cpuinfo,
 	.restart		= rtas_restart,
-	.power_off		= rtas_power_off,
 	.halt			= rtas_halt,
 	.get_boot_time		= rtas_get_boot_time,
 	.get_rtc_time		= rtas_get_rtc_time,
Signature · 1 line
1.8.1.4
#9 lore raw

PATCH v2 9/20 powerpc/cell/qpace: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/cell/qpace_setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/cell/qpace_setup.c +1 -1
index 6e3409d..d328140 100644
@@ -127,6 +127,7 @@ static int __init qpace_probe(void)
 		return 0;
 
 	hpte_init_native();
+	pm_power_off = rtas_power_off;
 
 	return 1;
 }
@@ -137,7 +138,6 @@ define_machine(qpace) {
 	.setup_arch		= qpace_setup_arch,
 	.show_cpuinfo		= qpace_show_cpuinfo,
 	.restart		= rtas_restart,
-	.power_off		= rtas_power_off,
 	.halt			= rtas_halt,
 	.get_boot_time		= rtas_get_boot_time,
 	.get_rtc_time		= rtas_get_rtc_time,
Signature · 1 line
1.8.1.4
#10 lore raw

PATCH v2 10/20 powerpc/cell: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/cell/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/cell/setup.c +1 -1
index 6ae25fb..d62aa98 100644
@@ -259,6 +259,7 @@ static int __init cell_probe(void)
 		return 0;
 
 	hpte_init_native();
+	pm_power_off = rtas_power_off;
 
 	return 1;
 }
@@ -269,7 +270,6 @@ define_machine(cell) {
 	.setup_arch		= cell_setup_arch,
 	.show_cpuinfo		= cell_show_cpuinfo,
 	.restart		= rtas_restart,
-	.power_off		= rtas_power_off,
 	.halt			= rtas_halt,
 	.get_boot_time		= rtas_get_boot_time,
 	.get_rtc_time		= rtas_get_rtc_time,
Signature · 1 line
1.8.1.4
#11 lore raw

PATCH v2 11/20 powerpc/chrp: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/chrp/setup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/chrp/setup.c +2 -1
index 5b77b19..dbe7d16 100644
@@ -585,6 +585,8 @@ static int __init chrp_probe(void)
 	DMA_MODE_READ = 0x44;
 	DMA_MODE_WRITE = 0x48;
 
+	pm_power_off = rtas_power_off,
+
 	return 1;
 }
 
@@ -597,7 +599,6 @@ define_machine(chrp) {
 	.show_cpuinfo		= chrp_show_cpuinfo,
 	.init_IRQ		= chrp_init_IRQ,
 	.restart		= rtas_restart,
-	.power_off		= rtas_power_off,
 	.halt			= rtas_halt,
 	.time_init		= chrp_time_init,
 	.set_rtc_time		= chrp_set_rtc_time,
Signature · 1 line
1.8.1.4
#12 lore raw

PATCH v2 12/20 powerpc/6xx/gamecube: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---
 arch/powerpc/platforms/embedded6xx/gamecube.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/embedded6xx/gamecube.c +2 -1
index bd4ba5d..fe0ed6e 100644
@@ -67,6 +67,8 @@ static int __init gamecube_probe(void)
 	if (!of_flat_dt_is_compatible(dt_root, "nintendo,gamecube"))
 		return 0;
 
+	pm_power_off = gamecube_power_off;
+
 	return 1;
 }
 
@@ -80,7 +82,6 @@ define_machine(gamecube) {
 	.probe			= gamecube_probe,
 	.init_early		= gamecube_init_early,
 	.restart		= gamecube_restart,
-	.power_off		= gamecube_power_off,
 	.halt			= gamecube_halt,
 	.init_IRQ		= flipper_pic_probe,
 	.get_irq		= flipper_pic_get_irq,
Signature · 1 line
1.8.1.4
#13 lore raw

PATCH v2 13/20 powerpc/6xx/linkstation: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/embedded6xx/linkstation.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/platforms/embedded6xx/linkstation.c +3 -1
index 168e1d8..540eeb5 100644
@@ -147,6 +147,9 @@ static int __init linkstation_probe(void)
 
 	if (!of_flat_dt_is_compatible(root, "linkstation"))
 		return 0;
+
+	pm_power_off = linkstation_power_off;
+
 	return 1;
 }
 
@@ -158,7 +161,6 @@ define_machine(linkstation){
 	.show_cpuinfo 		= linkstation_show_cpuinfo,
 	.get_irq 		= mpic_get_irq,
 	.restart 		= linkstation_restart,
-	.power_off 		= linkstation_power_off,
 	.halt	 		= linkstation_halt,
 	.calibrate_decr 	= generic_calibrate_decr,
 };
Signature · 1 line
1.8.1.4
#14 lore raw

PATCH v2 14/20 powerpc/6xx/wii: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/embedded6xx/wii.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/embedded6xx/wii.c +2 -1
index 388e29b..352592d 100644
@@ -211,6 +211,8 @@ static int __init wii_probe(void)
 	if (!of_flat_dt_is_compatible(dt_root, "nintendo,wii"))
 		return 0;
 
+	pm_power_off = wii_power_off;
+
 	return 1;
 }
 
@@ -226,7 +228,6 @@ define_machine(wii) {
 	.init_early		= wii_init_early,
 	.setup_arch		= wii_setup_arch,
 	.restart		= wii_restart,
-	.power_off		= wii_power_off,
 	.halt			= wii_halt,
 	.init_IRQ		= wii_pic_probe,
 	.get_irq		= flipper_pic_get_irq,
Signature · 1 line
1.8.1.4
#15 lore raw

PATCH v2 15/20 powerpc/maple: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/maple/setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/maple/setup.c +2 -2
index cb1b0b3..56b85cd 100644
@@ -169,7 +169,7 @@ static void __init maple_use_rtas_reboot_and_halt_if_present(void)
 	if (rtas_service_present("system-reboot") &&
 	    rtas_service_present("power-off")) {
 		ppc_md.restart = rtas_restart;
-		ppc_md.power_off = rtas_power_off;
+		pm_power_off = rtas_power_off;
 		ppc_md.halt = rtas_halt;
 	}
 }
@@ -312,6 +312,7 @@ static int __init maple_probe(void)
 	alloc_dart_table();
 
 	hpte_init_native();
+	pm_power_off = maple_power_off;
 
 	return 1;
 }
@@ -325,7 +326,6 @@ define_machine(maple) {
 	.pci_irq_fixup		= maple_pci_irq_fixup,
 	.pci_get_legacy_ide_irq	= maple_pci_get_legacy_ide_irq,
 	.restart		= maple_restart,
-	.power_off		= maple_power_off,
 	.halt			= maple_halt,
        	.get_boot_time		= maple_get_boot_time,
        	.set_rtc_time		= maple_set_rtc_time,
Signature · 1 line
1.8.1.4
#16 lore raw

PATCH v2 16/20 powerpc/powermac: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/powermac/setup.c | 147 ++++++++++++++++----------------
 1 file changed, 74 insertions(+), 73 deletions(-)
arch/powerpc/platforms/powermac/setup.c +74 -73
index b127a29..1b03bc1 100644
@@ -274,6 +274,78 @@ static void __init l2cr_init(void)
 }
 #endif
 
+#ifdef CONFIG_ADB_CUDA
+static void cuda_restart(void)
+{
+	struct adb_request req;
+
+	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
+	for (;;)
+		cuda_poll();
+}
+
+static void cuda_shutdown(void)
+{
+	struct adb_request req;
+
+	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
+	for (;;)
+		cuda_poll();
+}
+
+#else
+#define cuda_restart()
+#define cuda_shutdown()
+#endif
+
+#ifndef CONFIG_ADB_PMU
+#define pmu_restart()
+#define pmu_shutdown()
+#endif
+
+#ifndef CONFIG_PMAC_SMU
+#define smu_restart()
+#define smu_shutdown()
+#endif
+
+static void pmac_restart(char *cmd)
+{
+	switch (sys_ctrler) {
+	case SYS_CTRLER_CUDA:
+		cuda_restart();
+		break;
+	case SYS_CTRLER_PMU:
+		pmu_restart();
+		break;
+	case SYS_CTRLER_SMU:
+		smu_restart();
+		break;
+	default: ;
+	}
+}
+
+static void pmac_power_off(void)
+{
+	switch (sys_ctrler) {
+	case SYS_CTRLER_CUDA:
+		cuda_shutdown();
+		break;
+	case SYS_CTRLER_PMU:
+		pmu_shutdown();
+		break;
+	case SYS_CTRLER_SMU:
+		smu_shutdown();
+		break;
+	default: ;
+	}
+}
+
+static void
+pmac_halt(void)
+{
+	pmac_power_off();
+}
+
 static void __init pmac_setup_arch(void)
 {
 	struct device_node *cpu, *ic;
@@ -382,78 +454,6 @@ void __init_refok note_bootable_part(dev_t dev, int part, int goodness)
 	current_root_goodness = goodness;
 }
 
-#ifdef CONFIG_ADB_CUDA
-static void cuda_restart(void)
-{
-	struct adb_request req;
-
-	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
-	for (;;)
-		cuda_poll();
-}
-
-static void cuda_shutdown(void)
-{
-	struct adb_request req;
-
-	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
-	for (;;)
-		cuda_poll();
-}
-
-#else
-#define cuda_restart()
-#define cuda_shutdown()
-#endif
-
-#ifndef CONFIG_ADB_PMU
-#define pmu_restart()
-#define pmu_shutdown()
-#endif
-
-#ifndef CONFIG_PMAC_SMU
-#define smu_restart()
-#define smu_shutdown()
-#endif
-
-static void pmac_restart(char *cmd)
-{
-	switch (sys_ctrler) {
-	case SYS_CTRLER_CUDA:
-		cuda_restart();
-		break;
-	case SYS_CTRLER_PMU:
-		pmu_restart();
-		break;
-	case SYS_CTRLER_SMU:
-		smu_restart();
-		break;
-	default: ;
-	}
-}
-
-static void pmac_power_off(void)
-{
-	switch (sys_ctrler) {
-	case SYS_CTRLER_CUDA:
-		cuda_shutdown();
-		break;
-	case SYS_CTRLER_PMU:
-		pmu_shutdown();
-		break;
-	case SYS_CTRLER_SMU:
-		smu_shutdown();
-		break;
-	default: ;
-	}
-}
-
-static void
-pmac_halt(void)
-{
-	pmac_power_off();
-}
-
 /* 
  * Early initialization.
  */
@@ -632,6 +632,8 @@ static int __init pmac_probe(void)
 	smu_cmdbuf_abs = memblock_alloc_base(4096, 4096, 0x80000000UL);
 #endif /* CONFIG_PMAC_SMU */
 
+	pm_power_off = pmac_power_off;
+
 	return 1;
 }
 
@@ -663,7 +665,6 @@ define_machine(powermac) {
 	.get_irq		= NULL,	/* changed later */
 	.pci_irq_fixup		= pmac_pci_irq_fixup,
 	.restart		= pmac_restart,
-	.power_off		= pmac_power_off,
 	.halt			= pmac_halt,
 	.time_init		= pmac_time_init,
 	.get_boot_time		= pmac_get_boot_time,
Signature · 1 line
1.8.1.4
#17 lore raw

PATCH v2 17/20 powerpc/powernv: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---
 arch/powerpc/platforms/powernv/setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/setup.c +2 -2
index 3f9546d..941831d 100644
@@ -268,7 +268,7 @@ static void __init pnv_setup_machdep_opal(void)
 	ppc_md.get_rtc_time = opal_get_rtc_time;
 	ppc_md.set_rtc_time = opal_set_rtc_time;
 	ppc_md.restart = pnv_restart;
-	ppc_md.power_off = pnv_power_off;
+	pm_power_off = pnv_power_off;
 	ppc_md.halt = pnv_halt;
 	ppc_md.machine_check_exception = opal_machine_check;
 	ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery;
@@ -285,7 +285,7 @@ static void __init pnv_setup_machdep_rtas(void)
 		ppc_md.set_rtc_time = rtas_set_rtc_time;
 	}
 	ppc_md.restart = rtas_restart;
-	ppc_md.power_off = rtas_power_off;
+	pm_power_off = rtas_power_off;
 	ppc_md.halt = rtas_halt;
 }
 #endif /* CONFIG_PPC_POWERNV_RTAS */
Signature · 1 line
1.8.1.4
#18 lore raw

PATCH v2 18/20 powerpc/ps3: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/ps3/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/ps3/setup.c +1 -1
index 3f509f8..009a200 100644
@@ -248,6 +248,7 @@ static int __init ps3_probe(void)
 	ps3_mm_init();
 	ps3_mm_vas_create(&htab_size);
 	ps3_hpte_init(htab_size);
+	pm_power_off = ps3_power_off;
 
 	DBG(" <- %s:%d\n", __func__, __LINE__);
 	return 1;
@@ -278,7 +279,6 @@ define_machine(ps3) {
 	.calibrate_decr			= ps3_calibrate_decr,
 	.progress			= ps3_progress,
 	.restart			= ps3_restart,
-	.power_off			= ps3_power_off,
 	.halt				= ps3_halt,
 #if defined(CONFIG_KEXEC)
 	.kexec_cpu_down			= ps3_kexec_cpu_down,
Signature · 1 line
1.8.1.4
#19 lore raw

PATCH v2 19/20 powerpc/pseries: Use pm_power_off rather than ppc_md.power_off

In reply to Alexander Graf

The generic power off callback is pm_power_off. Use that one rather than the powerpc specific ppc_md.power_off.

---

v1 -> v2:

- write pm_power_off in probe function

---
 arch/powerpc/platforms/pseries/setup.c | 59 +++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 29 deletions(-)
arch/powerpc/platforms/pseries/setup.c +30 -29
index 125c589..9ce1cf0 100644
@@ -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,
Signature · 1 line
1.8.1.4
#20 lore raw

PATCH v2 20/20 powerpc: Remove ppc_md.power_off

In reply to Alexander Graf

Now that we have all implementations of ppc_md.power_off converted to pm_power_off we can remove the ppc_md variant.

While at it, also set the default for pm_power_off to NULL so that non machine drivers can implement overrides.

---
 arch/powerpc/include/asm/machdep.h | 1 -
 arch/powerpc/kernel/setup-common.c | 6 ++----
 arch/powerpc/xmon/xmon.c           | 2 --
 3 files changed, 2 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/machdep.h +0 -1
index 307347f..f15f15c 100644
@@ -142,7 +142,6 @@ struct machdep_calls {
 #endif
 
 	void		(*restart)(char *cmd);
-	void		(*power_off)(void);
 	void		(*halt)(void);
 	void		(*panic)(char *str);
 	void		(*cpu_die)(void);
arch/powerpc/kernel/setup-common.c +2 -4
index 6398239..44c8d03 100644
@@ -139,9 +139,7 @@ void machine_restart(char *cmd)
 void machine_power_off(void)
 {
 	machine_shutdown();
-	if (ppc_md.power_off)
-		ppc_md.power_off();
-	if (pm_power_off != machine_power_off)
+	if (pm_power_off)
 		pm_power_off();
 #ifdef CONFIG_SMP
 	smp_send_stop();
@@ -153,7 +151,7 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
+void (*pm_power_off)(void);
 EXPORT_SYMBOL_GPL(pm_power_off);
 
 void machine_halt(void)
arch/powerpc/xmon/xmon.c +0 -2
index 531f649..506d256 100644
@@ -981,8 +981,6 @@ static void bootcmds(void)
 	else if (cmd == 'h')
 		ppc_md.halt();
 	else if (cmd == 'p')
-		if (ppc_md.power_off)
-			ppc_md.power_off();
 		if (pm_power_off)
 			pm_power_off();
 }
Signature · 1 line
1.8.1.4
#21 lore raw
In reply to Alexander Graf
Quoted 23 lines · Alexander Graf

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.

Quoted 6 lines

Michael / Ben, you can find this patch set as a git branch at the URL below. When applying it, please use that one to ensure that Guenter can easily merge his work with my work.

   git://github.com/agraf/linux-2.6.git pm_power_off-v2

Best for me would be if someone (you or Ben or Michael) could create an immutable branch which contains the patch set as to be submitted to Linus, with all signatures, so I can merge it into my poweroff branch. If possible that branch should have a signed tag which I can merge, to ensure that I don't merge anything bad.

If I just merge your branch, I would not get the maintainer signature(s), nor would it have the final SHA. Both would obviously be less than desirable.

Thanks,
Guenter

#22 lore raw
In reply to Alexander Graf
Quoted 52 lines · Alexander Graf

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.

Michael / Ben, you can find this patch set as a git branch at the URL below. When applying it, please use that one to ensure that Guenter can easily merge his work with my work.

   git://github.com/agraf/linux-2.6.git pm_power_off-v2

Alex

---

v1 -> v2:

- fix typo in 47x
- put ppc_md static replacement setters into probe function

Alexander Graf (20):
powerpc: Support override of pm_power_off
powerpc/xmon: Support either ppc_md.power_off or pm_power_off powerpc/47x: Use pm_power_off rather than ppc_md.power_off powerpc/52xx/efika: Use pm_power_off rather than ppc_md.power_off powerpc/mpc8349emitx: Use pm_power_off rather than ppc_md.power_off powerpc/corenet: Use pm_power_off rather than ppc_md.power_off powerpc/85xx/sgy_cts1000: Use pm_power_off rather than
ppc_md.power_off
powerpc/celleb: Use pm_power_off rather than ppc_md.power_off powerpc/cell/qpace: Use pm_power_off rather than ppc_md.power_off powerpc/cell: Use pm_power_off rather than ppc_md.power_off powerpc/chrp: Use pm_power_off rather than ppc_md.power_off powerpc/6xx/gamecube: Use pm_power_off rather than ppc_md.power_off

Quoted 9 lines

powerpc/6xx/linkstation: Use pm_power_off rather than ppc_md.power_off powerpc/6xx/wii: Use pm_power_off rather than ppc_md.power_off powerpc/maple: Use pm_power_off rather than ppc_md.power_off powerpc/powermac: Use pm_power_off rather than ppc_md.power_off powerpc/powernv: Use pm_power_off rather than ppc_md.power_off powerpc/ps3: Use pm_power_off rather than ppc_md.power_off powerpc/pseries: Use pm_power_off rather than ppc_md.power_off
powerpc: Remove ppc_md.power_off

On another note, and maybe you discussed this separately: I don't really see the value of having 20 separate patches here, other than creating a lot of work for the maintainer. Wouldn't it be easier
to just have one patch instead ?

Sure, it would touch 20+ files instead of just one, but then you could drop some of the workarounds you have to put in place just to undo it at the end, and it is not as if the patches are really independent of each other or as if there would be any benefit in respect to the ability to bisect or merge into earlier versions of the kernel.

I for my part don't plan for 20 patches when I convert it to use the poweroff handler. Hope it is ok with everyone that it will be just one patch.

Thanks,
Guenter