Skip to contentSkip to conversation

Enabling Auto poweron after power is restored.

PATCH In review Manish Ahuja 7 participants 22 messages Dec 1, 2006 – Feb 8, 2007 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enabling Auto poweron after power is restored.

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to poweron when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

Resending this email as earlier attempts failed.

arch/powerpc/kernel/rtas.c +22 -3
Index: 2.6-git2/arch/powerpc/kernel/rtas.c
===================================================================
@@ -603,11 +603,30 @@
 
 void rtas_power_off(void)
 {
+	int rc = 0;
+	int rtas_poweron_auto_token;
+
 	if (rtas_flash_term_hook)
 		rtas_flash_term_hook(SYS_POWER_OFF);
-	/* allow power on only with power button press */
-	printk("RTAS power-off returned %d\n",
-	       rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
+
+	if (rtas_poweron_auto == 0) {
+		/* allow power on only with power button press */
+		printk(KERN_INFO "RTAS power-off returned %d\n",
+			rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
+	} else {
+		rtas_poweron_auto_token = rtas_token("ibm,power-off-ups");
+
+		if (rtas_poweron_auto_token == RTAS_UNKNOWN_SERVICE) {
+			/* ibm,power-off-ups failed or token does not exist */
+			rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
+	 		printk(KERN_EMERG "Power-off called instead %d\n", rc );
+		} else {
+			/* Enable the system to reboot if power comes back on */
+			rc = rtas_call(rtas_token("ibm,power-off-ups"), 0, 1, NULL);
+			printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
+		}
+
+	}
 	for (;;);
 }
 
arch/powerpc/kernel/rtas-proc.c +41 -0

68 lines not on this page · raw message

include/asm-powerpc/rtas.h +3 -0
Index: 2.6-git2/include/asm-powerpc/rtas.h
===================================================================
@@ -228,6 +228,9 @@
 /* RMO buffer reserved for user-space RTAS use */
 extern unsigned long rtas_rmo_buf;
 
+/* Poweron buffer used for enabling auto ups restart */
+extern unsigned long rtas_poweron_auto;
+
 #define GLOBAL_INTERRUPT_QUEUE 9005
 
 /**
#1 lore raw
Quoted 21 lines · Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to poweron when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

plain text document attachment (power-off-ups.patch)
Index: 2.6-git2/arch/powerpc/kernel/rtas.c
===================================================================

arch/powerpc/kernel/rtas.c +1 -0
@@ -603,11 +603,30 @@
 
 void rtas_power_off(void)
 {
+	int rc = 0;

arch/powerpc/kernel/rtas.c line 613

Quoted 10 lines
arch/powerpc/kernel/rtas.c +5 -3
+	int rtas_poweron_auto_token;
+
 	if (rtas_flash_term_hook)
 		rtas_flash_term_hook(SYS_POWER_OFF);
-	/* allow power on only with power button press */
-	printk("RTAS power-off returned %d\n",
-	       rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
+
+	if (rtas_poweron_auto == 0) {
+		/* allow power on only with power button press */

I expect someone will agree or strongly disagree with me here on cosmetics.. :-) I'd be tempted to pull the one-liner comments out of the code and replace them with a short paragraph above the function name.

And..
Do we have a preference for "(rtas_poweron_auto == 0)" versus "(!rtas_poweron_auto)"
notation? rtas.c has some of each, so I'm not sure.

Quoted 4 lines
arch/powerpc/kernel/rtas.c +4 -0
+		printk(KERN_INFO "RTAS power-off returned %d\n",
+			rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
+	} else {
+		rtas_poweron_auto_token = rtas_token("ibm,power-off-ups");

arch/powerpc/kernel/rtas.c line 627

Quoted 10 lines
arch/powerpc/kernel/rtas.c +10 -0
+
+		if (rtas_poweron_auto_token == RTAS_UNKNOWN_SERVICE) {
+			/* ibm,power-off-ups failed or token does not exist */
+			rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
+	 		printk(KERN_EMERG "Power-off called instead %d\n", rc );
+		} else {
+			/* Enable the system to reboot if power comes back on */
+			rc = rtas_call(rtas_token("ibm,power-off-ups"), 0, 1, NULL);
+			printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
+		}

You could eliminate the temp variable rtas_poweron_auto_token, and rewrite as something like:

               if (rtas_token("ibm,power-off-ups") == RTAS_UNKNOWN_SERVICE) {
                       rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
                       printk(KERN_EMERG "Power-off called instead %d\n", rc );
               } else {
                       rc = rtas_call(rtas_token("ibm,power-off-ups"),0, 1, NULL);
                       printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
               }

arch/powerpc/kernel/rtas.c line 631

Quoted 4 lines
arch/powerpc/kernel/rtas.c +2 -0
+
+	}
 	for (;;);
 }

<snippage>

arch/powerpc/kernel/rtas.c

Quoted 10 lines
arch/powerpc/kernel/rtas.c +10 -0
+static ssize_t ppc_rtas_poweron_auto_write(struct file *file,
+		const char __user *buf, size_t count, loff_t *ppos)
+{
+	unsigned long ups_restart;
+	int error = parse_number(buf, count, &ups_restart);
+	if (error)
+		return error;
+
+	if (ups_restart != 0)
+		rtas_poweron_auto = 1;

the !=0 is redundant here.. just "if (ups_restart) " should be sufficient.

Quoted 9 lines
arch/powerpc/kernel/rtas.c +3 -0
+
+	return count;
+}
 
 /**

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#2 lore raw
Quoted 7 lines · Will Schmidt

You could eliminate the temp variable rtas_poweron_auto_token, and rewrite as something like:

               if (rtas_token("ibm,power-off-ups") == RTAS_UNKNOWN_SERVICE) {
                       rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
                       printk(KERN_EMERG "Power-off called instead %d\n", rc );

Heh. I encouraged Manish to create the temp variable in an earlier round of reviews. My personal taste is that nested subroutine calls are both ugly and hard to debug, e.g. if rtas_token() for some reason returns unexpected values, etc.

--linas

#3 lore raw
In reply to Will Schmidt
Quoted 10 lines · On Mon, 04 Dec 2006 09:48:58 -0600 Will Schmidt <[email protected]>…

You could eliminate the temp variable rtas_poweron_auto_token, and rewrite as something like:

               if (rtas_token("ibm,power-off-ups") == RTAS_UNKNOWN_SERVICE) {
                       rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
                       printk(KERN_EMERG "Power-off called instead %d\n", rc );
               } else {
                       rc = rtas_call(rtas_token("ibm,power-off-ups"),0, 1, NULL);
                       printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
               }

It'd be even cleaner if you went the other way around instead, always do the temp variable. I also renamed it since it was misleading:

void rtas_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) {
		/* allow power on only with power button press */
		rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1)
		printk(KERN_INFO "RTAS power-off returned %d\n", rc);
	} else {
		/* Enable the system to reboot if power comes back on */
		rc = rtas_call(rtas_poweroff_ups_token, 0, 1, NULL);
		printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
	}

