Blame view

arch/um/drivers/xterm_kern.c 1.54 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /* 
63920f471   Jeff Dike   uml: xterm driver...
2
   * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
   * Licensed under the GPL
   */
63920f471   Jeff Dike   uml: xterm driver...
5
6
7
8
  #include <linux/slab.h>
  #include <linux/completion.h>
  #include <linux/irqreturn.h>
  #include <asm/irq.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
  #include "irq_kern.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  #include "os.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
15
16
17
  
  struct xterm_wait {
  	struct completion ready;
  	int fd;
  	int pid;
  	int new_fd;
  };
7bea96fd2   Al Viro   [PATCH] uml pt_re...
18
  static irqreturn_t xterm_interrupt(int irq, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
  {
  	struct xterm_wait *xterm = data;
  	int fd;
  
  	fd = os_rcv_fd(xterm->fd, &xterm->pid);
63920f471   Jeff Dike   uml: xterm driver...
24
25
  	if (fd == -EAGAIN)
  		return IRQ_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
  
  	xterm->new_fd = fd;
  	complete(&xterm->ready);
63920f471   Jeff Dike   uml: xterm driver...
29
30
  
  	return IRQ_HANDLED;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
36
37
38
  }
  
  int xterm_fd(int socket, int *pid_out)
  {
  	struct xterm_wait *data;
  	int err, ret;
  
  	data = kmalloc(sizeof(*data), GFP_KERNEL);
63920f471   Jeff Dike   uml: xterm driver...
39
  	if (data == NULL) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
  		printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait
  ");
63920f471   Jeff Dike   uml: xterm driver...
42
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
44
45
  	}
  
  	/* This is a locked semaphore... */
63920f471   Jeff Dike   uml: xterm driver...
46
47
48
  	*data = ((struct xterm_wait) { .fd 		= socket,
  				       .pid 		= -1,
  				       .new_fd	 	= -1 });
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  	init_completion(&data->ready);
63920f471   Jeff Dike   uml: xterm driver...
50
  	err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt,
bd6aa6502   Thomas Gleixner   [PATCH] irq-flags...
51
  			     IRQF_DISABLED | IRQF_SHARED | IRQF_SAMPLE_RANDOM,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
  			     "xterm", data);
63920f471   Jeff Dike   uml: xterm driver...
53
  	if (err) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
56
57
58
59
60
61
62
63
64
65
  		printk(KERN_ERR "xterm_fd : failed to get IRQ for xterm, "
  		       "err = %d
  ",  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);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
71
  	free_irq(XTERM_IRQ, data);
  
  	ret = data->new_fd;
  	*pid_out = data->pid;
   out:
  	kfree(data);
63920f471   Jeff Dike   uml: xterm driver...
72
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  }