]> git.hungrycats.org Git - linux/commitdiff
Add platform driver object
authorPatrick Mochel <mochel@segfault.osdl.org>
Fri, 5 Apr 2002 02:12:08 +0000 (18:12 -0800)
committerPatrick Mochel <mochel@hera.kernel.org>
Fri, 5 Apr 2002 02:12:08 +0000 (18:12 -0800)
include/linux/platform.h [new file with mode: 0644]
kernel/Makefile
kernel/platform.c [new file with mode: 0644]

diff --git a/include/linux/platform.h b/include/linux/platform.h
new file mode 100644 (file)
index 0000000..3c33084
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * include/linux/platform.h - platform driver definitions
+ *
+ * Because of the prolific consumerism of the average American,
+ * and the dominant marketing budgets of PC OEMs, we have been
+ * blessed with frequent updates of the PC architecture. 
+ *
+ * While most of these calls are singular per architecture, they 
+ * require an extra layer of abstraction on the x86 so the right
+ * subsystem gets the right call. 
+ *
+ * Basically, this consolidates the power off and reboot callbacks 
+ * into one structure, as well as adding power management hooks.
+ *
+ * When adding a platform driver, please make sure all callbacks are 
+ * filled. There are defaults defined below that do nothing; use those
+ * if you do not support that callback.
+ */ 
+
+#ifndef _PLATFORM_H_
+#define _PLATFORM_H_
+#ifdef __KERNEL__
+
+#include <linux/types.h>
+
+struct platform_t {
+       char    * name;
+       u32     suspend_states;
+       void    (*reboot)(char * cmd);
+       void    (*halt)(void);
+       void    (*power_off)(void);
+       int     (*suspend)(int state, int flags);
+       void    (*idle)(void);
+};
+
+extern struct platform_t * platform;
+extern void default_reboot(char * cmd);
+extern void default_halt(void);
+extern int default_suspend(int state, int flags);
+extern void default_idle(void);
+
+#endif /* __KERNEL__ */
+#endif /* _PLATFORM_H */
index 2384e5fe9bea03d8c56612b55a433d694bd7bc2e..2c8154ed277890c846abed926fc1d2b726b86ca1 100644 (file)
 O_TARGET := kernel.o
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-               printk.o 
+               printk.o platform.o 
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
            module.o exit.o itimer.o info.o time.o softirq.o resource.o \
            sysctl.o capability.o ptrace.o timer.o user.o \
-           signal.o sys.o kmod.o context.o futex.o
+           signal.o sys.o kmod.o context.o futex.o platform.o
 
 obj-$(CONFIG_UID16) += uid16.o
 obj-$(CONFIG_MODULES) += ksyms.o
diff --git a/kernel/platform.c b/kernel/platform.c
new file mode 100644 (file)
index 0000000..2d786dc
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * platform driver support 
+ */
+
+#include <linux/platform.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+
+static struct platform_t default_platform;
+
+struct platform_t * platform = &default_platform;
+static spinlock_t platform_lock = SPIN_LOCK_UNLOCKED;
+
+void default_reboot(char * cmd)
+{
+       /* nothing */
+}
+
+void default_halt(void)
+{
+       /* nothing */
+}
+
+int default_suspend(int state, int flags)
+{
+       return -ENOSYS;
+}
+
+static struct platform_t default_platform = {
+       name:           "Default Platform",
+       suspend_states: 0,
+       reboot:         default_reboot,
+       halt:           default_halt,
+       power_off:      default_halt,
+       suspend:        default_suspend,
+       idle:           default_idle,
+};
+
+/**
+ * set_platform_driver - set the platform driver.
+ * @pf:        driver to set it to
+ *
+ * Return -EEXIST if someone else already owns it.
+ */
+int set_platform_driver(struct platform_t * pf)
+{
+       if (!pf)
+               return -EINVAL;
+       spin_lock(&platform_lock);
+       if (platform != &default_platform) {
+               spin_unlock(&platform_lock);
+               return -EEXIST;
+       }
+       platform = pf;
+       spin_unlock(&platform_lock);
+       return 0;
+}
+
+void remove_platform_driver(struct platform_t * pf)
+{
+       spin_lock(&platform_lock);
+       if (platform == pf)
+               platform = &default_platform;
+       spin_unlock(&platform_lock);
+}
+
+EXPORT_SYMBOL(default_reboot);
+EXPORT_SYMBOL(default_halt);
+EXPORT_SYMBOL(default_suspend);
+
+EXPORT_SYMBOL(platform);
+EXPORT_SYMBOL(set_platform_driver);
+EXPORT_SYMBOL(remove_platform_driver);