for (;;);
}

-Olof

#4 lore raw

Allrighty,

Code cleaning suggestions taken.

Will resend a new patch out..

-M

#5 lore raw
In reply to Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

arch/powerpc/kernel/rtas.c +24 -6
Index: 2.6-git2/arch/powerpc/kernel/rtas.c
===================================================================
@@ -601,14 +601,32 @@
 	for (;;);
 }
 
+/**
+ * rtas_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.
+ */
 void rtas_power_off(void)
 {
-	if (rtas_flash_term_hook)
-		rtas_flash_term_hook(SYS_POWER_OFF);
-	/* allow power on only with power button press */
-	printk("RTAS power-off returned %d\n",
-	       rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
-	for (;;);
+	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 (;;);
 }
 
 void rtas_halt(void)
arch/powerpc/kernel/rtas-proc.c +41 -0

68 lines not on this page · raw message

include/asm-powerpc/rtas.h +3 -0
Index: 2.6-git2/include/asm-powerpc/rtas.h
===================================================================
@@ -228,6 +228,9 @@
 /* RMO buffer reserved for user-space RTAS use */
 extern unsigned long rtas_rmo_buf;
 
+/* Poweron buffer used for enabling auto ups restart */
+extern unsigned long rtas_poweron_auto;
+
 #define GLOBAL_INTERRUPT_QUEUE 9005
 
 /**
#6 lore raw
Quoted 6 lines · Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

With this patch, the kernel won't build if CONFIG_PPC_RTAS=y and CONFIG_RTAS_PROC=n. Please move the definition of rtas_poweron_auto from rtas-proc.c to rtas.c so that this (admittedly somewhat strange) config will build.

Thanks,
Paul.

#7 lore raw

Okay,

Will post the new patch in a few hours.

was out sick and on vacation so didnt get a chance to do the needful.

-M

Quoted 14 lines · Paul Mackerras
Quoted 2 lines · Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

With this patch, the kernel won't build if CONFIG_PPC_RTAS=y and CONFIG_RTAS_PROC=n. Please move the definition of rtas_poweron_auto from rtas-proc.c to rtas.c so that this (admittedly somewhat strange) config will build.

Thanks,
Paul.

#8 lore raw
In reply to Paul Mackerras

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

arch/powerpc/kernel/rtas.c +25 -6
Index: 2.6-git2/arch/powerpc/kernel/rtas.c
===================================================================
@@ -52,6 +52,7 @@
 EXPORT_SYMBOL(rtas_data_buf);
 
 unsigned long rtas_rmo_buf;
+unsigned long rtas_poweron_auto; /* default and normal state is 0 */
 
 /*
  * If non-NULL, this gets called when the kernel terminates.
@@ -601,14 +602,32 @@
 	for (;;);
 }
 
+/**
+ * rtas_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.
+ */
 void rtas_power_off(void)
 {
-	if (rtas_flash_term_hook)
-		rtas_flash_term_hook(SYS_POWER_OFF);
-	/* allow power on only with power button press */
-	printk("RTAS power-off returned %d\n",
-	       rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
-	for (;;);
+	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 (;;);
 }
 
 void rtas_halt(void)
arch/powerpc/kernel/rtas-proc.c +40 -0
Index: 2.6-git2/arch/powerpc/kernel/rtas-proc.c
===================================================================
@@ -154,6 +154,9 @@
 		const char __user *buf, size_t count, loff_t *ppos);
 static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v);
 static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v);
