]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/um/drivers/tty.c
Merge tag 'media/v4.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[mirror_ubuntu-zesty-kernel.git] / arch / um / drivers / tty.c
CommitLineData
108ffa8c 1/*
e99525f9 2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
1da177e4
LT
3 * Licensed under the GPL
4 */
5
1da177e4 6#include <errno.h>
e99525f9
JD
7#include <fcntl.h>
8#include <termios.h>
1da177e4 9#include "chan_user.h"
37185b33
AV
10#include <os.h>
11#include <um_malloc.h>
1da177e4
LT
12
13struct tty_chan {
14 char *dev;
15 int raw;
16 struct termios tt;
17};
18
5e7672ec 19static void *tty_chan_init(char *str, int device, const struct chan_opts *opts)
1da177e4
LT
20{
21 struct tty_chan *data;
22
e99525f9
JD
23 if (*str != ':') {
24 printk(UM_KERN_ERR "tty_init : channel type 'tty' must specify "
1da177e4 25 "a device\n");
108ffa8c 26 return NULL;
1da177e4
LT
27 }
28 str++;
29
43f5b308 30 data = uml_kmalloc(sizeof(*data), UM_GFP_KERNEL);
e99525f9 31 if (data == NULL)
108ffa8c 32 return NULL;
1da177e4
LT
33 *data = ((struct tty_chan) { .dev = str,
34 .raw = opts->raw });
108ffa8c
JD
35
36 return data;
1da177e4
LT
37}
38
39static int tty_open(int input, int output, int primary, void *d,
40 char **dev_out)
41{
42 struct tty_chan *data = d;
e99525f9
JD
43 int fd, err, mode = 0;
44
45 if (input && output)
46 mode = O_RDWR;
47 else if (input)
48 mode = O_RDONLY;
49 else if (output)
50 mode = O_WRONLY;
1da177e4 51
e99525f9
JD
52 fd = open(data->dev, mode);
53 if (fd < 0)
54 return -errno;
108ffa8c 55
e99525f9 56 if (data->raw) {
1da177e4 57 CATCH_EINTR(err = tcgetattr(fd, &data->tt));
e99525f9 58 if (err)
108ffa8c 59 return err;
1da177e4
LT
60
61 err = raw(fd);
e99525f9 62 if (err)
108ffa8c 63 return err;
1da177e4
LT
64 }
65
66 *dev_out = data->dev;
108ffa8c 67 return fd;
1da177e4
LT
68}
69
5e7672ec 70const struct chan_ops tty_ops = {
1da177e4
LT
71 .type = "tty",
72 .init = tty_chan_init,
73 .open = tty_open,
74 .close = generic_close,
75 .read = generic_read,
76 .write = generic_write,
fd9bc53b 77 .console_write = generic_console_write,
1da177e4
LT
78 .window_size = generic_window_size,
79 .free = generic_free,
80 .winch = 0,
81};