ALSA: virtuoso: rename AC97 callback function
[zen-stable.git] / arch / um / os-Linux / irq.c
blob0348b975e81cb3a5a4d067a8f3b39c5d2db1fff5
1 /*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <stdlib.h>
7 #include <errno.h>
8 #include <poll.h>
9 #include <signal.h>
10 #include <string.h>
11 #include "irq_user.h"
12 #include "kern_constants.h"
13 #include "os.h"
14 #include "process.h"
15 #include "um_malloc.h"
16 #include "user.h"
19 * Locked by irq_lock in arch/um/kernel/irq.c. Changed by os_create_pollfd
20 * and os_free_irq_by_cb, which are called under irq_lock.
22 static struct pollfd *pollfds = NULL;
23 static int pollfds_num = 0;
24 static int pollfds_size = 0;
26 int os_waiting_for_events(struct irq_fd *active_fds)
28 struct irq_fd *irq_fd;
29 int i, n, err;
31 n = poll(pollfds, pollfds_num, 0);
32 if (n < 0) {
33 err = -errno;
34 if (errno != EINTR)
35 printk(UM_KERN_ERR "os_waiting_for_events:"
36 " poll returned %d, errno = %d\n", n, errno);
37 return err;
40 if (n == 0)
41 return 0;
43 irq_fd = active_fds;
45 for (i = 0; i < pollfds_num; i++) {
46 if (pollfds[i].revents != 0) {
47 irq_fd->current_events = pollfds[i].revents;
48 pollfds[i].fd = -1;
50 irq_fd = irq_fd->next;
52 return n;
55 int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
57 if (pollfds_num == pollfds_size) {
58 if (size_tmpfds <= pollfds_size * sizeof(pollfds[0])) {
59 /* return min size needed for new pollfds area */
60 return (pollfds_size + 1) * sizeof(pollfds[0]);
63 if (pollfds != NULL) {
64 memcpy(tmp_pfd, pollfds,
65 sizeof(pollfds[0]) * pollfds_size);
66 /* remove old pollfds */
67 kfree(pollfds);
69 pollfds = tmp_pfd;
70 pollfds_size++;
71 } else
72 kfree(tmp_pfd); /* remove not used tmp_pfd */
74 pollfds[pollfds_num] = ((struct pollfd) { .fd = fd,
75 .events = events,
76 .revents = 0 });
77 pollfds_num++;
79 return 0;
82 void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
83 struct irq_fd *active_fds, struct irq_fd ***last_irq_ptr2)
85 struct irq_fd **prev;
86 int i = 0;
88 prev = &active_fds;
89 while (*prev != NULL) {
90 if ((*test)(*prev, arg)) {
91 struct irq_fd *old_fd = *prev;
92 if ((pollfds[i].fd != -1) &&
93 (pollfds[i].fd != (*prev)->fd)) {
94 printk(UM_KERN_ERR "os_free_irq_by_cb - "
95 "mismatch between active_fds and "
96 "pollfds, fd %d vs %d\n",
97 (*prev)->fd, pollfds[i].fd);
98 goto out;
101 pollfds_num--;
104 * This moves the *whole* array after pollfds[i]
105 * (though it doesn't spot as such)!
107 memmove(&pollfds[i], &pollfds[i + 1],
108 (pollfds_num - i) * sizeof(pollfds[0]));
109 if (*last_irq_ptr2 == &old_fd->next)
110 *last_irq_ptr2 = prev;
112 *prev = (*prev)->next;
113 if (old_fd->type == IRQ_WRITE)
114 ignore_sigio_fd(old_fd->fd);
115 kfree(old_fd);
116 continue;
118 prev = &(*prev)->next;
119 i++;
121 out:
122 return;
125 int os_get_pollfd(int i)
127 return pollfds[i].fd;
130 void os_set_pollfd(int i, int fd)
132 pollfds[i].fd = fd;
135 void os_set_ioignore(void)
137 signal(SIGIO, SIG_IGN);