+static int ppc_rtas_poweron_auto_show(struct seq_file *m, void *v);
+static ssize_t ppc_rtas_poweron_auto_write(struct file *file,
+		const char __user *buf, size_t count, loff_t *ppos);
 
 static int sensors_open(struct inode *inode, struct file *file)
 {
@@ -244,6 +247,18 @@
 	.release	= single_release,
 };
 
+static int poweron_auto_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, ppc_rtas_poweron_auto_show, NULL);
+}
+
+struct file_operations ppc_rtas_poweron_auto_operations = {
+	.open		= poweron_auto_open,
+	.read		= seq_read,
+	.write		= ppc_rtas_poweron_auto_write,
+	.release	= single_release,
+};
+
 static int ppc_rtas_find_all_sensors(void);
 static void ppc_rtas_process_sensor(struct seq_file *m,
 	struct individual_sensor *s, int state, int error, const char *loc);
@@ -293,6 +308,10 @@
 	if (entry)
 		entry->proc_fops = &ppc_rtas_rmo_buf_ops;
 
+	entry = create_proc_entry("ppc64/rtas/poweron_auto", S_IRUGO|S_IWUSR, NULL);
+	if (entry)
+		entry->proc_fops = &ppc_rtas_poweron_auto_operations;
+
 	return 0;
 }
 
@@ -805,3 +824,24 @@
 	seq_printf(m, "%016lx %x\n", rtas_rmo_buf, RTAS_RMOBUF_MAX);
 	return 0;
 }
+
+static ssize_t ppc_rtas_poweron_auto_write(struct file *file,
+		const char __user *buf, size_t count, loff_t *ppos)
+{
+	unsigned long ups_restart;
+	int error = parse_number(buf, count, &ups_restart);
+	if (error)
+		return error;
+
+	if (ups_restart)
+		rtas_poweron_auto = 1;
+
+	return count;
+}
+
+static int ppc_rtas_poweron_auto_show(struct seq_file *m, void *v)
+{
+        seq_printf(m, "%lu\n", rtas_poweron_auto);
+        return 0;
+
+}
include/asm-powerpc/rtas.h +3 -0
Index: 2.6-git2/include/asm-powerpc/rtas.h
===================================================================
@@ -228,6 +228,9 @@
 /* RMO buffer reserved for user-space RTAS use */
 extern unsigned long rtas_rmo_buf;
 
