2019-05-29 22:18:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-09-07 06:17:15 +08:00
|
|
|
/*
|
|
|
|
* dcdbas.c: Dell Systems Management Base Driver
|
|
|
|
*
|
|
|
|
* The Dell Systems Management Base Driver provides a sysfs interface for
|
|
|
|
* systems management software to perform System Management Interrupts (SMIs)
|
|
|
|
* and Host Control Actions (power cycle or power off after OS shutdown) on
|
|
|
|
* Dell systems.
|
|
|
|
*
|
2019-06-28 02:39:22 +08:00
|
|
|
* See Documentation/driver-api/dcdbas.rst for more information.
|
2005-09-07 06:17:15 +08:00
|
|
|
*
|
2006-10-20 14:29:09 +08:00
|
|
|
* Copyright (C) 1995-2006 Dell Inc.
|
2005-09-07 06:17:15 +08:00
|
|
|
*/
|
|
|
|
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2018-09-27 05:50:18 +08:00
|
|
|
#include <linux/acpi.h>
|
2005-09-07 06:17:15 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/errno.h>
|
2016-08-29 14:48:46 +08:00
|
|
|
#include <linux/cpu.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-09-07 06:17:15 +08:00
|
|
|
#include <linux/init.h>
|
2018-10-03 05:16:42 +08:00
|
|
|
#include <linux/io.h>
|
2005-09-07 06:17:15 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mc146818rtc.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/types.h>
|
2006-03-23 19:00:21 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
#include "dcdbas.h"
|
|
|
|
|
|
|
|
#define DRIVER_NAME "dcdbas"
|
2018-09-27 05:50:18 +08:00
|
|
|
#define DRIVER_VERSION "5.6.0-3.3"
|
2005-09-07 06:17:15 +08:00
|
|
|
#define DRIVER_DESCRIPTION "Dell Systems Management Base Driver"
|
|
|
|
|
|
|
|
static struct platform_device *dcdbas_pdev;
|
|
|
|
|
|
|
|
static u8 *smi_data_buf;
|
|
|
|
static dma_addr_t smi_data_buf_handle;
|
|
|
|
static unsigned long smi_data_buf_size;
|
2018-09-27 05:50:18 +08:00
|
|
|
static unsigned long max_smi_data_buf_size = MAX_SMI_DATA_BUF_SIZE;
|
2005-09-07 06:17:15 +08:00
|
|
|
static u32 smi_data_buf_phys_addr;
|
2006-03-23 19:00:21 +08:00
|
|
|
static DEFINE_MUTEX(smi_data_lock);
|
2018-09-27 05:50:18 +08:00
|
|
|
static u8 *eps_buffer;
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
static unsigned int host_control_action;
|
|
|
|
static unsigned int host_control_smi_type;
|
|
|
|
static unsigned int host_control_on_shutdown;
|
|
|
|
|
2018-09-27 05:50:18 +08:00
|
|
|
static bool wsmt_enabled;
|
|
|
|
|
2005-09-07 06:17:15 +08:00
|
|
|
/**
|
|
|
|
* smi_data_buf_free: free SMI data buffer
|
|
|
|
*/
|
|
|
|
static void smi_data_buf_free(void)
|
|
|
|
{
|
2018-09-27 05:50:18 +08:00
|
|
|
if (!smi_data_buf || wsmt_enabled)
|
2005-09-07 06:17:15 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
dev_dbg(&dcdbas_pdev->dev, "%s: phys: %x size: %lu\n",
|
2008-04-29 15:59:19 +08:00
|
|
|
__func__, smi_data_buf_phys_addr, smi_data_buf_size);
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
dma_free_coherent(&dcdbas_pdev->dev, smi_data_buf_size, smi_data_buf,
|
|
|
|
smi_data_buf_handle);
|
|
|
|
smi_data_buf = NULL;
|
|
|
|
smi_data_buf_handle = 0;
|
|
|
|
smi_data_buf_phys_addr = 0;
|
|
|
|
smi_data_buf_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* smi_data_buf_realloc: grow SMI data buffer if needed
|
|
|
|
*/
|
|
|
|
static int smi_data_buf_realloc(unsigned long size)
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
dma_addr_t handle;
|
|
|
|
|
|
|
|
if (smi_data_buf_size >= size)
|
|
|
|
return 0;
|
|
|
|
|
2018-09-27 05:50:18 +08:00
|
|
|
if (size > max_smi_data_buf_size)
|
2005-09-07 06:17:15 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* new buffer is needed */
|
|
|
|
buf = dma_alloc_coherent(&dcdbas_pdev->dev, size, &handle, GFP_KERNEL);
|
|
|
|
if (!buf) {
|
|
|
|
dev_dbg(&dcdbas_pdev->dev,
|
|
|
|
"%s: failed to allocate memory size %lu\n",
|
2008-04-29 15:59:19 +08:00
|
|
|
__func__, size);
|
2005-09-07 06:17:15 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
/* memory zeroed by dma_alloc_coherent */
|
|
|
|
|
|
|
|
if (smi_data_buf)
|
|
|
|
memcpy(buf, smi_data_buf, smi_data_buf_size);
|
|
|
|
|
|
|
|
/* free any existing buffer */
|
|
|
|
smi_data_buf_free();
|
|
|
|
|
|
|
|
/* set up new buffer for use */
|
|
|
|
smi_data_buf = buf;
|
|
|
|
smi_data_buf_handle = handle;
|
|
|
|
smi_data_buf_phys_addr = (u32) virt_to_phys(buf);
|
|
|
|
smi_data_buf_size = size;
|
|
|
|
|
|
|
|
dev_dbg(&dcdbas_pdev->dev, "%s: phys: %x size: %lu\n",
|
2008-04-29 15:59:19 +08:00
|
|
|
__func__, smi_data_buf_phys_addr, smi_data_buf_size);
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t smi_data_buf_phys_addr_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%x\n", smi_data_buf_phys_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t smi_data_buf_size_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%lu\n", smi_data_buf_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t smi_data_buf_size_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long buf_size;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
buf_size = simple_strtoul(buf, NULL, 10);
|
|
|
|
|
|
|
|
/* make sure SMI data buffer is at least buf_size */
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_lock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
ret = smi_data_buf_realloc(buf_size);
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_unlock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-05-13 09:28:57 +08:00
|
|
|
static ssize_t smi_data_read(struct file *filp, struct kobject *kobj,
|
2007-06-09 13:57:22 +08:00
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buf, loff_t pos, size_t count)
|
2005-09-07 06:17:15 +08:00
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_lock(&smi_data_lock);
|
2008-07-25 16:48:24 +08:00
|
|
|
ret = memory_read_from_buffer(buf, count, &pos, smi_data_buf,
|
|
|
|
smi_data_buf_size);
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_unlock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-13 09:28:57 +08:00
|
|
|
static ssize_t smi_data_write(struct file *filp, struct kobject *kobj,
|
2007-06-09 13:57:22 +08:00
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buf, loff_t pos, size_t count)
|
2005-09-07 06:17:15 +08:00
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
|
2018-09-27 05:50:18 +08:00
|
|
|
if ((pos + count) > max_smi_data_buf_size)
|
2006-10-20 14:29:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_lock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
ret = smi_data_buf_realloc(pos + count);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
memcpy(smi_data_buf + pos, buf, count);
|
|
|
|
ret = count;
|
|
|
|
out:
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_unlock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t host_control_action_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%u\n", host_control_action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t host_control_action_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
/* make sure buffer is available for host control command */
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_lock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
ret = smi_data_buf_realloc(sizeof(struct apm_cmd));
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_unlock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
host_control_action = simple_strtoul(buf, NULL, 10);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t host_control_smi_type_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%u\n", host_control_smi_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t host_control_smi_type_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
host_control_smi_type = simple_strtoul(buf, NULL, 10);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t host_control_on_shutdown_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%u\n", host_control_on_shutdown);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t host_control_on_shutdown_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
host_control_on_shutdown = simple_strtoul(buf, NULL, 10);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:48:46 +08:00
|
|
|
static int raise_smi(void *par)
|
2005-09-07 06:17:15 +08:00
|
|
|
{
|
2016-08-29 14:48:46 +08:00
|
|
|
struct smi_cmd *smi_cmd = par;
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
if (smp_processor_id() != 0) {
|
|
|
|
dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n",
|
2008-04-29 15:59:19 +08:00
|
|
|
__func__);
|
2016-08-29 14:48:46 +08:00
|
|
|
return -EBUSY;
|
2005-09-07 06:17:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* generate SMI */
|
2011-03-02 20:42:05 +08:00
|
|
|
/* inb to force posted write through and make SMI happen now */
|
2005-09-07 06:17:15 +08:00
|
|
|
asm volatile (
|
2011-03-02 20:42:05 +08:00
|
|
|
"outb %b0,%w1\n"
|
|
|
|
"inb %w1"
|
2005-09-07 06:17:15 +08:00
|
|
|
: /* no output args */
|
|
|
|
: "a" (smi_cmd->command_code),
|
|
|
|
"d" (smi_cmd->command_address),
|
|
|
|
"b" (smi_cmd->ebx),
|
|
|
|
"c" (smi_cmd->ecx)
|
|
|
|
: "memory"
|
|
|
|
);
|
|
|
|
|
2016-08-29 14:48:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* dcdbas_smi_request: generate SMI request
|
|
|
|
*
|
|
|
|
* Called with smi_data_lock.
|
|
|
|
*/
|
|
|
|
int dcdbas_smi_request(struct smi_cmd *smi_cmd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (smi_cmd->magic != SMI_CMD_MAGIC) {
|
|
|
|
dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
|
|
|
|
__func__);
|
|
|
|
return -EBADR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SMI requires CPU 0 */
|
|
|
|
get_online_cpus();
|
|
|
|
ret = smp_call_on_cpu(0, raise_smi, smi_cmd, true);
|
|
|
|
put_online_cpus();
|
|
|
|
|
2005-09-07 06:17:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* smi_request_store:
|
|
|
|
*
|
|
|
|
* The valid values are:
|
|
|
|
* 0: zero SMI data buffer
|
|
|
|
* 1: generate calling interface SMI
|
|
|
|
* 2: generate raw SMI
|
|
|
|
*
|
|
|
|
* User application writes smi_cmd to smi_data before telling driver
|
|
|
|
* to generate SMI.
|
|
|
|
*/
|
|
|
|
static ssize_t smi_request_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct smi_cmd *smi_cmd;
|
|
|
|
unsigned long val = simple_strtoul(buf, NULL, 10);
|
|
|
|
ssize_t ret;
|
|
|
|
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_lock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
if (smi_data_buf_size < sizeof(struct smi_cmd)) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
smi_cmd = (struct smi_cmd *)smi_data_buf;
|
|
|
|
|
|
|
|
switch (val) {
|
|
|
|
case 2:
|
|
|
|
/* Raw SMI */
|
2009-01-08 10:08:54 +08:00
|
|
|
ret = dcdbas_smi_request(smi_cmd);
|
2005-09-07 06:17:15 +08:00
|
|
|
if (!ret)
|
|
|
|
ret = count;
|
|
|
|
break;
|
|
|
|
case 1:
|
2018-09-27 05:50:18 +08:00
|
|
|
/*
|
|
|
|
* Calling Interface SMI
|
|
|
|
*
|
|
|
|
* Provide physical address of command buffer field within
|
|
|
|
* the struct smi_cmd to BIOS.
|
|
|
|
*
|
|
|
|
* Because the address that smi_cmd (smi_data_buf) points to
|
|
|
|
* will be from memremap() of a non-memory address if WSMT
|
|
|
|
* is present, we can't use virt_to_phys() on smi_cmd, so
|
|
|
|
* we have to use the physical address that was saved when
|
|
|
|
* the virtual address for smi_cmd was received.
|
|
|
|
*/
|
|
|
|
smi_cmd->ebx = smi_data_buf_phys_addr +
|
|
|
|
offsetof(struct smi_cmd, command_buffer);
|
2009-01-08 10:08:54 +08:00
|
|
|
ret = dcdbas_smi_request(smi_cmd);
|
2005-09-07 06:17:15 +08:00
|
|
|
if (!ret)
|
|
|
|
ret = count;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
memset(smi_data_buf, 0, smi_data_buf_size);
|
|
|
|
ret = count;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2006-03-23 19:00:21 +08:00
|
|
|
mutex_unlock(&smi_data_lock);
|
2005-09-07 06:17:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2009-01-08 10:08:54 +08:00
|
|
|
EXPORT_SYMBOL(dcdbas_smi_request);
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* host_control_smi: generate host control SMI
|
|
|
|
*
|
|
|
|
* Caller must set up the host control command in smi_data_buf.
|
|
|
|
*/
|
|
|
|
static int host_control_smi(void)
|
|
|
|
{
|
|
|
|
struct apm_cmd *apm_cmd;
|
|
|
|
u8 *data;
|
|
|
|
unsigned long flags;
|
|
|
|
u32 num_ticks;
|
|
|
|
s8 cmd_status;
|
|
|
|
u8 index;
|
|
|
|
|
|
|
|
apm_cmd = (struct apm_cmd *)smi_data_buf;
|
|
|
|
apm_cmd->status = ESM_STATUS_CMD_UNSUCCESSFUL;
|
|
|
|
|
|
|
|
switch (host_control_smi_type) {
|
|
|
|
case HC_SMITYPE_TYPE1:
|
|
|
|
spin_lock_irqsave(&rtc_lock, flags);
|
|
|
|
/* write SMI data buffer physical address */
|
|
|
|
data = (u8 *)&smi_data_buf_phys_addr;
|
|
|
|
for (index = PE1300_CMOS_CMD_STRUCT_PTR;
|
|
|
|
index < (PE1300_CMOS_CMD_STRUCT_PTR + 4);
|
|
|
|
index++, data++) {
|
|
|
|
outb(index,
|
|
|
|
(CMOS_BASE_PORT + CMOS_PAGE2_INDEX_PORT_PIIX4));
|
|
|
|
outb(*data,
|
|
|
|
(CMOS_BASE_PORT + CMOS_PAGE2_DATA_PORT_PIIX4));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first set status to -1 as called by spec */
|
|
|
|
cmd_status = ESM_STATUS_CMD_UNSUCCESSFUL;
|
|
|
|
outb((u8) cmd_status, PCAT_APM_STATUS_PORT);
|
|
|
|
|
|
|
|
/* generate SMM call */
|
|
|
|
outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
|
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
|
|
|
|
|
|
|
/* wait a few to see if it executed */
|
|
|
|
num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
|
|
|
|
while ((cmd_status = inb(PCAT_APM_STATUS_PORT))
|
|
|
|
== ESM_STATUS_CMD_UNSUCCESSFUL) {
|
|
|
|
num_ticks--;
|
|
|
|
if (num_ticks == EXPIRED_TIMER)
|
|
|
|
return -ETIME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HC_SMITYPE_TYPE2:
|
|
|
|
case HC_SMITYPE_TYPE3:
|
|
|
|
spin_lock_irqsave(&rtc_lock, flags);
|
|
|
|
/* write SMI data buffer physical address */
|
|
|
|
data = (u8 *)&smi_data_buf_phys_addr;
|
|
|
|
for (index = PE1400_CMOS_CMD_STRUCT_PTR;
|
|
|
|
index < (PE1400_CMOS_CMD_STRUCT_PTR + 4);
|
|
|
|
index++, data++) {
|
|
|
|
outb(index, (CMOS_BASE_PORT + CMOS_PAGE1_INDEX_PORT));
|
|
|
|
outb(*data, (CMOS_BASE_PORT + CMOS_PAGE1_DATA_PORT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* generate SMM call */
|
|
|
|
if (host_control_smi_type == HC_SMITYPE_TYPE3)
|
|
|
|
outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
|
|
|
|
else
|
|
|
|
outb(ESM_APM_CMD, PE1400_APM_CONTROL_PORT);
|
|
|
|
|
|
|
|
/* restore RTC index pointer since it was written to above */
|
|
|
|
CMOS_READ(RTC_REG_C);
|
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
|
|
|
|
|
|
|
/* read control port back to serialize write */
|
|
|
|
cmd_status = inb(PE1400_APM_CONTROL_PORT);
|
|
|
|
|
|
|
|
/* wait a few to see if it executed */
|
|
|
|
num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
|
|
|
|
while (apm_cmd->status == ESM_STATUS_CMD_UNSUCCESSFUL) {
|
|
|
|
num_ticks--;
|
|
|
|
if (num_ticks == EXPIRED_TIMER)
|
|
|
|
return -ETIME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_dbg(&dcdbas_pdev->dev, "%s: invalid SMI type %u\n",
|
2008-04-29 15:59:19 +08:00
|
|
|
__func__, host_control_smi_type);
|
2005-09-07 06:17:15 +08:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dcdbas_host_control: initiate host control
|
|
|
|
*
|
|
|
|
* This function is called by the driver after the system has
|
|
|
|
* finished shutting down if the user application specified a
|
|
|
|
* host control action to perform on shutdown. It is safe to
|
|
|
|
* use smi_data_buf at this point because the system has finished
|
|
|
|
* shutting down and no userspace apps are running.
|
|
|
|
*/
|
|
|
|
static void dcdbas_host_control(void)
|
|
|
|
{
|
|
|
|
struct apm_cmd *apm_cmd;
|
|
|
|
u8 action;
|
|
|
|
|
|
|
|
if (host_control_action == HC_ACTION_NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
action = host_control_action;
|
|
|
|
host_control_action = HC_ACTION_NONE;
|
|
|
|
|
|
|
|
if (!smi_data_buf) {
|
2008-04-29 15:59:19 +08:00
|
|
|
dev_dbg(&dcdbas_pdev->dev, "%s: no SMI buffer\n", __func__);
|
2005-09-07 06:17:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (smi_data_buf_size < sizeof(struct apm_cmd)) {
|
|
|
|
dev_dbg(&dcdbas_pdev->dev, "%s: SMI buffer too small\n",
|
2008-04-29 15:59:19 +08:00
|
|
|
__func__);
|
2005-09-07 06:17:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
apm_cmd = (struct apm_cmd *)smi_data_buf;
|
|
|
|
|
|
|
|
/* power off takes precedence */
|
|
|
|
if (action & HC_ACTION_HOST_CONTROL_POWEROFF) {
|
|
|
|
apm_cmd->command = ESM_APM_POWER_CYCLE;
|
|
|
|
apm_cmd->reserved = 0;
|
|
|
|
*((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 0;
|
|
|
|
host_control_smi();
|
|
|
|
} else if (action & HC_ACTION_HOST_CONTROL_POWERCYCLE) {
|
|
|
|
apm_cmd->command = ESM_APM_POWER_CYCLE;
|
|
|
|
apm_cmd->reserved = 0;
|
|
|
|
*((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 20;
|
|
|
|
host_control_smi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 05:50:18 +08:00
|
|
|
/* WSMT */
|
|
|
|
|
|
|
|
static u8 checksum(u8 *buffer, u8 length)
|
|
|
|
{
|
|
|
|
u8 sum = 0;
|
|
|
|
u8 *end = buffer + length;
|
|
|
|
|
|
|
|
while (buffer < end)
|
|
|
|
sum += *buffer++;
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct smm_eps_table *check_eps_table(u8 *addr)
|
|
|
|
{
|
|
|
|
struct smm_eps_table *eps = (struct smm_eps_table *)addr;
|
|
|
|
|
|
|
|
if (strncmp(eps->smm_comm_buff_anchor, SMM_EPS_SIG, 4) != 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (checksum(addr, eps->length) != 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return eps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dcdbas_check_wsmt(void)
|
|
|
|
{
|
|
|
|
struct acpi_table_wsmt *wsmt = NULL;
|
|
|
|
struct smm_eps_table *eps = NULL;
|
|
|
|
u64 remap_size;
|
|
|
|
u8 *addr;
|
|
|
|
|
|
|
|
acpi_get_table(ACPI_SIG_WSMT, 0, (struct acpi_table_header **)&wsmt);
|
|
|
|
if (!wsmt)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Check if WSMT ACPI table shows that protection is enabled */
|
|
|
|
if (!(wsmt->protection_flags & ACPI_WSMT_FIXED_COMM_BUFFERS) ||
|
|
|
|
!(wsmt->protection_flags & ACPI_WSMT_COMM_BUFFER_NESTED_PTR_PROTECTION))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Scan for EPS (entry point structure) */
|
|
|
|
for (addr = (u8 *)__va(0xf0000);
|
|
|
|
addr < (u8 *)__va(0x100000 - sizeof(struct smm_eps_table));
|
|
|
|
addr += 16) {
|
|
|
|
eps = check_eps_table(addr);
|
|
|
|
if (eps)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eps) {
|
|
|
|
dev_dbg(&dcdbas_pdev->dev, "found WSMT, but no EPS found\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get physical address of buffer and map to virtual address.
|
|
|
|
* Table gives size in 4K pages, regardless of actual system page size.
|
|
|
|
*/
|
|
|
|
if (upper_32_bits(eps->smm_comm_buff_addr + 8)) {
|
|
|
|
dev_warn(&dcdbas_pdev->dev, "found WSMT, but EPS buffer address is above 4GB\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Limit remap size to MAX_SMI_DATA_BUF_SIZE + 8 (since the first 8
|
|
|
|
* bytes are used for a semaphore, not the data buffer itself).
|
|
|
|
*/
|
|
|
|
remap_size = eps->num_of_4k_pages * PAGE_SIZE;
|
|
|
|
if (remap_size > MAX_SMI_DATA_BUF_SIZE + 8)
|
|
|
|
remap_size = MAX_SMI_DATA_BUF_SIZE + 8;
|
|
|
|
eps_buffer = memremap(eps->smm_comm_buff_addr, remap_size, MEMREMAP_WB);
|
|
|
|
if (!eps_buffer) {
|
|
|
|
dev_warn(&dcdbas_pdev->dev, "found WSMT, but failed to map EPS buffer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First 8 bytes is for a semaphore, not part of the smi_data_buf */
|
|
|
|
smi_data_buf_phys_addr = eps->smm_comm_buff_addr + 8;
|
|
|
|
smi_data_buf = eps_buffer + 8;
|
|
|
|
smi_data_buf_size = remap_size - 8;
|
|
|
|
max_smi_data_buf_size = smi_data_buf_size;
|
|
|
|
wsmt_enabled = true;
|
|
|
|
dev_info(&dcdbas_pdev->dev,
|
|
|
|
"WSMT found, using firmware-provided SMI buffer.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-09-07 06:17:15 +08:00
|
|
|
/**
|
|
|
|
* dcdbas_reboot_notify: handle reboot notification for host control
|
|
|
|
*/
|
|
|
|
static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
|
|
|
|
void *unused)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case SYS_DOWN:
|
|
|
|
case SYS_HALT:
|
|
|
|
case SYS_POWER_OFF:
|
|
|
|
if (host_control_on_shutdown) {
|
|
|
|
/* firmware is going to perform host control action */
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
printk(KERN_WARNING "Please wait for shutdown "
|
|
|
|
"action to complete...\n");
|
|
|
|
dcdbas_host_control();
|
2005-09-07 06:17:15 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block dcdbas_reboot_nb = {
|
|
|
|
.notifier_call = dcdbas_reboot_notify,
|
|
|
|
.next = NULL,
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
.priority = INT_MIN
|
2005-09-07 06:17:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static DCDBAS_BIN_ATTR_RW(smi_data);
|
|
|
|
|
|
|
|
static struct bin_attribute *dcdbas_bin_attrs[] = {
|
|
|
|
&bin_attr_smi_data,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static DCDBAS_DEV_ATTR_RW(smi_data_buf_size);
|
|
|
|
static DCDBAS_DEV_ATTR_RO(smi_data_buf_phys_addr);
|
|
|
|
static DCDBAS_DEV_ATTR_WO(smi_request);
|
|
|
|
static DCDBAS_DEV_ATTR_RW(host_control_action);
|
|
|
|
static DCDBAS_DEV_ATTR_RW(host_control_smi_type);
|
|
|
|
static DCDBAS_DEV_ATTR_RW(host_control_on_shutdown);
|
|
|
|
|
2006-03-22 16:07:56 +08:00
|
|
|
static struct attribute *dcdbas_dev_attrs[] = {
|
|
|
|
&dev_attr_smi_data_buf_size.attr,
|
|
|
|
&dev_attr_smi_data_buf_phys_addr.attr,
|
|
|
|
&dev_attr_smi_request.attr,
|
|
|
|
&dev_attr_host_control_action.attr,
|
|
|
|
&dev_attr_host_control_smi_type.attr,
|
|
|
|
&dev_attr_host_control_on_shutdown.attr,
|
2005-09-07 06:17:15 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-08-19 03:49:45 +08:00
|
|
|
static const struct attribute_group dcdbas_attr_group = {
|
2006-03-22 16:07:56 +08:00
|
|
|
.attrs = dcdbas_dev_attrs,
|
2013-08-21 08:17:57 +08:00
|
|
|
.bin_attrs = dcdbas_bin_attrs,
|
2006-03-22 16:07:56 +08:00
|
|
|
};
|
|
|
|
|
2012-12-22 07:14:44 +08:00
|
|
|
static int dcdbas_probe(struct platform_device *dev)
|
2005-09-07 06:17:15 +08:00
|
|
|
{
|
2013-08-21 08:17:57 +08:00
|
|
|
int error;
|
2005-09-07 06:17:15 +08:00
|
|
|
|
|
|
|
host_control_action = HC_ACTION_NONE;
|
|
|
|
host_control_smi_type = HC_SMITYPE_NONE;
|
|
|
|
|
2013-06-27 21:14:43 +08:00
|
|
|
dcdbas_pdev = dev;
|
|
|
|
|
2018-09-27 05:50:18 +08:00
|
|
|
/* Check if ACPI WSMT table specifies protected SMI buffer address */
|
|
|
|
error = dcdbas_check_wsmt();
|
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
|
2005-09-07 06:17:15 +08:00
|
|
|
/*
|
|
|
|
* BIOS SMI calls require buffer addresses be in 32-bit address space.
|
|
|
|
* This is done by setting the DMA mask below.
|
|
|
|
*/
|
2013-06-27 21:14:43 +08:00
|
|
|
error = dma_set_coherent_mask(&dcdbas_pdev->dev, DMA_BIT_MASK(32));
|
|
|
|
if (error)
|
|
|
|
return error;
|
2005-09-07 06:17:15 +08:00
|
|
|
|
2006-03-22 16:07:56 +08:00
|
|
|
error = sysfs_create_group(&dev->dev.kobj, &dcdbas_attr_group);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2005-09-07 06:17:15 +08:00
|
|
|
register_reboot_notifier(&dcdbas_reboot_nb);
|
|
|
|
|
2006-03-22 16:07:56 +08:00
|
|
|
dev_info(&dev->dev, "%s (version %s)\n",
|
|
|
|
DRIVER_DESCRIPTION, DRIVER_VERSION);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 07:14:44 +08:00
|
|
|
static int dcdbas_remove(struct platform_device *dev)
|
2006-03-22 16:07:56 +08:00
|
|
|
{
|
|
|
|
unregister_reboot_notifier(&dcdbas_reboot_nb);
|
|
|
|
sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
|
2005-09-07 06:17:15 +08:00
|
|
|
|
2006-03-22 16:07:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-09-07 06:17:15 +08:00
|
|
|
|
2006-03-22 16:07:56 +08:00
|
|
|
static struct platform_driver dcdbas_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
},
|
|
|
|
.probe = dcdbas_probe,
|
2012-12-22 07:14:44 +08:00
|
|
|
.remove = dcdbas_remove,
|
2006-03-22 16:07:56 +08:00
|
|
|
};
|
|
|
|
|
2014-02-08 15:52:09 +08:00
|
|
|
static const struct platform_device_info dcdbas_dev_info __initconst = {
|
2013-06-27 21:14:43 +08:00
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.id = -1,
|
|
|
|
.dma_mask = DMA_BIT_MASK(32),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *dcdbas_pdev_reg;
|
|
|
|
|
2006-03-22 16:07:56 +08:00
|
|
|
/**
|
|
|
|
* dcdbas_init: initialize driver
|
|
|
|
*/
|
|
|
|
static int __init dcdbas_init(void)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = platform_driver_register(&dcdbas_driver);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2013-06-27 21:14:43 +08:00
|
|
|
dcdbas_pdev_reg = platform_device_register_full(&dcdbas_dev_info);
|
|
|
|
if (IS_ERR(dcdbas_pdev_reg)) {
|
|
|
|
error = PTR_ERR(dcdbas_pdev_reg);
|
2006-03-22 16:07:56 +08:00
|
|
|
goto err_unregister_driver;
|
|
|
|
}
|
|
|
|
|
2005-09-07 06:17:15 +08:00
|
|
|
return 0;
|
2006-03-22 16:07:56 +08:00
|
|
|
|
|
|
|
err_unregister_driver:
|
|
|
|
platform_driver_unregister(&dcdbas_driver);
|
|
|
|
return error;
|
2005-09-07 06:17:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dcdbas_exit: perform driver cleanup
|
|
|
|
*/
|
|
|
|
static void __exit dcdbas_exit(void)
|
|
|
|
{
|
2006-03-10 09:33:35 +08:00
|
|
|
/*
|
|
|
|
* make sure functions that use dcdbas_pdev are called
|
|
|
|
* before platform_device_unregister
|
|
|
|
*/
|
2005-09-07 06:17:15 +08:00
|
|
|
unregister_reboot_notifier(&dcdbas_reboot_nb);
|
2006-03-22 16:07:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to free the buffer here instead of dcdbas_remove
|
|
|
|
* because only in module exit function we can be sure that
|
|
|
|
* all sysfs attributes belonging to this module have been
|
|
|
|
* released.
|
|
|
|
*/
|
2013-06-27 21:14:43 +08:00
|
|
|
if (dcdbas_pdev)
|
|
|
|
smi_data_buf_free();
|
2018-09-27 05:50:18 +08:00
|
|
|
if (eps_buffer)
|
|
|
|
memunmap(eps_buffer);
|
2013-06-27 21:14:43 +08:00
|
|
|
platform_device_unregister(dcdbas_pdev_reg);
|
2010-07-05 09:35:47 +08:00
|
|
|
platform_driver_unregister(&dcdbas_driver);
|
2005-09-07 06:17:15 +08:00
|
|
|
}
|
|
|
|
|
2018-03-13 14:28:00 +08:00
|
|
|
subsys_initcall_sync(dcdbas_init);
|
2005-09-07 06:17:15 +08:00
|
|
|
module_exit(dcdbas_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")");
|
|
|
|
MODULE_VERSION(DRIVER_VERSION);
|
|
|
|
MODULE_AUTHOR("Dell Inc.");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-02-06 17:36:24 +08:00
|
|
|
/* Any System or BIOS claiming to be by Dell */
|
|
|
|
MODULE_ALIAS("dmi:*:[bs]vnD[Ee][Ll][Ll]*:*");
|