18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * sysfs.c - ACPI sysfs interface to userspace. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#define pr_fmt(fmt) "ACPI: " fmt 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/init.h> 98c2ecf20Sopenharmony_ci#include <linux/kernel.h> 108c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 118c2ecf20Sopenharmony_ci#include <linux/acpi.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "internal.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define _COMPONENT ACPI_SYSTEM_COMPONENT 168c2ecf20Sopenharmony_ciACPI_MODULE_NAME("sysfs"); 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_DEBUG 198c2ecf20Sopenharmony_ci/* 208c2ecf20Sopenharmony_ci * ACPI debug sysfs I/F, including: 218c2ecf20Sopenharmony_ci * /sys/modules/acpi/parameters/debug_layer 228c2ecf20Sopenharmony_ci * /sys/modules/acpi/parameters/debug_level 238c2ecf20Sopenharmony_ci * /sys/modules/acpi/parameters/trace_method_name 248c2ecf20Sopenharmony_ci * /sys/modules/acpi/parameters/trace_state 258c2ecf20Sopenharmony_ci * /sys/modules/acpi/parameters/trace_debug_layer 268c2ecf20Sopenharmony_ci * /sys/modules/acpi/parameters/trace_debug_level 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct acpi_dlayer { 308c2ecf20Sopenharmony_ci const char *name; 318c2ecf20Sopenharmony_ci unsigned long value; 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_cistruct acpi_dlevel { 348c2ecf20Sopenharmony_ci const char *name; 358c2ecf20Sopenharmony_ci unsigned long value; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci#define ACPI_DEBUG_INIT(v) { .name = #v, .value = v } 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic const struct acpi_dlayer acpi_debug_layers[] = { 408c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_UTILITIES), 418c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_HARDWARE), 428c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_EVENTS), 438c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_TABLES), 448c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_NAMESPACE), 458c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_PARSER), 468c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_DISPATCHER), 478c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_EXECUTER), 488c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_RESOURCES), 498c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER), 508c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_OS_SERVICES), 518c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER), 528c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_COMPILER), 538c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_TOOLS), 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_BUS_COMPONENT), 568c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_AC_COMPONENT), 578c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_BATTERY_COMPONENT), 588c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_BUTTON_COMPONENT), 598c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_SBS_COMPONENT), 608c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_FAN_COMPONENT), 618c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_PCI_COMPONENT), 628c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_POWER_COMPONENT), 638c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_CONTAINER_COMPONENT), 648c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_SYSTEM_COMPONENT), 658c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_THERMAL_COMPONENT), 668c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_MEMORY_DEVICE_COMPONENT), 678c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_VIDEO_COMPONENT), 688c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_PROCESSOR_COMPONENT), 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic const struct acpi_dlevel acpi_debug_levels[] = { 728c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_INIT), 738c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT), 748c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_INFO), 758c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_REPAIR), 768c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_TRACE_POINT), 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES), 798c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_PARSE), 808c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_LOAD), 818c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_DISPATCH), 828c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_EXEC), 838c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_NAMES), 848c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_OPREGION), 858c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_BFIELD), 868c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_TABLES), 878c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_VALUES), 888c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_OBJECTS), 898c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_RESOURCES), 908c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS), 918c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_PACKAGE), 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS), 948c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS), 958c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS), 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_MUTEX), 988c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_THREADS), 998c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_IO), 1008c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS), 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE), 1038c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO), 1048c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES), 1058c2ecf20Sopenharmony_ci ACPI_DEBUG_INIT(ACPI_LV_EVENTS), 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic int param_get_debug_layer(char *buffer, const struct kernel_param *kp) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci int result = 0; 1118c2ecf20Sopenharmony_ci int i; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci result = sprintf(buffer, "%-25s\tHex SET\n", "Description"); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) { 1168c2ecf20Sopenharmony_ci result += sprintf(buffer + result, "%-25s\t0x%08lX [%c]\n", 1178c2ecf20Sopenharmony_ci acpi_debug_layers[i].name, 1188c2ecf20Sopenharmony_ci acpi_debug_layers[i].value, 1198c2ecf20Sopenharmony_ci (acpi_dbg_layer & acpi_debug_layers[i].value) 1208c2ecf20Sopenharmony_ci ? '*' : ' '); 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci result += 1238c2ecf20Sopenharmony_ci sprintf(buffer + result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS", 1248c2ecf20Sopenharmony_ci ACPI_ALL_DRIVERS, 1258c2ecf20Sopenharmony_ci (acpi_dbg_layer & ACPI_ALL_DRIVERS) == 1268c2ecf20Sopenharmony_ci ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer & ACPI_ALL_DRIVERS) 1278c2ecf20Sopenharmony_ci == 0 ? ' ' : '-'); 1288c2ecf20Sopenharmony_ci result += 1298c2ecf20Sopenharmony_ci sprintf(buffer + result, 1308c2ecf20Sopenharmony_ci "--\ndebug_layer = 0x%08X ( * = enabled)\n", 1318c2ecf20Sopenharmony_ci acpi_dbg_layer); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci return result; 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic int param_get_debug_level(char *buffer, const struct kernel_param *kp) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci int result = 0; 1398c2ecf20Sopenharmony_ci int i; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci result = sprintf(buffer, "%-25s\tHex SET\n", "Description"); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) { 1448c2ecf20Sopenharmony_ci result += sprintf(buffer + result, "%-25s\t0x%08lX [%c]\n", 1458c2ecf20Sopenharmony_ci acpi_debug_levels[i].name, 1468c2ecf20Sopenharmony_ci acpi_debug_levels[i].value, 1478c2ecf20Sopenharmony_ci (acpi_dbg_level & acpi_debug_levels[i].value) 1488c2ecf20Sopenharmony_ci ? '*' : ' '); 1498c2ecf20Sopenharmony_ci } 1508c2ecf20Sopenharmony_ci result += 1518c2ecf20Sopenharmony_ci sprintf(buffer + result, "--\ndebug_level = 0x%08X (* = enabled)\n", 1528c2ecf20Sopenharmony_ci acpi_dbg_level); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci return result; 1558c2ecf20Sopenharmony_ci} 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistatic const struct kernel_param_ops param_ops_debug_layer = { 1588c2ecf20Sopenharmony_ci .set = param_set_uint, 1598c2ecf20Sopenharmony_ci .get = param_get_debug_layer, 1608c2ecf20Sopenharmony_ci}; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistatic const struct kernel_param_ops param_ops_debug_level = { 1638c2ecf20Sopenharmony_ci .set = param_set_uint, 1648c2ecf20Sopenharmony_ci .get = param_get_debug_level, 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cimodule_param_cb(debug_layer, ¶m_ops_debug_layer, &acpi_dbg_layer, 0644); 1688c2ecf20Sopenharmony_cimodule_param_cb(debug_level, ¶m_ops_debug_level, &acpi_dbg_level, 0644); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic char trace_method_name[1024]; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cistatic int param_set_trace_method_name(const char *val, 1738c2ecf20Sopenharmony_ci const struct kernel_param *kp) 1748c2ecf20Sopenharmony_ci{ 1758c2ecf20Sopenharmony_ci u32 saved_flags = 0; 1768c2ecf20Sopenharmony_ci bool is_abs_path = true; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci if (*val != '\\') 1798c2ecf20Sopenharmony_ci is_abs_path = false; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci if ((is_abs_path && strlen(val) > 1023) || 1828c2ecf20Sopenharmony_ci (!is_abs_path && strlen(val) > 1022)) { 1838c2ecf20Sopenharmony_ci pr_err("%s: string parameter too long\n", kp->name); 1848c2ecf20Sopenharmony_ci return -ENOSPC; 1858c2ecf20Sopenharmony_ci } 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* 1888c2ecf20Sopenharmony_ci * It's not safe to update acpi_gbl_trace_method_name without 1898c2ecf20Sopenharmony_ci * having the tracer stopped, so we save the original tracer 1908c2ecf20Sopenharmony_ci * state and disable it. 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_ci saved_flags = acpi_gbl_trace_flags; 1938c2ecf20Sopenharmony_ci (void)acpi_debug_trace(NULL, 1948c2ecf20Sopenharmony_ci acpi_gbl_trace_dbg_level, 1958c2ecf20Sopenharmony_ci acpi_gbl_trace_dbg_layer, 1968c2ecf20Sopenharmony_ci 0); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci /* This is a hack. We can't kmalloc in early boot. */ 1998c2ecf20Sopenharmony_ci if (is_abs_path) 2008c2ecf20Sopenharmony_ci strcpy(trace_method_name, val); 2018c2ecf20Sopenharmony_ci else { 2028c2ecf20Sopenharmony_ci trace_method_name[0] = '\\'; 2038c2ecf20Sopenharmony_ci strcpy(trace_method_name+1, val); 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci /* Restore the original tracer state */ 2078c2ecf20Sopenharmony_ci (void)acpi_debug_trace(trace_method_name, 2088c2ecf20Sopenharmony_ci acpi_gbl_trace_dbg_level, 2098c2ecf20Sopenharmony_ci acpi_gbl_trace_dbg_layer, 2108c2ecf20Sopenharmony_ci saved_flags); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci return 0; 2138c2ecf20Sopenharmony_ci} 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cistatic int param_get_trace_method_name(char *buffer, const struct kernel_param *kp) 2168c2ecf20Sopenharmony_ci{ 2178c2ecf20Sopenharmony_ci return scnprintf(buffer, PAGE_SIZE, "%s\n", acpi_gbl_trace_method_name); 2188c2ecf20Sopenharmony_ci} 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_cistatic const struct kernel_param_ops param_ops_trace_method = { 2218c2ecf20Sopenharmony_ci .set = param_set_trace_method_name, 2228c2ecf20Sopenharmony_ci .get = param_get_trace_method_name, 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistatic const struct kernel_param_ops param_ops_trace_attrib = { 2268c2ecf20Sopenharmony_ci .set = param_set_uint, 2278c2ecf20Sopenharmony_ci .get = param_get_uint, 2288c2ecf20Sopenharmony_ci}; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cimodule_param_cb(trace_method_name, ¶m_ops_trace_method, &trace_method_name, 0644); 2318c2ecf20Sopenharmony_cimodule_param_cb(trace_debug_layer, ¶m_ops_trace_attrib, &acpi_gbl_trace_dbg_layer, 0644); 2328c2ecf20Sopenharmony_cimodule_param_cb(trace_debug_level, ¶m_ops_trace_attrib, &acpi_gbl_trace_dbg_level, 0644); 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistatic int param_set_trace_state(const char *val, 2358c2ecf20Sopenharmony_ci const struct kernel_param *kp) 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci acpi_status status; 2388c2ecf20Sopenharmony_ci const char *method = trace_method_name; 2398c2ecf20Sopenharmony_ci u32 flags = 0; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci/* So "xxx-once" comparison should go prior than "xxx" comparison */ 2428c2ecf20Sopenharmony_ci#define acpi_compare_param(val, key) \ 2438c2ecf20Sopenharmony_ci strncmp((val), (key), sizeof(key) - 1) 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci if (!acpi_compare_param(val, "enable")) { 2468c2ecf20Sopenharmony_ci method = NULL; 2478c2ecf20Sopenharmony_ci flags = ACPI_TRACE_ENABLED; 2488c2ecf20Sopenharmony_ci } else if (!acpi_compare_param(val, "disable")) 2498c2ecf20Sopenharmony_ci method = NULL; 2508c2ecf20Sopenharmony_ci else if (!acpi_compare_param(val, "method-once")) 2518c2ecf20Sopenharmony_ci flags = ACPI_TRACE_ENABLED | ACPI_TRACE_ONESHOT; 2528c2ecf20Sopenharmony_ci else if (!acpi_compare_param(val, "method")) 2538c2ecf20Sopenharmony_ci flags = ACPI_TRACE_ENABLED; 2548c2ecf20Sopenharmony_ci else if (!acpi_compare_param(val, "opcode-once")) 2558c2ecf20Sopenharmony_ci flags = ACPI_TRACE_ENABLED | ACPI_TRACE_ONESHOT | ACPI_TRACE_OPCODE; 2568c2ecf20Sopenharmony_ci else if (!acpi_compare_param(val, "opcode")) 2578c2ecf20Sopenharmony_ci flags = ACPI_TRACE_ENABLED | ACPI_TRACE_OPCODE; 2588c2ecf20Sopenharmony_ci else 2598c2ecf20Sopenharmony_ci return -EINVAL; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci status = acpi_debug_trace(method, 2628c2ecf20Sopenharmony_ci acpi_gbl_trace_dbg_level, 2638c2ecf20Sopenharmony_ci acpi_gbl_trace_dbg_layer, 2648c2ecf20Sopenharmony_ci flags); 2658c2ecf20Sopenharmony_ci if (ACPI_FAILURE(status)) 2668c2ecf20Sopenharmony_ci return -EBUSY; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci return 0; 2698c2ecf20Sopenharmony_ci} 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic int param_get_trace_state(char *buffer, const struct kernel_param *kp) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED)) 2748c2ecf20Sopenharmony_ci return sprintf(buffer, "disable\n"); 2758c2ecf20Sopenharmony_ci else { 2768c2ecf20Sopenharmony_ci if (acpi_gbl_trace_method_name) { 2778c2ecf20Sopenharmony_ci if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) 2788c2ecf20Sopenharmony_ci return sprintf(buffer, "method-once\n"); 2798c2ecf20Sopenharmony_ci else 2808c2ecf20Sopenharmony_ci return sprintf(buffer, "method\n"); 2818c2ecf20Sopenharmony_ci } else 2828c2ecf20Sopenharmony_ci return sprintf(buffer, "enable\n"); 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci return 0; 2858c2ecf20Sopenharmony_ci} 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_cimodule_param_call(trace_state, param_set_trace_state, param_get_trace_state, 2888c2ecf20Sopenharmony_ci NULL, 0644); 2898c2ecf20Sopenharmony_ci#endif /* CONFIG_ACPI_DEBUG */ 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci/* /sys/modules/acpi/parameters/aml_debug_output */ 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_cimodule_param_named(aml_debug_output, acpi_gbl_enable_aml_debug_object, 2958c2ecf20Sopenharmony_ci byte, 0644); 2968c2ecf20Sopenharmony_ciMODULE_PARM_DESC(aml_debug_output, 2978c2ecf20Sopenharmony_ci "To enable/disable the ACPI Debug Object output."); 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci/* /sys/module/acpi/parameters/acpica_version */ 3008c2ecf20Sopenharmony_cistatic int param_get_acpica_version(char *buffer, 3018c2ecf20Sopenharmony_ci const struct kernel_param *kp) 3028c2ecf20Sopenharmony_ci{ 3038c2ecf20Sopenharmony_ci int result; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci result = sprintf(buffer, "%x\n", ACPI_CA_VERSION); 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci return result; 3088c2ecf20Sopenharmony_ci} 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_cimodule_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci/* 3138c2ecf20Sopenharmony_ci * ACPI table sysfs I/F: 3148c2ecf20Sopenharmony_ci * /sys/firmware/acpi/tables/ 3158c2ecf20Sopenharmony_ci * /sys/firmware/acpi/tables/data/ 3168c2ecf20Sopenharmony_ci * /sys/firmware/acpi/tables/dynamic/ 3178c2ecf20Sopenharmony_ci */ 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_cistatic LIST_HEAD(acpi_table_attr_list); 3208c2ecf20Sopenharmony_cistatic struct kobject *tables_kobj; 3218c2ecf20Sopenharmony_cistatic struct kobject *tables_data_kobj; 3228c2ecf20Sopenharmony_cistatic struct kobject *dynamic_tables_kobj; 3238c2ecf20Sopenharmony_cistatic struct kobject *hotplug_kobj; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci#define ACPI_MAX_TABLE_INSTANCES 999 3268c2ecf20Sopenharmony_ci#define ACPI_INST_SIZE 4 /* including trailing 0 */ 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistruct acpi_table_attr { 3298c2ecf20Sopenharmony_ci struct bin_attribute attr; 3308c2ecf20Sopenharmony_ci char name[ACPI_NAMESEG_SIZE]; 3318c2ecf20Sopenharmony_ci int instance; 3328c2ecf20Sopenharmony_ci char filename[ACPI_NAMESEG_SIZE+ACPI_INST_SIZE]; 3338c2ecf20Sopenharmony_ci struct list_head node; 3348c2ecf20Sopenharmony_ci}; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cistruct acpi_data_attr { 3378c2ecf20Sopenharmony_ci struct bin_attribute attr; 3388c2ecf20Sopenharmony_ci u64 addr; 3398c2ecf20Sopenharmony_ci}; 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cistatic ssize_t acpi_table_show(struct file *filp, struct kobject *kobj, 3428c2ecf20Sopenharmony_ci struct bin_attribute *bin_attr, char *buf, 3438c2ecf20Sopenharmony_ci loff_t offset, size_t count) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci struct acpi_table_attr *table_attr = 3468c2ecf20Sopenharmony_ci container_of(bin_attr, struct acpi_table_attr, attr); 3478c2ecf20Sopenharmony_ci struct acpi_table_header *table_header = NULL; 3488c2ecf20Sopenharmony_ci acpi_status status; 3498c2ecf20Sopenharmony_ci ssize_t rc; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci status = acpi_get_table(table_attr->name, table_attr->instance, 3528c2ecf20Sopenharmony_ci &table_header); 3538c2ecf20Sopenharmony_ci if (ACPI_FAILURE(status)) 3548c2ecf20Sopenharmony_ci return -ENODEV; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci rc = memory_read_from_buffer(buf, count, &offset, table_header, 3578c2ecf20Sopenharmony_ci table_header->length); 3588c2ecf20Sopenharmony_ci acpi_put_table(table_header); 3598c2ecf20Sopenharmony_ci return rc; 3608c2ecf20Sopenharmony_ci} 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_cistatic int acpi_table_attr_init(struct kobject *tables_obj, 3638c2ecf20Sopenharmony_ci struct acpi_table_attr *table_attr, 3648c2ecf20Sopenharmony_ci struct acpi_table_header *table_header) 3658c2ecf20Sopenharmony_ci{ 3668c2ecf20Sopenharmony_ci struct acpi_table_header *header = NULL; 3678c2ecf20Sopenharmony_ci struct acpi_table_attr *attr = NULL; 3688c2ecf20Sopenharmony_ci char instance_str[ACPI_INST_SIZE]; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci sysfs_attr_init(&table_attr->attr.attr); 3718c2ecf20Sopenharmony_ci ACPI_COPY_NAMESEG(table_attr->name, table_header->signature); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci list_for_each_entry(attr, &acpi_table_attr_list, node) { 3748c2ecf20Sopenharmony_ci if (ACPI_COMPARE_NAMESEG(table_attr->name, attr->name)) 3758c2ecf20Sopenharmony_ci if (table_attr->instance < attr->instance) 3768c2ecf20Sopenharmony_ci table_attr->instance = attr->instance; 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci table_attr->instance++; 3798c2ecf20Sopenharmony_ci if (table_attr->instance > ACPI_MAX_TABLE_INSTANCES) { 3808c2ecf20Sopenharmony_ci pr_warn("%4.4s: too many table instances\n", 3818c2ecf20Sopenharmony_ci table_attr->name); 3828c2ecf20Sopenharmony_ci return -ERANGE; 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci ACPI_COPY_NAMESEG(table_attr->filename, table_header->signature); 3868c2ecf20Sopenharmony_ci table_attr->filename[ACPI_NAMESEG_SIZE] = '\0'; 3878c2ecf20Sopenharmony_ci if (table_attr->instance > 1 || (table_attr->instance == 1 && 3888c2ecf20Sopenharmony_ci !acpi_get_table 3898c2ecf20Sopenharmony_ci (table_header->signature, 2, &header))) { 3908c2ecf20Sopenharmony_ci snprintf(instance_str, sizeof(instance_str), "%u", 3918c2ecf20Sopenharmony_ci table_attr->instance); 3928c2ecf20Sopenharmony_ci strcat(table_attr->filename, instance_str); 3938c2ecf20Sopenharmony_ci } 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci table_attr->attr.size = table_header->length; 3968c2ecf20Sopenharmony_ci table_attr->attr.read = acpi_table_show; 3978c2ecf20Sopenharmony_ci table_attr->attr.attr.name = table_attr->filename; 3988c2ecf20Sopenharmony_ci table_attr->attr.attr.mode = 0400; 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci return sysfs_create_bin_file(tables_obj, &table_attr->attr); 4018c2ecf20Sopenharmony_ci} 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ciacpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci struct acpi_table_attr *table_attr; 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci switch (event) { 4088c2ecf20Sopenharmony_ci case ACPI_TABLE_EVENT_INSTALL: 4098c2ecf20Sopenharmony_ci table_attr = 4108c2ecf20Sopenharmony_ci kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL); 4118c2ecf20Sopenharmony_ci if (!table_attr) 4128c2ecf20Sopenharmony_ci return AE_NO_MEMORY; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci if (acpi_table_attr_init(dynamic_tables_kobj, 4158c2ecf20Sopenharmony_ci table_attr, table)) { 4168c2ecf20Sopenharmony_ci kfree(table_attr); 4178c2ecf20Sopenharmony_ci return AE_ERROR; 4188c2ecf20Sopenharmony_ci } 4198c2ecf20Sopenharmony_ci list_add_tail(&table_attr->node, &acpi_table_attr_list); 4208c2ecf20Sopenharmony_ci break; 4218c2ecf20Sopenharmony_ci case ACPI_TABLE_EVENT_LOAD: 4228c2ecf20Sopenharmony_ci case ACPI_TABLE_EVENT_UNLOAD: 4238c2ecf20Sopenharmony_ci case ACPI_TABLE_EVENT_UNINSTALL: 4248c2ecf20Sopenharmony_ci /* 4258c2ecf20Sopenharmony_ci * we do not need to do anything right now 4268c2ecf20Sopenharmony_ci * because the table is not deleted from the 4278c2ecf20Sopenharmony_ci * global table list when unloading it. 4288c2ecf20Sopenharmony_ci */ 4298c2ecf20Sopenharmony_ci break; 4308c2ecf20Sopenharmony_ci default: 4318c2ecf20Sopenharmony_ci return AE_BAD_PARAMETER; 4328c2ecf20Sopenharmony_ci } 4338c2ecf20Sopenharmony_ci return AE_OK; 4348c2ecf20Sopenharmony_ci} 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_cistatic ssize_t acpi_data_show(struct file *filp, struct kobject *kobj, 4378c2ecf20Sopenharmony_ci struct bin_attribute *bin_attr, char *buf, 4388c2ecf20Sopenharmony_ci loff_t offset, size_t count) 4398c2ecf20Sopenharmony_ci{ 4408c2ecf20Sopenharmony_ci struct acpi_data_attr *data_attr; 4418c2ecf20Sopenharmony_ci void __iomem *base; 4428c2ecf20Sopenharmony_ci ssize_t size; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci data_attr = container_of(bin_attr, struct acpi_data_attr, attr); 4458c2ecf20Sopenharmony_ci size = data_attr->attr.size; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci if (offset < 0) 4488c2ecf20Sopenharmony_ci return -EINVAL; 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci if (offset >= size) 4518c2ecf20Sopenharmony_ci return 0; 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci if (count > size - offset) 4548c2ecf20Sopenharmony_ci count = size - offset; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci base = acpi_os_map_iomem(data_attr->addr, size); 4578c2ecf20Sopenharmony_ci if (!base) 4588c2ecf20Sopenharmony_ci return -ENOMEM; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci memcpy_fromio(buf, base + offset, count); 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci acpi_os_unmap_iomem(base, size); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci return count; 4658c2ecf20Sopenharmony_ci} 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_cistatic int acpi_bert_data_init(void *th, struct acpi_data_attr *data_attr) 4688c2ecf20Sopenharmony_ci{ 4698c2ecf20Sopenharmony_ci struct acpi_table_bert *bert = th; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci if (bert->header.length < sizeof(struct acpi_table_bert) || 4728c2ecf20Sopenharmony_ci bert->region_length < sizeof(struct acpi_hest_generic_status)) { 4738c2ecf20Sopenharmony_ci kfree(data_attr); 4748c2ecf20Sopenharmony_ci return -EINVAL; 4758c2ecf20Sopenharmony_ci } 4768c2ecf20Sopenharmony_ci data_attr->addr = bert->address; 4778c2ecf20Sopenharmony_ci data_attr->attr.size = bert->region_length; 4788c2ecf20Sopenharmony_ci data_attr->attr.attr.name = "BERT"; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci return sysfs_create_bin_file(tables_data_kobj, &data_attr->attr); 4818c2ecf20Sopenharmony_ci} 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_cistatic struct acpi_data_obj { 4848c2ecf20Sopenharmony_ci char *name; 4858c2ecf20Sopenharmony_ci int (*fn)(void *, struct acpi_data_attr *); 4868c2ecf20Sopenharmony_ci} acpi_data_objs[] = { 4878c2ecf20Sopenharmony_ci { ACPI_SIG_BERT, acpi_bert_data_init }, 4888c2ecf20Sopenharmony_ci}; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci#define NUM_ACPI_DATA_OBJS ARRAY_SIZE(acpi_data_objs) 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_cistatic int acpi_table_data_init(struct acpi_table_header *th) 4938c2ecf20Sopenharmony_ci{ 4948c2ecf20Sopenharmony_ci struct acpi_data_attr *data_attr; 4958c2ecf20Sopenharmony_ci int i; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci for (i = 0; i < NUM_ACPI_DATA_OBJS; i++) { 4988c2ecf20Sopenharmony_ci if (ACPI_COMPARE_NAMESEG(th->signature, acpi_data_objs[i].name)) { 4998c2ecf20Sopenharmony_ci data_attr = kzalloc(sizeof(*data_attr), GFP_KERNEL); 5008c2ecf20Sopenharmony_ci if (!data_attr) 5018c2ecf20Sopenharmony_ci return -ENOMEM; 5028c2ecf20Sopenharmony_ci sysfs_attr_init(&data_attr->attr.attr); 5038c2ecf20Sopenharmony_ci data_attr->attr.read = acpi_data_show; 5048c2ecf20Sopenharmony_ci data_attr->attr.attr.mode = 0400; 5058c2ecf20Sopenharmony_ci return acpi_data_objs[i].fn(th, data_attr); 5068c2ecf20Sopenharmony_ci } 5078c2ecf20Sopenharmony_ci } 5088c2ecf20Sopenharmony_ci return 0; 5098c2ecf20Sopenharmony_ci} 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_cistatic int acpi_tables_sysfs_init(void) 5128c2ecf20Sopenharmony_ci{ 5138c2ecf20Sopenharmony_ci struct acpi_table_attr *table_attr; 5148c2ecf20Sopenharmony_ci struct acpi_table_header *table_header = NULL; 5158c2ecf20Sopenharmony_ci int table_index; 5168c2ecf20Sopenharmony_ci acpi_status status; 5178c2ecf20Sopenharmony_ci int ret; 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci tables_kobj = kobject_create_and_add("tables", acpi_kobj); 5208c2ecf20Sopenharmony_ci if (!tables_kobj) 5218c2ecf20Sopenharmony_ci goto err; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci tables_data_kobj = kobject_create_and_add("data", tables_kobj); 5248c2ecf20Sopenharmony_ci if (!tables_data_kobj) 5258c2ecf20Sopenharmony_ci goto err_tables_data; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj); 5288c2ecf20Sopenharmony_ci if (!dynamic_tables_kobj) 5298c2ecf20Sopenharmony_ci goto err_dynamic_tables; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci for (table_index = 0;; table_index++) { 5328c2ecf20Sopenharmony_ci status = acpi_get_table_by_index(table_index, &table_header); 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci if (status == AE_BAD_PARAMETER) 5358c2ecf20Sopenharmony_ci break; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci if (ACPI_FAILURE(status)) 5388c2ecf20Sopenharmony_ci continue; 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci table_attr = kzalloc(sizeof(*table_attr), GFP_KERNEL); 5418c2ecf20Sopenharmony_ci if (!table_attr) 5428c2ecf20Sopenharmony_ci return -ENOMEM; 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci ret = acpi_table_attr_init(tables_kobj, 5458c2ecf20Sopenharmony_ci table_attr, table_header); 5468c2ecf20Sopenharmony_ci if (ret) { 5478c2ecf20Sopenharmony_ci kfree(table_attr); 5488c2ecf20Sopenharmony_ci return ret; 5498c2ecf20Sopenharmony_ci } 5508c2ecf20Sopenharmony_ci list_add_tail(&table_attr->node, &acpi_table_attr_list); 5518c2ecf20Sopenharmony_ci acpi_table_data_init(table_header); 5528c2ecf20Sopenharmony_ci } 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci kobject_uevent(tables_kobj, KOBJ_ADD); 5558c2ecf20Sopenharmony_ci kobject_uevent(tables_data_kobj, KOBJ_ADD); 5568c2ecf20Sopenharmony_ci kobject_uevent(dynamic_tables_kobj, KOBJ_ADD); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci return 0; 5598c2ecf20Sopenharmony_cierr_dynamic_tables: 5608c2ecf20Sopenharmony_ci kobject_put(tables_data_kobj); 5618c2ecf20Sopenharmony_cierr_tables_data: 5628c2ecf20Sopenharmony_ci kobject_put(tables_kobj); 5638c2ecf20Sopenharmony_cierr: 5648c2ecf20Sopenharmony_ci return -ENOMEM; 5658c2ecf20Sopenharmony_ci} 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci/* 5688c2ecf20Sopenharmony_ci * Detailed ACPI IRQ counters: 5698c2ecf20Sopenharmony_ci * /sys/firmware/acpi/interrupts/ 5708c2ecf20Sopenharmony_ci */ 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ciu32 acpi_irq_handled; 5738c2ecf20Sopenharmony_ciu32 acpi_irq_not_handled; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci#define COUNT_GPE 0 5768c2ecf20Sopenharmony_ci#define COUNT_SCI 1 /* acpi_irq_handled */ 5778c2ecf20Sopenharmony_ci#define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */ 5788c2ecf20Sopenharmony_ci#define COUNT_ERROR 3 /* other */ 5798c2ecf20Sopenharmony_ci#define NUM_COUNTERS_EXTRA 4 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_cistruct event_counter { 5828c2ecf20Sopenharmony_ci u32 count; 5838c2ecf20Sopenharmony_ci u32 flags; 5848c2ecf20Sopenharmony_ci}; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_cistatic struct event_counter *all_counters; 5878c2ecf20Sopenharmony_cistatic u32 num_gpes; 5888c2ecf20Sopenharmony_cistatic u32 num_counters; 5898c2ecf20Sopenharmony_cistatic struct attribute **all_attrs; 5908c2ecf20Sopenharmony_cistatic u32 acpi_gpe_count; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_cistatic struct attribute_group interrupt_stats_attr_group = { 5938c2ecf20Sopenharmony_ci .name = "interrupts", 5948c2ecf20Sopenharmony_ci}; 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_cistatic struct kobj_attribute *counter_attrs; 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_cistatic void delete_gpe_attr_array(void) 5998c2ecf20Sopenharmony_ci{ 6008c2ecf20Sopenharmony_ci struct event_counter *tmp = all_counters; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci all_counters = NULL; 6038c2ecf20Sopenharmony_ci kfree(tmp); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci if (counter_attrs) { 6068c2ecf20Sopenharmony_ci int i; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci for (i = 0; i < num_gpes; i++) 6098c2ecf20Sopenharmony_ci kfree(counter_attrs[i].attr.name); 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci kfree(counter_attrs); 6128c2ecf20Sopenharmony_ci } 6138c2ecf20Sopenharmony_ci kfree(all_attrs); 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci return; 6168c2ecf20Sopenharmony_ci} 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_cistatic void gpe_count(u32 gpe_number) 6198c2ecf20Sopenharmony_ci{ 6208c2ecf20Sopenharmony_ci acpi_gpe_count++; 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci if (!all_counters) 6238c2ecf20Sopenharmony_ci return; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci if (gpe_number < num_gpes) 6268c2ecf20Sopenharmony_ci all_counters[gpe_number].count++; 6278c2ecf20Sopenharmony_ci else 6288c2ecf20Sopenharmony_ci all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + 6298c2ecf20Sopenharmony_ci COUNT_ERROR].count++; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci return; 6328c2ecf20Sopenharmony_ci} 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_cistatic void fixed_event_count(u32 event_number) 6358c2ecf20Sopenharmony_ci{ 6368c2ecf20Sopenharmony_ci if (!all_counters) 6378c2ecf20Sopenharmony_ci return; 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci if (event_number < ACPI_NUM_FIXED_EVENTS) 6408c2ecf20Sopenharmony_ci all_counters[num_gpes + event_number].count++; 6418c2ecf20Sopenharmony_ci else 6428c2ecf20Sopenharmony_ci all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + 6438c2ecf20Sopenharmony_ci COUNT_ERROR].count++; 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci return; 6468c2ecf20Sopenharmony_ci} 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_cistatic void acpi_global_event_handler(u32 event_type, acpi_handle device, 6498c2ecf20Sopenharmony_ci u32 event_number, void *context) 6508c2ecf20Sopenharmony_ci{ 6518c2ecf20Sopenharmony_ci if (event_type == ACPI_EVENT_TYPE_GPE) { 6528c2ecf20Sopenharmony_ci gpe_count(event_number); 6538c2ecf20Sopenharmony_ci pr_debug("GPE event 0x%02x\n", event_number); 6548c2ecf20Sopenharmony_ci } else if (event_type == ACPI_EVENT_TYPE_FIXED) { 6558c2ecf20Sopenharmony_ci fixed_event_count(event_number); 6568c2ecf20Sopenharmony_ci pr_debug("Fixed event 0x%02x\n", event_number); 6578c2ecf20Sopenharmony_ci } else { 6588c2ecf20Sopenharmony_ci pr_debug("Other event 0x%02x\n", event_number); 6598c2ecf20Sopenharmony_ci } 6608c2ecf20Sopenharmony_ci} 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_cistatic int get_status(u32 index, acpi_event_status *ret, 6638c2ecf20Sopenharmony_ci acpi_handle *handle) 6648c2ecf20Sopenharmony_ci{ 6658c2ecf20Sopenharmony_ci acpi_status status; 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS) 6688c2ecf20Sopenharmony_ci return -EINVAL; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci if (index < num_gpes) { 6718c2ecf20Sopenharmony_ci status = acpi_get_gpe_device(index, handle); 6728c2ecf20Sopenharmony_ci if (ACPI_FAILURE(status)) { 6738c2ecf20Sopenharmony_ci ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND, 6748c2ecf20Sopenharmony_ci "Invalid GPE 0x%x", index)); 6758c2ecf20Sopenharmony_ci return -ENXIO; 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci status = acpi_get_gpe_status(*handle, index, ret); 6788c2ecf20Sopenharmony_ci } else { 6798c2ecf20Sopenharmony_ci status = acpi_get_event_status(index - num_gpes, ret); 6808c2ecf20Sopenharmony_ci } 6818c2ecf20Sopenharmony_ci if (ACPI_FAILURE(status)) 6828c2ecf20Sopenharmony_ci return -EIO; 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci return 0; 6858c2ecf20Sopenharmony_ci} 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_cistatic ssize_t counter_show(struct kobject *kobj, 6888c2ecf20Sopenharmony_ci struct kobj_attribute *attr, char *buf) 6898c2ecf20Sopenharmony_ci{ 6908c2ecf20Sopenharmony_ci int index = attr - counter_attrs; 6918c2ecf20Sopenharmony_ci int size; 6928c2ecf20Sopenharmony_ci acpi_handle handle; 6938c2ecf20Sopenharmony_ci acpi_event_status status; 6948c2ecf20Sopenharmony_ci int result = 0; 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count = 6978c2ecf20Sopenharmony_ci acpi_irq_handled; 6988c2ecf20Sopenharmony_ci all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count = 6998c2ecf20Sopenharmony_ci acpi_irq_not_handled; 7008c2ecf20Sopenharmony_ci all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count = 7018c2ecf20Sopenharmony_ci acpi_gpe_count; 7028c2ecf20Sopenharmony_ci size = sprintf(buf, "%8u", all_counters[index].count); 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci /* "gpe_all" or "sci" */ 7058c2ecf20Sopenharmony_ci if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS) 7068c2ecf20Sopenharmony_ci goto end; 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci result = get_status(index, &status, &handle); 7098c2ecf20Sopenharmony_ci if (result) 7108c2ecf20Sopenharmony_ci goto end; 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci if (status & ACPI_EVENT_FLAG_ENABLE_SET) 7138c2ecf20Sopenharmony_ci size += sprintf(buf + size, " EN"); 7148c2ecf20Sopenharmony_ci else 7158c2ecf20Sopenharmony_ci size += sprintf(buf + size, " "); 7168c2ecf20Sopenharmony_ci if (status & ACPI_EVENT_FLAG_STATUS_SET) 7178c2ecf20Sopenharmony_ci size += sprintf(buf + size, " STS"); 7188c2ecf20Sopenharmony_ci else 7198c2ecf20Sopenharmony_ci size += sprintf(buf + size, " "); 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci if (!(status & ACPI_EVENT_FLAG_HAS_HANDLER)) 7228c2ecf20Sopenharmony_ci size += sprintf(buf + size, " invalid "); 7238c2ecf20Sopenharmony_ci else if (status & ACPI_EVENT_FLAG_ENABLED) 7248c2ecf20Sopenharmony_ci size += sprintf(buf + size, " enabled "); 7258c2ecf20Sopenharmony_ci else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED) 7268c2ecf20Sopenharmony_ci size += sprintf(buf + size, " wake_enabled"); 7278c2ecf20Sopenharmony_ci else 7288c2ecf20Sopenharmony_ci size += sprintf(buf + size, " disabled "); 7298c2ecf20Sopenharmony_ci if (status & ACPI_EVENT_FLAG_MASKED) 7308c2ecf20Sopenharmony_ci size += sprintf(buf + size, " masked "); 7318c2ecf20Sopenharmony_ci else 7328c2ecf20Sopenharmony_ci size += sprintf(buf + size, " unmasked"); 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ciend: 7358c2ecf20Sopenharmony_ci size += sprintf(buf + size, "\n"); 7368c2ecf20Sopenharmony_ci return result ? result : size; 7378c2ecf20Sopenharmony_ci} 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci/* 7408c2ecf20Sopenharmony_ci * counter_set() sets the specified counter. 7418c2ecf20Sopenharmony_ci * setting the total "sci" file to any value clears all counters. 7428c2ecf20Sopenharmony_ci * enable/disable/clear a gpe/fixed event in user space. 7438c2ecf20Sopenharmony_ci */ 7448c2ecf20Sopenharmony_cistatic ssize_t counter_set(struct kobject *kobj, 7458c2ecf20Sopenharmony_ci struct kobj_attribute *attr, const char *buf, 7468c2ecf20Sopenharmony_ci size_t size) 7478c2ecf20Sopenharmony_ci{ 7488c2ecf20Sopenharmony_ci int index = attr - counter_attrs; 7498c2ecf20Sopenharmony_ci acpi_event_status status; 7508c2ecf20Sopenharmony_ci acpi_handle handle; 7518c2ecf20Sopenharmony_ci int result = 0; 7528c2ecf20Sopenharmony_ci unsigned long tmp; 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { 7558c2ecf20Sopenharmony_ci int i; 7568c2ecf20Sopenharmony_ci for (i = 0; i < num_counters; ++i) 7578c2ecf20Sopenharmony_ci all_counters[i].count = 0; 7588c2ecf20Sopenharmony_ci acpi_gpe_count = 0; 7598c2ecf20Sopenharmony_ci acpi_irq_handled = 0; 7608c2ecf20Sopenharmony_ci acpi_irq_not_handled = 0; 7618c2ecf20Sopenharmony_ci goto end; 7628c2ecf20Sopenharmony_ci } 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci /* show the event status for both GPEs and Fixed Events */ 7658c2ecf20Sopenharmony_ci result = get_status(index, &status, &handle); 7668c2ecf20Sopenharmony_ci if (result) 7678c2ecf20Sopenharmony_ci goto end; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci if (!(status & ACPI_EVENT_FLAG_HAS_HANDLER)) { 7708c2ecf20Sopenharmony_ci printk(KERN_WARNING PREFIX 7718c2ecf20Sopenharmony_ci "Can not change Invalid GPE/Fixed Event status\n"); 7728c2ecf20Sopenharmony_ci return -EINVAL; 7738c2ecf20Sopenharmony_ci } 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci if (index < num_gpes) { 7768c2ecf20Sopenharmony_ci if (!strcmp(buf, "disable\n") && 7778c2ecf20Sopenharmony_ci (status & ACPI_EVENT_FLAG_ENABLED)) 7788c2ecf20Sopenharmony_ci result = acpi_disable_gpe(handle, index); 7798c2ecf20Sopenharmony_ci else if (!strcmp(buf, "enable\n") && 7808c2ecf20Sopenharmony_ci !(status & ACPI_EVENT_FLAG_ENABLED)) 7818c2ecf20Sopenharmony_ci result = acpi_enable_gpe(handle, index); 7828c2ecf20Sopenharmony_ci else if (!strcmp(buf, "clear\n") && 7838c2ecf20Sopenharmony_ci (status & ACPI_EVENT_FLAG_STATUS_SET)) 7848c2ecf20Sopenharmony_ci result = acpi_clear_gpe(handle, index); 7858c2ecf20Sopenharmony_ci else if (!strcmp(buf, "mask\n")) 7868c2ecf20Sopenharmony_ci result = acpi_mask_gpe(handle, index, TRUE); 7878c2ecf20Sopenharmony_ci else if (!strcmp(buf, "unmask\n")) 7888c2ecf20Sopenharmony_ci result = acpi_mask_gpe(handle, index, FALSE); 7898c2ecf20Sopenharmony_ci else if (!kstrtoul(buf, 0, &tmp)) 7908c2ecf20Sopenharmony_ci all_counters[index].count = tmp; 7918c2ecf20Sopenharmony_ci else 7928c2ecf20Sopenharmony_ci result = -EINVAL; 7938c2ecf20Sopenharmony_ci } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) { 7948c2ecf20Sopenharmony_ci int event = index - num_gpes; 7958c2ecf20Sopenharmony_ci if (!strcmp(buf, "disable\n") && 7968c2ecf20Sopenharmony_ci (status & ACPI_EVENT_FLAG_ENABLE_SET)) 7978c2ecf20Sopenharmony_ci result = acpi_disable_event(event, ACPI_NOT_ISR); 7988c2ecf20Sopenharmony_ci else if (!strcmp(buf, "enable\n") && 7998c2ecf20Sopenharmony_ci !(status & ACPI_EVENT_FLAG_ENABLE_SET)) 8008c2ecf20Sopenharmony_ci result = acpi_enable_event(event, ACPI_NOT_ISR); 8018c2ecf20Sopenharmony_ci else if (!strcmp(buf, "clear\n") && 8028c2ecf20Sopenharmony_ci (status & ACPI_EVENT_FLAG_STATUS_SET)) 8038c2ecf20Sopenharmony_ci result = acpi_clear_event(event); 8048c2ecf20Sopenharmony_ci else if (!kstrtoul(buf, 0, &tmp)) 8058c2ecf20Sopenharmony_ci all_counters[index].count = tmp; 8068c2ecf20Sopenharmony_ci else 8078c2ecf20Sopenharmony_ci result = -EINVAL; 8088c2ecf20Sopenharmony_ci } else 8098c2ecf20Sopenharmony_ci all_counters[index].count = strtoul(buf, NULL, 0); 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci if (ACPI_FAILURE(result)) 8128c2ecf20Sopenharmony_ci result = -EINVAL; 8138c2ecf20Sopenharmony_ciend: 8148c2ecf20Sopenharmony_ci return result ? result : size; 8158c2ecf20Sopenharmony_ci} 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci/* 8188c2ecf20Sopenharmony_ci * A Quirk Mechanism for GPE Flooding Prevention: 8198c2ecf20Sopenharmony_ci * 8208c2ecf20Sopenharmony_ci * Quirks may be needed to prevent GPE flooding on a specific GPE. The 8218c2ecf20Sopenharmony_ci * flooding typically cannot be detected and automatically prevented by 8228c2ecf20Sopenharmony_ci * ACPI_GPE_DISPATCH_NONE check because there is a _Lxx/_Exx prepared in 8238c2ecf20Sopenharmony_ci * the AML tables. This normally indicates a feature gap in Linux, thus 8248c2ecf20Sopenharmony_ci * instead of providing endless quirk tables, we provide a boot parameter 8258c2ecf20Sopenharmony_ci * for those who want this quirk. For example, if the users want to prevent 8268c2ecf20Sopenharmony_ci * the GPE flooding for GPE 00, they need to specify the following boot 8278c2ecf20Sopenharmony_ci * parameter: 8288c2ecf20Sopenharmony_ci * acpi_mask_gpe=0x00 8298c2ecf20Sopenharmony_ci * The masking status can be modified by the following runtime controlling 8308c2ecf20Sopenharmony_ci * interface: 8318c2ecf20Sopenharmony_ci * echo unmask > /sys/firmware/acpi/interrupts/gpe00 8328c2ecf20Sopenharmony_ci */ 8338c2ecf20Sopenharmony_ci#define ACPI_MASKABLE_GPE_MAX 0x100 8348c2ecf20Sopenharmony_cistatic DECLARE_BITMAP(acpi_masked_gpes_map, ACPI_MASKABLE_GPE_MAX) __initdata; 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_cistatic int __init acpi_gpe_set_masked_gpes(char *val) 8378c2ecf20Sopenharmony_ci{ 8388c2ecf20Sopenharmony_ci u8 gpe; 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci if (kstrtou8(val, 0, &gpe)) 8418c2ecf20Sopenharmony_ci return -EINVAL; 8428c2ecf20Sopenharmony_ci set_bit(gpe, acpi_masked_gpes_map); 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci return 1; 8458c2ecf20Sopenharmony_ci} 8468c2ecf20Sopenharmony_ci__setup("acpi_mask_gpe=", acpi_gpe_set_masked_gpes); 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_civoid __init acpi_gpe_apply_masked_gpes(void) 8498c2ecf20Sopenharmony_ci{ 8508c2ecf20Sopenharmony_ci acpi_handle handle; 8518c2ecf20Sopenharmony_ci acpi_status status; 8528c2ecf20Sopenharmony_ci u16 gpe; 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci for_each_set_bit(gpe, acpi_masked_gpes_map, ACPI_MASKABLE_GPE_MAX) { 8558c2ecf20Sopenharmony_ci status = acpi_get_gpe_device(gpe, &handle); 8568c2ecf20Sopenharmony_ci if (ACPI_SUCCESS(status)) { 8578c2ecf20Sopenharmony_ci pr_info("Masking GPE 0x%x.\n", gpe); 8588c2ecf20Sopenharmony_ci (void)acpi_mask_gpe(handle, gpe, TRUE); 8598c2ecf20Sopenharmony_ci } 8608c2ecf20Sopenharmony_ci } 8618c2ecf20Sopenharmony_ci} 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_civoid acpi_irq_stats_init(void) 8648c2ecf20Sopenharmony_ci{ 8658c2ecf20Sopenharmony_ci acpi_status status; 8668c2ecf20Sopenharmony_ci int i; 8678c2ecf20Sopenharmony_ci 8688c2ecf20Sopenharmony_ci if (all_counters) 8698c2ecf20Sopenharmony_ci return; 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci num_gpes = acpi_current_gpe_count; 8728c2ecf20Sopenharmony_ci num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA; 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci all_attrs = kcalloc(num_counters + 1, sizeof(struct attribute *), 8758c2ecf20Sopenharmony_ci GFP_KERNEL); 8768c2ecf20Sopenharmony_ci if (all_attrs == NULL) 8778c2ecf20Sopenharmony_ci return; 8788c2ecf20Sopenharmony_ci 8798c2ecf20Sopenharmony_ci all_counters = kcalloc(num_counters, sizeof(struct event_counter), 8808c2ecf20Sopenharmony_ci GFP_KERNEL); 8818c2ecf20Sopenharmony_ci if (all_counters == NULL) 8828c2ecf20Sopenharmony_ci goto fail; 8838c2ecf20Sopenharmony_ci 8848c2ecf20Sopenharmony_ci status = acpi_install_global_event_handler(acpi_global_event_handler, NULL); 8858c2ecf20Sopenharmony_ci if (ACPI_FAILURE(status)) 8868c2ecf20Sopenharmony_ci goto fail; 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_ci counter_attrs = kcalloc(num_counters, sizeof(struct kobj_attribute), 8898c2ecf20Sopenharmony_ci GFP_KERNEL); 8908c2ecf20Sopenharmony_ci if (counter_attrs == NULL) 8918c2ecf20Sopenharmony_ci goto fail; 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci for (i = 0; i < num_counters; ++i) { 8948c2ecf20Sopenharmony_ci char buffer[12]; 8958c2ecf20Sopenharmony_ci char *name; 8968c2ecf20Sopenharmony_ci 8978c2ecf20Sopenharmony_ci if (i < num_gpes) 8988c2ecf20Sopenharmony_ci sprintf(buffer, "gpe%02X", i); 8998c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_EVENT_PMTIMER) 9008c2ecf20Sopenharmony_ci sprintf(buffer, "ff_pmtimer"); 9018c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_EVENT_GLOBAL) 9028c2ecf20Sopenharmony_ci sprintf(buffer, "ff_gbl_lock"); 9038c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON) 9048c2ecf20Sopenharmony_ci sprintf(buffer, "ff_pwr_btn"); 9058c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON) 9068c2ecf20Sopenharmony_ci sprintf(buffer, "ff_slp_btn"); 9078c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_EVENT_RTC) 9088c2ecf20Sopenharmony_ci sprintf(buffer, "ff_rt_clk"); 9098c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE) 9108c2ecf20Sopenharmony_ci sprintf(buffer, "gpe_all"); 9118c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) 9128c2ecf20Sopenharmony_ci sprintf(buffer, "sci"); 9138c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT) 9148c2ecf20Sopenharmony_ci sprintf(buffer, "sci_not"); 9158c2ecf20Sopenharmony_ci else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR) 9168c2ecf20Sopenharmony_ci sprintf(buffer, "error"); 9178c2ecf20Sopenharmony_ci else 9188c2ecf20Sopenharmony_ci sprintf(buffer, "bug%02X", i); 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci name = kstrdup(buffer, GFP_KERNEL); 9218c2ecf20Sopenharmony_ci if (name == NULL) 9228c2ecf20Sopenharmony_ci goto fail; 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci sysfs_attr_init(&counter_attrs[i].attr); 9258c2ecf20Sopenharmony_ci counter_attrs[i].attr.name = name; 9268c2ecf20Sopenharmony_ci counter_attrs[i].attr.mode = 0644; 9278c2ecf20Sopenharmony_ci counter_attrs[i].show = counter_show; 9288c2ecf20Sopenharmony_ci counter_attrs[i].store = counter_set; 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci all_attrs[i] = &counter_attrs[i].attr; 9318c2ecf20Sopenharmony_ci } 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci interrupt_stats_attr_group.attrs = all_attrs; 9348c2ecf20Sopenharmony_ci if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group)) 9358c2ecf20Sopenharmony_ci return; 9368c2ecf20Sopenharmony_ci 9378c2ecf20Sopenharmony_cifail: 9388c2ecf20Sopenharmony_ci delete_gpe_attr_array(); 9398c2ecf20Sopenharmony_ci return; 9408c2ecf20Sopenharmony_ci} 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_cistatic void __exit interrupt_stats_exit(void) 9438c2ecf20Sopenharmony_ci{ 9448c2ecf20Sopenharmony_ci sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group); 9458c2ecf20Sopenharmony_ci 9468c2ecf20Sopenharmony_ci delete_gpe_attr_array(); 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci return; 9498c2ecf20Sopenharmony_ci} 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_cistatic ssize_t 9528c2ecf20Sopenharmony_ciacpi_show_profile(struct kobject *kobj, struct kobj_attribute *attr, 9538c2ecf20Sopenharmony_ci char *buf) 9548c2ecf20Sopenharmony_ci{ 9558c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", acpi_gbl_FADT.preferred_profile); 9568c2ecf20Sopenharmony_ci} 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_cistatic const struct kobj_attribute pm_profile_attr = 9598c2ecf20Sopenharmony_ci __ATTR(pm_profile, S_IRUGO, acpi_show_profile, NULL); 9608c2ecf20Sopenharmony_ci 9618c2ecf20Sopenharmony_cistatic ssize_t hotplug_enabled_show(struct kobject *kobj, 9628c2ecf20Sopenharmony_ci struct kobj_attribute *attr, char *buf) 9638c2ecf20Sopenharmony_ci{ 9648c2ecf20Sopenharmony_ci struct acpi_hotplug_profile *hotplug = to_acpi_hotplug_profile(kobj); 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", hotplug->enabled); 9678c2ecf20Sopenharmony_ci} 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_cistatic ssize_t hotplug_enabled_store(struct kobject *kobj, 9708c2ecf20Sopenharmony_ci struct kobj_attribute *attr, 9718c2ecf20Sopenharmony_ci const char *buf, size_t size) 9728c2ecf20Sopenharmony_ci{ 9738c2ecf20Sopenharmony_ci struct acpi_hotplug_profile *hotplug = to_acpi_hotplug_profile(kobj); 9748c2ecf20Sopenharmony_ci unsigned int val; 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci if (kstrtouint(buf, 10, &val) || val > 1) 9778c2ecf20Sopenharmony_ci return -EINVAL; 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci acpi_scan_hotplug_enabled(hotplug, val); 9808c2ecf20Sopenharmony_ci return size; 9818c2ecf20Sopenharmony_ci} 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_cistatic struct kobj_attribute hotplug_enabled_attr = 9848c2ecf20Sopenharmony_ci __ATTR(enabled, S_IRUGO | S_IWUSR, hotplug_enabled_show, 9858c2ecf20Sopenharmony_ci hotplug_enabled_store); 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_cistatic struct attribute *hotplug_profile_attrs[] = { 9888c2ecf20Sopenharmony_ci &hotplug_enabled_attr.attr, 9898c2ecf20Sopenharmony_ci NULL 9908c2ecf20Sopenharmony_ci}; 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_cistatic struct kobj_type acpi_hotplug_profile_ktype = { 9938c2ecf20Sopenharmony_ci .sysfs_ops = &kobj_sysfs_ops, 9948c2ecf20Sopenharmony_ci .default_attrs = hotplug_profile_attrs, 9958c2ecf20Sopenharmony_ci}; 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_civoid acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug, 9988c2ecf20Sopenharmony_ci const char *name) 9998c2ecf20Sopenharmony_ci{ 10008c2ecf20Sopenharmony_ci int error; 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci if (!hotplug_kobj) 10038c2ecf20Sopenharmony_ci goto err_out; 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci error = kobject_init_and_add(&hotplug->kobj, 10068c2ecf20Sopenharmony_ci &acpi_hotplug_profile_ktype, hotplug_kobj, "%s", name); 10078c2ecf20Sopenharmony_ci if (error) { 10088c2ecf20Sopenharmony_ci kobject_put(&hotplug->kobj); 10098c2ecf20Sopenharmony_ci goto err_out; 10108c2ecf20Sopenharmony_ci } 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci kobject_uevent(&hotplug->kobj, KOBJ_ADD); 10138c2ecf20Sopenharmony_ci return; 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci err_out: 10168c2ecf20Sopenharmony_ci pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name); 10178c2ecf20Sopenharmony_ci} 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_cistatic ssize_t force_remove_show(struct kobject *kobj, 10208c2ecf20Sopenharmony_ci struct kobj_attribute *attr, char *buf) 10218c2ecf20Sopenharmony_ci{ 10228c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", 0); 10238c2ecf20Sopenharmony_ci} 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_cistatic ssize_t force_remove_store(struct kobject *kobj, 10268c2ecf20Sopenharmony_ci struct kobj_attribute *attr, 10278c2ecf20Sopenharmony_ci const char *buf, size_t size) 10288c2ecf20Sopenharmony_ci{ 10298c2ecf20Sopenharmony_ci bool val; 10308c2ecf20Sopenharmony_ci int ret; 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci ret = strtobool(buf, &val); 10338c2ecf20Sopenharmony_ci if (ret < 0) 10348c2ecf20Sopenharmony_ci return ret; 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_ci if (val) { 10378c2ecf20Sopenharmony_ci pr_err("Enabling force_remove is not supported anymore. Please report to linux-acpi@vger.kernel.org if you depend on this functionality\n"); 10388c2ecf20Sopenharmony_ci return -EINVAL; 10398c2ecf20Sopenharmony_ci } 10408c2ecf20Sopenharmony_ci return size; 10418c2ecf20Sopenharmony_ci} 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_cistatic const struct kobj_attribute force_remove_attr = 10448c2ecf20Sopenharmony_ci __ATTR(force_remove, S_IRUGO | S_IWUSR, force_remove_show, 10458c2ecf20Sopenharmony_ci force_remove_store); 10468c2ecf20Sopenharmony_ci 10478c2ecf20Sopenharmony_ciint __init acpi_sysfs_init(void) 10488c2ecf20Sopenharmony_ci{ 10498c2ecf20Sopenharmony_ci int result; 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_ci result = acpi_tables_sysfs_init(); 10528c2ecf20Sopenharmony_ci if (result) 10538c2ecf20Sopenharmony_ci return result; 10548c2ecf20Sopenharmony_ci 10558c2ecf20Sopenharmony_ci hotplug_kobj = kobject_create_and_add("hotplug", acpi_kobj); 10568c2ecf20Sopenharmony_ci if (!hotplug_kobj) 10578c2ecf20Sopenharmony_ci return -ENOMEM; 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci result = sysfs_create_file(hotplug_kobj, &force_remove_attr.attr); 10608c2ecf20Sopenharmony_ci if (result) 10618c2ecf20Sopenharmony_ci return result; 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_ci result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr); 10648c2ecf20Sopenharmony_ci return result; 10658c2ecf20Sopenharmony_ci} 1066