Implement serial logging. Finish modularizing power management.
[monolithium.git] / kernel / src / power.c
index fe5897cb9fc0c87596341c1669475b0ad3dffa82..8f6c97615b885cfa75b5d7c72563e07056633c0d 100644 (file)
 #include <syscalls.h>
 #include <user.h>
 
+static power_callbacks_t *power_callbacks = NULL;
+
+dword_t register_power_callbacks(power_callbacks_t *callbacks)
+{
+    if (callbacks && power_callbacks) return ERR_EXISTS;
+    power_callbacks = callbacks;
+    return ERR_SUCCESS;
+}
+
 sysret_t syscall_power_control(power_command_t command)
 {
     if (get_previous_mode() == USER_MODE && !check_privileges(PRIVILEGE_POWER_CONTROL))
@@ -30,6 +39,9 @@ sysret_t syscall_power_control(power_command_t command)
 
     switch (command)
     {
+    case POWER_COMMAND_SHUTDOWN:
+        if (power_callbacks) power_callbacks->set_state(POWER_STATE_OFF);
+
     case POWER_COMMAND_HALT:
         disable_ints();
         halt();
@@ -42,11 +54,6 @@ sysret_t syscall_power_control(power_command_t command)
         halt();
         break;
 
-    case POWER_COMMAND_SHUTDOWN:
-        // TODO: ACPI set to S5
-        halt();
-        break;
-
     default:
         return ERR_INVALID;
     }