2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2007-07-16 00:38:52 -06:00
|
|
|
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 16:20:36 -06:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
2007-07-16 00:38:52 -06:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/irqreturn.h>
|
|
|
|
#include <asm/irq.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "irq_kern.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
struct xterm_wait {
|
|
|
|
struct completion ready;
|
|
|
|
int fd;
|
|
|
|
int pid;
|
|
|
|
int new_fd;
|
|
|
|
};
|
|
|
|
|
2006-10-08 15:49:34 -06:00
|
|
|
static irqreturn_t xterm_interrupt(int irq, void *data)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct xterm_wait *xterm = data;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = os_rcv_fd(xterm->fd, &xterm->pid);
|
2007-07-16 00:38:52 -06:00
|
|
|
if (fd == -EAGAIN)
|
|
|
|
return IRQ_NONE;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
xterm->new_fd = fd;
|
|
|
|
complete(&xterm->ready);
|
2007-07-16 00:38:52 -06:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int xterm_fd(int socket, int *pid_out)
|
|
|
|
{
|
|
|
|
struct xterm_wait *data;
|
|
|
|
int err, ret;
|
|
|
|
|
|
|
|
data = kmalloc(sizeof(*data), GFP_KERNEL);
|
2007-07-16 00:38:52 -06:00
|
|
|
if (data == NULL) {
|
2005-04-16 16:20:36 -06:00
|
|
|
printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait\n");
|
2007-07-16 00:38:52 -06:00
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is a locked semaphore... */
|
2007-07-16 00:38:52 -06:00
|
|
|
*data = ((struct xterm_wait) { .fd = socket,
|
|
|
|
.pid = -1,
|
|
|
|
.new_fd = -1 });
|
2005-04-16 16:20:36 -06:00
|
|
|
init_completion(&data->ready);
|
|
|
|
|
2007-07-16 00:38:52 -06:00
|
|
|
err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt,
|
2006-07-01 20:29:27 -06:00
|
|
|
IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
|
2005-04-16 16:20:36 -06:00
|
|
|
"xterm", data);
|
2007-07-16 00:38:52 -06:00
|
|
|
if (err) {
|
2005-04-16 16:20:36 -06:00
|
|
|
printk(KERN_ERR "xterm_fd : failed to get IRQ for xterm, "
|
|
|
|
"err = %d\n", err);
|
|
|
|
ret = err;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ... so here we wait for an xterm interrupt.
|
|
|
|
*
|
|
|
|
* XXX Note, if the xterm doesn't work for some reason (eg. DISPLAY
|
|
|
|
* isn't set) this will hang... */
|
|
|
|
wait_for_completion(&data->ready);
|
|
|
|
|
|
|
|
free_irq(XTERM_IRQ, data);
|
|
|
|
|
|
|
|
ret = data->new_fd;
|
|
|
|
*pid_out = data->pid;
|
|
|
|
out:
|
|
|
|
kfree(data);
|
|
|
|
|
2007-07-16 00:38:52 -06:00
|
|
|
return ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|