All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]Enabling Auto poweron after power is restored.
@ 2006-12-01 18:28 Manish Ahuja
  2006-12-04 15:48 ` Will Schmidt
  2006-12-05 21:41 ` Manish Ahuja
  0 siblings, 2 replies; 22+ messages in thread
From: Manish Ahuja @ 2006-12-01 18:28 UTC (permalink / raw)
  To: ppc-dev

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

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.

Signed-off-by: Manish Ahuja <ahuja@austin.ibm.com>

Resending this email as earlier attempts failed.



[-- Attachment #2: power-off-ups.patch --]
[-- Type: text/plain, Size: 4270 bytes --]

Index: 2.6-git2/arch/powerpc/kernel/rtas.c
===================================================================
--- 2.6-git2.orig/arch/powerpc/kernel/rtas.c	2006-11-29 12:00:26.000000000 -0800
+++ 2.6-git2/arch/powerpc/kernel/rtas.c	2006-11-30 10:56:12.000000000 -0800
@@ -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 (;;);
 }
 
Index: 2.6-git2/arch/powerpc/kernel/rtas-proc.c
===================================================================
--- 2.6-git2.orig/arch/powerpc/kernel/rtas-proc.c	2006-11-29 11:51:49.000000000 -0800
+++ 2.6-git2/arch/powerpc/kernel/rtas-proc.c	2006-11-30 11:01:55.000000000 -0800
@@ -122,6 +122,7 @@
 
 static unsigned long rtas_tone_frequency = 1000;
 static unsigned long rtas_tone_volume = 0;
+unsigned long rtas_poweron_auto; /* default and normal state is 0 */
 
 /* ****************STRUCTS******************************************* */
 struct individual_sensor {
@@ -154,6 +155,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 +248,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 +309,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 +825,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 != 0)
+		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;
+
+}
Index: 2.6-git2/include/asm-powerpc/rtas.h
===================================================================
--- 2.6-git2.orig/include/asm-powerpc/rtas.h	2006-11-28 14:41:17.000000000 -0800
+++ 2.6-git2/include/asm-powerpc/rtas.h	2006-11-30 10:42:35.000000000 -0800
@@ -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
 
 /**

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-01 18:28 [PATCH]Enabling Auto poweron after power is restored Manish Ahuja
@ 2006-12-04 15:48 ` Will Schmidt
  2006-12-04 19:31   ` Linas Vepstas
  2006-12-04 19:49   ` Olof Johansson
  2006-12-05 21:41 ` Manish Ahuja
  1 sibling, 2 replies; 22+ messages in thread
From: Will Schmidt @ 2006-12-04 15:48 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev

On Fri, 2006-01-12 at 12:28 -0600, Manish Ahuja wrote:
> 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.
> 
> Signed-off-by: Manish Ahuja <ahuja@austin.ibm.com>
> 


> plain text document attachment (power-off-ups.patch)
> Index: 2.6-git2/arch/powerpc/kernel/rtas.c
> ===================================================================
> --- 2.6-git2.orig/arch/powerpc/kernel/rtas.c	2006-11-29 12:00:26.000000000 -0800
> +++ 2.6-git2/arch/powerpc/kernel/rtas.c	2006-11-30 10:56:12.000000000 -0800
> @@ -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 */

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.


> +		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);
> +		}

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);
               }


> +
> +	}
>  	for (;;);
>  }

<snippage> 
> +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. 

> +
> +	return count;
> +}

>  /**
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-04 15:48 ` Will Schmidt
@ 2006-12-04 19:31   ` Linas Vepstas
  2006-12-04 19:49   ` Olof Johansson
  1 sibling, 0 replies; 22+ messages in thread
From: Linas Vepstas @ 2006-12-04 19:31 UTC (permalink / raw)
  To: Will Schmidt; +Cc: ppc-dev

On Mon, Dec 04, 2006 at 09:48:58AM -0600, Will Schmidt wrote:
> 
> 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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-04 15:48 ` Will Schmidt
  2006-12-04 19:31   ` Linas Vepstas
@ 2006-12-04 19:49   ` Olof Johansson
  2006-12-04 21:26     ` Manish Ahuja
  1 sibling, 1 reply; 22+ messages in thread
From: Olof Johansson @ 2006-12-04 19:49 UTC (permalink / raw)
  To: will_schmidt; +Cc: ppc-dev

On Mon, 04 Dec 2006 09:48:58 -0600 Will Schmidt <will_schmidt@vnet.ibm.com> wrote:

> 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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-04 19:49   ` Olof Johansson
@ 2006-12-04 21:26     ` Manish Ahuja
  0 siblings, 0 replies; 22+ messages in thread
From: Manish Ahuja @ 2006-12-04 21:26 UTC (permalink / raw)
  To: Olof Johansson; +Cc: ppc-dev

Allrighty,

Code cleaning suggestions taken.

Will resend a new patch out..

-M

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-01 18:28 [PATCH]Enabling Auto poweron after power is restored Manish Ahuja
  2006-12-04 15:48 ` Will Schmidt
@ 2006-12-05 21:41 ` Manish Ahuja
  2006-12-08  6:09   ` Paul Mackerras
  1 sibling, 1 reply; 22+ messages in thread
From: Manish Ahuja @ 2006-12-05 21:41 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev, paulus

[-- Attachment #1: Type: text/plain, Size: 454 bytes --]

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.

Signed-off-by: Manish Ahuja <ahuja@austin.ibm.com>

[-- Attachment #2: power-off-ups.patch --]
[-- Type: text/plain, Size: 4453 bytes --]

Index: 2.6-git2/arch/powerpc/kernel/rtas.c
===================================================================
--- 2.6-git2.orig/arch/powerpc/kernel/rtas.c	2006-11-29 12:00:26.000000000 -0800
+++ 2.6-git2/arch/powerpc/kernel/rtas.c	2006-12-05 13:35:22.000000000 -0800
@@ -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)
Index: 2.6-git2/arch/powerpc/kernel/rtas-proc.c
===================================================================
--- 2.6-git2.orig/arch/powerpc/kernel/rtas-proc.c	2006-11-29 11:51:49.000000000 -0800
+++ 2.6-git2/arch/powerpc/kernel/rtas-proc.c	2006-12-05 12:00:47.000000000 -0800
@@ -122,6 +122,7 @@
 
 static unsigned long rtas_tone_frequency = 1000;
 static unsigned long rtas_tone_volume = 0;
+unsigned long rtas_poweron_auto; /* default and normal state is 0 */
 
 /* ****************STRUCTS******************************************* */
 struct individual_sensor {
@@ -154,6 +155,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 +248,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 +309,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 +825,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;
+
+}
Index: 2.6-git2/include/asm-powerpc/rtas.h
===================================================================
--- 2.6-git2.orig/include/asm-powerpc/rtas.h	2006-11-28 14:41:17.000000000 -0800
+++ 2.6-git2/include/asm-powerpc/rtas.h	2006-11-30 10:42:35.000000000 -0800
@@ -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
 
 /**

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-05 21:41 ` Manish Ahuja
@ 2006-12-08  6:09   ` Paul Mackerras
  2006-12-24 16:56     ` Manish Ahuja
  2006-12-24 17:50     ` Manish Ahuja
  0 siblings, 2 replies; 22+ messages in thread
From: Paul Mackerras @ 2006-12-08  6:09 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev

Manish Ahuja writes:

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-08  6:09   ` Paul Mackerras
@ 2006-12-24 16:56     ` Manish Ahuja
  2006-12-24 17:50     ` Manish Ahuja
  1 sibling, 0 replies; 22+ messages in thread
From: Manish Ahuja @ 2006-12-24 16:56 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: ppc-dev

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



Paul Mackerras wrote:
> Manish Ahuja writes:
>
>   
>> 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.
>   

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-08  6:09   ` Paul Mackerras
  2006-12-24 16:56     ` Manish Ahuja
@ 2006-12-24 17:50     ` Manish Ahuja
  2007-01-09  4:16       ` Paul Mackerras
  1 sibling, 1 reply; 22+ messages in thread
From: Manish Ahuja @ 2006-12-24 17:50 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: ppc-dev

[-- Attachment #1: Type: text/plain, Size: 456 bytes --]


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.

Signed-off-by: Manish Ahuja <ahuja@austin.ibm.com>


[-- Attachment #2: power-off-ups.patch --]
[-- Type: text/plain, Size: 4381 bytes --]

Index: 2.6-git2/arch/powerpc/kernel/rtas.c
===================================================================
--- 2.6-git2.orig/arch/powerpc/kernel/rtas.c	2006-11-29 12:00:26.000000000 -0800
+++ 2.6-git2/arch/powerpc/kernel/rtas.c	2006-12-24 09:30:01.000000000 -0800
@@ -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)
Index: 2.6-git2/arch/powerpc/kernel/rtas-proc.c
===================================================================
--- 2.6-git2.orig/arch/powerpc/kernel/rtas-proc.c	2006-11-29 11:51:49.000000000 -0800
+++ 2.6-git2/arch/powerpc/kernel/rtas-proc.c	2006-12-24 09:28:41.000000000 -0800
@@ -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;
+
+}
Index: 2.6-git2/include/asm-powerpc/rtas.h
===================================================================
--- 2.6-git2.orig/include/asm-powerpc/rtas.h	2006-11-28 14:41:17.000000000 -0800
+++ 2.6-git2/include/asm-powerpc/rtas.h	2006-11-30 10:42:35.000000000 -0800
@@ -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
 
 /**

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2006-12-24 17:50     ` Manish Ahuja
@ 2007-01-09  4:16       ` Paul Mackerras
  2007-01-09 14:21         ` Segher Boessenkool
                           ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Paul Mackerras @ 2007-01-09  4:16 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev

Manish Ahuja writes:

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-01-09  4:16       ` Paul Mackerras
@ 2007-01-09 14:21         ` Segher Boessenkool
  2007-01-09 15:05         ` Nathan Lynch
  2007-02-03  4:16         ` Manish Ahuja
  2 siblings, 0 replies; 22+ messages in thread
From: Segher Boessenkool @ 2007-01-09 14:21 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: ppc-dev

>> 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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-01-09  4:16       ` Paul Mackerras
  2007-01-09 14:21         ` Segher Boessenkool
@ 2007-01-09 15:05         ` Nathan Lynch
  2007-01-10 20:58           ` Linas Vepstas
  2007-01-10 20:58           ` Manish Ahuja
  2007-02-03  4:16         ` Manish Ahuja
  2 siblings, 2 replies; 22+ messages in thread
From: Nathan Lynch @ 2007-01-09 15:05 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: ppc-dev

Paul Mackerras wrote:
> Manish Ahuja writes:
> 
> > 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?

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-01-09 15:05         ` Nathan Lynch
@ 2007-01-10 20:58           ` Linas Vepstas
  2007-01-10 20:58           ` Manish Ahuja
  1 sibling, 0 replies; 22+ messages in thread
From: Linas Vepstas @ 2007-01-10 20:58 UTC (permalink / raw)
  To: Nathan Lynch; +Cc: ppc-dev, Paul Mackerras

On Tue, Jan 09, 2007 at 09:05:19AM -0600, Nathan Lynch wrote:
> Paul Mackerras wrote:
> > Manish Ahuja writes:
> > 
> > > 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?

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-01-09 15:05         ` Nathan Lynch
  2007-01-10 20:58           ` Linas Vepstas
@ 2007-01-10 20:58           ` Manish Ahuja
  2007-01-12  0:38             ` Linas Vepstas
  1 sibling, 1 reply; 22+ messages in thread
From: Manish Ahuja @ 2007-01-10 20:58 UTC (permalink / raw)
  To: Nathan Lynch; +Cc: ppc-dev, Paul Mackerras

Nathan Lynch wrote:
> Paul Mackerras wrote:
>   
>> Manish Ahuja writes:
>>
>>     
>>> 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.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-01-10 20:58           ` Manish Ahuja
@ 2007-01-12  0:38             ` Linas Vepstas
  0 siblings, 0 replies; 22+ messages in thread
From: Linas Vepstas @ 2007-01-12  0:38 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev, Nathan Lynch, Paul Mackerras

On Wed, Jan 10, 2007 at 02:58:40PM -0600, Manish Ahuja wrote:
> Nathan Lynch wrote:
> > Paul Mackerras wrote:
> >   
> >> Manish Ahuja writes:
> >>
> >>> 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.

?? where?

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

> 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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-01-09  4:16       ` Paul Mackerras
  2007-01-09 14:21         ` Segher Boessenkool
  2007-01-09 15:05         ` Nathan Lynch
@ 2007-02-03  4:16         ` Manish Ahuja
  2007-02-06 17:58           ` Linas Vepstas
                             ` (2 more replies)
  2 siblings, 3 replies; 22+ messages in thread
From: Manish Ahuja @ 2007-02-03  4:16 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: ppc-dev

[-- Attachment #1: Type: text/plain, Size: 766 bytes --]

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.

Signed-off-by: Manish Ahuja <ahuja@austin.ibm.com>


[-- Attachment #2: Auto-poweron-patch --]
[-- Type: text/plain, Size: 5360 bytes --]

Index: 2.6.20-rc6-git1-t2/arch/powerpc/kernel/rtas.c
===================================================================
--- 2.6.20-rc6-git1-t2.orig/arch/powerpc/kernel/rtas.c	2007-02-02 05:47:13.000000000 -0800
+++ 2.6.20-rc6-git1-t2/arch/powerpc/kernel/rtas.c	2007-02-02 08:37:09.000000000 -0800
@@ -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 (;;);
 }
 
Index: 2.6.20-rc6-git1-t2/include/asm-powerpc/rtas.h
===================================================================
--- 2.6.20-rc6-git1-t2.orig/include/asm-powerpc/rtas.h	2007-02-02 05:47:32.000000000 -0800
+++ 2.6.20-rc6-git1-t2/include/asm-powerpc/rtas.h	2007-02-02 08:39:25.000000000 -0800
@@ -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
 
 /**
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/power.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/power.c	2007-02-02 13:18:09.000000000 -0800
@@ -0,0 +1,87 @@
+/*
+ *  Interface for power-management for ppc64 compliant platform
+ *
+ *  Manish Ahuja <mahuja@us.ibm.com>
+ *
+ *  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
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/Makefile
===================================================================
--- 2.6.20-rc6-git1-t2.orig/arch/powerpc/platforms/pseries/Makefile	2007-02-02 05:47:13.000000000 -0800
+++ 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/Makefile	2007-02-02 09:32:09.000000000 -0800
@@ -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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-02-03  4:16         ` Manish Ahuja
@ 2007-02-06 17:58           ` Linas Vepstas
  2007-02-07  2:24           ` Paul Mackerras
  2007-02-07 16:59           ` Olof Johansson
  2 siblings, 0 replies; 22+ messages in thread
From: Linas Vepstas @ 2007-02-06 17:58 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev, Paul Mackerras

On Fri, Feb 02, 2007 at 10:16:23PM -0600, Manish Ahuja wrote:
> 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.
> 
> Signed-off-by: Manish Ahuja <ahuja@austin.ibm.com>

Acked-by: Linas Vepstas <linas@austin.ibm.com>


--linas

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-02-03  4:16         ` Manish Ahuja
  2007-02-06 17:58           ` Linas Vepstas
@ 2007-02-07  2:24           ` Paul Mackerras
  2007-02-07 19:42             ` Manish Ahuja
  2007-02-08 22:01             ` Manish Ahuja
  2007-02-07 16:59           ` Olof Johansson
  2 siblings, 2 replies; 22+ messages in thread
From: Paul Mackerras @ 2007-02-07  2:24 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev

Manish Ahuja writes:

> Index: 2.6.20-rc6-git1-t2/arch/powerpc/kernel/rtas.c
> ===================================================================
> --- 2.6.20-rc6-git1-t2.orig/arch/powerpc/kernel/rtas.c	2007-02-02 05:47:13.000000000 -0800
> +++ 2.6.20-rc6-git1-t2/arch/powerpc/kernel/rtas.c	2007-02-02 08:37:09.000000000 -0800
> @@ -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);
> +	}

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.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-02-03  4:16         ` Manish Ahuja
  2007-02-06 17:58           ` Linas Vepstas
  2007-02-07  2:24           ` Paul Mackerras
@ 2007-02-07 16:59           ` Olof Johansson
  2007-02-07 17:05             ` Manish Ahuja
  2 siblings, 1 reply; 22+ messages in thread
From: Olof Johansson @ 2007-02-07 16:59 UTC (permalink / raw)
  To: Manish Ahuja; +Cc: ppc-dev, Paul Mackerras

On Fri, Feb 02, 2007 at 10:16:23PM -0600, Manish Ahuja wrote:
> 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...

>  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);

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



-Olof

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-02-07 16:59           ` Olof Johansson
@ 2007-02-07 17:05             ` Manish Ahuja
  0 siblings, 0 replies; 22+ messages in thread
From: Manish Ahuja @ 2007-02-07 17:05 UTC (permalink / raw)
  To: Olof Johansson; +Cc: ppc-dev, Paul Mackerras


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

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


-M

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-02-07  2:24           ` Paul Mackerras
@ 2007-02-07 19:42             ` Manish Ahuja
  2007-02-08 22:01             ` Manish Ahuja
  1 sibling, 0 replies; 22+ messages in thread
From: Manish Ahuja @ 2007-02-07 19:42 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: ppc-dev

Paul Mackerras wrote:
>  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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH]Enabling Auto poweron after power is restored.
  2007-02-07  2:24           ` Paul Mackerras
  2007-02-07 19:42             ` Manish Ahuja
@ 2007-02-08 22:01             ` Manish Ahuja
  1 sibling, 0 replies; 22+ messages in thread
From: Manish Ahuja @ 2007-02-08 22:01 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: ppc-dev

[-- Attachment #1: Type: text/plain, Size: 646 bytes --]

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.

Signed-off-by: Manish Ahuja <ahuja@austin.ibm.com>






[-- Attachment #2: Auto-poweron-patch-1 --]
[-- Type: text/plain, Size: 6003 bytes --]

---
 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(-)

Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/power.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/power.c	2007-02-08 12:37:30.000000000 -0800
@@ -0,0 +1,87 @@
+/*
+ *  Interface for power-management for ppc64 compliant platform
+ *
+ *  Manish Ahuja <mahuja@us.ibm.com>
+ *
+ *  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
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/Makefile
===================================================================
--- 2.6.20-rc6-git1-t2.orig/arch/powerpc/platforms/pseries/Makefile	2007-02-08 12:37:28.000000000 -0800
+++ 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/Makefile	2007-02-08 12:37:30.000000000 -0800
@@ -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
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/setup.c
===================================================================
--- 2.6.20-rc6-git1-t2.orig/arch/powerpc/platforms/pseries/setup.c	2007-02-08 12:37:28.000000000 -0800
+++ 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/setup.c	2007-02-08 12:37:30.000000000 -0800
@@ -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,
Index: 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/pseries.h
===================================================================
--- 2.6.20-rc6-git1-t2.orig/arch/powerpc/platforms/pseries/pseries.h	2007-02-08 12:37:28.000000000 -0800
+++ 2.6.20-rc6-git1-t2/arch/powerpc/platforms/pseries/pseries.h	2007-02-08 12:48:10.000000000 -0800
@@ -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 */


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2007-02-08 22:01 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-01 18:28 [PATCH]Enabling Auto poweron after power is restored Manish Ahuja
2006-12-04 15:48 ` Will Schmidt
2006-12-04 19:31   ` Linas Vepstas
2006-12-04 19:49   ` Olof Johansson
2006-12-04 21:26     ` Manish Ahuja
2006-12-05 21:41 ` Manish Ahuja
2006-12-08  6:09   ` Paul Mackerras
2006-12-24 16:56     ` Manish Ahuja
2006-12-24 17:50     ` Manish Ahuja
2007-01-09  4:16       ` Paul Mackerras
2007-01-09 14:21         ` Segher Boessenkool
2007-01-09 15:05         ` Nathan Lynch
2007-01-10 20:58           ` Linas Vepstas
2007-01-10 20:58           ` Manish Ahuja
2007-01-12  0:38             ` Linas Vepstas
2007-02-03  4:16         ` Manish Ahuja
2007-02-06 17:58           ` Linas Vepstas
2007-02-07  2:24           ` Paul Mackerras
2007-02-07 19:42             ` Manish Ahuja
2007-02-08 22:01             ` Manish Ahuja
2007-02-07 16:59           ` Olof Johansson
2007-02-07 17:05             ` Manish Ahuja

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.