sysfs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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 <linux/acpi.h>
  8. #include "internal.h"
  9. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  10. ACPI_MODULE_NAME("sysfs");
  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", sizeof("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", sizeof("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/modules/acpi/parameters/aml_debug_output */
  192. module_param_named(aml_debug_output, acpi_gbl_enable_aml_debug_object,
  193. byte, 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. static struct kobject *hotplug_kobj;
  213. struct acpi_table_attr {
  214. struct bin_attribute attr;
  215. char name[8];
  216. int instance;
  217. struct list_head node;
  218. };
  219. static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj,
  220. struct bin_attribute *bin_attr, char *buf,
  221. loff_t offset, size_t count)
  222. {
  223. struct acpi_table_attr *table_attr =
  224. container_of(bin_attr, struct acpi_table_attr, attr);
  225. struct acpi_table_header *table_header = NULL;
  226. acpi_status status;
  227. char name[ACPI_NAME_SIZE];
  228. if (strncmp(table_attr->name, "NULL", 4))
  229. memcpy(name, table_attr->name, ACPI_NAME_SIZE);
  230. else
  231. memcpy(name, "\0\0\0\0", 4);
  232. status = acpi_get_table(name, table_attr->instance, &table_header);
  233. if (ACPI_FAILURE(status))
  234. return -ENODEV;
  235. return memory_read_from_buffer(buf, count, &offset,
  236. table_header, table_header->length);
  237. }
  238. static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
  239. struct acpi_table_header *table_header)
  240. {
  241. struct acpi_table_header *header = NULL;
  242. struct acpi_table_attr *attr = NULL;
  243. sysfs_attr_init(&table_attr->attr.attr);
  244. if (table_header->signature[0] != '\0')
  245. memcpy(table_attr->name, table_header->signature,
  246. ACPI_NAME_SIZE);
  247. else
  248. memcpy(table_attr->name, "NULL", 4);
  249. list_for_each_entry(attr, &acpi_table_attr_list, node) {
  250. if (!memcmp(table_attr->name, attr->name, ACPI_NAME_SIZE))
  251. if (table_attr->instance < attr->instance)
  252. table_attr->instance = attr->instance;
  253. }
  254. table_attr->instance++;
  255. if (table_attr->instance > 1 || (table_attr->instance == 1 &&
  256. !acpi_get_table
  257. (table_header->signature, 2, &header)))
  258. sprintf(table_attr->name + ACPI_NAME_SIZE, "%d",
  259. table_attr->instance);
  260. table_attr->attr.size = table_header->length;
  261. table_attr->attr.read = acpi_table_show;
  262. table_attr->attr.attr.name = table_attr->name;
  263. table_attr->attr.attr.mode = 0400;
  264. return;
  265. }
  266. static acpi_status
  267. acpi_sysfs_table_handler(u32 event, void *table, void *context)
  268. {
  269. struct acpi_table_attr *table_attr;
  270. switch (event) {
  271. case ACPI_TABLE_EVENT_LOAD:
  272. table_attr =
  273. kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
  274. if (!table_attr)
  275. return AE_NO_MEMORY;
  276. acpi_table_attr_init(table_attr, table);
  277. if (sysfs_create_bin_file(dynamic_tables_kobj,
  278. &table_attr->attr)) {
  279. kfree(table_attr);
  280. return AE_ERROR;
  281. } else
  282. list_add_tail(&table_attr->node, &acpi_table_attr_list);
  283. break;
  284. case ACPI_TABLE_EVENT_UNLOAD:
  285. /*
  286. * we do not need to do anything right now
  287. * because the table is not deleted from the
  288. * global table list when unloading it.
  289. */
  290. break;
  291. default:
  292. return AE_BAD_PARAMETER;
  293. }
  294. return AE_OK;
  295. }
  296. static int acpi_tables_sysfs_init(void)
  297. {
  298. struct acpi_table_attr *table_attr;
  299. struct acpi_table_header *table_header = NULL;
  300. int table_index;
  301. acpi_status status;
  302. int ret;
  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. for (table_index = 0;; table_index++) {
  310. status = acpi_get_table_by_index(table_index, &table_header);
  311. if (status == AE_BAD_PARAMETER)
  312. break;
  313. if (ACPI_FAILURE(status))
  314. continue;
  315. table_attr = NULL;
  316. table_attr = kzalloc(sizeof(*table_attr), GFP_KERNEL);
  317. if (!table_attr)
  318. return -ENOMEM;
  319. acpi_table_attr_init(table_attr, table_header);
  320. ret = sysfs_create_bin_file(tables_kobj, &table_attr->attr);
  321. if (ret) {
  322. kfree(table_attr);
  323. return ret;
  324. }
  325. list_add_tail(&table_attr->node, &acpi_table_attr_list);
  326. }
  327. kobject_uevent(tables_kobj, KOBJ_ADD);
  328. kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
  329. status = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
  330. return ACPI_FAILURE(status) ? -EINVAL : 0;
  331. err_dynamic_tables:
  332. kobject_put(tables_kobj);
  333. err:
  334. return -ENOMEM;
  335. }
  336. /*
  337. * Detailed ACPI IRQ counters:
  338. * /sys/firmware/acpi/interrupts/
  339. */
  340. u32 acpi_irq_handled;
  341. u32 acpi_irq_not_handled;
  342. #define COUNT_GPE 0
  343. #define COUNT_SCI 1 /* acpi_irq_handled */
  344. #define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */
  345. #define COUNT_ERROR 3 /* other */
  346. #define NUM_COUNTERS_EXTRA 4
  347. struct event_counter {
  348. u32 count;
  349. u32 flags;
  350. };
  351. static struct event_counter *all_counters;
  352. static u32 num_gpes;
  353. static u32 num_counters;
  354. static struct attribute **all_attrs;
  355. static u32 acpi_gpe_count;
  356. static struct attribute_group interrupt_stats_attr_group = {
  357. .name = "interrupts",
  358. };
  359. static struct kobj_attribute *counter_attrs;
  360. static void delete_gpe_attr_array(void)
  361. {
  362. struct event_counter *tmp = all_counters;
  363. all_counters = NULL;
  364. kfree(tmp);
  365. if (counter_attrs) {
  366. int i;
  367. for (i = 0; i < num_gpes; i++)
  368. kfree(counter_attrs[i].attr.name);
  369. kfree(counter_attrs);
  370. }
  371. kfree(all_attrs);
  372. return;
  373. }
  374. static void gpe_count(u32 gpe_number)
  375. {
  376. acpi_gpe_count++;
  377. if (!all_counters)
  378. return;
  379. if (gpe_number < num_gpes)
  380. all_counters[gpe_number].count++;
  381. else
  382. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
  383. COUNT_ERROR].count++;
  384. return;
  385. }
  386. static void fixed_event_count(u32 event_number)
  387. {
  388. if (!all_counters)
  389. return;
  390. if (event_number < ACPI_NUM_FIXED_EVENTS)
  391. all_counters[num_gpes + event_number].count++;
  392. else
  393. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
  394. COUNT_ERROR].count++;
  395. return;
  396. }
  397. static void acpi_global_event_handler(u32 event_type, acpi_handle device,
  398. u32 event_number, void *context)
  399. {
  400. if (event_type == ACPI_EVENT_TYPE_GPE)
  401. gpe_count(event_number);
  402. if (event_type == ACPI_EVENT_TYPE_FIXED)
  403. fixed_event_count(event_number);
  404. }
  405. static int get_status(u32 index, acpi_event_status *status,
  406. acpi_handle *handle)
  407. {
  408. int result = 0;
  409. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  410. goto end;
  411. if (index < num_gpes) {
  412. result = acpi_get_gpe_device(index, handle);
  413. if (result) {
  414. ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
  415. "Invalid GPE 0x%x", index));
  416. goto end;
  417. }
  418. result = acpi_get_gpe_status(*handle, index, status);
  419. } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
  420. result = acpi_get_event_status(index - num_gpes, status);
  421. end:
  422. return result;
  423. }
  424. static ssize_t counter_show(struct kobject *kobj,
  425. struct kobj_attribute *attr, char *buf)
  426. {
  427. int index = attr - counter_attrs;
  428. int size;
  429. acpi_handle handle;
  430. acpi_event_status status;
  431. int result = 0;
  432. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count =
  433. acpi_irq_handled;
  434. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count =
  435. acpi_irq_not_handled;
  436. all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
  437. acpi_gpe_count;
  438. size = sprintf(buf, "%8u", all_counters[index].count);
  439. /* "gpe_all" or "sci" */
  440. if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS)
  441. goto end;
  442. result = get_status(index, &status, &handle);
  443. if (result)
  444. goto end;
  445. if (!(status & ACPI_EVENT_FLAG_HAS_HANDLER))
  446. size += sprintf(buf + size, " invalid");
  447. else if (status & ACPI_EVENT_FLAG_ENABLED)
  448. size += sprintf(buf + size, " enabled");
  449. else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED)
  450. size += sprintf(buf + size, " wake_enabled");
  451. else
  452. size += sprintf(buf + size, " disabled");
  453. end:
  454. size += sprintf(buf + size, "\n");
  455. return result ? result : size;
  456. }
  457. /*
  458. * counter_set() sets the specified counter.
  459. * setting the total "sci" file to any value clears all counters.
  460. * enable/disable/clear a gpe/fixed event in user space.
  461. */
  462. static ssize_t counter_set(struct kobject *kobj,
  463. struct kobj_attribute *attr, const char *buf,
  464. size_t size)
  465. {
  466. int index = attr - counter_attrs;
  467. acpi_event_status status;
  468. acpi_handle handle;
  469. int result = 0;
  470. unsigned long tmp;
  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_HAS_HANDLER)) {
  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 if (!kstrtoul(buf, 0, &tmp))
  500. all_counters[index].count = tmp;
  501. else
  502. result = -EINVAL;
  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 if (!kstrtoul(buf, 0, &tmp))
  515. all_counters[index].count = tmp;
  516. else
  517. result = -EINVAL;
  518. } else
  519. all_counters[index].count = strtoul(buf, NULL, 0);
  520. if (ACPI_FAILURE(result))
  521. result = -EINVAL;
  522. end:
  523. return result ? result : size;
  524. }
  525. void acpi_irq_stats_init(void)
  526. {
  527. acpi_status status;
  528. int i;
  529. if (all_counters)
  530. return;
  531. num_gpes = acpi_current_gpe_count;
  532. num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
  533. all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
  534. GFP_KERNEL);
  535. if (all_attrs == NULL)
  536. return;
  537. all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
  538. GFP_KERNEL);
  539. if (all_counters == NULL)
  540. goto fail;
  541. status = acpi_install_global_event_handler(acpi_global_event_handler, NULL);
  542. if (ACPI_FAILURE(status))
  543. goto fail;
  544. counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
  545. GFP_KERNEL);
  546. if (counter_attrs == NULL)
  547. goto fail;
  548. for (i = 0; i < num_counters; ++i) {
  549. char buffer[12];
  550. char *name;
  551. if (i < num_gpes)
  552. sprintf(buffer, "gpe%02X", i);
  553. else if (i == num_gpes + ACPI_EVENT_PMTIMER)
  554. sprintf(buffer, "ff_pmtimer");
  555. else if (i == num_gpes + ACPI_EVENT_GLOBAL)
  556. sprintf(buffer, "ff_gbl_lock");
  557. else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON)
  558. sprintf(buffer, "ff_pwr_btn");
  559. else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON)
  560. sprintf(buffer, "ff_slp_btn");
  561. else if (i == num_gpes + ACPI_EVENT_RTC)
  562. sprintf(buffer, "ff_rt_clk");
  563. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE)
  564. sprintf(buffer, "gpe_all");
  565. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
  566. sprintf(buffer, "sci");
  567. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT)
  568. sprintf(buffer, "sci_not");
  569. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
  570. sprintf(buffer, "error");
  571. else
  572. sprintf(buffer, "bug%02X", i);
  573. name = kstrdup(buffer, GFP_KERNEL);
  574. if (name == NULL)
  575. goto fail;
  576. sysfs_attr_init(&counter_attrs[i].attr);
  577. counter_attrs[i].attr.name = name;
  578. counter_attrs[i].attr.mode = 0644;
  579. counter_attrs[i].show = counter_show;
  580. counter_attrs[i].store = counter_set;
  581. all_attrs[i] = &counter_attrs[i].attr;
  582. }
  583. interrupt_stats_attr_group.attrs = all_attrs;
  584. if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group))
  585. return;
  586. fail:
  587. delete_gpe_attr_array();
  588. return;
  589. }
  590. static void __exit interrupt_stats_exit(void)
  591. {
  592. sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group);
  593. delete_gpe_attr_array();
  594. return;
  595. }
  596. static ssize_t
  597. acpi_show_profile(struct device *dev, struct device_attribute *attr,
  598. char *buf)
  599. {
  600. return sprintf(buf, "%d\n", acpi_gbl_FADT.preferred_profile);
  601. }
  602. static const struct device_attribute pm_profile_attr =
  603. __ATTR(pm_profile, S_IRUGO, acpi_show_profile, NULL);
  604. static ssize_t hotplug_enabled_show(struct kobject *kobj,
  605. struct kobj_attribute *attr, char *buf)
  606. {
  607. struct acpi_hotplug_profile *hotplug = to_acpi_hotplug_profile(kobj);
  608. return sprintf(buf, "%d\n", hotplug->enabled);
  609. }
  610. static ssize_t hotplug_enabled_store(struct kobject *kobj,
  611. struct kobj_attribute *attr,
  612. const char *buf, size_t size)
  613. {
  614. struct acpi_hotplug_profile *hotplug = to_acpi_hotplug_profile(kobj);
  615. unsigned int val;
  616. if (kstrtouint(buf, 10, &val) || val > 1)
  617. return -EINVAL;
  618. acpi_scan_hotplug_enabled(hotplug, val);
  619. return size;
  620. }
  621. static struct kobj_attribute hotplug_enabled_attr =
  622. __ATTR(enabled, S_IRUGO | S_IWUSR, hotplug_enabled_show,
  623. hotplug_enabled_store);
  624. static struct attribute *hotplug_profile_attrs[] = {
  625. &hotplug_enabled_attr.attr,
  626. NULL
  627. };
  628. static struct kobj_type acpi_hotplug_profile_ktype = {
  629. .sysfs_ops = &kobj_sysfs_ops,
  630. .default_attrs = hotplug_profile_attrs,
  631. };
  632. void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug,
  633. const char *name)
  634. {
  635. int error;
  636. if (!hotplug_kobj)
  637. goto err_out;
  638. error = kobject_init_and_add(&hotplug->kobj,
  639. &acpi_hotplug_profile_ktype, hotplug_kobj, "%s", name);
  640. if (error)
  641. goto err_out;
  642. kobject_uevent(&hotplug->kobj, KOBJ_ADD);
  643. return;
  644. err_out:
  645. pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name);
  646. }
  647. static ssize_t force_remove_show(struct kobject *kobj,
  648. struct kobj_attribute *attr, char *buf)
  649. {
  650. return sprintf(buf, "%d\n", !!acpi_force_hot_remove);
  651. }
  652. static ssize_t force_remove_store(struct kobject *kobj,
  653. struct kobj_attribute *attr,
  654. const char *buf, size_t size)
  655. {
  656. bool val;
  657. int ret;
  658. ret = strtobool(buf, &val);
  659. if (ret < 0)
  660. return ret;
  661. lock_device_hotplug();
  662. acpi_force_hot_remove = val;
  663. unlock_device_hotplug();
  664. return size;
  665. }
  666. static const struct kobj_attribute force_remove_attr =
  667. __ATTR(force_remove, S_IRUGO | S_IWUSR, force_remove_show,
  668. force_remove_store);
  669. int __init acpi_sysfs_init(void)
  670. {
  671. int result;
  672. result = acpi_tables_sysfs_init();
  673. if (result)
  674. return result;
  675. hotplug_kobj = kobject_create_and_add("hotplug", acpi_kobj);
  676. result = sysfs_create_file(hotplug_kobj, &force_remove_attr.attr);
  677. if (result)
  678. return result;
  679. result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr);
  680. return result;
  681. }