diff --git a/common/console.c b/common/console.c index aa1e055..3868bfa 100644 --- a/common/console.c +++ b/common/console.c @@ -34,8 +34,10 @@ #include #include #include +#include -static struct console_device *first_console = NULL; +LIST_HEAD(console_list); +EXPORT_SYMBOL(console_list); #define CONSOLE_UNINITIALIZED 0 #define CONSOLE_INIT_EARLY 1 @@ -95,7 +97,6 @@ int console_register(struct console_device *newcdev) { - struct console_device *cdev = first_console; struct device_d *dev = newcdev->dev; if (newcdev->setbrg) { @@ -118,33 +119,33 @@ #ifdef CONFIG_CONSOLE_ACTIVATE_ALL console_std_set(dev, &newcdev->active_param, "ioe"); #endif - if (!first_console) { #ifdef CONFIG_CONSOLE_ACTIVATE_FIRST + if (list_empty(&console_list)) console_std_set(dev, &newcdev->active_param, "ioe"); #endif - first_console = newcdev; - return 0; - } - while (1) { - if (!cdev->next) { - cdev->next = newcdev; - return 0; - } - cdev = cdev->next; - } + list_add_tail(&newcdev->list, &console_list); + + return 0; } EXPORT_SYMBOL(console_register); int getc_raw(void) { - struct console_device *cdev = NULL; + struct console_device *cdev; + int active = 0; + while (1) { - if (!cdev) - cdev = first_console; - if (cdev->f_active & CONSOLE_STDIN && cdev->tstc(cdev)) - return cdev->getc(cdev); - cdev = cdev->next; + for_each_console(cdev) { + if (!(cdev->f_active & CONSOLE_STDIN)) + continue; + active = 1; + if (cdev->tstc(cdev)) + return cdev->getc(cdev); + } + if (!active) + /* no active console found. bail out */ + return -1; } } @@ -191,12 +192,13 @@ int tstc(void) { - struct console_device *cdev = first_console; + struct console_device *cdev; - while (cdev) { - if (cdev->f_active & CONSOLE_STDIN && cdev->tstc(cdev)) + for_each_console(cdev) { + if (!(cdev->f_active & CONSOLE_STDIN)) + continue; + if (cdev->tstc(cdev)) return 1; - cdev = cdev->next; } return 0; @@ -207,7 +209,7 @@ void console_putc(unsigned int ch, char c) { - struct console_device *cdev = first_console; + struct console_device *cdev; int init = INITDATA(initialized); switch (init) { @@ -221,13 +223,12 @@ #endif case CONSOLE_INIT_FULL: - while (cdev) { + for_each_console(cdev) { if (cdev->f_active & ch) { cdev->putc(cdev, c); if (c == '\n') cdev->putc(cdev, '\r'); } - cdev = cdev->next; } return; default: @@ -241,7 +242,7 @@ int fputc(int fd, char c) { - if(!first_console) { + if(list_empty(&console_list)) { if(!fd) console_putc(0, c); return 0; diff --git a/include/console.h b/include/console.h index ce3855e..aa2c498 100644 --- a/include/console.h +++ b/include/console.h @@ -25,6 +25,7 @@ #define _CONSOLE_H_ #include +#include #define CONSOLE_STDIN (1 << 0) #define CONSOLE_STDOUT (1 << 1) @@ -38,7 +39,7 @@ int (*getc)(struct console_device *cdev); int (*setbrg)(struct console_device *cdev, int baudrate); - struct console_device *next; + struct list_head list; unsigned char f_caps; unsigned char f_active; @@ -52,6 +53,9 @@ int console_register(struct console_device *cdev); +extern struct list_head console_list; +#define for_each_console(console) list_for_each_entry(console, &console_list, list) + #define CFG_PBSIZE (CONFIG_CBSIZE+sizeof(CONFIG_PROMPT)+16) void early_console_putc(void *base, char c);