[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / um / drivers / fd.c
blobf0b888f66e0561ad3f73af964428f0d42c96e674
1 /*
2 * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <termios.h>
10 #include <errno.h>
11 #include "user.h"
12 #include "user_util.h"
13 #include "chan_user.h"
15 struct fd_chan {
16 int fd;
17 int raw;
18 struct termios tt;
19 char str[sizeof("1234567890\0")];
22 static void *fd_init(char *str, int device, struct chan_opts *opts)
24 struct fd_chan *data;
25 char *end;
26 int n;
28 if(*str != ':'){
29 printk("fd_init : channel type 'fd' must specify a file "
30 "descriptor\n");
31 return(NULL);
33 str++;
34 n = strtoul(str, &end, 0);
35 if((*end != '\0') || (end == str)){
36 printk("fd_init : couldn't parse file descriptor '%s'\n", str);
37 return(NULL);
39 data = um_kmalloc(sizeof(*data));
40 if(data == NULL) return(NULL);
41 *data = ((struct fd_chan) { .fd = n,
42 .raw = opts->raw });
43 return(data);
46 static int fd_open(int input, int output, int primary, void *d, char **dev_out)
48 struct fd_chan *data = d;
49 int err;
51 if(data->raw && isatty(data->fd)){
52 CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
53 if(err)
54 return(err);
56 err = raw(data->fd);
57 if(err)
58 return(err);
60 sprintf(data->str, "%d", data->fd);
61 *dev_out = data->str;
62 return(data->fd);
65 static void fd_close(int fd, void *d)
67 struct fd_chan *data = d;
68 int err;
70 if(data->raw && isatty(fd)){
71 CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
72 if(err)
73 printk("Failed to restore terminal state - "
74 "errno = %d\n", -err);
75 data->raw = 0;
79 static int fd_console_write(int fd, const char *buf, int n, void *d)
81 struct fd_chan *data = d;
83 return(generic_console_write(fd, buf, n, &data->tt));
86 struct chan_ops fd_ops = {
87 .type = "fd",
88 .init = fd_init,
89 .open = fd_open,
90 .close = fd_close,
91 .read = generic_read,
92 .write = generic_write,
93 .console_write = fd_console_write,
94 .window_size = generic_window_size,
95 .free = generic_free,
96 .winch = 1,
100 * Overrides for Emacs so that we follow Linus's tabbing style.
101 * Emacs will notice this stuff at the end of the file and automatically
102 * adjust the settings for this buffer only. This must remain at the end
103 * of the file.
104 * ---------------------------------------------------------------------------
105 * Local variables:
106 * c-file-style: "linux"
107 * End: