sysfs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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 = table_header->length;
  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;
  302. acpi_status status;
  303. int ret;
  304. tables_kobj = kobject_create_and_add("tables", acpi_kobj);
  305. if (!tables_kobj)
  306. goto err;
  307. dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj);
  308. if (!dynamic_tables_kobj)
  309. goto err_dynamic_tables;
  310. for (table_index = 0;; table_index++) {
  311. status = acpi_get_table_by_index(table_index, &table_header);
  312. if (status == AE_BAD_PARAMETER)
  313. break;
  314. if (ACPI_FAILURE(status))
  315. continue;
  316. table_attr = NULL;
  317. table_attr = kzalloc(sizeof(*table_attr), GFP_KERNEL);
  318. if (!table_attr)
  319. return -ENOMEM;
  320. acpi_table_attr_init(table_attr, table_header);
  321. ret = sysfs_create_bin_file(tables_kobj, &table_attr->attr);
  322. if (ret) {
  323. kfree(table_attr);
  324. return ret;
  325. }
  326. list_add_tail(&table_attr->node, &acpi_table_attr_list);
  327. }
  328. kobject_uevent(tables_kobj, KOBJ_ADD);
  329. kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
  330. status = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
  331. return ACPI_FAILURE(status) ? -EINVAL : 0;
  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_global_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", 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. unsigned long tmp;
  472. if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
  473. int i;
  474. for (i = 0; i < num_counters; ++i)
  475. all_counters[i].count = 0;
  476. acpi_gpe_count = 0;
  477. acpi_irq_handled = 0;
  478. acpi_irq_not_handled = 0;
  479. goto end;
  480. }
  481. /* show the event status for both GPEs and Fixed Events */
  482. result = get_status(index, &status, &handle);
  483. if (result)
  484. goto end;
  485. if (!(status & ACPI_EVENT_FLAG_HANDLE)) {
  486. printk(KERN_WARNING PREFIX
  487. "Can not change Invalid GPE/Fixed Event status\n");
  488. return -EINVAL;
  489. }
  490. if (index < num_gpes) {
  491. if (!strcmp(buf, "disable\n") &&
  492. (status & ACPI_EVENT_FLAG_ENABLED))
  493. result = acpi_disable_gpe(handle, index);
  494. else if (!strcmp(buf, "enable\n") &&
  495. !(status & ACPI_EVENT_FLAG_ENABLED))
  496. result = acpi_enable_gpe(handle, index);
  497. else if (!strcmp(buf, "clear\n") &&
  498. (status & ACPI_EVENT_FLAG_SET))
  499. result = acpi_clear_gpe(handle, index);
  500. else if (!kstrtoul(buf, 0, &tmp))
  501. all_counters[index].count = tmp;
  502. else
  503. result = -EINVAL;
  504. } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
  505. int event = index - num_gpes;
  506. if (!strcmp(buf, "disable\n") &&
  507. (status & ACPI_EVENT_FLAG_ENABLED))
  508. result = acpi_disable_event(event, ACPI_NOT_ISR);
  509. else if (!strcmp(buf, "enable\n") &&
  510. !(status & ACPI_EVENT_FLAG_ENABLED))
  511. result = acpi_enable_event(event, ACPI_NOT_ISR);
  512. else if (!strcmp(buf, "clear\n") &&
  513. (status & ACPI_EVENT_FLAG_SET))
  514. result = acpi_clear_event(event);
  515. else if (!kstrtoul(buf, 0, &tmp))
  516. all_counters[index].count = tmp;
  517. else
  518. result = -EINVAL;
  519. } else
  520. all_counters[index].count = strtoul(buf, NULL, 0);
  521. if (ACPI_FAILURE(result))
  522. result = -EINVAL;
  523. end:
  524. return result ? result : size;
  525. }
  526. void acpi_irq_stats_init(void)
  527. {
  528. acpi_status status;
  529. int i;
  530. if (all_counters)
  531. return;
  532. num_gpes = acpi_current_gpe_count;
  533. num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
  534. all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
  535. GFP_KERNEL);
  536. if (all_attrs == NULL)
  537. return;
  538. all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
  539. GFP_KERNEL);
  540. if (all_counters == NULL)
  541. goto fail;
  542. status = acpi_install_global_event_handler(acpi_global_event_handler, NULL);
  543. if (ACPI_FAILURE(status))
  544. goto fail;
  545. counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
  546. GFP_KERNEL);
  547. if (counter_attrs == NULL)
  548. goto fail;
  549. for (i = 0; i < num_counters; ++i) {
  550. char buffer[12];
  551. char *name;
  552. if (i < num_gpes)
  553. sprintf(buffer, "gpe%02X", i);
  554. else if (i == num_gpes + ACPI_EVENT_PMTIMER)
  555. sprintf(buffer, "ff_pmtimer");
  556. else if (i == num_gpes + ACPI_EVENT_GLOBAL)
  557. sprintf(buffer, "ff_gbl_lock");
  558. else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON)
  559. sprintf(buffer, "ff_pwr_btn");
  560. else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON)
  561. sprintf(buffer, "ff_slp_btn");
  562. else if (i == num_gpes + ACPI_EVENT_RTC)
  563. sprintf(buffer, "ff_rt_clk");
  564. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE)
  565. sprintf(buffer, "gpe_all");
  566. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
  567. sprintf(buffer, "sci");
  568. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT)
  569. sprintf(buffer, "sci_not");
  570. else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
  571. sprintf(buffer, "error");
  572. else
  573. sprintf(buffer, "bug%02X", i);
  574. name = kstrdup(buffer, GFP_KERNEL);
  575. if (name == NULL)
  576. goto fail;
  577. sysfs_attr_init(&counter_attrs[i].attr);
  578. counter_attrs[i].attr.name = name;
  579. counter_attrs[i].attr.mode = 0644;
  580. counter_attrs[i].show = counter_show;
  581. counter_attrs[i].store = counter_set;
  582. all_attrs[i] = &counter_attrs[i].attr;
  583. }
  584. interrupt_stats_attr_group.attrs = all_attrs;
  585. if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group))
  586. return;
  587. fail:
  588. delete_gpe_attr_array();
  589. return;
  590. }
  591. static void __exit interrupt_stats_exit(void)
  592. {
  593. sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group);
  594. delete_gpe_attr_array();
  595. return;
  596. }
  597. static ssize_t
  598. acpi_show_profile(struct device *dev, struct device_attribute *attr,
  599. char *buf)
  600. {
  601. return sprintf(buf, "%d\n", acpi_gbl_FADT.preferred_profile);
  602. }
  603. static const struct device_attribute pm_profile_attr =
  604. __ATTR(pm_profile, S_IRUGO, acpi_show_profile, NULL);
  605. static ssize_t hotplug_enabled_show(struct kobject *kobj,
  606. struct kobj_attribute *attr, char *buf)
  607. {
  608. struct acpi_hotplug_profile *hotplug = to_acpi_hotplug_profile(kobj);
  609. return sprintf(buf, "%d\n", hotplug->enabled);
  610. }
  611. static ssize_t hotplug_enabled_store(struct kobject *kobj,
  612. struct kobj_attribute *attr,
  613. const char *buf, size_t size)
  614. {
  615. struct acpi_hotplug_profile *hotplug = to_acpi_hotplug_profile(kobj);
  616. unsigned int val;
  617. if (kstrtouint(buf, 10, &val) || val > 1)
  618. return -EINVAL;
  619. acpi_scan_hotplug_enabled(hotplug, val);
  620. return size;
  621. }
  622. static struct kobj_attribute hotplug_enabled_attr =
  623. __ATTR(enabled, S_IRUGO | S_IWUSR, hotplug_enabled_show,
  624. hotplug_enabled_store);
  625. static struct attribute *hotplug_profile_attrs[] = {
  626. &hotplug_enabled_attr.attr,
  627. NULL
  628. };
  629. static struct kobj_type acpi_hotplug_profile_ktype = {
  630. .sysfs_ops = &kobj_sysfs_ops,
  631. .default_attrs = hotplug_profile_attrs,
  632. };
  633. void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug,
  634. const char *name)
  635. {
  636. int error;
  637. if (!hotplug_kobj)
  638. goto err_out;
  639. error = kobject_init_and_add(&hotplug->kobj,
  640. &acpi_hotplug_profile_ktype, hotplug_kobj, "%s", name);
  641. if (error)
  642. goto err_out;
  643. kobject_uevent(&hotplug->kobj, KOBJ_ADD);
  644. return;
  645. err_out:
  646. pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name);
  647. }
  648. static ssize_t force_remove_show(struct kobject *kobj,
  649. struct kobj_attribute *attr, char *buf)
  650. {
  651. return sprintf(buf, "%d\n", !!acpi_force_hot_remove);
  652. }
  653. static ssize_t force_remove_store(struct kobject *kobj,
  654. struct kobj_attribute *attr,
  655. const char *buf, size_t size)
  656. {
  657. bool val;
  658. int ret;
  659. ret = strtobool(buf, &val);
  660. if (ret < 0)
  661. return ret;
  662. lock_device_hotplug();
  663. acpi_force_hot_remove = val;
  664. unlock_device_hotplug();
  665. return size;
  666. }
  667. static const struct kobj_attribute force_remove_attr =
  668. __ATTR(force_remove, S_IRUGO | S_IWUSR, force_remove_show,
  669. force_remove_store);
  670. int __init acpi_sysfs_init(void)
  671. {
  672. int result;
  673. result = acpi_tables_sysfs_init();
  674. if (result)
  675. return result;
  676. hotplug_kobj = kobject_create_and_add("hotplug", acpi_kobj);
  677. result = sysfs_create_file(hotplug_kobj, &force_remove_attr.attr);
  678. if (result)
  679. return result;
  680. result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr);
  681. return result;
  682. }