apm-emulation.c 18 KB

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