sysfs.c 20 KB

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