2019-08-25 02:49:16 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
2007-07-15 23:38:52 -07:00
|
|
|
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 15:20:36 -07:00
|
|
|
*/
|
|
|
|
|
2007-07-15 23:38:52 -07:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/irqreturn.h>
|
|
|
|
#include <asm/irq.h>
|
2012-10-07 19:27:32 -07:00
|
|
|
#include <irq_kern.h>
|
|
|
|
#include <os.h>
|
2023-08-08 11:15:24 -07:00
|
|
|
#include "xterm.h"
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
struct xterm_wait {
|
|
|
|
struct completion ready;
|
|
|
|
int fd;
|
|
|
|
int pid;
|
|
|
|
int new_fd;
|
|
|
|
};
|
|
|
|
|
2006-10-08 14:49:34 -07:00
|
|
|
static irqreturn_t xterm_interrupt(int irq, void *data)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct xterm_wait *xterm = data;
|
2024-07-02 10:21:19 -07:00
|
|
|
int fd = -1, n_fds = 1;
|
|
|
|
ssize_t ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2024-07-02 10:21:19 -07:00
|
|
|
ret = os_rcv_fd_msg(xterm->fd, &fd, n_fds,
|
|
|
|
&xterm->pid, sizeof(xterm->pid));
|
|
|
|
if (ret == -EAGAIN)
|
2007-07-15 23:38:52 -07:00
|
|
|
return IRQ_NONE;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2024-07-02 10:21:19 -07:00
|
|
|
if (ret < 0)
|
|
|
|
fd = ret;
|
|
|
|
else if (ret != sizeof(xterm->pid))
|
|
|
|
fd = -EMSGSIZE;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
xterm->new_fd = fd;
|
|
|
|
complete(&xterm->ready);
|
2007-07-15 23:38:52 -07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int xterm_fd(int socket, int *pid_out)
|
|
|
|
{
|
|
|
|
struct xterm_wait *data;
|
|
|
|
int err, ret;
|
|
|
|
|
|
|
|
data = kmalloc(sizeof(*data), GFP_KERNEL);
|
2007-07-15 23:38:52 -07:00
|
|
|
if (data == NULL) {
|
2005-04-16 15:20:36 -07:00
|
|
|
printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait\n");
|
2007-07-15 23:38:52 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is a locked semaphore... */
|
2007-07-15 23:38:52 -07:00
|
|
|
*data = ((struct xterm_wait) { .fd = socket,
|
|
|
|
.pid = -1,
|
|
|
|
.new_fd = -1 });
|
2005-04-16 15:20:36 -07:00
|
|
|
init_completion(&data->ready);
|
|
|
|
|
2007-07-15 23:38:52 -07:00
|
|
|
err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt,
|
2012-07-17 11:18:23 -07:00
|
|
|
IRQF_SHARED, "xterm", data);
|
2020-12-02 04:59:50 -07:00
|
|
|
if (err < 0) {
|
2005-04-16 15:20:36 -07: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);
|
|
|
|
|
2012-04-17 13:37:13 -07:00
|
|
|
um_free_irq(XTERM_IRQ, data);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
ret = data->new_fd;
|
|
|
|
*pid_out = data->pid;
|
|
|
|
out:
|
|
|
|
kfree(data);
|
|
|
|
|
2007-07-15 23:38:52 -07:00
|
|
|
return ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|