sysfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. * sysfs.c - ACPI sysfs interface to userspace.
  3. */
  4. #include <linux/init.h>
  5. #include <linux/kernel.h>
  6. #include <linux/moduleparam.h>
  7. #include <acpi/acpi_drivers.h>
  8. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  9. ACPI_MODULE_NAME("sysfs");
  10. #define PREFIX "ACPI: "
  11. #ifdef CONFIG_ACPI_DEBUG
  12. /*
  13. * ACPI debug sysfs I/F, including:
  14. * /sys/modules/acpi/parameters/debug_layer
  15. * /sys/modules/acpi/parameters/debug_level
  16. * /sys/modules/acpi/parameters/trace_method_name
  17. * /sys/modules/acpi/parameters/trace_state
  18. * /sys/modules/acpi/parameters/trace_debug_layer
  19. * /sys/modules/acpi/parameters/trace_debug_level
  20. */
  21. struct acpi_dlayer {
  22. const char *name;
  23. unsigned long value;
  24. };
  25. struct acpi_dlevel {
  26. const char *name;
  27. unsigned long value;
  28. };
  29. #define ACPI_DEBUG_INIT(v) { .name = #v, .value = v }
  30. static const struct acpi_dlayer acpi_debug_layers[] = {
  31. ACPI_DEBUG_INIT(ACPI_UTILITIES),
  32. ACPI_DEBUG_INIT(ACPI_HARDWARE),
  33. ACPI_DEBUG_INIT(ACPI_EVENTS),
  34. ACPI_DEBUG_INIT(ACPI_TABLES),
  35. ACPI_DEBUG_INIT(ACPI_NAMESPACE),
  36. ACPI_DEBUG_INIT(ACPI_PARSER),
  37. ACPI_DEBUG_INIT(ACPI_DISPATCHER),
  38. ACPI_DEBUG_INIT(ACPI_EXECUTER),
  39. ACPI_DEBUG_INIT(ACPI_RESOURCES),
  40. ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER),
  41. ACPI_DEBUG_INIT(ACPI_OS_SERVICES),
  42. ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER),
  43. ACPI_DEBUG_INIT(ACPI_COMPILER),
  44. ACPI_DEBUG_INIT(ACPI_TOOLS),
  45. ACPI_DEBUG_INIT(ACPI_BUS_COMPONENT),
  46. ACPI_DEBUG_INIT(ACPI_AC_COMPONENT),
  47. ACPI_DEBUG_INIT(ACPI_BATTERY_COMPONENT),
  48. ACPI_DEBUG_INIT(ACPI_BUTTON_COMPONENT),
  49. ACPI_DEBUG_INIT(ACPI_SBS_COMPONENT),
  50. ACPI_DEBUG_INIT(ACPI_FAN_COMPONENT),
  51. ACPI_DEBUG_INIT(ACPI_PCI_COMPONENT),
  52. ACPI_DEBUG_INIT(ACPI_POWER_COMPONENT),
  53. ACPI_DEBUG_INIT(ACPI_CONTAINER_COMPONENT),
  54. ACPI_DEBUG_INIT(ACPI_SYSTEM_COMPONENT),
  55. ACPI_DEBUG_INIT(ACPI_THERMAL_COMPONENT),
  56. ACPI_DEBUG_INIT(ACPI_MEMORY_DEVICE_COMPONENT),
  57. ACPI_DEBUG_INIT(ACPI_VIDEO_COMPONENT),
  58. ACPI_DEBUG_INIT(ACPI_PROCESSOR_COMPONENT),
  59. };
  60. static const struct acpi_dlevel acpi_debug_levels[] = {
  61. ACPI_DEBUG_INIT(ACPI_LV_INIT),
  62. ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT),
  63. ACPI_DEBUG_INIT(ACPI_LV_INFO),
  64. ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES),
  65. ACPI_DEBUG_INIT(ACPI_LV_PARSE),
  66. ACPI_DEBUG_INIT(ACPI_LV_LOAD),
  67. ACPI_DEBUG_INIT(ACPI_LV_DISPATCH),
  68. ACPI_DEBUG_INIT(ACPI_LV_EXEC),
  69. ACPI_DEBUG_INIT(ACPI_LV_NAMES),
  70. ACPI_DEBUG_INIT(ACPI_LV_OPREGION),
  71. ACPI_DEBUG_INIT(ACPI_LV_BFIELD),
  72. ACPI_DEBUG_INIT(ACPI_LV_TABLES),
  73. ACPI_DEBUG_INIT(ACPI_LV_VALUES),
  74. ACPI_DEBUG_INIT(ACPI_LV_OBJECTS),
  75. ACPI_DEBUG_INIT(ACPI_LV_RESOURCES),
  76. ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS),
  77. ACPI_DEBUG_INIT(ACPI_LV_PACKAGE),
  78. ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS),
  79. ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS),
  80. ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS),
  81. ACPI_DEBUG_INIT(ACPI_LV_MUTEX),
  82. ACPI_DEBUG_INIT(ACPI_LV_THREADS),
  83. ACPI_DEBUG_INIT(ACPI_LV_IO),
  84. ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS),
  85. ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE),
  86. ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO),
  87. ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES),
  88. ACPI_DEBUG_INIT(ACPI_LV_EVENTS),
  89. };
  90. static int param_get_debug_layer(char *buffer, const struct kernel_param *kp)
  91. {
  92. int result = 0;
  93. int i;
  94. result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
  95. for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) {
  96. result += sprintf(buffer + result, "%-25s\t0x%08lX [%c]\n",
  97. acpi_debug_layers[i].name,
  98. acpi_debug_layers[i].value,
  99. (acpi_dbg_layer & acpi_debug_layers[i].value)
  100. ? '*' : ' ');
  101. }
  102. result +=
  103. sprintf(buffer + result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
  104. ACPI_ALL_DRIVERS,
  105. (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
  106. ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer & ACPI_ALL_DRIVERS)
  107. == 0 ? ' ' : '-');
  108. result +=
  109. sprintf(buffer + result,
  110. "--\ndebug_layer = 0x%08X ( * = enabled)\n",
  111. acpi_dbg_layer);
  112. return result;
  113. }
  114. static int param_get_debug_level(char *buffer, const struct kernel_param *kp)
  115. {
  116. int result = 0;
  117. int i;
  118. result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
  119. for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
  120. result += sprintf(buffer + result, "%-25s\t0x%08lX [%c]\n",
  121. acpi_debug_levels[i].name,
  122. acpi_debug_levels[i].value,
  123. (acpi_dbg_level & acpi_debug_levels[i].value)
  124. ? '*' : ' ');
  125. }
  126. result +=
  127. sprintf(buffer + result, "--\ndebug_level = 0x%08X (* = enabled)\n",
  128. acpi_dbg_level);
  129. return result;
  130. }
  131. static struct kernel_param_ops param_ops_debug_layer = {
  132. .set = param_set_uint,
  133. .get = param_get_debug_layer,
  134. };
  135. static struct kernel_param_ops param_ops_debug_level = {
  136. .set = param_set_uint,
  137. .get = param_get_debug_level,
  138. };
  139. module_param_cb(debug_layer, &param_ops_debug_layer, &acpi_dbg_layer, 0644);
  140. module_param_cb(debug_level, &param_ops_debug_level, &acpi_dbg_level, 0644);
  141. static char trace_method_name[6];
  142. module_param_string(trace_method_name, trace_method_name, 6, 0644);
  143. static unsigned int trace_debug_layer;
  144. module_param(trace_debug_layer, uint, 0644);
  145. static unsigned int trace_debug_level;
  146. module_param(trace_debug_level, uint, 0644);
  147. static int param_set_trace_state(const char *val, struct kernel_param *kp)
  148. {
  149. int result = 0;
  150. if (!strncmp(val, "enable", strlen("enable") - 1)) {
  151. result = acpi_debug_trace(trace_method_name, trace_debug_level,
  152. trace_debug_layer, 0);
  153. if (result)
  154. result = -EBUSY;
  155. goto exit;
  156. }
  157. if (!strncmp(val, "disable", strlen("disable") - 1)) {
  158. int name = 0;
  159. result = acpi_debug_trace((char *)&name, trace_debug_level,
  160. trace_debug_layer, 0);
  161. if (result)
  162. result = -EBUSY;
  163. goto exit;
  164. }
  165. if (!strncmp(val, "1", 1)) {
  166. result = acpi_debug_trace(trace_method_name, trace_debug_level,
  167. trace_debug_layer, 1);
  168. if (result)
  169. result = -EBUSY;
  170. goto exit;
  171. }
  172. result = -EINVAL;
  173. exit:
  174. return result;
  175. }
  176. static int param_get_trace_state(char *buffer, struct kernel_param *kp)
  177. {
  178. if (!acpi_gbl_trace_method_name)
  179. return sprintf(buffer, "disable");
  180. else {
  181. if (acpi_gbl_trace_flags & 1)
  182. return sprintf(buffer, "1");
  183. else
  184. return sprintf(buffer, "enable");
  185. }
  186. return 0;
  187. }
  188. module_param_call(trace_state, param_set_trace_state, param_get_trace_state,
  189. NULL, 0644);
  190. #endif /* CONFIG_ACPI_DEBUG */
  191. /* /sys/module/acpi/parameters/acpica_version */
  192. static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
  193. {
  194. int result;
  195. result = sprintf(buffer, "%x", ACPI_CA_VERSION);
  196. return result;
  197. }
  198. module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
  199. /*
  200. * ACPI table sysfs I/F:
  201. * /sys/firmware/acpi/tables/
  202. * /sys/firmware/acpi/tables/dynamic/
  203. */
  204. static LIST_HEAD(acpi_table_attr_list);
  205. static struct kobject *tables_kobj;
  206. static struct kobject *dynamic_tables_kobj;
  207. struct acpi_table_attr {
  208. struct bin_attribute attr;
  209. char name[8];
  210. int instance;
  211. struct list_head node;
  212. };
  213. static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj,
  214. struct bin_attribute *bin_attr, char *buf,
  215. loff_t offset, size_t count)
  216. {
  217. struct acpi_table_attr *table_attr =
  218. container_of(bin_attr, struct acpi_table_attr, attr);
  219. struct acpi_table_header *table_header = NULL;
  220. acpi_status status;
  221. char name[ACPI_NAME_SIZE];
  222. if (strncmp(table_attr->name, "NULL", 4))
  223. memcpy(name, table_attr->name, ACPI_NAME_SIZE);
  224. else
  225. memcpy(name, "\0\0\0\0", 4);
  226. status = acpi_get_table(name, table_attr->instance, &table_header);
  227. if (ACPI_FAILURE(status))
  228. return -ENODEV;
  229. return memory_read_from_buffer(buf, count, &offset,
  230. table_header, table_header->length);
  231. }
  232. static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
  233. struct acpi_table_header *table_header)
  234. {
  235. struct acpi_table_header *header = NULL;
  236. struct acpi_table_attr *attr = NULL;
  237. sysfs_attr_init(&table_attr->attr.attr);
  238. if (table_header->signature[0] != '\0')
  239. memcpy(table_attr->name, table_header->signature,
  240. ACPI_NAME_SIZE);
  241. else
  242. memcpy(table_attr->name, "NULL", 4);
  243. list_for_each_entry(attr, &acpi_table_attr_list, node) {
  244. if (!memcmp(table_attr->name, attr->name, ACPI_NAME_SIZE))
  245. if (table_attr->instance < attr->instance)
  246. table_attr->instance = attr->instance;
  247. }
  248. table_attr->instance++;
  249. if (table_attr->instance > 1 || (table_attr->instance == 1 &&
  250. !acpi_get_table
  251. (table_header->signature, 2, &header)))
  252. sprintf(table_attr->name + ACPI_NAME_SIZE, "%d",
  253. table_attr->instance);
  254. table_attr->attr.size = 0;
  255. table_attr->attr.read = acpi_table_show;
  256. table_attr->attr.attr.name = table_attr->name;
  257. table_attr->attr.attr.mode = 0400;
  258. return;
  259. }
  260. static acpi_status
  261. acpi_sysfs_table_handler(u32 event, void *table, void *context)
  262. {
  263. struct acpi_table_attr *table_attr;
  264. switch (event) {
  265. case ACPI_TABLE_EVENT_LOAD:
  266. table_attr =
  267. kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
  268. if (!table_attr)
  269. return AE_NO_MEMORY;
  270. acpi_table_attr_init(table_attr, table);
  271. if (sysfs_create_bin_file(dynamic_tables_kobj,
  272. &table_attr->attr)) {
  273. kfree(table_attr);
  274. return AE_ERROR;
  275. } else
  276. list_add_tail(&table_attr->node, &acpi_table_attr_list);
  277. break;
  278. case ACPI_TABLE_EVENT_UNLOAD:
  279. /*
  280. * we do not need to do anything right now
  281. * because the table is not deleted from the
  282. * global table list when unloading it.
  283. */
  284. break;
  285. default:
  286. return AE_BAD_PARAMETER;
  287. }
  288. return AE_OK;
  289. }
  290. static int acpi_tables_sysfs_init(void)
  291. {
  292. struct acpi_table_attr *table_attr;
  293. struct acpi_table_header *table_header = NULL;
  294. int table_index = 0;
  295. int result;
  296. tables_kobj = kobject_create_and_add("tables", acpi_kobj);
  297. if (!tables_kobj)
  298. goto err;
  299. dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj);
  300. if (!dynamic_tables_kobj)
  301. goto err_dynamic_tables;
  302. do {
  303. result = acpi_get_table_by_index(table_index, &table_header);
  304. if (!result) {
  305. table_index++;
  306. table_attr = NULL;
  307. table_attr =
  308. kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
  309. if (!table_attr)
  310. return -ENOMEM;
  311. acpi_table_attr_init(table_attr, table_header);
  312. result =
  313. sysfs_create_bin_file(tables_kobj,
  314. &table_attr->attr);
  315. if (result) {
  316. kfree(table_attr);
  317. return result;
  318. } else
  319. list_add_tail(&table_attr->node,
  320. &acpi_table_attr_list);
  321. }
  322. } while (!result);
  323. kobject_uevent(tables_kobj, KOBJ_ADD);
  324. kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
  325. result = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
  326. return result == AE_OK ? 0 : -EINVAL;
  327. err_dynamic_tables:
  328. kobject_put(tables_kobj);
  329. err:
  330. return -ENOMEM;
  331. }
  332. /*
  333. * Detailed ACPI IRQ counters:
  334. * /sys/firmware/acpi/interrupts/
  335. */
  336. u32 acpi_irq_handled;
  337. u32 acpi_irq_not_handled;
  338. #define COUNT_GPE 0
  339. #define COUNT_SCI 1 /* acpi_irq_handled */
  340. #define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */
  341. #define COUNT_ERROR 3 /* other */
  342. #define NUM_COUNTERS_EXTRA 4
  343. struct event_counter {
  344. u32 count;
  345. u32 flags;
  346. };
  347. static struct event_counter *all_counters;
  348. static u32 num_gpes;
  349. static u32 num_counters;
  350. static struct attribute **all_attrs;
  351. static u32 acpi_gpe_count;
  352. static struct attribute_group interrupt_stats_attr_group = {
  353. .name = "interrupts",
  354. };
  355. static struct kobj_attribute *counter_attrs;
  356. static void delete_gpe_attr_array(void)
  357. {
  358. struct event_counter *tmp = all_counters;
  359. all_counters = NULL;
  360. kfree(tmp);
  361. if (counter_attrs) {
  362. int i;
  363. for (i = 0; i < num_gpes; i++)
  364. kfree(counter_attrs[i].attr.name);
  365. kfree(counter_attrs);
  366. }
  367. kfree(all_attrs);
  368. return;
  369. }
  370. static void gpe_count(u32 gpe_number)
  371. {
  372. acpi_gpe_count++;
  373. if (!all_counters)
  374. return;
  375. if (gpe_number < num_gpes)
  376. all_counters[gpe_number].count++;
  377. else
  378. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
  379. COUNT_ERROR].count++;
  380. return;
  381. }
  382. static void fixed_event_count(u32 event_number)
  383. {
  384. if (!all_counters)
  385. return;
  386. if (event_number < ACPI_NUM_FIXED_EVENTS)
  387. all_counters[num_gpes + event_number].count++;
  388. else
  389. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
  390. COUNT_ERROR].count++;
  391. return;
  392. }
  393. static void acpi_gbl_event_handler(u32 event_type, acpi_handle device,
  394. u32 event_number, void *context)
  395. {
  396. if (event_type == ACPI_EVENT_TYPE_GPE)
  397. gpe_count(event_number);
  398. if (event_type == ACPI_EVENT_TYPE_FIXED)
  399. fixed_event_count(event_number);
  400. }
  401. static int get_status(u32 index, acpi_event_status *status,
  402. acpi_handle *handle)
  403. {
  404. int result = 0;
  405. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  406. goto end;
  407. if (index < num_gpes) {
  408. result = acpi_get_gpe_device(index, handle);
  409. if (result) {
  410. ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
  411. "Invalid GPE 0x%x\n", index));
  412. goto end;
  413. }
  414. result = acpi_get_gpe_status(*handle, index, status);
  415. } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
  416. result = acpi_get_event_status(index - num_gpes, status);
  417. end:
  418. return result;
  419. }
  420. static ssize_t counter_show(struct kobject *kobj,
  421. struct kobj_attribute *attr, char *buf)
  422. {
  423. int index = attr - counter_attrs;
  424. int size;
  425. acpi_handle handle;
  426. acpi_event_status status;
  427. int result = 0;
  428. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count =
  429. acpi_irq_handled;
  430. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count =
  431. acpi_irq_not_handled;
  432. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
  433. acpi_gpe_count;
  434. size = sprintf(buf, "%8d", all_counters[index].count);
  435. /* "gpe_all" or "sci" */
  436. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  437. goto end;
  438. result = get_status(index, &status, &handle);
  439. if (result)
  440. goto end;
  441. if (!(status & ACPI_EVENT_FLAG_HANDLE))
  442. size += sprintf(buf + size, " invalid");
  443. else if (status & ACPI_EVENT_FLAG_ENABLED)
  444. size += sprintf(buf + size, " enabled");
  445. else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED)
  446. size += sprintf(buf + size, " wake_enabled");
  447. else
  448. size += sprintf(buf + size, " disabled");
  449. end:
  450. size += sprintf(buf + size, "\n");
  451. return result ? result : size;
  452. }
  453. /*
  454. * counter_set() sets the specified counter.
  455. * setting the total "sci" file to any value clears all counters.
  456. * enable/disable/clear a gpe/fixed event in user space.
  457. */
  458. static ssize_t counter_set(struct kobject *kobj,
  459. struct kobj_attribute *attr, const char *buf,
  460. size_t size)
  461. {
  462. int index = attr - counter_attrs;
  463. acpi_event_status status;
  464. acpi_handle handle;
  465. int result = 0;
  466. if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
  467. int i;
  468. for (i = 0; i < num_counters; ++i)
  469. all_counters[i].count = 0;
  470. acpi_gpe_count = 0;
  471. acpi_irq_handled = 0;
  472. acpi_irq_not_handled = 0;
  473. goto end;
  474. }
  475. /* show the event status for both GPEs and Fixed Events */
  476. result = get_status(index, &status, &handle);
  477. if (result)
  478. goto end;
  479. if (!(status & ACPI_EVENT_FLAG_HANDLE)) {
  480. printk(KERN_WARNING PREFIX
  481. "Can not change Invalid GPE/Fixed Event status\n");
  482. return -EINVAL;
  483. }
  484. if (index < num_gpes) {
  485. if (!strcmp(buf, "disable\n") &&
  486. (status & ACPI_EVENT_FLAG_ENABLED))
  487. result = acpi_disable_gpe(handle, index);
  488. else if (!strcmp(buf, "enable\n") &&
  489. !(status & ACPI_EVENT_FLAG_ENABLED))
  490. result = acpi_enable_gpe(handle, index);
  491. else if (!strcmp(buf, "clear\n") &&
  492. (status & ACPI_EVENT_FLAG_SET))
  493. result = acpi_clear_gpe(handle, index);
  494. else
  495. all_counters[index].count = strtoul(buf, NULL, 0);
  496. } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
  497. int event = index - num_gpes;
  498. if (!strcmp(buf, "disable\n") &&
  499. (status & ACPI_EVENT_FLAG_ENABLED))
  500. result = acpi_disable_event(event, ACPI_NOT_ISR);
  501. else if (!strcmp(buf, "enable\n") &&
  502. !(status & ACPI_EVENT_FLAG_ENABLED))
  503. result = acpi_enable_event(event, ACPI_NOT_ISR);
  504. else if (!strcmp(buf, "clear\n") &&
  505. (status & ACPI_EVENT_FLAG_SET))
  506. result = acpi_clear_event(event);
  507. else
  508. all_counters[index].count = strtoul(buf, NULL, 0);
  509. } else
  510. all_counters[index].count = strtoul(buf, NULL, 0);
  511. if (ACPI_FAILURE(result))
  512. result = -EINVAL;
  513. end:
  514. return result ? result : size;
  515. }
  516. void acpi_irq_stats_init(void)
  517. {
  518. acpi_status status;
  519. int i;
  520. if (all_counters)
  521. return;
  522. num_gpes = acpi_current_gpe_count;
  523. num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
  524. all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
  525. GFP_KERNEL);
  526. if (all_attrs == NULL)
  527. return;
  528. all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
  529. GFP_KERNEL);
  530. if (all_counters == NULL)
  531. goto fail;
  532. status = acpi_install_global_event_handler(acpi_gbl_event_handler, NULL);
  533. if (ACPI_FAILURE(status))
  534. goto fail;
  535. counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
  536. GFP_KERNEL);
  537. if (counter_attrs == NULL)
  538. goto fail;
  539. for (i = 0; i < num_counters; ++i) {
  540. char buffer[12];
  541. char *name;
  542. if (i < num_gpes)
  543. sprintf(buffer, "gpe%02X", i);
  544. else if (i == num_gpes + ACPI_EVENT_PMTIMER)
  545. sprintf(buffer, "ff_pmtimer");
  546. else if (i == num_gpes + ACPI_EVENT_GLOBAL)
  547. sprintf(buffer, "ff_gbl_lock");
  548. else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON)
  549. sprintf(buffer, "ff_pwr_btn");
  550. else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON)
  551. sprintf(buffer, "ff_slp_btn");
  552. else if (i == num_gpes + ACPI_EVENT_RTC)
  553. sprintf(buffer, "ff_rt_clk");
  554. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE)
  555. sprintf(buffer, "gpe_all");
  556. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
  557. sprintf(buffer, "sci");
  558. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT)
  559. sprintf(buffer, "sci_not");
  560. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
  561. sprintf(buffer, "error");
  562. else
  563. sprintf(buffer, "bug%02X", i);
  564. name = kzalloc(strlen(buffer) + 1, GFP_KERNEL);
  565. if (name == NULL)
  566. goto fail;
  567. strncpy(name, buffer, strlen(buffer) + 1);
  568. sysfs_attr_init(&counter_attrs[i].attr);
  569. counter_attrs[i].attr.name = name;
  570. counter_attrs[i].attr.mode = 0644;
  571. counter_attrs[i].show = counter_show;
  572. counter_attrs[i].store = counter_set;
  573. all_attrs[i] = &counter_attrs[i].attr;
  574. }
  575. interrupt_stats_attr_group.attrs = all_attrs;
  576. if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group))
  577. return;
  578. fail:
  579. delete_gpe_attr_array();
  580. return;
  581. }
  582. static void __exit interrupt_stats_exit(void)
  583. {
  584. sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group);
  585. delete_gpe_attr_array();
  586. return;
  587. }
  588. int __init acpi_sysfs_init(void)
  589. {
  590. int result;
  591. result = acpi_tables_sysfs_init();
  592. return result;
  593. }