+/* Poweron buffer used for enabling auto ups restart */
+extern unsigned long rtas_poweron_auto;
+
 #define GLOBAL_INTERRUPT_QUEUE 9005
 
 /**
#9 lore raw
Quoted 6 lines · Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

Creating new non-process-related files in /proc is frowned upon these days, so we'll have to find somewhere in /sys for this. Anybody got a suggestion?

Paul.

#10 lore raw
Quoted 10 lines
Quoted 6 lines

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

Creating new non-process-related files in /proc is frowned upon these days, so we'll have to find somewhere in /sys for this. Anybody got a suggestion?

/sys doesn't sound too good either; it sounds like what Manish really wants is a character device? I could be way off though, not looking at the actual patch :-)

Segher

#11 lore raw
In reply to Paul Mackerras
Quoted 9 lines · Paul Mackerras
Quoted 6 lines · Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

Quoted 3 lines

Creating new non-process-related files in /proc is frowned upon these days, so we'll have to find somewhere in /sys for this. Anybody got a suggestion?

Maybe a sysctl instead?

#12 lore raw
Quoted 10 lines · Nathan Lynch
Quoted 9 lines · Paul Mackerras
Quoted 6 lines · Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

Quoted 5 lines
Quoted 3 lines

Creating new non-process-related files in /proc is frowned upon these days, so we'll have to find somewhere in /sys for this. Anybody got a suggestion?

Maybe a sysctl instead?

What's a sysctl?

Create a new /sys/class/rtas class?
There's a suggestive /sys/firmware directory, but don't know why its there...

-- linas

#13 lore raw
In reply to Nathan Lynch
Quoted 5 lines · Nathan Lynch
Quoted 3 lines · Paul Mackerras

Manish Ahuja writes:

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

Creating new non-process-related files in /proc is frowned upon these days, so we'll have to find somewhere in /sys for this. Anybody got a suggestion?

Maybe a sysctl instead?

Wouldn't sysctl be /proc/sys/something again.

I did look under /sys but couldn't come up with a location to create this new file.

Although creating new files under /proc is frowned upon, the subset of files in the directory seemed similar in functionality and connected to the new file I was creating and hence this new file in /proc/ppc64/rtas.

linux:/proc/ppc64/rtas # ls -x

.         ..          clock    error_log  frequency  poweron  poweron_auto
progress  rmo_buffer  sensors  volume

I don't mind creating a /sys entry if anyone has a good suggestion.

#14 lore raw
Quoted 12 lines · Manish Ahuja
Quoted 11 lines · Nathan Lynch
Quoted 9 lines · Paul Mackerras
Quoted 7 lines · Manish Ahuja

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to power on when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a proc interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Creating new non-process-related files in /proc is frowned upon these days, so we'll have to find somewhere in /sys for this. Anybody got a suggestion?

Maybe a sysctl instead?

Wouldn't sysctl be /proc/sys/something again.

?? where?

Quoted 2 lines

I did look under /sys but couldn't come up with a location to create this new file.

Candidates are /sys/class/rtas or /sys/devices/system/rtas or /sys/devices/system/of_platform or /sys/firmware or /sys/platform

I'd have to do some study & research to figure out which location would be appropriate.

Quoted 9 lines

Although creating new files under /proc is frowned upon, the subset of files in the directory
seemed similar in functionality and connected to the new file I was creating and hence this new file in
/proc/ppc64/rtas.

linux:/proc/ppc64/rtas # ls -x

.         ..          clock    error_log  frequency  poweron  poweron_auto
progress  rmo_buffer  sensors  volume

It would make sense to move some or all of these over to the new location as well.

--linas

#15 lore raw
In reply to Paul Mackerras

Resubmitting this patch with a sysfs interface instead of /proc.
During some off line discussion, /sys/power was suggested as a possible candidate area for this functionality to reside.

-------------------------------------------------------------------------------------------------------------------------

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to poweron when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a sysfs interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

arch/powerpc/kernel/rtas.c +22 -4
Index: 2.6.20-rc6-git1-t2/arch/powerpc/kernel/rtas.c
===================================================================
@@ -607,13 +607,31 @@
 	for (;;);
 }
 
+/**
+ * rtas_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.
+ */
 void rtas_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);
-	/* allow power on only with power button press */
-	printk("RTAS power-off returned %d\n",
-	       rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
+	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 (;;);
 }
 
