From 2cfd93dd21b0127feae2579d46b7650fbacd2af1 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Fri, 27 May 2016 09:00:28 -0700 Subject: ACPI / PCI: pci_slot: Use more common logging style Use generic pr_ functions with pr_fmt for info and err. This also reduces object size a trivial bit: $ size drivers/acpi/pci_slot.o* text data bss dec hex filename 935 752 5 1692 69c drivers/acpi/pci_slot.o.new 1027 752 5 1784 6f8 drivers/acpi/pci_slot.o.old Miscellanea: o Remove unnecessary OOM message as k.alloc functions get a generic stack dump on OOM o Remove unnecessary embedded prefix from a dbg() message Signed-off-by: Joe Perches Signed-off-by: Rafael J. Wysocki --- drivers/acpi/pci_slot.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c index 7188e53b6b7c..aa8f4c72b687 100644 --- a/drivers/acpi/pci_slot.c +++ b/drivers/acpi/pci_slot.c @@ -22,6 +22,8 @@ * General Public License for more details. */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -48,14 +50,11 @@ module_param(debug, bool, 0644); #define _COMPONENT ACPI_PCI_COMPONENT ACPI_MODULE_NAME("pci_slot"); -#define MY_NAME "pci_slot" -#define err(format, arg...) pr_err("%s: " format , MY_NAME , ## arg) -#define info(format, arg...) pr_info("%s: " format , MY_NAME , ## arg) -#define dbg(format, arg...) \ - do { \ - if (debug) \ - pr_debug("%s: " format, MY_NAME , ## arg); \ - } while (0) +#define dbg(fmt, ...) \ +do { \ + if (debug) \ + pr_debug(fmt, ##__VA_ARGS__); \ +} while (0) #define SLOT_NAME_SIZE 21 /* Inspired by #define in acpiphp.h */ @@ -132,15 +131,13 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) } slot = kmalloc(sizeof(*slot), GFP_KERNEL); - if (!slot) { - err("%s: cannot allocate memory\n", __func__); + if (!slot) return AE_OK; - } snprintf(name, sizeof(name), "%llu", sun); pci_slot = pci_create_slot(pci_bus, device, name, NULL); if (IS_ERR(pci_slot)) { - err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot)); + pr_err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot)); kfree(slot); return AE_OK; } @@ -150,8 +147,8 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) get_device(&pci_bus->dev); - dbg("pci_slot: %p, pci_bus: %x, device: %d, name: %s\n", - pci_slot, pci_bus->number, device, name); + dbg("%p, pci_bus: %x, device: %d, name: %s\n", + pci_slot, pci_bus->number, device, name); return AE_OK; } @@ -186,7 +183,8 @@ void acpi_pci_slot_remove(struct pci_bus *bus) static int do_sta_before_sun(const struct dmi_system_id *d) { - info("%s detected: will evaluate _STA before calling _SUN\n", d->ident); + pr_info("%s detected: will evaluate _STA before calling _SUN\n", + d->ident); check_sta_before_sun = 1; return 0; } -- cgit From 409ffed2b6ae1d5db3cefed2e0fb2ca7e3f352bd Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Fri, 27 May 2016 09:13:29 -0700 Subject: ACPI / PCI: pci_slot: Use generic pr_debug utility Remove the dbg macro and debug module parameter and use the generic kernel facility. Trivially reduces defconfig object size on x86-64 $ size drivers/acpi/pci_slot.o* text data bss dec hex filename 880 752 4 1636 664 drivers/acpi/pci_slot.o.new 935 752 5 1692 69c drivers/acpi/pci_slot.o.old Signed-off-by: Joe Perches Signed-off-by: Rafael J. Wysocki --- drivers/acpi/pci_slot.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c index aa8f4c72b687..1236fb04a708 100644 --- a/drivers/acpi/pci_slot.c +++ b/drivers/acpi/pci_slot.c @@ -35,7 +35,6 @@ #include #include -static bool debug; static int check_sta_before_sun; #define DRIVER_VERSION "0.1" @@ -44,18 +43,10 @@ static int check_sta_before_sun; MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); -MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); -module_param(debug, bool, 0644); #define _COMPONENT ACPI_PCI_COMPONENT ACPI_MODULE_NAME("pci_slot"); -#define dbg(fmt, ...) \ -do { \ - if (debug) \ - pr_debug(fmt, ##__VA_ARGS__); \ -} while (0) - #define SLOT_NAME_SIZE 21 /* Inspired by #define in acpiphp.h */ struct acpi_pci_slot { @@ -75,7 +66,7 @@ check_slot(acpi_handle handle, unsigned long long *sun) struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); - dbg("Checking slot on path: %s\n", (char *)buffer.pointer); + pr_debug("Checking slot on path: %s\n", (char *)buffer.pointer); if (check_sta_before_sun) { /* If SxFy doesn't have _STA, we just assume it's there */ @@ -86,14 +77,16 @@ check_slot(acpi_handle handle, unsigned long long *sun) status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); if (ACPI_FAILURE(status)) { - dbg("_ADR returned %d on %s\n", status, (char *)buffer.pointer); + pr_debug("_ADR returned %d on %s\n", + status, (char *)buffer.pointer); goto out; } /* No _SUN == not a slot == bail */ status = acpi_evaluate_integer(handle, "_SUN", NULL, sun); if (ACPI_FAILURE(status)) { - dbg("_SUN returned %d on %s\n", status, (char *)buffer.pointer); + pr_debug("_SUN returned %d on %s\n", + status, (char *)buffer.pointer); goto out; } @@ -147,8 +140,8 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) get_device(&pci_bus->dev); - dbg("%p, pci_bus: %x, device: %d, name: %s\n", - pci_slot, pci_bus->number, device, name); + pr_debug("%p, pci_bus: %x, device: %d, name: %s\n", + pci_slot, pci_bus->number, device, name); return AE_OK; } -- cgit From f26f5c8b8b182c38074d942e9124679238aa04ef Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 16 Jun 2016 17:23:09 +0200 Subject: ACPI / bus: Use acpi_handle_debug() in acpi_print_osc_error() acpi_print_osc_error() basically duplicates the functionalit of acpi_handle_debug(), so use that one in there. While at it, convert the explicit KERN_DEBUG prints to pr_debug() (and apply it to continuation messages too). Signed-off-by: Rafael J. Wysocki --- drivers/acpi/bus.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 262ca31b86d9..a6bb8aef2573 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -174,22 +174,17 @@ void acpi_bus_detach_private_data(acpi_handle handle) EXPORT_SYMBOL_GPL(acpi_bus_detach_private_data); static void acpi_print_osc_error(acpi_handle handle, - struct acpi_osc_context *context, char *error) + struct acpi_osc_context *context, char *error) { - struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER}; int i; - if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer))) - printk(KERN_DEBUG "%s: %s\n", context->uuid_str, error); - else { - printk(KERN_DEBUG "%s (%s): %s\n", - (char *)buffer.pointer, context->uuid_str, error); - kfree(buffer.pointer); - } - printk(KERN_DEBUG "_OSC request data:"); + acpi_handle_debug(handle, "(%s): %s\n", context->uuid_str, error); + + pr_debug("_OSC request data:"); for (i = 0; i < context->cap.length; i += sizeof(u32)) - printk(" %x", *((u32 *)(context->cap.pointer + i))); - printk("\n"); + pr_debug(" %x", *((u32 *)(context->cap.pointer + i))); + + pr_debug("\n"); } acpi_status acpi_str_to_uuid(char *str, u8 *uuid) -- cgit From 3af03f77cb6638c8384c712f8fc7febe07ae2424 Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Mon, 4 Jul 2016 11:13:59 +0800 Subject: ACPI / bus: Correct the comments about acpi_subsystem_init() In acpi_subsystem_init(), function acpi_enable_subsystem() is called to do the real job. However with different flags passed to acpi_enable_subsystem(), different code is executed. In acpi_subsystem_init(), with "~ACPI_NO_ACPI_ENABLE" passed in, it will only switch over the platform to the ACPI mode. The remaining part of acpi_enable_subsystem() is done when acpi_bus_init() is called. So the comments above acpi_subsystem_init() is not exact, change it here. Signed-off-by: Baoquan He Signed-off-by: Rafael J. Wysocki --- drivers/acpi/bus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index a6bb8aef2573..9342f4b46a4e 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -956,8 +956,7 @@ void __init acpi_early_init(void) /** * acpi_subsystem_init - Finalize the early initialization of ACPI. * - * Switch over the platform to the ACPI mode (if possible), initialize the - * handling of ACPI events, install the interrupt and global lock handlers. + * Switch over the platform to the ACPI mode (if possible). * * Doing this too early is generally unsafe, but at the same time it needs to be * done before all things that really depend on ACPI. The right spot appears to -- cgit From baa0c019b4c6eb1759cf55e7858badca4758c143 Mon Sep 17 00:00:00 2001 From: "Prakash, Prashanth" Date: Thu, 23 Jun 2016 12:24:26 -0600 Subject: ACPI / bus: Support for platform initiated graceful shutdown This patch adds support for platform initited graceful shutdown as described in sections 5.6.6(Table-143) and 6.3.5.1 of ACPI 6.1 spec The OSPM will get a graceful shutdown request via a Notify operator on \_SB device with a value of 0x81 per section 5.6.6. Following the shutdown request from platform the OSPM needs to follow the processing sequence as described in section 6.2.5.1. v3 * Switched to regular work with delays from delayed work * Dropped changes to actypes.h * Small style changes v2 * Switched from standalone driver to a simple notify handler v1 * Initial Cc: "Rafael J. Wysocki" Signed-off-by: Prashanth Prakash Signed-off-by: Rafael J. Wysocki --- drivers/acpi/bus.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'drivers/acpi') diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 9342f4b46a4e..64a3fb0bf188 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -30,6 +30,9 @@ #include #include #include +#include +#include +#include #ifdef CONFIG_X86 #include #endif @@ -470,6 +473,56 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device) acpi_device_notify); } +/* Handle events targeting \_SB device (at present only graceful shutdown) */ + +#define ACPI_SB_NOTIFY_SHUTDOWN_REQUEST 0x81 +#define ACPI_SB_INDICATE_INTERVAL 10000 + +static void sb_notify_work(struct work_struct *dummy) +{ + acpi_handle sb_handle; + + orderly_poweroff(true); + + /* + * After initiating graceful shutdown, the ACPI spec requires OSPM + * to evaluate _OST method once every 10seconds to indicate that + * the shutdown is in progress + */ + acpi_get_handle(NULL, "\\_SB", &sb_handle); + while (1) { + pr_info("Graceful shutdown in progress.\n"); + acpi_evaluate_ost(sb_handle, ACPI_OST_EC_OSPM_SHUTDOWN, + ACPI_OST_SC_OS_SHUTDOWN_IN_PROGRESS, NULL); + msleep(ACPI_SB_INDICATE_INTERVAL); + } +} + +static void acpi_sb_notify(acpi_handle handle, u32 event, void *data) +{ + static DECLARE_WORK(acpi_sb_work, sb_notify_work); + + if (event == ACPI_SB_NOTIFY_SHUTDOWN_REQUEST) { + if (!work_busy(&acpi_sb_work)) + schedule_work(&acpi_sb_work); + } else + pr_warn("event %x is not supported by \\_SB device\n", event); +} + +static int __init acpi_setup_sb_notify_handler(void) +{ + acpi_handle sb_handle; + + if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &sb_handle))) + return -ENXIO; + + if (ACPI_FAILURE(acpi_install_notify_handler(sb_handle, ACPI_DEVICE_NOTIFY, + acpi_sb_notify, NULL))) + return -EINVAL; + + return 0; +} + /* -------------------------------------------------------------------------- Device Matching -------------------------------------------------------------------------- */ @@ -1118,6 +1171,7 @@ static int __init acpi_init(void) acpi_sleep_proc_init(); acpi_wakeup_device_init(); acpi_debugger_init(); + acpi_setup_sb_notify_handler(); return 0; } -- cgit From ffaab0aa2c3edd67a0cafbc66f9cc39276f233fa Mon Sep 17 00:00:00 2001 From: Paul Gortmaker Date: Mon, 11 Jul 2016 18:17:23 -0400 Subject: ACPI / PCI: make pci_slot explicitly non-modular The Kconfig for this file is: drivers/acpi/Kconfig:config ACPI_PCI_SLOT drivers/acpi/Kconfig: bool "PCI slot detection driver" ...and so it is not built as a module. Hence including module.h and everything that comes with it just for the no-op MODULE_LICENSE and friends is rather heavy handed. The license/author info is found at the top of the file, so we just remove the MODULE_LICENSE etc and the include of module.h We delete the DRIVER_VERSION macro as well since it is unused. Signed-off-by: Paul Gortmaker Signed-off-by: Rafael J. Wysocki --- drivers/acpi/pci_slot.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c index 1236fb04a708..f62c68e24317 100644 --- a/drivers/acpi/pci_slot.c +++ b/drivers/acpi/pci_slot.c @@ -25,7 +25,6 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include -#include #include #include #include @@ -37,13 +36,6 @@ static int check_sta_before_sun; -#define DRIVER_VERSION "0.1" -#define DRIVER_AUTHOR "Alex Chiang " -#define DRIVER_DESC "ACPI PCI Slot Detection Driver" -MODULE_AUTHOR(DRIVER_AUTHOR); -MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_LICENSE("GPL"); - #define _COMPONENT ACPI_PCI_COMPONENT ACPI_MODULE_NAME("pci_slot"); -- cgit