From 8fec62b2d9d0c80b594d0d85678bfdf57a70df1b Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Tue, 29 Jun 2010 10:07:09 +0200 Subject: acpi: use queue_work_on() instead of binding workqueue worker to cpu0 ACPI works need to be executed on cpu0 and acpi/osl.c achieves this by creating singlethread workqueue and then binding it to cpu0 from a work which is quite unorthodox. Make it create regular workqueues and use queue_work_on() instead. This is in preparation of concurrency managed workqueue and the extra workers won't be a problem after it's implemented. Signed-off-by: Tejun Heo --- drivers/acpi/osl.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 78418ce4fc7..46cce391fa4 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -191,36 +191,11 @@ acpi_status __init acpi_os_initialize(void) return AE_OK; } -static void bind_to_cpu0(struct work_struct *work) -{ - set_cpus_allowed_ptr(current, cpumask_of(0)); - kfree(work); -} - -static void bind_workqueue(struct workqueue_struct *wq) -{ - struct work_struct *work; - - work = kzalloc(sizeof(struct work_struct), GFP_KERNEL); - INIT_WORK(work, bind_to_cpu0); - queue_work(wq, work); -} - acpi_status acpi_os_initialize1(void) { - /* - * On some machines, a software-initiated SMI causes corruption unless - * the SMI runs on CPU 0. An SMI can be initiated by any AML, but - * typically it's done in GPE-related methods that are run via - * workqueues, so we can avoid the known corruption cases by binding - * the workqueues to CPU 0. - */ - kacpid_wq = create_singlethread_workqueue("kacpid"); - bind_workqueue(kacpid_wq); - kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify"); - bind_workqueue(kacpi_notify_wq); - kacpi_hotplug_wq = create_singlethread_workqueue("kacpi_hotplug"); - bind_workqueue(kacpi_hotplug_wq); + kacpid_wq = create_workqueue("kacpid"); + kacpi_notify_wq = create_workqueue("kacpi_notify"); + kacpi_hotplug_wq = create_workqueue("kacpi_hotplug"); BUG_ON(!kacpid_wq); BUG_ON(!kacpi_notify_wq); BUG_ON(!kacpi_hotplug_wq); @@ -766,7 +741,14 @@ static acpi_status __acpi_os_execute(acpi_execute_type type, else INIT_WORK(&dpc->work, acpi_os_execute_deferred); - ret = queue_work(queue, &dpc->work); + /* + * On some machines, a software-initiated SMI causes corruption unless + * the SMI runs on CPU 0. An SMI can be initiated by any AML, but + * typically it's done in GPE-related methods that are run via + * workqueues, so we can avoid the known corruption cases by always + * queueing on CPU 0. + */ + ret = queue_work_on(0, queue, &dpc->work); if (!ret) { printk(KERN_ERR PREFIX -- cgit v1.2.3 From 592913ecb87a9e06f98ddb55b298f1a66bf94c6b Mon Sep 17 00:00:00 2001 From: John Stultz Date: Tue, 13 Jul 2010 17:56:20 -0700 Subject: time: Kill off CONFIG_GENERIC_TIME Now that all arches have been converted over to use generic time via clocksources or arch_gettimeoffset(), we can remove the GENERIC_TIME config option and simplify the generic code. Signed-off-by: John Stultz LKML-Reference: <1279068988-21864-4-git-send-email-johnstul@us.ibm.com> Signed-off-by: Thomas Gleixner --- drivers/acpi/acpi_pad.c | 2 +- drivers/acpi/processor_idle.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c index 446aced33af..b76848c80be 100644 --- a/drivers/acpi/acpi_pad.c +++ b/drivers/acpi/acpi_pad.c @@ -77,7 +77,7 @@ static void power_saving_mwait_init(void) power_saving_mwait_eax = (highest_cstate << MWAIT_SUBSTATE_SIZE) | (highest_subcstate - 1); -#if defined(CONFIG_GENERIC_TIME) && defined(CONFIG_X86) +#if defined(CONFIG_X86) switch (boot_cpu_data.x86_vendor) { case X86_VENDOR_AMD: case X86_VENDOR_INTEL: diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index e9a8026d39f..294e10b5480 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -264,7 +264,7 @@ int acpi_processor_resume(struct acpi_device * device) return 0; } -#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86) +#if defined(CONFIG_X86) static void tsc_check_state(int state) { switch (boot_cpu_data.x86_vendor) { -- cgit v1.2.3 From 852972acff8f10f3a15679be2059bb94916cba5d Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Tue, 22 Jun 2010 11:25:43 -0400 Subject: ACPI: Disable ASPM if the platform won't provide _OSC control for PCIe The PCI SIG documentation for the _OSC OS/firmware handshaking interface states: "If the _OSC control method is absent from the scope of a host bridge device, then the operating system must not enable or attempt to use any features defined in this section for the hierarchy originated by the host bridge." The obvious interpretation of this is that the OS should not attempt to use PCIe hotplug, PME or AER - however, the specification also notes that an _OSC method is *required* for PCIe hierarchies, and experimental validation with An Alternative OS indicates that it doesn't use any PCIe functionality if the _OSC method is missing. That arguably means we shouldn't be using MSI or extended config space, but right now our problems seem to be limited to vendors being surprised when ASPM gets enabled on machines when other OSs refuse to do so. So, for now, let's just disable ASPM if the _OSC method doesn't exist or refuses to hand over PCIe capability control. Acked-by: Rafael J. Wysocki Signed-off-by: Matthew Garrett Signed-off-by: Jesse Barnes --- drivers/acpi/pci_root.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers/acpi') diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 4eac59393ed..1f67057af2a 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -543,6 +544,14 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device) if (flags != base_flags) acpi_pci_osc_support(root, flags); + status = acpi_pci_osc_control_set(root->device->handle, + OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); + + if (ACPI_FAILURE(status)) { + printk(KERN_INFO "Unable to assume PCIe control: Disabling ASPM\n"); + pcie_no_aspm(); + } + pci_acpi_add_bus_pm_notifier(device, root->bus); if (device->wakeup.flags.run_wake) device_set_run_wake(root->bus->bridge, true); -- cgit v1.2.3 From e8c534ec068af1a0845aceda373a9bfd2de62030 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Tue, 27 Jul 2010 18:53:35 +0200 Subject: x86: Fix keeping track of AMD C1E Accomodate the original C1E-aware idle routine to the different times during boot when the BIOS enables C1E. While at it, remove the synthetic CPUID flag in favor of a single global setting which denotes C1E status on the system. [ hpa: changed c1e_enabled to be a bool; clarified cpu bit 3:21 comment ] Signed-off-by: Michal Schmidt LKML-Reference: <20100727165335.GA11630@aftab> Signed-off-by: Borislav Petkov Signed-off-by: H. Peter Anvin Acked-by: Thomas Gleixner --- drivers/acpi/processor_idle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index e9a8026d39f..eead3f581fb 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -164,7 +164,7 @@ static void lapic_timer_check_state(int state, struct acpi_processor *pr, if (cpu_has(&cpu_data(pr->id), X86_FEATURE_ARAT)) return; - if (boot_cpu_has(X86_FEATURE_AMDC1E)) + if (c1e_detected) type = ACPI_STATE_C1; /* -- cgit v1.2.3 From 49c6c5ff924cecc0b6260109a510b7ed4c970dc5 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:34 +0200 Subject: ACPI: Remove /proc/acpi/embedded_controller/.. Other patches in this series add the same info to /sys/... and /proc/ioports. The info removed should never have been used in an application, eventually someone read it manually. /proc/acpi is deprecated for more than a year anyway... Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett --- drivers/acpi/ec.c | 81 +------------------------------------------------------ 1 file changed, 1 insertion(+), 80 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 5f2027d782e..ce1f07fd724 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -34,8 +34,6 @@ #include #include #include -#include -#include #include #include #include @@ -678,72 +676,6 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address, } } -/* -------------------------------------------------------------------------- - FS Interface (/proc) - -------------------------------------------------------------------------- */ - -static struct proc_dir_entry *acpi_ec_dir; - -static int acpi_ec_read_info(struct seq_file *seq, void *offset) -{ - struct acpi_ec *ec = seq->private; - - if (!ec) - goto end; - - seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe); - seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n", - (unsigned)ec->command_addr, (unsigned)ec->data_addr); - seq_printf(seq, "use global lock:\t%s\n", - ec->global_lock ? "yes" : "no"); - end: - return 0; -} - -static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) -{ - return single_open(file, acpi_ec_read_info, PDE(inode)->data); -} - -static const struct file_operations acpi_ec_info_ops = { - .open = acpi_ec_info_open_fs, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; - -static int acpi_ec_add_fs(struct acpi_device *device) -{ - struct proc_dir_entry *entry = NULL; - - if (!acpi_device_dir(device)) { - acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), - acpi_ec_dir); - if (!acpi_device_dir(device)) - return -ENODEV; - } - - entry = proc_create_data(ACPI_EC_FILE_INFO, S_IRUGO, - acpi_device_dir(device), - &acpi_ec_info_ops, acpi_driver_data(device)); - if (!entry) - return -ENODEV; - return 0; -} - -static int acpi_ec_remove_fs(struct acpi_device *device) -{ - - if (acpi_device_dir(device)) { - remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); - remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); - acpi_device_dir(device) = NULL; - } - - return 0; -} - /* -------------------------------------------------------------------------- Driver Interface -------------------------------------------------------------------------- */ @@ -894,7 +826,6 @@ static int acpi_ec_add(struct acpi_device *device) if (!first_ec) first_ec = ec; device->driver_data = ec; - acpi_ec_add_fs(device); pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", ec->gpe, ec->command_addr, ec->data_addr); @@ -921,7 +852,6 @@ static int acpi_ec_remove(struct acpi_device *device, int type) kfree(handler); } mutex_unlock(&ec->lock); - acpi_ec_remove_fs(device); device->driver_data = NULL; if (ec == first_ec) first_ec = NULL; @@ -1120,16 +1050,10 @@ int __init acpi_ec_init(void) { int result = 0; - acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); - if (!acpi_ec_dir) - return -ENODEV; - /* Now register the driver for the EC */ result = acpi_bus_register_driver(&acpi_ec_driver); - if (result < 0) { - remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); + if (result < 0) return -ENODEV; - } return result; } @@ -1140,9 +1064,6 @@ static void __exit acpi_ec_exit(void) { acpi_bus_unregister_driver(&acpi_ec_driver); - - remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); - return; } #endif /* 0 */ -- cgit v1.2.3 From 1195a098168fcacfef1cd80d05358e52fb366bf6 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:31 +0200 Subject: ACPI: Provide /sys/kernel/debug/ec/... This patch provides the same information through debugfs, which previously was provided through /proc/acpi/embedded_controller/*/info This is the gpe the EC is connected to and whether the global lock gets used. The io ports used are added to /proc/ioports in another patch. Beside the fact that /proc/acpi is deprecated for quite some time, this info is not needed for applications and thus can be moved to debugfs instead of a public interface like /sys. Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: Bjorn Helgaas CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett --- drivers/acpi/Kconfig | 13 +++++++++++ drivers/acpi/Makefile | 1 + drivers/acpi/ec.c | 18 +++++----------- drivers/acpi/ec_sys.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/acpi/internal.h | 24 +++++++++++++++++++++ 5 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 drivers/acpi/ec_sys.c (limited to 'drivers/acpi') diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 74641151880..f7226d1bc80 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -104,6 +104,19 @@ config ACPI_SYSFS_POWER help Say N to disable power /sys interface +config ACPI_EC_DEBUGFS + tristate "EC read/write access through /sys/kernel/debug/ec" + default y + help + Say N to disable Embedded Controller /sys/kernel/debug interface + + An Embedded Controller typically is available on laptops and reads + sensor values like battery state and temperature. + The kernel access the EC through ACPI parsed code provided by BIOS + tables. + Thus this option is a debug option that helps to write ACPI drivers + and can be used to identify ACPI code or EC firmware bugs. + config ACPI_PROC_EVENT bool "Deprecated /proc/acpi/event support" depends on PROC_FS diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 6ee33169e1d..833b582d176 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbs.o obj-$(CONFIG_ACPI_POWER_METER) += power_meter.o obj-$(CONFIG_ACPI_HED) += hed.o +obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o # processor has its own "processor." module_param namespace processor-y := processor_driver.o processor_throttling.o diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index ce1f07fd724..a79e1b193e8 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -43,10 +43,13 @@ #include #include +#include "internal.h" + #define ACPI_EC_CLASS "embedded_controller" #define ACPI_EC_DEVICE_NAME "Embedded Controller" #define ACPI_EC_FILE_INFO "info" +#undef PREFIX #define PREFIX "ACPI: EC: " /* EC status register */ @@ -104,19 +107,8 @@ struct transaction { bool done; }; -static struct acpi_ec { - acpi_handle handle; - unsigned long gpe; - unsigned long command_addr; - unsigned long data_addr; - unsigned long global_lock; - unsigned long flags; - struct mutex lock; - wait_queue_head_t wait; - struct list_head list; - struct transaction *curr; - spinlock_t curr_lock; -} *boot_ec, *first_ec; +struct acpi_ec *boot_ec, *first_ec; +EXPORT_SYMBOL(first_ec); static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */ static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */ diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c new file mode 100644 index 00000000000..834c21a42d6 --- /dev/null +++ b/drivers/acpi/ec_sys.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include "internal.h" + +MODULE_AUTHOR("Thomas Renninger "); +MODULE_DESCRIPTION("ACPI EC sysfs access driver"); +MODULE_LICENSE("GPL"); + +struct sysdev_class acpi_ec_sysdev_class = { + .name = "ec", +}; + +static struct dentry *acpi_ec_debugfs_dir; + +int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) +{ + struct dentry *dev_dir; + char name[64]; + if (ec_device_count == 0) { + acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL); + if (!acpi_ec_debugfs_dir) + return -ENOMEM; + } + + sprintf(name, "ec%u", ec_device_count); + dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir); + if (!dev_dir) { + if (ec_device_count == 0) + debugfs_remove_recursive(acpi_ec_debugfs_dir); + /* TBD: Proper cleanup for multiple ECs */ + return -ENOMEM; + } + + debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); + debugfs_create_bool("use_global_lock", 0444, dev_dir, + (u32 *)&first_ec->global_lock); + return 0; +} + +static int __init acpi_ec_sys_init(void) +{ + int err = 0; + if (first_ec) + err = acpi_ec_add_debugfs(first_ec, 0); + else + err = -ENODEV; + return err; +} + +static void __exit acpi_ec_sys_exit(void) +{ + debugfs_remove_recursive(acpi_ec_debugfs_dir); +} + +module_init(acpi_ec_sys_init); +module_exit(acpi_ec_sys_exit); diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index f8f190ec066..8ae27264a00 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -18,6 +18,11 @@ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _ACPI_INTERNAL_H_ +#define _ACPI_INTERNAL_H_ + +#include + #define PREFIX "ACPI: " int init_acpi_device_notify(void); @@ -46,6 +51,23 @@ void acpi_early_processor_set_pdc(void); /* -------------------------------------------------------------------------- Embedded Controller -------------------------------------------------------------------------- */ +struct acpi_ec { + acpi_handle handle; + unsigned long gpe; + unsigned long command_addr; + unsigned long data_addr; + unsigned long global_lock; + unsigned long flags; + struct mutex lock; + wait_queue_head_t wait; + struct list_head list; + struct transaction *curr; + spinlock_t curr_lock; + struct sys_device sysdev; +}; + +extern struct acpi_ec *first_ec; + int acpi_ec_init(void); int acpi_ec_ecdt_probe(void); int acpi_boot_ec_enable(void); @@ -63,3 +85,5 @@ int acpi_sleep_proc_init(void); #else static inline int acpi_sleep_proc_init(void) { return 0; } #endif + +#endif /* _ACPI_INTERNAL_H_ */ -- cgit v1.2.3 From 9827886dce77c47c378ce3154689cea2c45c731d Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:32 +0200 Subject: ACPI: Provide /sys/kernel/debug//ec/ec0/io for binary access to the EC A userspace app to easily read/write the EC can be found here: ftp://ftp.suse.com/pub/people/trenn/sources/ec/ec_access.c Multiple ECs are not supported, but shouldn't be hard to add as soon as the ec driver itself will support them. Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett --- drivers/acpi/ec_sys.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'drivers/acpi') diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c index 834c21a42d6..3ef978185c7 100644 --- a/drivers/acpi/ec_sys.c +++ b/drivers/acpi/ec_sys.c @@ -1,3 +1,13 @@ +/* + * ec_sys.c + * + * Copyright (C) 2010 SUSE Products GmbH/Novell + * Author: + * Thomas Renninger + * + * This work is licensed under the terms of the GNU GPL, version 2. + */ + #include #include #include @@ -7,12 +17,87 @@ MODULE_AUTHOR("Thomas Renninger "); MODULE_DESCRIPTION("ACPI EC sysfs access driver"); MODULE_LICENSE("GPL"); +#define EC_SPACE_SIZE 256 + struct sysdev_class acpi_ec_sysdev_class = { .name = "ec", }; static struct dentry *acpi_ec_debugfs_dir; +static int acpi_ec_open_io(struct inode *i, struct file *f) +{ + f->private_data = i->i_private; + return 0; +} + +static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + unsigned int size = EC_SPACE_SIZE; + u8 *data = (u8 *) buf; + loff_t init_off = *off; + int err = 0; + + if (*off >= size) + return 0; + if (*off + count >= size) { + size -= *off; + count = size; + } else + size = count; + + while (size) { + err = ec_read(*off, &data[*off - init_off]); + if (err) + return err; + *off += 1; + size--; + } + return count; +} + +static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + + unsigned int size = count; + loff_t init_off = *off; + u8 *data = (u8 *) buf; + int err = 0; + + if (*off >= EC_SPACE_SIZE) + return 0; + if (*off + count >= EC_SPACE_SIZE) { + size = EC_SPACE_SIZE - *off; + count = size; + } + + while (size) { + u8 byte_write = data[*off - init_off]; + err = ec_write(*off, byte_write); + if (err) + return err; + + *off += 1; + size--; + } + return count; +} + +static struct file_operations acpi_ec_io_ops = { + .owner = THIS_MODULE, + .open = acpi_ec_open_io, + .read = acpi_ec_read_io, + .write = acpi_ec_write_io, +}; + int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) { struct dentry *dev_dir; @@ -35,6 +120,7 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); debugfs_create_bool("use_global_lock", 0444, dev_dir, (u32 *)&first_ec->global_lock); + debugfs_create_file("io", 0666, dev_dir, ec, &acpi_ec_io_ops); return 0; } -- cgit v1.2.3 From b52e04216fcd86968c01ad0cfdb249375f19134d Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:33 +0200 Subject: ACPI: Register EC io ports in /proc/ioports Formerly these have been exposed through /proc/.. Better register them where all IO ports should get registered and scream loud if someone else claims to use them. EC data and command port typically should show up like this then: ... 0060-0060 : keyboard 0062-0062 : EC data 0064-0064 : keyboard 0066-0066 : EC command 0070-0071 : rtc0 ... Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: Bjorn Helgaas CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett --- drivers/acpi/ec.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index a79e1b193e8..265a99c1eb1 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -864,10 +864,18 @@ ec_parse_io_ports(struct acpi_resource *resource, void *context) * the second address region returned is the status/command * port. */ - if (ec->data_addr == 0) + if (ec->data_addr == 0) { ec->data_addr = resource->data.io.minimum; - else if (ec->command_addr == 0) + WARN(!request_region(ec->data_addr, 1, "EC data"), + "Could not request EC data io port %lu", + ec->data_addr); + } + else if (ec->command_addr == 0) { ec->command_addr = resource->data.io.minimum; + WARN(!request_region(ec->command_addr, 1, "EC command"), + "Could not request EC command io port %lu", + ec->command_addr); + } else return AE_CTRL_TERMINATE; -- cgit v1.2.3 From de4f10466e9347a2f1bfe39e501539557bed2c4b Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 29 Jul 2010 22:08:44 +0200 Subject: acpi ec: Fix possible double io port registration which will result in a harmless but ugly WARN message on some machines. Signed-off-by: Thomas Renninger CC: mjg59@srcf.ucam.org CC: platform-driver-x86@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: astarikovskiy@suse.de CC: akpm@linux-foundation.org Signed-off-by: Matthew Garrett --- drivers/acpi/ec.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 265a99c1eb1..1fa0aafebe2 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -818,6 +818,12 @@ static int acpi_ec_add(struct acpi_device *device) if (!first_ec) first_ec = ec; device->driver_data = ec; + + WARN(!request_region(ec->data_addr, 1, "EC data"), + "Could not request EC data io port 0x%lx", ec->data_addr); + WARN(!request_region(ec->command_addr, 1, "EC cmd"), + "Could not request EC cmd io port 0x%lx", ec->command_addr); + pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", ec->gpe, ec->command_addr, ec->data_addr); @@ -844,6 +850,8 @@ static int acpi_ec_remove(struct acpi_device *device, int type) kfree(handler); } mutex_unlock(&ec->lock); + release_region(ec->data_addr, 1); + release_region(ec->command_addr, 1); device->driver_data = NULL; if (ec == first_ec) first_ec = NULL; @@ -864,18 +872,10 @@ ec_parse_io_ports(struct acpi_resource *resource, void *context) * the second address region returned is the status/command * port. */ - if (ec->data_addr == 0) { + if (ec->data_addr == 0) ec->data_addr = resource->data.io.minimum; - WARN(!request_region(ec->data_addr, 1, "EC data"), - "Could not request EC data io port %lu", - ec->data_addr); - } - else if (ec->command_addr == 0) { + else if (ec->command_addr == 0) ec->command_addr = resource->data.io.minimum; - WARN(!request_region(ec->command_addr, 1, "EC command"), - "Could not request EC command io port %lu", - ec->command_addr); - } else return AE_CTRL_TERMINATE; -- cgit v1.2.3 From 500de3dd46ac9f9ae9d124634c68907b7d50d2cb Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 29 Jul 2010 22:30:24 +0200 Subject: acpi ec_sys: Be more cautious about ec write access - Set Kconfig option default n - Only allow root to read/write io file (sever bug!) - Introduce write support module param -> default off - Properly clean up if any debugfs files cannot be created Signed-off-by: Thomas Renninger CC: mjg59@srcf.ucam.org CC: platform-driver-x86@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: astarikovskiy@suse.de Signed-off-by: Matthew Garrett --- drivers/acpi/Kconfig | 11 ++++++++--- drivers/acpi/ec_sys.c | 31 ++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index f7226d1bc80..08e0140920e 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -106,14 +106,19 @@ config ACPI_SYSFS_POWER config ACPI_EC_DEBUGFS tristate "EC read/write access through /sys/kernel/debug/ec" - default y + default n help Say N to disable Embedded Controller /sys/kernel/debug interface + Be aware that using this interface can confuse your Embedded + Controller in a way that a normal reboot is not enough. You then + have to power of your system, and remove the laptop battery for + some seconds. An Embedded Controller typically is available on laptops and reads sensor values like battery state and temperature. - The kernel access the EC through ACPI parsed code provided by BIOS - tables. + The kernel accesses the EC through ACPI parsed code provided by BIOS + tables. This option allows to access the EC directly without ACPI + code being involved. Thus this option is a debug option that helps to write ACPI drivers and can be used to identify ACPI code or EC firmware bugs. diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c index 3ef978185c7..0e869b3f81c 100644 --- a/drivers/acpi/ec_sys.c +++ b/drivers/acpi/ec_sys.c @@ -17,6 +17,11 @@ MODULE_AUTHOR("Thomas Renninger "); MODULE_DESCRIPTION("ACPI EC sysfs access driver"); MODULE_LICENSE("GPL"); +static bool write_support; +module_param(write_support, bool, 0644); +MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may " + "be needed."); + #define EC_SPACE_SIZE 256 struct sysdev_class acpi_ec_sysdev_class = { @@ -102,6 +107,8 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) { struct dentry *dev_dir; char name[64]; + mode_t mode = 0400; + if (ec_device_count == 0) { acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL); if (!acpi_ec_debugfs_dir) @@ -111,17 +118,27 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) sprintf(name, "ec%u", ec_device_count); dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir); if (!dev_dir) { - if (ec_device_count == 0) - debugfs_remove_recursive(acpi_ec_debugfs_dir); - /* TBD: Proper cleanup for multiple ECs */ + if (ec_device_count != 0) + goto error; return -ENOMEM; } - debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); - debugfs_create_bool("use_global_lock", 0444, dev_dir, - (u32 *)&first_ec->global_lock); - debugfs_create_file("io", 0666, dev_dir, ec, &acpi_ec_io_ops); + if (!debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe)) + goto error; + if (!debugfs_create_bool("use_global_lock", 0444, dev_dir, + (u32 *)&first_ec->global_lock)) + goto error; + + if (write_support) + mode = 0600; + if (!debugfs_create_file("io", mode, dev_dir, ec, &acpi_ec_io_ops)) + goto error; + return 0; + +error: + debugfs_remove_recursive(acpi_ec_debugfs_dir); + return -ENOMEM; } static int __init acpi_ec_sys_init(void) -- cgit v1.2.3 From 4ef2db016aab27af05a95aeab1c30ad3f2fed7b9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 11 Aug 2010 23:04:39 -0600 Subject: param: update drivers/acpi/debug.c to new scheme The new module_param_cb() uses an ops struct, and the ops take a const struct kernel_param pointer (it's in .rodata). Signed-off-by: Rusty Russell --- drivers/acpi/debug.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c index 146135e7a6a..295dbfa2db9 100644 --- a/drivers/acpi/debug.c +++ b/drivers/acpi/debug.c @@ -96,7 +96,8 @@ static const struct acpi_dlevel acpi_debug_levels[] = { /* -------------------------------------------------------------------------- FS Interface (/sys) -------------------------------------------------------------------------- */ -static int param_get_debug_layer(char *buffer, struct kernel_param *kp) { +static int param_get_debug_layer(char *buffer, const struct kernel_param *kp) +{ int result = 0; int i; @@ -118,7 +119,8 @@ static int param_get_debug_layer(char *buffer, struct kernel_param *kp) { return result; } -static int param_get_debug_level(char *buffer, struct kernel_param *kp) { +static int param_get_debug_level(char *buffer, const struct kernel_param *kp) +{ int result = 0; int i; @@ -137,8 +139,18 @@ static int param_get_debug_level(char *buffer, struct kernel_param *kp) { return result; } -module_param_call(debug_layer, param_set_uint, param_get_debug_layer, &acpi_dbg_layer, 0644); -module_param_call(debug_level, param_set_uint, param_get_debug_level, &acpi_dbg_level, 0644); +static struct kernel_param_ops acpi_debug_layer_ops = { + .set = param_set_uint, + .get = param_get_debug_layer, +}; + +static struct kernel_param_ops acpi_debug_level_ops = { + .set = param_set_uint, + .get = param_get_debug_level, +}; + +module_param_cb(debug_layer, &acpi_debug_layer_ops, &acpi_dbg_layer, 0644); +module_param_cb(debug_level, &acpi_debug_level_ops, &acpi_dbg_level, 0644); static char trace_method_name[6]; module_param_string(trace_method_name, trace_method_name, 6, 0644); @@ -147,7 +159,7 @@ module_param(trace_debug_layer, uint, 0644); static unsigned int trace_debug_level; module_param(trace_debug_level, uint, 0644); -static int param_set_trace_state(const char *val, struct kernel_param *kp) +static int param_set_trace_state(const char *val, const struct kernel_param *kp) { int result = 0; @@ -181,7 +193,7 @@ exit: return result; } -static int param_get_trace_state(char *buffer, struct kernel_param *kp) +static int param_get_trace_state(char *buffer, const struct kernel_param *kp) { if (!acpi_gbl_trace_method_name) return sprintf(buffer, "disable"); @@ -194,8 +206,12 @@ static int param_get_trace_state(char *buffer, struct kernel_param *kp) return 0; } -module_param_call(trace_state, param_set_trace_state, param_get_trace_state, - NULL, 0644); +static struct kernel_param_ops param_ops_trace_state = { + .set = param_set_trace_state, + .get = param_get_trace_state, +}; + +module_param_cb(trace_state, ¶m_ops_trace_state, NULL, 0644); /* -------------------------------------------------------------------------- DebugFS Interface -- cgit v1.2.3 From 0a7992c90828a65281c3c9cf180be3b432d277b2 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Wed, 11 Aug 2010 14:17:29 -0700 Subject: acpi: fix bogus preemption logic The ACPI_PREEMPTION_POINT() logic was introduced in commit 8bd108d (ACPICA: add preemption point after each opcode parse). The follow up commits abe1dfab6, 138d15692, c084ca70 tried to fix the preemption logic back and forth, but nobody noticed that the usage of in_atomic_preempt_off() in that context is wrong. The check which guards the call of cond_resched() is: if (!in_atomic_preempt_off() && !irqs_disabled()) in_atomic_preempt_off() is not intended for general use as the comment above the macro definition clearly says: * Check whether we were atomic before we did preempt_disable(): * (used by the scheduler, *after* releasing the kernel lock) On a CONFIG_PREEMPT=n kernel the usage of in_atomic_preempt_off() works by accident, but with CONFIG_PREEMPT=y it's just broken. The whole purpose of the ACPI_PREEMPTION_POINT() is to reduce the latency on a CONFIG_PREEMPT=n kernel, so make ACPI_PREEMPTION_POINT() depend on CONFIG_PREEMPT=n and remove the in_atomic_preempt_off() check. Addresses https://bugzilla.kernel.org/show_bug.cgi?id=16210 [akpm@linux-foundation.org: fix build] Signed-off-by: Thomas Gleixner Cc: Len Brown Cc: Francois Valenduc Cc: Lin Ming Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/acpi/apei/erst.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/acpi') diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c index 864dd46c346..18645f4e83c 100644 --- a/drivers/acpi/apei/erst.c +++ b/drivers/acpi/apei/erst.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "apei-internal.h" -- cgit v1.2.3