Commit d4b86e56 authored by Patrick Mochel's avatar Patrick Mochel Committed by Patrick Mochel

Add platform driver object

parent c26faf67
/*
* 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 */
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
O_TARGET := kernel.o O_TARGET := kernel.o
export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.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 \ 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 \ module.o exit.o itimer.o info.o time.o softirq.o resource.o \
sysctl.o capability.o ptrace.o timer.o user.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_UID16) += uid16.o
obj-$(CONFIG_MODULES) += ksyms.o obj-$(CONFIG_MODULES) += ksyms.o
......
/*
* 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);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment