2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
13 #include <um_malloc.h>
16 * Locked by irq_lock in arch/um/kernel/irq.c. Changed by os_create_pollfd
17 * and os_free_irq_by_cb, which are called under irq_lock.
19 static struct pollfd
*pollfds
= NULL
;
20 static int pollfds_num
= 0;
21 static int pollfds_size
= 0;
23 int os_waiting_for_events(struct irq_fd
*active_fds
)
25 struct irq_fd
*irq_fd
;
28 n
= poll(pollfds
, pollfds_num
, 0);
32 printk(UM_KERN_ERR
"os_waiting_for_events:"
33 " poll returned %d, errno = %d\n", n
, errno
);
42 for (i
= 0; i
< pollfds_num
; i
++) {
43 if (pollfds
[i
].revents
!= 0) {
44 irq_fd
->current_events
= pollfds
[i
].revents
;
47 irq_fd
= irq_fd
->next
;
52 int os_create_pollfd(int fd
, int events
, void *tmp_pfd
, int size_tmpfds
)
54 if (pollfds_num
== pollfds_size
) {
55 if (size_tmpfds
<= pollfds_size
* sizeof(pollfds
[0])) {
56 /* return min size needed for new pollfds area */
57 return (pollfds_size
+ 1) * sizeof(pollfds
[0]);
60 if (pollfds
!= NULL
) {
61 memcpy(tmp_pfd
, pollfds
,
62 sizeof(pollfds
[0]) * pollfds_size
);
63 /* remove old pollfds */
69 kfree(tmp_pfd
); /* remove not used tmp_pfd */
71 pollfds
[pollfds_num
] = ((struct pollfd
) { .fd
= fd
,
79 void os_free_irq_by_cb(int (*test
)(struct irq_fd
*, void *), void *arg
,
80 struct irq_fd
*active_fds
, struct irq_fd
***last_irq_ptr2
)
86 while (*prev
!= NULL
) {
87 if ((*test
)(*prev
, arg
)) {
88 struct irq_fd
*old_fd
= *prev
;
89 if ((pollfds
[i
].fd
!= -1) &&
90 (pollfds
[i
].fd
!= (*prev
)->fd
)) {
91 printk(UM_KERN_ERR
"os_free_irq_by_cb - "
92 "mismatch between active_fds and "
93 "pollfds, fd %d vs %d\n",
94 (*prev
)->fd
, pollfds
[i
].fd
);
101 * This moves the *whole* array after pollfds[i]
102 * (though it doesn't spot as such)!
104 memmove(&pollfds
[i
], &pollfds
[i
+ 1],
105 (pollfds_num
- i
) * sizeof(pollfds
[0]));
106 if (*last_irq_ptr2
== &old_fd
->next
)
107 *last_irq_ptr2
= prev
;
109 *prev
= (*prev
)->next
;
110 if (old_fd
->type
== IRQ_WRITE
)
111 ignore_sigio_fd(old_fd
->fd
);
115 prev
= &(*prev
)->next
;
122 int os_get_pollfd(int i
)
124 return pollfds
[i
].fd
;
127 void os_set_pollfd(int i
, int fd
)
132 void os_set_ioignore(void)
134 signal(SIGIO
, SIG_IGN
);