apm-emulation.c 17 KB

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