Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / um / drivers / xterm_kern.c
blob7917b9d1cec8fa0fde9d4107dd5603862059ff05
1 /*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include "linux/errno.h"
7 #include "linux/slab.h"
8 #include "linux/signal.h"
9 #include "linux/interrupt.h"
10 #include "asm/semaphore.h"
11 #include "asm/irq.h"
12 #include "irq_user.h"
13 #include "irq_kern.h"
14 #include "kern_util.h"
15 #include "os.h"
16 #include "xterm.h"
18 struct xterm_wait {
19 struct completion ready;
20 int fd;
21 int pid;
22 int new_fd;
25 static irqreturn_t xterm_interrupt(int irq, void *data, struct pt_regs *regs)
27 struct xterm_wait *xterm = data;
28 int fd;
30 fd = os_rcv_fd(xterm->fd, &xterm->pid);
31 if(fd == -EAGAIN)
32 return(IRQ_NONE);
34 xterm->new_fd = fd;
35 complete(&xterm->ready);
36 return(IRQ_HANDLED);
39 int xterm_fd(int socket, int *pid_out)
41 struct xterm_wait *data;
42 int err, ret;
44 data = kmalloc(sizeof(*data), GFP_KERNEL);
45 if(data == NULL){
46 printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait\n");
47 return(-ENOMEM);
50 /* This is a locked semaphore... */
51 *data = ((struct xterm_wait)
52 { .fd = socket,
53 .pid = -1,
54 .new_fd = -1 });
55 init_completion(&data->ready);
57 err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt,
58 SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
59 "xterm", data);
60 if (err){
61 printk(KERN_ERR "xterm_fd : failed to get IRQ for xterm, "
62 "err = %d\n", err);
63 ret = err;
64 goto out;
67 /* ... so here we wait for an xterm interrupt.
69 * XXX Note, if the xterm doesn't work for some reason (eg. DISPLAY
70 * isn't set) this will hang... */
71 wait_for_completion(&data->ready);
73 free_irq_by_irq_and_dev(XTERM_IRQ, data);
74 free_irq(XTERM_IRQ, data);
76 ret = data->new_fd;
77 *pid_out = data->pid;
78 out:
79 kfree(data);
81 return(ret);
85 * Overrides for Emacs so that we follow Linus's tabbing style.
86 * Emacs will notice this stuff at the end of the file and automatically
87 * adjust the settings for this buffer only. This must remain at the end
88 * of the file.
89 * ---------------------------------------------------------------------------
90 * Local variables:
91 * c-file-style: "linux"
92 * End: