X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=arch%2Fum%2Fdrivers%2Fchan_kern.c;h=6e51424745ab3453bd839a24e8dd59fbfa37cfdf;hb=88ed86fee6651033de9b7038dac7869a9f19775a;hp=368d3e97dfd9a85a918c5455fb63390f3f0ab197;hpb=40b42f1ebf653cd72c32eb1a1a0b9fea2dfbfd7d;p=linux-2.6-omap-h63xx.git diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c index 368d3e97dfd..6e51424745a 100644 --- a/arch/um/drivers/chan_kern.c +++ b/arch/um/drivers/chan_kern.c @@ -1,28 +1,19 @@ /* - * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) * Licensed under the GPL */ -#include -#include -#include #include #include -#include #include -#include #include "chan_kern.h" -#include "kern.h" -#include "irq_user.h" -#include "sigio.h" -#include "line.h" #include "os.h" #ifdef CONFIG_NOCONFIG_CHAN static void *not_configged_init(char *str, int device, const struct chan_opts *opts) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); return NULL; } @@ -30,34 +21,34 @@ static void *not_configged_init(char *str, int device, static int not_configged_open(int input, int output, int primary, void *data, char **dev_out) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); return -ENODEV; } static void not_configged_close(int fd, void *data) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); } static int not_configged_read(int fd, char *c_out, void *data) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); return -EIO; } static int not_configged_write(int fd, const char *buf, int len, void *data) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); return -EIO; } static int not_configged_console_write(int fd, const char *buf, int len) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); return -EIO; } @@ -65,14 +56,14 @@ static int not_configged_console_write(int fd, const char *buf, int len) static int not_configged_window_size(int fd, void *data, unsigned short *rows, unsigned short *cols) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); return -ENODEV; } static void not_configged_free(void *data) { - printk("Using a channel type which is configured out of " + printk(KERN_ERR "Using a channel type which is configured out of " "UML\n"); } @@ -89,64 +80,17 @@ static const struct chan_ops not_configged_ops = { }; #endif /* CONFIG_NOCONFIG_CHAN */ -void generic_close(int fd, void *unused) -{ - os_close_file(fd); -} - -int generic_read(int fd, char *c_out, void *unused) -{ - int n; - - n = os_read_file(fd, c_out, sizeof(*c_out)); - - if(n == -EAGAIN) - return 0; - else if(n == 0) - return -EIO; - return n; -} - -/* XXX Trivial wrapper around os_write_file */ - -int generic_write(int fd, const char *buf, int n, void *unused) -{ - return os_write_file(fd, buf, n); -} - -int generic_window_size(int fd, void *unused, unsigned short *rows_out, - unsigned short *cols_out) -{ - int rows, cols; - int ret; - - ret = os_window_size(fd, &rows, &cols); - if(ret < 0) - return ret; - - ret = ((*rows_out != rows) || (*cols_out != cols)); - - *rows_out = rows; - *cols_out = cols; - - return ret; -} - -void generic_free(void *data) -{ - kfree(data); -} - static void tty_receive_char(struct tty_struct *tty, char ch) { - if(tty == NULL) return; + if (tty == NULL) + return; - if(I_IXON(tty) && !I_IXOFF(tty) && !tty->raw) { - if(ch == STOP_CHAR(tty)){ + if (I_IXON(tty) && !I_IXOFF(tty) && !tty->raw) { + if (ch == STOP_CHAR(tty)) { stop_tty(tty); return; } - else if(ch == START_CHAR(tty)){ + else if (ch == START_CHAR(tty)) { start_tty(tty); return; } @@ -157,33 +101,40 @@ static void tty_receive_char(struct tty_struct *tty, char ch) static int open_one_chan(struct chan *chan) { - int fd; + int fd, err; - if(chan->opened) + if (chan->opened) return 0; - if(chan->ops->open == NULL) + if (chan->ops->open == NULL) fd = 0; else fd = (*chan->ops->open)(chan->input, chan->output, chan->primary, chan->data, &chan->dev); - if(fd < 0) + if (fd < 0) return fd; + + err = os_set_fd_block(fd, 0); + if (err) { + (*chan->ops->close)(fd, chan->data); + return err; + } + chan->fd = fd; chan->opened = 1; return 0; } -int open_chan(struct list_head *chans) +static int open_chan(struct list_head *chans) { struct list_head *ele; struct chan *chan; int ret, err = 0; - list_for_each(ele, chans){ + list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); ret = open_one_chan(chan); - if(chan->primary) + if (chan->primary) err = ret; } return err; @@ -194,9 +145,9 @@ void chan_enable_winch(struct list_head *chans, struct tty_struct *tty) struct list_head *ele; struct chan *chan; - list_for_each(ele, chans){ + list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); - if(chan->primary && chan->output && chan->ops->winch){ + if (chan->primary && chan->output && chan->ops->winch) { register_winch(chan->fd, tty); return; } @@ -209,7 +160,7 @@ int enable_chan(struct line *line) struct chan *chan; int err; - list_for_each(ele, &line->chan_list){ + list_for_each(ele, &line->chan_list) { chan = list_entry(ele, struct chan, list); err = open_one_chan(chan); if (err) { @@ -219,7 +170,7 @@ int enable_chan(struct line *line) continue; } - if(chan->enabled) + if (chan->enabled) continue; err = line_setup_irq(chan->fd, chan->input, chan->output, line, chan); @@ -256,12 +207,12 @@ void free_irqs(void) list_splice_init(&irqs_to_free, &list); spin_unlock_irqrestore(&irqs_to_free_lock, flags); - list_for_each(ele, &list){ + list_for_each(ele, &list) { chan = list_entry(ele, struct chan, free_list); - if(chan->input) + if (chan->input) free_irq(chan->line->driver->read_irq, chan); - if(chan->output) + if (chan->output) free_irq(chan->line->driver->write_irq, chan); chan->enabled = 0; } @@ -271,22 +222,22 @@ static void close_one_chan(struct chan *chan, int delay_free_irq) { unsigned long flags; - if(!chan->opened) + if (!chan->opened) return; - if(delay_free_irq){ + if (delay_free_irq) { spin_lock_irqsave(&irqs_to_free_lock, flags); list_add(&chan->free_list, &irqs_to_free); spin_unlock_irqrestore(&irqs_to_free_lock, flags); } else { - if(chan->input) + if (chan->input) free_irq(chan->line->driver->read_irq, chan); - if(chan->output) + if (chan->output) free_irq(chan->line->driver->write_irq, chan); chan->enabled = 0; } - if(chan->ops->close != NULL) + if (chan->ops->close != NULL) (*chan->ops->close)(chan->fd, chan->data); chan->opened = 0; @@ -315,7 +266,7 @@ void deactivate_chan(struct list_head *chans, int irq) list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); - if(chan->enabled && chan->input) + if (chan->enabled && chan->input) deactivate_fd(chan->fd, irq); } } @@ -328,7 +279,7 @@ void reactivate_chan(struct list_head *chans, int irq) list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); - if(chan->enabled && chan->input) + if (chan->enabled && chan->input) reactivate_fd(chan->fd, irq); } } @@ -340,10 +291,14 @@ int write_chan(struct list_head *chans, const char *buf, int len, struct chan *chan = NULL; int n, ret = 0; + if (len == 0) + return 0; + list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); if (!chan->output || (chan->ops->write == NULL)) continue; + n = chan->ops->write(chan->fd, buf, len, chan->data); if (chan->primary) { ret = n; @@ -360,12 +315,14 @@ int console_write_chan(struct list_head *chans, const char *buf, int len) struct chan *chan; int n, ret = 0; - list_for_each(ele, chans){ + list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); - if(!chan->output || (chan->ops->console_write == NULL)) + if (!chan->output || (chan->ops->console_write == NULL)) continue; + n = chan->ops->console_write(chan->fd, buf, len); - if(chan->primary) ret = n; + if (chan->primary) + ret = n; } return ret; } @@ -375,10 +332,11 @@ int console_open_chan(struct line *line, struct console *co) int err; err = open_chan(&line->chan_list); - if(err) + if (err) return err; - printk("Console initialized on /dev/%s%d\n", co->name, co->index); + printk(KERN_INFO "Console initialized on /dev/%s%d\n", co->name, + co->index); return 0; } @@ -388,10 +346,10 @@ int chan_window_size(struct list_head *chans, unsigned short *rows_out, struct list_head *ele; struct chan *chan; - list_for_each(ele, chans){ + list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); - if(chan->primary){ - if(chan->ops->window_size == NULL) + if (chan->primary) { + if (chan->ops->window_size == NULL) return 0; return chan->ops->window_size(chan->fd, chan->data, rows_out, cols_out); @@ -406,10 +364,11 @@ static void free_one_chan(struct chan *chan, int delay_free_irq) close_one_chan(chan, delay_free_irq); - if(chan->ops->free != NULL) + if (chan->ops->free != NULL) (*chan->ops->free)(chan->data); - if(chan->primary && chan->output) ignore_sigio_fd(chan->fd); + if (chan->primary && chan->output) + ignore_sigio_fd(chan->fd); kfree(chan); } @@ -418,7 +377,7 @@ static void free_chan(struct list_head *chans, int delay_free_irq) struct list_head *ele, *next; struct chan *chan; - list_for_each_safe(ele, next, chans){ + list_for_each_safe(ele, next, chans) { chan = list_entry(ele, struct chan, list); free_one_chan(chan, delay_free_irq); } @@ -429,14 +388,14 @@ static int one_chan_config_string(struct chan *chan, char *str, int size, { int n = 0; - if(chan == NULL){ + if (chan == NULL) { CONFIG_CHUNK(str, size, n, "none", 1); return n; } CONFIG_CHUNK(str, size, n, chan->ops->type, 0); - if(chan->dev == NULL){ + if (chan->dev == NULL) { CONFIG_CHUNK(str, size, n, "", 1); return n; } @@ -456,7 +415,7 @@ static int chan_pair_config_string(struct chan *in, struct chan *out, str += n; size -= n; - if(in == out){ + if (in == out) { CONFIG_CHUNK(str, size, n, "", 1); return n; } @@ -476,13 +435,13 @@ int chan_config_string(struct list_head *chans, char *str, int size, struct list_head *ele; struct chan *chan, *in = NULL, *out = NULL; - list_for_each(ele, chans){ + list_for_each(ele, chans) { chan = list_entry(ele, struct chan, list); - if(!chan->primary) + if (!chan->primary) continue; - if(chan->input) + if (chan->input) in = chan; - if(chan->output) + if (chan->output) out = chan; } @@ -541,27 +500,27 @@ static struct chan *parse_chan(struct line *line, char *str, int device, ops = NULL; data = NULL; - for(i = 0; i < ARRAY_SIZE(chan_table); i++){ + for(i = 0; i < ARRAY_SIZE(chan_table); i++) { entry = &chan_table[i]; - if(!strncmp(str, entry->key, strlen(entry->key))){ + if (!strncmp(str, entry->key, strlen(entry->key))) { ops = entry->ops; str += strlen(entry->key); break; } } - if(ops == NULL){ + if (ops == NULL) { *error_out = "No match for configured backends"; return NULL; } data = (*ops->init)(str, device, opts); - if(data == NULL){ + if (data == NULL) { *error_out = "Configuration failed"; return NULL; } chan = kmalloc(sizeof(*chan), GFP_ATOMIC); - if(chan == NULL){ + if (chan == NULL) { *error_out = "Memory allocation failed"; return NULL; } @@ -587,26 +546,26 @@ int parse_chan_pair(char *str, struct line *line, int device, struct chan *new, *chan; char *in, *out; - if(!list_empty(chans)){ + if (!list_empty(chans)) { chan = list_entry(chans->next, struct chan, list); free_chan(chans, 0); INIT_LIST_HEAD(chans); } out = strchr(str, ','); - if(out != NULL){ + if (out != NULL) { in = str; *out = '\0'; out++; new = parse_chan(line, in, device, opts, error_out); - if(new == NULL) + if (new == NULL) return -1; new->input = 1; list_add(&new->list, chans); new = parse_chan(line, out, device, opts, error_out); - if(new == NULL) + if (new == NULL) return -1; list_add(&new->list, chans); @@ -614,7 +573,7 @@ int parse_chan_pair(char *str, struct line *line, int device, } else { new = parse_chan(line, str, device, opts, error_out); - if(new == NULL) + if (new == NULL) return -1; list_add(&new->list, chans); @@ -624,19 +583,6 @@ int parse_chan_pair(char *str, struct line *line, int device, return 0; } -int chan_out_fd(struct list_head *chans) -{ - struct list_head *ele; - struct chan *chan; - - list_for_each(ele, chans){ - chan = list_entry(ele, struct chan, list); - if(chan->primary && chan->output) - return chan->fd; - } - return -1; -} - void chan_interrupt(struct list_head *chans, struct delayed_work *task, struct tty_struct *tty, int irq) { @@ -645,23 +591,25 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task, int err; char c; - list_for_each_safe(ele, next, chans){ + list_for_each_safe(ele, next, chans) { chan = list_entry(ele, struct chan, list); - if(!chan->input || (chan->ops->read == NULL)) continue; + if (!chan->input || (chan->ops->read == NULL)) + continue; do { if (tty && !tty_buffer_request_room(tty, 1)) { schedule_delayed_work(task, 1); goto out; } err = chan->ops->read(chan->fd, &c, chan->data); - if(err > 0) + if (err > 0) tty_receive_char(tty, c); - } while(err > 0); + } while (err > 0); - if(err == 0) reactivate_fd(chan->fd, irq); - if(err == -EIO){ - if(chan->primary){ - if(tty != NULL) + if (err == 0) + reactivate_fd(chan->fd, irq); + if (err == -EIO) { + if (chan->primary) { + if (tty != NULL) tty_hangup(tty); close_chan(chans, 1); return; @@ -670,5 +618,6 @@ void chan_interrupt(struct list_head *chans, struct delayed_work *task, } } out: - if(tty) tty_flip_buffer_push(tty); + if (tty) + tty_flip_buffer_push(tty); }