linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] machine_reboot and friends
@ 2003-06-06 21:51 Anders Gustafsson
  2003-06-08  5:18 ` Dave Hansen
  0 siblings, 1 reply; 2+ messages in thread
From: Anders Gustafsson @ 2003-06-06 21:51 UTC (permalink / raw)
  To: linux-kernel

Hi,

just a thought:

What if machine_restart/machine_halt/machine_power_off were made
functionpointers instead? And let the architectures assign to them
instead of defining the functions? Some architectures are already
doing this. (There should be no problems with races or so, they are
assigned early in the boot, and used at shutdowntime. And letting modules
assign them wouldn't work in the ideal world where modules are
deinitialized at shutdown)

A bit orthogonal: Different architechtures do different things if the action
fails (or is unimplemented), some panic, some return, some do "for(;;);",
isn't it about time someone defined the semantics for these functions?

I mean something like the following, modulo changes to architechtures...

-- 
Anders Gustafsson - andersg@0x63.nu - http://0x63.nu/


--- 1.3/include/linux/reboot.h	Thu Dec  5 02:05:34 2002
+++ edited/include/linux/reboot.h	Fri Jun  6 21:07:01 2003
@@ -44,9 +44,9 @@
  * Architecture-specific implementations of sys_reboot commands.
  */
 
-extern void machine_restart(char *cmd);
-extern void machine_halt(void);
-extern void machine_power_off(void);
+extern void (*machine_restart)(char *cmd);
+extern void (*machine_halt)(void);
+extern void (*machine_power_off)(void);
 
 #endif
 
--- 1.45/kernel/sys.c	Sun May 25 23:08:02 2003
+++ edited/kernel/sys.c	Fri Jun  6 21:32:14 2003
@@ -63,6 +63,14 @@
 int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
 
 /*
+ * These callbacks define archspecific behaviour.
+ */
+void (*machine_restart)(char *cmd);
+void (*machine_halt)(void);
+void (*machine_power_off)(void);
+void (*pm_power_off)(void);
+
+/*
  * this indicates whether you can reboot with ctrl-alt-del: the default is yes
  */
 
@@ -403,7 +411,8 @@
 		system_running = 0;
 		device_shutdown();
 		printk(KERN_EMERG "Restarting system.\n");
-		machine_restart(NULL);
+		if(machine_restart)
+			machine_restart(NULL);
 		break;
 
 	case LINUX_REBOOT_CMD_CAD_ON:
@@ -419,7 +428,8 @@
 		system_running = 0;
 		device_shutdown();
 		printk(KERN_EMERG "System halted.\n");
-		machine_halt();
+		if(machine_halt)
+			machine_halt();
 		unlock_kernel();
 		do_exit(0);
 		break;
@@ -429,7 +439,10 @@
 		system_running = 0;
 		device_shutdown();
 		printk(KERN_EMERG "Power down.\n");
-		machine_power_off();
+		if(machine_power_off)
+			machine_power_off();
+		if(pm_power_off)
+			pm_power_off();
 		unlock_kernel();
 		do_exit(0);
 		break;
@@ -445,7 +458,9 @@
 		system_running = 0;
 		device_shutdown();
 		printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
-		machine_restart(buffer);
+		
+		if(machine_restart)
+			machine_restart(buffer);
 		break;
 
 #ifdef CONFIG_SOFTWARE_SUSPEND
@@ -470,7 +485,8 @@
 static void deferred_cad(void *dummy)
 {
 	notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
-	machine_restart(NULL);
+	if(machine_restart)
+		machine_restart(NULL);
 }
 
 /*
@@ -1414,3 +1430,4 @@
 EXPORT_SYMBOL(unregister_reboot_notifier);
 EXPORT_SYMBOL(in_group_p);
 EXPORT_SYMBOL(in_egroup_p);
+EXPORT_SYMBOL(pm_power_off);



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

* Re: [RFC] machine_reboot and friends
  2003-06-06 21:51 [RFC] machine_reboot and friends Anders Gustafsson
@ 2003-06-08  5:18 ` Dave Hansen
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Hansen @ 2003-06-08  5:18 UTC (permalink / raw)
  To: Anders Gustafsson; +Cc: Linux Kernel Mailing List

On Fri, 2003-06-06 at 14:51, Anders Gustafsson wrote:
> What if machine_restart/machine_halt/machine_power_off were made
> functionpointers instead? And let the architectures assign to them
> instead of defining the functions? Some architectures are already
> doing this.

We don't usually abstract out architecture features with function
pointers.  The more standard way is with definitions in
architecture-specific files.  Also, the 

               if(machine_restart)
                       machine_restart(NULL);

stuff is fairly messy, and it would probably be preferable to do
something like this instead:

void machine_restart(void)
{
               if(arch_machine_restart)
                       arch_machine_restart(NULL);
}

Then, let the architectures define arch_machine_restart(), and keep tons
of duplicate if()s from being scattered around.

> A bit orthogonal: Different architechtures do different things if the action
> fails (or is unimplemented), some panic, some return, some do "for(;;);",
> isn't it about time someone defined the semantics for these functions?

Not really.  It's architecture specific :)  Some machines simply don't
have a recourse when something that low-level fails.  Is there a case
when something happens that you don't expect?  The three architecures
that I compile for work happily, and as I expect.

-- 
Dave Hansen
haveblue@us.ibm.com


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

end of thread, other threads:[~2003-06-08  5:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-06 21:51 [RFC] machine_reboot and friends Anders Gustafsson
2003-06-08  5:18 ` Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).