sysfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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. void acpi_os_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. void acpi_os_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 int get_status(u32 index, acpi_event_status *status,
  394. acpi_handle *handle)
  395. {
  396. int result = 0;
  397. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  398. goto end;
  399. if (index < num_gpes) {
  400. result = acpi_get_gpe_device(index, handle);
  401. if (result) {
  402. ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
  403. "Invalid GPE 0x%x\n", index));
  404. goto end;
  405. }
  406. result = acpi_get_gpe_status(*handle, index, status);
  407. } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
  408. result = acpi_get_event_status(index - num_gpes, status);
  409. end:
  410. return result;
  411. }
  412. static ssize_t counter_show(struct kobject *kobj,
  413. struct kobj_attribute *attr, char *buf)
  414. {
  415. int index = attr - counter_attrs;
  416. int size;
  417. acpi_handle handle;
  418. acpi_event_status status;
  419. int result = 0;
  420. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count =
  421. acpi_irq_handled;
  422. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count =
  423. acpi_irq_not_handled;
  424. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
  425. acpi_gpe_count;
  426. size = sprintf(buf, "%8d", all_counters[index].count);
  427. /* "gpe_all" or "sci" */
  428. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  429. goto end;
  430. result = get_status(index, &status, &handle);
  431. if (result)
  432. goto end;
  433. if (!(status & ACPI_EVENT_FLAG_HANDLE))
  434. size += sprintf(buf + size, " invalid");
  435. else if (status & ACPI_EVENT_FLAG_ENABLED)
  436. size += sprintf(buf + size, " enabled");
  437. else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED)
  438. size += sprintf(buf + size, " wake_enabled");
  439. else
  440. size += sprintf(buf + size, " disabled");
  441. end:
  442. size += sprintf(buf + size, "\n");
  443. return result ? result : size;
  444. }
  445. /*
  446. * counter_set() sets the specified counter.
  447. * setting the total "sci" file to any value clears all counters.
  448. * enable/disable/clear a gpe/fixed event in user space.
  449. */
  450. static ssize_t counter_set(struct kobject *kobj,
  451. struct kobj_attribute *attr, const char *buf,
  452. size_t size)
  453. {
  454. int index = attr - counter_attrs;
  455. acpi_event_status status;
  456. acpi_handle handle;
  457. int result = 0;
  458. if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
  459. int i;
  460. for (i = 0; i < num_counters; ++i)
  461. all_counters[i].count = 0;
  462. acpi_gpe_count = 0;
  463. acpi_irq_handled = 0;
  464. acpi_irq_not_handled = 0;
  465. goto end;
  466. }
  467. /* show the event status for both GPEs and Fixed Events */
  468. result = get_status(index, &status, &handle);
  469. if (result)
  470. goto end;
  471. if (!(status & ACPI_EVENT_FLAG_HANDLE)) {
  472. printk(KERN_WARNING PREFIX
  473. "Can not change Invalid GPE/Fixed Event status\n");
  474. return -EINVAL;
  475. }
  476. if (index < num_gpes) {
  477. if (!strcmp(buf, "disable\n") &&
  478. (status & ACPI_EVENT_FLAG_ENABLED))
  479. result = acpi_disable_gpe(handle, index);
  480. else if (!strcmp(buf, "enable\n") &&
  481. !(status & ACPI_EVENT_FLAG_ENABLED))
  482. result = acpi_enable_gpe(handle, index);
  483. else if (!strcmp(buf, "clear\n") &&
  484. (status & ACPI_EVENT_FLAG_SET))
  485. result = acpi_clear_gpe(handle, index);
  486. else
  487. all_counters[index].count = strtoul(buf, NULL, 0);
  488. } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
  489. int event = index - num_gpes;
  490. if (!strcmp(buf, "disable\n") &&
  491. (status & ACPI_EVENT_FLAG_ENABLED))
  492. result = acpi_disable_event(event, ACPI_NOT_ISR);
  493. else if (!strcmp(buf, "enable\n") &&
  494. !(status & ACPI_EVENT_FLAG_ENABLED))
  495. result = acpi_enable_event(event, ACPI_NOT_ISR);
  496. else if (!strcmp(buf, "clear\n") &&
  497. (status & ACPI_EVENT_FLAG_SET))
  498. result = acpi_clear_event(event);
  499. else
  500. all_counters[index].count = strtoul(buf, NULL, 0);
  501. } else
  502. all_counters[index].count = strtoul(buf, NULL, 0);
  503. if (ACPI_FAILURE(result))
  504. result = -EINVAL;
  505. end:
  506. return result ? result : size;
  507. }
  508. void acpi_irq_stats_init(void)
  509. {
  510. int i;
  511. if (all_counters)
  512. return;
  513. num_gpes = acpi_current_gpe_count;
  514. num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
  515. all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
  516. GFP_KERNEL);
  517. if (all_attrs == NULL)
  518. return;
  519. all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
  520. GFP_KERNEL);
  521. if (all_counters == NULL)
  522. goto fail;
  523. counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
  524. GFP_KERNEL);
  525. if (counter_attrs == NULL)
  526. goto fail;
  527. for (i = 0; i < num_counters; ++i) {
  528. char buffer[12];
  529. char *name;
  530. if (i < num_gpes)
  531. sprintf(buffer, "gpe%02X", i);
  532. else if (i == num_gpes + ACPI_EVENT_PMTIMER)
  533. sprintf(buffer, "ff_pmtimer");
  534. else if (i == num_gpes + ACPI_EVENT_GLOBAL)
  535. sprintf(buffer, "ff_gbl_lock");
  536. else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON)
  537. sprintf(buffer, "ff_pwr_btn");
  538. else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON)
  539. sprintf(buffer, "ff_slp_btn");
  540. else if (i == num_gpes + ACPI_EVENT_RTC)
  541. sprintf(buffer, "ff_rt_clk");
  542. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE)
  543. sprintf(buffer, "gpe_all");
  544. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
  545. sprintf(buffer, "sci");
  546. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT)
  547. sprintf(buffer, "sci_not");
  548. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
  549. sprintf(buffer, "error");
  550. else
  551. sprintf(buffer, "bug%02X", i);
  552. name = kzalloc(strlen(buffer) + 1, GFP_KERNEL);
  553. if (name == NULL)
  554. goto fail;
  555. strncpy(name, buffer, strlen(buffer) + 1);
  556. sysfs_attr_init(&counter_attrs[i].attr);
  557. counter_attrs[i].attr.name = name;
  558. counter_attrs[i].attr.mode = 0644;
  559. counter_attrs[i].show = counter_show;
  560. counter_attrs[i].store = counter_set;
  561. all_attrs[i] = &counter_attrs[i].attr;
  562. }
  563. interrupt_stats_attr_group.attrs = all_attrs;
  564. if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group))
  565. return;
  566. fail:
  567. delete_gpe_attr_array();
  568. return;
  569. }
  570. static void __exit interrupt_stats_exit(void)
  571. {
  572. sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group);
  573. delete_gpe_attr_array();
  574. return;
  575. }
  576. int __init acpi_sysfs_init(void)
  577. {
  578. int result;
  579. result = acpi_tables_sysfs_init();
  580. return result;
  581. }