include/asm-powerpc/rtas.h +3 -0
Index: 2.6.20-rc6-git1-t2/include/asm-powerpc/rtas.h
===================================================================
@@ -225,6 +225,9 @@
 /* RMO buffer reserved for user-space RTAS use */
 extern unsigned long rtas_rmo_buf;
 
+/* Poweron buffer used for enabling auto ups restart */
+extern unsigned long rtas_poweron_auto;
+
 #define GLOBAL_INTERRUPT_QUEUE 9005
 
 /**
arch/powerpc/platforms/pseries/power.c new file +87 -0

87 lines not on this page · raw message

arch/powerpc/platforms/pseries/Makefile +1 -1
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/Makefile
===================================================================
@@ -4,7 +4,7 @@
 
 obj-y			:= pci.o lpar.o hvCall.o nvram.o reconfig.o \
 			   setup.o iommu.o ras.o rtasd.o pci_dlpar.o \
-			   firmware.o
+			   firmware.o power.o
 obj-$(CONFIG_SMP)	+= smp.o
 obj-$(CONFIG_XICS)	+= xics.o
 obj-$(CONFIG_SCANLOG)	+= scanlog.o
Acked-by
#16 lore raw
Quoted 6 lines · Manish Ahuja

Resubmitting this patch with a sysfs interface instead of /proc. During some off line discussion, /sys/power was suggested as a possible candidate area for this functionality to reside.

-------------------------------------------------------------------------------------------------------------------------

Quoted 8 lines

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to poweron when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a sysfs interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

--linas

#17 lore raw
In reply to Manish Ahuja
Quoted 27 lines · Manish Ahuja

Index: 2.6.20-rc6-git1-t2/arch/powerpc/kernel/rtas.c
===================================================================

arch/powerpc/kernel/rtas.c +12 -4
@@ -607,13 +607,31 @@
 	for (;;);
 }
 
+/**
+ * rtas_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.
+ */
 void rtas_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);
-	/* allow power on only with power button press */
-	printk("RTAS power-off returned %d\n",
-	       rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));

arch/powerpc/kernel/rtas.c line 634

Quoted 10 lines
arch/powerpc/kernel/rtas.c +10 -0
+	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);
+	}

Unfortunately this causes a compilation error on platforms that use RTAS but aren't pSeries, since rtas_poweron_auto is defined in arch/powerpc/platforms/pseries/power.c. Either define rtas_poweron_auto in rtas.c, or move all this logic into arch/powerpc/platforms/pseries (i.e., make the pSeries setup.c set ppc_md.power_off to a pSeries-specific power off routine where you do this logic, setting it to rtas_power_off).

Paul.

#20 lore raw
In reply to Manish Ahuja
Quoted 3 lines · Manish Ahuja

Resubmitting this patch with a sysfs interface instead of /proc. During some off line discussion, /sys/power was suggested as a possible candidate area for this functionality to reside.

Minor nitpick since you have to respin based on Paul's comments anyway...

arch/powerpc/kernel/rtas.c line 625

Quoted 11 lines

void rtas_power_off(void)
{

arch/powerpc/kernel/rtas.c +4 -4
+	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);
-	/* allow power on only with power button press */
-	printk("RTAS power-off returned %d\n",
-	       rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
+	rtas_flash_term_hook(SYS_POWER_OFF);

Looks like you have an if (rtas_flash_term_hook) with an unindented line right after it.

-Olof

#21 lore raw
Quoted 3 lines

Minor nitpick since you have to respin based on Paul's comments anyway...

:) No problem. will get em both.. Thanks for reviewing it ..

-M

#18 lore raw
In reply to Paul Mackerras
Quoted 7 lines · Paul Mackerras

or move all this logic into
arch/powerpc/platforms/pseries (i.e., make the pSeries setup.c set ppc_md.power_off to a pSeries-specific power off routine where you do this logic, setting it to rtas_power_off).

Paul.

Duh, of course, thats how it should have been done.. Sorry I didn't think of it myself.. Will amend that as well.

-Manish

#19 lore raw
In reply to Paul Mackerras

Re-spun as suggested. I think this should be i-series friendly.

-------------------------------------------------------------------------------------------------------------------------

During power outages, the ups notifies the system for a shutdown. In the current setup, it isn't possible to poweron when power is restored. This patch fixes the issue by calling the right ibm,power-off-ups token during such events. It also adds a sysfs interface so that rc.powerfail can parse the epow events and modify the power-off behavior accordingly to enable the right token to be called.

