sysfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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, 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, 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. module_param_call(debug_layer, param_set_uint, param_get_debug_layer,
  132. &acpi_dbg_layer, 0644);
  133. module_param_call(debug_level, param_set_uint, param_get_debug_level,
  134. &acpi_dbg_level, 0644);
  135. static char trace_method_name[6];
  136. module_param_string(trace_method_name, trace_method_name, 6, 0644);
  137. static unsigned int trace_debug_layer;
  138. module_param(trace_debug_layer, uint, 0644);
  139. static unsigned int trace_debug_level;
  140. module_param(trace_debug_level, uint, 0644);
  141. static int param_set_trace_state(const char *val, struct kernel_param *kp)
  142. {
  143. int result = 0;
  144. if (!strncmp(val, "enable", strlen("enable") - 1)) {
  145. result = acpi_debug_trace(trace_method_name, trace_debug_level,
  146. trace_debug_layer, 0);
  147. if (result)
  148. result = -EBUSY;
  149. goto exit;
  150. }
  151. if (!strncmp(val, "disable", strlen("disable") - 1)) {
  152. int name = 0;
  153. result = acpi_debug_trace((char *)&name, trace_debug_level,
  154. trace_debug_layer, 0);
  155. if (result)
  156. result = -EBUSY;
  157. goto exit;
  158. }
  159. if (!strncmp(val, "1", 1)) {
  160. result = acpi_debug_trace(trace_method_name, trace_debug_level,
  161. trace_debug_layer, 1);
  162. if (result)
  163. result = -EBUSY;
  164. goto exit;
  165. }
  166. result = -EINVAL;
  167. exit:
  168. return result;
  169. }
  170. static int param_get_trace_state(char *buffer, struct kernel_param *kp)
  171. {
  172. if (!acpi_gbl_trace_method_name)
  173. return sprintf(buffer, "disable");
  174. else {
  175. if (acpi_gbl_trace_flags & 1)
  176. return sprintf(buffer, "1");
  177. else
  178. return sprintf(buffer, "enable");
  179. }
  180. return 0;
  181. }
  182. module_param_call(trace_state, param_set_trace_state, param_get_trace_state,
  183. NULL, 0644);
  184. #endif /* CONFIG_ACPI_DEBUG */
  185. /* /sys/module/acpi/parameters/acpica_version */
  186. static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
  187. {
  188. int result;
  189. result = sprintf(buffer, "%x", ACPI_CA_VERSION);
  190. return result;
  191. }
  192. module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
  193. /*
  194. * ACPI table sysfs I/F:
  195. * /sys/firmware/acpi/tables/
  196. * /sys/firmware/acpi/tables/dynamic/
  197. */
  198. static LIST_HEAD(acpi_table_attr_list);
  199. static struct kobject *tables_kobj;
  200. static struct kobject *dynamic_tables_kobj;
  201. struct acpi_table_attr {
  202. struct bin_attribute attr;
  203. char name[8];
  204. int instance;
  205. struct list_head node;
  206. };
  207. static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj,
  208. struct bin_attribute *bin_attr, char *buf,
  209. loff_t offset, size_t count)
  210. {
  211. struct acpi_table_attr *table_attr =
  212. container_of(bin_attr, struct acpi_table_attr, attr);
  213. struct acpi_table_header *table_header = NULL;
  214. acpi_status status;
  215. char name[ACPI_NAME_SIZE];
  216. if (strncmp(table_attr->name, "NULL", 4))
  217. memcpy(name, table_attr->name, ACPI_NAME_SIZE);
  218. else
  219. memcpy(name, "\0\0\0\0", 4);
  220. status = acpi_get_table(name, table_attr->instance, &table_header);
  221. if (ACPI_FAILURE(status))
  222. return -ENODEV;
  223. return memory_read_from_buffer(buf, count, &offset,
  224. table_header, table_header->length);
  225. }
  226. static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
  227. struct acpi_table_header *table_header)
  228. {
  229. struct acpi_table_header *header = NULL;
  230. struct acpi_table_attr *attr = NULL;
  231. sysfs_attr_init(&table_attr->attr.attr);
  232. if (table_header->signature[0] != '\0')
  233. memcpy(table_attr->name, table_header->signature,
  234. ACPI_NAME_SIZE);
  235. else
  236. memcpy(table_attr->name, "NULL", 4);
  237. list_for_each_entry(attr, &acpi_table_attr_list, node) {
  238. if (!memcmp(table_attr->name, attr->name, ACPI_NAME_SIZE))
  239. if (table_attr->instance < attr->instance)
  240. table_attr->instance = attr->instance;
  241. }
  242. table_attr->instance++;
  243. if (table_attr->instance > 1 || (table_attr->instance == 1 &&
  244. !acpi_get_table
  245. (table_header->signature, 2, &header)))
  246. sprintf(table_attr->name + ACPI_NAME_SIZE, "%d",
  247. table_attr->instance);
  248. table_attr->attr.size = 0;
  249. table_attr->attr.read = acpi_table_show;
  250. table_attr->attr.attr.name = table_attr->name;
  251. table_attr->attr.attr.mode = 0400;
  252. return;
  253. }
  254. static acpi_status
  255. acpi_sysfs_table_handler(u32 event, void *table, void *context)
  256. {
  257. struct acpi_table_attr *table_attr;
  258. switch (event) {
  259. case ACPI_TABLE_EVENT_LOAD:
  260. table_attr =
  261. kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
  262. if (!table_attr)
  263. return AE_NO_MEMORY;
  264. acpi_table_attr_init(table_attr, table);
  265. if (sysfs_create_bin_file(dynamic_tables_kobj,
  266. &table_attr->attr)) {
  267. kfree(table_attr);
  268. return AE_ERROR;
  269. } else
  270. list_add_tail(&table_attr->node, &acpi_table_attr_list);
  271. break;
  272. case ACPI_TABLE_EVENT_UNLOAD:
  273. /*
  274. * we do not need to do anything right now
  275. * because the table is not deleted from the
  276. * global table list when unloading it.
  277. */
  278. break;
  279. default:
  280. return AE_BAD_PARAMETER;
  281. }
  282. return AE_OK;
  283. }
  284. static int acpi_tables_sysfs_init(void)
  285. {
  286. struct acpi_table_attr *table_attr;
  287. struct acpi_table_header *table_header = NULL;
  288. int table_index = 0;
  289. int result;
  290. tables_kobj = kobject_create_and_add("tables", acpi_kobj);
  291. if (!tables_kobj)
  292. goto err;
  293. dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj);
  294. if (!dynamic_tables_kobj)
  295. goto err_dynamic_tables;
  296. do {
  297. result = acpi_get_table_by_index(table_index, &table_header);
  298. if (!result) {
  299. table_index++;
  300. table_attr = NULL;
  301. table_attr =
  302. kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
  303. if (!table_attr)
  304. return -ENOMEM;
  305. acpi_table_attr_init(table_attr, table_header);
  306. result =
  307. sysfs_create_bin_file(tables_kobj,
  308. &table_attr->attr);
  309. if (result) {
  310. kfree(table_attr);
  311. return result;
  312. } else
  313. list_add_tail(&table_attr->node,
  314. &acpi_table_attr_list);
  315. }
  316. } while (!result);
  317. kobject_uevent(tables_kobj, KOBJ_ADD);
  318. kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
  319. result = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
  320. return result == AE_OK ? 0 : -EINVAL;
  321. err_dynamic_tables:
  322. kobject_put(tables_kobj);
  323. err:
  324. return -ENOMEM;
  325. }
  326. /*
  327. * Detailed ACPI IRQ counters:
  328. * /sys/firmware/acpi/interrupts/
  329. */
  330. u32 acpi_irq_handled;
  331. u32 acpi_irq_not_handled;
  332. #define COUNT_GPE 0
  333. #define COUNT_SCI 1 /* acpi_irq_handled */
  334. #define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */
  335. #define COUNT_ERROR 3 /* other */
  336. #define NUM_COUNTERS_EXTRA 4
  337. struct event_counter {
  338. u32 count;
  339. u32 flags;
  340. };
  341. static struct event_counter *all_counters;
  342. static u32 num_gpes;
  343. static u32 num_counters;
  344. static struct attribute **all_attrs;
  345. static u32 acpi_gpe_count;
  346. static struct attribute_group interrupt_stats_attr_group = {
  347. .name = "interrupts",
  348. };
  349. static struct kobj_attribute *counter_attrs;
  350. static void delete_gpe_attr_array(void)
  351. {
  352. struct event_counter *tmp = all_counters;
  353. all_counters = NULL;
  354. kfree(tmp);
  355. if (counter_attrs) {
  356. int i;
  357. for (i = 0; i < num_gpes; i++)
  358. kfree(counter_attrs[i].attr.name);
  359. kfree(counter_attrs);
  360. }
  361. kfree(all_attrs);
  362. return;
  363. }
  364. void acpi_os_gpe_count(u32 gpe_number)
  365. {
  366. acpi_gpe_count++;
  367. if (!all_counters)
  368. return;
  369. if (gpe_number < num_gpes)
  370. all_counters[gpe_number].count++;
  371. else
  372. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
  373. COUNT_ERROR].count++;
  374. return;
  375. }
  376. void acpi_os_fixed_event_count(u32 event_number)
  377. {
  378. if (!all_counters)
  379. return;
  380. if (event_number < ACPI_NUM_FIXED_EVENTS)
  381. all_counters[num_gpes + event_number].count++;
  382. else
  383. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
  384. COUNT_ERROR].count++;
  385. return;
  386. }
  387. static int get_status(u32 index, acpi_event_status *status,
  388. acpi_handle *handle)
  389. {
  390. int result = 0;
  391. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  392. goto end;
  393. if (index < num_gpes) {
  394. result = acpi_get_gpe_device(index, handle);
  395. if (result) {
  396. ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
  397. "Invalid GPE 0x%x\n", index));
  398. goto end;
  399. }
  400. result = acpi_get_gpe_status(*handle, index, status);
  401. } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
  402. result = acpi_get_event_status(index - num_gpes, status);
  403. end:
  404. return result;
  405. }
  406. static ssize_t counter_show(struct kobject *kobj,
  407. struct kobj_attribute *attr, char *buf)
  408. {
  409. int index = attr - counter_attrs;
  410. int size;
  411. acpi_handle handle;
  412. acpi_event_status status;
  413. int result = 0;
  414. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count =
  415. acpi_irq_handled;
  416. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count =
  417. acpi_irq_not_handled;
  418. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
  419. acpi_gpe_count;
  420. size = sprintf(buf, "%8d", all_counters[index].count);
  421. /* "gpe_all" or "sci" */
  422. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  423. goto end;
  424. result = get_status(index, &status, &handle);
  425. if (result)
  426. goto end;
  427. if (!(status & ACPI_EVENT_FLAG_HANDLE))
  428. size += sprintf(buf + size, " invalid");
  429. else if (status & ACPI_EVENT_FLAG_ENABLED)
  430. size += sprintf(buf + size, " enabled");
  431. else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED)
  432. size += sprintf(buf + size, " wake_enabled");
  433. else
  434. size += sprintf(buf + size, " disabled");
  435. end:
  436. size += sprintf(buf + size, "\n");
  437. return result ? result : size;
  438. }
  439. /*
  440. * counter_set() sets the specified counter.
  441. * setting the total "sci" file to any value clears all counters.
  442. * enable/disable/clear a gpe/fixed event in user space.
  443. */
  444. static ssize_t counter_set(struct kobject *kobj,
  445. struct kobj_attribute *attr, const char *buf,
  446. size_t size)
  447. {
  448. int index = attr - counter_attrs;
  449. acpi_event_status status;
  450. acpi_handle handle;
  451. int result = 0;
  452. if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
  453. int i;
  454. for (i = 0; i < num_counters; ++i)
  455. all_counters[i].count = 0;
  456. acpi_gpe_count = 0;
  457. acpi_irq_handled = 0;
  458. acpi_irq_not_handled = 0;
  459. goto end;
  460. }
  461. /* show the event status for both GPEs and Fixed Events */
  462. result = get_status(index, &status, &handle);
  463. if (result)
  464. goto end;
  465. if (!(status & ACPI_EVENT_FLAG_HANDLE)) {
  466. printk(KERN_WARNING PREFIX
  467. "Can not change Invalid GPE/Fixed Event status\n");
  468. return -EINVAL;
  469. }
  470. if (index < num_gpes) {
  471. if (!strcmp(buf, "disable\n") &&
  472. (status & ACPI_EVENT_FLAG_ENABLED))
  473. result = acpi_disable_gpe(handle, index);
  474. else if (!strcmp(buf, "enable\n") &&
  475. !(status & ACPI_EVENT_FLAG_ENABLED))
  476. result = acpi_enable_gpe(handle, index);
  477. else if (!strcmp(buf, "clear\n") &&
  478. (status & ACPI_EVENT_FLAG_SET))
  479. result = acpi_clear_gpe(handle, index);
  480. else
  481. all_counters[index].count = strtoul(buf, NULL, 0);
  482. } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
  483. int event = index - num_gpes;
  484. if (!strcmp(buf, "disable\n") &&
  485. (status & ACPI_EVENT_FLAG_ENABLED))
  486. result = acpi_disable_event(event, ACPI_NOT_ISR);
  487. else if (!strcmp(buf, "enable\n") &&
  488. !(status & ACPI_EVENT_FLAG_ENABLED))
  489. result = acpi_enable_event(event, ACPI_NOT_ISR);
  490. else if (!strcmp(buf, "clear\n") &&
  491. (status & ACPI_EVENT_FLAG_SET))
  492. result = acpi_clear_event(event);
  493. else
  494. all_counters[index].count = strtoul(buf, NULL, 0);
  495. } else
  496. all_counters[index].count = strtoul(buf, NULL, 0);
  497. if (ACPI_FAILURE(result))
  498. result = -EINVAL;
  499. end:
  500. return result ? result : size;
  501. }
  502. void acpi_irq_stats_init(void)
  503. {
  504. int i;
  505. if (all_counters)
  506. return;
  507. num_gpes = acpi_current_gpe_count;
  508. num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
  509. all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
  510. GFP_KERNEL);
  511. if (all_attrs == NULL)
  512. return;
  513. all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
  514. GFP_KERNEL);
  515. if (all_counters == NULL)
  516. goto fail;
  517. counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
  518. GFP_KERNEL);
  519. if (counter_attrs == NULL)
  520. goto fail;
  521. for (i = 0; i < num_counters; ++i) {
  522. char buffer[12];
  523. char *name;
  524. if (i < num_gpes)
  525. sprintf(buffer, "gpe%02X", i);
  526. else if (i == num_gpes + ACPI_EVENT_PMTIMER)
  527. sprintf(buffer, "ff_pmtimer");
  528. else if (i == num_gpes + ACPI_EVENT_GLOBAL)
  529. sprintf(buffer, "ff_gbl_lock");
  530. else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON)
  531. sprintf(buffer, "ff_pwr_btn");
  532. else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON)
  533. sprintf(buffer, "ff_slp_btn");
  534. else if (i == num_gpes + ACPI_EVENT_RTC)
  535. sprintf(buffer, "ff_rt_clk");
  536. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE)
  537. sprintf(buffer, "gpe_all");
  538. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
  539. sprintf(buffer, "sci");
  540. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT)
  541. sprintf(buffer, "sci_not");
  542. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
  543. sprintf(buffer, "error");
  544. else
  545. sprintf(buffer, "bug%02X", i);
  546. name = kzalloc(strlen(buffer) + 1, GFP_KERNEL);
  547. if (name == NULL)
  548. goto fail;
  549. strncpy(name, buffer, strlen(buffer) + 1);
  550. sysfs_attr_init(&counter_attrs[i].attr);
  551. counter_attrs[i].attr.name = name;
  552. counter_attrs[i].attr.mode = 0644;
  553. counter_attrs[i].show = counter_show;
  554. counter_attrs[i].store = counter_set;
  555. all_attrs[i] = &counter_attrs[i].attr;
  556. }
  557. interrupt_stats_attr_group.attrs = all_attrs;
  558. if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group))
  559. return;
  560. fail:
  561. delete_gpe_attr_array();
  562. return;
  563. }
  564. static void __exit interrupt_stats_exit(void)
  565. {
  566. sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group);
  567. delete_gpe_attr_array();
  568. return;
  569. }
  570. int __init acpi_sysfs_init(void)
  571. {
  572. int result;
  573. result = acpi_tables_sysfs_init();
  574. return result;
  575. }