2 * sysfs.c - ACPI sysfs interface to userspace.
5 #include <linux/init.h>
6 #include <linux/kernel.h>
7 #include <linux/moduleparam.h>
8 #include <acpi/acpi_drivers.h>
10 #define _COMPONENT ACPI_SYSTEM_COMPONENT
11 ACPI_MODULE_NAME("sysfs");
13 #define PREFIX "ACPI: "
15 #ifdef CONFIG_ACPI_DEBUG
17 * ACPI debug sysfs I/F, including:
18 * /sys/modules/acpi/parameters/debug_layer
19 * /sys/modules/acpi/parameters/debug_level
20 * /sys/modules/acpi/parameters/trace_method_name
21 * /sys/modules/acpi/parameters/trace_state
22 * /sys/modules/acpi/parameters/trace_debug_layer
23 * /sys/modules/acpi/parameters/trace_debug_level
34 #define ACPI_DEBUG_INIT(v) { .name = #v, .value = v }
36 static const struct acpi_dlayer acpi_debug_layers
[] = {
37 ACPI_DEBUG_INIT(ACPI_UTILITIES
),
38 ACPI_DEBUG_INIT(ACPI_HARDWARE
),
39 ACPI_DEBUG_INIT(ACPI_EVENTS
),
40 ACPI_DEBUG_INIT(ACPI_TABLES
),
41 ACPI_DEBUG_INIT(ACPI_NAMESPACE
),
42 ACPI_DEBUG_INIT(ACPI_PARSER
),
43 ACPI_DEBUG_INIT(ACPI_DISPATCHER
),
44 ACPI_DEBUG_INIT(ACPI_EXECUTER
),
45 ACPI_DEBUG_INIT(ACPI_RESOURCES
),
46 ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER
),
47 ACPI_DEBUG_INIT(ACPI_OS_SERVICES
),
48 ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER
),
49 ACPI_DEBUG_INIT(ACPI_COMPILER
),
50 ACPI_DEBUG_INIT(ACPI_TOOLS
),
52 ACPI_DEBUG_INIT(ACPI_BUS_COMPONENT
),
53 ACPI_DEBUG_INIT(ACPI_AC_COMPONENT
),
54 ACPI_DEBUG_INIT(ACPI_BATTERY_COMPONENT
),
55 ACPI_DEBUG_INIT(ACPI_BUTTON_COMPONENT
),
56 ACPI_DEBUG_INIT(ACPI_SBS_COMPONENT
),
57 ACPI_DEBUG_INIT(ACPI_FAN_COMPONENT
),
58 ACPI_DEBUG_INIT(ACPI_PCI_COMPONENT
),
59 ACPI_DEBUG_INIT(ACPI_POWER_COMPONENT
),
60 ACPI_DEBUG_INIT(ACPI_CONTAINER_COMPONENT
),
61 ACPI_DEBUG_INIT(ACPI_SYSTEM_COMPONENT
),
62 ACPI_DEBUG_INIT(ACPI_THERMAL_COMPONENT
),
63 ACPI_DEBUG_INIT(ACPI_MEMORY_DEVICE_COMPONENT
),
64 ACPI_DEBUG_INIT(ACPI_VIDEO_COMPONENT
),
65 ACPI_DEBUG_INIT(ACPI_PROCESSOR_COMPONENT
),
68 static const struct acpi_dlevel acpi_debug_levels
[] = {
69 ACPI_DEBUG_INIT(ACPI_LV_INIT
),
70 ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT
),
71 ACPI_DEBUG_INIT(ACPI_LV_INFO
),
73 ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES
),
74 ACPI_DEBUG_INIT(ACPI_LV_PARSE
),
75 ACPI_DEBUG_INIT(ACPI_LV_LOAD
),
76 ACPI_DEBUG_INIT(ACPI_LV_DISPATCH
),
77 ACPI_DEBUG_INIT(ACPI_LV_EXEC
),
78 ACPI_DEBUG_INIT(ACPI_LV_NAMES
),
79 ACPI_DEBUG_INIT(ACPI_LV_OPREGION
),
80 ACPI_DEBUG_INIT(ACPI_LV_BFIELD
),
81 ACPI_DEBUG_INIT(ACPI_LV_TABLES
),
82 ACPI_DEBUG_INIT(ACPI_LV_VALUES
),
83 ACPI_DEBUG_INIT(ACPI_LV_OBJECTS
),
84 ACPI_DEBUG_INIT(ACPI_LV_RESOURCES
),
85 ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS
),
86 ACPI_DEBUG_INIT(ACPI_LV_PACKAGE
),
88 ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS
),
89 ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS
),
90 ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS
),
92 ACPI_DEBUG_INIT(ACPI_LV_MUTEX
),
93 ACPI_DEBUG_INIT(ACPI_LV_THREADS
),
94 ACPI_DEBUG_INIT(ACPI_LV_IO
),
95 ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS
),
97 ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE
),
98 ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO
),
99 ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES
),
100 ACPI_DEBUG_INIT(ACPI_LV_EVENTS
),
103 static int param_get_debug_layer(char *buffer
, struct kernel_param
*kp
)
108 result
= sprintf(buffer
, "%-25s\tHex SET\n", "Description");
110 for (i
= 0; i
< ARRAY_SIZE(acpi_debug_layers
); i
++) {
111 result
+= sprintf(buffer
+ result
, "%-25s\t0x%08lX [%c]\n",
112 acpi_debug_layers
[i
].name
,
113 acpi_debug_layers
[i
].value
,
114 (acpi_dbg_layer
& acpi_debug_layers
[i
].value
)
118 sprintf(buffer
+ result
, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
120 (acpi_dbg_layer
& ACPI_ALL_DRIVERS
) ==
121 ACPI_ALL_DRIVERS
? '*' : (acpi_dbg_layer
& ACPI_ALL_DRIVERS
)
124 sprintf(buffer
+ result
,
125 "--\ndebug_layer = 0x%08X ( * = enabled)\n",
131 static int param_get_debug_level(char *buffer
, struct kernel_param
*kp
)
136 result
= sprintf(buffer
, "%-25s\tHex SET\n", "Description");
138 for (i
= 0; i
< ARRAY_SIZE(acpi_debug_levels
); i
++) {
139 result
+= sprintf(buffer
+ result
, "%-25s\t0x%08lX [%c]\n",
140 acpi_debug_levels
[i
].name
,
141 acpi_debug_levels
[i
].value
,
142 (acpi_dbg_level
& acpi_debug_levels
[i
].value
)
146 sprintf(buffer
+ result
, "--\ndebug_level = 0x%08X (* = enabled)\n",
152 module_param_call(debug_layer
, param_set_uint
, param_get_debug_layer
,
153 &acpi_dbg_layer
, 0644);
154 module_param_call(debug_level
, param_set_uint
, param_get_debug_level
,
155 &acpi_dbg_level
, 0644);
157 static char trace_method_name
[6];
158 module_param_string(trace_method_name
, trace_method_name
, 6, 0644);
159 static unsigned int trace_debug_layer
;
160 module_param(trace_debug_layer
, uint
, 0644);
161 static unsigned int trace_debug_level
;
162 module_param(trace_debug_level
, uint
, 0644);
164 static int param_set_trace_state(const char *val
, struct kernel_param
*kp
)
168 if (!strncmp(val
, "enable", strlen("enable") - 1)) {
169 result
= acpi_debug_trace(trace_method_name
, trace_debug_level
,
170 trace_debug_layer
, 0);
176 if (!strncmp(val
, "disable", strlen("disable") - 1)) {
178 result
= acpi_debug_trace((char *)&name
, trace_debug_level
,
179 trace_debug_layer
, 0);
185 if (!strncmp(val
, "1", 1)) {
186 result
= acpi_debug_trace(trace_method_name
, trace_debug_level
,
187 trace_debug_layer
, 1);
198 static int param_get_trace_state(char *buffer
, struct kernel_param
*kp
)
200 if (!acpi_gbl_trace_method_name
)
201 return sprintf(buffer
, "disable");
203 if (acpi_gbl_trace_flags
& 1)
204 return sprintf(buffer
, "1");
206 return sprintf(buffer
, "enable");
211 module_param_call(trace_state
, param_set_trace_state
, param_get_trace_state
,
213 #endif /* CONFIG_ACPI_DEBUG */
215 /* /sys/module/acpi/parameters/acpica_version */
216 static int param_get_acpica_version(char *buffer
, struct kernel_param
*kp
)
220 result
= sprintf(buffer
, "%x", ACPI_CA_VERSION
);
225 module_param_call(acpica_version
, NULL
, param_get_acpica_version
, NULL
, 0444);
228 * ACPI table sysfs I/F:
229 * /sys/firmware/acpi/tables/
230 * /sys/firmware/acpi/tables/dynamic/
233 static LIST_HEAD(acpi_table_attr_list
);
234 static struct kobject
*tables_kobj
;
235 static struct kobject
*dynamic_tables_kobj
;
237 struct acpi_table_attr
{
238 struct bin_attribute attr
;
241 struct list_head node
;
244 static ssize_t
acpi_table_show(struct file
*filp
, struct kobject
*kobj
,
245 struct bin_attribute
*bin_attr
, char *buf
,
246 loff_t offset
, size_t count
)
248 struct acpi_table_attr
*table_attr
=
249 container_of(bin_attr
, struct acpi_table_attr
, attr
);
250 struct acpi_table_header
*table_header
= NULL
;
252 char name
[ACPI_NAME_SIZE
];
254 if (strncmp(table_attr
->name
, "NULL", 4))
255 memcpy(name
, table_attr
->name
, ACPI_NAME_SIZE
);
257 memcpy(name
, "\0\0\0\0", 4);
259 status
= acpi_get_table(name
, table_attr
->instance
, &table_header
);
260 if (ACPI_FAILURE(status
))
263 return memory_read_from_buffer(buf
, count
, &offset
,
264 table_header
, table_header
->length
);
267 static void acpi_table_attr_init(struct acpi_table_attr
*table_attr
,
268 struct acpi_table_header
*table_header
)
270 struct acpi_table_header
*header
= NULL
;
271 struct acpi_table_attr
*attr
= NULL
;
273 sysfs_attr_init(&table_attr
->attr
.attr
);
274 if (table_header
->signature
[0] != '\0')
275 memcpy(table_attr
->name
, table_header
->signature
,
278 memcpy(table_attr
->name
, "NULL", 4);
280 list_for_each_entry(attr
, &acpi_table_attr_list
, node
) {
281 if (!memcmp(table_attr
->name
, attr
->name
, ACPI_NAME_SIZE
))
282 if (table_attr
->instance
< attr
->instance
)
283 table_attr
->instance
= attr
->instance
;
285 table_attr
->instance
++;
287 if (table_attr
->instance
> 1 || (table_attr
->instance
== 1 &&
289 (table_header
->signature
, 2, &header
)))
290 sprintf(table_attr
->name
+ ACPI_NAME_SIZE
, "%d",
291 table_attr
->instance
);
293 table_attr
->attr
.size
= 0;
294 table_attr
->attr
.read
= acpi_table_show
;
295 table_attr
->attr
.attr
.name
= table_attr
->name
;
296 table_attr
->attr
.attr
.mode
= 0400;
302 acpi_sysfs_table_handler(u32 event
, void *table
, void *context
)
304 struct acpi_table_attr
*table_attr
;
307 case ACPI_TABLE_EVENT_LOAD
:
309 kzalloc(sizeof(struct acpi_table_attr
), GFP_KERNEL
);
313 acpi_table_attr_init(table_attr
, table
);
314 if (sysfs_create_bin_file(dynamic_tables_kobj
,
315 &table_attr
->attr
)) {
319 list_add_tail(&table_attr
->node
, &acpi_table_attr_list
);
321 case ACPI_TABLE_EVENT_UNLOAD
:
323 * we do not need to do anything right now
324 * because the table is not deleted from the
325 * global table list when unloading it.
329 return AE_BAD_PARAMETER
;
334 static int acpi_tables_sysfs_init(void)
336 struct acpi_table_attr
*table_attr
;
337 struct acpi_table_header
*table_header
= NULL
;
341 tables_kobj
= kobject_create_and_add("tables", acpi_kobj
);
345 dynamic_tables_kobj
= kobject_create_and_add("dynamic", tables_kobj
);
346 if (!dynamic_tables_kobj
)
347 goto err_dynamic_tables
;
350 result
= acpi_get_table_by_index(table_index
, &table_header
);
355 kzalloc(sizeof(struct acpi_table_attr
), GFP_KERNEL
);
359 acpi_table_attr_init(table_attr
, table_header
);
361 sysfs_create_bin_file(tables_kobj
,
367 list_add_tail(&table_attr
->node
,
368 &acpi_table_attr_list
);
371 kobject_uevent(tables_kobj
, KOBJ_ADD
);
372 kobject_uevent(dynamic_tables_kobj
, KOBJ_ADD
);
373 result
= acpi_install_table_handler(acpi_sysfs_table_handler
, NULL
);
375 return result
== AE_OK
? 0 : -EINVAL
;
377 kobject_put(tables_kobj
);
383 * Detailed ACPI IRQ counters:
384 * /sys/firmware/acpi/interrupts/
387 u32 acpi_irq_handled
;
388 u32 acpi_irq_not_handled
;
391 #define COUNT_SCI 1 /* acpi_irq_handled */
392 #define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */
393 #define COUNT_ERROR 3 /* other */
394 #define NUM_COUNTERS_EXTRA 4
396 struct event_counter
{
401 static struct event_counter
*all_counters
;
403 static u32 num_counters
;
404 static struct attribute
**all_attrs
;
405 static u32 acpi_gpe_count
;
407 static struct attribute_group interrupt_stats_attr_group
= {
408 .name
= "interrupts",
411 static struct kobj_attribute
*counter_attrs
;
413 static void delete_gpe_attr_array(void)
415 struct event_counter
*tmp
= all_counters
;
423 for (i
= 0; i
< num_gpes
; i
++)
424 kfree(counter_attrs
[i
].attr
.name
);
426 kfree(counter_attrs
);
433 void acpi_os_gpe_count(u32 gpe_number
)
440 if (gpe_number
< num_gpes
)
441 all_counters
[gpe_number
].count
++;
443 all_counters
[num_gpes
+ ACPI_NUM_FIXED_EVENTS
+
444 COUNT_ERROR
].count
++;
449 void acpi_os_fixed_event_count(u32 event_number
)
454 if (event_number
< ACPI_NUM_FIXED_EVENTS
)
455 all_counters
[num_gpes
+ event_number
].count
++;
457 all_counters
[num_gpes
+ ACPI_NUM_FIXED_EVENTS
+
458 COUNT_ERROR
].count
++;
463 static int get_status(u32 index
, acpi_event_status
*status
,
468 if (index
>= num_gpes
+ ACPI_NUM_FIXED_EVENTS
)
471 if (index
< num_gpes
) {
472 result
= acpi_get_gpe_device(index
, handle
);
474 ACPI_EXCEPTION((AE_INFO
, AE_NOT_FOUND
,
475 "Invalid GPE 0x%x\n", index
));
478 result
= acpi_get_gpe_status(*handle
, index
, status
);
479 } else if (index
< (num_gpes
+ ACPI_NUM_FIXED_EVENTS
))
480 result
= acpi_get_event_status(index
- num_gpes
, status
);
486 static ssize_t
counter_show(struct kobject
*kobj
,
487 struct kobj_attribute
*attr
, char *buf
)
489 int index
= attr
- counter_attrs
;
492 acpi_event_status status
;
495 all_counters
[num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_SCI
].count
=
497 all_counters
[num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_SCI_NOT
].count
=
498 acpi_irq_not_handled
;
499 all_counters
[num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_GPE
].count
=
501 size
= sprintf(buf
, "%8d", all_counters
[index
].count
);
503 /* "gpe_all" or "sci" */
504 if (index
>= num_gpes
+ ACPI_NUM_FIXED_EVENTS
)
507 result
= get_status(index
, &status
, &handle
);
511 if (!(status
& ACPI_EVENT_FLAG_HANDLE
))
512 size
+= sprintf(buf
+ size
, " invalid");
513 else if (status
& ACPI_EVENT_FLAG_ENABLED
)
514 size
+= sprintf(buf
+ size
, " enabled");
515 else if (status
& ACPI_EVENT_FLAG_WAKE_ENABLED
)
516 size
+= sprintf(buf
+ size
, " wake_enabled");
518 size
+= sprintf(buf
+ size
, " disabled");
521 size
+= sprintf(buf
+ size
, "\n");
522 return result
? result
: size
;
526 * counter_set() sets the specified counter.
527 * setting the total "sci" file to any value clears all counters.
528 * enable/disable/clear a gpe/fixed event in user space.
530 static ssize_t
counter_set(struct kobject
*kobj
,
531 struct kobj_attribute
*attr
, const char *buf
,
534 int index
= attr
- counter_attrs
;
535 acpi_event_status status
;
539 if (index
== num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_SCI
) {
541 for (i
= 0; i
< num_counters
; ++i
)
542 all_counters
[i
].count
= 0;
544 acpi_irq_handled
= 0;
545 acpi_irq_not_handled
= 0;
549 /* show the event status for both GPEs and Fixed Events */
550 result
= get_status(index
, &status
, &handle
);
554 if (!(status
& ACPI_EVENT_FLAG_HANDLE
)) {
555 printk(KERN_WARNING PREFIX
556 "Can not change Invalid GPE/Fixed Event status\n");
560 if (index
< num_gpes
) {
561 if (!strcmp(buf
, "disable\n") &&
562 (status
& ACPI_EVENT_FLAG_ENABLED
))
563 result
= acpi_disable_gpe(handle
, index
);
564 else if (!strcmp(buf
, "enable\n") &&
565 !(status
& ACPI_EVENT_FLAG_ENABLED
))
566 result
= acpi_enable_gpe(handle
, index
);
567 else if (!strcmp(buf
, "clear\n") &&
568 (status
& ACPI_EVENT_FLAG_SET
))
569 result
= acpi_clear_gpe(handle
, index
);
571 all_counters
[index
].count
= strtoul(buf
, NULL
, 0);
572 } else if (index
< num_gpes
+ ACPI_NUM_FIXED_EVENTS
) {
573 int event
= index
- num_gpes
;
574 if (!strcmp(buf
, "disable\n") &&
575 (status
& ACPI_EVENT_FLAG_ENABLED
))
576 result
= acpi_disable_event(event
, ACPI_NOT_ISR
);
577 else if (!strcmp(buf
, "enable\n") &&
578 !(status
& ACPI_EVENT_FLAG_ENABLED
))
579 result
= acpi_enable_event(event
, ACPI_NOT_ISR
);
580 else if (!strcmp(buf
, "clear\n") &&
581 (status
& ACPI_EVENT_FLAG_SET
))
582 result
= acpi_clear_event(event
);
584 all_counters
[index
].count
= strtoul(buf
, NULL
, 0);
586 all_counters
[index
].count
= strtoul(buf
, NULL
, 0);
588 if (ACPI_FAILURE(result
))
591 return result
? result
: size
;
594 void acpi_irq_stats_init(void)
601 num_gpes
= acpi_current_gpe_count
;
602 num_counters
= num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ NUM_COUNTERS_EXTRA
;
604 all_attrs
= kzalloc(sizeof(struct attribute
*) * (num_counters
+ 1),
606 if (all_attrs
== NULL
)
609 all_counters
= kzalloc(sizeof(struct event_counter
) * (num_counters
),
611 if (all_counters
== NULL
)
614 counter_attrs
= kzalloc(sizeof(struct kobj_attribute
) * (num_counters
),
616 if (counter_attrs
== NULL
)
619 for (i
= 0; i
< num_counters
; ++i
) {
624 sprintf(buffer
, "gpe%02X", i
);
625 else if (i
== num_gpes
+ ACPI_EVENT_PMTIMER
)
626 sprintf(buffer
, "ff_pmtimer");
627 else if (i
== num_gpes
+ ACPI_EVENT_GLOBAL
)
628 sprintf(buffer
, "ff_gbl_lock");
629 else if (i
== num_gpes
+ ACPI_EVENT_POWER_BUTTON
)
630 sprintf(buffer
, "ff_pwr_btn");
631 else if (i
== num_gpes
+ ACPI_EVENT_SLEEP_BUTTON
)
632 sprintf(buffer
, "ff_slp_btn");
633 else if (i
== num_gpes
+ ACPI_EVENT_RTC
)
634 sprintf(buffer
, "ff_rt_clk");
635 else if (i
== num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_GPE
)
636 sprintf(buffer
, "gpe_all");
637 else if (i
== num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_SCI
)
638 sprintf(buffer
, "sci");
639 else if (i
== num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_SCI_NOT
)
640 sprintf(buffer
, "sci_not");
641 else if (i
== num_gpes
+ ACPI_NUM_FIXED_EVENTS
+ COUNT_ERROR
)
642 sprintf(buffer
, "error");
644 sprintf(buffer
, "bug%02X", i
);
646 name
= kzalloc(strlen(buffer
) + 1, GFP_KERNEL
);
649 strncpy(name
, buffer
, strlen(buffer
) + 1);
651 sysfs_attr_init(&counter_attrs
[i
].attr
);
652 counter_attrs
[i
].attr
.name
= name
;
653 counter_attrs
[i
].attr
.mode
= 0644;
654 counter_attrs
[i
].show
= counter_show
;
655 counter_attrs
[i
].store
= counter_set
;
657 all_attrs
[i
] = &counter_attrs
[i
].attr
;
660 interrupt_stats_attr_group
.attrs
= all_attrs
;
661 if (!sysfs_create_group(acpi_kobj
, &interrupt_stats_attr_group
))
665 delete_gpe_attr_array();
669 static void __exit
interrupt_stats_exit(void)
671 sysfs_remove_group(acpi_kobj
, &interrupt_stats_attr_group
);
673 delete_gpe_attr_array();
678 int __init
acpi_sysfs_init(void)
682 result
= acpi_tables_sysfs_init();