add Dell Systems Management Base Driver (dcdbas) with sysfs support
RFC PATCH 1/1 add Dell Systems Management Base Driver (dcdbas) with sysfs support
This patch adds the Dell Systems Management Base Driver with sysfs support.
This driver has been tested with Dell OpenManage.
---
Documentation/dcdbas.txt +71 -0
@@ -0,0 +1,71 @@ +Overview + +The Dell Systems Management Base Driver provides a sysfs interface for +systems management software such as Dell OpenManage to perform system +management interrupts and host control actions (system power cycle or +power off after OS shutdown) on certain Dell systems. + +Dell OpenManage requires this driver on the following Dell PowerEdge systems: +300, 1300, 1400, 400SC, 500SC, 1500SC, 1550, 600SC, 1600SC, 650, 1655MC, +700, and 750. Other Dell software such as the open source Libsmbios library +is expected to make use of this driver, and it may include use on other Dell +systems. + + +System Management Interrupt + +On some Dell systems, systems management software must access certain +management information via a system management interrupt (SMI). The SMI data +buffer must reside in 32-bit address space, and the physical address of the +buffer is required for the SMI. The driver maintains the memory required for +the SMI and provides a way for the application to generate the SMI. +The driver creates the following sysfs entries for systems management +software to perform these system management interrupts: + +/sys/devices/platform/dcdbas/smi_data +/sys/devices/platform/dcdbas/smi_data_buf_phys_addr +/sys/devices/platform/dcdbas/smi_data_buf_size +/sys/devices/platform/dcdbas/callintf_smi + +Systems management software must perform the following steps to execute +a SMI using this driver: + +1) Lock smi_data. +2) Determine buffer size needed for system management command. +3) Write buffer size needed to smi_data_buf_size. + (Driver will ensure that its SMI data buffer is at least that size.) +4) If physical address of SMI data buffer is needed to set up system + management command, read physical address from smi_data_buf_phys_addr + and add to command data. +5) Write system management command to smi_data. +6) Write "1" to callintf_smi to generate a calling interface SMI. +7) Read system management command response from smi_data. +8) Unlock smi_data. + + +Host Control Action + +Dell OpenManage supports a host control feature that allows the administrator +to perform a power cycle or power off of the system after the OS has finished +shutting down. On some Dell systems, this host control feature requires that +a driver perform a SMI after the OS has finished shutting down. + +The driver creates the following sysfs entries for systems management software +to schedule the driver to perform a power cycle or power off host control +action after the system has finished shutting down: + +/sys/devices/platform/dcdbas/host_control_action +/sys/devices/platform/dcdbas/host_control_smi_type +/sys/devices/platform/dcdbas/host_control_on_shutdown + +Dell OpenManage performs the following steps to execute a power cycle or +power off host control action using this driver: + +1) Write host control action to be performed to host_control_action. +2) Write type of SMI that driver needs to perform to host_control_smi_type. +3) Write "1" to host_control_on_shutdown to enable host control action. +4) Initiate OS shutdown. + (Driver will perform host control SMI when it is notified that the OS + has finished shutting down.) + +
drivers/firmware/dcdbas.c +601 -0
601 lines not on this page · raw message
drivers/firmware/dcdbas.h +106 -0
106 lines not on this page · raw message
drivers/firmware/Kconfig +17 -0
@@ -58,4 +58,21 @@ config EFI_PCDP See <http://www.dig64.org/specifications/DIG64_HCDPv20_042804.pdf> +config DCDBAS + tristate "Dell Systems Management Base Driver" + depends on X86 || X86_64 + default m + help + The Dell Systems Management Base Driver provides a sysfs interface + for systems management software to perform System Management + Interrupts (SMIs) and Host Control Actions (system power cycle or + power off after OS shutdown) on certain Dell systems. + + See <file:Documentation/dcdbas.txt> for more details on the driver + and the Dell systems on which Dell systems management software makes + use of this driver. + + Say Y or M here to enable the driver for use by Dell systems + management software such as Dell OpenManage. + endmenu
drivers/firmware/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_EDD) += edd.o obj-$(CONFIG_EFI_VARS) += efivars.o obj-$(CONFIG_EFI_PCDP) += pcdp.o +obj-$(CONFIG_DCDBAS) += dcdbas.o
MAINTAINERS +5 -0
@@ -696,6 +696,11 @@ M: [email protected] W: http://www.debian.org/~dz/i8k/ S: Maintained +DELL SYSTEMS MANAGEMENT BASE DRIVER (dcdbas) +P: Doug Warzecha +M: [email protected] +S: Maintained + DEVICE-MAPPER P: Alasdair Kergon L: [email protected]
Documentation/dcdbas.txt line 23
Quoted 12 lines · Doug Warzecha
This patch adds the Dell Systems Management Base Driver with sysfs support.
(quoted diff) +2
-0+On some Dell systems, systems management software must access certain +management information via a system management interrupt (SMI).The SMI data
+buffer must reside in 32-bit address space, and the physical address of the
+buffer is required for the SMI. The driver maintains the memory required forDocumentation/dcdbas.txt +3
-0+the SMI and provides a way for the application to generate the SMI. +The driver creates the following sysfs entries for systems management +software to perform these system management interrupts:
Why can't you just implement the system management actions in the kernel driver? This is tantamount to a binary SMI hook to userspace. What functionality does this provide on a dell system from an administrator's point of view?
Quoted 14 lines
Documentation/dcdbas.txt +3
-0+Host Control Action + +Dell OpenManage supports a host control feature that allows theadministrator
+to perform a power cycle or power off of the system after the OS has finished
+shutting down. On some Dell systems, this host control feature requires thatDocumentation/dcdbas.txt +3
-0+a driver perform a SMI after the OS has finished shutting down. + +The driver creates the following sysfs entries for systemsmanagement software
+to schedule the driver to perform a power cycle or power off host control
Documentation/dcdbas.txt line 59
Quoted 5 lines
Documentation/dcdbas.txt +5
-0+action after the system has finished shutting down: + +/sys/devices/platform/dcdbas/host_control_action +/sys/devices/platform/dcdbas/host_control_smi_type +/sys/devices/platform/dcdbas/host_control_on_shutdown
How is this different from shutdown() or reboot()? What exactly is smi_type used for? Please provide better documentation on how to use this and what it does.
If this is supposed to be used with the RBU code to trigger a BIOS update, then why not integrate it into one kernel driver that receives firmware, loads it into the BIOS, and properly resets the machine at powerdown? I think PowerPC does a similar thing with OpenFirmware flash memory. When I change the default boot device or other firmware environment, I get a message from the kernel upon shutdown:
Erasing <BRAND> flash bank 1...
Writing <BRAND> flash bank 1...
Would not a similar system work for Dell? It would be far simpler to use than the current mess of patches you've proposed. If done properly, I could even do this:
cat firmware-with-checksum.img >/sys/devices/platform/dellbios/firmware_upgrade
Then an ordinary system reboot or shutdown would automatically use the SMI and host-control-action to upgrade the firmware and shutdown or reboot, instead of the normal ACPI shutdown and reboot code.
Cheers,
Kyle Moffett
--
Somone asked me why I work on this free (http://www.fsf.org/philosophy/)
software stuff and not get a real job. Charles Shultz had the best answer:
"Why do musicians compose symphonies and poets write poems? They do it because life wouldn't have any meaning for them if they didn't. That's why I draw cartoons. It's my life."
-- Charles Shultz
Quoted 4 lines · Kyle Moffett
Quoted 2 lines · Doug Warzecha
This patch adds the Dell Systems Management Base Driver with sysfs support.
Quoted 13 lines
Documentation/dcdbas.txt line 23
Quoted 10 lines
(quoted diff) +2
-0+On some Dell systems, systems management software must access certain +management information via a system management interrupt (SMI).The SMI data
+buffer must reside in 32-bit address space, and the physical address of the
+buffer is required for the SMI. The driver maintains the memory required forDocumentation/dcdbas.txt +3
-0+the SMI and provides a way for the application to generate the SMI. +The driver creates the following sysfs entries for systems management +software to perform these system management interrupts:Why can't you just implement the system management actions in the kernel driver?
We want to minimize the amount of code in the kernel and avoid having to update the driver each time a new system management command is added.
Quoted 3 lines
This is tantamount to a binary SMI hook to userspace. What functionality does this provide on a dell system from an administrator's point of view?
The libsmbios project is being updated to use this code. http://linux.dell.com/libsmbios/main/. Using the libsmbios code, you will be able to set all of the options in BIOS F2 screen from Linux userspace. Also, libsmbios is looking at implementing a few other things like fan status. Libsmbios is 100% open-source (OSL/GPL dual license).
Quoted 13 lines
Quoted 13 lines
Documentation/dcdbas.txt +3
-0+Host Control Action + +Dell OpenManage supports a host control feature that allows theadministrator
+to perform a power cycle or power off of the system after the OS has finished
+shutting down. On some Dell systems, this host control feature requires thatDocumentation/dcdbas.txt +3
-0+a driver perform a SMI after the OS has finished shutting down. + +The driver creates the following sysfs entries for systemsmanagement software
+to schedule the driver to perform a power cycle or power off host
Quoted 8 lines
Documentation/dcdbas.txt line 59
Quoted 6 lines
control
Documentation/dcdbas.txt +5
-0+action after the system has finished shutting down: + +/sys/devices/platform/dcdbas/host_control_action +/sys/devices/platform/dcdbas/host_control_smi_type +/sys/devices/platform/dcdbas/host_control_on_shutdownHow is this different from
shutdown()orreboot()?
The power cycle feature of the system powers off the system for a few seconds and then powers the system back on without user intervention. shutdown() and reboot() don't provide that feature.
Quoted 2 lines
What exactly is
smi_typeused for? Please provide better documentation on how to use this and what it does.
The method of generating a host control SMI is not exactly the same for each PowerEdge system listed in dcdbas.txt. host_control_smi_type tells the driver how to generate the host control SMI for the system in use. I'll update dcdbas.txt with the SMI type value associated with the systems listed in that file.
Quoted 2 lines
If this is supposed to be used with the RBU code to trigger a BIOS update, ...
This driver is not needed by the RBU code.
Doug
Quoted 6 lines · Doug Warzecha
Quoted 2 lines · Kyle Moffett
Why can't you just implement the system management actions in the kernel driver?
We want to minimize the amount of code in the kernel and avoid having to update the driver each time a new system management command is added.
One of the recent trends in kernel driver development is to make as much as possible accessible through standard tools (like with echo and cat via sysfs).
Quoted 4 lines
The libsmbios project is being updated to use this code. http://linux.dell.com/libsmbios/main/. Using the libsmbios code, you will be able to set all of the options in BIOS F2 screen from Linux
userspace. Also, libsmbios is looking at implementing a few other things
like fan status. Libsmbios is 100% open-source (OSL/GPL dual license).
From my point of view, this driver could use sysfs almost entirely and put all of the hardware-manipulation code completely in kernel space, along with the hardware detection code. You could have plain-text files in /sys/bus/platform/dellbios/ that have all of the BIOS F2 options accessible to the admin from the command line, without special tools. (You could always add an extra program that presents a BIOS-like interface)
Quoted 3 lines
The power cycle feature of the system powers off the system for a few seconds and then powers the system back on without user intervention.
shutdown()andreboot()don't provide that feature.
Please ensure that the code is only run on reboot (and maybe halt), but definitely not in the poweroff code.
Quoted 8 lines
Quoted 2 lines
What exactly is
smi_typeused for? Please provide better documentation on how to use this and what it does.The method of generating a host control SMI is not exactly the same for each PowerEdge system listed in dcdbas.txt.
host_control_smi_typetells the driver how to generate the host control SMI for the system in use. I'll update dcdbas.txt with the SMI type value associated with the systems listed in that file.
This is an _excellent_ reason why more of this should be in the kernel. What happens if the wrong SMI is used? Shouldn't it be relatively easy for the kernel to determine the correct SMI itself?
Thanks for your hard work!
Cheers,
Kyle Moffett
--
Unix was not designed to stop people from doing stupid things, because that would also stop them from doing clever things.
-- Doug Gwyn
Quoted 4 lines · Doug Warzecha
Quoted 2 lines
If this is supposed to be used with the RBU code to trigger a BIOS update, ...
This driver is not needed by the RBU code.
Documentation/dell_rbu.txt says:
Quoted 2 lines
The rbu driver needs to have an application which will inform the BIOS to enable the update in the next system reboot.
Can the dcdbas code be used to implement that application?
Quoted 2 lines · Kyle Moffett
Why can't you just implement the system management actions in the kernel driver?
Why put things in the kernel unless it's really needed?
I'm not thrillied about the lack of userspace support for this driver but that still doesn't mean we need to shovel wads of crap into the kernel.
Quoted 9 lines · Chris Wedgwood
Quoted 2 lines · Kyle Moffett
Why can't you just implement the system management actions in the kernel driver?
Why put things in the kernel unless it's really needed?
I'm not thrillied about the lack of userspace support for this driver but that still doesn't mean we need to shovel wads of crap into the kernel.
I'm worried that it might be more of a mess in userspace than it could be if done properly in the kernel. Hardware drivers, especially for something as critical as the BIOS, should probably be done in-kernel. Look at the mess that X has become, it mmaps /dev/mem and pokes at the PCI busses directly. I just don't want an MSI-driver to become another /dev/mem.
Cheers,
Kyle Moffett
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/U d- s++: a18 C++++>$ UB/L/X/*++++(+)>$ P+++(++++)>$ L++++(+++) E W++(+) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+ PGP+++ t+(+++) 5 X R? tv-(--) b++++(++) DI+ D+ G e->++++$ h!*()>++$ r !y?(-) ------END GEEK CODE BLOCK------
Quoted 2 lines · Kyle Moffett
I'm worried that it might be more of a mess in userspace than it could be if done properly in the kernel.
I would rather if it's gonna be a mess it's, then we put that mess in userspace rather than in the kernel.
Quoted 2 lines
Hardware drivers, especially for something as critical as the BIOS, should probably be done in-kernel.
For the most part it's not for the BIOS though AFAICT. It's for some hacky little microcontroller that controls fans and similar things that Dell won't give up details for.
Quoted 3 lines
Look at the mess that X has become, it mmaps
/dev/memand pokes at the PCI busses directly. I just don't want an MSI-driver to become another/dev/mem.
It's for old hardware, I'm not sure it will evolve much other than just for maintenance.
It's really hard to say, maybe if Dell gave more details about the userspace we would have a better idea?
Quoted 3 lines · Doug Warzecha
This patch adds the Dell Systems Management Base Driver with sysfs support.
This driver has been tested with Dell OpenManage.
Much better, but I still have a few questions:
Quoted 12 lines
Documentation/dcdbas.txt +12
-0+System Management Interrupt + +On some Dell systems, systems management software must access certain +management information via a system management interrupt (SMI). The SMI data +buffer must reside in 32-bit address space, and the physical address of the +buffer is required for the SMI. The driver maintains the memory required for +the SMI and provides a way for the application to generate the SMI. +The driver creates the following sysfs entries for systems management +software to perform these system management interrupts: + +/sys/devices/platform/dcdbas/smi_data +/sys/devices/platform/dcdbas/smi_data_buf_phys_addr
Documentation/dcdbas.txt line 36
Quoted 10 lines
Documentation/dcdbas.txt +10
-0+/sys/devices/platform/dcdbas/smi_data_buf_size +/sys/devices/platform/dcdbas/callintf_smi + +Systems management software must perform the following steps to execute +a SMI using this driver: + +1) Lock smi_data. +2) Determine buffer size needed for system management command. +3) Write buffer size needed to smi_data_buf_size. + (Driver will ensure that its SMI data buffer is at least that size.)
Why have this step? Why is it needed? Just go off of the size of the buffer that is written to smi_data. Or am I missing something?
Documentation/dcdbas.txt line 39
Quoted 3 lines
+4) If physical address of SMI data buffer is needed to set up system
Documentation/dcdbas.txt +2
-0+ management command, read physical address from smi_data_buf_phys_addr + and add to command data.
How do you know this?
Quoted 693 lines
+5) Write system management command to
smi_data.
+6) Write "1" tocallintf_smito generate a calling interface SMI. +7) Read system management command response fromsmi_data. +8) Unlocksmi_data.Documentation/dcdbas.txt +28
-0+ + +Host Control Action + +Dell OpenManage supports a host control feature that allows the administrator +to perform a power cycle or power off of the system after the OS has finished +shutting down. On some Dell systems, this host control feature requires that +a driver perform a SMI after the OS has finished shutting down. + +The driver creates the following sysfs entries for systems management software +to schedule the driver to perform a power cycle or power off host control +action after the system has finished shutting down: + +/sys/devices/platform/dcdbas/host_control_action +/sys/devices/platform/dcdbas/host_control_smi_type +/sys/devices/platform/dcdbas/host_control_on_shutdown + +Dell OpenManage performs the following steps to execute a power cycle or +power off host control action using this driver: + +1) Write host control action to be performed to host_control_action. +2) Write type of SMI that driver needs to perform to host_control_smi_type. +3) Write "1" to host_control_on_shutdown to enable host control action. +4) Initiate OS shutdown. + (Driver will perform host control SMI when it is notified that the OS + has finished shutting down.) + +diff -uprN
linux-2.6.13-rc6.orig/drivers/firmware/dcdbas.clinux-2.6.13-rc6/drivers/firmware/dcdbas.cdrivers/firmware/dcdbas.c +601
-0@@ -0,0 +1,601 @@ +/* +* 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. +* +* See Documentation/dcdbas.txt for more information. +* +* Copyright (C) 1995-2005 Dell Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License v2.0 as published by +* the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/errno.h> +#include <linux/init.h> +#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> +#include <asm/io.h> +#include <asm/semaphore.h> + +#include "dcdbas.h" + +#define DRIVER_NAME "dcdbas" +#define DRIVER_VERSION "5.6.0-1" +#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; +static u32 smi_data_buf_phys_addr; +static DECLARE_MUTEX (smi_data_lock); + +static unsigned int host_control_action; +static unsigned int host_control_smi_type; +static unsigned int host_control_on_shutdown; + +/** +* smi_data_buf_free: free SMI data buffer +*/ +static void smi_data_buf_free (void ) +{ +if (!smi_data_buf) +return ; + +dev_dbg (&dcdbas_pdev->dev,"%s: phys: %x size: %lu\n" , + __FUNCTION__, smi_data_buf_phys_addr, smi_data_buf_size); + +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; +int ret =0 ; + +if (size >MAX_SMI_DATA_BUF_SIZE ) +return -EINVAL ; + +down (&smi_data_lock); + +/* check if current buffer is big enough */ +if (smi_data_buf_size >= size) { +if (size && !smi_data_buf) { +dev_dbg (&dcdbas_pdev->dev, +"%s: corruption detected\n" , __FUNCTION__); + ret = -EFAULT ; + goto out; + } + +/* current buffer is big enough */ + goto out; + } + +/* 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" , + __FUNCTION__, size); + ret = -ENOMEM ; + goto out; + } +/* memory zeroed by dma_alloc_coherent */ + +/* 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" , + __FUNCTION__, smi_data_buf_phys_addr, smi_data_buf_size); +out: +up (&smi_data_lock); +return ret; +} + +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 */ + ret =smi_data_buf_realloc (buf_size); +if (ret) +return ret; + +return count; +} + +static ssize_t smi_data_read (struct kobject *kobj,char *buf,loff_t pos, +size_t count) +{ +size_t max_read; +ssize_t ret; + +down (&smi_data_lock); + +if (pos >= smi_data_buf_size) { + ret =0 ; + goto out; + } + + max_read = smi_data_buf_size - pos; + ret =min (max_read, count); +memcpy (buf, smi_data_buf + pos, ret); +out: +up (&smi_data_lock); +return ret; +} + +static ssize_t smi_data_write (struct kobject *kobj,char *buf,loff_t pos, +size_t count) +{ +size_t max_write; +ssize_t ret; + +down (&smi_data_lock); + +if (pos >= smi_data_buf_size) { + ret =0 ; + goto out; + } + + max_write = smi_data_buf_size - pos; + ret =min (max_write, count); +memcpy (smi_data_buf + pos, buf, ret); +out: +up (&smi_data_lock); +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 */ + ret =smi_data_buf_realloc (sizeof (struct apm_cmd )); +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; +} + +/** +* callintf_smi: generate calling interface SMI +*/ +static int callintf_smi (void ) +{ +struct callintf_cmd *ci_cmd; +cpumask_t old_mask; +u32 command_buffer_phys_addr; +int ret =0 ; + +/* SMI requires CPU 0 */ + old_mask = current->cpus_allowed; +set_cpus_allowed (current,cpumask_of_cpu (0 )); +if (smp_processor_id () !=0 ) { +dev_dbg (&dcdbas_pdev->dev,"%s: failed to get CPU 0\n" , + __FUNCTION__); + ret = -EBUSY ; + goto out1; + } + +down (&smi_data_lock); + +if (smi_data_buf_size <sizeof (struct callintf_cmd )) { + ret = -ENODEV ; + goto out2; + } + + ci_cmd = (struct callintf_cmd *)smi_data_buf; +if (ci_cmd->magic !=CALLINTF_CMD_MAGIC ) { + ret = -EBADR ; + goto out2; + } + +/* +* SMI requires command buffer physical address in ebx and +* command signature in ecx. +*/ + command_buffer_phys_addr = (u32 )virt_to_phys (ci_cmd->command_buffer); + +/* generate SMI */ + __asm__ __volatile__( +"outb %b0,%w1" + :/* no output args */ + :"a" (ci_cmd->command_code), +"d" (ci_cmd->command_address), +"b" (command_buffer_phys_addr), +"c" (ci_cmd->command_signature) + :"memory" + ); + +out2: +up (&smi_data_lock); +out1: +set_cpus_allowed (current, old_mask); +return ret; +} + +/** +* callintf_smi_store: +* +* The valid values are: +* 1: generate calling interface SMI +* +* User application writes calling interface command to smi_data +* before telling driver to generate SMI. +*/ +static ssize_t callintf_smi_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +int ret; + +if (simple_strtoul (buf,NULL ,10 ) !=1 ) +return -EINVAL ; + + ret =callintf_smi (); +if (ret) +return ret; + +return count; +} + +/** +* 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 : +/* write SMI data buffer physical address */ + data = (u8 *)&smi_data_buf_phys_addr; +spin_lock_irqsave (&rtc_lock, flags); +for (index =PE1300_CMOS_CMD_STRUCT_PTR ; + index < (PE1300_CMOS_CMD_STRUCT_PTR +4 ); + index++) { +outb (index, + (CMOS_BASE_PORT +CMOS_PAGE2_INDEX_PORT_PIIX4 )); +outb (*data++, + (CMOS_BASE_PORT +CMOS_PAGE2_DATA_PORT_PIIX4 )); + } +spin_unlock_irqrestore (&rtc_lock, flags); + +/* 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 ); + +/* restore RTC index pointer */ +spin_lock_irqsave (&rtc_lock, flags); +outb (0x0C ,0x70 ); +inb (0x70 ); +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 : +/* write SMI data buffer physical address */ + data = (u8 *)&smi_data_buf_phys_addr; +spin_lock_irqsave (&rtc_lock, flags); +for (index =PE1400_CMOS_CMD_STRUCT_PTR ; + index < (PE1400_CMOS_CMD_STRUCT_PTR +4 ); + index++) { +outb (index, (CMOS_BASE_PORT +CMOS_PAGE1_INDEX_PORT )); +outb (*data++, (CMOS_BASE_PORT +CMOS_PAGE1_DATA_PORT )); + } +spin_unlock_irqrestore (&rtc_lock, flags); + +/* 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 */ +spin_lock_irqsave (&rtc_lock, flags); +outb (0x0C ,0x70 ); +inb (0x70 ); +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" , + __FUNCTION__, host_control_smi_type); +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) { +dev_dbg (&dcdbas_pdev->dev,"%s: no SMI buffer\n" , __FUNCTION__); +return ; + } + +if (smi_data_buf_size <sizeof (struct apm_cmd )) { +dev_dbg (&dcdbas_pdev->dev,"%s: SMI buffer too small\n" , + __FUNCTION__); +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 (); + } +} + +/** +* dcdbas_reboot_notify: handle reboot notification for host control +*/ +static int dcdbas_reboot_notify (struct notifier_block *nb,unsigned long code, +void *unused) +{ +static unsigned int notify_cnt =0 ; + +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 */ +if (++notify_cnt ==2 ) { +printk (KERN_WARNING +"Please wait for shutdown " +"action to complete...\n" ); +dcdbas_host_control (); + } +/* +* register again and initiate the host control +* action on the second notification to allow +* everyone that registered to be notified +*/ +register_reboot_notifier (nb); + } +break ; + } + +return NOTIFY_DONE ; +} + +static struct notifier_block dcdbas_reboot_nb = { + .notifier_call = dcdbas_reboot_notify, + .next =NULL , + .priority =0 +}; + +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 (callintf_smi); +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); + +static struct device_attribute *dcdbas_dev_attrs[] = { + &dev_attr_smi_data_buf_size, + &dev_attr_smi_data_buf_phys_addr, + &dev_attr_callintf_smi, + &dev_attr_host_control_action, + &dev_attr_host_control_smi_type, + &dev_attr_host_control_on_shutdown, +NULL +}; + +/** +* dcdbas_init: initialize driver +*/ +static int __init dcdbas_init (void ) +{ +int i; + + host_control_action =HC_ACTION_NONE ; + host_control_smi_type =HC_SMITYPE_NONE ; + + dcdbas_pdev =platform_device_register_simple (DRIVER_NAME ,-1 ,NULL ,0 ); +if (IS_ERR (dcdbas_pdev)) +return PTR_ERR (dcdbas_pdev); + +/* +* BIOS SMI calls require buffer addresses be in 32-bit address space. +* This is done by setting the DMA mask below. +*/ + dcdbas_pdev->dev.coherent_dma_mask =DMA_32BIT_MASK ; + dcdbas_pdev->dev.dma_mask = &dcdbas_pdev->dev.coherent_dma_mask; + +register_reboot_notifier (&dcdbas_reboot_nb); + +for (i =0 ; dcdbas_bin_attrs[i]; i++) +sysfs_create_bin_file (&dcdbas_pdev->dev.kobj, + dcdbas_bin_attrs[i]); + +for (i =0 ; dcdbas_dev_attrs[i]; i++) +device_create_file (&dcdbas_pdev->dev, dcdbas_dev_attrs[i]); + +dev_info (&dcdbas_pdev->dev,"%s (version %s)\n" , +DRIVER_DESCRIPTION ,DRIVER_VERSION ); + +return 0 ; +} + +/** +* dcdbas_exit: perform driver cleanup +*/ +static void __exit dcdbas_exit(void) +{ +platform_device_unregister (dcdbas_pdev); +unregister_reboot_notifier (&dcdbas_reboot_nb); +smi_data_buf_free (); +} + +module_init (dcdbas_init); +module_exit (dcdbas_exit); + +MODULE_DESCRIPTION (DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")" ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_AUTHOR ("Dell Inc." ); +MODULE_LICENSE ("GPL" ); +diff -uprN
linux-2.6.13-rc6.orig/drivers/firmware/dcdbas.hlinux-2.6.13-rc6/drivers/firmware/dcdbas.hdrivers/firmware/dcdbas.h +52
-0@@ -0,0 +1,106 @@ +/* +* dcdbas.h: Definitions for Dell Systems Management Base driver +* +* Copyright (C) 1995-2005 Dell Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License v2.0 as published by +* the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _DCDBAS_H_ +#define _DCDBAS_H_ + +#include <linux/device.h> +#include <linux/input.h> +#include <linux/sysfs.h> +#include <linux/types.h> + +#define MAX_SMI_DATA_BUF_SIZE (256 * 1024) + +#define HC_ACTION_NONE (0) +#define HC_ACTION_HOST_CONTROL_POWEROFF BIT(1) +#define HC_ACTION_HOST_CONTROL_POWERCYCLE BIT(2) + +#define HC_SMITYPE_NONE (0) +#define HC_SMITYPE_TYPE1 (1) +#define HC_SMITYPE_TYPE2 (2) +#define HC_SMITYPE_TYPE3 (3) + +#define ESM_APM_CMD (0x0A0) +#define ESM_APM_POWER_CYCLE (0x10) +#define ESM_STATUS_CMD_UNSUCCESSFUL (-1) + +#define CMOS_BASE_PORT (0x070) +#define CMOS_PAGE1_INDEX_PORT (0) +#define CMOS_PAGE1_DATA_PORT (1) +#define CMOS_PAGE2_INDEX_PORT_PIIX4 (2) +#define CMOS_PAGE2_DATA_PORT_PIIX4 (3) +#define PE1400_APM_CONTROL_PORT (0x0B0) +#define PCAT_APM_CONTROL_PORT (0x0B2) +#define PCAT_APM_STATUS_PORT (0x0B3) +#define PE1300_CMOS_CMD_STRUCT_PTR (0x38) +#define PE1400_CMOS_CMD_STRUCT_PTR (0x70) + +#define MAX_SYSMGMT_SHORTCMD_PARMBUF_LEN (14) +#define MAX_SYSMGMT_LONGCMD_SGENTRY_NUM (16) +
drivers/firmware/dcdbas.h line 62
Quoted 10 lines
drivers/firmware/dcdbas.h +10
-0+#define TIMEOUT_USEC_SHORT_SEMA_BLOCKING (10000) +#define EXPIRED_TIMER (0) + +#define CALLINTF_CMD_MAGIC (0x43414C4C) + +#define DCDBAS_DEV_ATTR_RW (_name) \ + DEVICE_ATTR(_name,0644,_name##_show,_name##_store); + +#define DCDBAS_DEV_ATTR_RO (_name) \ + DEVICE_ATTR(_name,0444,_name##_show,NULL);
Why let all users read this data?
drivers/firmware/dcdbas.h line 70
Quoted 8 lines
drivers/firmware/dcdbas.h +8
-0+ +#define DCDBAS_DEV_ATTR_WO (_name) \ + DEVICE_ATTR(_name,0200,NULL,_name##_store); + +#define DCDBAS_BIN_ATTR_RW (_name) \ +struct bin_attribute bin_attr_##_name = { \ + .attr = { .name = __stringify(_name), \ + .mode = 0644, \
Why let everyone read this data?
drivers/firmware/dcdbas.h line 77
Quoted 7 lines
drivers/firmware/dcdbas.h +7
-0+ .owner = THIS_MODULE }, \ + .read = _name##_read, \ + .write = _name##_write, \ +} + +struct callintf_cmd { + u32 magic;
Why even have this? Does it really stop anything except random scribblings?
drivers/firmware/dcdbas.h line 83
Quoted 6 lines
drivers/firmware/dcdbas.h +6
-0+u16 command_address; +u8 command_code; +u8 reserved; +u32 command_signature; +u8 command_buffer[1 ]; +} __attribute__ ((packed));
As these cross the userspace/kernelspace boundry, please use the __u32, __u16, and __u8 variable types.
Quoted 9 lines
drivers/firmware/dcdbas.h +9
-0+struct apm_cmd { +u8 command; +s8 status; +u16 reserved; +union { +struct { +u8 parm[MAX_SYSMGMT_SHORTCMD_PARMBUF_LEN ]; + } __attribute__ ((packed)) shortreq; +
drivers/firmware/dcdbas.h line 103
Quoted 10 lines
drivers/firmware/dcdbas.h +10
-0+struct { +u16 num_sg_entries; +struct { +u32 size; +u64 addr; + } __attribute__ ((packed)) + sglist[MAX_SYSMGMT_LONGCMD_SGENTRY_NUM ]; + } __attribute__ ((packed)) longreq; + } __attribute__ ((packed)) parameters; +} __attribute__ ((packed));
Same here (I think...)
thanks,
greg k-h
Quoted 9 lines · Greg KH
Documentation/dcdbas.txt line 36
Quoted 5 lines · Doug Warzecha
Documentation/dcdbas.txt +5
-0+ +1) Lock smi_data. +2) Determine buffer size needed for system management command. +3) Write buffer size needed to smi_data_buf_size. + (Driver will ensure that its SMI data buffer is at least that size.)Why have this step? Why is it needed? Just go off of the size of the buffer that is written to
smi_data. Or am I missing something?
I'll change smi_data_write to do that.
Quoted 5 lines
Documentation/dcdbas.txt line 39
Quoted 3 lines
+4) If physical address of SMI data buffer is needed to set up system
Documentation/dcdbas.txt +2
-0+ management command, read physical address from smi_data_buf_phys_addr + and add to command data.How do you know this?
It depends on the SMI calling convention. Dell OpenManage needs the physical address for the SMI to get the ESM log on the PowerEdge systems listed in this doc.
Quoted 7 lines
drivers/firmware/dcdbas.h line 62
Quoted 5 lines
drivers/firmware/dcdbas.h +5
-0+#define DCDBAS_DEV_ATTR_RW (_name) \ + DEVICE_ATTR(_name,0644,_name##_show,_name##_store); + +#define DCDBAS_DEV_ATTR_RO (_name) \ + DEVICE_ATTR(_name,0444,_name##_show,NULL);Why let all users read this data?
Will be changed so that only owner can read.
Quoted 6 lines
drivers/firmware/dcdbas.h line 70
Quoted 4 lines
drivers/firmware/dcdbas.h +4
-0+#define DCDBAS_BIN_ATTR_RW (_name) \ +struct bin_attribute bin_attr_##_name = { \ + .attr = { .name = __stringify(_name), \ + .mode = 0644, \Why let everyone read this data?
Will be changed so that only owner can read.
Quoted 5 lines
drivers/firmware/dcdbas.h line 77
Quoted 2 lines
drivers/firmware/dcdbas.h +2
-0+struct callintf_cmd { +u32 magic;Why even have this? Does it really stop anything except random scribblings?
It's to stop random writing.
Quoted 9 lines
drivers/firmware/dcdbas.h line 83
Quoted 6 lines
drivers/firmware/dcdbas.h +6
-0+u16 command_address; +u8 command_code; +u8 reserved; +u32 command_signature; +u8 command_buffer[1 ]; +} __attribute__ ((packed));As these cross the userspace/kernelspace boundry, please use the
__u32,__u16, and__u8variable types.
Will be changed.
Quoted 13 lines
Quoted 13 lines
drivers/firmware/dcdbas.h +13
-0+struct apm_cmd { + u8 command; + s8 status; + u16 reserved; + union { + struct { + u8 parm[MAX_SYSMGMT_SHORTCMD_PARMBUF_LEN]; + } __attribute__ ((packed)) shortreq; + + struct { + u16 num_sg_entries; + struct { + u32 size;
Quoted 8 lines
drivers/firmware/dcdbas.h line 103
Quoted 6 lines
drivers/firmware/dcdbas.h +6
-0+u64 addr; + } __attribute__ ((packed)) + sglist[MAX_SYSMGMT_LONGCMD_SGENTRY_NUM]; + } __attribute__ ((packed)) longreq; + } __attribute__ ((packed)) parameters; +} __attribute__ ((packed));Same here (I think...)
Will be changed.
Doug