Lines Matching refs:as

1158 static int queue_empty(struct apm_user *as)  in queue_empty()  argument
1160 return as->event_head == as->event_tail; in queue_empty()
1163 static apm_event_t get_queued_event(struct apm_user *as) in get_queued_event() argument
1165 if (++as->event_tail >= APM_MAX_EVENTS) in get_queued_event()
1166 as->event_tail = 0; in get_queued_event()
1167 return as->events[as->event_tail]; in get_queued_event()
1172 struct apm_user *as; in queue_event() local
1177 for (as = user_list; as != NULL; as = as->next) { in queue_event()
1178 if ((as == sender) || (!as->reader)) in queue_event()
1180 if (++as->event_head >= APM_MAX_EVENTS) in queue_event()
1181 as->event_head = 0; in queue_event()
1183 if (as->event_head == as->event_tail) { in queue_event()
1188 if (++as->event_tail >= APM_MAX_EVENTS) in queue_event()
1189 as->event_tail = 0; in queue_event()
1191 as->events[as->event_head] = event; in queue_event()
1192 if (!as->suser || !as->writer) in queue_event()
1197 as->suspends_pending++; in queue_event()
1203 as->standbys_pending++; in queue_event()
1233 struct apm_user *as; in suspend() local
1265 for (as = user_list; as != NULL; as = as->next) { in suspend()
1266 as->suspend_wait = 0; in suspend()
1267 as->suspend_result = err; in suspend()
1447 static int check_apm_user(struct apm_user *as, const char *func) in check_apm_user() argument
1449 if (as == NULL || as->magic != APM_BIOS_MAGIC) { in check_apm_user()
1458 struct apm_user *as; in do_read() local
1462 as = fp->private_data; in do_read()
1463 if (check_apm_user(as, "read")) in do_read()
1467 if ((queue_empty(as)) && (fp->f_flags & O_NONBLOCK)) in do_read()
1469 wait_event_interruptible(apm_waitqueue, !queue_empty(as)); in do_read()
1471 while ((i >= sizeof(event)) && !queue_empty(as)) { in do_read()
1472 event = get_queued_event(as); in do_read()
1481 as->suspends_read++; in do_read()
1486 as->standbys_read++; in do_read()
1501 struct apm_user *as; in do_poll() local
1503 as = fp->private_data; in do_poll()
1504 if (check_apm_user(as, "poll")) in do_poll()
1507 if (!queue_empty(as)) in do_poll()
1514 struct apm_user *as; in do_ioctl() local
1517 as = filp->private_data; in do_ioctl()
1518 if (check_apm_user(as, "ioctl")) in do_ioctl()
1520 if (!as->suser || !as->writer) in do_ioctl()
1525 if (as->standbys_read > 0) { in do_ioctl()
1526 as->standbys_read--; in do_ioctl()
1527 as->standbys_pending--; in do_ioctl()
1530 queue_event(APM_USER_STANDBY, as); in do_ioctl()
1537 if (as->suspends_read > 0) { in do_ioctl()
1538 as->suspends_read--; in do_ioctl()
1539 as->suspends_pending--; in do_ioctl()
1542 queue_event(APM_USER_SUSPEND, as); in do_ioctl()
1547 as->suspend_wait = 1; in do_ioctl()
1550 as->suspend_wait == 0); in do_ioctl()
1551 ret = as->suspend_result; in do_ioctl()
1562 struct apm_user *as; in do_release() local
1564 as = filp->private_data; in do_release()
1565 if (check_apm_user(as, "release")) in do_release()
1568 if (as->standbys_pending > 0) { in do_release()
1569 standbys_pending -= as->standbys_pending; in do_release()
1573 if (as->suspends_pending > 0) { in do_release()
1574 suspends_pending -= as->suspends_pending; in do_release()
1579 if (user_list == as) in do_release()
1580 user_list = as->next; in do_release()
1585 (as1 != NULL) && (as1->next != as); in do_release()
1591 as1->next = as->next; in do_release()
1594 kfree(as); in do_release()
1600 struct apm_user *as; in do_open() local
1602 as = kmalloc(sizeof(*as), GFP_KERNEL); in do_open()
1603 if (as == NULL) { in do_open()
1605 sizeof(*as)); in do_open()
1608 as->magic = APM_BIOS_MAGIC; in do_open()
1609 as->event_tail = as->event_head = 0; in do_open()
1610 as->suspends_pending = as->standbys_pending = 0; in do_open()
1611 as->suspends_read = as->standbys_read = 0; in do_open()
1619 as->suser = capable(CAP_SYS_ADMIN); in do_open()
1620 as->writer = (filp->f_mode & FMODE_WRITE) == FMODE_WRITE; in do_open()
1621 as->reader = (filp->f_mode & FMODE_READ) == FMODE_READ; in do_open()
1623 as->next = user_list; in do_open()
1624 user_list = as; in do_open()
1626 filp->private_data = as; in do_open()