sysfs.c 18 KB

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