1
0

apm-emulation.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * bios-less APM driver for ARM Linux
  4. * Jamey Hicks <jamey@crl.dec.com>
  5. * adapted from the APM BIOS driver for Linux by Stephen Rothwell (sfr@linuxcare.com)
  6. *
  7. * APM 1.2 Reference:
  8. * Intel Corporation, Microsoft Corporation. Advanced Power Management
  9. * (APM) BIOS Interface Specification, Revision 1.2, February 1996.
  10. *
  11. * This document is available from Microsoft at:
  12. * http://www.microsoft.com/whdc/archive/amp_12.mspx
  13. */
  14. #include <linux/module.h>
  15. #include <linux/poll.h>
  16. #include <linux/slab.h>
  17. #include <linux/mutex.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/miscdevice.h>
  21. #include <linux/apm_bios.h>
  22. #include <linux/capability.h>
  23. #include <linux/sched.h>
  24. #include <linux/suspend.h>
  25. #include <linux/apm-emulation.h>
  26. #include <linux/freezer.h>
  27. #include <linux/device.h>
  28. #include <linux/kernel.h>
  29. #include <linux/list.h>
  30. #include <linux/init.h>
  31. #include <linux/completion.h>
  32. #include <linux/kthread.h>
  33. #include <linux/delay.h>
  34. /*
  35. * One option can be changed at boot time as follows:
  36. * apm=on/off enable/disable APM
  37. */
  38. /*
  39. * Maximum number of events stored
  40. */
  41. #define APM_MAX_EVENTS 16
  42. struct apm_queue {
  43. unsigned int event_head;
  44. unsigned int event_tail;
  45. apm_event_t events[APM_MAX_EVENTS];
  46. };
  47. /*
  48. * thread states (for threads using a writable /dev/apm_bios fd):
  49. *
  50. * SUSPEND_NONE: nothing happening
  51. * SUSPEND_PENDING: suspend event queued for thread and pending to be read
  52. * SUSPEND_READ: suspend event read, pending acknowledgement
  53. * SUSPEND_ACKED: acknowledgement received from thread (via ioctl),
  54. * waiting for resume
  55. * SUSPEND_ACKTO: acknowledgement timeout
  56. * SUSPEND_DONE: thread had acked suspend and is now notified of
  57. * resume
  58. *
  59. * SUSPEND_WAIT: this thread invoked suspend and is waiting for resume
  60. *
  61. * A thread migrates in one of three paths:
  62. * NONE -1-> PENDING -2-> READ -3-> ACKED -4-> DONE -5-> NONE
  63. * -6-> ACKTO -7-> NONE
  64. * NONE -8-> WAIT -9-> NONE
  65. *
  66. * While in PENDING or READ, the thread is accounted for in the
  67. * suspend_acks_pending counter.
  68. *
  69. * The transitions are invoked as follows:
  70. * 1: suspend event is signalled from the core PM code
  71. * 2: the suspend event is read from the fd by the userspace thread
  72. * 3: userspace thread issues the APM_IOC_SUSPEND ioctl (as ack)
  73. * 4: core PM code signals that we have resumed
  74. * 5: APM_IOC_SUSPEND ioctl returns
  75. *
  76. * 6: the notifier invoked from the core PM code timed out waiting
  77. * for all relevant threds to enter ACKED state and puts those
  78. * that haven't into ACKTO
  79. * 7: those threads issue APM_IOC_SUSPEND ioctl too late,
  80. * get an error
  81. *
  82. * 8: userspace thread issues the APM_IOC_SUSPEND ioctl (to suspend),
  83. * ioctl code invokes pm_suspend()
  84. * 9: pm_suspend() returns indicating resume
  85. */
  86. enum apm_suspend_state {
  87. SUSPEND_NONE,
  88. SUSPEND_PENDING,
  89. SUSPEND_READ,
  90. SUSPEND_ACKED,
  91. SUSPEND_ACKTO,
  92. SUSPEND_WAIT,
  93. SUSPEND_DONE,
  94. };
  95. /*
  96. * The per-file APM data
  97. */
  98. struct apm_user {
  99. struct list_head list;
  100. unsigned int suser: 1;
  101. unsigned int writer: 1;
  102. unsigned int reader: 1;
  103. int suspend_result;
  104. enum apm_suspend_state suspend_state;
  105. struct apm_queue queue;
  106. };
  107. /*
  108. * Local variables
  109. */
  110. static atomic_t suspend_acks_pending = ATOMIC_INIT(0);
  111. static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0);
  112. static int apm_disabled;
  113. static struct task_struct *kapmd_tsk;
  114. static DECLARE_WAIT_QUEUE_HEAD(apm_waitqueue);
  115. static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
  116. /*
  117. * This is a list of everyone who has opened /dev/apm_bios
  118. */
  119. static DECLARE_RWSEM(user_list_lock);
  120. static LIST_HEAD(apm_user_list);
  121. /*
  122. * kapmd info. kapmd provides us a process context to handle
  123. * "APM" events within - specifically necessary if we're going
  124. * to be suspending the system.
  125. */
  126. static DECLARE_WAIT_QUEUE_HEAD(kapmd_wait);
  127. static DEFINE_SPINLOCK(kapmd_queue_lock);
  128. static struct apm_queue kapmd_queue;
  129. static DEFINE_MUTEX(state_lock);
  130. /*
  131. * This allows machines to provide their own "apm get power status" function.
  132. */
  133. void (*apm_get_power_status)(struct apm_power_info *);
  134. EXPORT_SYMBOL(apm_get_power_status);
  135. /*
  136. * APM event queue management.
  137. */
  138. static inline int queue_empty(struct apm_queue *q)
  139. {
  140. return q->event_head == q->event_tail;
  141. }
  142. static inline apm_event_t queue_get_event(struct apm_queue *q)
  143. {
  144. q->event_tail = (q->event_tail + 1) % APM_MAX_EVENTS;
  145. return q->events[q->event_tail];
  146. }
  147. static void queue_add_event(struct apm_queue *q, apm_event_t event)
  148. {
  149. q->event_head = (q->event_head + 1) % APM_MAX_EVENTS;
  150. if (q->event_head == q->event_tail) {
  151. static int notified;
  152. if (notified++ == 0)
  153. printk(KERN_ERR "apm: an event queue overflowed\n");
  154. q->event_tail = (q->event_tail + 1) % APM_MAX_EVENTS;
  155. }
  156. q->events[q->event_head] = event;
  157. }
  158. static void queue_event(apm_event_t event)
  159. {
  160. struct apm_user *as;
  161. down_read(&user_list_lock);
  162. list_for_each_entry(as, &apm_user_list, list) {
  163. if (as->reader)
  164. queue_add_event(&as->queue, event);
  165. }
  166. up_read(&user_list_lock);
  167. wake_up_interruptible(&apm_waitqueue);
  168. }
  169. static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
  170. {
  171. struct apm_user *as = fp->private_data;
  172. apm_event_t event;
  173. int i = count, ret = 0;
  174. if (count < sizeof(apm_event_t))
  175. return -EINVAL;
  176. if (queue_empty(&as->queue) && fp->f_flags & O_NONBLOCK)
  177. return -EAGAIN;
  178. wait_event_interruptible(apm_waitqueue, !queue_empty(&as->queue));
  179. while ((i >= sizeof(event)) && !queue_empty(&as->queue)) {
  180. event = queue_get_event(&as->queue);
  181. ret = -EFAULT;
  182. if (copy_to_user(buf, &event, sizeof(event)))
  183. break;
  184. mutex_lock(&state_lock);
  185. if (as->suspend_state == SUSPEND_PENDING &&
  186. (event == APM_SYS_SUSPEND || event == APM_USER_SUSPEND))
  187. as->suspend_state = SUSPEND_READ;
  188. mutex_unlock(&state_lock);
  189. buf += sizeof(event);
  190. i -= sizeof(event);
  191. }
  192. if (i < count)
  193. ret = count - i;
  194. return ret;
  195. }
  196. static __poll_t apm_poll(struct file *fp, poll_table * wait)
  197. {
  198. struct apm_user *as = fp->private_data;
  199. poll_wait(fp, &apm_waitqueue, wait);
  200. return queue_empty(&as->queue) ? 0 : EPOLLIN | EPOLLRDNORM;
  201. }
  202. /*
  203. * apm_ioctl - handle APM ioctl
  204. *
  205. * APM_IOC_SUSPEND
  206. * This IOCTL is overloaded, and performs two functions. It is used to:
  207. * - initiate a suspend
  208. * - acknowledge a suspend read from /dev/apm_bios.
  209. * Only when everyone who has opened /dev/apm_bios with write permission
  210. * has acknowledge does the actual suspend happen.
  211. */
  212. static long
  213. apm_ioctl(struct file *filp, u_int cmd, u_long arg)
  214. {
  215. struct apm_user *as = filp->private_data;
  216. int err = -EINVAL;
  217. if (!as->suser || !as->writer)
  218. return -EPERM;
  219. switch (cmd) {
  220. case APM_IOC_SUSPEND:
  221. mutex_lock(&state_lock);
  222. as->suspend_result = -EINTR;
  223. switch (as->suspend_state) {
  224. case SUSPEND_READ:
  225. /*
  226. * If we read a suspend command from /dev/apm_bios,
  227. * then the corresponding APM_IOC_SUSPEND ioctl is
  228. * interpreted as an acknowledge.
  229. */
  230. as->suspend_state = SUSPEND_ACKED;
  231. atomic_dec(&suspend_acks_pending);
  232. mutex_unlock(&state_lock);
  233. /*
  234. * suspend_acks_pending changed, the notifier needs to
  235. * be woken up for this
  236. */
  237. wake_up(&apm_suspend_waitqueue);
  238. /*
  239. * Wait for the suspend/resume to complete. If there
  240. * are pending acknowledges, we wait here for them.
  241. * wait_event_freezable() is interruptible and pending
  242. * signal can cause busy looping. We aren't doing
  243. * anything critical, chill a bit on each iteration.
  244. */
  245. while (wait_event_freezable(apm_suspend_waitqueue,
  246. as->suspend_state != SUSPEND_ACKED))
  247. msleep(10);
  248. break;
  249. case SUSPEND_ACKTO:
  250. as->suspend_result = -ETIMEDOUT;
  251. mutex_unlock(&state_lock);
  252. break;
  253. default:
  254. as->suspend_state = SUSPEND_WAIT;
  255. mutex_unlock(&state_lock);
  256. /*
  257. * Otherwise it is a request to suspend the system.
  258. * Just invoke pm_suspend(), we'll handle it from
  259. * there via the notifier.
  260. */
  261. as->suspend_result = pm_suspend(PM_SUSPEND_MEM);
  262. }
  263. mutex_lock(&state_lock);
  264. err = as->suspend_result;
  265. as->suspend_state = SUSPEND_NONE;
  266. mutex_unlock(&state_lock);
  267. break;
  268. }
  269. return err;
  270. }
  271. static int apm_release(struct inode * inode, struct file * filp)
  272. {
  273. struct apm_user *as = filp->private_data;
  274. filp->private_data = NULL;
  275. down_write(&user_list_lock);
  276. list_del(&as->list);
  277. up_write(&user_list_lock);
  278. /*
  279. * We are now unhooked from the chain. As far as new
  280. * events are concerned, we no longer exist.
  281. */
  282. mutex_lock(&state_lock);
  283. if (as->suspend_state == SUSPEND_PENDING ||
  284. as->suspend_state == SUSPEND_READ)
  285. atomic_dec(&suspend_acks_pending);
  286. mutex_unlock(&state_lock);
  287. wake_up(&apm_suspend_waitqueue);
  288. kfree(as);
  289. return 0;
  290. }
  291. static int apm_open(struct inode * inode, struct file * filp)
  292. {
  293. struct apm_user *as;
  294. as = kzalloc_obj(*as);
  295. if (as) {
  296. /*
  297. * XXX - this is a tiny bit broken, when we consider BSD
  298. * process accounting. If the device is opened by root, we
  299. * instantly flag that we used superuser privs. Who knows,
  300. * we might close the device immediately without doing a
  301. * privileged operation -- cevans
  302. */
  303. as->suser = capable(CAP_SYS_ADMIN);
  304. as->writer = (filp->f_mode & FMODE_WRITE) == FMODE_WRITE;
  305. as->reader = (filp->f_mode & FMODE_READ) == FMODE_READ;
  306. down_write(&user_list_lock);
  307. list_add(&as->list, &apm_user_list);
  308. up_write(&user_list_lock);
  309. filp->private_data = as;
  310. }
  311. return as ? 0 : -ENOMEM;
  312. }
  313. static const struct file_operations apm_bios_fops = {
  314. .owner = THIS_MODULE,
  315. .read = apm_read,
  316. .poll = apm_poll,
  317. .unlocked_ioctl = apm_ioctl,
  318. .open = apm_open,
  319. .release = apm_release,
  320. .llseek = noop_llseek,
  321. };
  322. static struct miscdevice apm_device = {
  323. .minor = APM_MINOR_DEV,
  324. .name = "apm_bios",
  325. .fops = &apm_bios_fops
  326. };
  327. #ifdef CONFIG_PROC_FS
  328. /*
  329. * Arguments, with symbols from linux/apm_bios.h.
  330. *
  331. * 0) Linux driver version (this will change if format changes)
  332. * 1) APM BIOS Version. Usually 1.0, 1.1 or 1.2.
  333. * 2) APM flags from APM Installation Check (0x00):
  334. * bit 0: APM_16_BIT_SUPPORT
  335. * bit 1: APM_32_BIT_SUPPORT
  336. * bit 2: APM_IDLE_SLOWS_CLOCK
  337. * bit 3: APM_BIOS_DISABLED
  338. * bit 4: APM_BIOS_DISENGAGED
  339. * 3) AC line status
  340. * 0x00: Off-line
  341. * 0x01: On-line
  342. * 0x02: On backup power (BIOS >= 1.1 only)
  343. * 0xff: Unknown
  344. * 4) Battery status
  345. * 0x00: High
  346. * 0x01: Low
  347. * 0x02: Critical
  348. * 0x03: Charging
  349. * 0x04: Selected battery not present (BIOS >= 1.2 only)
  350. * 0xff: Unknown
  351. * 5) Battery flag
  352. * bit 0: High
  353. * bit 1: Low
  354. * bit 2: Critical
  355. * bit 3: Charging
  356. * bit 7: No system battery
  357. * 0xff: Unknown
  358. * 6) Remaining battery life (percentage of charge):
  359. * 0-100: valid
  360. * -1: Unknown
  361. * 7) Remaining battery life (time units):
  362. * Number of remaining minutes or seconds
  363. * -1: Unknown
  364. * 8) min = minutes; sec = seconds
  365. */
  366. static int proc_apm_show(struct seq_file *m, void *v)
  367. {
  368. static const char driver_version[] = "1.13"; /* no spaces */
  369. struct apm_power_info info;
  370. char *units;
  371. info.ac_line_status = 0xff;
  372. info.battery_status = 0xff;
  373. info.battery_flag = 0xff;
  374. info.battery_life = -1;
  375. info.time = -1;
  376. info.units = -1;
  377. if (apm_get_power_status)
  378. apm_get_power_status(&info);
  379. switch (info.units) {
  380. default: units = "?"; break;
  381. case 0: units = "min"; break;
  382. case 1: units = "sec"; break;
  383. }
  384. seq_printf(m, "%s 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
  385. driver_version, APM_32_BIT_SUPPORT,
  386. info.ac_line_status, info.battery_status,
  387. info.battery_flag, info.battery_life,
  388. info.time, units);
  389. return 0;
  390. }
  391. #endif
  392. static int kapmd(void *arg)
  393. {
  394. do {
  395. apm_event_t event;
  396. wait_event_interruptible(kapmd_wait,
  397. !queue_empty(&kapmd_queue) || kthread_should_stop());
  398. if (kthread_should_stop())
  399. break;
  400. spin_lock_irq(&kapmd_queue_lock);
  401. event = 0;
  402. if (!queue_empty(&kapmd_queue))
  403. event = queue_get_event(&kapmd_queue);
  404. spin_unlock_irq(&kapmd_queue_lock);
  405. switch (event) {
  406. case 0:
  407. break;
  408. case APM_LOW_BATTERY:
  409. case APM_POWER_STATUS_CHANGE:
  410. queue_event(event);
  411. break;
  412. case APM_USER_SUSPEND:
  413. case APM_SYS_SUSPEND:
  414. pm_suspend(PM_SUSPEND_MEM);
  415. break;
  416. case APM_CRITICAL_SUSPEND:
  417. atomic_inc(&userspace_notification_inhibit);
  418. pm_suspend(PM_SUSPEND_MEM);
  419. atomic_dec(&userspace_notification_inhibit);
  420. break;
  421. }
  422. } while (1);
  423. return 0;
  424. }
  425. static int apm_suspend_notifier(struct notifier_block *nb,
  426. unsigned long event,
  427. void *dummy)
  428. {
  429. struct apm_user *as;
  430. int err;
  431. unsigned long apm_event;
  432. /* short-cut emergency suspends */
  433. if (atomic_read(&userspace_notification_inhibit))
  434. return NOTIFY_DONE;
  435. switch (event) {
  436. case PM_SUSPEND_PREPARE:
  437. case PM_HIBERNATION_PREPARE:
  438. apm_event = (event == PM_SUSPEND_PREPARE) ?
  439. APM_USER_SUSPEND : APM_USER_HIBERNATION;
  440. /*
  441. * Queue an event to all "writer" users that we want
  442. * to suspend and need their ack.
  443. */
  444. mutex_lock(&state_lock);
  445. down_read(&user_list_lock);
  446. list_for_each_entry(as, &apm_user_list, list) {
  447. if (as->suspend_state != SUSPEND_WAIT && as->reader &&
  448. as->writer && as->suser) {
  449. as->suspend_state = SUSPEND_PENDING;
  450. atomic_inc(&suspend_acks_pending);
  451. queue_add_event(&as->queue, apm_event);
  452. }
  453. }
  454. up_read(&user_list_lock);
  455. mutex_unlock(&state_lock);
  456. wake_up_interruptible(&apm_waitqueue);
  457. /*
  458. * Wait for the suspend_acks_pending variable to drop to
  459. * zero, meaning everybody acked the suspend event (or the
  460. * process was killed.)
  461. *
  462. * If the app won't answer within a short while we assume it
  463. * locked up and ignore it.
  464. */
  465. err = wait_event_interruptible_timeout(
  466. apm_suspend_waitqueue,
  467. atomic_read(&suspend_acks_pending) == 0,
  468. 5*HZ);
  469. /* timed out */
  470. if (err == 0) {
  471. /*
  472. * Move anybody who timed out to "ack timeout" state.
  473. *
  474. * We could time out and the userspace does the ACK
  475. * right after we time out but before we enter the
  476. * locked section here, but that's fine.
  477. */
  478. mutex_lock(&state_lock);
  479. down_read(&user_list_lock);
  480. list_for_each_entry(as, &apm_user_list, list) {
  481. if (as->suspend_state == SUSPEND_PENDING ||
  482. as->suspend_state == SUSPEND_READ) {
  483. as->suspend_state = SUSPEND_ACKTO;
  484. atomic_dec(&suspend_acks_pending);
  485. }
  486. }
  487. up_read(&user_list_lock);
  488. mutex_unlock(&state_lock);
  489. }
  490. /* let suspend proceed */
  491. if (err >= 0)
  492. return NOTIFY_OK;
  493. /* interrupted by signal */
  494. return notifier_from_errno(err);
  495. case PM_POST_SUSPEND:
  496. case PM_POST_HIBERNATION:
  497. apm_event = (event == PM_POST_SUSPEND) ?
  498. APM_NORMAL_RESUME : APM_HIBERNATION_RESUME;
  499. /*
  500. * Anyone on the APM queues will think we're still suspended.
  501. * Send a message so everyone knows we're now awake again.
  502. */
  503. queue_event(apm_event);
  504. /*
  505. * Finally, wake up anyone who is sleeping on the suspend.
  506. */
  507. mutex_lock(&state_lock);
  508. down_read(&user_list_lock);
  509. list_for_each_entry(as, &apm_user_list, list) {
  510. if (as->suspend_state == SUSPEND_ACKED) {
  511. /*
  512. * TODO: maybe grab error code, needs core
  513. * changes to push the error to the notifier
  514. * chain (could use the second parameter if
  515. * implemented)
  516. */
  517. as->suspend_result = 0;
  518. as->suspend_state = SUSPEND_DONE;
  519. }
  520. }
  521. up_read(&user_list_lock);
  522. mutex_unlock(&state_lock);
  523. wake_up(&apm_suspend_waitqueue);
  524. return NOTIFY_OK;
  525. default:
  526. return NOTIFY_DONE;
  527. }
  528. }
  529. static struct notifier_block apm_notif_block = {
  530. .notifier_call = apm_suspend_notifier,
  531. };
  532. static int __init apm_init(void)
  533. {
  534. int ret;
  535. if (apm_disabled) {
  536. printk(KERN_NOTICE "apm: disabled on user request.\n");
  537. return -ENODEV;
  538. }
  539. kapmd_tsk = kthread_create(kapmd, NULL, "kapmd");
  540. if (IS_ERR(kapmd_tsk)) {
  541. ret = PTR_ERR(kapmd_tsk);
  542. kapmd_tsk = NULL;
  543. goto out;
  544. }
  545. wake_up_process(kapmd_tsk);
  546. #ifdef CONFIG_PROC_FS
  547. proc_create_single("apm", 0, NULL, proc_apm_show);
  548. #endif
  549. ret = misc_register(&apm_device);
  550. if (ret)
  551. goto out_stop;
  552. ret = register_pm_notifier(&apm_notif_block);
  553. if (ret)
  554. goto out_unregister;
  555. return 0;
  556. out_unregister:
  557. misc_deregister(&apm_device);
  558. out_stop:
  559. remove_proc_entry("apm", NULL);
  560. kthread_stop(kapmd_tsk);
  561. out:
  562. return ret;
  563. }
  564. static void __exit apm_exit(void)
  565. {
  566. unregister_pm_notifier(&apm_notif_block);
  567. misc_deregister(&apm_device);
  568. remove_proc_entry("apm", NULL);
  569. kthread_stop(kapmd_tsk);
  570. }
  571. module_init(apm_init);
  572. module_exit(apm_exit);
  573. MODULE_AUTHOR("Stephen Rothwell");
  574. MODULE_DESCRIPTION("Advanced Power Management");
  575. MODULE_LICENSE("GPL");
  576. #ifndef MODULE
  577. static int __init apm_setup(char *str)
  578. {
  579. while ((str != NULL) && (*str != '\0')) {
  580. if (strncmp(str, "off", 3) == 0)
  581. apm_disabled = 1;
  582. if (strncmp(str, "on", 2) == 0)
  583. apm_disabled = 0;
  584. str = strchr(str, ',');
  585. if (str != NULL)
  586. str += strspn(str, ", \t");
  587. }
  588. return 1;
  589. }
  590. __setup("apm=", apm_setup);
  591. #endif
  592. /**
  593. * apm_queue_event - queue an APM event for kapmd
  594. * @event: APM event
  595. *
  596. * Queue an APM event for kapmd to process and ultimately take the
  597. * appropriate action. Only a subset of events are handled:
  598. * %APM_LOW_BATTERY
  599. * %APM_POWER_STATUS_CHANGE
  600. * %APM_USER_SUSPEND
  601. * %APM_SYS_SUSPEND
  602. * %APM_CRITICAL_SUSPEND
  603. */
  604. void apm_queue_event(apm_event_t event)
  605. {
  606. unsigned long flags;
  607. spin_lock_irqsave(&kapmd_queue_lock, flags);
  608. queue_add_event(&kapmd_queue, event);
  609. spin_unlock_irqrestore(&kapmd_queue_lock, flags);
  610. wake_up_interruptible(&kapmd_wait);
  611. }
  612. EXPORT_SYMBOL(apm_queue_event);