---
 arch/powerpc/platforms/pseries/Makefile  |    2 
 arch/powerpc/platforms/pseries/power.c   |   87 +++++++++++++++++++++++++++++++
 arch/powerpc/platforms/pseries/pseries.h |    3 +
 arch/powerpc/platforms/pseries/setup.c   |   30 ++++++++++
 4 files changed, 120 insertions(+), 2 deletions(-)
arch/powerpc/platforms/pseries/power.c new file +87 -0
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/power.c
===================================================================
@@ -0,0 +1,87 @@
+/*
+ *  Interface for power-management for ppc64 compliant platform
+ *
+ *  Manish Ahuja <[email protected]>
+ *
+ *  Feb 2007
+ *
+ *  Copyright (C) 2007 IBM Corporation.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+
+unsigned long rtas_poweron_auto; /* default and normal state is 0 */
+
+static ssize_t auto_poweron_show(struct subsystem * subsys, char * buf)
+{
+        return sprintf(buf, "%lu\n", rtas_poweron_auto);
+}
+
+static ssize_t
+auto_poweron_store(struct subsystem * subsys, const char * buf, size_t n)
+{
+	int ret;
+	unsigned long ups_restart;
+	ret = sscanf(buf, "%lu", &ups_restart);
+
+	if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){
+		rtas_poweron_auto = ups_restart;
+		return n;
+	}
+	return -EINVAL;
+}
+
+static struct subsys_attribute auto_poweron_attr = {
+        .attr   = {
+                .name = __stringify(auto_poweron),
+                .mode = 0644,
+        },
+        .show   = auto_poweron_show,
+        .store  = auto_poweron_store,
+};
+
+#ifndef CONFIG_PM
+decl_subsys(power,NULL,NULL);
+
+static struct attribute * g[] = {
+        &auto_poweron_attr.attr,
+        NULL,
+};
+
+static struct attribute_group attr_group = {
+        .attrs = g,
+};
+
+static int __init pm_init(void)
+{
+        int error = subsystem_register(&power_subsys);
+        if (!error)
+                error = sysfs_create_group(&power_subsys.kset.kobj,&attr_group);
+        return error;
+}
+core_initcall(pm_init);
+#else
+extern struct subsystem power_subsys;
+
+static int __init apo_pm_init(void)
+{
+	return(subsys_create_file(&power_subsys, &auto_poweron_attr));
+}
+__initcall(apo_pm_init);
+#endif
arch/powerpc/platforms/pseries/Makefile +1 -1
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/Makefile
===================================================================
@@ -4,7 +4,7 @@ endif
 
 obj-y			:= pci.o lpar.o hvCall.o nvram.o reconfig.o \
 			   setup.o iommu.o ras.o rtasd.o pci_dlpar.o \
-			   firmware.o
+			   firmware.o power.o
 obj-$(CONFIG_SMP)	+= smp.o
 obj-$(CONFIG_XICS)	+= xics.o
 obj-$(CONFIG_SCANLOG)	+= scanlog.o
arch/powerpc/platforms/pseries/setup.c +29 -1
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/setup.c
===================================================================
@@ -486,6 +486,34 @@ static int pSeries_pci_probe_mode(struct
 	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.
+ */
+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 (;;);
+}
+
 define_machine(pseries) {
 	.name			= "pSeries",
 	.probe			= pSeries_probe,
@@ -496,7 +524,7 @@ define_machine(pseries) {
 	.pcibios_fixup		= pSeries_final_fixup,
 	.pci_probe_mode		= pSeries_pci_probe_mode,
 	.restart		= rtas_restart,
-	.power_off		= rtas_power_off,
+	.power_off		= pSeries_power_off,
 	.halt			= rtas_halt,
 	.panic			= rtas_os_term,
 	.get_boot_time		= rtas_get_boot_time,
arch/powerpc/platforms/pseries/pseries.h +3 -0
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/pseries.h
===================================================================
@@ -33,4 +33,7 @@ static inline setup_kexec_cpu_down_xics(
 static inline setup_kexec_cpu_down_mpic(void) { };
 #endif
 
+/* Poweron buffer used for enabling auto ups restart */
+extern unsigned long rtas_poweron_auto;
+
 #endif /* _PSERIES_PSERIES_H */