From 69f698adcf43930a283f630395a1bb781962cfe6 Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Sat, 1 Nov 2008 19:53:34 +0100 Subject: ftrace: sysrq-z to dump the buffers Impact: add SysRq-z support to dump trace buffers Allows one to force an ftrace dump from sysrq Signed-off-by: Peter Zijlstra Acked-by: Steven Rostedt Signed-off-by: Ingo Molnar --- drivers/char/sysrq.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c index ce0d9da52a8..94966edfb44 100644 --- a/drivers/char/sysrq.c +++ b/drivers/char/sysrq.c @@ -274,6 +274,22 @@ static struct sysrq_key_op sysrq_showstate_blocked_op = { .enable_mask = SYSRQ_ENABLE_DUMP, }; +#ifdef CONFIG_TRACING +#include + +static void sysrq_ftrace_dump(int key, struct tty_struct *tty) +{ + ftrace_dump(); +} +static struct sysrq_key_op sysrq_ftrace_dump_op = { + .handler = sysrq_ftrace_dump, + .help_msg = "dumpZ-ftrace-buffer", + .action_msg = "Dump ftrace buffer", + .enable_mask = SYSRQ_ENABLE_DUMP, +}; +#else +#define sysrq_ftrace_dump_op (*(struct sysrq_key_op *)0) +#endif static void sysrq_handle_showmem(int key, struct tty_struct *tty) { @@ -406,7 +422,7 @@ static struct sysrq_key_op *sysrq_key_table[36] = { NULL, /* x */ /* y: May be registered on sparc64 for global register dump */ NULL, /* y */ - NULL /* z */ + &sysrq_ftrace_dump_op, /* z */ }; /* key2index calculation, -1 on invalid index */ -- cgit v1.2.3 From 971ddcf8ad3aa88e0daee6799925858e9f820cb4 Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Tue, 11 Nov 2008 09:44:07 +0000 Subject: [PATCH] nvram - CodingStyle Bring drivers/char/nvram.c in line with the Coding Style. Signed-off-by: Wim Van Sebroeck --- drivers/char/nvram.c | 126 +++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 74 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index 8054ee839b3..1a04f3df91e 100644 --- a/drivers/char/nvram.c +++ b/drivers/char/nvram.c @@ -46,7 +46,7 @@ /* select machine configuration */ #if defined(CONFIG_ATARI) # define MACH ATARI -#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and others?? */ +#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and ?? */ # define MACH PC #else # error Cannot build nvram driver for this machine configuration. @@ -107,9 +107,9 @@ #include #include #include +#include +#include -#include -#include #include static DEFINE_SPINLOCK(nvram_state_lock); @@ -123,7 +123,7 @@ static void mach_set_checksum(void); #ifdef CONFIG_PROC_FS static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, - off_t *begin, off_t offset, int size); + off_t *begin, off_t offset, int size); #endif /* @@ -133,18 +133,17 @@ static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, * * It is worth noting that these functions all access bytes of general * purpose memory in the NVRAM - that is to say, they all add the - * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not + * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not * know about the RTC cruft. */ -unsigned char -__nvram_read_byte(int i) +unsigned char __nvram_read_byte(int i) { return CMOS_READ(NVRAM_FIRST_BYTE + i); } +EXPORT_SYMBOL(__nvram_read_byte); -unsigned char -nvram_read_byte(int i) +unsigned char nvram_read_byte(int i) { unsigned long flags; unsigned char c; @@ -154,16 +153,16 @@ nvram_read_byte(int i) spin_unlock_irqrestore(&rtc_lock, flags); return c; } +EXPORT_SYMBOL(nvram_read_byte); /* This races nicely with trying to read with checksum checking (nvram_read) */ -void -__nvram_write_byte(unsigned char c, int i) +void __nvram_write_byte(unsigned char c, int i) { CMOS_WRITE(c, NVRAM_FIRST_BYTE + i); } +EXPORT_SYMBOL(__nvram_write_byte); -void -nvram_write_byte(unsigned char c, int i) +void nvram_write_byte(unsigned char c, int i) { unsigned long flags; @@ -171,15 +170,15 @@ nvram_write_byte(unsigned char c, int i) __nvram_write_byte(c, i); spin_unlock_irqrestore(&rtc_lock, flags); } +EXPORT_SYMBOL(nvram_write_byte); -int -__nvram_check_checksum(void) +int __nvram_check_checksum(void) { return mach_check_checksum(); } +EXPORT_SYMBOL(__nvram_check_checksum); -int -nvram_check_checksum(void) +int nvram_check_checksum(void) { unsigned long flags; int rv; @@ -189,16 +188,15 @@ nvram_check_checksum(void) spin_unlock_irqrestore(&rtc_lock, flags); return rv; } +EXPORT_SYMBOL(nvram_check_checksum); -static void -__nvram_set_checksum(void) +static void __nvram_set_checksum(void) { mach_set_checksum(); } #if 0 -void -nvram_set_checksum(void) +void nvram_set_checksum(void) { unsigned long flags; @@ -212,7 +210,7 @@ nvram_set_checksum(void) * The are the file operation function for user access to /dev/nvram */ -static loff_t nvram_llseek(struct file *file,loff_t offset, int origin ) +static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) { lock_kernel(); switch (origin) { @@ -230,8 +228,8 @@ static loff_t nvram_llseek(struct file *file,loff_t offset, int origin ) return (offset >= 0) ? (file->f_pos = offset) : -EINVAL; } -static ssize_t -nvram_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) +static ssize_t nvram_read(struct file *file, char __user *buf, + size_t count, loff_t *ppos) { unsigned char contents[NVRAM_BYTES]; unsigned i = *ppos; @@ -254,13 +252,13 @@ nvram_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) return tmp - contents; - checksum_err: +checksum_err: spin_unlock_irq(&rtc_lock); return -EIO; } -static ssize_t -nvram_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) +static ssize_t nvram_write(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) { unsigned char contents[NVRAM_BYTES]; unsigned i = *ppos; @@ -287,14 +285,13 @@ nvram_write(struct file *file, const char __user *buf, size_t count, loff_t *ppo return tmp - contents; - checksum_err: +checksum_err: spin_unlock_irq(&rtc_lock); return -EIO; } -static int -nvram_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg) +static int nvram_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) { int i; @@ -315,7 +312,7 @@ nvram_ioctl(struct inode *inode, struct file *file, return 0; case NVRAM_SETCKS: - /* just set checksum, contents unchanged (maybe useful after + /* just set checksum, contents unchanged (maybe useful after * checksum garbaged somehow...) */ if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -330,8 +327,7 @@ nvram_ioctl(struct inode *inode, struct file *file, } } -static int -nvram_open(struct inode *inode, struct file *file) +static int nvram_open(struct inode *inode, struct file *file) { lock_kernel(); spin_lock(&nvram_state_lock); @@ -356,8 +352,7 @@ nvram_open(struct inode *inode, struct file *file) return 0; } -static int -nvram_release(struct inode *inode, struct file *file) +static int nvram_release(struct inode *inode, struct file *file) { spin_lock(&nvram_state_lock); @@ -375,17 +370,15 @@ nvram_release(struct inode *inode, struct file *file) } #ifndef CONFIG_PROC_FS -static int -nvram_read_proc(char *buffer, char **start, off_t offset, - int size, int *eof, void *data) +static int nvram_read_proc(char *buffer, char **start, off_t offset, + int size, int *eof, void *data) { return 0; } #else -static int -nvram_read_proc(char *buffer, char **start, off_t offset, - int size, int *eof, void *data) +static int nvram_read_proc(char *buffer, char **start, off_t offset, + int size, int *eof, void *data) { unsigned char contents[NVRAM_BYTES]; int i, len = 0; @@ -409,14 +402,14 @@ nvram_read_proc(char *buffer, char **start, off_t offset, * this like that... */ #define PRINT_PROC(fmt,args...) \ do { \ - *len += sprintf(buffer+*len, fmt, ##args); \ + *len += sprintf(buffer + *len, fmt, ##args); \ if (*begin + *len > offset + size) \ return 0; \ if (*begin + *len < offset) { \ *begin += *len; \ *len = 0; \ } \ - } while(0) + } while (0) #endif /* CONFIG_PROC_FS */ @@ -436,8 +429,7 @@ static struct miscdevice nvram_dev = { &nvram_fops }; -static int __init -nvram_init(void) +static int __init nvram_init(void) { int ret; @@ -459,15 +451,14 @@ nvram_init(void) } ret = 0; printk(KERN_INFO "Non-volatile memory driver v" NVRAM_VERSION "\n"); - out: +out: return ret; - outmisc: +outmisc: misc_deregister(&nvram_dev); goto out; } -static void __exit -nvram_cleanup_module(void) +static void __exit nvram_cleanup_module(void) { remove_proc_entry("driver/nvram", NULL); misc_deregister(&nvram_dev); @@ -482,8 +473,7 @@ module_exit(nvram_cleanup_module); #if MACH == PC -static int -pc_check_checksum(void) +static int pc_check_checksum(void) { int i; unsigned short sum = 0; @@ -493,11 +483,10 @@ pc_check_checksum(void) sum += __nvram_read_byte(i); expect = __nvram_read_byte(PC_CKS_LOC)<<8 | __nvram_read_byte(PC_CKS_LOC+1); - return ((sum & 0xffff) == expect); + return (sum & 0xffff) == expect; } -static void -pc_set_checksum(void) +static void pc_set_checksum(void) { int i; unsigned short sum = 0; @@ -522,9 +511,8 @@ static char *gfx_types[] = { "monochrome", }; -static int -pc_proc_infos(unsigned char *nvram, char *buffer, int *len, - off_t *begin, off_t offset, int size) +static int pc_proc_infos(unsigned char *nvram, char *buffer, int *len, + off_t *begin, off_t offset, int size) { int checksum; int type; @@ -590,20 +578,18 @@ pc_proc_infos(unsigned char *nvram, char *buffer, int *len, #if MACH == ATARI -static int -atari_check_checksum(void) +static int atari_check_checksum(void) { int i; unsigned char sum = 0; for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i) sum += __nvram_read_byte(i); - return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff) && - __nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff)); + return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff)) && + (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff)); } -static void -atari_set_checksum(void) +static void atari_set_checksum(void) { int i; unsigned char sum = 0; @@ -654,9 +640,8 @@ static char *colors[] = { "2", "4", "16", "256", "65536", "??", "??", "??" }; -static int -atari_proc_infos(unsigned char *nvram, char *buffer, int *len, - off_t *begin, off_t offset, int size) +static int atari_proc_infos(unsigned char *nvram, char *buffer, int *len, + off_t *begin, off_t offset, int size) { int checksum = nvram_check_checksum(); int i; @@ -725,11 +710,4 @@ atari_proc_infos(unsigned char *nvram, char *buffer, int *len, #endif /* MACH == ATARI */ MODULE_LICENSE("GPL"); - -EXPORT_SYMBOL(__nvram_read_byte); -EXPORT_SYMBOL(nvram_read_byte); -EXPORT_SYMBOL(__nvram_write_byte); -EXPORT_SYMBOL(nvram_write_byte); -EXPORT_SYMBOL(__nvram_check_checksum); -EXPORT_SYMBOL(nvram_check_checksum); MODULE_ALIAS_MISCDEV(NVRAM_MINOR); -- cgit v1.2.3 From 8587b33f4adee4e7614ea7f443346c3b6bb5427a Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Tue, 11 Nov 2008 09:56:00 +0000 Subject: [PATCH] nvram - convert PRINT_PROC to seq_file Convert the /proc/drivers/nvram file from the old PRINT_PROC macro to the new seq_file filesystem. Signed-off-by: Wim Van Sebroeck --- drivers/char/nvram.c | 160 ++++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 78 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index 1a04f3df91e..88cee4099be 100644 --- a/drivers/char/nvram.c +++ b/drivers/char/nvram.c @@ -32,9 +32,10 @@ * added changelog * 1.2 Erik Gilling: Cobalt Networks support * Tim Hockin: general cleanup, Cobalt support + * 1.3 Wim Van Sebroeck: convert PRINT_PROC to seq_file */ -#define NVRAM_VERSION "1.2" +#define NVRAM_VERSION "1.3" #include #include @@ -106,6 +107,7 @@ #include #include #include +#include #include #include #include @@ -122,8 +124,8 @@ static int mach_check_checksum(void); static void mach_set_checksum(void); #ifdef CONFIG_PROC_FS -static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, - off_t *begin, off_t offset, int size); +static void mach_proc_infos(unsigned char *contents, struct seq_file *seq, + void *offset); #endif /* @@ -370,46 +372,47 @@ static int nvram_release(struct inode *inode, struct file *file) } #ifndef CONFIG_PROC_FS -static int nvram_read_proc(char *buffer, char **start, off_t offset, - int size, int *eof, void *data) +static int nvram_add_proc_fs(void) { return 0; } + #else -static int nvram_read_proc(char *buffer, char **start, off_t offset, - int size, int *eof, void *data) +static int nvram_proc_read(struct seq_file *seq, void *offset) { unsigned char contents[NVRAM_BYTES]; - int i, len = 0; - off_t begin = 0; + int i = 0; spin_lock_irq(&rtc_lock); for (i = 0; i < NVRAM_BYTES; ++i) contents[i] = __nvram_read_byte(i); spin_unlock_irq(&rtc_lock); - *eof = mach_proc_infos(contents, buffer, &len, &begin, offset, size); + mach_proc_infos(contents, seq, offset); - if (offset >= begin + len) - return 0; - *start = buffer + (offset - begin); - return (size < begin + len - offset) ? size : begin + len - offset; + return 0; +} +static int nvram_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, nvram_proc_read, NULL); } -/* This macro frees the machine specific function from bounds checking and - * this like that... */ -#define PRINT_PROC(fmt,args...) \ - do { \ - *len += sprintf(buffer + *len, fmt, ##args); \ - if (*begin + *len > offset + size) \ - return 0; \ - if (*begin + *len < offset) { \ - *begin += *len; \ - *len = 0; \ - } \ - } while (0) +static const struct file_operations nvram_proc_fops = { + .owner = THIS_MODULE, + .open = nvram_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int nvram_add_proc_fs(void) +{ + if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops)) + return -ENOMEM; + return 0; +} #endif /* CONFIG_PROC_FS */ @@ -443,10 +446,9 @@ static int __init nvram_init(void) NVRAM_MINOR); goto out; } - if (!create_proc_read_entry("driver/nvram", 0, NULL, nvram_read_proc, - NULL)) { + ret = nvram_add_proc_fs(); + if (ret) { printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n"); - ret = -ENOMEM; goto outmisc; } ret = 0; @@ -511,8 +513,8 @@ static char *gfx_types[] = { "monochrome", }; -static int pc_proc_infos(unsigned char *nvram, char *buffer, int *len, - off_t *begin, off_t offset, int size) +static void pc_proc_infos(unsigned char *nvram, struct seq_file *seq, + void *offset) { int checksum; int type; @@ -521,56 +523,57 @@ static int pc_proc_infos(unsigned char *nvram, char *buffer, int *len, checksum = __nvram_check_checksum(); spin_unlock_irq(&rtc_lock); - PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not "); + seq_printf(seq, "Checksum status: %svalid\n", checksum ? "" : "not "); - PRINT_PROC("# floppies : %d\n", + seq_printf(seq, "# floppies : %d\n", (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0); - PRINT_PROC("Floppy 0 type : "); + seq_printf(seq, "Floppy 0 type : "); type = nvram[2] >> 4; if (type < ARRAY_SIZE(floppy_types)) - PRINT_PROC("%s\n", floppy_types[type]); + seq_printf(seq, "%s\n", floppy_types[type]); else - PRINT_PROC("%d (unknown)\n", type); - PRINT_PROC("Floppy 1 type : "); + seq_printf(seq, "%d (unknown)\n", type); + seq_printf(seq, "Floppy 1 type : "); type = nvram[2] & 0x0f; if (type < ARRAY_SIZE(floppy_types)) - PRINT_PROC("%s\n", floppy_types[type]); + seq_printf(seq, "%s\n", floppy_types[type]); else - PRINT_PROC("%d (unknown)\n", type); + seq_printf(seq, "%d (unknown)\n", type); - PRINT_PROC("HD 0 type : "); + seq_printf(seq, "HD 0 type : "); type = nvram[4] >> 4; if (type) - PRINT_PROC("%02x\n", type == 0x0f ? nvram[11] : type); + seq_printf(seq, "%02x\n", type == 0x0f ? nvram[11] : type); else - PRINT_PROC("none\n"); + seq_printf(seq, "none\n"); - PRINT_PROC("HD 1 type : "); + seq_printf(seq, "HD 1 type : "); type = nvram[4] & 0x0f; if (type) - PRINT_PROC("%02x\n", type == 0x0f ? nvram[12] : type); + seq_printf(seq, "%02x\n", type == 0x0f ? nvram[12] : type); else - PRINT_PROC("none\n"); + seq_printf(seq, "none\n"); - PRINT_PROC("HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", + seq_printf(seq, "HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", nvram[18] | (nvram[19] << 8), nvram[20], nvram[25], nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8)); - PRINT_PROC("HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", + seq_printf(seq, "HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", nvram[39] | (nvram[40] << 8), nvram[41], nvram[46], nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8)); - PRINT_PROC("DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); - PRINT_PROC("Extended memory: %d kB (configured), %d kB (tested)\n", + seq_printf(seq, "DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); + seq_printf(seq, "Extended memory: %d kB (configured), %d kB (tested)\n", nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8)); - PRINT_PROC("Gfx adapter : %s\n", gfx_types[(nvram[6] >> 4) & 3]); + seq_printf(seq, "Gfx adapter : %s\n", + gfx_types[(nvram[6] >> 4) & 3]); - PRINT_PROC("FPU : %sinstalled\n", + seq_printf(seq, "FPU : %sinstalled\n", (nvram[6] & 2) ? "" : "not "); - return 1; + return; } #endif @@ -640,70 +643,71 @@ static char *colors[] = { "2", "4", "16", "256", "65536", "??", "??", "??" }; -static int atari_proc_infos(unsigned char *nvram, char *buffer, int *len, - off_t *begin, off_t offset, int size) +static void atari_proc_infos(unsigned char *nvram, struct seq_file *seq, + void *offset) { int checksum = nvram_check_checksum(); int i; unsigned vmode; - PRINT_PROC("Checksum status : %svalid\n", checksum ? "" : "not "); + seq_printf(seq, "Checksum status : %svalid\n", checksum ? "" : "not "); - PRINT_PROC("Boot preference : "); + seq_printf(seq, "Boot preference : "); for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) { if (nvram[1] == boot_prefs[i].val) { - PRINT_PROC("%s\n", boot_prefs[i].name); + seq_printf(seq, "%s\n", boot_prefs[i].name); break; } } if (i < 0) - PRINT_PROC("0x%02x (undefined)\n", nvram[1]); + seq_printf(seq, "0x%02x (undefined)\n", nvram[1]); - PRINT_PROC("SCSI arbitration : %s\n", + seq_printf(seq, "SCSI arbitration : %s\n", (nvram[16] & 0x80) ? "on" : "off"); - PRINT_PROC("SCSI host ID : "); + seq_printf(seq, "SCSI host ID : "); if (nvram[16] & 0x80) - PRINT_PROC("%d\n", nvram[16] & 7); + seq_printf(seq, "%d\n", nvram[16] & 7); else - PRINT_PROC("n/a\n"); + seq_printf(seq, "n/a\n"); /* the following entries are defined only for the Falcon */ if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON) - return 1; + return; - PRINT_PROC("OS language : "); + seq_printf(seq, "OS language : "); if (nvram[6] < ARRAY_SIZE(languages)) - PRINT_PROC("%s\n", languages[nvram[6]]); + seq_printf(seq, "%s\n", languages[nvram[6]]); else - PRINT_PROC("%u (undefined)\n", nvram[6]); - PRINT_PROC("Keyboard language: "); + seq_printf(seq, "%u (undefined)\n", nvram[6]); + seq_printf(seq, "Keyboard language: "); if (nvram[7] < ARRAY_SIZE(languages)) - PRINT_PROC("%s\n", languages[nvram[7]]); + seq_printf(seq, "%s\n", languages[nvram[7]]); else - PRINT_PROC("%u (undefined)\n", nvram[7]); - PRINT_PROC("Date format : "); - PRINT_PROC(dateformat[nvram[8] & 7], + seq_printf(seq, "%u (undefined)\n", nvram[7]); + seq_printf(seq, "Date format : "); + seq_printf(seq, dateformat[nvram[8] & 7], nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/'); - PRINT_PROC(", %dh clock\n", nvram[8] & 16 ? 24 : 12); - PRINT_PROC("Boot delay : "); + seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12); + seq_printf(seq, "Boot delay : "); if (nvram[10] == 0) - PRINT_PROC("default"); + seq_printf(seq, "default"); else - PRINT_PROC("%ds%s\n", nvram[10], + seq_printf(seq, "%ds%s\n", nvram[10], nvram[10] < 8 ? ", no memory test" : ""); vmode = (nvram[14] << 8) || nvram[15]; - PRINT_PROC("Video mode : %s colors, %d columns, %s %s monitor\n", + seq_printf(seq, + "Video mode : %s colors, %d columns, %s %s monitor\n", colors[vmode & 7], vmode & 8 ? 80 : 40, vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC"); - PRINT_PROC(" %soverscan, compat. mode %s%s\n", + seq_printf(seq, " %soverscan, compat. mode %s%s\n", vmode & 64 ? "" : "no ", vmode & 128 ? "on" : "off", vmode & 256 ? (vmode & 16 ? ", line doubling" : ", half screen") : ""); - return 1; + return; } #endif -- cgit v1.2.3 From 66303bce9b924e35e435d35409d3abc371755767 Mon Sep 17 00:00:00 2001 From: David Howells Date: Fri, 14 Nov 2008 10:38:41 +1100 Subject: CRED: Wrap task credential accesses in the tty driver Wrap access to task credentials so that they can be separated more easily from the task_struct during the introduction of COW creds. Change most current->(|e|s|fs)[ug]id to current_(|e|s|fs)[ug]id(). Change some task->e?[ug]id to task_e?[ug]id(). In some places it makes more sense to use RCU directly rather than a convenient wrapper; these will be addressed by later patches. Signed-off-by: David Howells Reviewed-by: James Morris Acked-by: Serge Hallyn Cc: Alan Cox Signed-off-by: James Morris --- drivers/char/tty_audit.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c index 5787249934c..d961fa9612c 100644 --- a/drivers/char/tty_audit.c +++ b/drivers/char/tty_audit.c @@ -86,10 +86,12 @@ static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid, ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); if (ab) { char name[sizeof(tsk->comm)]; + uid_t uid = task_uid(tsk); audit_log_format(ab, "tty pid=%u uid=%u auid=%u ses=%u " - "major=%d minor=%d comm=", tsk->pid, tsk->uid, - loginuid, sessionid, buf->major, buf->minor); + "major=%d minor=%d comm=", + tsk->pid, uid, loginuid, sessionid, + buf->major, buf->minor); get_task_comm(name, tsk); audit_log_untrustedstring(ab, name); audit_log_format(ab, " data="); -- cgit v1.2.3 From d5e54913433fff89609adfc4b96fefcf807a9030 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 5 Nov 2008 14:20:17 +0000 Subject: powerpc: udbg-based backend for hvc_console This adds a new backend for the hvc console based on the low-level udbg callbacks. This effectively implements a working runtime console in terms of the simple udbg primitives. This is kind of a hack - since udbg isn't something you really want to be using routinely - but it's really useful during bringup. This can be used to quickly implement a userspace-usable console while you're working on a proper driver for whatever console I/O device the hardware has. Or, it can be used to avoid writing a full blown tty/console driver entirely for quick-and-dirty I/O hardware that will later be replaced by something else. Signed-off-by: David Gibson Signed-off-by: Paul Mackerras --- drivers/char/Kconfig | 6 ++++ drivers/char/Makefile | 1 + drivers/char/hvc_udbg.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 drivers/char/hvc_udbg.c (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 43b35d0369d..19e255c49f1 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -631,6 +631,12 @@ config HVC_XEN help Xen virtual console device driver +config HVC_UDBG + bool "udbg based fake hypervisor console" + depends on PPC && EXPERIMENTAL + select HVC_DRIVER + default n + config VIRTIO_CONSOLE tristate "Virtio console" depends on VIRTIO diff --git a/drivers/char/Makefile b/drivers/char/Makefile index 438f71317c5..52e15524af3 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_HVC_BEAT) += hvc_beat.o obj-$(CONFIG_HVC_DRIVER) += hvc_console.o obj-$(CONFIG_HVC_IRQ) += hvc_irq.o obj-$(CONFIG_HVC_XEN) += hvc_xen.o +obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o obj-$(CONFIG_RAW_DRIVER) += raw.o obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c new file mode 100644 index 00000000000..bd63ba878a5 --- /dev/null +++ b/drivers/char/hvc_udbg.c @@ -0,0 +1,96 @@ +/* + * udbg interface to hvc_console.c + * + * (C) Copyright David Gibson, IBM Corporation 2008. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "hvc_console.h" + +struct hvc_struct *hvc_udbg_dev; + +static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count) +{ + int i; + + for (i = 0; i < count; i++) + udbg_putc(buf[i]); + + return i; +} + +static int hvc_udbg_get(uint32_t vtermno, char *buf, int count) +{ + int i, c; + + if (!udbg_getc_poll) + return 0; + + for (i = 0; i < count; i++) { + if ((c = udbg_getc_poll()) == -1) + break; + buf[i] = c; + } + + return i; +} + +static struct hv_ops hvc_udbg_ops = { + .get_chars = hvc_udbg_get, + .put_chars = hvc_udbg_put, +}; + +static int __init hvc_udbg_init(void) +{ + struct hvc_struct *hp; + + BUG_ON(hvc_udbg_dev); + + hp = hvc_alloc(0, NO_IRQ, &hvc_udbg_ops, 16); + if (IS_ERR(hp)) + return PTR_ERR(hp); + + hvc_udbg_dev = hp; + + return 0; +} +module_init(hvc_udbg_init); + +static void __exit hvc_udbg_exit(void) +{ + if (hvc_udbg_dev) + hvc_remove(hvc_udbg_dev); +} +module_exit(hvc_udbg_exit); + +static int __init hvc_udbg_console_init(void) +{ + hvc_instantiate(0, 0, &hvc_udbg_ops); + add_preferred_console("hvc", 0, NULL); + + return 0; +} +console_initcall(hvc_udbg_console_init); -- cgit v1.2.3 From e45f2c07742d447597df001c878bc4a8aafcde37 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Mon, 24 Nov 2008 11:28:36 +0300 Subject: x86: correct link to HPET timer specification Impact: update documentation / help text Original link is dead. Signed-off-by: Denis V. Lunev Signed-off-by: Ingo Molnar --- drivers/char/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index 53fdc7ff387..32b8bbf5003 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c @@ -46,7 +46,7 @@ /* * The High Precision Event Timer driver. * This driver is closely modelled after the rtc.c driver. - * http://www.intel.com/hardwaredesign/hpetspec.htm + * http://www.intel.com/hardwaredesign/hpetspec_1.pdf */ #define HPET_USER_FREQ (64) #define HPET_DRIFT (500) -- cgit v1.2.3 From a0e2f9f4a2487572803d5a00c7302db30e4c60d3 Mon Sep 17 00:00:00 2001 From: Sonny Rao Date: Sun, 9 Nov 2008 14:15:11 +0000 Subject: powerpc/BSR: Support multiple OF-node description of BSR This adds support for multiple BSR nodes in the OF device tree. Previously, the BSR driver only supported a single OF node describing a BSR. Apparently when an LPAR is set to use "all system resources" the BSR appears as a single node, but when it is handed out in pieces, each 8 byte piece gets its own node. So, this keeps a list of BSR devices instead of the array and includes all nodes. Also, this makes the code be more inclusive of what BSR devices we accept by only checking compatibility and not the device name property (which might change in the future versions of BSR). Signed-off-by: Sonny Rao Signed-off-by: Paul Mackerras --- drivers/char/bsr.c | 84 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 29 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/bsr.c b/drivers/char/bsr.c index 456f54db73e..977dfb1096a 100644 --- a/drivers/char/bsr.c +++ b/drivers/char/bsr.c @@ -60,6 +60,8 @@ struct bsr_dev { unsigned bsr_num; /* bsr id number for its type */ int bsr_minor; + struct list_head bsr_list; + dev_t bsr_dev; struct cdev bsr_cdev; struct device *bsr_device; @@ -67,8 +69,8 @@ struct bsr_dev { }; -static unsigned num_bsr_devs; -static struct bsr_dev *bsr_devs; +static unsigned total_bsr_devs; +static struct list_head bsr_devs = LIST_HEAD_INIT(bsr_devs); static struct class *bsr_class; static int bsr_major; @@ -146,24 +148,25 @@ const static struct file_operations bsr_fops = { static void bsr_cleanup_devs(void) { - int i; - for (i=0 ; i < num_bsr_devs; i++) { - struct bsr_dev *cur = bsr_devs + i; + struct bsr_dev *cur, *n; + + list_for_each_entry_safe(cur, n, &bsr_devs, bsr_list) { if (cur->bsr_device) { cdev_del(&cur->bsr_cdev); device_del(cur->bsr_device); } + list_del(&cur->bsr_list); + kfree(cur); } - - kfree(bsr_devs); } -static int bsr_create_devs(struct device_node *bn) +static int bsr_add_node(struct device_node *bn) { - int bsr_stride_len, bsr_bytes_len; + int bsr_stride_len, bsr_bytes_len, num_bsr_devs; const u32 *bsr_stride; const u32 *bsr_bytes; unsigned i; + int ret = -ENODEV; bsr_stride = of_get_property(bn, "ibm,lock-stride", &bsr_stride_len); bsr_bytes = of_get_property(bn, "ibm,#lock-bytes", &bsr_bytes_len); @@ -171,35 +174,36 @@ static int bsr_create_devs(struct device_node *bn) if (!bsr_stride || !bsr_bytes || (bsr_stride_len != bsr_bytes_len)) { printk(KERN_ERR "bsr of-node has missing/incorrect property\n"); - return -ENODEV; + return ret; } num_bsr_devs = bsr_bytes_len / sizeof(u32); - /* only a warning, its informational since we'll fail and exit */ - WARN_ON(num_bsr_devs > BSR_MAX_DEVS); - - bsr_devs = kzalloc(sizeof(struct bsr_dev) * num_bsr_devs, GFP_KERNEL); - if (!bsr_devs) - return -ENOMEM; - for (i = 0 ; i < num_bsr_devs; i++) { - struct bsr_dev *cur = bsr_devs + i; + struct bsr_dev *cur = kzalloc(sizeof(struct bsr_dev), + GFP_KERNEL); struct resource res; int result; + if (!cur) { + printk(KERN_ERR "Unable to alloc bsr dev\n"); + ret = -ENOMEM; + goto out_err; + } + result = of_address_to_resource(bn, i, &res); if (result < 0) { - printk(KERN_ERR "bsr of-node has invalid reg property\n"); - goto out_err; + printk(KERN_ERR "bsr of-node has invalid reg property, skipping\n"); + kfree(cur); + continue; } - cur->bsr_minor = i; + cur->bsr_minor = i + total_bsr_devs; cur->bsr_addr = res.start; cur->bsr_len = res.end - res.start + 1; cur->bsr_bytes = bsr_bytes[i]; cur->bsr_stride = bsr_stride[i]; - cur->bsr_dev = MKDEV(bsr_major, i); + cur->bsr_dev = MKDEV(bsr_major, i + total_bsr_devs); switch(cur->bsr_bytes) { case 8: @@ -220,14 +224,15 @@ static int bsr_create_devs(struct device_node *bn) } cur->bsr_num = bsr_types[cur->bsr_type]; - bsr_types[cur->bsr_type] = cur->bsr_num + 1; snprintf(cur->bsr_name, 32, "bsr%d_%d", cur->bsr_bytes, cur->bsr_num); cdev_init(&cur->bsr_cdev, &bsr_fops); result = cdev_add(&cur->bsr_cdev, cur->bsr_dev, 1); - if (result) + if (result) { + kfree(cur); goto out_err; + } cur->bsr_device = device_create(bsr_class, NULL, cur->bsr_dev, cur, cur->bsr_name); @@ -235,16 +240,37 @@ static int bsr_create_devs(struct device_node *bn) printk(KERN_ERR "device_create failed for %s\n", cur->bsr_name); cdev_del(&cur->bsr_cdev); + kfree(cur); goto out_err; } + + bsr_types[cur->bsr_type] = cur->bsr_num + 1; + list_add_tail(&cur->bsr_list, &bsr_devs); } + total_bsr_devs += num_bsr_devs; + return 0; out_err: bsr_cleanup_devs(); - return -ENODEV; + return ret; +} + +static int bsr_create_devs(struct device_node *bn) +{ + int ret; + + while (bn) { + ret = bsr_add_node(bn); + if (ret) { + of_node_put(bn); + return ret; + } + bn = of_find_compatible_node(bn, NULL, "ibm,bsr"); + } + return 0; } static int __init bsr_init(void) @@ -254,7 +280,7 @@ static int __init bsr_init(void) int ret = -ENODEV; int result; - np = of_find_compatible_node(NULL, "ibm,bsr", "ibm,bsr"); + np = of_find_compatible_node(NULL, NULL, "ibm,bsr"); if (!np) goto out_err; @@ -272,10 +298,10 @@ static int __init bsr_init(void) goto out_err_2; } - if ((ret = bsr_create_devs(np)) < 0) + if ((ret = bsr_create_devs(np)) < 0) { + np = NULL; goto out_err_3; - - of_node_put(np); + } return 0; -- cgit v1.2.3 From dc42149fccda63a5d2fa4457808c3489a5111c5e Mon Sep 17 00:00:00 2001 From: Nicolas Palix Date: Tue, 2 Dec 2008 03:38:55 +0000 Subject: drivers/hvc: Add missing of_node_put of_node_put is needed before discarding a value received from of_find_node_by_name, e.g., in error handling code or when the device node is no longer used. The semantic match that catches the bug is as follows: (http://www.emn.fr/x-info/coccinelle/) // @r exists@ local idexpression struct device_node *n; position p1, p2; statement S1,S2; expression E,E1; expression *ptr != NULL; @@ ( if (!(n@p1 = of_find_node_by_name(...))) S1 | n@p1 = of_find_node_by_name(...) ) <... when != of_node_put(n) when != if (...) { <+... of_node_put(n) ...+> } when != true !n || ... when != n = E when != E = n if (!n || ...) S2 ...> ( return \(0\|<+...n...+>\|ptr\); | return@p2 ...; | n = E1 | E1 = n ) @script:python@ p1 << r.p1; p2 << r.p2; @@ print "* file: %s of_find_node_by_name %s return %s" % (p1[0].file,p1[0].line,p2[0].line) // Signed-off-by: Nicolas Palix Signed-off-by: Julia Lawall Acked-by: Stephen Rothwell Signed-off-by: Paul Mackerras --- drivers/char/hvc_iseries.c | 4 +++- drivers/char/hvc_vio.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c index b74a2f8ab90..449727b6166 100644 --- a/drivers/char/hvc_iseries.c +++ b/drivers/char/hvc_iseries.c @@ -575,8 +575,10 @@ static int __init hvc_find_vtys(void) * of console adapters. */ if ((num_found >= MAX_NR_HVC_CONSOLES) || - (num_found >= VTTY_PORTS)) + (num_found >= VTTY_PORTS)) { + of_node_put(vty); break; + } vtermno = of_get_property(vty, "reg", NULL); if (!vtermno) diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c index 019e0b58593..bd62dc86b47 100644 --- a/drivers/char/hvc_vio.c +++ b/drivers/char/hvc_vio.c @@ -153,8 +153,10 @@ static int hvc_find_vtys(void) /* We have statically defined space for only a certain number * of console adapters. */ - if (num_found >= MAX_NR_HVC_CONSOLES) + if (num_found >= MAX_NR_HVC_CONSOLES) { + of_node_put(vty); break; + } vtermno = of_get_property(vty, "reg", NULL); if (!vtermno) -- cgit v1.2.3 From 3d26825ec03f623f20ba860e6e6113ab2d0bb0f1 Mon Sep 17 00:00:00 2001 From: roel kluin Date: Tue, 2 Dec 2008 11:21:43 +0000 Subject: powerpc: Make open count variables signed in hvcs/hvsi/hvc_console Otherwise the tests for count < 0 will never be true. Signed-off-by: Roel Kluin Signed-off-by: Paul Mackerras --- drivers/char/hvc_console.h | 2 +- drivers/char/hvcs.c | 2 +- drivers/char/hvsi.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h index 8297dbc2e6e..3c85d78c975 100644 --- a/drivers/char/hvc_console.h +++ b/drivers/char/hvc_console.h @@ -48,7 +48,7 @@ struct hvc_struct { spinlock_t lock; int index; struct tty_struct *tty; - unsigned int count; + int count; int do_wakeup; char *outbuf; int outbuf_size; diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c index 473d9b14439..6e6eb445d37 100644 --- a/drivers/char/hvcs.c +++ b/drivers/char/hvcs.c @@ -269,7 +269,7 @@ struct hvcs_struct { unsigned int index; struct tty_struct *tty; - unsigned int open_count; + int open_count; /* * Used to tell the driver kernel_thread what operations need to take diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c index 59c6f9ab94e..af055287271 100644 --- a/drivers/char/hvsi.c +++ b/drivers/char/hvsi.c @@ -75,7 +75,7 @@ struct hvsi_struct { spinlock_t lock; int index; struct tty_struct *tty; - unsigned int count; + int count; uint8_t throttle_buf[128]; uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */ /* inbuf is for packet reassembly. leave a little room for leftovers. */ -- cgit v1.2.3 From 7947cf0dd4b6a2bb06c57971502fb81c76a66f2d Mon Sep 17 00:00:00 2001 From: Hendrik Brueckner Date: Tue, 18 Nov 2008 01:28:28 +0000 Subject: hvc_console: Always schedule resize work on resize The test to check for a new winsize runs out-of-sync with the underlying tty. After a tty has been released and initialized again, the winsize might differ between the tty and the hp struct. The solution is to simply remove the check and always schedule the resize work. Signed-off-by: Hendrik Brueckner Acked-by: Christian Borntraeger Signed-off-by: Paul Mackerras --- drivers/char/hvc_console.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c index 5b819b12675..74ecb5b2968 100644 --- a/drivers/char/hvc_console.c +++ b/drivers/char/hvc_console.c @@ -689,10 +689,8 @@ EXPORT_SYMBOL_GPL(hvc_poll); */ void hvc_resize(struct hvc_struct *hp, struct winsize ws) { - if ((hp->ws.ws_row != ws.ws_row) || (hp->ws.ws_col != ws.ws_col)) { - hp->ws = ws; - schedule_work(&hp->tty_resize); - } + hp->ws = ws; + schedule_work(&hp->tty_resize); } /* -- cgit v1.2.3 From 0b8f1efad30bd58f89961b82dfe68b9edf8fd2ac Mon Sep 17 00:00:00 2001 From: Yinghai Lu Date: Fri, 5 Dec 2008 18:58:31 -0800 Subject: sparse irq_desc[] array: core kernel and x86 changes Impact: new feature Problem on distro kernels: irq_desc[NR_IRQS] takes megabytes of RAM with NR_CPUS set to large values. The goal is to be able to scale up to much larger NR_IRQS value without impacting the (important) common case. To solve this, we generalize irq_desc[NR_IRQS] to an (optional) array of irq_desc pointers. When CONFIG_SPARSE_IRQ=y is used, we use kzalloc_node to get irq_desc, this also makes the IRQ descriptors NUMA-local (to the site that calls request_irq()). This gets rid of the irq_cfg[] static array on x86 as well: irq_cfg now uses desc->chip_data for x86 to store irq_cfg. Signed-off-by: Yinghai Lu Signed-off-by: Ingo Molnar --- drivers/char/random.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/random.c b/drivers/char/random.c index 675076f5fca..d26891bfcd4 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -558,23 +558,9 @@ struct timer_rand_state { unsigned dont_count_entropy:1; }; -static struct timer_rand_state *irq_timer_state[NR_IRQS]; - -static struct timer_rand_state *get_timer_rand_state(unsigned int irq) -{ - if (irq >= nr_irqs) - return NULL; - - return irq_timer_state[irq]; -} - -static void set_timer_rand_state(unsigned int irq, struct timer_rand_state *state) -{ - if (irq >= nr_irqs) - return; - - irq_timer_state[irq] = state; -} +#ifndef CONFIG_SPARSE_IRQ +struct timer_rand_state *irq_timer_state[NR_IRQS]; +#endif static struct timer_rand_state input_timer_state; @@ -933,8 +919,10 @@ void rand_initialize_irq(int irq) { struct timer_rand_state *state; +#ifndef CONFIG_SPARSE_IRQ if (irq >= nr_irqs) return; +#endif state = get_timer_rand_state(irq); -- cgit v1.2.3 From 1e641743f055f075ed9a4edd75f1fb1e05669ddc Mon Sep 17 00:00:00 2001 From: Al Viro Date: Tue, 9 Dec 2008 09:23:33 +0000 Subject: Audit: Log TIOCSTI AUDIT_TTY records currently log all data read by processes marked for TTY input auditing, even if the data was "pushed back" using the TIOCSTI ioctl, not typed by the user. This patch records all TIOCSTI calls to disambiguate the input. It generates one audit message per character pushed back; considering TIOCSTI is used very rarely, this simple solution is probably good enough. (The only program I could find that uses TIOCSTI is mailx/nail in "header editing" mode, e.g. using the ~h escape. mailx is used very rarely, and the escapes are used even rarer.) Signed-Off-By: Miloslav Trmac Signed-off-by: Al Viro Signed-off-by: James Morris --- drivers/char/tty_audit.c | 78 +++++++++++++++++++++++++++++++++++++----------- drivers/char/tty_io.c | 1 + 2 files changed, 62 insertions(+), 17 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c index d961fa9612c..34ab6d798f8 100644 --- a/drivers/char/tty_audit.c +++ b/drivers/char/tty_audit.c @@ -67,37 +67,45 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf) tty_audit_buf_free(buf); } -/** - * tty_audit_buf_push - Push buffered data out - * - * Generate an audit message from the contents of @buf, which is owned by - * @tsk with @loginuid. @buf->mutex must be locked. - */ -static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid, - unsigned int sessionid, - struct tty_audit_buf *buf) +static void tty_audit_log(const char *description, struct task_struct *tsk, + uid_t loginuid, unsigned sessionid, int major, + int minor, unsigned char *data, size_t size) { struct audit_buffer *ab; - if (buf->valid == 0) - return; - if (audit_enabled == 0) - return; ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); if (ab) { char name[sizeof(tsk->comm)]; uid_t uid = task_uid(tsk); - audit_log_format(ab, "tty pid=%u uid=%u auid=%u ses=%u " - "major=%d minor=%d comm=", + audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u " + "major=%d minor=%d comm=", description, tsk->pid, uid, loginuid, sessionid, - buf->major, buf->minor); + major, minor); get_task_comm(name, tsk); audit_log_untrustedstring(ab, name); audit_log_format(ab, " data="); - audit_log_n_hex(ab, buf->data, buf->valid); + audit_log_n_hex(ab, data, size); audit_log_end(ab); } +} + +/** + * tty_audit_buf_push - Push buffered data out + * + * Generate an audit message from the contents of @buf, which is owned by + * @tsk with @loginuid. @buf->mutex must be locked. + */ +static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid, + unsigned int sessionid, + struct tty_audit_buf *buf) +{ + if (buf->valid == 0) + return; + if (audit_enabled == 0) + return; + tty_audit_log("tty", tsk, loginuid, sessionid, buf->major, buf->minor, + buf->data, buf->valid); buf->valid = 0; } @@ -151,6 +159,42 @@ void tty_audit_fork(struct signal_struct *sig) sig->tty_audit_buf = NULL; } +/** + * tty_audit_tiocsti - Log TIOCSTI + */ +void tty_audit_tiocsti(struct tty_struct *tty, char ch) +{ + struct tty_audit_buf *buf; + int major, minor, should_audit; + + spin_lock_irq(¤t->sighand->siglock); + should_audit = current->signal->audit_tty; + buf = current->signal->tty_audit_buf; + if (buf) + atomic_inc(&buf->count); + spin_unlock_irq(¤t->sighand->siglock); + + major = tty->driver->major; + minor = tty->driver->minor_start + tty->index; + if (buf) { + mutex_lock(&buf->mutex); + if (buf->major == major && buf->minor == minor) + tty_audit_buf_push_current(buf); + mutex_unlock(&buf->mutex); + tty_audit_buf_put(buf); + } + + if (should_audit && audit_enabled) { + uid_t auid; + unsigned int sessionid; + + auid = audit_get_loginuid(current); + sessionid = audit_get_sessionid(current); + tty_audit_log("ioctl=TIOCSTI", current, auid, sessionid, major, + minor, &ch, 1); + } +} + /** * tty_audit_push_task - Flush task's pending audit data */ diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 1412a8d1e58..db15f9ba7c0 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -2018,6 +2018,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p) return -EPERM; if (get_user(ch, p)) return -EFAULT; + tty_audit_tiocsti(tty, ch); ld = tty_ldisc_ref_wait(tty); ld->ops->receive_buf(tty, &ch, &mbz, 1); tty_ldisc_deref(ld); -- cgit v1.2.3 From 70d13e083c8589dd3edc2313777655da39cb3568 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sat, 6 Dec 2008 08:25:16 +0000 Subject: [ARM] netwinder: clean up GPIO naming Netwinder was using gpio_xxx names which could clash with the GPIO layer. Add a 'nw_' prefix to ensure that these remain separate. Signed-off-by: Russell King --- drivers/char/ds1620.c | 25 ++++++++++++------------- drivers/char/nwflash.c | 8 +++----- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/ds1620.c b/drivers/char/ds1620.c index 74e9cd81b5b..61f0146e215 100644 --- a/drivers/char/ds1620.c +++ b/drivers/char/ds1620.c @@ -43,52 +43,51 @@ static const char *fan_state[] = { "off", "on", "on (hardwired)" }; * chance that the WaveArtist driver could touch these bits to * enable or disable the speaker. */ -extern spinlock_t gpio_lock; extern unsigned int system_rev; static inline void netwinder_ds1620_set_clk(int clk) { - gpio_modify_op(GPIO_DSCLK, clk ? GPIO_DSCLK : 0); + nw_gpio_modify_op(GPIO_DSCLK, clk ? GPIO_DSCLK : 0); } static inline void netwinder_ds1620_set_data(int dat) { - gpio_modify_op(GPIO_DATA, dat ? GPIO_DATA : 0); + nw_gpio_modify_op(GPIO_DATA, dat ? GPIO_DATA : 0); } static inline int netwinder_ds1620_get_data(void) { - return gpio_read() & GPIO_DATA; + return nw_gpio_read() & GPIO_DATA; } static inline void netwinder_ds1620_set_data_dir(int dir) { - gpio_modify_io(GPIO_DATA, dir ? GPIO_DATA : 0); + nw_gpio_modify_io(GPIO_DATA, dir ? GPIO_DATA : 0); } static inline void netwinder_ds1620_reset(void) { - cpld_modify(CPLD_DS_ENABLE, 0); - cpld_modify(CPLD_DS_ENABLE, CPLD_DS_ENABLE); + nw_cpld_modify(CPLD_DS_ENABLE, 0); + nw_cpld_modify(CPLD_DS_ENABLE, CPLD_DS_ENABLE); } static inline void netwinder_lock(unsigned long *flags) { - spin_lock_irqsave(&gpio_lock, *flags); + spin_lock_irqsave(&nw_gpio_lock, *flags); } static inline void netwinder_unlock(unsigned long *flags) { - spin_unlock_irqrestore(&gpio_lock, *flags); + spin_unlock_irqrestore(&nw_gpio_lock, *flags); } static inline void netwinder_set_fan(int i) { unsigned long flags; - spin_lock_irqsave(&gpio_lock, flags); - gpio_modify_op(GPIO_FAN, i ? GPIO_FAN : 0); - spin_unlock_irqrestore(&gpio_lock, flags); + spin_lock_irqsave(&nw_gpio_lock, flags); + nw_gpio_modify_op(GPIO_FAN, i ? GPIO_FAN : 0); + spin_unlock_irqrestore(&nw_gpio_lock, flags); } static inline int netwinder_get_fan(void) @@ -96,7 +95,7 @@ static inline int netwinder_get_fan(void) if ((system_rev & 0xf000) == 0x4000) return FAN_ALWAYS_ON; - return (gpio_read() & GPIO_FAN) ? FAN_ON : FAN_OFF; + return (nw_gpio_read() & GPIO_FAN) ? FAN_ON : FAN_OFF; } /* diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c index 006be92ee3f..8c7df5ba088 100644 --- a/drivers/char/nwflash.c +++ b/drivers/char/nwflash.c @@ -58,8 +58,6 @@ static volatile unsigned char *FLASH_BASE; static int gbFlashSize = KFLASH_SIZE; static DEFINE_MUTEX(nwflash_mutex); -extern spinlock_t gpio_lock; - static int get_flash_id(void) { volatile unsigned int c1, c2; @@ -616,9 +614,9 @@ static void kick_open(void) * we want to write a bit pattern XXX1 to Xilinx to enable * the write gate, which will be open for about the next 2ms. */ - spin_lock_irqsave(&gpio_lock, flags); - cpld_modify(1, 1); - spin_unlock_irqrestore(&gpio_lock, flags); + spin_lock_irqsave(&nw_gpio_lock, flags); + nw_cpld_modify(CPLD_FLASH_WR_ENABLE, CPLD_FLASH_WR_ENABLE); + spin_unlock_irqrestore(&nw_gpio_lock, flags); /* * let the ISA bus to catch on... -- cgit v1.2.3 From 368c1e3249afe0e59097e7df664435ae55fb9f8d Mon Sep 17 00:00:00 2001 From: Hendrik Brueckner Date: Tue, 16 Dec 2008 00:09:38 +0000 Subject: hvc_console: Escape magic sysrq key The ctrl-o (^O) is a common control key used by several applications, such as vim, but hvc_console uses ^O as the magic-sysrq key. This commit allows users to send ^O to applications by pressing ^O twice in succession. To implement this, this commit introduces a check if ^O is pressed again if the sysrq_pressed variable is already set. In this case, clear sysrq_pressed state and flip the ^O character to the tty. (The old behavior has always set "sysrq_pressed" if ^O has been entered, and it has not flipped the ^O character to the tty.) Signed-off-by: Hendrik Brueckner Signed-off-by: Paul Mackerras --- drivers/char/hvc_console.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c index 74ecb5b2968..fb57f67bb42 100644 --- a/drivers/char/hvc_console.c +++ b/drivers/char/hvc_console.c @@ -642,8 +642,11 @@ int hvc_poll(struct hvc_struct *hp) /* Handle the SysRq Hack */ /* XXX should support a sequence */ if (buf[i] == '\x0f') { /* ^O */ - sysrq_pressed = 1; - continue; + /* if ^O is pressed again, reset + * sysrq_pressed and flip ^O char */ + sysrq_pressed = !sysrq_pressed; + if (sysrq_pressed) + continue; } else if (sysrq_pressed) { handle_sysrq(buf[i], tty); sysrq_pressed = 0; -- cgit v1.2.3 From 44a01d5ba8a4d543694461cd3e178cfa6b3f221b Mon Sep 17 00:00:00 2001 From: Hendrik Brueckner Date: Thu, 25 Dec 2008 13:38:57 +0100 Subject: [S390] s390/hvc_console: z/VM IUCV hypervisor console support This patch introduces a new hypervisor console (HVC) back-end that provides terminal access over the z/VM inter-user communication vehicle (IUCV). The z/VM IUCV communication is independent of the regular tcp/ip network and allows access even if there is no network connection between two z/VM guest virtual machines. The z/VM IUCV hypervisor console back-end helps the user to access a z/VM guest virtual machine that lacks of network connectivity; and thus, provides a "full-screen" terminal alternative to 3215/3270 terminal sessions. Use the hvc_iucv=[0..8] kernel boot parameter to specify the number of HVC terminals using a z/VM IUCV back-end. A recent version of the s390-tools package is required to establish a terminal connection to a z/VM IUCV hypervisor console back-end. Signed-off-by: Hendrik Brueckner Signed-off-by: Martin Schwidefsky --- drivers/char/Kconfig | 10 + drivers/char/Makefile | 1 + drivers/char/hvc_iucv.c | 850 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 861 insertions(+) create mode 100644 drivers/char/hvc_iucv.c (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 43d6ba83a19..8783457b93d 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -622,6 +622,16 @@ config HVC_BEAT help Toshiba's Cell Reference Set Beat Console device driver +config HVC_IUCV + bool "z/VM IUCV Hypervisor console support (VM only)" + depends on S390 + select HVC_DRIVER + select IUCV + default y + help + This driver provides a Hypervisor console (HVC) back-end to access + a Linux (console) terminal via a z/VM IUCV communication path. + config HVC_XEN bool "Xen Hypervisor Console support" depends on XEN diff --git a/drivers/char/Makefile b/drivers/char/Makefile index 438f71317c5..36151bae0d7 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_HVC_BEAT) += hvc_beat.o obj-$(CONFIG_HVC_DRIVER) += hvc_console.o obj-$(CONFIG_HVC_IRQ) += hvc_irq.o obj-$(CONFIG_HVC_XEN) += hvc_xen.o +obj-$(CONFIG_HVC_IUCV) += hvc_iucv.o obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o obj-$(CONFIG_RAW_DRIVER) += raw.o obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c new file mode 100644 index 00000000000..5ea7d7713fc --- /dev/null +++ b/drivers/char/hvc_iucv.c @@ -0,0 +1,850 @@ +/* + * hvc_iucv.c - z/VM IUCV back-end for the Hypervisor Console (HVC) + * + * This back-end for HVC provides terminal access via + * z/VM IUCV communication paths. + * + * Copyright IBM Corp. 2008. + * + * Author(s): Hendrik Brueckner + */ +#define KMSG_COMPONENT "hvc_iucv" + +#include +#include +#include +#include +#include +#include + +#include "hvc_console.h" + + +/* HVC backend for z/VM IUCV */ +#define HVC_IUCV_MAGIC 0xc9e4c3e5 +#define MAX_HVC_IUCV_LINES HVC_ALLOC_TTY_ADAPTERS +#define MEMPOOL_MIN_NR (PAGE_SIZE / sizeof(struct iucv_tty_buffer)/4) + +/* IUCV TTY message */ +#define MSG_VERSION 0x02 /* Message version */ +#define MSG_TYPE_ERROR 0x01 /* Error message */ +#define MSG_TYPE_TERMENV 0x02 /* Terminal environment variable */ +#define MSG_TYPE_TERMIOS 0x04 /* Terminal IO struct update */ +#define MSG_TYPE_WINSIZE 0x08 /* Terminal window size update */ +#define MSG_TYPE_DATA 0x10 /* Terminal data */ + +#define MSG_SIZE(s) ((s) + offsetof(struct iucv_tty_msg, data)) +struct iucv_tty_msg { + u8 version; /* Message version */ + u8 type; /* Message type */ +#define MSG_MAX_DATALEN (~(u16)0) + u16 datalen; /* Payload length */ + u8 data[]; /* Payload buffer */ +} __attribute__((packed)); + +enum iucv_state_t { + IUCV_DISCONN = 0, + IUCV_CONNECTED = 1, + IUCV_SEVERED = 2, +}; + +enum tty_state_t { + TTY_CLOSED = 0, + TTY_OPENED = 1, +}; + +struct hvc_iucv_private { + struct hvc_struct *hvc; /* HVC console struct reference */ + u8 srv_name[8]; /* IUCV service name (ebcdic) */ + enum iucv_state_t iucv_state; /* IUCV connection status */ + enum tty_state_t tty_state; /* TTY status */ + struct iucv_path *path; /* IUCV path pointer */ + spinlock_t lock; /* hvc_iucv_private lock */ + struct list_head tty_outqueue; /* outgoing IUCV messages */ + struct list_head tty_inqueue; /* incoming IUCV messages */ +}; + +struct iucv_tty_buffer { + struct list_head list; /* list pointer */ + struct iucv_message msg; /* store an incoming IUCV message */ + size_t offset; /* data buffer offset */ + struct iucv_tty_msg *mbuf; /* buffer to store input/output data */ +}; + +/* IUCV callback handler */ +static int hvc_iucv_path_pending(struct iucv_path *, u8[8], u8[16]); +static void hvc_iucv_path_severed(struct iucv_path *, u8[16]); +static void hvc_iucv_msg_pending(struct iucv_path *, struct iucv_message *); +static void hvc_iucv_msg_complete(struct iucv_path *, struct iucv_message *); + + +/* Kernel module parameters */ +static unsigned long hvc_iucv_devices; + +/* Array of allocated hvc iucv tty lines... */ +static struct hvc_iucv_private *hvc_iucv_table[MAX_HVC_IUCV_LINES]; + +/* Kmem cache and mempool for iucv_tty_buffer elements */ +static struct kmem_cache *hvc_iucv_buffer_cache; +static mempool_t *hvc_iucv_mempool; + +/* IUCV handler callback functions */ +static struct iucv_handler hvc_iucv_handler = { + .path_pending = hvc_iucv_path_pending, + .path_severed = hvc_iucv_path_severed, + .message_complete = hvc_iucv_msg_complete, + .message_pending = hvc_iucv_msg_pending, +}; + + +/** + * hvc_iucv_get_private() - Return a struct hvc_iucv_private instance. + * @num: The HVC virtual terminal number (vtermno) + * + * This function returns the struct hvc_iucv_private instance that corresponds + * to the HVC virtual terminal number specified as parameter @num. + */ +struct hvc_iucv_private *hvc_iucv_get_private(uint32_t num) +{ + if ((num < HVC_IUCV_MAGIC) || (num - HVC_IUCV_MAGIC > hvc_iucv_devices)) + return NULL; + return hvc_iucv_table[num - HVC_IUCV_MAGIC]; +} + +/** + * alloc_tty_buffer() - Returns a new struct iucv_tty_buffer element. + * @size: Size of the internal buffer used to store data. + * @flags: Memory allocation flags passed to mempool. + * + * This function allocates a new struct iucv_tty_buffer element and, optionally, + * allocates an internal data buffer with the specified size @size. + * Note: The total message size arises from the internal buffer size and the + * members of the iucv_tty_msg structure. + * + * The function returns NULL if memory allocation has failed. + */ +static struct iucv_tty_buffer *alloc_tty_buffer(size_t size, gfp_t flags) +{ + struct iucv_tty_buffer *bufp; + + bufp = mempool_alloc(hvc_iucv_mempool, flags); + if (!bufp) + return NULL; + memset(bufp, 0, sizeof(struct iucv_tty_buffer)); + + if (size > 0) { + bufp->msg.length = MSG_SIZE(size); + bufp->mbuf = kmalloc(bufp->msg.length, flags); + if (!bufp->mbuf) { + mempool_free(bufp, hvc_iucv_mempool); + return NULL; + } + bufp->mbuf->version = MSG_VERSION; + bufp->mbuf->type = MSG_TYPE_DATA; + bufp->mbuf->datalen = (u16) size; + } + return bufp; +} + +/** + * destroy_tty_buffer() - destroy struct iucv_tty_buffer element. + * @bufp: Pointer to a struct iucv_tty_buffer element, SHALL NOT be NULL. + * + * The destroy_tty_buffer() function frees the internal data buffer and returns + * the struct iucv_tty_buffer element back to the mempool for freeing. + */ +static void destroy_tty_buffer(struct iucv_tty_buffer *bufp) +{ + kfree(bufp->mbuf); + mempool_free(bufp, hvc_iucv_mempool); +} + +/** + * destroy_tty_buffer_list() - call destroy_tty_buffer() for each list element. + * @list: List head pointer to a list containing struct iucv_tty_buffer + * elements. + * + * Calls destroy_tty_buffer() for each struct iucv_tty_buffer element in the + * list @list. + */ +static void destroy_tty_buffer_list(struct list_head *list) +{ + struct iucv_tty_buffer *ent, *next; + + list_for_each_entry_safe(ent, next, list, list) { + list_del(&ent->list); + destroy_tty_buffer(ent); + } +} + +/** + * hvc_iucv_write() - Receive IUCV message write data to HVC console buffer. + * @priv: Pointer to hvc_iucv_private structure. + * @buf: HVC console buffer for writing received terminal data. + * @count: HVC console buffer size. + * @has_more_data: Pointer to an int variable. + * + * The function picks up pending messages from the input queue and receives + * the message data that is then written to the specified buffer @buf. + * If the buffer size @count is less than the data message size, then the + * message is kept on the input queue and @has_more_data is set to 1. + * If the message data has been entirely written, the message is removed from + * the input queue. + * + * The function returns the number of bytes written to the terminal, zero if + * there are no pending data messages available or if there is no established + * IUCV path. + * If the IUCV path has been severed, then -EPIPE is returned to cause a + * hang up (that is issued by the HVC console layer). + */ +static int hvc_iucv_write(struct hvc_iucv_private *priv, + char *buf, int count, int *has_more_data) +{ + struct iucv_tty_buffer *rb; + int written; + int rc; + + /* Immediately return if there is no IUCV connection */ + if (priv->iucv_state == IUCV_DISCONN) + return 0; + + /* If the IUCV path has been severed, return -EPIPE to inform the + * hvc console layer to hang up the tty device. */ + if (priv->iucv_state == IUCV_SEVERED) + return -EPIPE; + + /* check if there are pending messages */ + if (list_empty(&priv->tty_inqueue)) + return 0; + + /* receive a iucv message and flip data to the tty (ldisc) */ + rb = list_first_entry(&priv->tty_inqueue, struct iucv_tty_buffer, list); + + written = 0; + if (!rb->mbuf) { /* message not yet received ... */ + /* allocate mem to store msg data; if no memory is available + * then leave the buffer on the list and re-try later */ + rb->mbuf = kmalloc(rb->msg.length, GFP_ATOMIC); + if (!rb->mbuf) + return -ENOMEM; + + rc = __iucv_message_receive(priv->path, &rb->msg, 0, + rb->mbuf, rb->msg.length, NULL); + switch (rc) { + case 0: /* Successful */ + break; + case 2: /* No message found */ + case 9: /* Message purged */ + break; + default: + written = -EIO; + } + /* remove buffer if an error has occured or received data + * is not correct */ + if (rc || (rb->mbuf->version != MSG_VERSION) || + (rb->msg.length != MSG_SIZE(rb->mbuf->datalen))) + goto out_remove_buffer; + } + + switch (rb->mbuf->type) { + case MSG_TYPE_DATA: + written = min_t(int, rb->mbuf->datalen - rb->offset, count); + memcpy(buf, rb->mbuf->data + rb->offset, written); + if (written < (rb->mbuf->datalen - rb->offset)) { + rb->offset += written; + *has_more_data = 1; + goto out_written; + } + break; + + case MSG_TYPE_WINSIZE: + if (rb->mbuf->datalen != sizeof(struct winsize)) + break; + hvc_resize(priv->hvc, *((struct winsize *)rb->mbuf->data)); + break; + + case MSG_TYPE_ERROR: /* ignored ... */ + case MSG_TYPE_TERMENV: /* ignored ... */ + case MSG_TYPE_TERMIOS: /* ignored ... */ + break; + } + +out_remove_buffer: + list_del(&rb->list); + destroy_tty_buffer(rb); + *has_more_data = !list_empty(&priv->tty_inqueue); + +out_written: + return written; +} + +/** + * hvc_iucv_get_chars() - HVC get_chars operation. + * @vtermno: HVC virtual terminal number. + * @buf: Pointer to a buffer to store data + * @count: Size of buffer available for writing + * + * The hvc_console thread calls this method to read characters from + * the terminal backend. If an IUCV communication path has been established, + * pending IUCV messages are received and data is copied into buffer @buf + * up to @count bytes. + * + * Locking: The routine gets called under an irqsave() spinlock; and + * the routine locks the struct hvc_iucv_private->lock to call + * helper functions. + */ +static int hvc_iucv_get_chars(uint32_t vtermno, char *buf, int count) +{ + struct hvc_iucv_private *priv = hvc_iucv_get_private(vtermno); + int written; + int has_more_data; + + if (count <= 0) + return 0; + + if (!priv) + return -ENODEV; + + spin_lock(&priv->lock); + has_more_data = 0; + written = hvc_iucv_write(priv, buf, count, &has_more_data); + spin_unlock(&priv->lock); + + /* if there are still messages on the queue... schedule another run */ + if (has_more_data) + hvc_kick(); + + return written; +} + +/** + * hvc_iucv_send() - Send an IUCV message containing terminal data. + * @priv: Pointer to struct hvc_iucv_private instance. + * @buf: Buffer containing data to send. + * @size: Size of buffer and amount of data to send. + * + * If an IUCV communication path is established, the function copies the buffer + * data to a newly allocated struct iucv_tty_buffer element, sends the data and + * puts the element to the outqueue. + * + * If there is no IUCV communication path established, the function returns 0. + * If an existing IUCV communicaton path has been severed, the function returns + * -EPIPE (can be passed to HVC layer to cause a tty hangup). + */ +static int hvc_iucv_send(struct hvc_iucv_private *priv, const char *buf, + int count) +{ + struct iucv_tty_buffer *sb; + int rc; + u16 len; + + if (priv->iucv_state == IUCV_SEVERED) + return -EPIPE; + + if (priv->iucv_state == IUCV_DISCONN) + return 0; + + len = min_t(u16, MSG_MAX_DATALEN, count); + + /* allocate internal buffer to store msg data and also compute total + * message length */ + sb = alloc_tty_buffer(len, GFP_ATOMIC); + if (!sb) + return -ENOMEM; + + sb->mbuf->datalen = len; + memcpy(sb->mbuf->data, buf, len); + + list_add_tail(&sb->list, &priv->tty_outqueue); + + rc = __iucv_message_send(priv->path, &sb->msg, 0, 0, + (void *) sb->mbuf, sb->msg.length); + if (rc) { + list_del(&sb->list); + destroy_tty_buffer(sb); + len = 0; + } + + return len; +} + +/** + * hvc_iucv_put_chars() - HVC put_chars operation. + * @vtermno: HVC virtual terminal number. + * @buf: Pointer to an buffer to read data from + * @count: Size of buffer available for reading + * + * The hvc_console thread calls this method to write characters from + * to the terminal backend. + * The function calls hvc_iucv_send() under the lock of the + * struct hvc_iucv_private instance that corresponds to the tty @vtermno. + * + * Locking: The method gets called under an irqsave() spinlock; and + * locks struct hvc_iucv_private->lock. + */ +static int hvc_iucv_put_chars(uint32_t vtermno, const char *buf, int count) +{ + struct hvc_iucv_private *priv = hvc_iucv_get_private(vtermno); + int sent; + + if (count <= 0) + return 0; + + if (!priv) + return -ENODEV; + + spin_lock(&priv->lock); + sent = hvc_iucv_send(priv, buf, count); + spin_unlock(&priv->lock); + + return sent; +} + +/** + * hvc_iucv_notifier_add() - HVC notifier for opening a TTY for the first time. + * @hp: Pointer to the HVC device (struct hvc_struct) + * @id: Additional data (originally passed to hvc_alloc): the index of an struct + * hvc_iucv_private instance. + * + * The function sets the tty state to TTY_OPEN for the struct hvc_iucv_private + * instance that is derived from @id. Always returns 0. + * + * Locking: struct hvc_iucv_private->lock, spin_lock_bh + */ +static int hvc_iucv_notifier_add(struct hvc_struct *hp, int id) +{ + struct hvc_iucv_private *priv; + + priv = hvc_iucv_get_private(id); + if (!priv) + return 0; + + spin_lock_bh(&priv->lock); + priv->tty_state = TTY_OPENED; + spin_unlock_bh(&priv->lock); + + return 0; +} + +/** + * hvc_iucv_cleanup() - Clean up function if the tty portion is finally closed. + * @priv: Pointer to the struct hvc_iucv_private instance. + * + * The functions severs the established IUCV communication path (if any), and + * destroy struct iucv_tty_buffer elements from the in- and outqueue. Finally, + * the functions resets the states to TTY_CLOSED and IUCV_DISCONN. + */ +static void hvc_iucv_cleanup(struct hvc_iucv_private *priv) +{ + destroy_tty_buffer_list(&priv->tty_outqueue); + destroy_tty_buffer_list(&priv->tty_inqueue); + + priv->tty_state = TTY_CLOSED; + priv->iucv_state = IUCV_DISCONN; +} + +/** + * hvc_iucv_notifier_hangup() - HVC notifier for tty hangups. + * @hp: Pointer to the HVC device (struct hvc_struct) + * @id: Additional data (originally passed to hvc_alloc): the index of an struct + * hvc_iucv_private instance. + * + * This routine notifies the HVC backend that a tty hangup (carrier loss, + * virtual or otherwise) has occured. + * + * The HVC backend for z/VM IUCV ignores virtual hangups (vhangup()), to keep + * an existing IUCV communication path established. + * (Background: vhangup() is called from user space (by getty or login) to + * disable writing to the tty by other applications). + * + * If the tty has been opened (e.g. getty) and an established IUCV path has been + * severed (we caused the tty hangup in that case), then the functions invokes + * hvc_iucv_cleanup() to clean up. + * + * Locking: struct hvc_iucv_private->lock + */ +static void hvc_iucv_notifier_hangup(struct hvc_struct *hp, int id) +{ + struct hvc_iucv_private *priv; + + priv = hvc_iucv_get_private(id); + if (!priv) + return; + + spin_lock_bh(&priv->lock); + /* NOTE: If the hangup was scheduled by ourself (from the iucv + * path_servered callback [IUCV_SEVERED]), then we have to + * finally clean up the tty backend structure and set state to + * TTY_CLOSED. + * + * If the tty was hung up otherwise (e.g. vhangup()), then we + * ignore this hangup and keep an established IUCV path open... + * (...the reason is that we are not able to connect back to the + * client if we disconnect on hang up) */ + priv->tty_state = TTY_CLOSED; + + if (priv->iucv_state == IUCV_SEVERED) + hvc_iucv_cleanup(priv); + spin_unlock_bh(&priv->lock); +} + +/** + * hvc_iucv_notifier_del() - HVC notifier for closing a TTY for the last time. + * @hp: Pointer to the HVC device (struct hvc_struct) + * @id: Additional data (originally passed to hvc_alloc): + * the index of an struct hvc_iucv_private instance. + * + * This routine notifies the HVC backend that the last tty device file + * descriptor has been closed. + * The function calls hvc_iucv_cleanup() to clean up the struct hvc_iucv_private + * instance. + * + * Locking: struct hvc_iucv_private->lock + */ +static void hvc_iucv_notifier_del(struct hvc_struct *hp, int id) +{ + struct hvc_iucv_private *priv; + struct iucv_path *path; + + priv = hvc_iucv_get_private(id); + if (!priv) + return; + + spin_lock_bh(&priv->lock); + path = priv->path; /* save reference to IUCV path */ + priv->path = NULL; + hvc_iucv_cleanup(priv); + spin_unlock_bh(&priv->lock); + + /* sever IUCV path outside of priv->lock due to lock ordering of: + * priv->lock <--> iucv_table_lock */ + if (path) { + iucv_path_sever(path, NULL); + iucv_path_free(path); + } +} + +/** + * hvc_iucv_path_pending() - IUCV handler to process a connection request. + * @path: Pending path (struct iucv_path) + * @ipvmid: Originator z/VM system identifier + * @ipuser: User specified data for this path + * (AF_IUCV: port/service name and originator port) + * + * The function uses the @ipuser data to check to determine if the pending + * path belongs to a terminal managed by this HVC backend. + * If the check is successful, then an additional check is done to ensure + * that a terminal cannot be accessed multiple times (only one connection + * to a terminal is allowed). In that particular case, the pending path is + * severed. If it is the first connection, the pending path is accepted and + * associated to the struct hvc_iucv_private. The iucv state is updated to + * reflect that a communication path has been established. + * + * Returns 0 if the path belongs to a terminal managed by the this HVC backend; + * otherwise returns -ENODEV in order to dispatch this path to other handlers. + * + * Locking: struct hvc_iucv_private->lock + */ +static int hvc_iucv_path_pending(struct iucv_path *path, + u8 ipvmid[8], u8 ipuser[16]) +{ + struct hvc_iucv_private *priv; + u8 nuser_data[16]; + int i, rc; + + priv = NULL; + for (i = 0; i < hvc_iucv_devices; i++) + if (hvc_iucv_table[i] && + (0 == memcmp(hvc_iucv_table[i]->srv_name, ipuser, 8))) { + priv = hvc_iucv_table[i]; + break; + } + + if (!priv) + return -ENODEV; + + spin_lock(&priv->lock); + + /* If the terminal is already connected or being severed, then sever + * this path to enforce that there is only ONE established communication + * path per terminal. */ + if (priv->iucv_state != IUCV_DISCONN) { + iucv_path_sever(path, ipuser); + iucv_path_free(path); + goto out_path_handled; + } + + /* accept path */ + memcpy(nuser_data, ipuser + 8, 8); /* remote service (for af_iucv) */ + memcpy(nuser_data + 8, ipuser, 8); /* local service (for af_iucv) */ + path->msglim = 0xffff; /* IUCV MSGLIMIT */ + path->flags &= ~IUCV_IPRMDATA; /* TODO: use IUCV_IPRMDATA */ + rc = iucv_path_accept(path, &hvc_iucv_handler, nuser_data, priv); + if (rc) { + iucv_path_sever(path, ipuser); + iucv_path_free(path); + goto out_path_handled; + } + priv->path = path; + priv->iucv_state = IUCV_CONNECTED; + +out_path_handled: + spin_unlock(&priv->lock); + return 0; +} + +/** + * hvc_iucv_path_severed() - IUCV handler to process a path sever. + * @path: Pending path (struct iucv_path) + * @ipuser: User specified data for this path + * (AF_IUCV: port/service name and originator port) + * + * The function also severs the path (as required by the IUCV protocol) and + * sets the iucv state to IUCV_SEVERED for the associated struct + * hvc_iucv_private instance. Later, the IUCV_SEVERED state triggers a tty + * hangup (hvc_iucv_get_chars() / hvc_iucv_write()). + * + * If tty portion of the HVC is closed then clean up the outqueue in addition. + * + * Locking: struct hvc_iucv_private->lock + */ +static void hvc_iucv_path_severed(struct iucv_path *path, u8 ipuser[16]) +{ + struct hvc_iucv_private *priv = path->private; + + spin_lock(&priv->lock); + priv->iucv_state = IUCV_SEVERED; + + /* NOTE: If the tty has not yet been opened by a getty program + * (e.g. to see console messages), then cleanup the + * hvc_iucv_private structure to allow re-connects. + * + * If the tty has been opened, the get_chars() callback returns + * -EPIPE to signal the hvc console layer to hang up the tty. */ + priv->path = NULL; + if (priv->tty_state == TTY_CLOSED) + hvc_iucv_cleanup(priv); + spin_unlock(&priv->lock); + + /* finally sever path (outside of priv->lock due to lock ordering) */ + iucv_path_sever(path, ipuser); + iucv_path_free(path); +} + +/** + * hvc_iucv_msg_pending() - IUCV handler to process an incoming IUCV message. + * @path: Pending path (struct iucv_path) + * @msg: Pointer to the IUCV message + * + * The function stores an incoming message on the input queue for later + * processing (by hvc_iucv_get_chars() / hvc_iucv_write()). + * However, if the tty has not yet been opened, the message is rejected. + * + * Locking: struct hvc_iucv_private->lock + */ +static void hvc_iucv_msg_pending(struct iucv_path *path, + struct iucv_message *msg) +{ + struct hvc_iucv_private *priv = path->private; + struct iucv_tty_buffer *rb; + + spin_lock(&priv->lock); + + /* reject messages if tty has not yet been opened */ + if (priv->tty_state == TTY_CLOSED) { + iucv_message_reject(path, msg); + goto unlock_return; + } + + /* allocate buffer an empty buffer element */ + rb = alloc_tty_buffer(0, GFP_ATOMIC); + if (!rb) { + iucv_message_reject(path, msg); + goto unlock_return; /* -ENOMEM */ + } + rb->msg = *msg; + + list_add_tail(&rb->list, &priv->tty_inqueue); + + hvc_kick(); /* wakup hvc console thread */ + +unlock_return: + spin_unlock(&priv->lock); +} + +/** + * hvc_iucv_msg_complete() - IUCV handler to process message completion + * @path: Pending path (struct iucv_path) + * @msg: Pointer to the IUCV message + * + * The function is called upon completion of message delivery and the + * message is removed from the outqueue. Additional delivery information + * can be found in msg->audit: rejected messages (0x040000 (IPADRJCT)) and + * purged messages (0x010000 (IPADPGNR)). + * + * Locking: struct hvc_iucv_private->lock + */ +static void hvc_iucv_msg_complete(struct iucv_path *path, + struct iucv_message *msg) +{ + struct hvc_iucv_private *priv = path->private; + struct iucv_tty_buffer *ent, *next; + LIST_HEAD(list_remove); + + spin_lock(&priv->lock); + list_for_each_entry_safe(ent, next, &priv->tty_outqueue, list) + if (ent->msg.id == msg->id) { + list_move(&ent->list, &list_remove); + break; + } + spin_unlock(&priv->lock); + destroy_tty_buffer_list(&list_remove); +} + + +/* HVC operations */ +static struct hv_ops hvc_iucv_ops = { + .get_chars = hvc_iucv_get_chars, + .put_chars = hvc_iucv_put_chars, + .notifier_add = hvc_iucv_notifier_add, + .notifier_del = hvc_iucv_notifier_del, + .notifier_hangup = hvc_iucv_notifier_hangup, +}; + +/** + * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance + * @id: hvc_iucv_table index + * + * This function allocates a new hvc_iucv_private struct and put the + * instance into hvc_iucv_table at index @id. + * Returns 0 on success; otherwise non-zero. + */ +static int __init hvc_iucv_alloc(int id) +{ + struct hvc_iucv_private *priv; + char name[9]; + int rc; + + priv = kzalloc(sizeof(struct hvc_iucv_private), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + spin_lock_init(&priv->lock); + INIT_LIST_HEAD(&priv->tty_outqueue); + INIT_LIST_HEAD(&priv->tty_inqueue); + + /* Finally allocate hvc */ + priv->hvc = hvc_alloc(HVC_IUCV_MAGIC + id, + HVC_IUCV_MAGIC + id, &hvc_iucv_ops, PAGE_SIZE); + if (IS_ERR(priv->hvc)) { + rc = PTR_ERR(priv->hvc); + kfree(priv); + return rc; + } + + /* setup iucv related information */ + snprintf(name, 9, "ihvc%-4d", id); + memcpy(priv->srv_name, name, 8); + ASCEBC(priv->srv_name, 8); + + hvc_iucv_table[id] = priv; + return 0; +} + +/** + * hvc_iucv_init() - Initialization of HVC backend for z/VM IUCV + */ +static int __init hvc_iucv_init(void) +{ + int rc, i; + + if (!MACHINE_IS_VM) { + pr_warning("The z/VM IUCV Hypervisor console cannot be " + "used without z/VM.\n"); + return -ENODEV; + } + + if (!hvc_iucv_devices) + return -ENODEV; + + if (hvc_iucv_devices > MAX_HVC_IUCV_LINES) + return -EINVAL; + + hvc_iucv_buffer_cache = kmem_cache_create(KMSG_COMPONENT, + sizeof(struct iucv_tty_buffer), + 0, 0, NULL); + if (!hvc_iucv_buffer_cache) { + pr_err("Not enough memory for driver initialization " + "(rs=%d).\n", 1); + return -ENOMEM; + } + + hvc_iucv_mempool = mempool_create_slab_pool(MEMPOOL_MIN_NR, + hvc_iucv_buffer_cache); + if (!hvc_iucv_mempool) { + pr_err("Not enough memory for driver initialization " + "(rs=%d).\n", 2); + kmem_cache_destroy(hvc_iucv_buffer_cache); + return -ENOMEM; + } + + /* allocate hvc_iucv_private structs */ + for (i = 0; i < hvc_iucv_devices; i++) { + rc = hvc_iucv_alloc(i); + if (rc) { + pr_err("Could not create new z/VM IUCV HVC backend " + "rc=%d.\n", rc); + goto out_error_hvc; + } + } + + /* register IUCV callback handler */ + rc = iucv_register(&hvc_iucv_handler, 0); + if (rc) { + pr_err("Could not register iucv handler (rc=%d).\n", rc); + goto out_error_iucv; + } + + return 0; + +out_error_iucv: + iucv_unregister(&hvc_iucv_handler, 0); +out_error_hvc: + for (i = 0; i < hvc_iucv_devices; i++) + if (hvc_iucv_table[i]) { + if (hvc_iucv_table[i]->hvc) + hvc_remove(hvc_iucv_table[i]->hvc); + kfree(hvc_iucv_table[i]); + } + mempool_destroy(hvc_iucv_mempool); + kmem_cache_destroy(hvc_iucv_buffer_cache); + return rc; +} + +/** + * hvc_iucv_console_init() - Early console initialization + */ +static int __init hvc_iucv_console_init(void) +{ + if (!MACHINE_IS_VM || !hvc_iucv_devices) + return -ENODEV; + return hvc_instantiate(HVC_IUCV_MAGIC, 0, &hvc_iucv_ops); +} + +/** + * hvc_iucv_config() - Parsing of hvc_iucv= kernel command line parameter + * @val: Parameter value (numeric) + */ +static int __init hvc_iucv_config(char *val) +{ + return strict_strtoul(val, 10, &hvc_iucv_devices); +} + + +module_init(hvc_iucv_init); +console_initcall(hvc_iucv_console_init); +__setup("hvc_iucv=", hvc_iucv_config); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("HVC back-end for z/VM IUCV."); +MODULE_AUTHOR("Hendrik Brueckner "); -- cgit v1.2.3 From a50ccc6c6623ab0e64f2109881e07c176b2d876f Mon Sep 17 00:00:00 2001 From: Zhenyu Wang Date: Mon, 17 Nov 2008 14:39:00 +0800 Subject: agp/intel: add support for G41 chipset Signed-off-by: Zhenyu Wang Signed-off-by: Eric Anholt Signed-off-by: Dave Airlie --- drivers/char/agp/intel-agp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c index 9cf6e9bb017..7d8db5a6110 100644 --- a/drivers/char/agp/intel-agp.c +++ b/drivers/char/agp/intel-agp.c @@ -40,6 +40,8 @@ #define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12 #define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20 #define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22 +#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30 +#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32 /* cover 915 and 945 variants */ #define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \ @@ -63,7 +65,8 @@ #define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \ agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \ agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \ - agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB) + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \ + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB) extern int agp_memory_reserved; @@ -1196,6 +1199,7 @@ static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size) case PCI_DEVICE_ID_INTEL_IGD_E_HB: case PCI_DEVICE_ID_INTEL_Q45_HB: case PCI_DEVICE_ID_INTEL_G45_HB: + case PCI_DEVICE_ID_INTEL_G41_HB: *gtt_offset = *gtt_size = MB(2); break; default: @@ -2163,6 +2167,8 @@ static const struct intel_driver_description { "Q45/Q43", NULL, &intel_i965_driver }, { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0, "G45/G43", NULL, &intel_i965_driver }, + { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0, + "G41", NULL, &intel_i965_driver }, { 0, 0, 0, NULL, NULL, NULL } }; @@ -2360,6 +2366,7 @@ static struct pci_device_id agp_intel_pci_table[] = { ID(PCI_DEVICE_ID_INTEL_IGD_E_HB), ID(PCI_DEVICE_ID_INTEL_Q45_HB), ID(PCI_DEVICE_ID_INTEL_G45_HB), + ID(PCI_DEVICE_ID_INTEL_G41_HB), { } }; -- cgit v1.2.3 From b854b2ab959e8175d75e01cf8ed452ed2624d0c8 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 22 Dec 2008 18:56:27 -0800 Subject: =?UTF-8?q?agp/intel:=20Fix=20broken=20=C2=AE=20symbol=20in=20devi?= =?UTF-8?q?ce=20name.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eric Anholt Signed-off-by: Dave Airlie --- drivers/char/agp/intel-agp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c index 7d8db5a6110..c7714185f83 100644 --- a/drivers/char/agp/intel-agp.c +++ b/drivers/char/agp/intel-agp.c @@ -2160,7 +2160,7 @@ static const struct intel_driver_description { { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33", NULL, &intel_g33_driver }, { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0, - "Mobile Intel? GM45 Express", NULL, &intel_i965_driver }, + "Mobile Intel® GM45 Express", NULL, &intel_i965_driver }, { PCI_DEVICE_ID_INTEL_IGD_E_HB, PCI_DEVICE_ID_INTEL_IGD_E_IG, 0, "Intel Integrated Graphics Device", NULL, &intel_i965_driver }, { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0, -- cgit v1.2.3 From c29834584ea4eafccf2f62a0b8a32e64f792044c Mon Sep 17 00:00:00 2001 From: Christian Borntraeger Date: Tue, 25 Nov 2008 13:36:26 +0100 Subject: virtio_console: support console resizing this patch uses the new hvc callback hvc_resize to set the window size which allows to change the tty size of hvc_console via a hvc_resize function. I have added a new feature bit VIRTIO_CONSOLE_F_SIZE. The driver will change the window size on tty open and via the config_changed callback of the transport. Currently lguest and kvm_s390 have not implemented this callback, but the callback can be implemented at a later point in time. Signed-off-by: Christian Borntraeger Signed-off-by: Rusty Russell --- drivers/char/hvc_console.c | 1 + drivers/char/virtio_console.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c index fb57f67bb42..0587b66d6fc 100644 --- a/drivers/char/hvc_console.c +++ b/drivers/char/hvc_console.c @@ -695,6 +695,7 @@ void hvc_resize(struct hvc_struct *hp, struct winsize ws) hp->ws = ws; schedule_work(&hp->tty_resize); } +EXPORT_SYMBOL_GPL(hvc_resize); /* * This kthread is either polling or interrupt driven. This is determined by diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 3fb0d2c88ba..ff6f5a4b58f 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -137,13 +137,34 @@ int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)) return hvc_instantiate(0, 0, &virtio_cons); } +/* + * virtio console configuration. This supports: + * - console resize + */ +static void virtcons_apply_config(struct virtio_device *dev) +{ + struct winsize ws; + + if (virtio_has_feature(dev, VIRTIO_CONSOLE_F_SIZE)) { + dev->config->get(dev, + offsetof(struct virtio_console_config, cols), + &ws.ws_col, sizeof(u16)); + dev->config->get(dev, + offsetof(struct virtio_console_config, rows), + &ws.ws_row, sizeof(u16)); + hvc_resize(hvc, ws); + } +} + /* * we support only one console, the hvc struct is a global var - * There is no need to do anything + * We set the configuration at this point, since we now have a tty */ static int notifier_add_vio(struct hvc_struct *hp, int data) { hp->irq_requested = 1; + virtcons_apply_config(vdev); + return 0; } @@ -234,11 +255,18 @@ static struct virtio_device_id id_table[] = { { 0 }, }; +static unsigned int features[] = { + VIRTIO_CONSOLE_F_SIZE, +}; + static struct virtio_driver virtio_console = { + .feature_table = features, + .feature_table_size = ARRAY_SIZE(features), .driver.name = KBUILD_MODNAME, .driver.owner = THIS_MODULE, .id_table = id_table, .probe = virtcons_probe, + .config_changed = virtcons_apply_config, }; static int __init init(void) -- cgit v1.2.3 From a88a69c91256418c5907c2f1f8a0ec0a36f9e6cc Mon Sep 17 00:00:00 2001 From: Joe Peterson Date: Fri, 2 Jan 2009 13:40:53 +0000 Subject: n_tty: Fix loss of echoed characters and remove bkl from n_tty Fixes the loss of echoed (and other ldisc-generated characters) when the tty is stopped or when the driver output buffer is full (happens frequently for input during continuous program output, such as ^C) and removes the Big Kernel Lock from the N_TTY line discipline. Adds an "echo buffer" to the N_TTY line discipline that handles all ldisc-generated output (including echoed characters). Along with the loss of characters, this also fixes the associated loss of sync between tty output and the ldisc state when characters cannot be immediately written to the tty driver. The echo buffer stores (in addition to characters) state operations that need to be done at the time of character output (like management of the column position). This allows echo to cooperate correctly with program output, since the ldisc state remains consistent with actual characters written. Since the echo buffer code now isolates the tty column state code to the process_out* and process_echoes functions, we can remove the Big Kernel Lock (BKL) and replace it with mutex locks. Highlights are: * Handles echo (and other ldisc output) when tty driver buffer is full - continuous program output can block echo * Saves echo when tty is in stopped state (e.g. ^S) - (e.g.: ^Q will correctly cause held characters to be released for output) * Control character pairs (e.g. "^C") are treated atomically and not split up by interleaved program output * Line discipline state is kept consistent with characters sent to the tty driver * Remove the big kernel lock (BKL) from N_TTY line discipline Signed-off-by: Joe Peterson Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/n_tty.c | 736 +++++++++++++++++++++++++++++++++++++++----------- drivers/char/tty_io.c | 6 +- drivers/char/vt.c | 2 +- 3 files changed, 588 insertions(+), 156 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index efbfe961265..a9bc5764fe7 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c @@ -62,6 +62,17 @@ #define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */ #define TTY_THRESHOLD_UNTHROTTLE 128 +/* + * Special byte codes used in the echo buffer to represent operations + * or special handling of characters. Bytes in the echo buffer that + * are not part of such special blocks are treated as normal character + * codes. + */ +#define ECHO_OP_START 0xff +#define ECHO_OP_MOVE_BACK_COL 0x80 +#define ECHO_OP_SET_CANON_COL 0x81 +#define ECHO_OP_ERASE_TAB 0x82 + static inline unsigned char *alloc_buf(void) { gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; @@ -169,6 +180,7 @@ static void check_unthrottle(struct tty_struct *tty) * * Locking: tty_read_lock for read fields. */ + static void reset_buffer_flags(struct tty_struct *tty) { unsigned long flags; @@ -176,6 +188,11 @@ static void reset_buffer_flags(struct tty_struct *tty) spin_lock_irqsave(&tty->read_lock, flags); tty->read_head = tty->read_tail = tty->read_cnt = 0; spin_unlock_irqrestore(&tty->read_lock, flags); + + mutex_lock(&tty->echo_lock); + tty->echo_pos = tty->echo_cnt = tty->echo_overrun = 0; + mutex_unlock(&tty->echo_lock); + tty->canon_head = tty->canon_data = tty->erasing = 0; memset(&tty->read_flags, 0, sizeof tty->read_flags); n_tty_set_room(tty); @@ -266,89 +283,116 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty) } /** - * opost - output post processor + * do_output_char - output one character * @c: character (or partial unicode symbol) * @tty: terminal device + * @space: space available in tty driver write buffer * - * Perform OPOST processing. Returns -1 when the output device is - * full and the character must be retried. Note that Linux currently - * ignores TABDLY, CRDLY, VTDLY, FFDLY and NLDLY. They simply aren't - * relevant in the world today. If you ever need them, add them here. + * This is a helper function that handles one output character + * (including special characters like TAB, CR, LF, etc.), + * putting the results in the tty driver's write buffer. + * + * Note that Linux currently ignores TABDLY, CRDLY, VTDLY, FFDLY + * and NLDLY. They simply aren't relevant in the world today. + * If you ever need them, add them here. * - * Called from both the receive and transmit sides and can be called - * re-entrantly. Relies on lock_kernel() for tty->column state. + * Returns the number of bytes of buffer space used or -1 if + * no space left. + * + * Locking: should be called under the output_lock to protect + * the column state and space left in the buffer */ -static int opost(unsigned char c, struct tty_struct *tty) +static int do_output_char(unsigned char c, struct tty_struct *tty, int space) { - int space, spaces; + int spaces; - space = tty_write_room(tty); if (!space) return -1; - - lock_kernel(); - if (O_OPOST(tty)) { - switch (c) { - case '\n': - if (O_ONLRET(tty)) - tty->column = 0; - if (O_ONLCR(tty)) { - if (space < 2) { - unlock_kernel(); - return -1; - } - tty_put_char(tty, '\r'); - tty->column = 0; - } - tty->canon_column = tty->column; - break; - case '\r': - if (O_ONOCR(tty) && tty->column == 0) { - unlock_kernel(); - return 0; - } - if (O_OCRNL(tty)) { - c = '\n'; - if (O_ONLRET(tty)) - tty->canon_column = tty->column = 0; - break; - } + + switch (c) { + case '\n': + if (O_ONLRET(tty)) + tty->column = 0; + if (O_ONLCR(tty)) { + if (space < 2) + return -1; tty->canon_column = tty->column = 0; + tty_put_char(tty, '\r'); + tty_put_char(tty, c); + return 2; + } + tty->canon_column = tty->column; + break; + case '\r': + if (O_ONOCR(tty) && tty->column == 0) + return 0; + if (O_OCRNL(tty)) { + c = '\n'; + if (O_ONLRET(tty)) + tty->canon_column = tty->column = 0; break; - case '\t': - spaces = 8 - (tty->column & 7); - if (O_TABDLY(tty) == XTABS) { - if (space < spaces) { - unlock_kernel(); - return -1; - } - tty->column += spaces; - tty->ops->write(tty, " ", spaces); - unlock_kernel(); - return 0; - } + } + tty->canon_column = tty->column = 0; + break; + case '\t': + spaces = 8 - (tty->column & 7); + if (O_TABDLY(tty) == XTABS) { + if (space < spaces) + return -1; tty->column += spaces; - break; - case '\b': - if (tty->column > 0) - tty->column--; - break; - default: - if (O_OLCUC(tty)) - c = toupper(c); - if (!iscntrl(c) && !is_continuation(c, tty)) - tty->column++; - break; + tty->ops->write(tty, " ", spaces); + return spaces; } + tty->column += spaces; + break; + case '\b': + if (tty->column > 0) + tty->column--; + break; + default: + if (O_OLCUC(tty)) + c = toupper(c); + if (!iscntrl(c) && !is_continuation(c, tty)) + tty->column++; + break; } + tty_put_char(tty, c); - unlock_kernel(); - return 0; + return 1; +} + +/** + * process_output - output post processor + * @c: character (or partial unicode symbol) + * @tty: terminal device + * + * Perform OPOST processing. Returns -1 when the output device is + * full and the character must be retried. + * + * Locking: output_lock to protect column state and space left + * (also, this is called from n_tty_write under the + * tty layer write lock) + */ + +static int process_output(unsigned char c, struct tty_struct *tty) +{ + int space, retval; + + mutex_lock(&tty->output_lock); + + space = tty_write_room(tty); + retval = do_output_char(c, tty, space); + + mutex_unlock(&tty->output_lock); + if (retval < 0) + return -1; + else + return 0; } /** - * opost_block - block postprocess + * process_output_block - block post processor * @tty: terminal device * @inbuf: user buffer * @nr: number of bytes @@ -358,24 +402,29 @@ static int opost(unsigned char c, struct tty_struct *tty) * the simple cases normally found and helps to generate blocks of * symbols for the console driver and thus improve performance. * - * Called from n_tty_write under the tty layer write lock. Relies - * on lock_kernel for the tty->column state. + * Locking: output_lock to protect column state and space left + * (also, this is called from n_tty_write under the + * tty layer write lock) */ -static ssize_t opost_block(struct tty_struct *tty, - const unsigned char *buf, unsigned int nr) +static ssize_t process_output_block(struct tty_struct *tty, + const unsigned char *buf, unsigned int nr) { int space; int i; const unsigned char *cp; + mutex_lock(&tty->output_lock); + space = tty_write_room(tty); if (!space) + { + mutex_unlock(&tty->output_lock); return 0; + } if (nr > space) nr = space; - lock_kernel(); for (i = 0, cp = buf; i < nr; i++, cp++) { switch (*cp) { case '\n': @@ -407,46 +456,393 @@ static ssize_t opost_block(struct tty_struct *tty, } } break_out: - if (tty->ops->flush_chars) - tty->ops->flush_chars(tty); i = tty->ops->write(tty, buf, i); - unlock_kernel(); + + mutex_unlock(&tty->output_lock); return i; } +/** + * process_echoes - write pending echo characters + * @tty: terminal device + * + * Write previously buffered echo (and other ldisc-generated) + * characters to the tty. + * + * Characters generated by the ldisc (including echoes) need to + * be buffered because the driver's write buffer can fill during + * heavy program output. Echoing straight to the driver will + * often fail under these conditions, causing lost characters and + * resulting mismatches of ldisc state information. + * + * Since the ldisc state must represent the characters actually sent + * to the driver at the time of the write, operations like certain + * changes in column state are also saved in the buffer and executed + * here. + * + * A circular fifo buffer is used so that the most recent characters + * are prioritized. Also, when control characters are echoed with a + * prefixed "^", the pair is treated atomically and thus not separated. + * + * Locking: output_lock to protect column state and space left, + * echo_lock to protect the echo buffer + */ + +static void process_echoes(struct tty_struct *tty) +{ + int space, nr; + unsigned char c; + unsigned char *cp, *buf_end; + + if (!tty->echo_cnt) + return; + + mutex_lock(&tty->output_lock); + mutex_lock(&tty->echo_lock); + + space = tty_write_room(tty); + + buf_end = tty->echo_buf + N_TTY_BUF_SIZE; + cp = tty->echo_buf + tty->echo_pos; + nr = tty->echo_cnt; + while (nr > 0) { + c = *cp; + if (c == ECHO_OP_START) { + unsigned char op; + unsigned char *opp; + int no_space_left = 0; + + /* + * If the buffer byte is the start of a multi-byte + * operation, get the next byte, which is either the + * op code or a control character value. + */ + opp = cp + 1; + if (opp == buf_end) + opp -= N_TTY_BUF_SIZE; + op = *opp; + + switch (op) { + unsigned int num_chars, num_bs; + + case ECHO_OP_ERASE_TAB: + if (++opp == buf_end) + opp -= N_TTY_BUF_SIZE; + num_chars = *opp; + + /* + * Determine how many columns to go back + * in order to erase the tab. + * This depends on the number of columns + * used by other characters within the tab + * area. If this (modulo 8) count is from + * the start of input rather than from a + * previous tab, we offset by canon column. + * Otherwise, tab spacing is normal. + */ + if (!(num_chars & 0x80)) + num_chars += tty->canon_column; + num_bs = 8 - (num_chars & 7); + + if (num_bs > space) { + no_space_left = 1; + break; + } + space -= num_bs; + while (num_bs--) { + tty_put_char(tty, '\b'); + if (tty->column > 0) + tty->column--; + } + cp += 3; + nr -= 3; + break; + + case ECHO_OP_SET_CANON_COL: + tty->canon_column = tty->column; + cp += 2; + nr -= 2; + break; + + case ECHO_OP_MOVE_BACK_COL: + if (tty->column > 0) + tty->column--; + cp += 2; + nr -= 2; + break; + + case ECHO_OP_START: + /* This is an escaped echo op start code */ + if (!space) { + no_space_left = 1; + break; + } + tty_put_char(tty, ECHO_OP_START); + tty->column++; + space--; + cp += 2; + nr -= 2; + break; + + default: + if (iscntrl(op)) { + if (L_ECHOCTL(tty)) { + /* + * Ensure there is enough space + * for the whole ctrl pair. + */ + if (space < 2) { + no_space_left = 1; + break; + } + tty_put_char(tty, '^'); + tty_put_char(tty, op ^ 0100); + tty->column += 2; + space -= 2; + } else { + if (!space) { + no_space_left = 1; + break; + } + tty_put_char(tty, op); + space--; + } + } + /* + * If above falls through, this was an + * undefined op. + */ + cp += 2; + nr -= 2; + } + + if (no_space_left) + break; + } else { + int retval; + + if ((retval = do_output_char(c, tty, space)) < 0) + break; + space -= retval; + cp += 1; + nr -= 1; + } + + /* When end of circular buffer reached, wrap around */ + if (cp >= buf_end) + cp -= N_TTY_BUF_SIZE; + } + + if (nr == 0) { + tty->echo_pos = 0; + tty->echo_cnt = 0; + tty->echo_overrun = 0; + } else { + int num_processed = tty->echo_cnt - nr; + tty->echo_pos += num_processed; + tty->echo_pos &= N_TTY_BUF_SIZE - 1; + tty->echo_cnt = nr; + if (num_processed > 0) + tty->echo_overrun = 0; + } + + mutex_unlock(&tty->echo_lock); + mutex_unlock(&tty->output_lock); + + if (tty->ops->flush_chars) + tty->ops->flush_chars(tty); +} + +/** + * add_echo_byte - add a byte to the echo buffer + * @c: unicode byte to echo + * @tty: terminal device + * + * Add a character or operation byte to the echo buffer. + * + * Should be called under the echo lock to protect the echo buffer. + */ + +static void add_echo_byte(unsigned char c, struct tty_struct *tty) +{ + int new_byte_pos; + + if (tty->echo_cnt == N_TTY_BUF_SIZE) { + /* Circular buffer is already at capacity */ + new_byte_pos = tty->echo_pos; + + /* + * Since the buffer start position needs to be advanced, + * be sure to step by a whole operation byte group. + */ + if (tty->echo_buf[tty->echo_pos] == ECHO_OP_START) + { + if (tty->echo_buf[(tty->echo_pos + 1) & + (N_TTY_BUF_SIZE - 1)] == + ECHO_OP_ERASE_TAB) { + tty->echo_pos += 3; + tty->echo_cnt -= 2; + } else { + tty->echo_pos += 2; + tty->echo_cnt -= 1; + } + } else { + tty->echo_pos++; + } + tty->echo_pos &= N_TTY_BUF_SIZE - 1; + + tty->echo_overrun = 1; + } else { + new_byte_pos = tty->echo_pos + tty->echo_cnt; + new_byte_pos &= N_TTY_BUF_SIZE - 1; + tty->echo_cnt++; + } + + tty->echo_buf[new_byte_pos] = c; +} + +/** + * echo_move_back_col - add operation to move back a column + * @tty: terminal device + * + * Add an operation to the echo buffer to move back one column. + * + * Locking: echo_lock to protect the echo buffer + */ + +static void echo_move_back_col(struct tty_struct *tty) +{ + mutex_lock(&tty->echo_lock); + + add_echo_byte(ECHO_OP_START, tty); + add_echo_byte(ECHO_OP_MOVE_BACK_COL, tty); + + mutex_unlock(&tty->echo_lock); +} + +/** + * echo_set_canon_col - add operation to set the canon column + * @tty: terminal device + * + * Add an operation to the echo buffer to set the canon column + * to the current column. + * + * Locking: echo_lock to protect the echo buffer + */ + +static void echo_set_canon_col(struct tty_struct *tty) +{ + mutex_lock(&tty->echo_lock); + + add_echo_byte(ECHO_OP_START, tty); + add_echo_byte(ECHO_OP_SET_CANON_COL, tty); + + mutex_unlock(&tty->echo_lock); +} + +/** + * echo_erase_tab - add operation to erase a tab + * @num_chars: number of character columns already used + * @after_tab: true if num_chars starts after a previous tab + * @tty: terminal device + * + * Add an operation to the echo buffer to erase a tab. + * + * Called by the eraser function, which knows how many character + * columns have been used since either a previous tab or the start + * of input. This information will be used later, along with + * canon column (if applicable), to go back the correct number + * of columns. + * + * Locking: echo_lock to protect the echo buffer + */ + +static void echo_erase_tab(unsigned int num_chars, int after_tab, + struct tty_struct *tty) +{ + mutex_lock(&tty->echo_lock); + + add_echo_byte(ECHO_OP_START, tty); + add_echo_byte(ECHO_OP_ERASE_TAB, tty); + + /* We only need to know this modulo 8 (tab spacing) */ + num_chars &= 7; + + /* Set the high bit as a flag if num_chars is after a previous tab */ + if (after_tab) + num_chars |= 0x80; + + add_echo_byte(num_chars, tty); + + mutex_unlock(&tty->echo_lock); +} + +/** + * echo_char_raw - echo a character raw + * @c: unicode byte to echo + * @tty: terminal device + * + * Echo user input back onto the screen. This must be called only when + * L_ECHO(tty) is true. Called from the driver receive_buf path. + * + * This variant does not treat control characters specially. + * + * Locking: echo_lock to protect the echo buffer + */ + +static void echo_char_raw(unsigned char c, struct tty_struct *tty) +{ + mutex_lock(&tty->echo_lock); + + if (c == ECHO_OP_START) { + add_echo_byte(ECHO_OP_START, tty); + add_echo_byte(ECHO_OP_START, tty); + } else { + add_echo_byte(c, tty); + } + + mutex_unlock(&tty->echo_lock); +} /** - * echo_char - echo characters + * echo_char - echo a character * @c: unicode byte to echo * @tty: terminal device * * Echo user input back onto the screen. This must be called only when * L_ECHO(tty) is true. Called from the driver receive_buf path. * - * Relies on BKL for tty column locking + * This variant tags control characters to be possibly echoed as + * as "^X" (where X is the letter representing the control char). + * + * Locking: echo_lock to protect the echo buffer */ static void echo_char(unsigned char c, struct tty_struct *tty) { - if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') { - tty_put_char(tty, '^'); - tty_put_char(tty, c ^ 0100); - tty->column += 2; - } else - opost(c, tty); + mutex_lock(&tty->echo_lock); + + if (c == ECHO_OP_START) { + add_echo_byte(ECHO_OP_START, tty); + add_echo_byte(ECHO_OP_START, tty); + } else { + if (iscntrl(c) && c != '\t') + add_echo_byte(ECHO_OP_START, tty); + add_echo_byte(c, tty); + } + + mutex_unlock(&tty->echo_lock); } /** - * finsh_erasing - complete erase + * finish_erasing - complete erase * @tty: tty doing the erase - * - * Relies on BKL for tty column locking */ + static inline void finish_erasing(struct tty_struct *tty) { if (tty->erasing) { - tty_put_char(tty, '/'); - tty->column++; + echo_char_raw('/', tty); tty->erasing = 0; } } @@ -460,7 +856,7 @@ static inline void finish_erasing(struct tty_struct *tty) * present in the stream from the driver layer. Handles the complexities * of UTF-8 multibyte symbols. * - * Locking: read_lock for tty buffers, BKL for column/erasing state + * Locking: read_lock for tty buffers */ static void eraser(unsigned char c, struct tty_struct *tty) @@ -471,7 +867,7 @@ static void eraser(unsigned char c, struct tty_struct *tty) /* FIXME: locking needed ? */ if (tty->read_head == tty->canon_head) { - /* opost('\a', tty); */ /* what do you think? */ + /* echo_char_raw('\a', tty); */ /* what do you think? */ return; } if (c == ERASE_CHAR(tty)) @@ -497,7 +893,7 @@ static void eraser(unsigned char c, struct tty_struct *tty) echo_char(KILL_CHAR(tty), tty); /* Add a newline if ECHOK is on and ECHOKE is off. */ if (L_ECHOK(tty)) - opost('\n', tty); + echo_char_raw('\n', tty); return; } kill_type = KILL; @@ -533,67 +929,62 @@ static void eraser(unsigned char c, struct tty_struct *tty) if (L_ECHO(tty)) { if (L_ECHOPRT(tty)) { if (!tty->erasing) { - tty_put_char(tty, '\\'); - tty->column++; + echo_char_raw('\\', tty); tty->erasing = 1; } /* if cnt > 1, output a multi-byte character */ echo_char(c, tty); while (--cnt > 0) { head = (head+1) & (N_TTY_BUF_SIZE-1); - tty_put_char(tty, tty->read_buf[head]); + echo_char_raw(tty->read_buf[head], tty); + echo_move_back_col(tty); } } else if (kill_type == ERASE && !L_ECHOE(tty)) { echo_char(ERASE_CHAR(tty), tty); } else if (c == '\t') { - unsigned int col = tty->canon_column; - unsigned long tail = tty->canon_head; - - /* Find the column of the last char. */ - while (tail != tty->read_head) { + unsigned int num_chars = 0; + int after_tab = 0; + unsigned long tail = tty->read_head; + + /* + * Count the columns used for characters + * since the start of input or after a + * previous tab. + * This info is used to go back the correct + * number of columns. + */ + while (tail != tty->canon_head) { + tail = (tail-1) & (N_TTY_BUF_SIZE-1); c = tty->read_buf[tail]; - if (c == '\t') - col = (col | 7) + 1; + if (c == '\t') { + after_tab = 1; + break; + } else if (iscntrl(c)) { if (L_ECHOCTL(tty)) - col += 2; - } else if (!is_continuation(c, tty)) - col++; - tail = (tail+1) & (N_TTY_BUF_SIZE-1); - } - - /* should never happen */ - if (tty->column > 0x80000000) - tty->column = 0; - - /* Now backup to that column. */ - while (tty->column > col) { - /* Can't use opost here. */ - tty_put_char(tty, '\b'); - if (tty->column > 0) - tty->column--; + num_chars += 2; + } else if (!is_continuation(c, tty)) { + num_chars++; + } } + echo_erase_tab(num_chars, after_tab, tty); } else { if (iscntrl(c) && L_ECHOCTL(tty)) { - tty_put_char(tty, '\b'); - tty_put_char(tty, ' '); - tty_put_char(tty, '\b'); - if (tty->column > 0) - tty->column--; + echo_char_raw('\b', tty); + echo_char_raw(' ', tty); + echo_char_raw('\b', tty); } if (!iscntrl(c) || L_ECHOCTL(tty)) { - tty_put_char(tty, '\b'); - tty_put_char(tty, ' '); - tty_put_char(tty, '\b'); - if (tty->column > 0) - tty->column--; + echo_char_raw('\b', tty); + echo_char_raw(' ', tty); + echo_char_raw('\b', tty); } } } if (kill_type == ERASE) break; } - if (tty->read_head == tty->canon_head) + if (tty->read_head == tty->canon_head && L_ECHO(tty)) finish_erasing(tty); } @@ -724,14 +1115,18 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) c=tolower(c); if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && - ((I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty)) || - c == INTR_CHAR(tty) || c == QUIT_CHAR(tty) || c == SUSP_CHAR(tty))) + I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty) && + c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && c != SUSP_CHAR(tty)) { start_tty(tty); + process_echoes(tty); + } if (tty->closing) { if (I_IXON(tty)) { - if (c == START_CHAR(tty)) + if (c == START_CHAR(tty)) { start_tty(tty); + process_echoes(tty); + } else if (c == STOP_CHAR(tty)) stop_tty(tty); } @@ -745,17 +1140,20 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) * up. */ if (!test_bit(c, tty->process_char_map) || tty->lnext) { - finish_erasing(tty); tty->lnext = 0; if (L_ECHO(tty)) { + finish_erasing(tty); if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { - tty_put_char(tty, '\a'); /* beep if no space */ + /* beep if no space */ + echo_char_raw('\a', tty); + process_echoes(tty); return; } /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) - tty->canon_column = tty->column; + echo_set_canon_col(tty); echo_char(c, tty); + process_echoes(tty); } if (I_PARMRK(tty) && c == (unsigned char) '\377') put_tty_queue(c, tty); @@ -766,6 +1164,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) if (I_IXON(tty)) { if (c == START_CHAR(tty)) { start_tty(tty); + process_echoes(tty); return; } if (c == STOP_CHAR(tty)) { @@ -786,7 +1185,6 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) if (c == SUSP_CHAR(tty)) { send_signal: /* - * Echo character, and then send the signal. * Note that we do not use isig() here because we want * the order to be: * 1) flush, 2) echo, 3) signal @@ -795,8 +1193,12 @@ send_signal: n_tty_flush_buffer(tty); tty_driver_flush_buffer(tty); } - if (L_ECHO(tty)) + if (I_IXON(tty)) + start_tty(tty); + if (L_ECHO(tty)) { echo_char(c, tty); + process_echoes(tty); + } if (tty->pgrp) kill_pgrp(tty->pgrp, signal, 1); return; @@ -815,6 +1217,7 @@ send_signal: if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { eraser(c, tty); + process_echoes(tty); return; } if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { @@ -822,8 +1225,9 @@ send_signal: if (L_ECHO(tty)) { finish_erasing(tty); if (L_ECHOCTL(tty)) { - tty_put_char(tty, '^'); - tty_put_char(tty, '\b'); + echo_char_raw('^', tty); + echo_char_raw('\b', tty); + process_echoes(tty); } } return; @@ -834,18 +1238,20 @@ send_signal: finish_erasing(tty); echo_char(c, tty); - opost('\n', tty); + echo_char_raw('\n', tty); while (tail != tty->read_head) { echo_char(tty->read_buf[tail], tty); tail = (tail+1) & (N_TTY_BUF_SIZE-1); } + process_echoes(tty); return; } if (c == '\n') { if (L_ECHO(tty) || L_ECHONL(tty)) { if (tty->read_cnt >= N_TTY_BUF_SIZE-1) - tty_put_char(tty, '\a'); - opost('\n', tty); + echo_char_raw('\a', tty); + echo_char_raw('\n', tty); + process_echoes(tty); } goto handle_newline; } @@ -862,11 +1268,12 @@ send_signal: */ if (L_ECHO(tty)) { if (tty->read_cnt >= N_TTY_BUF_SIZE-1) - tty_put_char(tty, '\a'); + echo_char_raw('\a', tty); /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) - tty->canon_column = tty->column; + echo_set_canon_col(tty); echo_char(c, tty); + process_echoes(tty); } /* * XXX does PARMRK doubling happen for @@ -889,20 +1296,23 @@ handle_newline: } } - finish_erasing(tty); if (L_ECHO(tty)) { + finish_erasing(tty); if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { - tty_put_char(tty, '\a'); /* beep if no space */ + /* beep if no space */ + echo_char_raw('\a', tty); + process_echoes(tty); return; } if (c == '\n') - opost('\n', tty); + echo_char_raw('\n', tty); else { /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) - tty->canon_column = tty->column; + echo_set_canon_col(tty); echo_char(c, tty); } + process_echoes(tty); } if (I_PARMRK(tty) && c == (unsigned char) '\377') @@ -923,6 +1333,9 @@ handle_newline: static void n_tty_write_wakeup(struct tty_struct *tty) { + /* Write out any echoed characters that are still pending */ + process_echoes(tty); + if (tty->fasync) { set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); kill_fasync(&tty->fasync, SIGIO, POLL_OUT); @@ -1134,6 +1547,10 @@ static void n_tty_close(struct tty_struct *tty) free_buf(tty->read_buf); tty->read_buf = NULL; } + if (tty->echo_buf) { + free_buf(tty->echo_buf); + tty->echo_buf = NULL; + } } /** @@ -1151,13 +1568,19 @@ static int n_tty_open(struct tty_struct *tty) if (!tty) return -EINVAL; - /* This one is ugly. Currently a malloc failure here can panic */ + /* These are ugly. Currently a malloc failure here can panic */ if (!tty->read_buf) { tty->read_buf = alloc_buf(); if (!tty->read_buf) return -ENOMEM; } + if (!tty->echo_buf) { + tty->echo_buf = alloc_buf(); + if (!tty->echo_buf) + return -ENOMEM; + } memset(tty->read_buf, 0, N_TTY_BUF_SIZE); + memset(tty->echo_buf, 0, N_TTY_BUF_SIZE); reset_buffer_flags(tty); tty->column = 0; n_tty_set_termios(tty, NULL); @@ -1487,16 +1910,23 @@ do_it_again: * @buf: userspace buffer pointer * @nr: size of I/O * - * Write function of the terminal device. This is serialized with + * Write function of the terminal device. This is serialized with * respect to other write callers but not to termios changes, reads - * and other such events. We must be careful with N_TTY as the receive - * code will echo characters, thus calling driver write methods. + * and other such events. Since the receive code will echo characters, + * thus calling driver write methods, the output_lock is used in + * the output processing functions called here as well as in the + * echo processing function to protect the column state and space + * left in the buffer. * * This code must be sure never to sleep through a hangup. + * + * Locking: output_lock to protect column state and space left + * (note that the process_output*() functions take this + * lock themselves) */ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, - const unsigned char *buf, size_t nr) + const unsigned char *buf, size_t nr) { const unsigned char *b = buf; DECLARE_WAITQUEUE(wait, current); @@ -1510,6 +1940,9 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, return retval; } + /* Write out any echoed characters that are still pending */ + process_echoes(tty); + add_wait_queue(&tty->write_wait, &wait); while (1) { set_current_state(TASK_INTERRUPTIBLE); @@ -1523,7 +1956,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, } if (O_OPOST(tty) && !(test_bit(TTY_HW_COOK_OUT, &tty->flags))) { while (nr > 0) { - ssize_t num = opost_block(tty, b, nr); + ssize_t num = process_output_block(tty, b, nr); if (num < 0) { if (num == -EAGAIN) break; @@ -1535,7 +1968,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, if (nr == 0) break; c = *b; - if (opost(c, tty) < 0) + if (process_output(c, tty) < 0) break; b++; nr--; } @@ -1663,4 +2096,3 @@ struct tty_ldisc_ops tty_ldisc_N_TTY = { .receive_buf = n_tty_receive_buf, .write_wakeup = n_tty_write_wakeup }; - diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index db15f9ba7c0..d8d240c8a25 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -1111,9 +1111,7 @@ void tty_write_message(struct tty_struct *tty, char *msg) * Locks the line discipline as required * Writes to the tty driver are serialized by the atomic_write_lock * and are then processed in chunks to the device. The line discipline - * write method will not be involked in parallel for each device - * The line discipline write method is called under the big - * kernel lock for historical reasons. New code should not rely on this. + * write method will not be invoked in parallel for each device. */ static ssize_t tty_write(struct file *file, const char __user *buf, @@ -2785,6 +2783,8 @@ void initialize_tty_struct(struct tty_struct *tty, INIT_WORK(&tty->hangup_work, do_tty_hangup); mutex_init(&tty->atomic_read_lock); mutex_init(&tty->atomic_write_lock); + mutex_init(&tty->output_lock); + mutex_init(&tty->echo_lock); spin_lock_init(&tty->read_lock); spin_lock_init(&tty->ctrl_lock); INIT_LIST_HEAD(&tty->tty_files); diff --git a/drivers/char/vt.c b/drivers/char/vt.c index 008176edbd6..639e126b2bf 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -2679,7 +2679,7 @@ static int con_write_room(struct tty_struct *tty) { if (tty->stopped) return 0; - return 4096; /* No limit, really; we're not buffering */ + return 32768; /* No limit, really; we're not buffering */ } static int con_chars_in_buffer(struct tty_struct *tty) -- cgit v1.2.3 From 300a6204b4d45dc70359b24384ad04ae899179c3 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:41:04 +0000 Subject: n_tty: clean up coding style Now the main work is done its polishing time Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/n_tty.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index a9bc5764fe7..a223823544b 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c @@ -47,8 +47,8 @@ #include #include #include +#include -#include #include /* number of characters left in xmit buffer before select has we have room */ @@ -309,7 +309,7 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space) if (!space) return -1; - + switch (c) { case '\n': if (O_ONLRET(tty)) @@ -417,8 +417,7 @@ static ssize_t process_output_block(struct tty_struct *tty, mutex_lock(&tty->output_lock); space = tty_write_room(tty); - if (!space) - { + if (!space) { mutex_unlock(&tty->output_lock); return 0; } @@ -521,7 +520,7 @@ static void process_echoes(struct tty_struct *tty) if (opp == buf_end) opp -= N_TTY_BUF_SIZE; op = *opp; - + switch (op) { unsigned int num_chars, num_bs; @@ -621,7 +620,8 @@ static void process_echoes(struct tty_struct *tty) } else { int retval; - if ((retval = do_output_char(c, tty, space)) < 0) + retval = do_output_char(c, tty, space); + if (retval < 0) break; space -= retval; cp += 1; @@ -675,8 +675,7 @@ static void add_echo_byte(unsigned char c, struct tty_struct *tty) * Since the buffer start position needs to be advanced, * be sure to step by a whole operation byte group. */ - if (tty->echo_buf[tty->echo_pos] == ECHO_OP_START) - { + if (tty->echo_buf[tty->echo_pos] == ECHO_OP_START) { if (tty->echo_buf[(tty->echo_pos + 1) & (N_TTY_BUF_SIZE - 1)] == ECHO_OP_ERASE_TAB) { @@ -771,7 +770,7 @@ static void echo_erase_tab(unsigned int num_chars, int after_tab, /* Set the high bit as a flag if num_chars is after a previous tab */ if (after_tab) num_chars |= 0x80; - + add_echo_byte(num_chars, tty); mutex_unlock(&tty->echo_lock); @@ -959,8 +958,7 @@ static void eraser(unsigned char c, struct tty_struct *tty) if (c == '\t') { after_tab = 1; break; - } - else if (iscntrl(c)) { + } else if (iscntrl(c)) { if (L_ECHOCTL(tty)) num_chars += 2; } else if (!is_continuation(c, tty)) { @@ -1112,7 +1110,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) if (I_ISTRIP(tty)) c &= 0x7f; if (I_IUCLC(tty) && L_IEXTEN(tty)) - c=tolower(c); + c = tolower(c); if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty) && @@ -1126,8 +1124,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) if (c == START_CHAR(tty)) { start_tty(tty); process_echoes(tty); - } - else if (c == STOP_CHAR(tty)) + } else if (c == STOP_CHAR(tty)) stop_tty(tty); } return; @@ -1335,7 +1332,7 @@ static void n_tty_write_wakeup(struct tty_struct *tty) { /* Write out any echoed characters that are still pending */ process_echoes(tty); - + if (tty->fasync) { set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); kill_fasync(&tty->fasync, SIGIO, POLL_OUT); @@ -1942,7 +1939,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, /* Write out any echoed characters that are still pending */ process_echoes(tty); - + add_wait_queue(&tty->write_wait, &wait); while (1) { set_current_state(TASK_INTERRUPTIBLE); -- cgit v1.2.3 From e4adca27bcbb8a73c4cf1dfa71392654cfa33345 Mon Sep 17 00:00:00 2001 From: Sukadev Bhattiprolu Date: Fri, 2 Jan 2009 13:41:54 +0000 Subject: Add DEVPTS_MULTIPLE_INSTANCES config token Signed-off-by: Sukadev Bhattiprolu Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index c602b547cc6..c52a167227e 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -443,6 +443,17 @@ config UNIX98_PTYS All modern Linux systems use the Unix98 ptys. Say Y unless you're on an embedded system and want to conserve memory. +config DEVPTS_MULTIPLE_INSTANCES + bool "Support multiple instances of devpts" + depends on UNIX98_PTYS + default n + ---help--- + Enable support for multiple instances of devpts filesystem. + If you want to have isolated PTY namespaces (eg: in containers), + say Y here. Otherwise, say N. If enabled, each mount of devpts + filesystem with the '-o newinstance' option will create an + independent PTY namespace. + config LEGACY_PTYS bool "Legacy (BSD) PTY support" default y -- cgit v1.2.3 From a47d545f5782cbde871b50bdf4a83379ed2da222 Mon Sep 17 00:00:00 2001 From: Jason Wessel Date: Fri, 2 Jan 2009 13:43:04 +0000 Subject: tty: Fix sparse static warning for tty_driver_lookup_tty Fixed sparse warning: drivers/char/tty_io.c:1216:19: warning: symbol 'tty_driver_lookup_tty' was not declared. Should it be static? Signed-off-by: Jason Wessel Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/tty_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index d8d240c8a25..2a15af65dd1 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -1211,7 +1211,7 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p) * be held until the 'fast-open' is also done. Will change once we * have refcounting in the driver and per driver locking */ -struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, +static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, struct inode *inode, int idx) { struct tty_struct *tty; -- cgit v1.2.3 From fc6f6238226e6d1248e1967eae2bf556eaf3ac17 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:43:17 +0000 Subject: pty: simplify resize We have special case logic for resizing pty/tty pairs. We also have a per driver resize method so for the pty case we should use it. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/hvc_console.c | 2 +- drivers/char/pty.c | 54 +++++++++++++++++++++++++++++++++++++++++++++- drivers/char/tty_io.c | 31 ++++++++++---------------- drivers/char/vt.c | 14 ++++++------ 4 files changed, 71 insertions(+), 30 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c index 0587b66d6fc..5a8a4c28c86 100644 --- a/drivers/char/hvc_console.c +++ b/drivers/char/hvc_console.c @@ -529,7 +529,7 @@ static void hvc_set_winsz(struct work_struct *work) tty = tty_kref_get(hp->tty); spin_unlock_irqrestore(&hp->lock, hvc_flags); - tty_do_resize(tty, tty, &ws); + tty_do_resize(tty, &ws); tty_kref_put(tty); } diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 6d4582712b1..b5daaaa9007 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c @@ -230,6 +230,55 @@ static void pty_set_termios(struct tty_struct *tty, tty->termios->c_cflag |= (CS8 | CREAD); } +/** + * pty_do_resize - resize event + * @tty: tty being resized + * @real_tty: real tty (not the same as tty if using a pty/tty pair) + * @rows: rows (character) + * @cols: cols (character) + * + * Update the termios variables and send the neccessary signals to + * peform a terminal resize correctly + */ + +int pty_resize(struct tty_struct *tty, struct winsize *ws) +{ + struct pid *pgrp, *rpgrp; + unsigned long flags; + struct tty_struct *pty = tty->link; + + /* For a PTY we need to lock the tty side */ + mutex_lock(&tty->termios_mutex); + if (!memcmp(ws, &tty->winsize, sizeof(*ws))) + goto done; + + /* Get the PID values and reference them so we can + avoid holding the tty ctrl lock while sending signals. + We need to lock these individually however. */ + + spin_lock_irqsave(&tty->ctrl_lock, flags); + pgrp = get_pid(tty->pgrp); + spin_unlock_irqrestore(&tty->ctrl_lock, flags); + + spin_lock_irqsave(&pty->ctrl_lock, flags); + rpgrp = get_pid(pty->pgrp); + spin_unlock_irqrestore(&pty->ctrl_lock, flags); + + if (pgrp) + kill_pgrp(pgrp, SIGWINCH, 1); + if (rpgrp != pgrp && rpgrp) + kill_pgrp(rpgrp, SIGWINCH, 1); + + put_pid(pgrp); + put_pid(rpgrp); + + tty->winsize = *ws; + pty->winsize = *ws; /* Never used so will go away soon */ +done: + mutex_unlock(&tty->termios_mutex); + return 0; +} + static int pty_install(struct tty_driver *driver, struct tty_struct *tty) { struct tty_struct *o_tty; @@ -290,6 +339,7 @@ static const struct tty_operations pty_ops = { .chars_in_buffer = pty_chars_in_buffer, .unthrottle = pty_unthrottle, .set_termios = pty_set_termios, + .resize = pty_resize }; /* Traditional BSD devices */ @@ -319,6 +369,7 @@ static const struct tty_operations pty_ops_bsd = { .unthrottle = pty_unthrottle, .set_termios = pty_set_termios, .ioctl = pty_bsd_ioctl, + .resize = pty_resize }; static void __init legacy_pty_init(void) @@ -561,7 +612,8 @@ static const struct tty_operations ptm_unix98_ops = { .unthrottle = pty_unthrottle, .set_termios = pty_set_termios, .ioctl = pty_unix98_ioctl, - .shutdown = pty_unix98_shutdown + .shutdown = pty_unix98_shutdown, + .resize = pty_resize }; static const struct tty_operations pty_unix98_ops = { diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 2a15af65dd1..d33e5ab0617 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -2048,7 +2048,6 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) /** * tty_do_resize - resize event * @tty: tty being resized - * @real_tty: real tty (not the same as tty if using a pty/tty pair) * @rows: rows (character) * @cols: cols (character) * @@ -2056,41 +2055,34 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) * peform a terminal resize correctly */ -int tty_do_resize(struct tty_struct *tty, struct tty_struct *real_tty, - struct winsize *ws) +int tty_do_resize(struct tty_struct *tty, struct winsize *ws) { - struct pid *pgrp, *rpgrp; + struct pid *pgrp; unsigned long flags; - /* For a PTY we need to lock the tty side */ - mutex_lock(&real_tty->termios_mutex); - if (!memcmp(ws, &real_tty->winsize, sizeof(*ws))) + /* Lock the tty */ + mutex_lock(&tty->termios_mutex); + if (!memcmp(ws, &tty->winsize, sizeof(*ws))) goto done; /* Get the PID values and reference them so we can avoid holding the tty ctrl lock while sending signals */ spin_lock_irqsave(&tty->ctrl_lock, flags); pgrp = get_pid(tty->pgrp); - rpgrp = get_pid(real_tty->pgrp); spin_unlock_irqrestore(&tty->ctrl_lock, flags); if (pgrp) kill_pgrp(pgrp, SIGWINCH, 1); - if (rpgrp != pgrp && rpgrp) - kill_pgrp(rpgrp, SIGWINCH, 1); - put_pid(pgrp); - put_pid(rpgrp); tty->winsize = *ws; - real_tty->winsize = *ws; done: - mutex_unlock(&real_tty->termios_mutex); + mutex_unlock(&tty->termios_mutex); return 0; } /** * tiocswinsz - implement window size set ioctl - * @tty; tty + * @tty; tty side of tty * @arg: user buffer for result * * Copies the user idea of the window size to the kernel. Traditionally @@ -2103,17 +2095,16 @@ done: * then calls into the default method. */ -static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, - struct winsize __user *arg) +static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg) { struct winsize tmp_ws; if (copy_from_user(&tmp_ws, arg, sizeof(*arg))) return -EFAULT; if (tty->ops->resize) - return tty->ops->resize(tty, real_tty, &tmp_ws); + return tty->ops->resize(tty, &tmp_ws); else - return tty_do_resize(tty, real_tty, &tmp_ws); + return tty_do_resize(tty, &tmp_ws); } /** @@ -2538,7 +2529,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case TIOCGWINSZ: return tiocgwinsz(real_tty, p); case TIOCSWINSZ: - return tiocswinsz(tty, real_tty, p); + return tiocswinsz(real_tty, p); case TIOCCONS: return real_tty != tty ? -EINVAL : tioccons(file); case FIONBIO: diff --git a/drivers/char/vt.c b/drivers/char/vt.c index 639e126b2bf..80014213fb5 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -819,8 +819,8 @@ static inline int resize_screen(struct vc_data *vc, int width, int height, * ctrl_lock of the tty IFF a tty is passed. */ -static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty, - struct vc_data *vc, unsigned int cols, unsigned int lines) +static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, + unsigned int cols, unsigned int lines) { unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; unsigned int old_cols, old_rows, old_row_size, old_screen_size; @@ -932,7 +932,7 @@ static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty, ws.ws_row = vc->vc_rows; ws.ws_col = vc->vc_cols; ws.ws_ypixel = vc->vc_scan_lines; - tty_do_resize(tty, real_tty, &ws); + tty_do_resize(tty, &ws); } if (CON_IS_VISIBLE(vc)) @@ -954,13 +954,12 @@ static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty, int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) { - return vc_do_resize(vc->vc_tty, vc->vc_tty, vc, cols, rows); + return vc_do_resize(vc->vc_tty, vc, cols, rows); } /** * vt_resize - resize a VT * @tty: tty to resize - * @real_tty: tty if a pty/tty pair * @ws: winsize attributes * * Resize a virtual terminal. This is called by the tty layer as we @@ -971,14 +970,13 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) * termios_mutex and the tty ctrl_lock in that order. */ -int vt_resize(struct tty_struct *tty, struct tty_struct *real_tty, - struct winsize *ws) +int vt_resize(struct tty_struct *tty, struct winsize *ws) { struct vc_data *vc = tty->driver_data; int ret; acquire_console_sem(); - ret = vc_do_resize(tty, real_tty, vc, ws->ws_col, ws->ws_row); + ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row); release_console_sem(); return ret; } -- cgit v1.2.3 From a59c0d6f14315a3f300f6f3786137213727e4c47 Mon Sep 17 00:00:00 2001 From: Joe Peterson Date: Fri, 2 Jan 2009 13:43:25 +0000 Subject: n_tty: Fix handling of control characters and continuations Fix process_output_block to detect continuation characters correctly and to handle control characters even when O_OLCUC is enabled. Make similar change to do_output_char(). Signed-off-by: Joe Peterson Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/n_tty.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index a223823544b..30b0426b378 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c @@ -351,10 +351,12 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space) tty->column--; break; default: - if (O_OLCUC(tty)) - c = toupper(c); - if (!iscntrl(c) && !is_continuation(c, tty)) - tty->column++; + if (!iscntrl(c)) { + if (O_OLCUC(tty)) + c = toupper(c); + if (!is_continuation(c, tty)) + tty->column++; + } break; } @@ -425,7 +427,9 @@ static ssize_t process_output_block(struct tty_struct *tty, nr = space; for (i = 0, cp = buf; i < nr; i++, cp++) { - switch (*cp) { + unsigned char c = *cp; + + switch (c) { case '\n': if (O_ONLRET(tty)) tty->column = 0; @@ -447,10 +451,12 @@ static ssize_t process_output_block(struct tty_struct *tty, tty->column--; break; default: - if (O_OLCUC(tty)) - goto break_out; - if (!iscntrl(*cp)) - tty->column++; + if (!iscntrl(c)) { + if (O_OLCUC(tty)) + goto break_out; + if (!is_continuation(c, tty)) + tty->column++; + } break; } } -- cgit v1.2.3 From acc71bbad33478973dbed68ebbc2d76dac9a51bd Mon Sep 17 00:00:00 2001 From: Joe Peterson Date: Fri, 2 Jan 2009 13:43:32 +0000 Subject: n_tty: Fix hanfling of buffer full corner cases Fix the handling of input characters when the tty buffer is full or nearly full. This includes tests that are done in n_tty_receive_char() and handling of PARMRK. Problems with the buffer-full tests done in receive_char() caused characters to be lost at times when the buffer(s) filled. Also, these full conditions would often only be detected with echo on, and PARMRK was not accounted for properly in all cases. One symptom of these problems, in addition to lost characters, was early termination from unix commands like tr and cat when ^Q was used to break from a stopped tty with full buffers (note that breaking out was often previously not possible, due to the pty getting in "gridlock", which will be addressed in another patch). Note space is always reserved at the end of the buffer for a newline (or EOF/EOL) in canonical mode. Signed-off-by: Joe Peterson Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/n_tty.c | 55 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index 30b0426b378..4b1e96b65ab 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c @@ -1107,6 +1107,7 @@ static inline void n_tty_receive_parity_error(struct tty_struct *tty, static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) { unsigned long flags; + int parmrk; if (tty->raw) { put_tty_queue(c, tty); @@ -1144,21 +1145,24 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) */ if (!test_bit(c, tty->process_char_map) || tty->lnext) { tty->lnext = 0; - if (L_ECHO(tty)) { - finish_erasing(tty); - if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { - /* beep if no space */ + parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; + if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { + /* beep if no space */ + if (L_ECHO(tty)) { echo_char_raw('\a', tty); process_echoes(tty); - return; } + return; + } + if (L_ECHO(tty)) { + finish_erasing(tty); /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) echo_set_canon_col(tty); echo_char(c, tty); process_echoes(tty); } - if (I_PARMRK(tty) && c == (unsigned char) '\377') + if (parmrk) put_tty_queue(c, tty); put_tty_queue(c, tty); return; @@ -1250,15 +1254,22 @@ send_signal: return; } if (c == '\n') { - if (L_ECHO(tty) || L_ECHONL(tty)) { - if (tty->read_cnt >= N_TTY_BUF_SIZE-1) + if (tty->read_cnt >= N_TTY_BUF_SIZE) { + if (L_ECHO(tty)) { echo_char_raw('\a', tty); + process_echoes(tty); + } + return; + } + if (L_ECHO(tty) || L_ECHONL(tty)) { echo_char_raw('\n', tty); process_echoes(tty); } goto handle_newline; } if (c == EOF_CHAR(tty)) { + if (tty->read_cnt >= N_TTY_BUF_SIZE) + return; if (tty->canon_head != tty->read_head) set_bit(TTY_PUSH, &tty->flags); c = __DISABLED_CHAR; @@ -1266,12 +1277,19 @@ send_signal: } if ((c == EOL_CHAR(tty)) || (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { + parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) + ? 1 : 0; + if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) { + if (L_ECHO(tty)) { + echo_char_raw('\a', tty); + process_echoes(tty); + } + return; + } /* * XXX are EOL_CHAR and EOL2_CHAR echoed?!? */ if (L_ECHO(tty)) { - if (tty->read_cnt >= N_TTY_BUF_SIZE-1) - echo_char_raw('\a', tty); /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) echo_set_canon_col(tty); @@ -1282,7 +1300,7 @@ send_signal: * XXX does PARMRK doubling happen for * EOL_CHAR and EOL2_CHAR? */ - if (I_PARMRK(tty) && c == (unsigned char) '\377') + if (parmrk) put_tty_queue(c, tty); handle_newline: @@ -1299,14 +1317,17 @@ handle_newline: } } - if (L_ECHO(tty)) { - finish_erasing(tty); - if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { - /* beep if no space */ + parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; + if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { + /* beep if no space */ + if (L_ECHO(tty)) { echo_char_raw('\a', tty); process_echoes(tty); - return; } + return; + } + if (L_ECHO(tty)) { + finish_erasing(tty); if (c == '\n') echo_char_raw('\n', tty); else { @@ -1318,7 +1339,7 @@ handle_newline: process_echoes(tty); } - if (I_PARMRK(tty) && c == (unsigned char) '\377') + if (parmrk) put_tty_queue(c, tty); put_tty_queue(c, tty); -- cgit v1.2.3 From 7e94b1d9bffc18dca3b45554d9d118a3ffcc4d1b Mon Sep 17 00:00:00 2001 From: Joe Peterson Date: Fri, 2 Jan 2009 13:43:40 +0000 Subject: n_tty: Output bells immediately on a full buffer This patch causes "bell" (^G) characters (invoked when the input buffer is full) to be immediately output rather than filling the echo buffer. This is especially a problem when the tty is stopped and buffers fill, since the bells do not serve their purpose of immediate notification that the buffer cannot take further input, and they will flush all at once when the tty is restarted. Signed-off-by: Joe Peterson Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/n_tty.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index 4b1e96b65ab..3922a084205 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c @@ -872,7 +872,7 @@ static void eraser(unsigned char c, struct tty_struct *tty) /* FIXME: locking needed ? */ if (tty->read_head == tty->canon_head) { - /* echo_char_raw('\a', tty); */ /* what do you think? */ + /* process_output('\a', tty); */ /* what do you think? */ return; } if (c == ERASE_CHAR(tty)) @@ -1148,10 +1148,8 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { /* beep if no space */ - if (L_ECHO(tty)) { - echo_char_raw('\a', tty); - process_echoes(tty); - } + if (L_ECHO(tty)) + process_output('\a', tty); return; } if (L_ECHO(tty)) { @@ -1255,10 +1253,8 @@ send_signal: } if (c == '\n') { if (tty->read_cnt >= N_TTY_BUF_SIZE) { - if (L_ECHO(tty)) { - echo_char_raw('\a', tty); - process_echoes(tty); - } + if (L_ECHO(tty)) + process_output('\a', tty); return; } if (L_ECHO(tty) || L_ECHONL(tty)) { @@ -1280,10 +1276,8 @@ send_signal: parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) { - if (L_ECHO(tty)) { - echo_char_raw('\a', tty); - process_echoes(tty); - } + if (L_ECHO(tty)) + process_output('\a', tty); return; } /* @@ -1320,10 +1314,8 @@ handle_newline: parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { /* beep if no space */ - if (L_ECHO(tty)) { - echo_char_raw('\a', tty); - process_echoes(tty); - } + if (L_ECHO(tty)) + process_output('\a', tty); return; } if (L_ECHO(tty)) { -- cgit v1.2.3 From c9b3976e3fec266be25c5001a70aa0a890b6c476 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:44:56 +0000 Subject: tty: Fix PPP hang under load Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/tty_ldisc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c index f307f135cbf..7a84b406a95 100644 --- a/drivers/char/tty_ldisc.c +++ b/drivers/char/tty_ldisc.c @@ -316,8 +316,7 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) { /* wait_event is a macro */ wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); - if (tty->ldisc.refcount == 0) - printk(KERN_ERR "tty_ldisc_ref_wait\n"); + WARN_ON(tty->ldisc.refcount == 0); return &tty->ldisc; } @@ -376,15 +375,17 @@ EXPORT_SYMBOL_GPL(tty_ldisc_deref); * @tty: terminal to activate ldisc on * * Set the TTY_LDISC flag when the line discipline can be called - * again. Do necessary wakeups for existing sleepers. + * again. Do necessary wakeups for existing sleepers. Clear the LDISC + * changing flag to indicate any ldisc change is now over. * - * Note: nobody should set this bit except via this function. Clearing - * directly is allowed. + * Note: nobody should set the TTY_LDISC bit except via this function. + * Clearing directly is allowed. */ void tty_ldisc_enable(struct tty_struct *tty) { set_bit(TTY_LDISC, &tty->flags); + clear_bit(TTY_LDISC_CHANGING, &tty->flags); wake_up(&tty_ldisc_wait); } @@ -496,7 +497,14 @@ restart: * reference to the line discipline. The TTY_LDISC bit * prevents anyone taking a reference once it is clear. * We need the lock to avoid racing reference takers. + * + * We must clear the TTY_LDISC bit here to avoid a livelock + * with a userspace app continually trying to use the tty in + * parallel to the change and re-referencing the tty. */ + clear_bit(TTY_LDISC, &tty->flags); + if (o_tty) + clear_bit(TTY_LDISC, &o_tty->flags); spin_lock_irqsave(&tty_ldisc_lock, flags); if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { @@ -528,7 +536,7 @@ restart: * If the TTY_LDISC bit is set, then we are racing against * another ldisc change */ - if (!test_bit(TTY_LDISC, &tty->flags)) { + if (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { struct tty_ldisc *ld; spin_unlock_irqrestore(&tty_ldisc_lock, flags); tty_ldisc_put(new_ldisc.ops); @@ -536,10 +544,14 @@ restart: tty_ldisc_deref(ld); goto restart; } - - clear_bit(TTY_LDISC, &tty->flags); + /* + * This flag is used to avoid two parallel ldisc changes. Once + * open and close are fine grained locked this may work better + * as a mutex shared with the open/close/hup paths + */ + set_bit(TTY_LDISC_CHANGING, &tty->flags); if (o_tty) - clear_bit(TTY_LDISC, &o_tty->flags); + set_bit(TTY_LDISC_CHANGING, &o_tty->flags); spin_unlock_irqrestore(&tty_ldisc_lock, flags); /* -- cgit v1.2.3 From 31f35939d1d9bcfb3099b32c67b896d2792603f9 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:05 +0000 Subject: tty_port: Add a port level carrier detect operation This is the first step to generalising the various pieces of waiting logic duplicated in all sorts of serial drivers. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/esp.c | 61 ++++++++++++++++++++++++---------------- drivers/char/generic_serial.c | 43 ++++++++++++++-------------- drivers/char/isicom.c | 51 ++++++++++++++++++++------------- drivers/char/istallion.c | 28 +++++++++++++------ drivers/char/moxa.c | 26 +++++++++++++---- drivers/char/mxser.c | 54 +++++++++++++++++++++-------------- drivers/char/rio/rio_linux.c | 18 ++++++------ drivers/char/riscom8.c | 65 ++++++++++++++++++++++++++----------------- drivers/char/rocket.c | 40 ++++++++++++++++---------- drivers/char/ser_a2232.c | 19 +++++++------ drivers/char/stallion.c | 28 ++++++++++++++----- drivers/char/sx.c | 27 +++++++++--------- drivers/char/synclink.c | 61 +++++++++++++++++++++++++++------------- drivers/char/synclink_gt.c | 48 +++++++++++++++++++++----------- drivers/char/synclinkmp.c | 55 +++++++++++++++++++++++------------- drivers/char/tty_port.c | 17 +++++++++++ drivers/char/vme_scc.c | 15 ++++++---- 17 files changed, 418 insertions(+), 238 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/esp.c b/drivers/char/esp.c index 7f077c0097f..45ec263ec01 100644 --- a/drivers/char/esp.c +++ b/drivers/char/esp.c @@ -2054,6 +2054,15 @@ static void esp_hangup(struct tty_struct *tty) wake_up_interruptible(&info->port.open_wait); } +static int esp_carrier_raised(struct tty_port *port) +{ + struct esp_struct *info = container_of(port, struct esp_struct, port); + serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); + if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD) + return 1; + return 0; +} + /* * ------------------------------------------------------------ * esp_open() and friends @@ -2066,17 +2075,19 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, int retval; int do_clocal = 0; unsigned long flags; + int cd; + struct tty_port *port = &info->port; /* * If the device is in the middle of being closed, then block * until it's done, and then try again. */ if (tty_hung_up_p(filp) || - (info->port.flags & ASYNC_CLOSING)) { - if (info->port.flags & ASYNC_CLOSING) - interruptible_sleep_on(&info->port.close_wait); + (port->flags & ASYNC_CLOSING)) { + if (port->flags & ASYNC_CLOSING) + interruptible_sleep_on(&port->close_wait); #ifdef SERIAL_DO_RESTART - if (info->port.flags & ASYNC_HUP_NOTIFY) + if (port->flags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; @@ -2091,7 +2102,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, */ if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -2101,20 +2112,20 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, /* * Block waiting for the carrier detect and the line to become * free (i.e., not in use by the callout). While we are in - * this loop, info->port.count is dropped by one, so that + * this loop, port->count is dropped by one, so that * rs_close() knows when to free things. We restore it upon * exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&info->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); #ifdef SERIAL_DEBUG_OPEN printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n", - info->line, info->port.count); + info->line, port->count); #endif spin_lock_irqsave(&info->lock, flags); if (!tty_hung_up_p(filp)) - info->port.count--; - info->port.blocked_open++; + port->count--; + port->blocked_open++; while (1) { if ((tty->termios->c_cflag & CBAUD)) { unsigned int scratch; @@ -2129,9 +2140,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || - !(info->port.flags & ASYNC_INITIALIZED)) { + !(port->flags & ASYNC_INITIALIZED)) { #ifdef SERIAL_DO_RESTART - if (info->port.flags & ASYNC_HUP_NOTIFY) + if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; @@ -2141,11 +2152,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, break; } - serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); - if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD) - do_clocal = 1; + cd = tty_port_carrier_raised(port); - if (!(info->port.flags & ASYNC_CLOSING) && + if (!(port->flags & ASYNC_CLOSING) && (do_clocal)) break; if (signal_pending(current)) { @@ -2154,25 +2163,25 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } #ifdef SERIAL_DEBUG_OPEN printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n", - info->line, info->port.count); + info->line, port->count); #endif spin_unlock_irqrestore(&info->lock, flags); schedule(); spin_lock_irqsave(&info->lock, flags); } set_current_state(TASK_RUNNING); - remove_wait_queue(&info->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (!tty_hung_up_p(filp)) - info->port.count++; - info->port.blocked_open--; + port->count++; + port->blocked_open--; spin_unlock_irqrestore(&info->lock, flags); #ifdef SERIAL_DEBUG_OPEN printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n", - info->line, info->port.count); + info->line, port->count); #endif if (retval) return retval; - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -2329,6 +2338,10 @@ static const struct tty_operations esp_ops = { .tiocmset = esp_tiocmset, }; +static const struct tty_port_operations esp_port_ops = { + .esp_carrier_raised, +}; + /* * The serial driver boot-time initialization code! */ @@ -2415,6 +2428,8 @@ static int __init espserial_init(void) offset = 0; do { + tty_port_init(&info->port); + info->port.ops = &esp_port_ops; info->io_port = esp[i] + offset; info->irq = irq[i]; info->line = (i * 8) + (offset / 8); @@ -2437,8 +2452,6 @@ static int __init espserial_init(void) info->config.flow_off = flow_off; info->config.pio_threshold = pio_threshold; info->next_port = ports; - init_waitqueue_head(&info->port.open_wait); - init_waitqueue_head(&info->port.close_wait); init_waitqueue_head(&info->delta_msr_wait); init_waitqueue_head(&info->break_wait); ports = info; diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c index c6090f84a2e..2356994ee01 100644 --- a/drivers/char/generic_serial.c +++ b/drivers/char/generic_serial.c @@ -397,7 +397,8 @@ void gs_hangup(struct tty_struct *tty) int gs_block_til_ready(void *port_, struct file * filp) { - struct gs_port *port = port_; + struct gs_port *gp = port_; + struct tty_port *port = &gp->port; DECLARE_WAITQUEUE(wait, current); int retval; int do_clocal = 0; @@ -409,16 +410,16 @@ int gs_block_til_ready(void *port_, struct file * filp) if (!port) return 0; - tty = port->port.tty; + tty = port->tty; gs_dprintk (GS_DEBUG_BTR, "Entering gs_block_till_ready.\n"); /* * If the device is in the middle of being closed, then block * until it's done, and then try again. */ - if (tty_hung_up_p(filp) || port->port.flags & ASYNC_CLOSING) { - interruptible_sleep_on(&port->port.close_wait); - if (port->port.flags & ASYNC_HUP_NOTIFY) + if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { + interruptible_sleep_on(&port->close_wait); + if (port->flags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; @@ -432,7 +433,7 @@ int gs_block_til_ready(void *port_, struct file * filp) */ if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -444,34 +445,34 @@ int gs_block_til_ready(void *port_, struct file * filp) /* * Block waiting for the carrier detect and the line to become * free (i.e., not in use by the callout). While we are in - * this loop, port->port.count is dropped by one, so that + * this loop, port->count is dropped by one, so that * rs_close() knows when to free things. We restore it upon * exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&port->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); gs_dprintk (GS_DEBUG_BTR, "after add waitq.\n"); - spin_lock_irqsave(&port->driver_lock, flags); + spin_lock_irqsave(&gp->driver_lock, flags); if (!tty_hung_up_p(filp)) { - port->port.count--; + port->count--; } - spin_unlock_irqrestore(&port->driver_lock, flags); - port->port.blocked_open++; + spin_unlock_irqrestore(&gp->driver_lock, flags); + port->blocked_open++; while (1) { - CD = port->rd->get_CD (port); + CD = tty_port_carrier_raised(port); gs_dprintk (GS_DEBUG_BTR, "CD is now %d.\n", CD); set_current_state (TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || - !(port->port.flags & ASYNC_INITIALIZED)) { - if (port->port.flags & ASYNC_HUP_NOTIFY) + !(port->flags & ASYNC_INITIALIZED)) { + if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } - if (!(port->port.flags & ASYNC_CLOSING) && + if (!(port->flags & ASYNC_CLOSING) && (do_clocal || CD)) break; gs_dprintk (GS_DEBUG_BTR, "signal_pending is now: %d (%lx)\n", @@ -483,17 +484,17 @@ int gs_block_til_ready(void *port_, struct file * filp) schedule(); } gs_dprintk (GS_DEBUG_BTR, "Got out of the loop. (%d)\n", - port->port.blocked_open); + port->blocked_open); set_current_state (TASK_RUNNING); - remove_wait_queue(&port->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (!tty_hung_up_p(filp)) { - port->port.count++; + port->count++; } - port->port.blocked_open--; + port->blocked_open--; if (retval) return retval; - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; func_exit (); return 0; } diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index 04e4549299b..b3da4858fd4 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c @@ -830,20 +830,28 @@ static int isicom_setup_port(struct tty_struct *tty) return 0; } +static int isicom_carrier_raised(struct tty_port *port) +{ + struct isi_port *ip = container_of(port, struct isi_port, port); + return (ip->status & ISI_DCD)?1 : 0; +} + static int block_til_ready(struct tty_struct *tty, struct file *filp, - struct isi_port *port) + struct isi_port *ip) { - struct isi_board *card = port->card; + struct isi_board *card = ip->card; + struct tty_port *port = &ip->port; int do_clocal = 0, retval; unsigned long flags; DECLARE_WAITQUEUE(wait, current); + int cd; /* block if port is in the process of being closed */ - if (tty_hung_up_p(filp) || port->port.flags & ASYNC_CLOSING) { + if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { pr_dbg("block_til_ready: close in progress.\n"); - interruptible_sleep_on(&port->port.close_wait); - if (port->port.flags & ASYNC_HUP_NOTIFY) + interruptible_sleep_on(&port->close_wait); + if (port->flags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; @@ -854,7 +862,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { pr_dbg("block_til_ready: non-block mode.\n"); - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -864,29 +872,29 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, /* block waiting for DCD to be asserted, and while callout dev is busy */ retval = 0; - add_wait_queue(&port->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); spin_lock_irqsave(&card->card_lock, flags); if (!tty_hung_up_p(filp)) - port->port.count--; - port->port.blocked_open++; + port->count--; + port->blocked_open++; spin_unlock_irqrestore(&card->card_lock, flags); while (1) { - raise_dtr_rts(port); + raise_dtr_rts(ip); set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(port->port.flags & ASYNC_INITIALIZED)) { - if (port->port.flags & ASYNC_HUP_NOTIFY) + if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { + if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } - if (!(port->port.flags & ASYNC_CLOSING) && - (do_clocal || (port->status & ISI_DCD))) { + cd = tty_port_carrier_raised(port); + if (!(port->flags & ASYNC_CLOSING) && + (do_clocal || cd)) break; - } if (signal_pending(current)) { retval = -ERESTARTSYS; break; @@ -894,15 +902,15 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, schedule(); } set_current_state(TASK_RUNNING); - remove_wait_queue(&port->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); spin_lock_irqsave(&card->card_lock, flags); if (!tty_hung_up_p(filp)) - port->port.count++; - port->port.blocked_open--; + port->count++; + port->blocked_open--; spin_unlock_irqrestore(&card->card_lock, flags); if (retval) return retval; - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -1452,6 +1460,10 @@ static const struct tty_operations isicom_ops = { .break_ctl = isicom_send_break, }; +static const struct tty_port_operations isicom_port_ops = { + .carrier_raised = isicom_carrier_raised, +}; + static int __devinit reset_card(struct pci_dev *pdev, const unsigned int card, unsigned int *signature) { @@ -1794,6 +1806,7 @@ static int __init isicom_init(void) spin_lock_init(&isi_card[idx].card_lock); for (channel = 0; channel < 16; channel++, port++) { tty_port_init(&port->port); + port->port.ops = &isicom_port_ops; port->magic = ISICOM_MAGIC; port->card = &isi_card[idx]; port->channel = channel; diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c index 4b10770fa93..c4682f9e34b 100644 --- a/drivers/char/istallion.c +++ b/drivers/char/istallion.c @@ -151,7 +151,7 @@ static char *stli_drvversion = "5.6.0"; static char *stli_serialname = "ttyE"; static struct tty_driver *stli_serial; - +static const struct tty_port_operations stli_port_ops; #define STLI_TXBUFSIZE 4096 @@ -1183,6 +1183,12 @@ static int stli_setport(struct tty_struct *tty) /*****************************************************************************/ +static int stli_carrier_raised(struct tty_port *port) +{ + struct stliport *portp = container_of(port, struct stliport, port); + return (portp->sigs & TIOCM_CD) ? 1 : 0; +} + /* * Possibly need to wait for carrier (DCD signal) to come high. Say * maybe because if we are clocal then we don't need to wait... @@ -1193,6 +1199,7 @@ static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp, { unsigned long flags; int rc, doclocal; + struct tty_port *port = &portp->port; rc = 0; doclocal = 0; @@ -1203,7 +1210,7 @@ static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp, spin_lock_irqsave(&stli_lock, flags); portp->openwaitcnt++; if (! tty_hung_up_p(filp)) - portp->port.count--; + port->count--; spin_unlock_irqrestore(&stli_lock, flags); for (;;) { @@ -1212,27 +1219,27 @@ static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp, &portp->asig, sizeof(asysigs_t), 0)) < 0) break; if (tty_hung_up_p(filp) || - ((portp->port.flags & ASYNC_INITIALIZED) == 0)) { - if (portp->port.flags & ASYNC_HUP_NOTIFY) + ((port->flags & ASYNC_INITIALIZED) == 0)) { + if (port->flags & ASYNC_HUP_NOTIFY) rc = -EBUSY; else rc = -ERESTARTSYS; break; } - if (((portp->port.flags & ASYNC_CLOSING) == 0) && - (doclocal || (portp->sigs & TIOCM_CD))) { + if (((port->flags & ASYNC_CLOSING) == 0) && + (doclocal || tty_port_carrier_raised(port))) { break; } if (signal_pending(current)) { rc = -ERESTARTSYS; break; } - interruptible_sleep_on(&portp->port.open_wait); + interruptible_sleep_on(&port->open_wait); } spin_lock_irqsave(&stli_lock, flags); if (! tty_hung_up_p(filp)) - portp->port.count++; + port->count++; portp->openwaitcnt--; spin_unlock_irqrestore(&stli_lock, flags); @@ -2696,6 +2703,7 @@ static int stli_initports(struct stlibrd *brdp) continue; } tty_port_init(&portp->port); + portp->port.ops = &stli_port_ops; portp->magic = STLI_PORTMAGIC; portp->portnr = i; portp->brdnr = brdp->brdnr; @@ -4518,6 +4526,10 @@ static const struct tty_operations stli_ops = { .tiocmset = stli_tiocmset, }; +static const struct tty_port_operations stli_port_ops = { + .carrier_raised = stli_carrier_raised, +}; + /*****************************************************************************/ /* * Loadable module initialization stuff. diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index 12d327a2c9b..8b0da97d529 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c @@ -206,6 +206,7 @@ static void moxa_poll(unsigned long); static void moxa_set_tty_param(struct tty_struct *, struct ktermios *); static void moxa_setup_empty_event(struct tty_struct *); static void moxa_shut_down(struct tty_struct *); +static int moxa_carrier_raised(struct tty_port *); /* * moxa board interface functions: */ @@ -405,6 +406,10 @@ static const struct tty_operations moxa_ops = { .tiocmset = moxa_tiocmset, }; +static const struct tty_port_operations moxa_port_ops = { + .carrier_raised = moxa_carrier_raised, +}; + static struct tty_driver *moxaDriver; static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); static DEFINE_SPINLOCK(moxa_lock); @@ -826,6 +831,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev) for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) { tty_port_init(&p->port); + p->port.ops = &moxa_port_ops; p->type = PORT_16550A; p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; } @@ -1115,15 +1121,27 @@ static void moxa_close_port(struct tty_struct *tty) tty_port_tty_set(&ch->port, NULL); } +static int moxa_carrier_raised(struct tty_port *port) +{ + struct moxa_port *ch = container_of(port, struct moxa_port, port); + int dcd; + + spin_lock_bh(&moxa_lock); + dcd = ch->DCDState; + spin_unlock_bh(&moxa_lock); + return dcd; +} + static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, struct moxa_port *ch) { + struct tty_port *port = &ch->port; DEFINE_WAIT(wait); int retval = 0; u8 dcd; while (1) { - prepare_to_wait(&ch->port.open_wait, &wait, TASK_INTERRUPTIBLE); + prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp)) { #ifdef SERIAL_DO_RESTART retval = -ERESTARTSYS; @@ -1132,9 +1150,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, #endif break; } - spin_lock_bh(&moxa_lock); - dcd = ch->DCDState; - spin_unlock_bh(&moxa_lock); + dcd = tty_port_carrier_raised(port); if (dcd) break; @@ -1144,7 +1160,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, } schedule(); } - finish_wait(&ch->port.open_wait, &wait); + finish_wait(&port->open_wait, &wait); return retval; } diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index 04776691541..eafbbcf355e 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -541,13 +541,21 @@ static unsigned char mxser_get_msr(int baseaddr, int mode, int port) return status; } +static int mxser_carrier_raised(struct tty_port *port) +{ + struct mxser_port *mp = container_of(port, struct mxser_port, port); + return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; +} + static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, - struct mxser_port *port) + struct mxser_port *mp) { DECLARE_WAITQUEUE(wait, current); int retval; int do_clocal = 0; unsigned long flags; + int cd; + struct tty_port *port = &mp->port; /* * If non-blocking mode is set, or the port is not enabled, @@ -555,7 +563,7 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, */ if ((filp->f_flags & O_NONBLOCK) || test_bit(TTY_IO_ERROR, &tty->flags)) { - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -565,34 +573,33 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, /* * Block waiting for the carrier detect and the line to become * free (i.e., not in use by the callout). While we are in - * this loop, port->port.count is dropped by one, so that + * this loop, port->count is dropped by one, so that * mxser_close() knows when to free things. We restore it upon * exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&port->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&port->slock, flags); + spin_lock_irqsave(&mp->slock, flags); if (!tty_hung_up_p(filp)) - port->port.count--; - spin_unlock_irqrestore(&port->slock, flags); - port->port.blocked_open++; + port->count--; + spin_unlock_irqrestore(&mp->slock, flags); + port->blocked_open++; while (1) { - spin_lock_irqsave(&port->slock, flags); - outb(inb(port->ioaddr + UART_MCR) | - UART_MCR_DTR | UART_MCR_RTS, port->ioaddr + UART_MCR); - spin_unlock_irqrestore(&port->slock, flags); + spin_lock_irqsave(&mp->slock, flags); + outb(inb(mp->ioaddr + UART_MCR) | + UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); + spin_unlock_irqrestore(&mp->slock, flags); set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(port->port.flags & ASYNC_INITIALIZED)) { - if (port->port.flags & ASYNC_HUP_NOTIFY) + if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { + if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } - if (!(port->port.flags & ASYNC_CLOSING) && - (do_clocal || - (inb(port->ioaddr + UART_MSR) & UART_MSR_DCD))) + cd = tty_port_carrier_raised(port); + if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd)) break; if (signal_pending(current)) { retval = -ERESTARTSYS; @@ -601,13 +608,13 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, schedule(); } set_current_state(TASK_RUNNING); - remove_wait_queue(&port->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (!tty_hung_up_p(filp)) - port->port.count++; - port->port.blocked_open--; + port->count++; + port->blocked_open--; if (retval) return retval; - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -2449,6 +2456,10 @@ static const struct tty_operations mxser_ops = { .tiocmset = mxser_tiocmset, }; +struct tty_port_operations mxser_port_ops = { + .carrier_raised = mxser_carrier_raised, +}; + /* * The MOXA Smartio/Industio serial driver boot-time initialization code! */ @@ -2482,6 +2493,7 @@ static int __devinit mxser_initbrd(struct mxser_board *brd, for (i = 0; i < brd->info->nports; i++) { info = &brd->ports[i]; tty_port_init(&info->port); + info->port.ops = &mxser_port_ops; info->board = brd; info->stop_rx = 0; info->ldisc_stop_rx = 0; diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c index a8f68a3f14d..ec2afd13947 100644 --- a/drivers/char/rio/rio_linux.c +++ b/drivers/char/rio/rio_linux.c @@ -173,7 +173,7 @@ static void rio_disable_tx_interrupts(void *ptr); static void rio_enable_tx_interrupts(void *ptr); static void rio_disable_rx_interrupts(void *ptr); static void rio_enable_rx_interrupts(void *ptr); -static int rio_get_CD(void *ptr); +static int rio_carrier_raised(struct tty_port *port); static void rio_shutdown_port(void *ptr); static int rio_set_real_termios(void *ptr); static void rio_hungup(void *ptr); @@ -224,7 +224,6 @@ static struct real_driver rio_real_driver = { rio_enable_tx_interrupts, rio_disable_rx_interrupts, rio_enable_rx_interrupts, - rio_get_CD, rio_shutdown_port, rio_set_real_termios, rio_chars_in_buffer, @@ -476,9 +475,9 @@ static void rio_enable_rx_interrupts(void *ptr) /* Jeez. Isn't this simple? */ -static int rio_get_CD(void *ptr) +static int rio_carrier_raised(struct tty_port *port) { - struct Port *PortP = ptr; + struct Port *PortP = container_of(port, struct Port, gs.port); int rv; func_enter(); @@ -806,7 +805,9 @@ static void *ckmalloc(int size) return p; } - +static const struct tty_port_operations rio_port_ops = { + .carrier_raised = rio_carrier_raised, +}; static int rio_init_datastructures(void) { @@ -842,17 +843,14 @@ static int rio_init_datastructures(void) goto free6; } rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped); + tty_port_init(&port->gs.port); + port->gs.port.ops = &rio_port_ops; port->PortNum = i; port->gs.magic = RIO_MAGIC; port->gs.close_delay = HZ / 2; port->gs.closing_wait = 30 * HZ; port->gs.rd = &rio_real_driver; spin_lock_init(&port->portSem); - /* - * Initializing wait queue - */ - init_waitqueue_head(&port->gs.port.open_wait); - init_waitqueue_head(&port->gs.port.close_wait); } #else /* We could postpone initializing them to when they are configured. */ diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c index 2c6c8f33d6b..6ad1c2aa2a9 100644 --- a/drivers/char/riscom8.c +++ b/drivers/char/riscom8.c @@ -857,23 +857,40 @@ static void rc_shutdown_port(struct tty_struct *tty, rc_shutdown_board(bp); } +static int carrier_raised(struct tty_port *port) +{ + struct riscom_port *p = container_of(port, struct riscom_port, port); + struct riscom_board *bp = port_Board(p); + unsigned long flags; + int CD; + + spin_lock_irqsave(&riscom_lock, flags); + rc_out(bp, CD180_CAR, port_No(p)); + CD = rc_in(bp, CD180_MSVR) & MSVR_CD; + rc_out(bp, CD180_MSVR, MSVR_RTS); + bp->DTR &= ~(1u << port_No(p)); + rc_out(bp, RC_DTR, bp->DTR); + spin_unlock_irqrestore(&riscom_lock, flags); + return CD; +} + static int block_til_ready(struct tty_struct *tty, struct file *filp, - struct riscom_port *port) + struct riscom_port *rp) { DECLARE_WAITQUEUE(wait, current); - struct riscom_board *bp = port_Board(port); int retval; int do_clocal = 0; int CD; unsigned long flags; + struct tty_port *port = &rp->port; /* * If the device is in the middle of being closed, then block * until it's done, and then try again. */ - if (tty_hung_up_p(filp) || port->port.flags & ASYNC_CLOSING) { - interruptible_sleep_on(&port->port.close_wait); - if (port->port.flags & ASYNC_HUP_NOTIFY) + if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { + interruptible_sleep_on(&port->close_wait); + if (port->flags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; @@ -885,7 +902,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, */ if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -900,37 +917,29 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, * exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&port->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); spin_lock_irqsave(&riscom_lock, flags); if (!tty_hung_up_p(filp)) - port->port.count--; + port->count--; spin_unlock_irqrestore(&riscom_lock, flags); - port->port.blocked_open++; + port->blocked_open++; while (1) { - spin_lock_irqsave(&riscom_lock, flags); - - rc_out(bp, CD180_CAR, port_No(port)); - CD = rc_in(bp, CD180_MSVR) & MSVR_CD; - rc_out(bp, CD180_MSVR, MSVR_RTS); - bp->DTR &= ~(1u << port_No(port)); - rc_out(bp, RC_DTR, bp->DTR); - - spin_unlock_irqrestore(&riscom_lock, flags); + CD = tty_port_carrier_raised(port); set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || - !(port->port.flags & ASYNC_INITIALIZED)) { - if (port->port.flags & ASYNC_HUP_NOTIFY) + !(port->flags & ASYNC_INITIALIZED)) { + if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } - if (!(port->port.flags & ASYNC_CLOSING) && + if (!(port->flags & ASYNC_CLOSING) && (do_clocal || CD)) break; if (signal_pending(current)) { @@ -940,14 +949,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, schedule(); } __set_current_state(TASK_RUNNING); - remove_wait_queue(&port->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (!tty_hung_up_p(filp)) - port->port.count++; - port->port.blocked_open--; + port->count++; + port->blocked_open--; if (retval) return retval; - port->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -1510,6 +1519,11 @@ static const struct tty_operations riscom_ops = { .break_ctl = rc_send_break, }; +static const struct tty_port_operations riscom_port_ops = { + .carrier_raised = carrier_raised, +}; + + static int __init rc_init_drivers(void) { int error; @@ -1541,6 +1555,7 @@ static int __init rc_init_drivers(void) memset(rc_port, 0, sizeof(rc_port)); for (i = 0; i < RC_NPORT * RC_NBOARD; i++) { tty_port_init(&rc_port[i].port); + rc_port[i].port.ops = &riscom_port_ops; rc_port[i].magic = RISCOM8_MAGIC; } return 0; diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index 584d791e84a..4a4110e703a 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -135,6 +135,7 @@ static int rcktpt_type[NUM_BOARDS]; static int is_PCI[NUM_BOARDS]; static rocketModel_t rocketModel[NUM_BOARDS]; static int max_board; +static const struct tty_port_operations rocket_port_ops; /* * The following arrays define the interrupt bits corresponding to each AIOP. @@ -649,9 +650,8 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev) info->board = board; info->aiop = aiop; info->chan = chan; - info->port.closing_wait = 3000; - info->port.close_delay = 50; - init_waitqueue_head(&info->port.open_wait); + tty_port_init(&info->port); + info->port.ops = &rocket_port_ops; init_completion(&info->close_wait); info->flags &= ~ROCKET_MODE_MASK; switch (pc104[board][line]) { @@ -864,11 +864,18 @@ static void configure_r_port(struct r_port *info, } } +static int carrier_raised(struct tty_port *port) +{ + struct r_port *info = container_of(port, struct r_port, port); + return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; +} + /* info->port.count is considered critical, protected by spinlocks. */ static int block_til_ready(struct tty_struct *tty, struct file *filp, struct r_port *info) { DECLARE_WAITQUEUE(wait, current); + struct tty_port *port = &info->port; int retval; int do_clocal = 0, extra_count = 0; unsigned long flags; @@ -898,13 +905,13 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, /* * Block waiting for the carrier detect and the line to become free. While we are in - * this loop, info->port.count is dropped by one, so that rp_close() knows when to free things. + * this loop, port->count is dropped by one, so that rp_close() knows when to free things. * We restore it upon exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&info->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); #ifdef ROCKET_DEBUG_OPEN - printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, info->port.count); + printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, port->count); #endif spin_lock_irqsave(&info->slock, flags); @@ -913,10 +920,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, #else if (!tty_hung_up_p(filp)) { extra_count = 1; - info->port.count--; + port->count--; } #endif - info->port.blocked_open++; + port->blocked_open++; spin_unlock_irqrestore(&info->slock, flags); @@ -933,7 +940,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, retval = -ERESTARTSYS; break; } - if (!(info->flags & ROCKET_CLOSING) && (do_clocal || (sGetChanStatusLo(&info->channel) & CD_ACT))) + if (!(info->flags & ROCKET_CLOSING) && + (do_clocal || tty_port_carrier_raised(port))) break; if (signal_pending(current)) { retval = -ERESTARTSYS; @@ -941,24 +949,24 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } #ifdef ROCKET_DEBUG_OPEN printk(KERN_INFO "block_til_ready blocking: ttyR%d, count = %d, flags=0x%0x\n", - info->line, info->port.count, info->flags); + info->line, port->count, info->flags); #endif schedule(); /* Don't hold spinlock here, will hang PC */ } __set_current_state(TASK_RUNNING); - remove_wait_queue(&info->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); spin_lock_irqsave(&info->slock, flags); if (extra_count) - info->port.count++; - info->port.blocked_open--; + port->count++; + port->blocked_open--; spin_unlock_irqrestore(&info->slock, flags); #ifdef ROCKET_DEBUG_OPEN printk(KERN_INFO "block_til_ready after blocking: ttyR%d, count = %d\n", - info->line, info->port.count); + info->line, port->count); #endif if (retval) return retval; @@ -2371,6 +2379,10 @@ static const struct tty_operations rocket_ops = { .tiocmset = rp_tiocmset, }; +static const struct tty_port_operations rocket_port_ops = { + .carrier_raised = carrier_raised, +}; + /* * The module "startup" routine; it's run when the module is loaded. */ diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c index 7b0c35207d9..0c97f34df63 100644 --- a/drivers/char/ser_a2232.c +++ b/drivers/char/ser_a2232.c @@ -122,7 +122,7 @@ static void a2232_disable_tx_interrupts(void *ptr); static void a2232_enable_tx_interrupts(void *ptr); static void a2232_disable_rx_interrupts(void *ptr); static void a2232_enable_rx_interrupts(void *ptr); -static int a2232_get_CD(void *ptr); +static int a2232_carrier_raised(struct tty_port *port); static void a2232_shutdown_port(void *ptr); static int a2232_set_real_termios(void *ptr); static int a2232_chars_in_buffer(void *ptr); @@ -148,7 +148,6 @@ static struct real_driver a2232_real_driver = { a2232_enable_tx_interrupts, a2232_disable_rx_interrupts, a2232_enable_rx_interrupts, - a2232_get_CD, a2232_shutdown_port, a2232_set_real_termios, a2232_chars_in_buffer, @@ -260,9 +259,10 @@ static void a2232_enable_rx_interrupts(void *ptr) port->disable_rx = 0; } -static int a2232_get_CD(void *ptr) +static int a2232_carrier_raised(struct tty_port *port) { - return ((struct a2232_port *) ptr)->cd_status; + struct a2232_port *ap = container_of(port, struct a2232_port, gs.port); + return ap->cd_status; } static void a2232_shutdown_port(void *ptr) @@ -638,6 +638,10 @@ int ch, err, n, p; return IRQ_HANDLED; } +static const struct tty_port_operations a2232_port_ops = { + .carrier_raised = a2232_carrier_raised, +}; + static void a2232_init_portstructs(void) { struct a2232_port *port; @@ -645,6 +649,8 @@ static void a2232_init_portstructs(void) for (i = 0; i < MAX_A2232_BOARDS*NUMLINES; i++) { port = a2232_ports + i; + tty_port_init(&port->gs.port); + port->gs.port.ops = &a2232_port_ops; port->which_a2232 = i/NUMLINES; port->which_port_on_a2232 = i%NUMLINES; port->disable_rx = port->throttle_input = port->cd_status = 0; @@ -652,11 +658,6 @@ static void a2232_init_portstructs(void) port->gs.close_delay = HZ/2; port->gs.closing_wait = 30 * HZ; port->gs.rd = &a2232_real_driver; -#ifdef NEW_WRITE_LOCKING - mutex_init(&(port->gs.port_write_mutex)); -#endif - init_waitqueue_head(&port->gs.port.open_wait); - init_waitqueue_head(&port->gs.port.close_wait); } } diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c index 963b03fb29e..12aecdaf61e 100644 --- a/drivers/char/stallion.c +++ b/drivers/char/stallion.c @@ -130,6 +130,8 @@ static char stl_unwanted[SC26198_RXFIFOSIZE]; static DEFINE_MUTEX(stl_brdslock); static struct stlbrd *stl_brds[STL_MAXBRDS]; +static const struct tty_port_operations stl_port_ops; + /* * Per board state flags. Used with the state field of the board struct. * Not really much here! @@ -786,6 +788,12 @@ static int stl_open(struct tty_struct *tty, struct file *filp) /*****************************************************************************/ +static int stl_carrier_raised(struct tty_port *port) +{ + struct stlport *portp = container_of(port, struct stlport, port); + return (portp->sigs & TIOCM_CD) ? 1 : 0; +} + /* * Possibly need to wait for carrier (DCD signal) to come high. Say * maybe because if we are clocal then we don't need to wait... @@ -796,6 +804,7 @@ static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, { unsigned long flags; int rc, doclocal; + struct tty_port *port = &portp->port; pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp); @@ -809,32 +818,32 @@ static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, portp->openwaitcnt++; if (! tty_hung_up_p(filp)) - portp->port.count--; + port->count--; for (;;) { /* Takes brd_lock internally */ stl_setsignals(portp, 1, 1); if (tty_hung_up_p(filp) || - ((portp->port.flags & ASYNC_INITIALIZED) == 0)) { - if (portp->port.flags & ASYNC_HUP_NOTIFY) + ((port->flags & ASYNC_INITIALIZED) == 0)) { + if (port->flags & ASYNC_HUP_NOTIFY) rc = -EBUSY; else rc = -ERESTARTSYS; break; } - if (((portp->port.flags & ASYNC_CLOSING) == 0) && - (doclocal || (portp->sigs & TIOCM_CD))) + if (((port->flags & ASYNC_CLOSING) == 0) && + (doclocal || tty_port_carrier_raised(port))) break; if (signal_pending(current)) { rc = -ERESTARTSYS; break; } /* FIXME */ - interruptible_sleep_on(&portp->port.open_wait); + interruptible_sleep_on(&port->open_wait); } if (! tty_hung_up_p(filp)) - portp->port.count++; + port->count++; portp->openwaitcnt--; spin_unlock_irqrestore(&stallion_lock, flags); @@ -1776,6 +1785,7 @@ static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp) break; } tty_port_init(&portp->port); + portp->port.ops = &stl_port_ops; portp->magic = STL_PORTMAGIC; portp->portnr = i; portp->brdnr = panelp->brdnr; @@ -2659,6 +2669,10 @@ static const struct tty_operations stl_ops = { .tiocmset = stl_tiocmset, }; +static const struct tty_port_operations stl_port_ops = { + .carrier_raised = stl_carrier_raised, +}; + /*****************************************************************************/ /* CD1400 HARDWARE FUNCTIONS */ /*****************************************************************************/ diff --git a/drivers/char/sx.c b/drivers/char/sx.c index ba4e86281fb..a71bc58abe7 100644 --- a/drivers/char/sx.c +++ b/drivers/char/sx.c @@ -279,7 +279,7 @@ static void sx_disable_tx_interrupts(void *ptr); static void sx_enable_tx_interrupts(void *ptr); static void sx_disable_rx_interrupts(void *ptr); static void sx_enable_rx_interrupts(void *ptr); -static int sx_get_CD(void *ptr); +static int sx_carrier_raised(struct tty_port *port); static void sx_shutdown_port(void *ptr); static int sx_set_real_termios(void *ptr); static void sx_close(void *ptr); @@ -360,7 +360,6 @@ static struct real_driver sx_real_driver = { sx_enable_tx_interrupts, sx_disable_rx_interrupts, sx_enable_rx_interrupts, - sx_get_CD, sx_shutdown_port, sx_set_real_termios, sx_chars_in_buffer, @@ -791,7 +790,7 @@ static int sx_getsignals(struct sx_port *port) sx_dprintk(SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) " "%02x/%02x\n", (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0, - port->c_dcd, sx_get_CD(port), + port->c_dcd, tty_port_carrier_raised(&port->gs.port), sx_read_channel_byte(port, hi_ip), sx_read_channel_byte(port, hi_state)); @@ -1190,7 +1189,7 @@ static inline void sx_check_modem_signals(struct sx_port *port) hi_state = sx_read_channel_byte(port, hi_state); sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n", - port->c_dcd, sx_get_CD(port)); + port->c_dcd, tty_port_carrier_raised(&port->gs.port)); if (hi_state & ST_BREAK) { hi_state &= ~ST_BREAK; @@ -1202,11 +1201,11 @@ static inline void sx_check_modem_signals(struct sx_port *port) hi_state &= ~ST_DCD; sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n"); sx_write_channel_byte(port, hi_state, hi_state); - c_dcd = sx_get_CD(port); + c_dcd = tty_port_carrier_raised(&port->gs.port); sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd); if (c_dcd != port->c_dcd) { port->c_dcd = c_dcd; - if (sx_get_CD(port)) { + if (tty_port_carrier_raised(&port->gs.port)) { /* DCD went UP */ if ((sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) && @@ -1415,13 +1414,10 @@ static void sx_enable_rx_interrupts(void *ptr) } /* Jeez. Isn't this simple? */ -static int sx_get_CD(void *ptr) +static int sx_carrier_raised(struct tty_port *port) { - struct sx_port *port = ptr; - func_enter2(); - - func_exit(); - return ((sx_read_channel_byte(port, hi_ip) & IP_DCD) != 0); + struct sx_port *sp = container_of(port, struct sx_port, gs.port); + return ((sx_read_channel_byte(sp, hi_ip) & IP_DCD) != 0); } /* Jeez. Isn't this simple? */ @@ -1536,7 +1532,7 @@ static int sx_open(struct tty_struct *tty, struct file *filp) } /* tty->low_latency = 1; */ - port->c_dcd = sx_get_CD(port); + port->c_dcd = sx_carrier_raised(&port->gs.port); sx_dprintk(SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd); func_exit(); @@ -2354,6 +2350,10 @@ static const struct tty_operations sx_ops = { .tiocmset = sx_tiocmset, }; +static const struct tty_port_operations sx_port_ops = { + .carrier_raised = sx_carrier_raised, +}; + static int sx_init_drivers(void) { int error; @@ -2410,6 +2410,7 @@ static int sx_init_portstructs(int nboards, int nports) for (j = 0; j < boards[i].nports; j++) { sx_dprintk(SX_DEBUG_INIT, "initing port %d\n", j); tty_port_init(&port->gs.port); + port->gs.port.ops = &sx_port_ops; port->gs.magic = SX_MAGIC; port->gs.close_delay = HZ / 2; port->gs.closing_wait = 30 * HZ; diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index 500f5176b6b..fb2e6b5e0ef 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c @@ -3281,6 +3281,23 @@ static void mgsl_hangup(struct tty_struct *tty) } /* end of mgsl_hangup() */ +/* + * carrier_raised() + * + * Return true if carrier is raised + */ + +static int carrier_raised(struct tty_port *port) +{ + unsigned long flags; + struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); + + spin_lock_irqsave(&info->irq_spinlock, flags); + usc_get_serial_signals(info); + spin_unlock_irqrestore(&info->irq_spinlock, flags); + return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; +} + /* block_til_ready() * * Block the current process until the specified port @@ -3302,6 +3319,8 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, bool do_clocal = false; bool extra_count = false; unsigned long flags; + int dcd; + struct tty_port *port = &info->port; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):block_til_ready on %s\n", @@ -3309,7 +3328,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ /* nonblock mode is set or port is not enabled */ - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -3318,25 +3337,25 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, /* Wait for carrier detect and the line to become * free (i.e., not in use by the callout). While we are in - * this loop, info->port.count is dropped by one, so that + * this loop, port->count is dropped by one, so that * mgsl_close() knows when to free things. We restore it upon * exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&info->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):block_til_ready before block on %s count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->port.count ); + __FILE__,__LINE__, tty->driver->name, port->count ); spin_lock_irqsave(&info->irq_spinlock, flags); if (!tty_hung_up_p(filp)) { extra_count = true; - info->port.count--; + port->count--; } spin_unlock_irqrestore(&info->irq_spinlock, flags); - info->port.blocked_open++; + port->blocked_open++; while (1) { if (tty->termios->c_cflag & CBAUD) { @@ -3348,20 +3367,16 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)){ - retval = (info->port.flags & ASYNC_HUP_NOTIFY) ? + if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){ + retval = (port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS; break; } - spin_lock_irqsave(&info->irq_spinlock,flags); - usc_get_serial_signals(info); - spin_unlock_irqrestore(&info->irq_spinlock,flags); + dcd = tty_port_carrier_raised(&info->port); - if (!(info->port.flags & ASYNC_CLOSING) && - (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) { + if (!(port->flags & ASYNC_CLOSING) && (do_clocal || dcd)) break; - } if (signal_pending(current)) { retval = -ERESTARTSYS; @@ -3370,24 +3385,24 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):block_til_ready blocking on %s count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->port.count ); + __FILE__,__LINE__, tty->driver->name, port->count ); schedule(); } set_current_state(TASK_RUNNING); - remove_wait_queue(&info->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (extra_count) - info->port.count++; - info->port.blocked_open--; + port->count++; + port->blocked_open--; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):block_til_ready after blocking on %s count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->port.count ); + __FILE__,__LINE__, tty->driver->name, port->count ); if (!retval) - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return retval; @@ -4304,6 +4319,11 @@ static void mgsl_add_device( struct mgsl_struct *info ) } /* end of mgsl_add_device() */ +static const struct tty_port_operations mgsl_port_ops = { + .carrier_raised = carrier_raised, +}; + + /* mgsl_allocate_device() * * Allocate and initialize a device instance structure @@ -4322,6 +4342,7 @@ static struct mgsl_struct* mgsl_allocate_device(void) printk("Error can't allocate device instance data\n"); } else { tty_port_init(&info->port); + info->port.ops = &mgsl_port_ops; info->magic = MGSL_MAGIC; INIT_WORK(&info->task, mgsl_bh_handler); info->max_frame_size = 4096; diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index 08911ed6649..39ccaba8ca3 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c @@ -3132,6 +3132,17 @@ static int tiocmset(struct tty_struct *tty, struct file *file, return 0; } +static int carrier_raised(struct tty_port *port) +{ + unsigned long flags; + struct slgt_info *info = container_of(port, struct slgt_info, port); + + spin_lock_irqsave(&info->lock,flags); + get_signals(info); + spin_unlock_irqrestore(&info->lock,flags); + return (info->signals & SerialSignal_DCD) ? 1 : 0; +} + /* * block current process until the device is ready to open */ @@ -3143,12 +3154,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, bool do_clocal = false; bool extra_count = false; unsigned long flags; + int cd; + struct tty_port *port = &info->port; DBGINFO(("%s block_til_ready\n", tty->driver->name)); if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ /* nonblock mode is set or port is not enabled */ - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -3157,21 +3170,21 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, /* Wait for carrier detect and the line to become * free (i.e., not in use by the callout). While we are in - * this loop, info->port.count is dropped by one, so that + * this loop, port->count is dropped by one, so that * close() knows when to free things. We restore it upon * exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&info->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); spin_lock_irqsave(&info->lock, flags); if (!tty_hung_up_p(filp)) { extra_count = true; - info->port.count--; + port->count--; } spin_unlock_irqrestore(&info->lock, flags); - info->port.blocked_open++; + port->blocked_open++; while (1) { if ((tty->termios->c_cflag & CBAUD)) { @@ -3183,20 +3196,16 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)){ - retval = (info->port.flags & ASYNC_HUP_NOTIFY) ? + if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){ + retval = (port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS; break; } - spin_lock_irqsave(&info->lock,flags); - get_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + cd = tty_port_carrier_raised(port); - if (!(info->port.flags & ASYNC_CLOSING) && - (do_clocal || (info->signals & SerialSignal_DCD)) ) { + if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd )) break; - } if (signal_pending(current)) { retval = -ERESTARTSYS; @@ -3208,14 +3217,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } set_current_state(TASK_RUNNING); - remove_wait_queue(&info->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (extra_count) - info->port.count++; - info->port.blocked_open--; + port->count++; + port->blocked_open--; if (!retval) - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval)); return retval; @@ -3444,6 +3453,10 @@ static void add_device(struct slgt_info *info) #endif } +static const struct tty_port_operations slgt_port_ops = { + .carrier_raised = carrier_raised, +}; + /* * allocate device instance structure, return NULL on failure */ @@ -3458,6 +3471,7 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev driver_name, adapter_num, port_num)); } else { tty_port_init(&info->port); + info->port.ops = &slgt_port_ops; info->magic = MGSL_MAGIC; INIT_WORK(&info->task, bh_handler); info->max_frame_size = 4096; diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index 6bdb44f7bec..fcf1ec77450 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c @@ -558,6 +558,7 @@ static void release_resources(SLMP_INFO *info); static int startup(SLMP_INFO *info); static int block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info); +static int carrier_raised(struct tty_port *port); static void shutdown(SLMP_INFO *info); static void program_hw(SLMP_INFO *info); static void change_params(SLMP_INFO *info); @@ -3318,7 +3319,17 @@ static int tiocmset(struct tty_struct *tty, struct file *file, return 0; } +static int carrier_raised(struct tty_port *port) +{ + SLMP_INFO *info = container_of(port, SLMP_INFO, port); + unsigned long flags; + spin_lock_irqsave(&info->lock,flags); + get_signals(info); + spin_unlock_irqrestore(&info->lock,flags); + + return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; +} /* Block the current process until the specified port is ready to open. */ @@ -3330,6 +3341,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, bool do_clocal = false; bool extra_count = false; unsigned long flags; + int cd; + struct tty_port *port = &info->port; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s block_til_ready()\n", @@ -3338,7 +3351,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ /* nonblock mode is set or port is not enabled */ /* just verify that callout device is not active */ - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -3347,25 +3360,25 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, /* Wait for carrier detect and the line to become * free (i.e., not in use by the callout). While we are in - * this loop, info->port.count is dropped by one, so that + * this loop, port->count is dropped by one, so that * close() knows when to free things. We restore it upon * exit, either normal or abnormal. */ retval = 0; - add_wait_queue(&info->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s block_til_ready() before block, count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->port.count ); + __FILE__,__LINE__, tty->driver->name, port->count ); spin_lock_irqsave(&info->lock, flags); if (!tty_hung_up_p(filp)) { extra_count = true; - info->port.count--; + port->count--; } spin_unlock_irqrestore(&info->lock, flags); - info->port.blocked_open++; + port->blocked_open++; while (1) { if ((tty->termios->c_cflag & CBAUD)) { @@ -3377,20 +3390,16 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)){ - retval = (info->port.flags & ASYNC_HUP_NOTIFY) ? + if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){ + retval = (port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS; break; } - spin_lock_irqsave(&info->lock,flags); - get_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + cd = tty_port_carrier_raised(port); - if (!(info->port.flags & ASYNC_CLOSING) && - (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) { + if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd)) break; - } if (signal_pending(current)) { retval = -ERESTARTSYS; @@ -3399,24 +3408,24 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s block_til_ready() count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->port.count ); + __FILE__,__LINE__, tty->driver->name, port->count ); schedule(); } set_current_state(TASK_RUNNING); - remove_wait_queue(&info->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (extra_count) - info->port.count++; - info->port.blocked_open--; + port->count++; + port->blocked_open--; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s block_til_ready() after, count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->port.count ); + __FILE__,__LINE__, tty->driver->name, port->count ); if (!retval) - info->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return retval; } @@ -3782,6 +3791,10 @@ static void add_device(SLMP_INFO *info) #endif } +static const struct tty_port_operations port_ops = { + .carrier_raised = carrier_raised, +}; + /* Allocate and initialize a device instance structure * * Return Value: pointer to SLMP_INFO if success, otherwise NULL @@ -3798,6 +3811,7 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev) __FILE__,__LINE__, adapter_num, port_num); } else { tty_port_init(&info->port); + info->port.ops = &port_ops; info->magic = MGSL_MAGIC; INIT_WORK(&info->task, bh_handler); info->max_frame_size = 4096; @@ -3940,6 +3954,7 @@ static const struct tty_operations ops = { .tiocmset = tiocmset, }; + static void synclinkmp_cleanup(void) { int rc; diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index c8f8024cb40..f54e40cbf02 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -94,3 +94,20 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) spin_unlock_irqrestore(&port->lock, flags); } EXPORT_SYMBOL(tty_port_tty_set); + +/** + * tty_port_carrier_raised - carrier raised check + * @port: tty port + * + * Wrapper for the carrier detect logic. For the moment this is used + * to hide some internal details. This will eventually become entirely + * internal to the tty port. + */ + +int tty_port_carrier_raised(struct tty_port *port) +{ + if (port->ops->carrier_raised == NULL) + return 1; + return port->ops->carrier_raised(port); +} +EXPORT_SYMBOL(tty_port_carrier_raised); diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c index 1718b3c481d..d4e1534c0e0 100644 --- a/drivers/char/vme_scc.c +++ b/drivers/char/vme_scc.c @@ -69,7 +69,7 @@ static void scc_disable_tx_interrupts(void * ptr); static void scc_enable_tx_interrupts(void * ptr); static void scc_disable_rx_interrupts(void * ptr); static void scc_enable_rx_interrupts(void * ptr); -static int scc_get_CD(void * ptr); +static int scc_carrier_raised(struct tty_port *port); static void scc_shutdown_port(void * ptr); static int scc_set_real_termios(void *ptr); static void scc_hungup(void *ptr); @@ -100,7 +100,6 @@ static struct real_driver scc_real_driver = { scc_enable_tx_interrupts, scc_disable_rx_interrupts, scc_enable_rx_interrupts, - scc_get_CD, scc_shutdown_port, scc_set_real_termios, scc_chars_in_buffer, @@ -129,6 +128,10 @@ static const struct tty_operations scc_ops = { .break_ctl = scc_break_ctl, }; +static const struct tty_port_operations scc_port_ops = { + .carrier_raised = scc_carrier_raised, +}; + /*---------------------------------------------------------------------------- * vme_scc_init() and support functions *---------------------------------------------------------------------------*/ @@ -176,6 +179,8 @@ static void scc_init_portstructs(void) for (i = 0; i < 2; i++) { port = scc_ports + i; + tty_port_init(&port->gs.port); + port->gs.port.ops = &scc_port_ops; port->gs.magic = SCC_MAGIC; port->gs.close_delay = HZ/2; port->gs.closing_wait = 30 * HZ; @@ -624,9 +629,9 @@ static void scc_enable_rx_interrupts(void *ptr) } -static int scc_get_CD(void *ptr) +static int scc_carrier_raised(struct tty_port *port) { - struct scc_port *port = ptr; + struct scc_port *scc = container_of(port, struct scc_port, gs.port); unsigned channel = port->channel; return !!(scc_last_status_reg[channel] & SR_DCD); @@ -896,7 +901,7 @@ static int scc_open (struct tty_struct * tty, struct file * filp) return retval; } - port->c_dcd = scc_get_CD (port); + port->c_dcd = tty_port_carrier_raised(&port->gs.port); scc_enable_rx_interrupts(port); -- cgit v1.2.3 From d0c9873addc1f18e7becb50094dad07df8cc4694 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:12 +0000 Subject: rio: Kill off ckmalloc This was an alloc/clear wrapper but makes even less sense now it uses kzalloc. Kill it off. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/rio/rio_linux.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c index ec2afd13947..2e8a6eed34b 100644 --- a/drivers/char/rio/rio_linux.c +++ b/drivers/char/rio/rio_linux.c @@ -796,15 +796,6 @@ static int rio_init_drivers(void) return 1; } - -static void *ckmalloc(int size) -{ - void *p; - - p = kzalloc(size, GFP_KERNEL); - return p; -} - static const struct tty_port_operations rio_port_ops = { .carrier_raised = rio_carrier_raised, }; @@ -827,18 +818,18 @@ static int rio_init_datastructures(void) #define TMIO_SZ sizeof(struct termios *) rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ); - if (!(p = ckmalloc(RI_SZ))) + if (!(p = kzalloc(RI_SZ, GFP_KERNEL))) goto free0; - if (!(p->RIOHosts = ckmalloc(RIO_HOSTS * HOST_SZ))) + if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL))) goto free1; - if (!(p->RIOPortp = ckmalloc(RIO_PORTS * PORT_SZ))) + if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL))) goto free2; p->RIOConf = RIOConf; rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp); #if 1 for (i = 0; i < RIO_PORTS; i++) { - port = p->RIOPortp[i] = ckmalloc(sizeof(struct Port)); + port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL); if (!port) { goto free6; } -- cgit v1.2.3 From 5d951fb458f847e5485b5251597fbf326000bb3b Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:19 +0000 Subject: tty: Pull the dtr raise into tty port This moves another per device special out of what should be shared open wait paths into private methods Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/isicom.c | 13 ++++++++----- drivers/char/mxser.c | 17 +++++++++++++---- drivers/char/rocket.c | 14 ++++++++++---- drivers/char/synclink.c | 21 +++++++++++++++------ drivers/char/synclink_gt.c | 21 +++++++++++++++------ drivers/char/tty_port.c | 16 ++++++++++++++++ 6 files changed, 77 insertions(+), 25 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index b3da4858fd4..a449449e301 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c @@ -328,11 +328,13 @@ static inline void drop_rts(struct isi_port *port) } /* card->lock MUST NOT be held */ -static inline void raise_dtr_rts(struct isi_port *port) + +static void isicom_raise_dtr_rts(struct tty_port *port) { - struct isi_board *card = port->card; + struct isi_port *ip = container_of(port, struct isi_port, port); + struct isi_board *card = ip->card; unsigned long base = card->base; - u16 channel = port->channel; + u16 channel = ip->channel; if (!lock_card(card)) return; @@ -340,7 +342,7 @@ static inline void raise_dtr_rts(struct isi_port *port) outw(0x8000 | (channel << card->shift_count) | 0x02, base); outw(0x0f04, base); InterruptTheCard(base); - port->status |= (ISI_DTR | ISI_RTS); + ip->status |= (ISI_DTR | ISI_RTS); unlock_card(card); } @@ -881,7 +883,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, spin_unlock_irqrestore(&card->card_lock, flags); while (1) { - raise_dtr_rts(ip); + tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { @@ -1462,6 +1464,7 @@ static const struct tty_operations isicom_ops = { static const struct tty_port_operations isicom_port_ops = { .carrier_raised = isicom_carrier_raised, + .raise_dtr_rts = isicom_raise_dtr_rts, }; static int __devinit reset_card(struct pci_dev *pdev, diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index eafbbcf355e..ff5ff618880 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -547,6 +547,17 @@ static int mxser_carrier_raised(struct tty_port *port) return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; } +static void mxser_raise_dtr_rts(struct tty_port *port) +{ + struct mxser_port *mp = container_of(port, struct mxser_port, port); + unsigned long flags; + + spin_lock_irqsave(&mp->slock, flags); + outb(inb(mp->ioaddr + UART_MCR) | + UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); + spin_unlock_irqrestore(&mp->slock, flags); +} + static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_port *mp) { @@ -586,10 +597,7 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, spin_unlock_irqrestore(&mp->slock, flags); port->blocked_open++; while (1) { - spin_lock_irqsave(&mp->slock, flags); - outb(inb(mp->ioaddr + UART_MCR) | - UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); - spin_unlock_irqrestore(&mp->slock, flags); + tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { if (port->flags & ASYNC_HUP_NOTIFY) @@ -2458,6 +2466,7 @@ static const struct tty_operations mxser_ops = { struct tty_port_operations mxser_port_ops = { .carrier_raised = mxser_carrier_raised, + .raise_dtr_rts = mxser_raise_dtr_rts, }; /* diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index 4a4110e703a..f4d9c399348 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -870,6 +870,13 @@ static int carrier_raised(struct tty_port *port) return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; } +static void raise_dtr_rts(struct tty_port *port) +{ + struct r_port *info = container_of(port, struct r_port, port); + sSetDTR(&info->channel); + sSetRTS(&info->channel); +} + /* info->port.count is considered critical, protected by spinlocks. */ static int block_til_ready(struct tty_struct *tty, struct file *filp, struct r_port *info) @@ -928,10 +935,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, spin_unlock_irqrestore(&info->slock, flags); while (1) { - if (tty->termios->c_cflag & CBAUD) { - sSetDTR(&info->channel); - sSetRTS(&info->channel); - } + if (tty->termios->c_cflag & CBAUD) + tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || !(info->flags & ROCKET_INITIALIZED)) { if (info->flags & ROCKET_HUP_NOTIFY) @@ -2381,6 +2386,7 @@ static const struct tty_operations rocket_ops = { static const struct tty_port_operations rocket_port_ops = { .carrier_raised = carrier_raised, + .raise_dtr_rts = raise_dtr_rts, }; /* diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index fb2e6b5e0ef..ac9f21e18c3 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c @@ -3298,6 +3298,18 @@ static int carrier_raised(struct tty_port *port) return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; } +static void raise_dtr_rts(struct tty_port *port) +{ + struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); + unsigned long flags; + + spin_lock_irqsave(&info->irq_spinlock,flags); + info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; + usc_set_serial_signals(info); + spin_unlock_irqrestore(&info->irq_spinlock,flags); +} + + /* block_til_ready() * * Block the current process until the specified port @@ -3358,12 +3370,8 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, port->blocked_open++; while (1) { - if (tty->termios->c_cflag & CBAUD) { - spin_lock_irqsave(&info->irq_spinlock,flags); - info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; - usc_set_serial_signals(info); - spin_unlock_irqrestore(&info->irq_spinlock,flags); - } + if (tty->termios->c_cflag & CBAUD) + tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); @@ -4321,6 +4329,7 @@ static void mgsl_add_device( struct mgsl_struct *info ) static const struct tty_port_operations mgsl_port_ops = { .carrier_raised = carrier_raised, + .raise_dtr_rts = raise_dtr_rts, }; diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index 39ccaba8ca3..625c9bde3be 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c @@ -3143,6 +3143,18 @@ static int carrier_raised(struct tty_port *port) return (info->signals & SerialSignal_DCD) ? 1 : 0; } +static void raise_dtr_rts(struct tty_port *port) +{ + unsigned long flags; + struct slgt_info *info = container_of(port, struct slgt_info, port); + + spin_lock_irqsave(&info->lock,flags); + info->signals |= SerialSignal_RTS + SerialSignal_DTR; + set_signals(info); + spin_unlock_irqrestore(&info->lock,flags); +} + + /* * block current process until the device is ready to open */ @@ -3187,12 +3199,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, port->blocked_open++; while (1) { - if ((tty->termios->c_cflag & CBAUD)) { - spin_lock_irqsave(&info->lock,flags); - info->signals |= SerialSignal_RTS + SerialSignal_DTR; - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); - } + if ((tty->termios->c_cflag & CBAUD)) + tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); @@ -3455,6 +3463,7 @@ static void add_device(struct slgt_info *info) static const struct tty_port_operations slgt_port_ops = { .carrier_raised = carrier_raised, + .raise_dtr_rts = raise_dtr_rts, }; /* diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index f54e40cbf02..0557b638474 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -111,3 +111,19 @@ int tty_port_carrier_raised(struct tty_port *port) return port->ops->carrier_raised(port); } EXPORT_SYMBOL(tty_port_carrier_raised); + +/** + * tty_port_raise_dtr_rts - Riase DTR/RTS + * @port: tty port + * + * Wrapper for the DTR/RTS raise logic. For the moment this is used + * to hide some internal details. This will eventually become entirely + * internal to the tty port. + */ + +void tty_port_raise_dtr_rts(struct tty_port *port) +{ + if (port->ops->raise_dtr_rts) + port->ops->raise_dtr_rts(port); +} +EXPORT_SYMBOL(tty_port_raise_dtr_rts); -- cgit v1.2.3 From 3e61696bdc2103107674b06d0daf30b76193e922 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:26 +0000 Subject: isicom: redo locking to use tty port locks This helps set the basis for moving block_til_ready into common code. We also introduce a tty_port_hangup helper as this will also be generally needed. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/isicom.c | 35 +++++++++++++++-------------------- drivers/char/synclinkmp.c | 20 ++++++++++++++------ drivers/char/tty_port.c | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 26 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index a449449e301..db53db91ae4 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c @@ -841,7 +841,6 @@ static int isicom_carrier_raised(struct tty_port *port) static int block_til_ready(struct tty_struct *tty, struct file *filp, struct isi_port *ip) { - struct isi_board *card = ip->card; struct tty_port *port = &ip->port; int do_clocal = 0, retval; unsigned long flags; @@ -876,11 +875,11 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, retval = 0; add_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&card->card_lock, flags); + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) port->count--; port->blocked_open++; - spin_unlock_irqrestore(&card->card_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); while (1) { tty_port_raise_dtr_rts(port); @@ -905,14 +904,13 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } set_current_state(TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&card->card_lock, flags); + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) port->count++; port->blocked_open--; - spin_unlock_irqrestore(&card->card_lock, flags); - if (retval) - return retval; - port->flags |= ASYNC_NORMAL_ACTIVE; + if (retval == 0) + port->flags |= ASYNC_NORMAL_ACTIVE; + spin_unlock_irqrestore(&port->lock, flags); return 0; } @@ -1034,9 +1032,9 @@ static void isicom_close(struct tty_struct *tty, struct file *filp) pr_dbg("Close start!!!.\n"); - spin_lock_irqsave(&card->card_lock, flags); + spin_lock_irqsave(&port->port.lock, flags); if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&card->card_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); return; } @@ -1054,12 +1052,12 @@ static void isicom_close(struct tty_struct *tty, struct file *filp) } if (port->port.count) { - spin_unlock_irqrestore(&card->card_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); return; } port->port.flags |= ASYNC_CLOSING; tty->closing = 1; - spin_unlock_irqrestore(&card->card_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, port->port.closing_wait); @@ -1076,22 +1074,22 @@ static void isicom_close(struct tty_struct *tty, struct file *filp) isicom_flush_buffer(tty); tty_ldisc_flush(tty); - spin_lock_irqsave(&card->card_lock, flags); + spin_lock_irqsave(&port->port.lock, flags); tty->closing = 0; if (port->port.blocked_open) { - spin_unlock_irqrestore(&card->card_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); if (port->port.close_delay) { pr_dbg("scheduling until time out.\n"); msleep_interruptible( jiffies_to_msecs(port->port.close_delay)); } - spin_lock_irqsave(&card->card_lock, flags); + spin_lock_irqsave(&port->port.lock, flags); wake_up_interruptible(&port->port.open_wait); } port->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); wake_up_interruptible(&port->port.close_wait); - spin_unlock_irqrestore(&card->card_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); } /* write et all */ @@ -1430,10 +1428,7 @@ static void isicom_hangup(struct tty_struct *tty) isicom_shutdown_port(port); spin_unlock_irqrestore(&port->card->card_lock, flags); - port->port.count = 0; - port->port.flags &= ~ASYNC_NORMAL_ACTIVE; - tty_port_tty_set(&port->port, NULL); - wake_up_interruptible(&port->port.open_wait); + tty_port_hangup(&port->port); } diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index fcf1ec77450..1f5c21ec4b1 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c @@ -3331,6 +3331,17 @@ static int carrier_raised(struct tty_port *port) return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; } +static void raise_dtr_rts(struct tty_port *port) +{ + SLMP_INFO *info = container_of(port, SLMP_INFO, port); + unsigned long flags; + + spin_lock_irqsave(&info->lock,flags); + info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; + set_signals(info); + spin_unlock_irqrestore(&info->lock,flags); +} + /* Block the current process until the specified port is ready to open. */ static int block_til_ready(struct tty_struct *tty, struct file *filp, @@ -3381,12 +3392,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, port->blocked_open++; while (1) { - if ((tty->termios->c_cflag & CBAUD)) { - spin_lock_irqsave(&info->lock,flags); - info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); - } + if (tty->termios->c_cflag & CBAUD) + tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); @@ -3793,6 +3800,7 @@ static void add_device(SLMP_INFO *info) static const struct tty_port_operations port_ops = { .carrier_raised = carrier_raised, + .raise_dtr_rts = raise_dtr_rts, }; /* Allocate and initialize a device instance structure diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index 0557b638474..9f418bca4a2 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,29 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) } EXPORT_SYMBOL(tty_port_tty_set); +/** + * tty_port_hangup - hangup helper + * @port: tty port + * + * Perform port level tty hangup flag and count changes. Drop the tty + * reference. + */ + +void tty_port_hangup(struct tty_port *port) +{ + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + port->count = 0; + port->flags &= ~ASYNC_NORMAL_ACTIVE; + if (port->tty) + tty_kref_put(port->tty); + port->tty = NULL; + spin_unlock_irqrestore(&port->lock, flags); + wake_up_interruptible(&port->open_wait); +} +EXPORT_SYMBOL(tty_port_hangup); + /** * tty_port_carrier_raised - carrier raised check * @port: tty port -- cgit v1.2.3 From 510a3049573868d3d77414bfa55d293f44d0dbbe Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:36 +0000 Subject: tty: relock generic_serial Switch generic_serial to do port count locking via the tty_port structure ready for moving to a common port wait routine. Keep the old driver lock for internal calling so we don't risk messing up the drivers below until we are ready. Still needs kref conversions Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/generic_serial.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c index 2356994ee01..2f040d1ed89 100644 --- a/drivers/char/generic_serial.c +++ b/drivers/char/generic_serial.c @@ -376,7 +376,8 @@ static void gs_shutdown_port (struct gs_port *port) void gs_hangup(struct tty_struct *tty) { - struct gs_port *port; + struct gs_port *port; + unsigned long flags; func_enter (); @@ -386,9 +387,11 @@ void gs_hangup(struct tty_struct *tty) return; gs_shutdown_port (port); + spin_lock_irqsave(&port->port.lock, flags); port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|GS_ACTIVE); port->port.tty = NULL; port->port.count = 0; + spin_unlock_irqrestore(&port->port.lock, flags); wake_up_interruptible(&port->port.open_wait); func_exit (); @@ -454,12 +457,12 @@ int gs_block_til_ready(void *port_, struct file * filp) add_wait_queue(&port->open_wait, &wait); gs_dprintk (GS_DEBUG_BTR, "after add waitq.\n"); - spin_lock_irqsave(&gp->driver_lock, flags); + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) { port->count--; } - spin_unlock_irqrestore(&gp->driver_lock, flags); port->blocked_open++; + spin_unlock_irqrestore(&port->lock, flags); while (1) { CD = tty_port_carrier_raised(port); gs_dprintk (GS_DEBUG_BTR, "CD is now %d.\n", CD); @@ -487,16 +490,17 @@ int gs_block_til_ready(void *port_, struct file * filp) port->blocked_open); set_current_state (TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); + + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) { port->count++; } port->blocked_open--; - if (retval) - return retval; - - port->flags |= ASYNC_NORMAL_ACTIVE; + if (retval == 0) + port->flags |= ASYNC_NORMAL_ACTIVE; + spin_unlock_irqrestore(&port->lock, flags); func_exit (); - return 0; + return retval; } @@ -517,10 +521,10 @@ void gs_close(struct tty_struct * tty, struct file * filp) port->port.tty = tty; } - spin_lock_irqsave(&port->driver_lock, flags); + spin_lock_irqsave(&port->port.lock, flags); if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&port->driver_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); if (port->rd->hungup) port->rd->hungup (port); func_exit (); @@ -539,7 +543,7 @@ void gs_close(struct tty_struct * tty, struct file * filp) if (port->port.count) { gs_dprintk(GS_DEBUG_CLOSE, "gs_close port %p: count: %d\n", port, port->port.count); - spin_unlock_irqrestore(&port->driver_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); func_exit (); return; } @@ -560,8 +564,10 @@ void gs_close(struct tty_struct * tty, struct file * filp) * line status register. */ + spin_lock_irqsave(&port->driver_lock, flags); port->rd->disable_rx_interrupts (port); spin_unlock_irqrestore(&port->driver_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); /* close has no way of returning "EINTR", so discard return value */ if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) @@ -574,20 +580,25 @@ void gs_close(struct tty_struct * tty, struct file * filp) tty_ldisc_flush(tty); tty->closing = 0; + spin_lock_irqsave(&port->driver_lock, flags); port->event = 0; port->rd->close (port); port->rd->shutdown_port (port); + spin_unlock_irqrestore(&port->driver_lock, flags); + + spin_lock_irqsave(&port->port.lock, flags); port->port.tty = NULL; if (port->port.blocked_open) { if (port->close_delay) { - spin_unlock_irqrestore(&port->driver_lock, flags); + spin_unlock_irqrestore(&port->port.lock, flags); msleep_interruptible(jiffies_to_msecs(port->close_delay)); - spin_lock_irqsave(&port->driver_lock, flags); + spin_lock_irqsave(&port->port.lock, flags); } wake_up_interruptible(&port->port.open_wait); } port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING | ASYNC_INITIALIZED); + spin_unlock_irqrestore(&port->port.lock, flags); wake_up_interruptible(&port->port.close_wait); func_exit (); -- cgit v1.2.3 From a129909ca910d086b8536c790338504878489a95 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:44 +0000 Subject: tty: rocketport uses different port flags to everyone else Normalise them so we can use the common helpers later on Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/rocket.c | 40 ++++++++++++++++++++-------------------- drivers/char/rocket.h | 2 +- drivers/char/rocket_int.h | 5 ----- 3 files changed, 21 insertions(+), 26 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index f4d9c399348..9d819808e84 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -499,7 +499,7 @@ static void rp_handle_port(struct r_port *info) if (!info) return; - if ((info->flags & ROCKET_INITIALIZED) == 0) { + if ((info->flags & ASYNC_INITIALIZED) == 0) { printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " "info->flags & NOT_INIT\n"); return; @@ -892,11 +892,11 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, * until it's done, and then try again. */ if (tty_hung_up_p(filp)) - return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); - if (info->flags & ROCKET_CLOSING) { + return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); + if (info->flags & ASYNC_CLOSING) { if (wait_for_completion_interruptible(&info->close_wait)) return -ERESTARTSYS; - return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); + return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); } /* @@ -904,7 +904,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, * then make the check up front and then exit. */ if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { - info->flags |= ROCKET_NORMAL_ACTIVE; + info->flags |= ASYNC_NORMAL_ACTIVE; return 0; } if (tty->termios->c_cflag & CLOCAL) @@ -923,7 +923,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, spin_lock_irqsave(&info->slock, flags); #ifdef ROCKET_DISABLE_SIMUSAGE - info->flags |= ROCKET_NORMAL_ACTIVE; + info->flags |= ASYNC_NORMAL_ACTIVE; #else if (!tty_hung_up_p(filp)) { extra_count = 1; @@ -938,14 +938,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, if (tty->termios->c_cflag & CBAUD) tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(info->flags & ROCKET_INITIALIZED)) { - if (info->flags & ROCKET_HUP_NOTIFY) + if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) { + if (info->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } - if (!(info->flags & ROCKET_CLOSING) && + if (!(info->flags & ASYNC_CLOSING) && (do_clocal || tty_port_carrier_raised(port))) break; if (signal_pending(current)) { @@ -975,7 +975,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, #endif if (retval) return retval; - info->flags |= ROCKET_NORMAL_ACTIVE; + info->flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -998,12 +998,12 @@ static int rp_open(struct tty_struct *tty, struct file *filp) if (!page) return -ENOMEM; - if (info->flags & ROCKET_CLOSING) { + if (info->flags & ASYNC_CLOSING) { retval = wait_for_completion_interruptible(&info->close_wait); free_page(page); if (retval) return retval; - return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); + return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); } /* @@ -1032,7 +1032,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) /* * Info->count is now 1; so it's safe to sleep now. */ - if ((info->flags & ROCKET_INITIALIZED) == 0) { + if ((info->flags & ASYNC_INITIALIZED) == 0) { cp = &info->channel; sSetRxTrigger(cp, TRIG_1); if (sGetChanStatus(cp) & CD_ACT) @@ -1056,7 +1056,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) sEnRxFIFO(cp); sEnTransmit(cp); - info->flags |= ROCKET_INITIALIZED; + info->flags |= ASYNC_INITIALIZED; /* * Set up the tty->alt_speed kludge @@ -1131,7 +1131,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp) spin_unlock_irqrestore(&info->slock, flags); return; } - info->flags |= ROCKET_CLOSING; + info->flags |= ASYNC_CLOSING; spin_unlock_irqrestore(&info->slock, flags); cp = &info->channel; @@ -1151,7 +1151,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp) /* * Wait for the transmit buffer to clear */ - if (info->port.closing_wait != ROCKET_CLOSING_WAIT_NONE) + if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, info->port.closing_wait); /* * Before we drop DTR, make sure the UART transmitter @@ -1192,7 +1192,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp) info->xmit_buf = NULL; } } - info->flags &= ~(ROCKET_INITIALIZED | ROCKET_CLOSING | ROCKET_NORMAL_ACTIVE); + info->flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE); tty->closing = 0; complete_all(&info->close_wait); atomic_dec(&rp_num_ports_open); @@ -1649,14 +1649,14 @@ static void rp_hangup(struct tty_struct *tty) printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line); #endif rp_flush_buffer(tty); - if (info->flags & ROCKET_CLOSING) + if (info->flags & ASYNC_CLOSING) return; if (info->port.count) atomic_dec(&rp_num_ports_open); clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); info->port.count = 0; - info->flags &= ~ROCKET_NORMAL_ACTIVE; + info->flags &= ~ASYNC_NORMAL_ACTIVE; info->port.tty = NULL; cp = &info->channel; @@ -1666,7 +1666,7 @@ static void rp_hangup(struct tty_struct *tty) sDisCTSFlowCtl(cp); sDisTxSoftFlowCtl(cp); sClrTxXOFF(cp); - info->flags &= ~ROCKET_INITIALIZED; + info->flags &= ~ASYNC_INITIALIZED; wake_up_interruptible(&info->port.open_wait); } diff --git a/drivers/char/rocket.h b/drivers/char/rocket.h index a8b09195ebb..ec863f35f1a 100644 --- a/drivers/char/rocket.h +++ b/drivers/char/rocket.h @@ -39,7 +39,7 @@ struct rocket_version { /* * Rocketport flags */ -#define ROCKET_CALLOUT_NOHUP 0x00000001 +/*#define ROCKET_CALLOUT_NOHUP 0x00000001 */ #define ROCKET_FORCE_CD 0x00000002 #define ROCKET_HUP_NOTIFY 0x00000004 #define ROCKET_SPLIT_TERMIOS 0x00000008 diff --git a/drivers/char/rocket_int.h b/drivers/char/rocket_int.h index 21f3ff53ba3..67e0f1e778a 100644 --- a/drivers/char/rocket_int.h +++ b/drivers/char/rocket_int.h @@ -1162,11 +1162,6 @@ struct r_port { /* number of characters left in xmit buffer before we ask for more */ #define WAKEUP_CHARS 256 -/* Internal flags used only by the rocketport driver */ -#define ROCKET_INITIALIZED 0x80000000 /* Port is active */ -#define ROCKET_CLOSING 0x40000000 /* Serial port is closing */ -#define ROCKET_NORMAL_ACTIVE 0x20000000 /* Normal port is active */ - /* * Assigned major numbers for the Comtrol Rocketport */ -- cgit v1.2.3 From c2ba38cd76df770a253f0cab4b6abe514c265a85 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:50 +0000 Subject: tty: relock riscom8 using port locks Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/riscom8.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c index 6ad1c2aa2a9..14662d7aa62 100644 --- a/drivers/char/riscom8.c +++ b/drivers/char/riscom8.c @@ -919,14 +919,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, retval = 0; add_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&riscom_lock, flags); - + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) port->count--; - - spin_unlock_irqrestore(&riscom_lock, flags); - port->blocked_open++; + spin_unlock_irqrestore(&port->lock, flags); + while (1) { CD = tty_port_carrier_raised(port); @@ -950,13 +948,13 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } __set_current_state(TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) port->count++; port->blocked_open--; - if (retval) - return retval; - - port->flags |= ASYNC_NORMAL_ACTIVE; + if (retval == 0) + port->flags |= ASYNC_NORMAL_ACTIVE; + spin_unlock_irqrestore(&port->lock, flags); return 0; } @@ -1015,7 +1013,7 @@ static void rc_close(struct tty_struct *tty, struct file *filp) if (!port || rc_paranoia_check(port, tty->name, "close")) return; - spin_lock_irqsave(&riscom_lock, flags); + spin_lock_irqsave(&port->port.lock, flags); if (tty_hung_up_p(filp)) goto out; @@ -1041,6 +1039,7 @@ static void rc_close(struct tty_struct *tty, struct file *filp) * the line discipline to only process XON/XOFF characters. */ tty->closing = 1; + spin_unlock_irqrestore(&port->port.lock, flags); if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, port->port.closing_wait); /* @@ -1049,6 +1048,8 @@ static void rc_close(struct tty_struct *tty, struct file *filp) * interrupt driver to stop checking the data ready bit in the * line status register. */ + + spin_lock_irqsave(&riscom_lock, flags); port->IER &= ~IER_RXD; if (port->port.flags & ASYNC_INITIALIZED) { port->IER &= ~IER_TXRDY; @@ -1062,21 +1063,27 @@ static void rc_close(struct tty_struct *tty, struct file *filp) */ timeout = jiffies + HZ; while (port->IER & IER_TXEMPTY) { + spin_unlock_irqrestore(&riscom_lock, flags); msleep_interruptible(jiffies_to_msecs(port->timeout)); + spin_lock_irqsave(&riscom_lock, flags); if (time_after(jiffies, timeout)) break; } } rc_shutdown_port(tty, bp, port); rc_flush_buffer(tty); + spin_unlock_irqrestore(&riscom_lock, flags); tty_ldisc_flush(tty); + spin_lock_irqsave(&port->port.lock, flags); tty->closing = 0; port->port.tty = NULL; if (port->port.blocked_open) { + spin_unlock_irqrestore(&port->port.lock, flags); if (port->port.close_delay) msleep_interruptible(jiffies_to_msecs(port->port.close_delay)); wake_up_interruptible(&port->port.open_wait); + spin_lock_irqsave(&port->port.lock, flags); } port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); wake_up_interruptible(&port->port.close_wait); @@ -1465,6 +1472,7 @@ static void rc_hangup(struct tty_struct *tty) { struct riscom_port *port = (struct riscom_port *)tty->driver_data; struct riscom_board *bp; + unsigned long flags; if (rc_paranoia_check(port, tty->name, "rc_hangup")) return; @@ -1472,10 +1480,12 @@ static void rc_hangup(struct tty_struct *tty) bp = port_Board(port); rc_shutdown_port(tty, bp, port); + spin_lock_irqsave(&port->port.lock, flags); port->port.count = 0; port->port.flags &= ~ASYNC_NORMAL_ACTIVE; port->port.tty = NULL; wake_up_interruptible(&port->port.open_wait); + spin_unlock_irqrestore(&port->port.lock, flags); } static void rc_set_termios(struct tty_struct *tty, -- cgit v1.2.3 From 3b6826b250633361f08a6427a4ac0035e5d88c72 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:45:58 +0000 Subject: tty: relock the mxser driver Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/mxser.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index ff5ff618880..e2471cf1ee9 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -591,11 +591,11 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, retval = 0; add_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&mp->slock, flags); + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) port->count--; - spin_unlock_irqrestore(&mp->slock, flags); port->blocked_open++; + spin_unlock_irqrestore(&port->lock, flags); while (1) { tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); @@ -617,12 +617,13 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, } set_current_state(TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); + spin_lock_irqsave(&port->lock, flags); if (!tty_hung_up_p(filp)) port->count++; port->blocked_open--; - if (retval) - return retval; - port->flags |= ASYNC_NORMAL_ACTIVE; + if (retval == 0) + port->flags |= ASYNC_NORMAL_ACTIVE; + spin_unlock_irqrestore(&port->lock, flags); return 0; } @@ -1102,9 +1103,9 @@ static int mxser_open(struct tty_struct *tty, struct file *filp) /* * Start up serial port */ - spin_lock_irqsave(&info->slock, flags); + spin_lock_irqsave(&info->port.lock, flags); info->port.count++; - spin_unlock_irqrestore(&info->slock, flags); + spin_unlock_irqrestore(&info->port.lock, flags); retval = mxser_startup(tty); if (retval) return retval; @@ -1157,10 +1158,10 @@ static void mxser_close(struct tty_struct *tty, struct file *filp) if (!info) return; - spin_lock_irqsave(&info->slock, flags); + spin_lock_irqsave(&info->port.lock, flags); if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&info->slock, flags); + spin_unlock_irqrestore(&info->port.lock, flags); return; } if ((tty->count == 1) && (info->port.count != 1)) { @@ -1181,11 +1182,11 @@ static void mxser_close(struct tty_struct *tty, struct file *filp) info->port.count = 0; } if (info->port.count) { - spin_unlock_irqrestore(&info->slock, flags); + spin_unlock_irqrestore(&info->port.lock, flags); return; } info->port.flags |= ASYNC_CLOSING; - spin_unlock_irqrestore(&info->slock, flags); + spin_unlock_irqrestore(&info->port.lock, flags); /* * Save the termios structure, since this port may have * separate termios for callout and dialin. @@ -2161,10 +2162,7 @@ static void mxser_hangup(struct tty_struct *tty) mxser_flush_buffer(tty); mxser_shutdown(tty); - info->port.count = 0; - info->port.flags &= ~ASYNC_NORMAL_ACTIVE; - tty_port_tty_set(&info->port, NULL); - wake_up_interruptible(&info->port.open_wait); + tty_port_hangup(&info->port); } /* -- cgit v1.2.3 From 36c621d82b956ff6ff72273f848af53e6c581aba Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:46:10 +0000 Subject: tty: Introduce a tty_port generic block_til_ready Start sucking more commonality out of the drivers into a single piece of core code. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/isicom.c | 79 +----------------------------------- drivers/char/mxser.c | 71 +------------------------------- drivers/char/riscom8.c | 86 +-------------------------------------- drivers/char/synclink.c | 1 + drivers/char/tty_port.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/char/vme_scc.c | 6 +-- 6 files changed, 113 insertions(+), 235 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index db53db91ae4..bac55cf4424 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c @@ -838,82 +838,6 @@ static int isicom_carrier_raised(struct tty_port *port) return (ip->status & ISI_DCD)?1 : 0; } -static int block_til_ready(struct tty_struct *tty, struct file *filp, - struct isi_port *ip) -{ - struct tty_port *port = &ip->port; - int do_clocal = 0, retval; - unsigned long flags; - DECLARE_WAITQUEUE(wait, current); - int cd; - - /* block if port is in the process of being closed */ - - if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { - pr_dbg("block_til_ready: close in progress.\n"); - interruptible_sleep_on(&port->close_wait); - if (port->flags & ASYNC_HUP_NOTIFY) - return -EAGAIN; - else - return -ERESTARTSYS; - } - - /* if non-blocking mode is set ... */ - - if ((filp->f_flags & O_NONBLOCK) || - (tty->flags & (1 << TTY_IO_ERROR))) { - pr_dbg("block_til_ready: non-block mode.\n"); - port->flags |= ASYNC_NORMAL_ACTIVE; - return 0; - } - - if (C_CLOCAL(tty)) - do_clocal = 1; - - /* block waiting for DCD to be asserted, and while - callout dev is busy */ - retval = 0; - add_wait_queue(&port->open_wait, &wait); - - spin_lock_irqsave(&port->lock, flags); - if (!tty_hung_up_p(filp)) - port->count--; - port->blocked_open++; - spin_unlock_irqrestore(&port->lock, flags); - - while (1) { - tty_port_raise_dtr_rts(port); - - set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { - if (port->flags & ASYNC_HUP_NOTIFY) - retval = -EAGAIN; - else - retval = -ERESTARTSYS; - break; - } - cd = tty_port_carrier_raised(port); - if (!(port->flags & ASYNC_CLOSING) && - (do_clocal || cd)) - break; - if (signal_pending(current)) { - retval = -ERESTARTSYS; - break; - } - schedule(); - } - set_current_state(TASK_RUNNING); - remove_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&port->lock, flags); - if (!tty_hung_up_p(filp)) - port->count++; - port->blocked_open--; - if (retval == 0) - port->flags |= ASYNC_NORMAL_ACTIVE; - spin_unlock_irqrestore(&port->lock, flags); - return 0; -} - static int isicom_open(struct tty_struct *tty, struct file *filp) { struct isi_port *port; @@ -940,12 +864,13 @@ static int isicom_open(struct tty_struct *tty, struct file *filp) isicom_setup_board(card); + /* FIXME: locking on port.count etc */ port->port.count++; tty->driver_data = port; tty_port_tty_set(&port->port, tty); error = isicom_setup_port(tty); if (error == 0) - error = block_til_ready(tty, filp, port); + error = tty_port_block_til_ready(&port->port, tty, filp); return error; } diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index e2471cf1ee9..08ba6eb1a38 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -558,75 +558,6 @@ static void mxser_raise_dtr_rts(struct tty_port *port) spin_unlock_irqrestore(&mp->slock, flags); } -static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, - struct mxser_port *mp) -{ - DECLARE_WAITQUEUE(wait, current); - int retval; - int do_clocal = 0; - unsigned long flags; - int cd; - struct tty_port *port = &mp->port; - - /* - * If non-blocking mode is set, or the port is not enabled, - * then make the check up front and then exit. - */ - if ((filp->f_flags & O_NONBLOCK) || - test_bit(TTY_IO_ERROR, &tty->flags)) { - port->flags |= ASYNC_NORMAL_ACTIVE; - return 0; - } - - if (tty->termios->c_cflag & CLOCAL) - do_clocal = 1; - - /* - * Block waiting for the carrier detect and the line to become - * free (i.e., not in use by the callout). While we are in - * this loop, port->count is dropped by one, so that - * mxser_close() knows when to free things. We restore it upon - * exit, either normal or abnormal. - */ - retval = 0; - add_wait_queue(&port->open_wait, &wait); - - spin_lock_irqsave(&port->lock, flags); - if (!tty_hung_up_p(filp)) - port->count--; - port->blocked_open++; - spin_unlock_irqrestore(&port->lock, flags); - while (1) { - tty_port_raise_dtr_rts(port); - set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { - if (port->flags & ASYNC_HUP_NOTIFY) - retval = -EAGAIN; - else - retval = -ERESTARTSYS; - break; - } - cd = tty_port_carrier_raised(port); - if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd)) - break; - if (signal_pending(current)) { - retval = -ERESTARTSYS; - break; - } - schedule(); - } - set_current_state(TASK_RUNNING); - remove_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&port->lock, flags); - if (!tty_hung_up_p(filp)) - port->count++; - port->blocked_open--; - if (retval == 0) - port->flags |= ASYNC_NORMAL_ACTIVE; - spin_unlock_irqrestore(&port->lock, flags); - return 0; -} - static int mxser_set_baud(struct tty_struct *tty, long newspd) { struct mxser_port *info = tty->driver_data; @@ -1110,7 +1041,7 @@ static int mxser_open(struct tty_struct *tty, struct file *filp) if (retval) return retval; - retval = mxser_block_til_ready(tty, filp, info); + retval = tty_port_block_til_ready(&info->port, tty, filp); if (retval) return retval; diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c index 14662d7aa62..af34c2054a0 100644 --- a/drivers/char/riscom8.c +++ b/drivers/char/riscom8.c @@ -874,90 +874,6 @@ static int carrier_raised(struct tty_port *port) return CD; } -static int block_til_ready(struct tty_struct *tty, struct file *filp, - struct riscom_port *rp) -{ - DECLARE_WAITQUEUE(wait, current); - int retval; - int do_clocal = 0; - int CD; - unsigned long flags; - struct tty_port *port = &rp->port; - - /* - * If the device is in the middle of being closed, then block - * until it's done, and then try again. - */ - if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { - interruptible_sleep_on(&port->close_wait); - if (port->flags & ASYNC_HUP_NOTIFY) - return -EAGAIN; - else - return -ERESTARTSYS; - } - - /* - * If non-blocking mode is set, or the port is not enabled, - * then make the check up front and then exit. - */ - if ((filp->f_flags & O_NONBLOCK) || - (tty->flags & (1 << TTY_IO_ERROR))) { - port->flags |= ASYNC_NORMAL_ACTIVE; - return 0; - } - - if (C_CLOCAL(tty)) - do_clocal = 1; - - /* - * Block waiting for the carrier detect and the line to become - * free (i.e., not in use by the callout). While we are in - * this loop, info->count is dropped by one, so that - * rs_close() knows when to free things. We restore it upon - * exit, either normal or abnormal. - */ - retval = 0; - add_wait_queue(&port->open_wait, &wait); - - spin_lock_irqsave(&port->lock, flags); - if (!tty_hung_up_p(filp)) - port->count--; - port->blocked_open++; - spin_unlock_irqrestore(&port->lock, flags); - - while (1) { - - CD = tty_port_carrier_raised(port); - set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || - !(port->flags & ASYNC_INITIALIZED)) { - if (port->flags & ASYNC_HUP_NOTIFY) - retval = -EAGAIN; - else - retval = -ERESTARTSYS; - break; - } - if (!(port->flags & ASYNC_CLOSING) && - (do_clocal || CD)) - break; - if (signal_pending(current)) { - retval = -ERESTARTSYS; - break; - } - schedule(); - } - __set_current_state(TASK_RUNNING); - remove_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&port->lock, flags); - if (!tty_hung_up_p(filp)) - port->count++; - port->blocked_open--; - if (retval == 0) - port->flags |= ASYNC_NORMAL_ACTIVE; - spin_unlock_irqrestore(&port->lock, flags); - return 0; -} - static int rc_open(struct tty_struct *tty, struct file *filp) { int board; @@ -984,7 +900,7 @@ static int rc_open(struct tty_struct *tty, struct file *filp) error = rc_setup_port(bp, port); if (error == 0) - error = block_til_ready(tty, filp, port); + error = tty_port_block_til_ready(&port->port, tty, filp); return error; } diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index ac9f21e18c3..0ded4ed3da3 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c @@ -3401,6 +3401,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, set_current_state(TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); + /* FIXME: Racy on hangup during close wait */ if (extra_count) port->count++; port->blocked_open--; diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index 9f418bca4a2..ff94182b381 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -151,3 +151,108 @@ void tty_port_raise_dtr_rts(struct tty_port *port) port->ops->raise_dtr_rts(port); } EXPORT_SYMBOL(tty_port_raise_dtr_rts); + +/** + * tty_port_block_til_ready - Waiting logic for tty open + * @port: the tty port being opened + * @tty: the tty device being bound + * @filp: the file pointer of the opener + * + * Implement the core POSIX/SuS tty behaviour when opening a tty device. + * Handles: + * - hangup (both before and during) + * - non blocking open + * - rts/dtr/dcd + * - signals + * - port flags and counts + * + * The passed tty_port must implement the carrier_raised method if it can + * do carrier detect and the raise_dtr_rts method if it supports software + * management of these lines. Note that the dtr/rts raise is done each + * iteration as a hangup may have previously dropped them while we wait. + */ + +int tty_port_block_til_ready(struct tty_port *port, + struct tty_struct *tty, struct file *filp) +{ + int do_clocal = 0, retval; + unsigned long flags; + DECLARE_WAITQUEUE(wait, current); + int cd; + + /* block if port is in the process of being closed */ + if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { + interruptible_sleep_on(&port->close_wait); + if (port->flags & ASYNC_HUP_NOTIFY) + return -EAGAIN; + else + return -ERESTARTSYS; + } + + /* if non-blocking mode is set we can pass directly to open unless + the port has just hung up or is in another error state */ + if ((filp->f_flags & O_NONBLOCK) || + (tty->flags & (1 << TTY_IO_ERROR))) { + port->flags |= ASYNC_NORMAL_ACTIVE; + return 0; + } + + if (C_CLOCAL(tty)) + do_clocal = 1; + + /* Block waiting until we can proceed. We may need to wait for the + carrier, but we must also wait for any close that is in progress + before the next open may complete */ + + retval = 0; + add_wait_queue(&port->open_wait, &wait); + + /* The port lock protects the port counts */ + spin_lock_irqsave(&port->lock, flags); + if (!tty_hung_up_p(filp)) + port->count--; + port->blocked_open++; + spin_unlock_irqrestore(&port->lock, flags); + + while (1) { + /* Indicate we are open */ + tty_port_raise_dtr_rts(port); + + set_current_state(TASK_INTERRUPTIBLE); + /* Check for a hangup or uninitialised port. Return accordingly */ + if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { + if (port->flags & ASYNC_HUP_NOTIFY) + retval = -EAGAIN; + else + retval = -ERESTARTSYS; + break; + } + /* Probe the carrier. For devices with no carrier detect this + will always return true */ + cd = tty_port_carrier_raised(port); + if (!(port->flags & ASYNC_CLOSING) && + (do_clocal || cd)) + break; + if (signal_pending(current)) { + retval = -ERESTARTSYS; + break; + } + schedule(); + } + set_current_state(TASK_RUNNING); + remove_wait_queue(&port->open_wait, &wait); + + /* Update counts. A parallel hangup will have set count to zero and + we must not mess that up further */ + spin_lock_irqsave(&port->lock, flags); + if (!tty_hung_up_p(filp)) + port->count++; + port->blocked_open--; + if (retval == 0) + port->flags |= ASYNC_NORMAL_ACTIVE; + spin_unlock_irqrestore(&port->lock, flags); + return 0; + +} +EXPORT_SYMBOL(tty_port_block_til_ready); + diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c index d4e1534c0e0..2d9242a45a0 100644 --- a/drivers/char/vme_scc.c +++ b/drivers/char/vme_scc.c @@ -631,8 +631,8 @@ static void scc_enable_rx_interrupts(void *ptr) static int scc_carrier_raised(struct tty_port *port) { - struct scc_port *scc = container_of(port, struct scc_port, gs.port); - unsigned channel = port->channel; + struct scc_port *sc = container_of(port, struct scc_port, gs.port); + unsigned channel = sc->channel; return !!(scc_last_status_reg[channel] & SR_DCD); } @@ -643,7 +643,7 @@ static void scc_shutdown_port(void *ptr) struct scc_port *port = ptr; port->gs.port.flags &= ~ GS_ACTIVE; - if (port->gs.port.tty && port->gs.port.tty->termios->c_cflag & HUPCL) { + if (port->gs.port.tty && (port->gs.port.tty->termios->c_cflag & HUPCL)) { scc_setsignals (port, 0, 0); } } -- cgit v1.2.3 From 2a6eadbd5a2ae8f458e421f3614f1ad13c0f9a1c Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:46:18 +0000 Subject: tty: Rework istallion to use the tty port changes Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/istallion.c | 159 +++++++++++++---------------------------------- 1 file changed, 43 insertions(+), 116 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c index c4682f9e34b..4c69ab97339 100644 --- a/drivers/char/istallion.c +++ b/drivers/char/istallion.c @@ -626,8 +626,6 @@ static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp); static int stli_initopen(struct tty_struct *tty, struct stlibrd *brdp, struct stliport *portp); static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); -static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp, - struct stliport *portp, struct file *filp); static int stli_setport(struct tty_struct *tty); static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); @@ -787,6 +785,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp) { struct stlibrd *brdp; struct stliport *portp; + struct tty_port *port; unsigned int minordev, brdnr, portnr; int rc; @@ -808,30 +807,19 @@ static int stli_open(struct tty_struct *tty, struct file *filp) return -ENODEV; if (portp->devnr < 1) return -ENODEV; - - -/* - * Check if this port is in the middle of closing. If so then wait - * until it is closed then return error status based on flag settings. - * The sleep here does not need interrupt protection since the wakeup - * for it is done with the same context. - */ - if (portp->port.flags & ASYNC_CLOSING) { - interruptible_sleep_on(&portp->port.close_wait); - if (portp->port.flags & ASYNC_HUP_NOTIFY) - return -EAGAIN; - return -ERESTARTSYS; - } + port = &portp->port; /* * On the first open of the device setup the port hardware, and * initialize the per port data structure. Since initializing the port * requires several commands to the board we will need to wait for any * other open that is already initializing the port. + * + * Review - locking */ - tty_port_tty_set(&portp->port, tty); + tty_port_tty_set(port, tty); tty->driver_data = portp; - portp->port.count++; + port->count++; wait_event_interruptible(portp->raw_wait, !test_bit(ST_INITIALIZING, &portp->state)); @@ -841,7 +829,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp) if ((portp->port.flags & ASYNC_INITIALIZED) == 0) { set_bit(ST_INITIALIZING, &portp->state); if ((rc = stli_initopen(tty, brdp, portp)) >= 0) { - portp->port.flags |= ASYNC_INITIALIZED; + /* Locking */ + port->flags |= ASYNC_INITIALIZED; clear_bit(TTY_IO_ERROR, &tty->flags); } clear_bit(ST_INITIALIZING, &portp->state); @@ -849,31 +838,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp) if (rc < 0) return rc; } - -/* - * Check if this port is in the middle of closing. If so then wait - * until it is closed then return error status, based on flag settings. - * The sleep here does not need interrupt protection since the wakeup - * for it is done with the same context. - */ - if (portp->port.flags & ASYNC_CLOSING) { - interruptible_sleep_on(&portp->port.close_wait); - if (portp->port.flags & ASYNC_HUP_NOTIFY) - return -EAGAIN; - return -ERESTARTSYS; - } - -/* - * Based on type of open being done check if it can overlap with any - * previous opens still in effect. If we are a normal serial device - * then also we might have to wait for carrier. - */ - if (!(filp->f_flags & O_NONBLOCK)) { - if ((rc = stli_waitcarrier(tty, brdp, portp, filp)) != 0) - return rc; - } - portp->port.flags |= ASYNC_NORMAL_ACTIVE; - return 0; + return tty_port_block_til_ready(&portp->port, tty, filp); } /*****************************************************************************/ @@ -882,25 +847,29 @@ static void stli_close(struct tty_struct *tty, struct file *filp) { struct stlibrd *brdp; struct stliport *portp; + struct tty_port *port; unsigned long flags; portp = tty->driver_data; if (portp == NULL) return; + port = &portp->port; - spin_lock_irqsave(&stli_lock, flags); + spin_lock_irqsave(&port->lock, flags); if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&stli_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); return; } - if ((tty->count == 1) && (portp->port.count != 1)) - portp->port.count = 1; - if (portp->port.count-- > 1) { - spin_unlock_irqrestore(&stli_lock, flags); + if (tty->count == 1 && port->count != 1) + port->count = 1; + if (port->count-- > 1) { + spin_unlock_irqrestore(&port->lock, flags); return; } - portp->port.flags |= ASYNC_CLOSING; + port->flags |= ASYNC_CLOSING; + tty->closing = 1; + spin_unlock_irqrestore(&port->lock, flags); /* * May want to wait for data to drain before closing. The BUSY flag @@ -908,15 +877,17 @@ static void stli_close(struct tty_struct *tty, struct file *filp) * updated by messages from the slave - indicating when all chars * really have drained. */ + spin_lock_irqsave(&stli_lock, flags); if (tty == stli_txcooktty) stli_flushchars(tty); - tty->closing = 1; spin_unlock_irqrestore(&stli_lock, flags); if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, portp->closing_wait); - portp->port.flags &= ~ASYNC_INITIALIZED; + /* FIXME: port locking here needs attending to */ + port->flags &= ~ASYNC_INITIALIZED; + brdp = stli_brds[portp->brdnr]; stli_rawclose(brdp, portp, 0, 0); if (tty->termios->c_cflag & HUPCL) { @@ -937,14 +908,14 @@ static void stli_close(struct tty_struct *tty, struct file *filp) tty->closing = 0; tty_port_tty_set(&portp->port, NULL); - if (portp->openwaitcnt) { + if (port->blocked_open) { if (portp->close_delay) msleep_interruptible(jiffies_to_msecs(portp->close_delay)); - wake_up_interruptible(&portp->port.open_wait); + wake_up_interruptible(&port->open_wait); } - portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - wake_up_interruptible(&portp->port.close_wait); + port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); + wake_up_interruptible(&port->close_wait); } /*****************************************************************************/ @@ -1189,63 +1160,17 @@ static int stli_carrier_raised(struct tty_port *port) return (portp->sigs & TIOCM_CD) ? 1 : 0; } -/* - * Possibly need to wait for carrier (DCD signal) to come high. Say - * maybe because if we are clocal then we don't need to wait... - */ - -static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp, - struct stliport *portp, struct file *filp) +static void stli_raise_dtr_rts(struct tty_port *port) { - unsigned long flags; - int rc, doclocal; - struct tty_port *port = &portp->port; - - rc = 0; - doclocal = 0; - - if (tty->termios->c_cflag & CLOCAL) - doclocal++; - - spin_lock_irqsave(&stli_lock, flags); - portp->openwaitcnt++; - if (! tty_hung_up_p(filp)) - port->count--; - spin_unlock_irqrestore(&stli_lock, flags); - - for (;;) { - stli_mkasysigs(&portp->asig, 1, 1); - if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, - &portp->asig, sizeof(asysigs_t), 0)) < 0) - break; - if (tty_hung_up_p(filp) || - ((port->flags & ASYNC_INITIALIZED) == 0)) { - if (port->flags & ASYNC_HUP_NOTIFY) - rc = -EBUSY; - else - rc = -ERESTARTSYS; - break; - } - if (((port->flags & ASYNC_CLOSING) == 0) && - (doclocal || tty_port_carrier_raised(port))) { - break; - } - if (signal_pending(current)) { - rc = -ERESTARTSYS; - break; - } - interruptible_sleep_on(&port->open_wait); - } - - spin_lock_irqsave(&stli_lock, flags); - if (! tty_hung_up_p(filp)) - port->count++; - portp->openwaitcnt--; - spin_unlock_irqrestore(&stli_lock, flags); - - return rc; + struct stliport *portp = container_of(port, struct stliport, port); + struct stlibrd *brdp = stli_brds[portp->brdnr]; + stli_mkasysigs(&portp->asig, 1, 1); + if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, + sizeof(asysigs_t), 0) < 0) + printk(KERN_WARNING "istallion: dtr raise failed.\n"); } + /*****************************************************************************/ /* @@ -1828,6 +1753,7 @@ static void stli_hangup(struct tty_struct *tty) { struct stliport *portp; struct stlibrd *brdp; + struct tty_port *port; unsigned long flags; portp = tty->driver_data; @@ -1838,8 +1764,11 @@ static void stli_hangup(struct tty_struct *tty) brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return; + port = &portp->port; - portp->port.flags &= ~ASYNC_INITIALIZED; + spin_lock_irqsave(&port->lock, flags); + port->flags &= ~ASYNC_INITIALIZED; + spin_unlock_irqrestore(&port->lock, flags); if (!test_bit(ST_CLOSING, &portp->state)) stli_rawclose(brdp, portp, 0, 0); @@ -1860,12 +1789,9 @@ static void stli_hangup(struct tty_struct *tty) clear_bit(ST_TXBUSY, &portp->state); clear_bit(ST_RXSTOP, &portp->state); set_bit(TTY_IO_ERROR, &tty->flags); - tty_port_tty_set(&portp->port, NULL); - portp->port.flags &= ~ASYNC_NORMAL_ACTIVE; - portp->port.count = 0; spin_unlock_irqrestore(&stli_lock, flags); - wake_up_interruptible(&portp->port.open_wait); + tty_port_hangup(port); } /*****************************************************************************/ @@ -4528,6 +4454,7 @@ static const struct tty_operations stli_ops = { static const struct tty_port_operations stli_port_ops = { .carrier_raised = stli_carrier_raised, + .raise_dtr_rts = stli_raise_dtr_rts, }; /*****************************************************************************/ -- cgit v1.2.3 From 4350f3ffec7a7e70770a7369186b3db7d97acfdf Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:46:24 +0000 Subject: tty: rework stallion to use the tty_port bits Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/stallion.c | 142 +++++++++++++----------------------------------- 1 file changed, 38 insertions(+), 104 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c index 12aecdaf61e..77eef61c46f 100644 --- a/drivers/char/stallion.c +++ b/drivers/char/stallion.c @@ -409,7 +409,6 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns static int stl_brdinit(struct stlbrd *brdp); static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp); static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp); -static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, struct file *filp); /* * CD1400 uart specific handling functions. @@ -705,8 +704,9 @@ static int stl_open(struct tty_struct *tty, struct file *filp) { struct stlport *portp; struct stlbrd *brdp; + struct tty_port *port; unsigned int minordev, brdnr, panelnr; - int portnr, rc; + int portnr; pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name); @@ -717,6 +717,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp) brdp = stl_brds[brdnr]; if (brdp == NULL) return -ENODEV; + minordev = MINOR2PORT(minordev); for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) { if (brdp->panels[panelnr] == NULL) @@ -733,16 +734,17 @@ static int stl_open(struct tty_struct *tty, struct file *filp) portp = brdp->panels[panelnr]->ports[portnr]; if (portp == NULL) return -ENODEV; + port = &portp->port; /* * On the first open of the device setup the port hardware, and * initialize the per port data structure. */ - tty_port_tty_set(&portp->port, tty); + tty_port_tty_set(port, tty); tty->driver_data = portp; - portp->port.count++; + port->count++; - if ((portp->port.flags & ASYNC_INITIALIZED) == 0) { + if ((port->flags & ASYNC_INITIALIZED) == 0) { if (!portp->tx.buf) { portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL); if (!portp->tx.buf) @@ -756,34 +758,9 @@ static int stl_open(struct tty_struct *tty, struct file *filp) stl_enablerxtx(portp, 1, 1); stl_startrxtx(portp, 1, 0); clear_bit(TTY_IO_ERROR, &tty->flags); - portp->port.flags |= ASYNC_INITIALIZED; - } - -/* - * Check if this port is in the middle of closing. If so then wait - * until it is closed then return error status, based on flag settings. - * The sleep here does not need interrupt protection since the wakeup - * for it is done with the same context. - */ - if (portp->port.flags & ASYNC_CLOSING) { - interruptible_sleep_on(&portp->port.close_wait); - if (portp->port.flags & ASYNC_HUP_NOTIFY) - return -EAGAIN; - return -ERESTARTSYS; + port->flags |= ASYNC_INITIALIZED; } - -/* - * Based on type of open being done check if it can overlap with any - * previous opens still in effect. If we are a normal serial device - * then also we might have to wait for carrier. - */ - if (!(filp->f_flags & O_NONBLOCK)) - if ((rc = stl_waitcarrier(tty, portp, filp)) != 0) - return rc; - - portp->port.flags |= ASYNC_NORMAL_ACTIVE; - - return 0; + return tty_port_block_til_ready(port, tty, filp); } /*****************************************************************************/ @@ -794,60 +771,11 @@ static int stl_carrier_raised(struct tty_port *port) return (portp->sigs & TIOCM_CD) ? 1 : 0; } -/* - * Possibly need to wait for carrier (DCD signal) to come high. Say - * maybe because if we are clocal then we don't need to wait... - */ - -static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, - struct file *filp) +static void stl_raise_dtr_rts(struct tty_port *port) { - unsigned long flags; - int rc, doclocal; - struct tty_port *port = &portp->port; - - pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp); - - rc = 0; - doclocal = 0; - - spin_lock_irqsave(&stallion_lock, flags); - - if (tty->termios->c_cflag & CLOCAL) - doclocal++; - - portp->openwaitcnt++; - if (! tty_hung_up_p(filp)) - port->count--; - - for (;;) { - /* Takes brd_lock internally */ - stl_setsignals(portp, 1, 1); - if (tty_hung_up_p(filp) || - ((port->flags & ASYNC_INITIALIZED) == 0)) { - if (port->flags & ASYNC_HUP_NOTIFY) - rc = -EBUSY; - else - rc = -ERESTARTSYS; - break; - } - if (((port->flags & ASYNC_CLOSING) == 0) && - (doclocal || tty_port_carrier_raised(port))) - break; - if (signal_pending(current)) { - rc = -ERESTARTSYS; - break; - } - /* FIXME */ - interruptible_sleep_on(&port->open_wait); - } - - if (! tty_hung_up_p(filp)) - port->count++; - portp->openwaitcnt--; - spin_unlock_irqrestore(&stallion_lock, flags); - - return rc; + struct stlport *portp = container_of(port, struct stlport, port); + /* Takes brd_lock internally */ + stl_setsignals(portp, 1, 1); } /*****************************************************************************/ @@ -899,6 +827,7 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout) static void stl_close(struct tty_struct *tty, struct file *filp) { struct stlport *portp; + struct tty_port *port; unsigned long flags; pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp); @@ -906,21 +835,22 @@ static void stl_close(struct tty_struct *tty, struct file *filp) portp = tty->driver_data; if (portp == NULL) return; + port = &portp->port; - spin_lock_irqsave(&stallion_lock, flags); + spin_lock_irqsave(&port->lock, flags); if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&stallion_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); return; } - if ((tty->count == 1) && (portp->port.count != 1)) - portp->port.count = 1; - if (portp->port.count-- > 1) { - spin_unlock_irqrestore(&stallion_lock, flags); + if (tty->count == 1 && port->count != 1) + port->count = 1; + if (port->count-- > 1) { + spin_unlock_irqrestore(&port->lock, flags); return; } - portp->port.count = 0; - portp->port.flags |= ASYNC_CLOSING; + port->count = 0; + port->flags |= ASYNC_CLOSING; /* * May want to wait for any data to drain before closing. The BUSY @@ -930,16 +860,16 @@ static void stl_close(struct tty_struct *tty, struct file *filp) */ tty->closing = 1; - spin_unlock_irqrestore(&stallion_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, portp->closing_wait); stl_waituntilsent(tty, (HZ / 2)); - spin_lock_irqsave(&stallion_lock, flags); + spin_lock_irqsave(&port->lock, flags); portp->port.flags &= ~ASYNC_INITIALIZED; - spin_unlock_irqrestore(&stallion_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); stl_disableintrs(portp); if (tty->termios->c_cflag & HUPCL) @@ -957,16 +887,16 @@ static void stl_close(struct tty_struct *tty, struct file *filp) tty_ldisc_flush(tty); tty->closing = 0; - tty_port_tty_set(&portp->port, NULL); + tty_port_tty_set(port, NULL); - if (portp->openwaitcnt) { + if (port->blocked_open) { if (portp->close_delay) msleep_interruptible(jiffies_to_msecs(portp->close_delay)); wake_up_interruptible(&portp->port.open_wait); } portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - wake_up_interruptible(&portp->port.close_wait); + wake_up_interruptible(&port->close_wait); } /*****************************************************************************/ @@ -1414,14 +1344,20 @@ static void stl_stop(struct tty_struct *tty) static void stl_hangup(struct tty_struct *tty) { struct stlport *portp; + struct tty_port *port; + unsigned long flags; pr_debug("stl_hangup(tty=%p)\n", tty); portp = tty->driver_data; if (portp == NULL) return; + port = &portp->port; + + spin_lock_irqsave(&port->lock, flags); + port->flags &= ~ASYNC_INITIALIZED; + spin_unlock_irqrestore(&port->lock, flags); - portp->port.flags &= ~ASYNC_INITIALIZED; stl_disableintrs(portp); if (tty->termios->c_cflag & HUPCL) stl_setsignals(portp, 0, 0); @@ -1435,10 +1371,7 @@ static void stl_hangup(struct tty_struct *tty) portp->tx.head = NULL; portp->tx.tail = NULL; } - tty_port_tty_set(&portp->port, NULL); - portp->port.flags &= ~ASYNC_NORMAL_ACTIVE; - portp->port.count = 0; - wake_up_interruptible(&portp->port.open_wait); + tty_port_hangup(port); } /*****************************************************************************/ @@ -2671,6 +2604,7 @@ static const struct tty_operations stl_ops = { static const struct tty_port_operations stl_port_ops = { .carrier_raised = stl_carrier_raised, + .raise_dtr_rts = stl_raise_dtr_rts, }; /*****************************************************************************/ -- cgit v1.2.3 From 0fdeceb88df7f4d9e4734859bcd650e8584cc0e4 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:46:34 +0000 Subject: tty: ESP has been broken for locking etc forver Mark it broken Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index c52a167227e..1697043119b 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -190,7 +190,7 @@ config DIGIEPCA config ESPSERIAL tristate "Hayes ESP serial port support" - depends on SERIAL_NONSTANDARD && ISA && ISA_DMA_API + depends on SERIAL_NONSTANDARD && ISA && ISA_DMA_API && BROKEN help This is a driver which supports Hayes ESP serial ports. Both single port cards and multiport cards are supported. Make sure to read -- cgit v1.2.3 From 7834909f1eb96ba7c49ca2b9e3a69b500a2cff76 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:46:43 +0000 Subject: tty: tty port zero baud open If we have no speed set at some point then we should not raise DTR/RTS at that point when opening as the tty is not ready Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/tty_port.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index ff94182b381..0723664fe0a 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -216,7 +216,8 @@ int tty_port_block_til_ready(struct tty_port *port, while (1) { /* Indicate we are open */ - tty_port_raise_dtr_rts(port); + if (tty->termios->c_cflag & CBAUD) + tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); /* Check for a hangup or uninitialised port. Return accordingly */ -- cgit v1.2.3 From a6614999e800cf3a134ce93ea46ef837e3c0e76e Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:46:50 +0000 Subject: tty: Introduce some close helpers for ports Again this is a lot of common code we can unify Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/isicom.c | 66 ++++++--------------------------------- drivers/char/istallion.c | 78 +++++++++++++++++----------------------------- drivers/char/mxser.c | 56 ++++++--------------------------- drivers/char/riscom8.c | 49 +++-------------------------- drivers/char/stallion.c | 39 +++-------------------- drivers/char/synclink.c | 58 ++-------------------------------- drivers/char/synclink_gt.c | 51 ++---------------------------- drivers/char/synclinkmp.c | 58 ++-------------------------------- drivers/char/tty_port.c | 58 ++++++++++++++++++++++++++++++++++ 9 files changed, 123 insertions(+), 390 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index bac55cf4424..24aa6e88e22 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c @@ -945,76 +945,30 @@ static void isicom_flush_buffer(struct tty_struct *tty) static void isicom_close(struct tty_struct *tty, struct file *filp) { - struct isi_port *port = tty->driver_data; + struct isi_port *ip = tty->driver_data; + struct tty_port *port = &ip->port; struct isi_board *card; unsigned long flags; - if (!port) - return; - card = port->card; - if (isicom_paranoia_check(port, tty->name, "isicom_close")) - return; - - pr_dbg("Close start!!!.\n"); - - spin_lock_irqsave(&port->port.lock, flags); - if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&port->port.lock, flags); - return; - } - - if (tty->count == 1 && port->port.count != 1) { - printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port " - "count tty->count = 1 port count = %d.\n", - card->base, port->port.count); - port->port.count = 1; - } - if (--port->port.count < 0) { - printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port " - "count for channel%d = %d", card->base, port->channel, - port->port.count); - port->port.count = 0; - } + BUG_ON(!ip); - if (port->port.count) { - spin_unlock_irqrestore(&port->port.lock, flags); + card = ip->card; + if (isicom_paranoia_check(ip, tty->name, "isicom_close")) return; - } - port->port.flags |= ASYNC_CLOSING; - tty->closing = 1; - spin_unlock_irqrestore(&port->port.lock, flags); - if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) - tty_wait_until_sent(tty, port->port.closing_wait); /* indicate to the card that no more data can be received on this port */ spin_lock_irqsave(&card->card_lock, flags); - if (port->port.flags & ASYNC_INITIALIZED) { - card->port_status &= ~(1 << port->channel); + if (port->flags & ASYNC_INITIALIZED) { + card->port_status &= ~(1 << ip->channel); outw(card->port_status, card->base + 0x02); } - isicom_shutdown_port(port); + isicom_shutdown_port(ip); spin_unlock_irqrestore(&card->card_lock, flags); isicom_flush_buffer(tty); - tty_ldisc_flush(tty); - - spin_lock_irqsave(&port->port.lock, flags); - tty->closing = 0; - - if (port->port.blocked_open) { - spin_unlock_irqrestore(&port->port.lock, flags); - if (port->port.close_delay) { - pr_dbg("scheduling until time out.\n"); - msleep_interruptible( - jiffies_to_msecs(port->port.close_delay)); - } - spin_lock_irqsave(&port->port.lock, flags); - wake_up_interruptible(&port->port.open_wait); - } - port->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); - wake_up_interruptible(&port->port.close_wait); - spin_unlock_irqrestore(&port->port.lock, flags); + + tty_port_close_end(port, tty); } /* write et all */ diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c index 4c69ab97339..5c3dc6b8411 100644 --- a/drivers/char/istallion.c +++ b/drivers/char/istallion.c @@ -767,7 +767,7 @@ static int stli_parsebrd(struct stlconf *confp, char **argp) break; } if (i == ARRAY_SIZE(stli_brdstr)) { - printk("STALLION: unknown board name, %s?\n", argp[0]); + printk(KERN_WARNING "istallion: unknown board name, %s?\n", argp[0]); return 0; } @@ -855,21 +855,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp) return; port = &portp->port; - spin_lock_irqsave(&port->lock, flags); - if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&port->lock, flags); - return; - } - if (tty->count == 1 && port->count != 1) - port->count = 1; - if (port->count-- > 1) { - spin_unlock_irqrestore(&port->lock, flags); + if (tty_port_close_start(port, tty, filp) == 0) return; - } - - port->flags |= ASYNC_CLOSING; - tty->closing = 1; - spin_unlock_irqrestore(&port->lock, flags); /* * May want to wait for data to drain before closing. The BUSY flag @@ -882,6 +869,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp) stli_flushchars(tty); spin_unlock_irqrestore(&stli_lock, flags); + /* We end up doing this twice for the moment. This needs looking at + eventually. Note we still use portp->closing_wait as a result */ if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, portp->closing_wait); @@ -905,17 +894,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp) set_bit(ST_DOFLUSHRX, &portp->state); stli_flushbuffer(tty); - tty->closing = 0; - tty_port_tty_set(&portp->port, NULL); - - if (port->blocked_open) { - if (portp->close_delay) - msleep_interruptible(jiffies_to_msecs(portp->close_delay)); - wake_up_interruptible(&port->open_wait); - } - - port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - wake_up_interruptible(&port->close_wait); + tty_port_close_end(port, tty); + tty_port_tty_set(port, NULL); } /*****************************************************************************/ @@ -1482,7 +1462,7 @@ static int stli_getserial(struct stliport *portp, struct serial_struct __user *s sio.irq = 0; sio.flags = portp->port.flags; sio.baud_base = portp->baud_base; - sio.close_delay = portp->close_delay; + sio.close_delay = portp->port.close_delay; sio.closing_wait = portp->closing_wait; sio.custom_divisor = portp->custom_divisor; sio.xmit_fifo_size = 0; @@ -1514,7 +1494,7 @@ static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *s return -EFAULT; if (!capable(CAP_SYS_ADMIN)) { if ((sio.baud_base != portp->baud_base) || - (sio.close_delay != portp->close_delay) || + (sio.close_delay != portp->port.close_delay) || ((sio.flags & ~ASYNC_USR_MASK) != (portp->port.flags & ~ASYNC_USR_MASK))) return -EPERM; @@ -1523,7 +1503,7 @@ static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *s portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) | (sio.flags & ASYNC_USR_MASK); portp->baud_base = sio.baud_base; - portp->close_delay = sio.close_delay; + portp->port.close_delay = sio.close_delay; portp->closing_wait = sio.closing_wait; portp->custom_divisor = sio.custom_divisor; @@ -2065,7 +2045,7 @@ static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigne unsigned char __iomem *bits; if (test_bit(ST_CMDING, &portp->state)) { - printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n", + printk(KERN_ERR "istallion: command already busy, cmd=%x!\n", (int) cmd); return; } @@ -2625,7 +2605,7 @@ static int stli_initports(struct stlibrd *brdp) for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { portp = kzalloc(sizeof(struct stliport), GFP_KERNEL); if (!portp) { - printk("STALLION: failed to allocate port structure\n"); + printk(KERN_WARNING "istallion: failed to allocate port structure\n"); continue; } tty_port_init(&portp->port); @@ -2635,7 +2615,7 @@ static int stli_initports(struct stlibrd *brdp) portp->brdnr = brdp->brdnr; portp->panelnr = panelnr; portp->baud_base = STL_BAUDBASE; - portp->close_delay = STL_CLOSEDELAY; + portp->port.close_delay = STL_CLOSEDELAY; portp->closing_wait = 30 * HZ; init_waitqueue_head(&portp->port.open_wait); init_waitqueue_head(&portp->port.close_wait); @@ -2692,7 +2672,7 @@ static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offse unsigned char val; if (offset > brdp->memsize) { - printk(KERN_ERR "STALLION: shared memory pointer=%x out of " + printk(KERN_ERR "istallion: shared memory pointer=%x out of " "range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr); ptr = NULL; @@ -2766,7 +2746,7 @@ static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long off unsigned char val; if (offset > brdp->memsize) { - printk(KERN_ERR "STALLION: shared memory pointer=%x out of " + printk(KERN_ERR "istallion: shared memory pointer=%x out of " "range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr); ptr = NULL; @@ -2818,7 +2798,7 @@ static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long off unsigned char val; if (offset > brdp->memsize) { - printk(KERN_ERR "STALLION: shared memory pointer=%x out of " + printk(KERN_ERR "istallion: shared memory pointer=%x out of " "range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr); ptr = NULL; @@ -2863,7 +2843,7 @@ static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long of unsigned char val; if (offset > brdp->memsize) { - printk(KERN_ERR "STALLION: shared memory pointer=%x out of " + printk(KERN_ERR "istallion: shared memory pointer=%x out of " "range at line=%d(%d), board=%d\n", (int) offset, line, __LINE__, brdp->brdnr); ptr = NULL; @@ -2928,7 +2908,7 @@ static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offse void __iomem *ptr; if (offset > brdp->memsize) { - printk(KERN_ERR "STALLION: shared memory pointer=%x out of " + printk(KERN_ERR "istallion: shared memory pointer=%x out of " "range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr); ptr = NULL; @@ -2994,7 +2974,7 @@ static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offs unsigned char val; if (offset > brdp->memsize) { - printk(KERN_ERR "STALLION: shared memory pointer=%x out of " + printk(KERN_ERR "istallion: shared memory pointer=%x out of " "range at line=%d(%d), brd=%d\n", (int) offset, line, __LINE__, brdp->brdnr); ptr = NULL; @@ -3433,7 +3413,7 @@ static int stli_startbrd(struct stlibrd *brdp) #endif if (nrdevs < (brdp->nrports + 1)) { - printk(KERN_ERR "STALLION: slave failed to allocate memory for " + printk(KERN_ERR "istallion: slave failed to allocate memory for " "all devices, devices=%d\n", nrdevs); brdp->nrports = nrdevs - 1; } @@ -3443,13 +3423,13 @@ static int stli_startbrd(struct stlibrd *brdp) brdp->bitsize = (nrdevs + 7) / 8; memoff = readl(&hdrp->memp); if (memoff > brdp->memsize) { - printk(KERN_ERR "STALLION: corrupted shared memory region?\n"); + printk(KERN_ERR "istallion: corrupted shared memory region?\n"); rc = -EIO; goto stli_donestartup; } memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff); if (readw(&memp->dtype) != TYP_ASYNCTRL) { - printk(KERN_ERR "STALLION: no slave control device found\n"); + printk(KERN_ERR "istallion: no slave control device found\n"); goto stli_donestartup; } memp++; @@ -3534,7 +3514,7 @@ static int __devinit stli_brdinit(struct stlibrd *brdp) retval = stli_initonb(brdp); break; default: - printk(KERN_ERR "STALLION: board=%d is unknown board " + printk(KERN_ERR "istallion: board=%d is unknown board " "type=%d\n", brdp->brdnr, brdp->brdtype); retval = -ENODEV; } @@ -3543,7 +3523,7 @@ static int __devinit stli_brdinit(struct stlibrd *brdp) return retval; stli_initports(brdp); - printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x " + printk(KERN_INFO "istallion: %s found, board=%d io=%x mem=%x " "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype], brdp->brdnr, brdp->iobase, (int) brdp->memaddr, brdp->nrpanels, brdp->nrports); @@ -3637,7 +3617,7 @@ static int stli_eisamemprobe(struct stlibrd *brdp) if (! foundit) { brdp->memaddr = 0; brdp->membase = NULL; - printk(KERN_ERR "STALLION: failed to probe shared memory " + printk(KERN_ERR "istallion: failed to probe shared memory " "region for %s in EISA slot=%d\n", stli_brdnames[brdp->brdtype], (brdp->iobase >> 12)); return -ENODEV; @@ -3782,7 +3762,7 @@ static int __devinit stli_pciprobe(struct pci_dev *pdev, mutex_lock(&stli_brdslock); brdnr = stli_getbrdnr(); if (brdnr < 0) { - printk(KERN_INFO "STALLION: too many boards found, " + printk(KERN_INFO "istallion: too many boards found, " "maximum supported %d\n", STL_MAXBRDS); mutex_unlock(&stli_brdslock); retval = -EIO; @@ -3854,7 +3834,7 @@ static struct stlibrd *stli_allocbrd(void) brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL); if (!brdp) { - printk(KERN_ERR "STALLION: failed to allocate memory " + printk(KERN_ERR "istallion: failed to allocate memory " "(size=%Zd)\n", sizeof(struct stlibrd)); return NULL; } @@ -4493,7 +4473,7 @@ static int __init istallion_module_init(void) stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); if (!stli_txcookbuf) { - printk(KERN_ERR "STALLION: failed to allocate memory " + printk(KERN_ERR "istallion: failed to allocate memory " "(size=%d)\n", STLI_TXBUFSIZE); retval = -ENOMEM; goto err; @@ -4518,7 +4498,7 @@ static int __init istallion_module_init(void) retval = tty_register_driver(stli_serial); if (retval) { - printk(KERN_ERR "STALLION: failed to register serial driver\n"); + printk(KERN_ERR "istallion: failed to register serial driver\n"); goto err_ttyput; } @@ -4532,7 +4512,7 @@ static int __init istallion_module_init(void) */ retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem); if (retval) { - printk(KERN_ERR "STALLION: failed to register serial memory " + printk(KERN_ERR "istallion: failed to register serial memory " "device\n"); goto err_deinit; } diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index 08ba6eb1a38..402c9f217f8 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -1080,57 +1080,26 @@ static void mxser_flush_buffer(struct tty_struct *tty) static void mxser_close(struct tty_struct *tty, struct file *filp) { struct mxser_port *info = tty->driver_data; + struct tty_port *port = &info->port; unsigned long timeout; - unsigned long flags; if (tty->index == MXSER_PORTS) return; if (!info) return; - spin_lock_irqsave(&info->port.lock, flags); - - if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&info->port.lock, flags); - return; - } - if ((tty->count == 1) && (info->port.count != 1)) { - /* - * Uh, oh. tty->count is 1, which means that the tty - * structure will be freed. Info->port.count should always - * be one in these conditions. If it's greater than - * one, we've got real problems, since it means the - * serial port won't be shutdown. - */ - printk(KERN_ERR "mxser_close: bad serial port count; " - "tty->count is 1, info->port.count is %d\n", info->port.count); - info->port.count = 1; - } - if (--info->port.count < 0) { - printk(KERN_ERR "mxser_close: bad serial port count for " - "ttys%d: %d\n", tty->index, info->port.count); - info->port.count = 0; - } - if (info->port.count) { - spin_unlock_irqrestore(&info->port.lock, flags); + if (tty_port_close_start(port, tty, filp) == 0) return; - } - info->port.flags |= ASYNC_CLOSING; - spin_unlock_irqrestore(&info->port.lock, flags); + /* * Save the termios structure, since this port may have * separate termios for callout and dialin. + * + * FIXME: Can this go ? */ if (info->port.flags & ASYNC_NORMAL_ACTIVE) info->normal_termios = *tty->termios; - /* - * Now we wait for the transmit buffer to clear; and we notify - * the line discipline to only process XON/XOFF characters. - */ - tty->closing = 1; - if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) - tty_wait_until_sent(tty, info->port.closing_wait); /* * At this point we stop accepting input. To do this, we * disable the receive line status interrupts, and tell the @@ -1156,19 +1125,12 @@ static void mxser_close(struct tty_struct *tty, struct file *filp) } } mxser_shutdown(tty); - mxser_flush_buffer(tty); - tty_ldisc_flush(tty); - - tty->closing = 0; - tty_port_tty_set(&info->port, NULL); - if (info->port.blocked_open) { - if (info->port.close_delay) - schedule_timeout_interruptible(info->port.close_delay); - wake_up_interruptible(&info->port.open_wait); - } - info->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); + /* Right now the tty_port set is done outside of the close_end helper + as we don't yet have everyone using refcounts */ + tty_port_close_end(port, tty); + tty_port_tty_set(port, NULL); } static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count) diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c index af34c2054a0..9ac5febd8ab 100644 --- a/drivers/char/riscom8.c +++ b/drivers/char/riscom8.c @@ -929,35 +929,11 @@ static void rc_close(struct tty_struct *tty, struct file *filp) if (!port || rc_paranoia_check(port, tty->name, "close")) return; - spin_lock_irqsave(&port->port.lock, flags); - - if (tty_hung_up_p(filp)) - goto out; - bp = port_Board(port); - if ((tty->count == 1) && (port->port.count != 1)) { - printk(KERN_INFO "rc%d: rc_close: bad port count;" - " tty->count is 1, port count is %d\n", - board_No(bp), port->port.count); - port->port.count = 1; - } - if (--port->port.count < 0) { - printk(KERN_INFO "rc%d: rc_close: bad port count " - "for tty%d: %d\n", - board_No(bp), port_No(port), port->port.count); - port->port.count = 0; - } - if (port->port.count) - goto out; - port->port.flags |= ASYNC_CLOSING; - /* - * Now we wait for the transmit buffer to clear; and we notify - * the line discipline to only process XON/XOFF characters. - */ - tty->closing = 1; - spin_unlock_irqrestore(&port->port.lock, flags); - if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) - tty_wait_until_sent(tty, port->port.closing_wait); + + if (tty_port_close_start(&port->port, tty, filp) == 0) + return; + /* * At this point we stop accepting input. To do this, we * disable the receive line status interrupts, and tell the @@ -989,23 +965,8 @@ static void rc_close(struct tty_struct *tty, struct file *filp) rc_shutdown_port(tty, bp, port); rc_flush_buffer(tty); spin_unlock_irqrestore(&riscom_lock, flags); - tty_ldisc_flush(tty); - spin_lock_irqsave(&port->port.lock, flags); - tty->closing = 0; - port->port.tty = NULL; - if (port->port.blocked_open) { - spin_unlock_irqrestore(&port->port.lock, flags); - if (port->port.close_delay) - msleep_interruptible(jiffies_to_msecs(port->port.close_delay)); - wake_up_interruptible(&port->port.open_wait); - spin_lock_irqsave(&port->port.lock, flags); - } - port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - wake_up_interruptible(&port->port.close_wait); - -out: - spin_unlock_irqrestore(&riscom_lock, flags); + tty_port_close_end(&port->port, tty); } static int rc_write(struct tty_struct *tty, diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c index 77eef61c46f..e1e0dd89ac9 100644 --- a/drivers/char/stallion.c +++ b/drivers/char/stallion.c @@ -833,40 +833,20 @@ static void stl_close(struct tty_struct *tty, struct file *filp) pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp); portp = tty->driver_data; - if (portp == NULL) - return; + BUG_ON(portp == NULL); + port = &portp->port; - spin_lock_irqsave(&port->lock, flags); - if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&port->lock, flags); + if (tty_port_close_start(port, tty, filp) == 0) return; - } - if (tty->count == 1 && port->count != 1) - port->count = 1; - if (port->count-- > 1) { - spin_unlock_irqrestore(&port->lock, flags); - return; - } - - port->count = 0; - port->flags |= ASYNC_CLOSING; - /* * May want to wait for any data to drain before closing. The BUSY * flag keeps track of whether we are still sending or not - it is * very accurate for the cd1400, not quite so for the sc26198. * (The sc26198 has no "end-of-data" interrupt only empty FIFO) */ - tty->closing = 1; - - spin_unlock_irqrestore(&port->lock, flags); - - if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) - tty_wait_until_sent(tty, portp->closing_wait); stl_waituntilsent(tty, (HZ / 2)); - spin_lock_irqsave(&port->lock, flags); portp->port.flags &= ~ASYNC_INITIALIZED; spin_unlock_irqrestore(&port->lock, flags); @@ -883,20 +863,9 @@ static void stl_close(struct tty_struct *tty, struct file *filp) portp->tx.head = NULL; portp->tx.tail = NULL; } - set_bit(TTY_IO_ERROR, &tty->flags); - tty_ldisc_flush(tty); - tty->closing = 0; + tty_port_close_end(port, tty); tty_port_tty_set(port, NULL); - - if (port->blocked_open) { - if (portp->close_delay) - msleep_interruptible(jiffies_to_msecs(portp->close_delay)); - wake_up_interruptible(&portp->port.open_wait); - } - - portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - wake_up_interruptible(&port->close_wait); } /*****************************************************************************/ diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index 0ded4ed3da3..fbd5a5ce2e1 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c @@ -3104,70 +3104,18 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgsl_close(%s) entry, count=%d\n", __FILE__,__LINE__, info->device_name, info->port.count); - - if (!info->port.count) - return; - if (tty_hung_up_p(filp)) + if (tty_port_close_start(&info->port, tty, filp) == 0) goto cleanup; - if ((tty->count == 1) && (info->port.count != 1)) { - /* - * tty->count is 1 and the tty structure will be freed. - * info->port.count should be one in this case. - * if it's not, correct it so that the port is shutdown. - */ - printk("mgsl_close: bad refcount; tty->count is 1, " - "info->port.count is %d\n", info->port.count); - info->port.count = 1; - } - - info->port.count--; - - /* if at least one open remaining, leave hardware active */ - if (info->port.count) - goto cleanup; - - info->port.flags |= ASYNC_CLOSING; - - /* set tty->closing to notify line discipline to - * only process XON/XOFF characters. Only the N_TTY - * discipline appears to use this (ppp does not). - */ - tty->closing = 1; - - /* wait for transmit data to clear all layers */ - - if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) { - if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):mgsl_close(%s) calling tty_wait_until_sent\n", - __FILE__,__LINE__, info->device_name ); - tty_wait_until_sent(tty, info->port.closing_wait); - } - if (info->port.flags & ASYNC_INITIALIZED) mgsl_wait_until_sent(tty, info->timeout); - mgsl_flush_buffer(tty); - tty_ldisc_flush(tty); - shutdown(info); - - tty->closing = 0; + + tty_port_close_end(&info->port, tty); info->port.tty = NULL; - - if (info->port.blocked_open) { - if (info->port.close_delay) { - msleep_interruptible(jiffies_to_msecs(info->port.close_delay)); - } - wake_up_interruptible(&info->port.open_wait); - } - - info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - - wake_up_interruptible(&info->port.close_wait); - cleanup: if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__, diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index 625c9bde3be..53544e21f19 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c @@ -720,44 +720,9 @@ static void close(struct tty_struct *tty, struct file *filp) return; DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count)); - if (!info->port.count) - return; - - if (tty_hung_up_p(filp)) + if (tty_port_close_start(&info->port, tty, filp) == 0) goto cleanup; - if ((tty->count == 1) && (info->port.count != 1)) { - /* - * tty->count is 1 and the tty structure will be freed. - * info->port.count should be one in this case. - * if it's not, correct it so that the port is shutdown. - */ - DBGERR(("%s close: bad refcount; tty->count=1, " - "info->port.count=%d\n", info->device_name, info->port.count)); - info->port.count = 1; - } - - info->port.count--; - - /* if at least one open remaining, leave hardware active */ - if (info->port.count) - goto cleanup; - - info->port.flags |= ASYNC_CLOSING; - - /* set tty->closing to notify line discipline to - * only process XON/XOFF characters. Only the N_TTY - * discipline appears to use this (ppp does not). - */ - tty->closing = 1; - - /* wait for transmit data to clear all layers */ - - if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) { - DBGINFO(("%s call tty_wait_until_sent\n", info->device_name)); - tty_wait_until_sent(tty, info->port.closing_wait); - } - if (info->port.flags & ASYNC_INITIALIZED) wait_until_sent(tty, info->timeout); flush_buffer(tty); @@ -765,20 +730,8 @@ static void close(struct tty_struct *tty, struct file *filp) shutdown(info); - tty->closing = 0; + tty_port_close_end(&info->port, tty); info->port.tty = NULL; - - if (info->port.blocked_open) { - if (info->port.close_delay) { - msleep_interruptible(jiffies_to_msecs(info->port.close_delay)); - } - wake_up_interruptible(&info->port.open_wait); - } - - info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - - wake_up_interruptible(&info->port.close_wait); - cleanup: DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count)); } diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index 1f5c21ec4b1..2aac55bcf5f 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c @@ -810,70 +810,18 @@ static void close(struct tty_struct *tty, struct file *filp) printk("%s(%d):%s close() entry, count=%d\n", __FILE__,__LINE__, info->device_name, info->port.count); - if (!info->port.count) - return; - - if (tty_hung_up_p(filp)) - goto cleanup; - - if ((tty->count == 1) && (info->port.count != 1)) { - /* - * tty->count is 1 and the tty structure will be freed. - * info->port.count should be one in this case. - * if it's not, correct it so that the port is shutdown. - */ - printk("%s(%d):%s close: bad refcount; tty->count is 1, " - "info->port.count is %d\n", - __FILE__,__LINE__, info->device_name, info->port.count); - info->port.count = 1; - } - - info->port.count--; - - /* if at least one open remaining, leave hardware active */ - if (info->port.count) + if (tty_port_close_start(&info->port, tty, filp) == 0) goto cleanup; - - info->port.flags |= ASYNC_CLOSING; - - /* set tty->closing to notify line discipline to - * only process XON/XOFF characters. Only the N_TTY - * discipline appears to use this (ppp does not). - */ - tty->closing = 1; - - /* wait for transmit data to clear all layers */ - - if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) { - if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):%s close() calling tty_wait_until_sent\n", - __FILE__,__LINE__, info->device_name ); - tty_wait_until_sent(tty, info->port.closing_wait); - } - + if (info->port.flags & ASYNC_INITIALIZED) wait_until_sent(tty, info->timeout); flush_buffer(tty); - tty_ldisc_flush(tty); - shutdown(info); - tty->closing = 0; + tty_port_close_end(&info->port, tty); info->port.tty = NULL; - - if (info->port.blocked_open) { - if (info->port.close_delay) { - msleep_interruptible(jiffies_to_msecs(info->port.close_delay)); - } - wake_up_interruptible(&info->port.open_wait); - } - - info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - - wake_up_interruptible(&info->port.close_wait); - cleanup: if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__, diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index 0723664fe0a..b3175f54fe0 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -257,3 +257,61 @@ int tty_port_block_til_ready(struct tty_port *port, } EXPORT_SYMBOL(tty_port_block_til_ready); +int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct file *filp) +{ + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + if (tty_hung_up_p(filp)) { + spin_unlock_irqrestore(&port->lock, flags); + return 0; + } + + if( tty->count == 1 && port->count != 1) { + printk(KERN_WARNING + "tty_port_close_start: tty->count = 1 port count = %d.\n", + port->count); + port->count = 1; + } + if (--port->count < 0) { + printk(KERN_WARNING "tty_port_close_start: count = %d\n", + port->count); + port->count = 0; + } + + if (port->count) { + spin_unlock_irqrestore(&port->lock, flags); + return 0; + } + port->flags |= ASYNC_CLOSING; + tty->closing = 1; + spin_unlock_irqrestore(&port->lock, flags); + if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) + tty_wait_until_sent(tty, port->closing_wait); + return 1; +} +EXPORT_SYMBOL(tty_port_close_start); + +void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) +{ + unsigned long flags; + + tty_ldisc_flush(tty); + + spin_lock_irqsave(&port->lock, flags); + tty->closing = 0; + + if (port->blocked_open) { + spin_unlock_irqrestore(&port->lock, flags); + if (port->close_delay) { + msleep_interruptible( + jiffies_to_msecs(port->close_delay)); + } + spin_lock_irqsave(&port->lock, flags); + wake_up_interruptible(&port->open_wait); + } + port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); + wake_up_interruptible(&port->close_wait); + spin_unlock_irqrestore(&port->lock, flags); +} +EXPORT_SYMBOL(tty_port_close_end); -- cgit v1.2.3 From ff8cb0fd6f195389aefe55d5dac9927d09a9de54 Mon Sep 17 00:00:00 2001 From: Thomas Pfaff Date: Fri, 2 Jan 2009 13:47:13 +0000 Subject: tty: N_TTY SIGIO only works for read The N_TTY ldisc layer does not send SIGIO POLL_OUTs correctly when output is possible due to flawed handling of the TTY_DO_WRITE_WAKEUP bit. It will either send no SIGIOs at all or on every tty wakeup. The fix is to set the bit when the tty driver write would block and test and clear it on write wakeup. [Merged with existing N_TTY patches and a small buglet fixed -- Alan] Signed-off-by: Thomas Pfaff Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/n_tty.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index 3922a084205..f6f0e4ec2b5 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c @@ -1352,10 +1352,8 @@ static void n_tty_write_wakeup(struct tty_struct *tty) /* Write out any echoed characters that are still pending */ process_echoes(tty); - if (tty->fasync) { - set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); + if (tty->fasync && test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) kill_fasync(&tty->fasync, SIGIO, POLL_OUT); - } } /** @@ -2014,6 +2012,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, break_out: __set_current_state(TASK_RUNNING); remove_wait_queue(&tty->write_wait, &wait); + if (b - buf != nr && tty->fasync) + set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); return (b - buf) ? b - buf : retval; } -- cgit v1.2.3 From 0ac6053c4db9369d7b0f9b39c30f4fb04405666b Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:47:20 +0000 Subject: tty: PTYs set TTY_DO_WRITE_WAKEUP when they don't need to The write wakeup is done anyway for the poll while DO_WRITE_WAKUP is cleared, set and managed by the ldisc layer and is no business of the pty code. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/pty.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pty.c b/drivers/char/pty.c index b5daaaa9007..112a6ba9a96 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c @@ -5,8 +5,6 @@ * * Added support for a Unix98-style ptmx device. * -- C. Scott Ananian , 14-Jan-1998 - * Added TTY_DO_WRITE_WAKEUP to enable n_tty to send POLL_OUT to - * waiting writers -- Sapan Bhatia * * When reading this code see also fs/devpts. In particular note that the * driver_data field is used by the devpts side as a binding to the devpts @@ -217,7 +215,6 @@ static int pty_open(struct tty_struct *tty, struct file *filp) clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); set_bit(TTY_THROTTLED, &tty->flags); - set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); retval = 0; out: return retval; -- cgit v1.2.3 From c9f19e96a2f33cd56c2bd19f87a0c4982d011c2b Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:47:26 +0000 Subject: tty: Remove some pointless casts disc_data and driver_data are void * Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/amiserial.c | 34 +++++++++++++++++----------------- drivers/char/epca.c | 10 +++++----- drivers/char/generic_serial.c | 2 +- drivers/char/hvsi.c | 12 ++++++------ drivers/char/n_r3964.c | 12 ++++++------ drivers/char/riscom8.c | 34 +++++++++++++++++----------------- drivers/char/rocket.c | 36 ++++++++++++++++++------------------ drivers/char/selection.c | 2 +- drivers/char/ser_a2232.c | 4 ++-- drivers/char/serial167.c | 32 ++++++++++++++++---------------- drivers/char/specialix.c | 34 +++++++++++++++++----------------- drivers/char/sx.c | 4 ++-- drivers/char/synclink.c | 36 ++++++++++++++++++------------------ drivers/char/synclinkmp.c | 38 +++++++++++++++++++------------------- drivers/char/vme_scc.c | 8 ++++---- drivers/char/vt_ioctl.c | 2 +- 16 files changed, 150 insertions(+), 150 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c index b97aebd7aeb..4e0cfdeab14 100644 --- a/drivers/char/amiserial.c +++ b/drivers/char/amiserial.c @@ -170,7 +170,7 @@ static __inline__ void rtsdtr_ctrl(int bits) */ static void rs_stop(struct tty_struct *tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->name, "rs_stop")) @@ -190,7 +190,7 @@ static void rs_stop(struct tty_struct *tty) static void rs_start(struct tty_struct *tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->name, "rs_start")) @@ -861,7 +861,7 @@ static int rs_put_char(struct tty_struct *tty, unsigned char ch) static void rs_flush_chars(struct tty_struct *tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) @@ -934,7 +934,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count static int rs_write_room(struct tty_struct *tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; if (serial_paranoia_check(info, tty->name, "rs_write_room")) return 0; @@ -943,7 +943,7 @@ static int rs_write_room(struct tty_struct *tty) static int rs_chars_in_buffer(struct tty_struct *tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) return 0; @@ -952,7 +952,7 @@ static int rs_chars_in_buffer(struct tty_struct *tty) static void rs_flush_buffer(struct tty_struct *tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) @@ -969,7 +969,7 @@ static void rs_flush_buffer(struct tty_struct *tty) */ static void rs_send_xchar(struct tty_struct *tty, char ch) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->name, "rs_send_char")) @@ -1004,7 +1004,7 @@ static void rs_send_xchar(struct tty_struct *tty, char ch) */ static void rs_throttle(struct tty_struct * tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; #ifdef SERIAL_DEBUG_THROTTLE char buf[64]; @@ -1029,7 +1029,7 @@ static void rs_throttle(struct tty_struct * tty) static void rs_unthrottle(struct tty_struct * tty) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; #ifdef SERIAL_DEBUG_THROTTLE char buf[64]; @@ -1194,7 +1194,7 @@ static int get_lsr_info(struct async_struct * info, unsigned int __user *value) static int rs_tiocmget(struct tty_struct *tty, struct file *file) { - struct async_struct * info = (struct async_struct *)tty->driver_data; + struct async_struct * info = tty->driver_data; unsigned char control, status; unsigned long flags; @@ -1217,7 +1217,7 @@ static int rs_tiocmget(struct tty_struct *tty, struct file *file) static int rs_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct async_struct * info = (struct async_struct *)tty->driver_data; + struct async_struct * info = tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->name, "rs_ioctl")) @@ -1244,7 +1244,7 @@ static int rs_tiocmset(struct tty_struct *tty, struct file *file, */ static int rs_break(struct tty_struct *tty, int break_state) { - struct async_struct * info = (struct async_struct *)tty->driver_data; + struct async_struct * info = tty->driver_data; unsigned long flags; if (serial_paranoia_check(info, tty->name, "rs_break")) @@ -1264,7 +1264,7 @@ static int rs_break(struct tty_struct *tty, int break_state) static int rs_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { - struct async_struct * info = (struct async_struct *)tty->driver_data; + struct async_struct * info = tty->driver_data; struct async_icount cprev, cnow; /* kernel counter temps */ struct serial_icounter_struct icount; void __user *argp = (void __user *)arg; @@ -1368,7 +1368,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file, static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { - struct async_struct *info = (struct async_struct *)tty->driver_data; + struct async_struct *info = tty->driver_data; unsigned long flags; unsigned int cflag = tty->termios->c_cflag; @@ -1428,7 +1428,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) */ static void rs_close(struct tty_struct *tty, struct file * filp) { - struct async_struct * info = (struct async_struct *)tty->driver_data; + struct async_struct * info = tty->driver_data; struct serial_state *state; unsigned long flags; @@ -1523,7 +1523,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp) */ static void rs_wait_until_sent(struct tty_struct *tty, int timeout) { - struct async_struct * info = (struct async_struct *)tty->driver_data; + struct async_struct * info = tty->driver_data; unsigned long orig_jiffies, char_time; int lsr; @@ -1587,7 +1587,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout) */ static void rs_hangup(struct tty_struct *tty) { - struct async_struct * info = (struct async_struct *)tty->driver_data; + struct async_struct * info = tty->driver_data; struct serial_state *state = info->state; if (serial_paranoia_check(info, tty->name, "rs_hangup")) diff --git a/drivers/char/epca.c b/drivers/char/epca.c index cf2461d34e5..da2d2cf16f5 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c @@ -392,7 +392,7 @@ static struct channel *verifyChannel(struct tty_struct *tty) * through tty->driver_data this should catch it. */ if (tty) { - struct channel *ch = (struct channel *)tty->driver_data; + struct channel *ch = tty->driver_data; if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) { if (ch->magic == EPCA_MAGIC) return ch; @@ -2097,7 +2097,7 @@ static int info_ioctl(struct tty_struct *tty, struct file *file, static int pc_tiocmget(struct tty_struct *tty, struct file *file) { - struct channel *ch = (struct channel *) tty->driver_data; + struct channel *ch = tty->driver_data; struct board_chan __iomem *bc; unsigned int mstat, mflag = 0; unsigned long flags; @@ -2131,7 +2131,7 @@ static int pc_tiocmget(struct tty_struct *tty, struct file *file) static int pc_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct channel *ch = (struct channel *) tty->driver_data; + struct channel *ch = tty->driver_data; unsigned long flags; if (!ch) @@ -2178,7 +2178,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file, unsigned int mflag, mstat; unsigned char startc, stopc; struct board_chan __iomem *bc; - struct channel *ch = (struct channel *) tty->driver_data; + struct channel *ch = tty->driver_data; void __user *argp = (void __user *)arg; if (ch) @@ -2473,7 +2473,7 @@ static void pc_unthrottle(struct tty_struct *tty) static int pc_send_break(struct tty_struct *tty, int msec) { - struct channel *ch = (struct channel *) tty->driver_data; + struct channel *ch = tty->driver_data; unsigned long flags; if (msec == -1) diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c index 2f040d1ed89..9e4e569dc00 100644 --- a/drivers/char/generic_serial.c +++ b/drivers/char/generic_serial.c @@ -511,7 +511,7 @@ void gs_close(struct tty_struct * tty, struct file * filp) func_enter (); - port = (struct gs_port *) tty->driver_data; + port = tty->driver_data; if (!port) return; diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c index af055287271..406f8742a26 100644 --- a/drivers/char/hvsi.c +++ b/drivers/char/hvsi.c @@ -997,14 +997,14 @@ out: static int hvsi_write_room(struct tty_struct *tty) { - struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; + struct hvsi_struct *hp = tty->driver_data; return N_OUTBUF - hp->n_outbuf; } static int hvsi_chars_in_buffer(struct tty_struct *tty) { - struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; + struct hvsi_struct *hp = tty->driver_data; return hp->n_outbuf; } @@ -1070,7 +1070,7 @@ out: */ static void hvsi_throttle(struct tty_struct *tty) { - struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; + struct hvsi_struct *hp = tty->driver_data; pr_debug("%s\n", __func__); @@ -1079,7 +1079,7 @@ static void hvsi_throttle(struct tty_struct *tty) static void hvsi_unthrottle(struct tty_struct *tty) { - struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; + struct hvsi_struct *hp = tty->driver_data; unsigned long flags; int shouldflip = 0; @@ -1100,7 +1100,7 @@ static void hvsi_unthrottle(struct tty_struct *tty) static int hvsi_tiocmget(struct tty_struct *tty, struct file *file) { - struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; + struct hvsi_struct *hp = tty->driver_data; hvsi_get_mctrl(hp); return hp->mctrl; @@ -1109,7 +1109,7 @@ static int hvsi_tiocmget(struct tty_struct *tty, struct file *file) static int hvsi_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; + struct hvsi_struct *hp = tty->driver_data; unsigned long flags; uint16_t new_mctrl; diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c index 4a8215a89ad..d2e93e34322 100644 --- a/drivers/char/n_r3964.c +++ b/drivers/char/n_r3964.c @@ -1003,7 +1003,7 @@ static int r3964_open(struct tty_struct *tty) static void r3964_close(struct tty_struct *tty) { - struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; + struct r3964_info *pInfo = tty->disc_data; struct r3964_client_info *pClient, *pNext; struct r3964_message *pMsg; struct r3964_block_header *pHeader, *pNextHeader; @@ -1058,7 +1058,7 @@ static void r3964_close(struct tty_struct *tty) static ssize_t r3964_read(struct tty_struct *tty, struct file *file, unsigned char __user * buf, size_t nr) { - struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; + struct r3964_info *pInfo = tty->disc_data; struct r3964_client_info *pClient; struct r3964_message *pMsg; struct r3964_client_message theMsg; @@ -1113,7 +1113,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, static ssize_t r3964_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count) { - struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; + struct r3964_info *pInfo = tty->disc_data; struct r3964_block_header *pHeader; struct r3964_client_info *pClient; unsigned char *new_data; @@ -1182,7 +1182,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, static int r3964_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { - struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; + struct r3964_info *pInfo = tty->disc_data; if (pInfo == NULL) return -EINVAL; switch (cmd) { @@ -1216,7 +1216,7 @@ static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old) static unsigned int r3964_poll(struct tty_struct *tty, struct file *file, struct poll_table_struct *wait) { - struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; + struct r3964_info *pInfo = tty->disc_data; struct r3964_client_info *pClient; struct r3964_message *pMsg = NULL; unsigned long flags; @@ -1241,7 +1241,7 @@ static unsigned int r3964_poll(struct tty_struct *tty, struct file *file, static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) { - struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; + struct r3964_info *pInfo = tty->disc_data; const unsigned char *p; char *f, flags = 0; int i; diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c index 9ac5febd8ab..9af8d74875b 100644 --- a/drivers/char/riscom8.c +++ b/drivers/char/riscom8.c @@ -906,7 +906,7 @@ static int rc_open(struct tty_struct *tty, struct file *filp) static void rc_flush_buffer(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; unsigned long flags; if (rc_paranoia_check(port, tty->name, "rc_flush_buffer")) @@ -921,7 +921,7 @@ static void rc_flush_buffer(struct tty_struct *tty) static void rc_close(struct tty_struct *tty, struct file *filp) { - struct riscom_port *port = (struct riscom_port *) tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; unsigned long flags; unsigned long timeout; @@ -972,7 +972,7 @@ static void rc_close(struct tty_struct *tty, struct file *filp) static int rc_write(struct tty_struct *tty, const unsigned char *buf, int count) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; int c, total = 0; unsigned long flags; @@ -1015,7 +1015,7 @@ static int rc_write(struct tty_struct *tty, static int rc_put_char(struct tty_struct *tty, unsigned char ch) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; unsigned long flags; int ret = 0; @@ -1039,7 +1039,7 @@ out: static void rc_flush_chars(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; unsigned long flags; if (rc_paranoia_check(port, tty->name, "rc_flush_chars")) @@ -1059,7 +1059,7 @@ static void rc_flush_chars(struct tty_struct *tty) static int rc_write_room(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; int ret; if (rc_paranoia_check(port, tty->name, "rc_write_room")) @@ -1073,7 +1073,7 @@ static int rc_write_room(struct tty_struct *tty) static int rc_chars_in_buffer(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer")) return 0; @@ -1083,7 +1083,7 @@ static int rc_chars_in_buffer(struct tty_struct *tty) static int rc_tiocmget(struct tty_struct *tty, struct file *file) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; unsigned char status; unsigned int result; @@ -1113,7 +1113,7 @@ static int rc_tiocmget(struct tty_struct *tty, struct file *file) static int rc_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; unsigned long flags; struct riscom_board *bp; @@ -1145,7 +1145,7 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file, static int rc_send_break(struct tty_struct *tty, int length) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp = port_Board(port); unsigned long flags; @@ -1238,7 +1238,7 @@ static int rc_get_serial_info(struct riscom_port *port, static int rc_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; void __user *argp = (void __user *)arg; int retval; @@ -1264,7 +1264,7 @@ static int rc_ioctl(struct tty_struct *tty, struct file *filp, static void rc_throttle(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; unsigned long flags; @@ -1286,7 +1286,7 @@ static void rc_throttle(struct tty_struct *tty) static void rc_unthrottle(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; unsigned long flags; @@ -1308,7 +1308,7 @@ static void rc_unthrottle(struct tty_struct *tty) static void rc_stop(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; unsigned long flags; @@ -1326,7 +1326,7 @@ static void rc_stop(struct tty_struct *tty) static void rc_start(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; unsigned long flags; @@ -1347,7 +1347,7 @@ static void rc_start(struct tty_struct *tty) static void rc_hangup(struct tty_struct *tty) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; struct riscom_board *bp; unsigned long flags; @@ -1368,7 +1368,7 @@ static void rc_hangup(struct tty_struct *tty) static void rc_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { - struct riscom_port *port = (struct riscom_port *)tty->driver_data; + struct riscom_port *port = tty->driver_data; unsigned long flags; if (rc_paranoia_check(port, tty->name, "rc_set_termios")) diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index 9d819808e84..1e68cc2296f 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -1094,7 +1094,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) */ static void rp_close(struct tty_struct *tty, struct file *filp) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; unsigned long flags; int timeout; CHANNEL_t *cp; @@ -1208,7 +1208,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp) static void rp_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; unsigned cflag; @@ -1251,7 +1251,7 @@ static void rp_set_termios(struct tty_struct *tty, static int rp_break(struct tty_struct *tty, int break_state) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; unsigned long flags; if (rocket_paranoia_check(info, "rp_break")) @@ -1297,7 +1297,7 @@ static int sGetChanRI(CHANNEL_T * ChP) */ static int rp_tiocmget(struct tty_struct *tty, struct file *file) { - struct r_port *info = (struct r_port *)tty->driver_data; + struct r_port *info = tty->driver_data; unsigned int control, result, ChanStatus; ChanStatus = sGetChanStatusLo(&info->channel); @@ -1318,7 +1318,7 @@ static int rp_tiocmget(struct tty_struct *tty, struct file *file) static int rp_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct r_port *info = (struct r_port *)tty->driver_data; + struct r_port *info = tty->driver_data; if (set & TIOCM_RTS) info->channel.TxControl[3] |= SET_RTS; @@ -1447,7 +1447,7 @@ static int get_version(struct r_port *info, struct rocket_version __user *retver static int rp_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; void __user *argp = (void __user *)arg; int ret = 0; @@ -1485,7 +1485,7 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file, static void rp_send_xchar(struct tty_struct *tty, char ch) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; if (rocket_paranoia_check(info, "rp_send_xchar")) @@ -1500,7 +1500,7 @@ static void rp_send_xchar(struct tty_struct *tty, char ch) static void rp_throttle(struct tty_struct *tty) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; #ifdef ROCKET_DEBUG_THROTTLE @@ -1520,7 +1520,7 @@ static void rp_throttle(struct tty_struct *tty) static void rp_unthrottle(struct tty_struct *tty) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; #ifdef ROCKET_DEBUG_THROTTLE printk(KERN_INFO "unthrottle %s: %d....\n", tty->name, @@ -1547,7 +1547,7 @@ static void rp_unthrottle(struct tty_struct *tty) */ static void rp_stop(struct tty_struct *tty) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; #ifdef ROCKET_DEBUG_FLOW printk(KERN_INFO "stop %s: %d %d....\n", tty->name, @@ -1563,7 +1563,7 @@ static void rp_stop(struct tty_struct *tty) static void rp_start(struct tty_struct *tty) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; #ifdef ROCKET_DEBUG_FLOW printk(KERN_INFO "start %s: %d %d....\n", tty->name, @@ -1583,7 +1583,7 @@ static void rp_start(struct tty_struct *tty) */ static void rp_wait_until_sent(struct tty_struct *tty, int timeout) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; unsigned long orig_jiffies; int check_time, exit_time; @@ -1640,7 +1640,7 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout) static void rp_hangup(struct tty_struct *tty) { CHANNEL_t *cp; - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; if (rocket_paranoia_check(info, "rp_hangup")) return; @@ -1680,7 +1680,7 @@ static void rp_hangup(struct tty_struct *tty) */ static int rp_put_char(struct tty_struct *tty, unsigned char ch) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; unsigned long flags; @@ -1727,7 +1727,7 @@ static int rp_put_char(struct tty_struct *tty, unsigned char ch) static int rp_write(struct tty_struct *tty, const unsigned char *buf, int count) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; const unsigned char *b; int c, retval = 0; @@ -1819,7 +1819,7 @@ end: */ static int rp_write_room(struct tty_struct *tty) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; int ret; if (rocket_paranoia_check(info, "rp_write_room")) @@ -1840,7 +1840,7 @@ static int rp_write_room(struct tty_struct *tty) */ static int rp_chars_in_buffer(struct tty_struct *tty) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; if (rocket_paranoia_check(info, "rp_chars_in_buffer")) @@ -1861,7 +1861,7 @@ static int rp_chars_in_buffer(struct tty_struct *tty) */ static void rp_flush_buffer(struct tty_struct *tty) { - struct r_port *info = (struct r_port *) tty->driver_data; + struct r_port *info = tty->driver_data; CHANNEL_t *cp; unsigned long flags; diff --git a/drivers/char/selection.c b/drivers/char/selection.c index 2978a49a172..f29fbe9b8ed 100644 --- a/drivers/char/selection.c +++ b/drivers/char/selection.c @@ -306,7 +306,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t */ int paste_selection(struct tty_struct *tty) { - struct vc_data *vc = (struct vc_data *)tty->driver_data; + struct vc_data *vc = tty->driver_data; int pasted = 0; unsigned int count; struct tty_ldisc *ld; diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c index 0c97f34df63..33872a219df 100644 --- a/drivers/char/ser_a2232.c +++ b/drivers/char/ser_a2232.c @@ -460,14 +460,14 @@ static void a2232_throttle(struct tty_struct *tty) if switched on. So the only thing we can do at this layer here is not taking any characters out of the A2232 buffer any more. */ - struct a2232_port *port = (struct a2232_port *) tty->driver_data; + struct a2232_port *port = tty->driver_data; port->throttle_input = -1; } static void a2232_unthrottle(struct tty_struct *tty) { /* Unthrottle: dual to "throttle()" above. */ - struct a2232_port *port = (struct a2232_port *) tty->driver_data; + struct a2232_port *port = tty->driver_data; port->throttle_input = 0; } diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c index a8f15e6be59..f1f24f0ee26 100644 --- a/drivers/char/serial167.c +++ b/drivers/char/serial167.c @@ -315,7 +315,7 @@ u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd) static void cy_stop(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; int channel; unsigned long flags; @@ -337,7 +337,7 @@ static void cy_stop(struct tty_struct *tty) static void cy_start(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; int channel; unsigned long flags; @@ -1062,7 +1062,7 @@ static void config_setup(struct cyclades_port *info) static int cy_put_char(struct tty_struct *tty, unsigned char ch) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; unsigned long flags; #ifdef SERIAL_DEBUG_IO @@ -1090,7 +1090,7 @@ static int cy_put_char(struct tty_struct *tty, unsigned char ch) static void cy_flush_chars(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; unsigned long flags; volatile unsigned char *base_addr = (u_char *) BASE_ADDR; int channel; @@ -1122,7 +1122,7 @@ static void cy_flush_chars(struct tty_struct *tty) */ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; unsigned long flags; int c, total = 0; @@ -1166,7 +1166,7 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count) static int cy_write_room(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; int ret; #ifdef SERIAL_DEBUG_IO @@ -1183,7 +1183,7 @@ static int cy_write_room(struct tty_struct *tty) static int cy_chars_in_buffer(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; #ifdef SERIAL_DEBUG_IO printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */ @@ -1197,7 +1197,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty) static void cy_flush_buffer(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; unsigned long flags; #ifdef SERIAL_DEBUG_IO @@ -1218,7 +1218,7 @@ static void cy_flush_buffer(struct tty_struct *tty) */ static void cy_throttle(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; unsigned long flags; volatile unsigned char *base_addr = (u_char *) BASE_ADDR; int channel; @@ -1250,7 +1250,7 @@ static void cy_throttle(struct tty_struct *tty) static void cy_unthrottle(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; unsigned long flags; volatile unsigned char *base_addr = (u_char *) BASE_ADDR; int channel; @@ -1345,7 +1345,7 @@ check_and_exit: static int cy_tiocmget(struct tty_struct *tty, struct file *file) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; int channel; volatile unsigned char *base_addr = (u_char *) BASE_ADDR; unsigned long flags; @@ -1369,7 +1369,7 @@ static int cy_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; int channel; volatile unsigned char *base_addr = (u_char *) BASE_ADDR; unsigned long flags; @@ -1532,7 +1532,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { unsigned long val; - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; int ret_val = 0; void __user *argp = (void __user *)arg; @@ -1607,7 +1607,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file, static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; #ifdef SERIAL_DEBUG_OTHER printk("cy_set_termios %s\n", tty->name); @@ -1631,7 +1631,7 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios) static void cy_close(struct tty_struct *tty, struct file *filp) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; /* CP('C'); */ #ifdef SERIAL_DEBUG_OTHER @@ -1698,7 +1698,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp) */ void cy_hangup(struct tty_struct *tty) { - struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; + struct cyclades_port *info = tty->driver_data; #ifdef SERIAL_DEBUG_OTHER printk("cy_hangup %s\n", tty->name); /* */ diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c index a16b94f12eb..3c67c3d83de 100644 --- a/drivers/char/specialix.c +++ b/drivers/char/specialix.c @@ -1450,7 +1450,7 @@ static int sx_open(struct tty_struct *tty, struct file *filp) static void sx_flush_buffer(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; unsigned long flags; struct specialix_board *bp; @@ -1472,7 +1472,7 @@ static void sx_flush_buffer(struct tty_struct *tty) static void sx_close(struct tty_struct *tty, struct file *filp) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; unsigned long flags; unsigned long timeout; @@ -1585,7 +1585,7 @@ static void sx_close(struct tty_struct *tty, struct file *filp) static int sx_write(struct tty_struct *tty, const unsigned char *buf, int count) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; int c, total = 0; unsigned long flags; @@ -1637,7 +1637,7 @@ static int sx_write(struct tty_struct *tty, static int sx_put_char(struct tty_struct *tty, unsigned char ch) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; unsigned long flags; struct specialix_board *bp; @@ -1676,7 +1676,7 @@ static int sx_put_char(struct tty_struct *tty, unsigned char ch) static void sx_flush_chars(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; unsigned long flags; struct specialix_board *bp = port_Board(port); @@ -1703,7 +1703,7 @@ static void sx_flush_chars(struct tty_struct *tty) static int sx_write_room(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; int ret; func_enter(); @@ -1724,7 +1724,7 @@ static int sx_write_room(struct tty_struct *tty) static int sx_chars_in_buffer(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; func_enter(); @@ -1738,7 +1738,7 @@ static int sx_chars_in_buffer(struct tty_struct *tty) static int sx_tiocmget(struct tty_struct *tty, struct file *file) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; unsigned char status; unsigned int result; @@ -1780,7 +1780,7 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file) static int sx_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; unsigned long flags; struct specialix_board *bp; @@ -1820,7 +1820,7 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file, static int sx_send_break(struct tty_struct *tty, int length) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp = port_Board(port); unsigned long flags; @@ -1931,7 +1931,7 @@ static int sx_get_serial_info(struct specialix_port *port, static int sx_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; void __user *argp = (void __user *)arg; func_enter(); @@ -1959,7 +1959,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp, static void sx_throttle(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; unsigned long flags; @@ -2004,7 +2004,7 @@ static void sx_throttle(struct tty_struct *tty) static void sx_unthrottle(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; unsigned long flags; @@ -2045,7 +2045,7 @@ static void sx_unthrottle(struct tty_struct *tty) static void sx_stop(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; unsigned long flags; @@ -2072,7 +2072,7 @@ static void sx_stop(struct tty_struct *tty) static void sx_start(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; unsigned long flags; @@ -2100,7 +2100,7 @@ static void sx_start(struct tty_struct *tty) static void sx_hangup(struct tty_struct *tty) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; struct specialix_board *bp; unsigned long flags; @@ -2135,7 +2135,7 @@ static void sx_hangup(struct tty_struct *tty) static void sx_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { - struct specialix_port *port = (struct specialix_port *)tty->driver_data; + struct specialix_port *port = tty->driver_data; unsigned long flags; struct specialix_board *bp; diff --git a/drivers/char/sx.c b/drivers/char/sx.c index a71bc58abe7..b60be7b0dec 100644 --- a/drivers/char/sx.c +++ b/drivers/char/sx.c @@ -1941,7 +1941,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp, static void sx_throttle(struct tty_struct *tty) { - struct sx_port *port = (struct sx_port *)tty->driver_data; + struct sx_port *port = tty->driver_data; func_enter2(); /* If the port is using any type of input flow @@ -1955,7 +1955,7 @@ static void sx_throttle(struct tty_struct *tty) static void sx_unthrottle(struct tty_struct *tty) { - struct sx_port *port = (struct sx_port *)tty->driver_data; + struct sx_port *port = tty->driver_data; func_enter2(); /* Always unthrottle even if flow control is not enabled on diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index fbd5a5ce2e1..b8063d4cad3 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c @@ -977,7 +977,7 @@ static void ldisc_receive_buf(struct tty_struct *tty, */ static void mgsl_stop(struct tty_struct *tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (mgsl_paranoia_check(info, tty->name, "mgsl_stop")) @@ -1000,7 +1000,7 @@ static void mgsl_stop(struct tty_struct *tty) */ static void mgsl_start(struct tty_struct *tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (mgsl_paranoia_check(info, tty->name, "mgsl_start")) @@ -2057,7 +2057,7 @@ static int mgsl_put_char(struct tty_struct *tty, unsigned char ch) */ static void mgsl_flush_chars(struct tty_struct *tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if ( debug_level >= DEBUG_LEVEL_INFO ) @@ -2109,7 +2109,7 @@ static int mgsl_write(struct tty_struct * tty, const unsigned char *buf, int count) { int c, ret = 0; - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if ( debug_level >= DEBUG_LEVEL_INFO ) @@ -2232,7 +2232,7 @@ cleanup: */ static int mgsl_write_room(struct tty_struct *tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; int ret; if (mgsl_paranoia_check(info, tty->name, "mgsl_write_room")) @@ -2267,7 +2267,7 @@ static int mgsl_write_room(struct tty_struct *tty) */ static int mgsl_chars_in_buffer(struct tty_struct *tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgsl_chars_in_buffer(%s)\n", @@ -2301,7 +2301,7 @@ static int mgsl_chars_in_buffer(struct tty_struct *tty) */ static void mgsl_flush_buffer(struct tty_struct *tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -2329,7 +2329,7 @@ static void mgsl_flush_buffer(struct tty_struct *tty) */ static void mgsl_send_xchar(struct tty_struct *tty, char ch) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -2358,7 +2358,7 @@ static void mgsl_send_xchar(struct tty_struct *tty, char ch) */ static void mgsl_throttle(struct tty_struct * tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -2388,7 +2388,7 @@ static void mgsl_throttle(struct tty_struct * tty) */ static void mgsl_unthrottle(struct tty_struct * tty) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -2841,7 +2841,7 @@ static int modem_input_wait(struct mgsl_struct *info,int arg) */ static int tiocmget(struct tty_struct *tty, struct file *file) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned int result; unsigned long flags; @@ -2867,7 +2867,7 @@ static int tiocmget(struct tty_struct *tty, struct file *file) static int tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -2898,7 +2898,7 @@ static int tiocmset(struct tty_struct *tty, struct file *file, */ static int mgsl_break(struct tty_struct *tty, int break_state) { - struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct * info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -2932,7 +2932,7 @@ static int mgsl_break(struct tty_struct *tty, int break_state) static int mgsl_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { - struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct * info = tty->driver_data; int ret; if (debug_level >= DEBUG_LEVEL_INFO) @@ -3042,7 +3042,7 @@ static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigne */ static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { - struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -3096,7 +3096,7 @@ static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termio */ static void mgsl_close(struct tty_struct *tty, struct file * filp) { - struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct * info = tty->driver_data; if (mgsl_paranoia_check(info, tty->name, "mgsl_close")) return; @@ -3136,7 +3136,7 @@ cleanup: */ static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout) { - struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct * info = tty->driver_data; unsigned long orig_jiffies, char_time; if (!info ) @@ -3209,7 +3209,7 @@ exit: */ static void mgsl_hangup(struct tty_struct *tty) { - struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; + struct mgsl_struct * info = tty->driver_data; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgsl_hangup(%s)\n", diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index 2aac55bcf5f..7b0c5b2dd26 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c @@ -801,7 +801,7 @@ cleanup: */ static void close(struct tty_struct *tty, struct file *filp) { - SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO * info = tty->driver_data; if (sanity_check(info, tty->name, "close")) return; @@ -833,7 +833,7 @@ cleanup: */ static void hangup(struct tty_struct *tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s hangup()\n", @@ -856,7 +856,7 @@ static void hangup(struct tty_struct *tty) */ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -909,7 +909,7 @@ static int write(struct tty_struct *tty, const unsigned char *buf, int count) { int c, ret = 0; - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -987,7 +987,7 @@ cleanup: */ static int put_char(struct tty_struct *tty, unsigned char ch) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; int ret = 0; @@ -1024,7 +1024,7 @@ static int put_char(struct tty_struct *tty, unsigned char ch) */ static void send_xchar(struct tty_struct *tty, char ch) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -1048,7 +1048,7 @@ static void send_xchar(struct tty_struct *tty, char ch) */ static void wait_until_sent(struct tty_struct *tty, int timeout) { - SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO * info = tty->driver_data; unsigned long orig_jiffies, char_time; if (!info ) @@ -1115,7 +1115,7 @@ exit: */ static int write_room(struct tty_struct *tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; int ret; if (sanity_check(info, tty->name, "write_room")) @@ -1142,7 +1142,7 @@ static int write_room(struct tty_struct *tty) */ static void flush_chars(struct tty_struct *tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if ( debug_level >= DEBUG_LEVEL_INFO ) @@ -1181,7 +1181,7 @@ static void flush_chars(struct tty_struct *tty) */ static void flush_buffer(struct tty_struct *tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -1203,7 +1203,7 @@ static void flush_buffer(struct tty_struct *tty) */ static void tx_hold(struct tty_struct *tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (sanity_check(info, tty->name, "tx_hold")) @@ -1223,7 +1223,7 @@ static void tx_hold(struct tty_struct *tty) */ static void tx_release(struct tty_struct *tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (sanity_check(info, tty->name, "tx_release")) @@ -1253,7 +1253,7 @@ static void tx_release(struct tty_struct *tty) static int do_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; int error; struct mgsl_icount cnow; /* kernel counter temps */ struct serial_icounter_struct __user *p_cuser; /* user space */ @@ -1464,7 +1464,7 @@ done: */ static int chars_in_buffer(struct tty_struct *tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; if (sanity_check(info, tty->name, "chars_in_buffer")) return 0; @@ -1480,7 +1480,7 @@ static int chars_in_buffer(struct tty_struct *tty) */ static void throttle(struct tty_struct * tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -1505,7 +1505,7 @@ static void throttle(struct tty_struct * tty) */ static void unthrottle(struct tty_struct * tty) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -1536,7 +1536,7 @@ static void unthrottle(struct tty_struct * tty) static int set_break(struct tty_struct *tty, int break_state) { unsigned char RegValue; - SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO * info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -3218,7 +3218,7 @@ static int modem_input_wait(SLMP_INFO *info,int arg) */ static int tiocmget(struct tty_struct *tty, struct file *file) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned int result; unsigned long flags; @@ -3244,7 +3244,7 @@ static int tiocmget(struct tty_struct *tty, struct file *file) static int tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) { - SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; + SLMP_INFO *info = tty->driver_data; unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c index 2d9242a45a0..0e8234bd0e1 100644 --- a/drivers/char/vme_scc.c +++ b/drivers/char/vme_scc.c @@ -784,7 +784,7 @@ static void scc_setsignals(struct scc_port *port, int dtr, int rts) static void scc_send_xchar(struct tty_struct *tty, char ch) { - struct scc_port *port = (struct scc_port *)tty->driver_data; + struct scc_port *port = tty->driver_data; port->x_char = ch; if (ch) @@ -911,7 +911,7 @@ static int scc_open (struct tty_struct * tty, struct file * filp) static void scc_throttle (struct tty_struct * tty) { - struct scc_port *port = (struct scc_port *)tty->driver_data; + struct scc_port *port = tty->driver_data; unsigned long flags; SCC_ACCESS_INIT(port); @@ -927,7 +927,7 @@ static void scc_throttle (struct tty_struct * tty) static void scc_unthrottle (struct tty_struct * tty) { - struct scc_port *port = (struct scc_port *)tty->driver_data; + struct scc_port *port = tty->driver_data; unsigned long flags; SCC_ACCESS_INIT(port); @@ -950,7 +950,7 @@ static int scc_ioctl(struct tty_struct *tty, struct file *file, static int scc_break_ctl(struct tty_struct *tty, int break_state) { - struct scc_port *port = (struct scc_port *)tty->driver_data; + struct scc_port *port = tty->driver_data; unsigned long flags; SCC_ACCESS_INIT(port); diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c index 8944ce508e2..a2dee0eb6da 100644 --- a/drivers/char/vt_ioctl.c +++ b/drivers/char/vt_ioctl.c @@ -366,7 +366,7 @@ do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud, int perm, struct vc_ int vt_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { - struct vc_data *vc = (struct vc_data *)tty->driver_data; + struct vc_data *vc = tty->driver_data; struct console_font_op op; /* used in multiple places here */ struct kbd_struct * kbd; unsigned int console; -- cgit v1.2.3 From 33dd474ae712dc435eb586b44cb771cc8d24e2bd Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:47:32 +0000 Subject: tty: kref nozomi Update the nozomi driver to use krefs Signed-off-by: Linus Torvalds --- drivers/char/nozomi.c | 85 +++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c index 9a34a193528..d6102b644b5 100644 --- a/drivers/char/nozomi.c +++ b/drivers/char/nozomi.c @@ -353,6 +353,7 @@ struct ctrl_ul { /* This holds all information that is needed regarding a port */ struct port { + struct tty_port port; u8 update_flow_control; struct ctrl_ul ctrl_ul; struct ctrl_dl ctrl_dl; @@ -365,8 +366,6 @@ struct port { u8 toggle_ul; u16 token_dl; - struct tty_struct *tty; - int tty_open_count; /* mutex to ensure one access patch to this port */ struct mutex tty_sem; wait_queue_head_t tty_wait; @@ -788,14 +787,14 @@ static void disable_transmit_dl(enum port_type port, struct nozomi *dc) * Return 1 - send buffer to card and ack. * Return 0 - don't ack, don't send buffer to card. */ -static int send_data(enum port_type index, const struct nozomi *dc) +static int send_data(enum port_type index, struct nozomi *dc) { u32 size = 0; - const struct port *port = &dc->port[index]; + struct port *port = &dc->port[index]; const u8 toggle = port->toggle_ul; void __iomem *addr = port->ul_addr[toggle]; const u32 ul_size = port->ul_size[toggle]; - struct tty_struct *tty = port->tty; + struct tty_struct *tty = tty_port_tty_get(&port->port); /* Get data from tty and place in buf for now */ size = __kfifo_get(port->fifo_ul, dc->send_buf, @@ -803,6 +802,7 @@ static int send_data(enum port_type index, const struct nozomi *dc) if (size == 0) { DBG4("No more data to send, disable link:"); + tty_kref_put(tty); return 0; } @@ -815,6 +815,7 @@ static int send_data(enum port_type index, const struct nozomi *dc) if (tty) tty_wakeup(tty); + tty_kref_put(tty); return 1; } @@ -826,7 +827,7 @@ static int receive_data(enum port_type index, struct nozomi *dc) u32 offset = 4; struct port *port = &dc->port[index]; void __iomem *addr = port->dl_addr[port->toggle_dl]; - struct tty_struct *tty = port->tty; + struct tty_struct *tty = tty_port_tty_get(&port->port); int i; if (unlikely(!tty)) { @@ -870,7 +871,7 @@ static int receive_data(enum port_type index, struct nozomi *dc) } set_bit(index, &dc->flip); - + tty_kref_put(tty); return 1; } @@ -1276,9 +1277,15 @@ static irqreturn_t interrupt_handler(int irq, void *dev_id) exit_handler: spin_unlock(&dc->spin_mutex); - for (a = 0; a < NOZOMI_MAX_PORTS; a++) - if (test_and_clear_bit(a, &dc->flip)) - tty_flip_buffer_push(dc->port[a].tty); + for (a = 0; a < NOZOMI_MAX_PORTS; a++) { + struct tty_struct *tty; + if (test_and_clear_bit(a, &dc->flip)) { + tty = tty_port_tty_get(&dc->port[a].port); + if (tty) + tty_flip_buffer_push(tty); + tty_kref_put(tty); + } + } return IRQ_HANDLED; none: spin_unlock(&dc->spin_mutex); @@ -1453,12 +1460,10 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev, for (i = 0; i < MAX_PORT; i++) { mutex_init(&dc->port[i].tty_sem); - dc->port[i].tty_open_count = 0; - dc->port[i].tty = NULL; + tty_port_init(&dc->port[i].port); tty_register_device(ntty_driver, dc->index_start + i, &pdev->dev); } - return 0; err_free_sbuf: @@ -1482,14 +1487,16 @@ static void __devexit tty_exit(struct nozomi *dc) flush_scheduled_work(); - for (i = 0; i < MAX_PORT; ++i) - if (dc->port[i].tty && \ - list_empty(&dc->port[i].tty->hangup_work.entry)) - tty_hangup(dc->port[i].tty); - + for (i = 0; i < MAX_PORT; ++i) { + struct tty_struct *tty = tty_port_tty_get(&dc->port[i].port); + if (tty && list_empty(&tty->hangup_work.entry)) + tty_hangup(tty); + tty_kref_put(tty); + } + /* Racy below - surely should wait for scheduled work to be done or + complete off a hangup method ? */ while (dc->open_ttys) msleep(1); - for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i) tty_unregister_device(ntty_driver, i); } @@ -1579,23 +1586,22 @@ static int ntty_open(struct tty_struct *tty, struct file *file) if (mutex_lock_interruptible(&port->tty_sem)) return -ERESTARTSYS; - port->tty_open_count++; + port->port.count++; dc->open_ttys++; /* Enable interrupt downlink for channel */ - if (port->tty_open_count == 1) { + if (port->port.count == 1) { + /* FIXME: is this needed now ? */ tty->low_latency = 1; tty->driver_data = port; - port->tty = tty; + tty_port_tty_set(&port->port, tty); DBG1("open: %d", port->token_dl); spin_lock_irqsave(&dc->spin_mutex, flags); dc->last_ier = dc->last_ier | port->token_dl; writew(dc->last_ier, dc->reg_ier); spin_unlock_irqrestore(&dc->spin_mutex, flags); } - mutex_unlock(&port->tty_sem); - return 0; } @@ -1606,31 +1612,30 @@ static int ntty_open(struct tty_struct *tty, struct file *file) static void ntty_close(struct tty_struct *tty, struct file *file) { struct nozomi *dc = get_dc_by_tty(tty); - struct port *port = tty->driver_data; + struct port *nport = tty->driver_data; + struct tty_port *port = &nport->port; unsigned long flags; - if (!dc || !port) + if (!dc || !nport) return; - if (mutex_lock_interruptible(&port->tty_sem)) - return; + /* Users cannot interrupt a close */ + mutex_lock(&nport->tty_sem); - if (!port->tty_open_count) - goto exit; + WARN_ON(!port->count); dc->open_ttys--; - port->tty_open_count--; + port->count--; + tty_port_tty_set(port, NULL); - if (port->tty_open_count == 0) { - DBG1("close: %d", port->token_dl); + if (port->count == 0) { + DBG1("close: %d", nport->token_dl); spin_lock_irqsave(&dc->spin_mutex, flags); - dc->last_ier &= ~(port->token_dl); + dc->last_ier &= ~(nport->token_dl); writew(dc->last_ier, dc->reg_ier); spin_unlock_irqrestore(&dc->spin_mutex, flags); } - -exit: - mutex_unlock(&port->tty_sem); + mutex_unlock(&nport->tty_sem); } /* @@ -1660,7 +1665,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer, return -EAGAIN; } - if (unlikely(!port->tty_open_count)) { + if (unlikely(!port->port.count)) { DBG1(" "); goto exit; } @@ -1710,7 +1715,7 @@ static int ntty_write_room(struct tty_struct *tty) if (!mutex_trylock(&port->tty_sem)) return 0; - if (!port->tty_open_count) + if (!port->port.count) goto exit; room = port->fifo_ul->size - __kfifo_len(port->fifo_ul); @@ -1866,7 +1871,7 @@ static s32 ntty_chars_in_buffer(struct tty_struct *tty) goto exit_in_buffer; } - if (unlikely(!port->tty_open_count)) { + if (unlikely(!port->port.count)) { dev_err(&dc->pdev->dev, "No tty open?\n"); rval = -ENODEV; goto exit_in_buffer; -- cgit v1.2.3 From d1c815e549ff40f9e9db65654855118e6bdff6a4 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:47:58 +0000 Subject: tty: relock epca Bring epca into line with the port locking. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/epca.c | 195 ++++++++++++++++++++++++++++------------------------ 1 file changed, 104 insertions(+), 91 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/epca.c b/drivers/char/epca.c index da2d2cf16f5..e07d7925c30 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c @@ -69,7 +69,9 @@ static int invalid_lilo_config; /* * The ISA boards do window flipping into the same spaces so its only sane with - * a single lock. It's still pretty efficient. + * a single lock. It's still pretty efficient. This lock guards the hardware + * and the tty_port lock guards the kernel side stuff like use counts. Take + * this lock inside the port lock if you must take both. */ static DEFINE_SPINLOCK(epca_lock); @@ -156,7 +158,7 @@ static struct channel *verifyChannel(struct tty_struct *); static void pc_sched_event(struct channel *, int); static void epca_error(int, char *); static void pc_close(struct tty_struct *, struct file *); -static void shutdown(struct channel *); +static void shutdown(struct channel *, struct tty_struct *tty); static void pc_hangup(struct tty_struct *); static int pc_write_room(struct tty_struct *); static int pc_chars_in_buffer(struct tty_struct *); @@ -419,76 +421,78 @@ static void epca_error(int line, char *msg) static void pc_close(struct tty_struct *tty, struct file *filp) { struct channel *ch; + struct tty_port *port; unsigned long flags; /* * verifyChannel returns the channel from the tty struct if it is * valid. This serves as a sanity check. */ ch = verifyChannel(tty); - if (ch != NULL) { - spin_lock_irqsave(&epca_lock, flags); - if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&epca_lock, flags); - return; - } - if (ch->port.count-- > 1) { - /* Begin channel is open more than once */ - /* - * Return without doing anything. Someone might still - * be using the channel. - */ - spin_unlock_irqrestore(&epca_lock, flags); - return; - } - /* Port open only once go ahead with shutdown & reset */ - BUG_ON(ch->port.count < 0); + if (ch == NULL) + return; + port = &ch->port; + spin_lock_irqsave(&port->lock, flags); + if (tty_hung_up_p(filp)) { + spin_unlock_irqrestore(&port->lock, flags); + return; + } + if (port->count-- > 1) { + /* Begin channel is open more than once */ /* - * Let the rest of the driver know the channel is being closed. - * This becomes important if an open is attempted before close - * is finished. + * Return without doing anything. Someone might still + * be using the channel. */ - ch->port.flags |= ASYNC_CLOSING; - tty->closing = 1; - - spin_unlock_irqrestore(&epca_lock, flags); - - if (ch->port.flags & ASYNC_INITIALIZED) { - /* Setup an event to indicate when the - transmit buffer empties */ - setup_empty_event(tty, ch); - /* 30 seconds timeout */ - tty_wait_until_sent(tty, 3000); - } - pc_flush_buffer(tty); + spin_unlock_irqrestore(&port->lock, flags); + return; + } + /* Port open only once go ahead with shutdown & reset */ + WARN_ON(port->count < 0); - tty_ldisc_flush(tty); - shutdown(ch); + /* + * Let the rest of the driver know the channel is being closed. + * This becomes important if an open is attempted before close + * is finished. + */ + port->flags |= ASYNC_CLOSING; + tty->closing = 1; - spin_lock_irqsave(&epca_lock, flags); - tty->closing = 0; - ch->event = 0; - ch->port.tty = NULL; - spin_unlock_irqrestore(&epca_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); - if (ch->port.blocked_open) { - if (ch->close_delay) - msleep_interruptible(jiffies_to_msecs(ch->close_delay)); - wake_up_interruptible(&ch->port.open_wait); - } - ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | - ASYNC_CLOSING); - wake_up_interruptible(&ch->port.close_wait); + if (port->flags & ASYNC_INITIALIZED) { + /* Setup an event to indicate when the + transmit buffer empties */ + setup_empty_event(tty, ch); + /* 30 seconds timeout */ + tty_wait_until_sent(tty, 3000); + } + pc_flush_buffer(tty); + tty_ldisc_flush(tty); + shutdown(ch, tty); + + spin_lock_irqsave(&port->lock, flags); + tty->closing = 0; + ch->event = 0; + port->tty = NULL; + spin_unlock_irqrestore(&port->lock, flags); + + if (port->blocked_open) { + if (ch->close_delay) + msleep_interruptible(jiffies_to_msecs(ch->close_delay)); + wake_up_interruptible(&port->open_wait); } + port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | + ASYNC_CLOSING); + wake_up_interruptible(&port->close_wait); } -static void shutdown(struct channel *ch) +static void shutdown(struct channel *ch, struct tty_struct *tty) { unsigned long flags; - struct tty_struct *tty; struct board_chan __iomem *bc; + struct tty_port *port = &ch->port; - if (!(ch->port.flags & ASYNC_INITIALIZED)) + if (!(port->flags & ASYNC_INITIALIZED)) return; spin_lock_irqsave(&epca_lock, flags); @@ -503,7 +507,6 @@ static void shutdown(struct channel *ch) */ if (bc) writeb(0, &bc->idata); - tty = ch->port.tty; /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */ if (tty->termios->c_cflag & HUPCL) { @@ -517,13 +520,15 @@ static void shutdown(struct channel *ch) * will have to reinitialized. Set a flag to indicate this. */ /* Prevent future Digi programmed interrupts from coming active */ - ch->port.flags &= ~ASYNC_INITIALIZED; + port->flags &= ~ASYNC_INITIALIZED; spin_unlock_irqrestore(&epca_lock, flags); } static void pc_hangup(struct tty_struct *tty) { struct channel *ch; + struct tty_port *port; + /* * verifyChannel returns the channel from the tty struct if it is * valid. This serves as a sanity check. @@ -531,18 +536,19 @@ static void pc_hangup(struct tty_struct *tty) ch = verifyChannel(tty); if (ch != NULL) { unsigned long flags; + port = &ch->port; pc_flush_buffer(tty); tty_ldisc_flush(tty); - shutdown(ch); - - spin_lock_irqsave(&epca_lock, flags); - ch->port.tty = NULL; - ch->event = 0; - ch->port.count = 0; - ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED); - spin_unlock_irqrestore(&epca_lock, flags); - wake_up_interruptible(&ch->port.open_wait); + shutdown(ch, tty); + + spin_lock_irqsave(&port->lock, flags); + port->tty = NULL; + ch->event = 0; /* FIXME: review locking of ch->event */ + port->count = 0; + port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED); + spin_unlock_irqrestore(&port->lock, flags); + wake_up_interruptible(&port->open_wait); } } @@ -792,9 +798,10 @@ static int block_til_ready(struct tty_struct *tty, DECLARE_WAITQUEUE(wait, current); int retval, do_clocal = 0; unsigned long flags; + struct tty_port *port = &ch->port; if (tty_hung_up_p(filp)) { - if (ch->port.flags & ASYNC_HUP_NOTIFY) + if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; @@ -805,10 +812,10 @@ static int block_til_ready(struct tty_struct *tty, * If the device is in the middle of being closed, then block until * it's done, and then try again. */ - if (ch->port.flags & ASYNC_CLOSING) { - interruptible_sleep_on(&ch->port.close_wait); + if (port->flags & ASYNC_CLOSING) { + interruptible_sleep_on(&port->close_wait); - if (ch->port.flags & ASYNC_HUP_NOTIFY) + if (port->flags & ASYNC_HUP_NOTIFY) return -EAGAIN; else return -ERESTARTSYS; @@ -819,7 +826,7 @@ static int block_til_ready(struct tty_struct *tty, * If non-blocking mode is set, then make the check up front * and then exit. */ - ch->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } if (tty->termios->c_cflag & CLOCAL) @@ -827,31 +834,31 @@ static int block_til_ready(struct tty_struct *tty, /* Block waiting for the carrier detect and the line to become free */ retval = 0; - add_wait_queue(&ch->port.open_wait, &wait); + add_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&epca_lock, flags); + spin_lock_irqsave(&port->lock, flags); /* We dec count so that pc_close will know when to free things */ if (!tty_hung_up_p(filp)) - ch->port.count--; - ch->port.blocked_open++; + port->count--; + port->blocked_open++; while (1) { set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || - !(ch->port.flags & ASYNC_INITIALIZED)) { - if (ch->port.flags & ASYNC_HUP_NOTIFY) + !(port->flags & ASYNC_INITIALIZED)) { + if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } - if (!(ch->port.flags & ASYNC_CLOSING) && + if (!(port->flags & ASYNC_CLOSING) && (do_clocal || (ch->imodem & ch->dcd))) break; if (signal_pending(current)) { retval = -ERESTARTSYS; break; } - spin_unlock_irqrestore(&epca_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); /* * Allow someone else to be scheduled. We will occasionally go * through this loop until one of the above conditions change. @@ -859,27 +866,28 @@ static int block_til_ready(struct tty_struct *tty, * and prevent this loop from hogging the cpu. */ schedule(); - spin_lock_irqsave(&epca_lock, flags); + spin_lock_irqsave(&port->lock, flags); } __set_current_state(TASK_RUNNING); - remove_wait_queue(&ch->port.open_wait, &wait); + remove_wait_queue(&port->open_wait, &wait); if (!tty_hung_up_p(filp)) - ch->port.count++; - ch->port.blocked_open--; + port->count++; + port->blocked_open--; - spin_unlock_irqrestore(&epca_lock, flags); + spin_unlock_irqrestore(&port->lock, flags); if (retval) return retval; - ch->port.flags |= ASYNC_NORMAL_ACTIVE; + port->flags |= ASYNC_NORMAL_ACTIVE; return 0; } static int pc_open(struct tty_struct *tty, struct file *filp) { struct channel *ch; + struct tty_port *port; unsigned long flags; int line, retval, boardnum; struct board_chan __iomem *bc; @@ -890,6 +898,7 @@ static int pc_open(struct tty_struct *tty, struct file *filp) return -ENODEV; ch = &digi_channels[line]; + port = &ch->port; boardnum = ch->boardnum; /* Check status of board configured in system. */ @@ -926,22 +935,24 @@ static int pc_open(struct tty_struct *tty, struct file *filp) return -ENODEV; } - spin_lock_irqsave(&epca_lock, flags); + spin_lock_irqsave(&port->lock, flags); /* * Every time a channel is opened, increment a counter. This is * necessary because we do not wish to flush and shutdown the channel * until the last app holding the channel open, closes it. */ - ch->port.count++; + port->count++; /* * Set a kernel structures pointer to our local channel structure. This * way we can get to it when passed only a tty struct. */ tty->driver_data = ch; + port->tty = tty; /* * If this is the first time the channel has been opened, initialize * the tty->termios struct otherwise let pc_close handle it. */ + spin_lock(&epca_lock); globalwinon(ch); ch->statusflags = 0; @@ -956,16 +967,16 @@ static int pc_open(struct tty_struct *tty, struct file *filp) writew(head, &bc->rout); /* Set the channels associated tty structure */ - ch->port.tty = tty; /* * The below routine generally sets up parity, baud, flow control * issues, etc.... It effect both control flags and input flags. */ epcaparam(tty, ch); - ch->port.flags |= ASYNC_INITIALIZED; memoff(ch); - spin_unlock_irqrestore(&epca_lock, flags); + spin_unlock(&epca_lock); + port->flags |= ASYNC_INITIALIZED; + spin_unlock_irqrestore(&port->lock, flags); retval = block_til_ready(tty, filp, ch); if (retval) @@ -974,13 +985,15 @@ static int pc_open(struct tty_struct *tty, struct file *filp) * Set this again in case a hangup set it to zero while this open() was * waiting for the line... */ - spin_lock_irqsave(&epca_lock, flags); - ch->port.tty = tty; + spin_lock_irqsave(&port->lock, flags); + port->tty = tty; + spin_lock(&epca_lock); globalwinon(ch); /* Enable Digi Data events */ writeb(1, &bc->idata); memoff(ch); - spin_unlock_irqrestore(&epca_lock, flags); + spin_unlock(&epca_lock); + spin_unlock_irqrestore(&port->lock, flags); return 0; } -- cgit v1.2.3 From 3969ffba71d39ced700d09d9cfde83174396299e Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:48:04 +0000 Subject: tty: refcount the epca driver Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/epca.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/epca.c b/drivers/char/epca.c index e07d7925c30..7a697055e4f 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c @@ -175,7 +175,7 @@ static unsigned termios2digi_h(struct channel *ch, unsigned); static unsigned termios2digi_i(struct channel *ch, unsigned); static unsigned termios2digi_c(struct channel *ch, unsigned); static void epcaparam(struct tty_struct *, struct channel *); -static void receive_data(struct channel *); +static void receive_data(struct channel *, struct tty_struct *tty); static int pc_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long); static int info_ioctl(struct tty_struct *, struct file *, @@ -473,7 +473,7 @@ static void pc_close(struct tty_struct *tty, struct file *filp) spin_lock_irqsave(&port->lock, flags); tty->closing = 0; ch->event = 0; - port->tty = NULL; + tty_port_tty_set(port, NULL); spin_unlock_irqrestore(&port->lock, flags); if (port->blocked_open) { @@ -1029,8 +1029,11 @@ static void __exit epca_module_exit(void) } ch = card_ptr[crd]; for (count = 0; count < bd->numports; count++, ch++) { - if (ch && ch->port.tty) - tty_hangup(ch->port.tty); + struct tty_struct *tty = tty_port_tty_get(&ch->port); + if (tty) { + tty_hangup(tty); + tty_kref_put(tty); + } } } pci_unregister_driver(&epca_driver); @@ -1441,7 +1444,7 @@ static void post_fep_init(unsigned int crd) ch->boardnum = crd; ch->channelnum = i; ch->magic = EPCA_MAGIC; - ch->port.tty = NULL; + tty_port_tty_set(&ch->port, NULL); if (shrinkmem) { fepcmd(ch, SETBUFFER, 32, 0, 0, 0); @@ -1635,8 +1638,9 @@ static void doevent(int crd) if (bc == NULL) goto next; + tty = tty_port_tty_get(&ch->port); if (event & DATA_IND) { /* Begin DATA_IND */ - receive_data(ch); + receive_data(ch, tty); assertgwinon(ch); } /* End DATA_IND */ /* else *//* Fix for DCD transition missed bug */ @@ -1651,7 +1655,6 @@ static void doevent(int crd) pc_sched_event(ch, EPCA_EVENT_HANGUP); } } - tty = ch->port.tty; if (tty) { if (event & BREAK_IND) { /* A break has been indicated */ @@ -1671,6 +1674,7 @@ static void doevent(int crd) tty_wakeup(tty); } } + tty_kref_put(tty); } next: globalwinon(ch); @@ -1965,11 +1969,10 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch) } /* Caller holds lock */ -static void receive_data(struct channel *ch) +static void receive_data(struct channel *ch, struct tty_struct *tty) { unchar *rptr; struct ktermios *ts = NULL; - struct tty_struct *tty; struct board_chan __iomem *bc; int dataToRead, wrapgap, bytesAvailable; unsigned int tail, head; @@ -1982,7 +1985,6 @@ static void receive_data(struct channel *ch) globalwinon(ch); if (ch->statusflags & RXSTOPPED) return; - tty = ch->port.tty; if (tty) ts = tty->termios; bc = ch->brdchan; @@ -2042,7 +2044,7 @@ static void receive_data(struct channel *ch) globalwinon(ch); writew(tail, &bc->rout); /* Must be called with global data */ - tty_schedule_flip(ch->port.tty); + tty_schedule_flip(tty); } static int info_ioctl(struct tty_struct *tty, struct file *file, @@ -2365,7 +2367,7 @@ static void do_softint(struct work_struct *work) struct channel *ch = container_of(work, struct channel, tqueue); /* Called in response to a modem change event */ if (ch && ch->magic == EPCA_MAGIC) { - struct tty_struct *tty = ch->port.tty; + struct tty_struct *tty = tty_port_tty_get(&ch->port);; if (tty && tty->driver_data) { if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { @@ -2374,6 +2376,7 @@ static void do_softint(struct work_struct *work) ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; } } + tty_kref_put(tty); } } -- cgit v1.2.3 From 6ed1dbaeadd62a026a93aa3ac8680d2dfe9f96b3 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:48:11 +0000 Subject: tty: Make epca use the port helpers Now the locking is straight and the port kref usage is straight we can replace lots of chunks of code with the standard port helpers Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/epca.c | 172 +++++++----------------------------------------- drivers/char/tty_port.c | 3 +- 2 files changed, 26 insertions(+), 149 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/epca.c b/drivers/char/epca.c index 7a697055e4f..71225d1af9e 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c @@ -432,58 +432,15 @@ static void pc_close(struct tty_struct *tty, struct file *filp) return; port = &ch->port; - spin_lock_irqsave(&port->lock, flags); - if (tty_hung_up_p(filp)) { - spin_unlock_irqrestore(&port->lock, flags); - return; - } - if (port->count-- > 1) { - /* Begin channel is open more than once */ - /* - * Return without doing anything. Someone might still - * be using the channel. - */ - spin_unlock_irqrestore(&port->lock, flags); + if (tty_port_close_start(port, tty, filp) == 0) return; - } - /* Port open only once go ahead with shutdown & reset */ - WARN_ON(port->count < 0); - /* - * Let the rest of the driver know the channel is being closed. - * This becomes important if an open is attempted before close - * is finished. - */ - port->flags |= ASYNC_CLOSING; - tty->closing = 1; - - spin_unlock_irqrestore(&port->lock, flags); - - if (port->flags & ASYNC_INITIALIZED) { - /* Setup an event to indicate when the - transmit buffer empties */ - setup_empty_event(tty, ch); - /* 30 seconds timeout */ - tty_wait_until_sent(tty, 3000); - } pc_flush_buffer(tty); - tty_ldisc_flush(tty); shutdown(ch, tty); - spin_lock_irqsave(&port->lock, flags); - tty->closing = 0; - ch->event = 0; + tty_port_close_end(port, tty); + ch->event = 0; /* FIXME: review ch->event locking */ tty_port_tty_set(port, NULL); - spin_unlock_irqrestore(&port->lock, flags); - - if (port->blocked_open) { - if (ch->close_delay) - msleep_interruptible(jiffies_to_msecs(ch->close_delay)); - wake_up_interruptible(&port->open_wait); - } - port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | - ASYNC_CLOSING); - wake_up_interruptible(&port->close_wait); } static void shutdown(struct channel *ch, struct tty_struct *tty) @@ -527,7 +484,6 @@ static void shutdown(struct channel *ch, struct tty_struct *tty) static void pc_hangup(struct tty_struct *tty) { struct channel *ch; - struct tty_port *port; /* * verifyChannel returns the channel from the tty struct if it is @@ -536,19 +492,13 @@ static void pc_hangup(struct tty_struct *tty) ch = verifyChannel(tty); if (ch != NULL) { unsigned long flags; - port = &ch->port; pc_flush_buffer(tty); tty_ldisc_flush(tty); shutdown(ch, tty); - spin_lock_irqsave(&port->lock, flags); - port->tty = NULL; ch->event = 0; /* FIXME: review locking of ch->event */ - port->count = 0; - port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED); - spin_unlock_irqrestore(&port->lock, flags); - wake_up_interruptible(&port->open_wait); + tty_port_hangup(&ch->port); } } @@ -792,98 +742,18 @@ static void pc_flush_chars(struct tty_struct *tty) } } -static int block_til_ready(struct tty_struct *tty, - struct file *filp, struct channel *ch) +static int epca_carrier_raised(struct tty_port *port) { - DECLARE_WAITQUEUE(wait, current); - int retval, do_clocal = 0; - unsigned long flags; - struct tty_port *port = &ch->port; - - if (tty_hung_up_p(filp)) { - if (port->flags & ASYNC_HUP_NOTIFY) - retval = -EAGAIN; - else - retval = -ERESTARTSYS; - return retval; - } - - /* - * If the device is in the middle of being closed, then block until - * it's done, and then try again. - */ - if (port->flags & ASYNC_CLOSING) { - interruptible_sleep_on(&port->close_wait); - - if (port->flags & ASYNC_HUP_NOTIFY) - return -EAGAIN; - else - return -ERESTARTSYS; - } - - if (filp->f_flags & O_NONBLOCK) { - /* - * If non-blocking mode is set, then make the check up front - * and then exit. - */ - port->flags |= ASYNC_NORMAL_ACTIVE; - return 0; - } - if (tty->termios->c_cflag & CLOCAL) - do_clocal = 1; - /* Block waiting for the carrier detect and the line to become free */ - - retval = 0; - add_wait_queue(&port->open_wait, &wait); - - spin_lock_irqsave(&port->lock, flags); - /* We dec count so that pc_close will know when to free things */ - if (!tty_hung_up_p(filp)) - port->count--; - port->blocked_open++; - while (1) { - set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || - !(port->flags & ASYNC_INITIALIZED)) { - if (port->flags & ASYNC_HUP_NOTIFY) - retval = -EAGAIN; - else - retval = -ERESTARTSYS; - break; - } - if (!(port->flags & ASYNC_CLOSING) && - (do_clocal || (ch->imodem & ch->dcd))) - break; - if (signal_pending(current)) { - retval = -ERESTARTSYS; - break; - } - spin_unlock_irqrestore(&port->lock, flags); - /* - * Allow someone else to be scheduled. We will occasionally go - * through this loop until one of the above conditions change. - * The below schedule call will allow other processes to enter - * and prevent this loop from hogging the cpu. - */ - schedule(); - spin_lock_irqsave(&port->lock, flags); - } - - __set_current_state(TASK_RUNNING); - remove_wait_queue(&port->open_wait, &wait); - if (!tty_hung_up_p(filp)) - port->count++; - port->blocked_open--; - - spin_unlock_irqrestore(&port->lock, flags); - - if (retval) - return retval; - - port->flags |= ASYNC_NORMAL_ACTIVE; + struct channel *ch = container_of(port, struct channel, port); + if (ch->imodem & ch->dcd) + return 1; return 0; } +static void epca_raise_dtr_rts(struct tty_port *port0 +{ +} + static int pc_open(struct tty_struct *tty, struct file *filp) { struct channel *ch; @@ -978,7 +848,7 @@ static int pc_open(struct tty_struct *tty, struct file *filp) port->flags |= ASYNC_INITIALIZED; spin_unlock_irqrestore(&port->lock, flags); - retval = block_til_ready(tty, filp, ch); + retval = tty_port_block_til_ready(port, tty, filp); if (retval) return retval; /* @@ -1058,6 +928,11 @@ static const struct tty_operations pc_ops = { .break_ctl = pc_send_break }; +static const struct tty_port_operations epca_port_ops = { + .carrier_raised = epca_carrier_raised, + .raise_dtr_rts = epca_raise_dtr_rts, +}; + static int info_open(struct tty_struct *tty, struct file *filp) { return 0; @@ -1393,6 +1268,7 @@ static void post_fep_init(unsigned int crd) u16 tseg, rseg; tty_port_init(&ch->port); + ch->port.ops - &epca_port_ops; ch->brdchan = bc; ch->mailbox = gd; INIT_WORK(&ch->tqueue, do_softint); @@ -1526,7 +1402,7 @@ static void post_fep_init(unsigned int crd) ch->fepstartca = 0; ch->fepstopca = 0; - ch->close_delay = 50; + ch->port.close_delay = 50; spin_unlock_irqrestore(&epca_lock, flags); } @@ -1647,7 +1523,7 @@ static void doevent(int crd) if (event & MODEMCHG_IND) { /* A modem signal change has been indicated */ ch->imodem = mstat; - if (ch->port.flags & ASYNC_CHECK_CD) { + if (test_bit(ASYNC_CHECK_CD, &ch->port.flags)) { /* We are now receiving dcd */ if (mstat & ch->dcd) wake_up_interruptible(&ch->port.open_wait); @@ -1894,9 +1770,9 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch) * that the driver will wait on carrier detect. */ if (ts->c_cflag & CLOCAL) - ch->port.flags &= ~ASYNC_CHECK_CD; + clear_bit(ASYNC_CHECK_CD, &ch->port.flags); else - ch->port.flags |= ASYNC_CHECK_CD; + set_bit(ASYNC_CHECK_CD, &ch->port.flags); mval = ch->m_dtr | ch->m_rts; } /* End CBAUD not detected */ iflag = termios2digi_i(ch, ts->c_iflag); @@ -2373,7 +2249,7 @@ static void do_softint(struct work_struct *work) if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { tty_hangup(tty); wake_up_interruptible(&ch->port.open_wait); - ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; + clear_bit(ASYNC_NORMAL_ACTIVE, &ch->port.flags); } } tty_kref_put(tty); diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index b3175f54fe0..b580fcf629f 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -286,7 +286,8 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f port->flags |= ASYNC_CLOSING; tty->closing = 1; spin_unlock_irqrestore(&port->lock, flags); - if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) + if (port->flags & ASYNC_INITIALIZED && + port->closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, port->closing_wait); return 1; } -- cgit v1.2.3 From c1314a49d7907b96d72f2c41f8927fc3c738e956 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:48:17 +0000 Subject: tty: Redo the rocket driver locking Bring this driver into the port locking model Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/epca.c | 9 ++------- drivers/char/rocket.c | 35 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 24 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/epca.c b/drivers/char/epca.c index 71225d1af9e..39ad820b235 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c @@ -164,8 +164,6 @@ static int pc_write_room(struct tty_struct *); static int pc_chars_in_buffer(struct tty_struct *); static void pc_flush_buffer(struct tty_struct *); static void pc_flush_chars(struct tty_struct *); -static int block_til_ready(struct tty_struct *, struct file *, - struct channel *); static int pc_open(struct tty_struct *, struct file *); static void post_fep_init(unsigned int crd); static void epcapoll(unsigned long); @@ -422,7 +420,6 @@ static void pc_close(struct tty_struct *tty, struct file *filp) { struct channel *ch; struct tty_port *port; - unsigned long flags; /* * verifyChannel returns the channel from the tty struct if it is * valid. This serves as a sanity check. @@ -491,8 +488,6 @@ static void pc_hangup(struct tty_struct *tty) */ ch = verifyChannel(tty); if (ch != NULL) { - unsigned long flags; - pc_flush_buffer(tty); tty_ldisc_flush(tty); shutdown(ch, tty); @@ -750,7 +745,7 @@ static int epca_carrier_raised(struct tty_port *port) return 0; } -static void epca_raise_dtr_rts(struct tty_port *port0 +static void epca_raise_dtr_rts(struct tty_port *port) { } @@ -1268,7 +1263,7 @@ static void post_fep_init(unsigned int crd) u16 tseg, rseg; tty_port_init(&ch->port); - ch->port.ops - &epca_port_ops; + ch->port.ops = &epca_port_ops; ch->brdchan = bc; ch->mailbox = gd; INIT_WORK(&ch->tqueue, do_softint); diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index 1e68cc2296f..efc3e5c51f6 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -920,7 +920,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, #ifdef ROCKET_DEBUG_OPEN printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, port->count); #endif - spin_lock_irqsave(&info->slock, flags); + spin_lock_irqsave(&port->lock, flags); #ifdef ROCKET_DISABLE_SIMUSAGE info->flags |= ASYNC_NORMAL_ACTIVE; @@ -932,7 +932,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, #endif port->blocked_open++; - spin_unlock_irqrestore(&info->slock, flags); + spin_unlock_irqrestore(&port->lock, flags); while (1) { if (tty->termios->c_cflag & CBAUD) @@ -961,13 +961,13 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, __set_current_state(TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); - spin_lock_irqsave(&info->slock, flags); + spin_lock_irqsave(&port->lock, flags); if (extra_count) port->count++; port->blocked_open--; - spin_unlock_irqrestore(&info->slock, flags); + spin_unlock_irqrestore(&port->lock, flags); #ifdef ROCKET_DEBUG_OPEN printk(KERN_INFO "block_til_ready after blocking: ttyR%d, count = %d\n", @@ -1095,6 +1095,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) static void rp_close(struct tty_struct *tty, struct file *filp) { struct r_port *info = tty->driver_data; + struct tty_port *port = &info->port; unsigned long flags; int timeout; CHANNEL_t *cp; @@ -1108,9 +1109,9 @@ static void rp_close(struct tty_struct *tty, struct file *filp) if (tty_hung_up_p(filp)) return; - spin_lock_irqsave(&info->slock, flags); + spin_lock_irqsave(&port->lock, flags); - if ((tty->count == 1) && (info->port.count != 1)) { + if (tty->count == 1 && port->count != 1) { /* * Uh, oh. tty->count is 1, which means that the tty * structure will be freed. Info->count should always @@ -1120,19 +1121,19 @@ static void rp_close(struct tty_struct *tty, struct file *filp) */ printk(KERN_WARNING "rp_close: bad serial port count; " "tty->count is 1, info->port.count is %d\n", info->port.count); - info->port.count = 1; + port->count = 1; } - if (--info->port.count < 0) { + if (--port->count < 0) { printk(KERN_WARNING "rp_close: bad serial port count for " "ttyR%d: %d\n", info->line, info->port.count); - info->port.count = 0; + port->count = 0; } - if (info->port.count) { - spin_unlock_irqrestore(&info->slock, flags); + if (port->count) { + spin_unlock_irqrestore(&port->lock, flags); return; } info->flags |= ASYNC_CLOSING; - spin_unlock_irqrestore(&info->slock, flags); + spin_unlock_irqrestore(&port->lock, flags); cp = &info->channel; @@ -1152,7 +1153,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp) * Wait for the transmit buffer to clear */ if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) - tty_wait_until_sent(tty, info->port.closing_wait); + tty_wait_until_sent(tty, port->closing_wait); /* * Before we drop DTR, make sure the UART transmitter * has completely drained; this is especially @@ -1181,11 +1182,11 @@ static void rp_close(struct tty_struct *tty, struct file *filp) clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); - if (info->port.blocked_open) { - if (info->port.close_delay) { - msleep_interruptible(jiffies_to_msecs(info->port.close_delay)); + if (port->blocked_open) { + if (port->close_delay) { + msleep_interruptible(jiffies_to_msecs(port->close_delay)); } - wake_up_interruptible(&info->port.open_wait); + wake_up_interruptible(&port->open_wait); } else { if (info->xmit_buf) { free_page((unsigned long) info->xmit_buf); -- cgit v1.2.3 From 21bed701da009b4192d9e86b3596cf210ac7369c Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:48:23 +0000 Subject: tty: make rocketport use standard port->flags We need to this ready for using the standard helpers Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/rocket.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index efc3e5c51f6..ca6fcdcca56 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -499,7 +499,7 @@ static void rp_handle_port(struct r_port *info) if (!info) return; - if ((info->flags & ASYNC_INITIALIZED) == 0) { + if ((info->port.flags & ASYNC_INITIALIZED) == 0) { printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " "info->flags & NOT_INIT\n"); return; @@ -892,11 +892,11 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, * until it's done, and then try again. */ if (tty_hung_up_p(filp)) - return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); + return ((info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); if (info->flags & ASYNC_CLOSING) { if (wait_for_completion_interruptible(&info->close_wait)) return -ERESTARTSYS; - return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); + return ((info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); } /* @@ -904,7 +904,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, * then make the check up front and then exit. */ if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { - info->flags |= ASYNC_NORMAL_ACTIVE; + info->port.flags |= ASYNC_NORMAL_ACTIVE; return 0; } if (tty->termios->c_cflag & CLOCAL) @@ -923,7 +923,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, spin_lock_irqsave(&port->lock, flags); #ifdef ROCKET_DISABLE_SIMUSAGE - info->flags |= ASYNC_NORMAL_ACTIVE; + info->port.flags |= ASYNC_NORMAL_ACTIVE; #else if (!tty_hung_up_p(filp)) { extra_count = 1; @@ -938,14 +938,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, if (tty->termios->c_cflag & CBAUD) tty_port_raise_dtr_rts(port); set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) { - if (info->flags & ASYNC_HUP_NOTIFY) + if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)) { + if (info->port.flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else retval = -ERESTARTSYS; break; } - if (!(info->flags & ASYNC_CLOSING) && + if (!(info->port.flags & ASYNC_CLOSING) && (do_clocal || tty_port_carrier_raised(port))) break; if (signal_pending(current)) { @@ -954,7 +954,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } #ifdef ROCKET_DEBUG_OPEN printk(KERN_INFO "block_til_ready blocking: ttyR%d, count = %d, flags=0x%0x\n", - info->line, port->count, info->flags); + info->line, port->count, info->port.flags); #endif schedule(); /* Don't hold spinlock here, will hang PC */ } @@ -975,7 +975,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, #endif if (retval) return retval; - info->flags |= ASYNC_NORMAL_ACTIVE; + info->port.flags |= ASYNC_NORMAL_ACTIVE; return 0; } @@ -998,12 +998,12 @@ static int rp_open(struct tty_struct *tty, struct file *filp) if (!page) return -ENOMEM; - if (info->flags & ASYNC_CLOSING) { + if (info->port.flags & ASYNC_CLOSING) { retval = wait_for_completion_interruptible(&info->close_wait); free_page(page); if (retval) return retval; - return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); + return ((info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); } /* @@ -1032,7 +1032,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) /* * Info->count is now 1; so it's safe to sleep now. */ - if ((info->flags & ASYNC_INITIALIZED) == 0) { + if ((info->port.flags & ASYNC_INITIALIZED) == 0) { cp = &info->channel; sSetRxTrigger(cp, TRIG_1); if (sGetChanStatus(cp) & CD_ACT) @@ -1056,7 +1056,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) sEnRxFIFO(cp); sEnTransmit(cp); - info->flags |= ASYNC_INITIALIZED; + info->port.flags |= ASYNC_INITIALIZED; /* * Set up the tty->alt_speed kludge @@ -1132,7 +1132,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp) spin_unlock_irqrestore(&port->lock, flags); return; } - info->flags |= ASYNC_CLOSING; + info->port.flags |= ASYNC_CLOSING; spin_unlock_irqrestore(&port->lock, flags); cp = &info->channel; @@ -1193,7 +1193,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp) info->xmit_buf = NULL; } } - info->flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE); + info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE); tty->closing = 0; complete_all(&info->close_wait); atomic_dec(&rp_num_ports_open); @@ -1650,14 +1650,14 @@ static void rp_hangup(struct tty_struct *tty) printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line); #endif rp_flush_buffer(tty); - if (info->flags & ASYNC_CLOSING) + if (info->port.flags & ASYNC_CLOSING) return; if (info->port.count) atomic_dec(&rp_num_ports_open); clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); info->port.count = 0; - info->flags &= ~ASYNC_NORMAL_ACTIVE; + info->port.flags &= ~ASYNC_NORMAL_ACTIVE; info->port.tty = NULL; cp = &info->channel; @@ -1667,7 +1667,7 @@ static void rp_hangup(struct tty_struct *tty) sDisCTSFlowCtl(cp); sDisTxSoftFlowCtl(cp); sClrTxXOFF(cp); - info->flags &= ~ASYNC_INITIALIZED; + info->port.flags &= ~ASYNC_INITIALIZED; wake_up_interruptible(&info->port.open_wait); } -- cgit v1.2.3 From 47b01b3a5fc7239f3e8d5d5cadc88afbea24d0c3 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:48:30 +0000 Subject: tty: kref the rocket driver We will need this kref fitted to make full use of the port operations. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/rocket.c | 78 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 37 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index ca6fcdcca56..b5e5e77c59d 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -436,15 +436,15 @@ static void rp_do_transmit(struct r_port *info) #endif if (!info) return; - if (!info->port.tty) { - printk(KERN_WARNING "rp: WARNING %s called with " - "info->port.tty==NULL\n", __func__); + tty = tty_port_tty_get(&info->port); + + if (tty == NULL) { + printk(KERN_WARNING "rp: WARNING %s called with tty==NULL\n", __func__); clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); return; } spin_lock_irqsave(&info->slock, flags); - tty = info->port.tty; info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp); /* Loop sending data to FIFO until done or FIFO full */ @@ -478,6 +478,7 @@ static void rp_do_transmit(struct r_port *info) } spin_unlock_irqrestore(&info->slock, flags); + tty_kref_put(tty); #ifdef ROCKET_DEBUG_INTR printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head, @@ -504,13 +505,13 @@ static void rp_handle_port(struct r_port *info) "info->flags & NOT_INIT\n"); return; } - if (!info->port.tty) { + tty = tty_port_tty_get(&info->port); + if (!tty) { printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " - "info->port.tty==NULL\n"); + "tty==NULL\n"); return; } cp = &info->channel; - tty = info->port.tty; IntMask = sGetChanIntID(cp) & info->intmask; #ifdef ROCKET_DEBUG_INTR @@ -542,6 +543,7 @@ static void rp_handle_port(struct r_port *info) printk(KERN_INFO "DSR change...\n"); } #endif + tty_kref_put(tty); } /* @@ -710,7 +712,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev) * Configures a rocketport port according to its termio settings. Called from * user mode into the driver (exception handler). *info CD manipulation is spinlock protected. */ -static void configure_r_port(struct r_port *info, +static void configure_r_port(struct tty_struct *tty, struct r_port *info, struct ktermios *old_termios) { unsigned cflag; @@ -718,7 +720,7 @@ static void configure_r_port(struct r_port *info, unsigned rocketMode; int bits, baud, divisor; CHANNEL_t *cp; - struct ktermios *t = info->port.tty->termios; + struct ktermios *t = tty->termios; cp = &info->channel; cflag = t->c_cflag; @@ -751,7 +753,7 @@ static void configure_r_port(struct r_port *info, } /* baud rate */ - baud = tty_get_baud_rate(info->port.tty); + baud = tty_get_baud_rate(tty); if (!baud) baud = 9600; divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1; @@ -769,7 +771,7 @@ static void configure_r_port(struct r_port *info, sSetBaud(cp, divisor); /* FIXME: Should really back compute a baud rate from the divisor */ - tty_encode_baud_rate(info->port.tty, baud, baud); + tty_encode_baud_rate(tty, baud, baud); if (cflag & CRTSCTS) { info->intmask |= DELTA_CTS; @@ -794,15 +796,15 @@ static void configure_r_port(struct r_port *info, * Handle software flow control in the board */ #ifdef ROCKET_SOFT_FLOW - if (I_IXON(info->port.tty)) { + if (I_IXON(tty)) { sEnTxSoftFlowCtl(cp); - if (I_IXANY(info->port.tty)) { + if (I_IXANY(tty)) { sEnIXANY(cp); } else { sDisIXANY(cp); } - sSetTxXONChar(cp, START_CHAR(info->port.tty)); - sSetTxXOFFChar(cp, STOP_CHAR(info->port.tty)); + sSetTxXONChar(cp, START_CHAR(tty)); + sSetTxXOFFChar(cp, STOP_CHAR(tty)); } else { sDisTxSoftFlowCtl(cp); sDisIXANY(cp); @@ -814,24 +816,24 @@ static void configure_r_port(struct r_port *info, * Set up ignore/read mask words */ info->read_status_mask = STMRCVROVRH | 0xFF; - if (I_INPCK(info->port.tty)) + if (I_INPCK(tty)) info->read_status_mask |= STMFRAMEH | STMPARITYH; - if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) + if (I_BRKINT(tty) || I_PARMRK(tty)) info->read_status_mask |= STMBREAKH; /* * Characters to ignore */ info->ignore_status_mask = 0; - if (I_IGNPAR(info->port.tty)) + if (I_IGNPAR(tty)) info->ignore_status_mask |= STMFRAMEH | STMPARITYH; - if (I_IGNBRK(info->port.tty)) { + if (I_IGNBRK(tty)) { info->ignore_status_mask |= STMBREAKH; /* * If we're ignoring parity and break indicators, * ignore overruns too. (For real raw support). */ - if (I_IGNPAR(info->port.tty)) + if (I_IGNPAR(tty)) info->ignore_status_mask |= STMRCVROVRH; } @@ -1015,7 +1017,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) info->xmit_buf = (unsigned char *) page; tty->driver_data = info; - info->port.tty = tty; + tty_port_tty_set(&info->port, tty); if (info->port.count++ == 0) { atomic_inc(&rp_num_ports_open); @@ -1062,15 +1064,15 @@ static int rp_open(struct tty_struct *tty, struct file *filp) * Set up the tty->alt_speed kludge */ if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI) - info->port.tty->alt_speed = 57600; + tty->alt_speed = 57600; if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI) - info->port.tty->alt_speed = 115200; + tty->alt_speed = 115200; if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI) - info->port.tty->alt_speed = 230400; + tty->alt_speed = 230400; if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP) - info->port.tty->alt_speed = 460800; + tty->alt_speed = 460800; - configure_r_port(info, NULL); + configure_r_port(tty, info, NULL); if (tty->termios->c_cflag & CBAUD) { sSetDTR(cp); sSetRTS(cp); @@ -1227,7 +1229,7 @@ static void rp_set_termios(struct tty_struct *tty, /* Or CMSPAR */ tty->termios->c_cflag &= ~CMSPAR; - configure_r_port(info, old_termios); + configure_r_port(tty, info, old_termios); cp = &info->channel; @@ -1352,7 +1354,8 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo) return 0; } -static int set_config(struct r_port *info, struct rocket_config __user *new_info) +static int set_config(struct tty_struct *tty, struct r_port *info, + struct rocket_config __user *new_info) { struct rocket_config new_serial; @@ -1364,7 +1367,7 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK)) return -EPERM; info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK)); - configure_r_port(info, NULL); + configure_r_port(tty, info, NULL); return 0; } @@ -1373,15 +1376,15 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info info->port.closing_wait = new_serial.closing_wait; if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI) - info->port.tty->alt_speed = 57600; + tty->alt_speed = 57600; if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI) - info->port.tty->alt_speed = 115200; + tty->alt_speed = 115200; if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI) - info->port.tty->alt_speed = 230400; + tty->alt_speed = 230400; if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP) - info->port.tty->alt_speed = 460800; + tty->alt_speed = 460800; - configure_r_port(info, NULL); + configure_r_port(tty, info, NULL); return 0; } @@ -1466,7 +1469,7 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file, ret = get_config(info, argp); break; case RCKP_SET_CONFIG: - ret = set_config(info, argp); + ret = set_config(tty, info, argp); break; case RCKP_GET_PORTS: ret = get_ports(info, argp); @@ -1658,7 +1661,7 @@ static void rp_hangup(struct tty_struct *tty) info->port.count = 0; info->port.flags &= ~ASYNC_NORMAL_ACTIVE; - info->port.tty = NULL; + tty_port_tty_set(&info->port, NULL); cp = &info->channel; sDisRxFIFO(cp); @@ -1778,7 +1781,8 @@ static int rp_write(struct tty_struct *tty, /* Write remaining data into the port's xmit_buf */ while (1) { - if (!info->port.tty) /* Seemingly obligatory check... */ + /* Hung up ? */ + if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags)) goto end; c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); c = min(c, XMIT_BUF_SIZE - info->xmit_head); -- cgit v1.2.3 From fba85e013f106a44e91ef5edec899fc56a7e61ee Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:48:39 +0000 Subject: tty: use port methods for the rocket driver Now we have our ducks in order we can begin switching to the port operations Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/rocket.c | 177 +++++------------------------------------------- drivers/char/tty_port.c | 3 + 2 files changed, 21 insertions(+), 159 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c index b5e5e77c59d..f59fc5cea06 100644 --- a/drivers/char/rocket.c +++ b/drivers/char/rocket.c @@ -879,108 +879,6 @@ static void raise_dtr_rts(struct tty_port *port) sSetRTS(&info->channel); } -/* info->port.count is considered critical, protected by spinlocks. */ -static int block_til_ready(struct tty_struct *tty, struct file *filp, - struct r_port *info) -{ - DECLARE_WAITQUEUE(wait, current); - struct tty_port *port = &info->port; - int retval; - int do_clocal = 0, extra_count = 0; - unsigned long flags; - - /* - * If the device is in the middle of being closed, then block - * until it's done, and then try again. - */ - if (tty_hung_up_p(filp)) - return ((info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); - if (info->flags & ASYNC_CLOSING) { - if (wait_for_completion_interruptible(&info->close_wait)) - return -ERESTARTSYS; - return ((info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); - } - - /* - * If non-blocking mode is set, or the port is not enabled, - * then make the check up front and then exit. - */ - if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { - info->port.flags |= ASYNC_NORMAL_ACTIVE; - return 0; - } - if (tty->termios->c_cflag & CLOCAL) - do_clocal = 1; - - /* - * Block waiting for the carrier detect and the line to become free. While we are in - * this loop, port->count is dropped by one, so that rp_close() knows when to free things. - * We restore it upon exit, either normal or abnormal. - */ - retval = 0; - add_wait_queue(&port->open_wait, &wait); -#ifdef ROCKET_DEBUG_OPEN - printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, port->count); -#endif - spin_lock_irqsave(&port->lock, flags); - -#ifdef ROCKET_DISABLE_SIMUSAGE - info->port.flags |= ASYNC_NORMAL_ACTIVE; -#else - if (!tty_hung_up_p(filp)) { - extra_count = 1; - port->count--; - } -#endif - port->blocked_open++; - - spin_unlock_irqrestore(&port->lock, flags); - - while (1) { - if (tty->termios->c_cflag & CBAUD) - tty_port_raise_dtr_rts(port); - set_current_state(TASK_INTERRUPTIBLE); - if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)) { - if (info->port.flags & ASYNC_HUP_NOTIFY) - retval = -EAGAIN; - else - retval = -ERESTARTSYS; - break; - } - if (!(info->port.flags & ASYNC_CLOSING) && - (do_clocal || tty_port_carrier_raised(port))) - break; - if (signal_pending(current)) { - retval = -ERESTARTSYS; - break; - } -#ifdef ROCKET_DEBUG_OPEN - printk(KERN_INFO "block_til_ready blocking: ttyR%d, count = %d, flags=0x%0x\n", - info->line, port->count, info->port.flags); -#endif - schedule(); /* Don't hold spinlock here, will hang PC */ - } - __set_current_state(TASK_RUNNING); - remove_wait_queue(&port->open_wait, &wait); - - spin_lock_irqsave(&port->lock, flags); - - if (extra_count) - port->count++; - port->blocked_open--; - - spin_unlock_irqrestore(&port->lock, flags); - -#ifdef ROCKET_DEBUG_OPEN - printk(KERN_INFO "block_til_ready after blocking: ttyR%d, count = %d\n", - info->line, port->count); -#endif - if (retval) - return retval; - info->port.flags |= ASYNC_NORMAL_ACTIVE; - return 0; -} - /* * Exception handler that opens a serial port. Creates xmit_buf storage, fills in * port's r_port struct. Initializes the port hardware. @@ -988,24 +886,26 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, static int rp_open(struct tty_struct *tty, struct file *filp) { struct r_port *info; + struct tty_port *port; int line = 0, retval; CHANNEL_t *cp; unsigned long page; line = tty->index; - if ((line < 0) || (line >= MAX_RP_PORTS) || ((info = rp_table[line]) == NULL)) + if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL)) return -ENXIO; - + port = &info->port; + page = __get_free_page(GFP_KERNEL); if (!page) return -ENOMEM; - if (info->port.flags & ASYNC_CLOSING) { + if (port->flags & ASYNC_CLOSING) { retval = wait_for_completion_interruptible(&info->close_wait); free_page(page); if (retval) return retval; - return ((info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); + return ((port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); } /* @@ -1017,9 +917,9 @@ static int rp_open(struct tty_struct *tty, struct file *filp) info->xmit_buf = (unsigned char *) page; tty->driver_data = info; - tty_port_tty_set(&info->port, tty); + tty_port_tty_set(port, tty); - if (info->port.count++ == 0) { + if (port->count++ == 0) { atomic_inc(&rp_num_ports_open); #ifdef ROCKET_DEBUG_OPEN @@ -1034,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) /* * Info->count is now 1; so it's safe to sleep now. */ - if ((info->port.flags & ASYNC_INITIALIZED) == 0) { + if (!test_bit(ASYNC_INITIALIZED, &port->flags)) { cp = &info->channel; sSetRxTrigger(cp, TRIG_1); if (sGetChanStatus(cp) & CD_ACT) @@ -1058,7 +958,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) sEnRxFIFO(cp); sEnTransmit(cp); - info->port.flags |= ASYNC_INITIALIZED; + set_bit(ASYNC_INITIALIZED, &info->port.flags); /* * Set up the tty->alt_speed kludge @@ -1081,7 +981,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) /* Starts (or resets) the maint polling loop */ mod_timer(&rocket_timer, jiffies + POLL_PERIOD); - retval = block_til_ready(tty, filp, info); + retval = tty_port_block_til_ready(port, tty, filp); if (retval) { #ifdef ROCKET_DEBUG_OPEN printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval); @@ -1098,7 +998,6 @@ static void rp_close(struct tty_struct *tty, struct file *filp) { struct r_port *info = tty->driver_data; struct tty_port *port = &info->port; - unsigned long flags; int timeout; CHANNEL_t *cp; @@ -1109,53 +1008,10 @@ static void rp_close(struct tty_struct *tty, struct file *filp) printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count); #endif - if (tty_hung_up_p(filp)) + if (tty_port_close_start(port, tty, filp) == 0) return; - spin_lock_irqsave(&port->lock, flags); - - if (tty->count == 1 && port->count != 1) { - /* - * Uh, oh. tty->count is 1, which means that the tty - * structure will be freed. Info->count should always - * be one in these conditions. If it's greater than - * one, we've got real problems, since it means the - * serial port won't be shutdown. - */ - printk(KERN_WARNING "rp_close: bad serial port count; " - "tty->count is 1, info->port.count is %d\n", info->port.count); - port->count = 1; - } - if (--port->count < 0) { - printk(KERN_WARNING "rp_close: bad serial port count for " - "ttyR%d: %d\n", info->line, info->port.count); - port->count = 0; - } - if (port->count) { - spin_unlock_irqrestore(&port->lock, flags); - return; - } - info->port.flags |= ASYNC_CLOSING; - spin_unlock_irqrestore(&port->lock, flags); cp = &info->channel; - - /* - * Notify the line discpline to only process XON/XOFF characters - */ - tty->closing = 1; - - /* - * If transmission was throttled by the application request, - * just flush the xmit buffer. - */ - if (tty->flow_stopped) - rp_flush_buffer(tty); - - /* - * Wait for the transmit buffer to clear - */ - if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) - tty_wait_until_sent(tty, port->closing_wait); /* * Before we drop DTR, make sure the UART transmitter * has completely drained; this is especially @@ -1184,6 +1040,9 @@ static void rp_close(struct tty_struct *tty, struct file *filp) clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); + /* We can't yet use tty_port_close_end as the buffer handling in this + driver is a bit different to the usual */ + if (port->blocked_open) { if (port->close_delay) { msleep_interruptible(jiffies_to_msecs(port->close_delay)); @@ -1197,6 +1056,8 @@ static void rp_close(struct tty_struct *tty, struct file *filp) } info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE); tty->closing = 0; + tty_port_tty_set(port, NULL); + wake_up_interruptible(&port->close_wait); complete_all(&info->close_wait); atomic_dec(&rp_num_ports_open); @@ -1659,9 +1520,7 @@ static void rp_hangup(struct tty_struct *tty) atomic_dec(&rp_num_ports_open); clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); - info->port.count = 0; - info->port.flags &= ~ASYNC_NORMAL_ACTIVE; - tty_port_tty_set(&info->port, NULL); + tty_port_hangup(&info->port); cp = &info->channel; sDisRxFIFO(cp); diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c index b580fcf629f..9b8004c7268 100644 --- a/drivers/char/tty_port.c +++ b/drivers/char/tty_port.c @@ -286,6 +286,9 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f port->flags |= ASYNC_CLOSING; tty->closing = 1; spin_unlock_irqrestore(&port->lock, flags); + /* Don't block on a stalled port, just pull the chain */ + if (tty->flow_stopped) + tty_driver_flush_buffer(tty); if (port->flags & ASYNC_INITIALIZED && port->closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, port->closing_wait); -- cgit v1.2.3 From eeb4613436f0f19a38f667ea3078821040559c68 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2009 13:48:47 +0000 Subject: synclink_cs: Convert to tty_port Use the tty port operations, add refcounting, and refactor a bit to make the refcounting work cleanly. Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/pcmcia/synclink_cs.c | 479 ++++++++++++++------------------------ 1 file changed, 181 insertions(+), 298 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 4d64a02612a..dc073e167ab 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -138,20 +138,15 @@ struct _input_signal_events { */ typedef struct _mgslpc_info { + struct tty_port port; void *if_ptr; /* General purpose pointer (used by SPPP) */ int magic; - int flags; - int count; /* count of opens */ int line; - unsigned short close_delay; - unsigned short closing_wait; /* time to wait before closing */ struct mgsl_icount icount; - struct tty_struct *tty; int timeout; int x_char; /* xon/xoff character */ - int blocked_open; /* # of blocked opens */ unsigned char read_status_mask; unsigned char ignore_status_mask; @@ -170,9 +165,6 @@ typedef struct _mgslpc_info { int rx_buf_count; /* total number of rx buffers */ int rx_frame_count; /* number of full rx buffers */ - wait_queue_head_t open_wait; - wait_queue_head_t close_wait; - wait_queue_head_t status_event_wait_q; wait_queue_head_t event_wait_q; struct timer_list tx_timer; /* HDLC transmit timeout timer */ @@ -375,7 +367,7 @@ static void irq_enable(MGSLPC_INFO *info, unsigned char channel, unsigned short static void rx_start(MGSLPC_INFO *info); static void rx_stop(MGSLPC_INFO *info); -static void tx_start(MGSLPC_INFO *info); +static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty); static void tx_stop(MGSLPC_INFO *info); static void tx_set_idle(MGSLPC_INFO *info); @@ -389,7 +381,8 @@ static void async_mode(MGSLPC_INFO *info); static void tx_timeout(unsigned long context); -static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg); +static int carrier_raised(struct tty_port *port); +static void raise_dtr_rts(struct tty_port *port); #if SYNCLINK_GENERIC_HDLC #define dev_to_port(D) (dev_to_hdlc(D)->priv) @@ -410,7 +403,7 @@ static void release_resources(MGSLPC_INFO *info); static void mgslpc_add_device(MGSLPC_INFO *info); static void mgslpc_remove_device(MGSLPC_INFO *info); -static bool rx_get_frame(MGSLPC_INFO *info); +static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty); static void rx_reset_buffers(MGSLPC_INFO *info); static int rx_alloc_buffers(MGSLPC_INFO *info); static void rx_free_buffers(MGSLPC_INFO *info); @@ -421,7 +414,7 @@ static irqreturn_t mgslpc_isr(int irq, void *dev_id); * Bottom half interrupt handlers */ static void bh_handler(struct work_struct *work); -static void bh_transmit(MGSLPC_INFO *info); +static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty); static void bh_status(MGSLPC_INFO *info); /* @@ -432,10 +425,10 @@ static int tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear); static int get_stats(MGSLPC_INFO *info, struct mgsl_icount __user *user_icount); static int get_params(MGSLPC_INFO *info, MGSL_PARAMS __user *user_params); -static int set_params(MGSLPC_INFO *info, MGSL_PARAMS __user *new_params); +static int set_params(MGSLPC_INFO *info, MGSL_PARAMS __user *new_params, struct tty_struct *tty); static int get_txidle(MGSLPC_INFO *info, int __user *idle_mode); static int set_txidle(MGSLPC_INFO *info, int idle_mode); -static int set_txenable(MGSLPC_INFO *info, int enable); +static int set_txenable(MGSLPC_INFO *info, int enable, struct tty_struct *tty); static int tx_abort(MGSLPC_INFO *info); static int set_rxenable(MGSLPC_INFO *info, int enable); static int wait_events(MGSLPC_INFO *info, int __user *mask); @@ -474,7 +467,7 @@ static struct tty_driver *serial_driver; /* number of characters left in xmit buffer before we ask for more */ #define WAKEUP_CHARS 256 -static void mgslpc_change_params(MGSLPC_INFO *info); +static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty); static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout); /* PCMCIA prototypes */ @@ -517,6 +510,11 @@ static void ldisc_receive_buf(struct tty_struct *tty, } } +static const struct tty_port_operations mgslpc_port_ops = { + .carrier_raised = carrier_raised, + .raise_dtr_rts = raise_dtr_rts +}; + static int mgslpc_probe(struct pcmcia_device *link) { MGSLPC_INFO *info; @@ -532,12 +530,12 @@ static int mgslpc_probe(struct pcmcia_device *link) } info->magic = MGSLPC_MAGIC; + tty_port_init(&info->port); + info->port.ops = &mgslpc_port_ops; INIT_WORK(&info->task, bh_handler); info->max_frame_size = 4096; - info->close_delay = 5*HZ/10; - info->closing_wait = 30*HZ; - init_waitqueue_head(&info->open_wait); - init_waitqueue_head(&info->close_wait); + info->port.close_delay = 5*HZ/10; + info->port.closing_wait = 30*HZ; init_waitqueue_head(&info->status_event_wait_q); init_waitqueue_head(&info->event_wait_q); spin_lock_init(&info->lock); @@ -784,7 +782,7 @@ static void tx_release(struct tty_struct *tty) spin_lock_irqsave(&info->lock,flags); if (!info->tx_enabled) - tx_start(info); + tx_start(info, tty); spin_unlock_irqrestore(&info->lock,flags); } @@ -823,6 +821,7 @@ static int bh_action(MGSLPC_INFO *info) static void bh_handler(struct work_struct *work) { MGSLPC_INFO *info = container_of(work, MGSLPC_INFO, task); + struct tty_struct *tty; int action; if (!info) @@ -833,6 +832,7 @@ static void bh_handler(struct work_struct *work) __FILE__,__LINE__,info->device_name); info->bh_running = true; + tty = tty_port_tty_get(&info->port); while((action = bh_action(info)) != 0) { @@ -844,10 +844,10 @@ static void bh_handler(struct work_struct *work) switch (action) { case BH_RECEIVE: - while(rx_get_frame(info)); + while(rx_get_frame(info, tty)); break; case BH_TRANSMIT: - bh_transmit(info); + bh_transmit(info, tty); break; case BH_STATUS: bh_status(info); @@ -859,14 +859,14 @@ static void bh_handler(struct work_struct *work) } } + tty_kref_put(tty); if (debug_level >= DEBUG_LEVEL_BH) printk( "%s(%d):bh_handler(%s) exit\n", __FILE__,__LINE__,info->device_name); } -static void bh_transmit(MGSLPC_INFO *info) +static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty) { - struct tty_struct *tty = info->tty; if (debug_level >= DEBUG_LEVEL_BH) printk("bh_transmit() entry on %s\n", info->device_name); @@ -945,12 +945,11 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom) issue_command(info, CHA, CMD_RXFIFO); } -static void rx_ready_async(MGSLPC_INFO *info, int tcd) +static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty) { unsigned char data, status, flag; int fifo_count; int work = 0; - struct tty_struct *tty = info->tty; struct mgsl_icount *icount = &info->icount; if (tcd) { @@ -1013,7 +1012,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd) } -static void tx_done(MGSLPC_INFO *info) +static void tx_done(MGSLPC_INFO *info, struct tty_struct *tty) { if (!info->tx_active) return; @@ -1042,7 +1041,7 @@ static void tx_done(MGSLPC_INFO *info) else #endif { - if (info->tty->stopped || info->tty->hw_stopped) { + if (tty->stopped || tty->hw_stopped) { tx_stop(info); return; } @@ -1050,7 +1049,7 @@ static void tx_done(MGSLPC_INFO *info) } } -static void tx_ready(MGSLPC_INFO *info) +static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty) { unsigned char fifo_count = 32; int c; @@ -1062,7 +1061,7 @@ static void tx_ready(MGSLPC_INFO *info) if (!info->tx_active) return; } else { - if (info->tty->stopped || info->tty->hw_stopped) { + if (tty->stopped || tty->hw_stopped) { tx_stop(info); return; } @@ -1099,7 +1098,7 @@ static void tx_ready(MGSLPC_INFO *info) } } -static void cts_change(MGSLPC_INFO *info) +static void cts_change(MGSLPC_INFO *info, struct tty_struct *tty) { get_signals(info); if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) @@ -1112,14 +1111,14 @@ static void cts_change(MGSLPC_INFO *info) wake_up_interruptible(&info->status_event_wait_q); wake_up_interruptible(&info->event_wait_q); - if (info->flags & ASYNC_CTS_FLOW) { - if (info->tty->hw_stopped) { + if (info->port.flags & ASYNC_CTS_FLOW) { + if (tty->hw_stopped) { if (info->serial_signals & SerialSignal_CTS) { if (debug_level >= DEBUG_LEVEL_ISR) printk("CTS tx start..."); - if (info->tty) - info->tty->hw_stopped = 0; - tx_start(info); + if (tty) + tty->hw_stopped = 0; + tx_start(info, tty); info->pending_bh |= BH_TRANSMIT; return; } @@ -1127,8 +1126,8 @@ static void cts_change(MGSLPC_INFO *info) if (!(info->serial_signals & SerialSignal_CTS)) { if (debug_level >= DEBUG_LEVEL_ISR) printk("CTS tx stop..."); - if (info->tty) - info->tty->hw_stopped = 1; + if (tty) + tty->hw_stopped = 1; tx_stop(info); } } @@ -1136,7 +1135,7 @@ static void cts_change(MGSLPC_INFO *info) info->pending_bh |= BH_STATUS; } -static void dcd_change(MGSLPC_INFO *info) +static void dcd_change(MGSLPC_INFO *info, struct tty_struct *tty) { get_signals(info); if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) @@ -1158,17 +1157,17 @@ static void dcd_change(MGSLPC_INFO *info) wake_up_interruptible(&info->status_event_wait_q); wake_up_interruptible(&info->event_wait_q); - if (info->flags & ASYNC_CHECK_CD) { + if (info->port.flags & ASYNC_CHECK_CD) { if (debug_level >= DEBUG_LEVEL_ISR) printk("%s CD now %s...", info->device_name, (info->serial_signals & SerialSignal_DCD) ? "on" : "off"); if (info->serial_signals & SerialSignal_DCD) - wake_up_interruptible(&info->open_wait); + wake_up_interruptible(&info->port.open_wait); else { if (debug_level >= DEBUG_LEVEL_ISR) printk("doing serial hangup..."); - if (info->tty) - tty_hangup(info->tty); + if (tty) + tty_hangup(tty); } } info->pending_bh |= BH_STATUS; @@ -1214,6 +1213,7 @@ static void ri_change(MGSLPC_INFO *info) static irqreturn_t mgslpc_isr(int dummy, void *dev_id) { MGSLPC_INFO *info = dev_id; + struct tty_struct *tty; unsigned short isr; unsigned char gis, pis; int count=0; @@ -1224,6 +1224,8 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) if (!(info->p_dev->_locked)) return IRQ_HANDLED; + tty = tty_port_tty_get(&info->port); + spin_lock(&info->lock); while ((gis = read_reg(info, CHA + GIS))) { @@ -1239,9 +1241,9 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) if (gis & (BIT1 + BIT0)) { isr = read_reg16(info, CHB + ISR); if (isr & IRQ_DCD) - dcd_change(info); + dcd_change(info, tty); if (isr & IRQ_CTS) - cts_change(info); + cts_change(info, tty); } if (gis & (BIT3 + BIT2)) { @@ -1258,8 +1260,8 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) } if (isr & IRQ_BREAK_ON) { info->icount.brk++; - if (info->flags & ASYNC_SAK) - do_SAK(info->tty); + if (info->port.flags & ASYNC_SAK) + do_SAK(tty); } if (isr & IRQ_RXTIME) { issue_command(info, CHA, CMD_RXFIFO_READ); @@ -1268,7 +1270,7 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) if (info->params.mode == MGSL_MODE_HDLC) rx_ready_hdlc(info, isr & IRQ_RXEOM); else - rx_ready_async(info, isr & IRQ_RXEOM); + rx_ready_async(info, isr & IRQ_RXEOM, tty); } /* transmit IRQs */ @@ -1277,14 +1279,14 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) info->icount.txabort++; else info->icount.txunder++; - tx_done(info); + tx_done(info, tty); } else if (isr & IRQ_ALLSENT) { info->icount.txok++; - tx_done(info); + tx_done(info, tty); } else if (isr & IRQ_TXFIFO) - tx_ready(info); + tx_ready(info, tty); } if (gis & BIT7) { pis = read_reg(info, CHA + PIS); @@ -1308,6 +1310,7 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) } spin_unlock(&info->lock); + tty_kref_put(tty); if (debug_level >= DEBUG_LEVEL_ISR) printk("%s(%d):mgslpc_isr(%d)exit.\n", @@ -1318,14 +1321,14 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) /* Initialize and start device. */ -static int startup(MGSLPC_INFO * info) +static int startup(MGSLPC_INFO * info, struct tty_struct *tty) { int retval = 0; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):startup(%s)\n",__FILE__,__LINE__,info->device_name); - if (info->flags & ASYNC_INITIALIZED) + if (info->port.flags & ASYNC_INITIALIZED) return 0; if (!info->tx_buf) { @@ -1352,30 +1355,30 @@ static int startup(MGSLPC_INFO * info) retval = adapter_test(info); if ( retval ) { - if (capable(CAP_SYS_ADMIN) && info->tty) - set_bit(TTY_IO_ERROR, &info->tty->flags); + if (capable(CAP_SYS_ADMIN) && tty) + set_bit(TTY_IO_ERROR, &tty->flags); release_resources(info); return retval; } /* program hardware for current parameters */ - mgslpc_change_params(info); + mgslpc_change_params(info, tty); - if (info->tty) - clear_bit(TTY_IO_ERROR, &info->tty->flags); + if (tty) + clear_bit(TTY_IO_ERROR, &tty->flags); - info->flags |= ASYNC_INITIALIZED; + info->port.flags |= ASYNC_INITIALIZED; return 0; } /* Called by mgslpc_close() and mgslpc_hangup() to shutdown hardware */ -static void shutdown(MGSLPC_INFO * info) +static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty) { unsigned long flags; - if (!(info->flags & ASYNC_INITIALIZED)) + if (!(info->port.flags & ASYNC_INITIALIZED)) return; if (debug_level >= DEBUG_LEVEL_INFO) @@ -1402,7 +1405,7 @@ static void shutdown(MGSLPC_INFO * info) /* TODO:disable interrupts instead of reset to preserve signal states */ reset_device(info); - if (!info->tty || info->tty->termios->c_cflag & HUPCL) { + if (!tty || tty->termios->c_cflag & HUPCL) { info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS); set_signals(info); } @@ -1411,13 +1414,13 @@ static void shutdown(MGSLPC_INFO * info) release_resources(info); - if (info->tty) - set_bit(TTY_IO_ERROR, &info->tty->flags); + if (tty) + set_bit(TTY_IO_ERROR, &tty->flags); - info->flags &= ~ASYNC_INITIALIZED; + info->port.flags &= ~ASYNC_INITIALIZED; } -static void mgslpc_program_hw(MGSLPC_INFO *info) +static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty) { unsigned long flags; @@ -1443,7 +1446,7 @@ static void mgslpc_program_hw(MGSLPC_INFO *info) port_irq_enable(info, (unsigned char) PVR_DSR | PVR_RI); get_signals(info); - if (info->netcount || info->tty->termios->c_cflag & CREAD) + if (info->netcount || (tty && (tty->termios->c_cflag & CREAD))) rx_start(info); spin_unlock_irqrestore(&info->lock,flags); @@ -1451,19 +1454,19 @@ static void mgslpc_program_hw(MGSLPC_INFO *info) /* Reconfigure adapter based on new parameters */ -static void mgslpc_change_params(MGSLPC_INFO *info) +static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty) { unsigned cflag; int bits_per_char; - if (!info->tty || !info->tty->termios) + if (!tty || !tty->termios) return; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_change_params(%s)\n", __FILE__,__LINE__, info->device_name ); - cflag = info->tty->termios->c_cflag; + cflag = tty->termios->c_cflag; /* if B0 rate (hangup) specified then negate DTR and RTS */ /* otherwise assert DTR and RTS */ @@ -1510,7 +1513,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info) * current data rate. */ if (info->params.data_rate <= 460800) { - info->params.data_rate = tty_get_baud_rate(info->tty); + info->params.data_rate = tty_get_baud_rate(tty); } if ( info->params.data_rate ) { @@ -1520,24 +1523,24 @@ static void mgslpc_change_params(MGSLPC_INFO *info) info->timeout += HZ/50; /* Add .02 seconds of slop */ if (cflag & CRTSCTS) - info->flags |= ASYNC_CTS_FLOW; + info->port.flags |= ASYNC_CTS_FLOW; else - info->flags &= ~ASYNC_CTS_FLOW; + info->port.flags &= ~ASYNC_CTS_FLOW; if (cflag & CLOCAL) - info->flags &= ~ASYNC_CHECK_CD; + info->port.flags &= ~ASYNC_CHECK_CD; else - info->flags |= ASYNC_CHECK_CD; + info->port.flags |= ASYNC_CHECK_CD; /* process tty input control flags */ info->read_status_mask = 0; - if (I_INPCK(info->tty)) + if (I_INPCK(tty)) info->read_status_mask |= BIT7 | BIT6; - if (I_IGNPAR(info->tty)) + if (I_IGNPAR(tty)) info->ignore_status_mask |= BIT7 | BIT6; - mgslpc_program_hw(info); + mgslpc_program_hw(info, tty); } /* Add a character to the transmit buffer @@ -1597,7 +1600,7 @@ static void mgslpc_flush_chars(struct tty_struct *tty) spin_lock_irqsave(&info->lock,flags); if (!info->tx_active) - tx_start(info); + tx_start(info, tty); spin_unlock_irqrestore(&info->lock,flags); } @@ -1659,7 +1662,7 @@ start: if (info->tx_count && !tty->stopped && !tty->hw_stopped) { spin_lock_irqsave(&info->lock,flags); if (!info->tx_active) - tx_start(info); + tx_start(info, tty); spin_unlock_irqrestore(&info->lock,flags); } cleanup: @@ -1764,7 +1767,7 @@ static void mgslpc_send_xchar(struct tty_struct *tty, char ch) if (ch) { spin_lock_irqsave(&info->lock,flags); if (!info->tx_enabled) - tx_start(info); + tx_start(info, tty); spin_unlock_irqrestore(&info->lock,flags); } } @@ -1862,7 +1865,7 @@ static int get_params(MGSLPC_INFO * info, MGSL_PARAMS __user *user_params) * * Returns: 0 if success, otherwise error code */ -static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params) +static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params, struct tty_struct *tty) { unsigned long flags; MGSL_PARAMS tmp_params; @@ -1883,7 +1886,7 @@ static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params) memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS)); spin_unlock_irqrestore(&info->lock,flags); - mgslpc_change_params(info); + mgslpc_change_params(info, tty); return 0; } @@ -1944,7 +1947,7 @@ static int set_interface(MGSLPC_INFO * info, int if_mode) return 0; } -static int set_txenable(MGSLPC_INFO * info, int enable) +static int set_txenable(MGSLPC_INFO * info, int enable, struct tty_struct *tty) { unsigned long flags; @@ -1954,7 +1957,7 @@ static int set_txenable(MGSLPC_INFO * info, int enable) spin_lock_irqsave(&info->lock,flags); if (enable) { if (!info->tx_enabled) - tx_start(info); + tx_start(info, tty); } else { if (info->tx_enabled) tx_stop(info); @@ -2263,6 +2266,11 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; + int error; + struct mgsl_icount cnow; /* kernel counter temps */ + struct serial_icounter_struct __user *p_cuser; /* user space */ + void __user *argp = (void __user *)arg; + unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__, @@ -2277,22 +2285,11 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file, return -EIO; } - return ioctl_common(info, cmd, arg); -} - -static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg) -{ - int error; - struct mgsl_icount cnow; /* kernel counter temps */ - struct serial_icounter_struct __user *p_cuser; /* user space */ - void __user *argp = (void __user *)arg; - unsigned long flags; - switch (cmd) { case MGSL_IOCGPARAMS: return get_params(info, argp); case MGSL_IOCSPARAMS: - return set_params(info, argp); + return set_params(info, argp, tty); case MGSL_IOCGTXIDLE: return get_txidle(info, argp); case MGSL_IOCSTXIDLE: @@ -2302,7 +2299,7 @@ static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg) case MGSL_IOCSIF: return set_interface(info,(int)arg); case MGSL_IOCTXENABLE: - return set_txenable(info,(int)arg); + return set_txenable(info,(int)arg, tty); case MGSL_IOCRXENABLE: return set_rxenable(info,(int)arg); case MGSL_IOCTXABORT: @@ -2369,7 +2366,7 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_term == RELEVANT_IFLAG(old_termios->c_iflag))) return; - mgslpc_change_params(info); + mgslpc_change_params(info, tty); /* Handle transition to B0 status */ if (old_termios->c_cflag & CBAUD && @@ -2404,81 +2401,34 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_term static void mgslpc_close(struct tty_struct *tty, struct file * filp) { MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; + struct tty_port *port = &info->port; if (mgslpc_paranoia_check(info, tty->name, "mgslpc_close")) return; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_close(%s) entry, count=%d\n", - __FILE__,__LINE__, info->device_name, info->count); - - if (!info->count) - return; + __FILE__,__LINE__, info->device_name, port->count); - if (tty_hung_up_p(filp)) - goto cleanup; - - if ((tty->count == 1) && (info->count != 1)) { - /* - * tty->count is 1 and the tty structure will be freed. - * info->count should be one in this case. - * if it's not, correct it so that the port is shutdown. - */ - printk("mgslpc_close: bad refcount; tty->count is 1, " - "info->count is %d\n", info->count); - info->count = 1; - } + WARN_ON(!port->count); - info->count--; - - /* if at least one open remaining, leave hardware active */ - if (info->count) + if (tty_port_close_start(port, tty, filp) == 0) goto cleanup; - info->flags |= ASYNC_CLOSING; - - /* set tty->closing to notify line discipline to - * only process XON/XOFF characters. Only the N_TTY - * discipline appears to use this (ppp does not). - */ - tty->closing = 1; - - /* wait for transmit data to clear all layers */ - - if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) { - if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):mgslpc_close(%s) calling tty_wait_until_sent\n", - __FILE__,__LINE__, info->device_name ); - tty_wait_until_sent(tty, info->closing_wait); - } - - if (info->flags & ASYNC_INITIALIZED) + if (port->flags & ASYNC_INITIALIZED) mgslpc_wait_until_sent(tty, info->timeout); mgslpc_flush_buffer(tty); tty_ldisc_flush(tty); - - shutdown(info); - - tty->closing = 0; - info->tty = NULL; - - if (info->blocked_open) { - if (info->close_delay) { - msleep_interruptible(jiffies_to_msecs(info->close_delay)); - } - wake_up_interruptible(&info->open_wait); - } - - info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); - - wake_up_interruptible(&info->close_wait); - + shutdown(info, tty); + + tty_port_close_end(port, tty); + tty_port_tty_set(port, NULL); cleanup: if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__, - tty->driver->name, info->count); + tty->driver->name, port->count); } /* Wait until the transmitter is empty. @@ -2498,7 +2448,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout) if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent")) return; - if (!(info->flags & ASYNC_INITIALIZED)) + if (!(info->port.flags & ASYNC_INITIALIZED)) goto exit; orig_jiffies = jiffies; @@ -2559,120 +2509,40 @@ static void mgslpc_hangup(struct tty_struct *tty) return; mgslpc_flush_buffer(tty); - shutdown(info); - - info->count = 0; - info->flags &= ~ASYNC_NORMAL_ACTIVE; - info->tty = NULL; - - wake_up_interruptible(&info->open_wait); + shutdown(info, tty); + tty_port_hangup(&info->port); } -/* Block the current process until the specified port - * is ready to be opened. - */ -static int block_til_ready(struct tty_struct *tty, struct file *filp, - MGSLPC_INFO *info) +static int carrier_raised(struct tty_port *port) { - DECLARE_WAITQUEUE(wait, current); - int retval; - bool do_clocal = false; - bool extra_count = false; - unsigned long flags; - - if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):block_til_ready on %s\n", - __FILE__,__LINE__, tty->driver->name ); - - if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ - /* nonblock mode is set or port is not enabled */ - /* just verify that callout device is not active */ - info->flags |= ASYNC_NORMAL_ACTIVE; - return 0; - } - - if (tty->termios->c_cflag & CLOCAL) - do_clocal = true; - - /* Wait for carrier detect and the line to become - * free (i.e., not in use by the callout). While we are in - * this loop, info->count is dropped by one, so that - * mgslpc_close() knows when to free things. We restore it upon - * exit, either normal or abnormal. - */ - - retval = 0; - add_wait_queue(&info->open_wait, &wait); - - if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):block_til_ready before block on %s count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->count ); - - spin_lock_irqsave(&info->lock, flags); - if (!tty_hung_up_p(filp)) { - extra_count = true; - info->count--; - } - spin_unlock_irqrestore(&info->lock, flags); - info->blocked_open++; - - while (1) { - if ((tty->termios->c_cflag & CBAUD)) { - spin_lock_irqsave(&info->lock,flags); - info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); - } - - set_current_state(TASK_INTERRUPTIBLE); - - if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){ - retval = (info->flags & ASYNC_HUP_NOTIFY) ? - -EAGAIN : -ERESTARTSYS; - break; - } - - spin_lock_irqsave(&info->lock,flags); - get_signals(info); - spin_unlock_irqrestore(&info->lock,flags); - - if (!(info->flags & ASYNC_CLOSING) && - (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) { - break; - } - - if (signal_pending(current)) { - retval = -ERESTARTSYS; - break; - } - - if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):block_til_ready blocking on %s count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->count ); - - schedule(); - } - - set_current_state(TASK_RUNNING); - remove_wait_queue(&info->open_wait, &wait); + MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); + unsigned long flags; - if (extra_count) - info->count++; - info->blocked_open--; + spin_lock_irqsave(&info->lock,flags); + get_signals(info); + spin_unlock_irqrestore(&info->lock,flags); - if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):block_til_ready after blocking on %s count=%d\n", - __FILE__,__LINE__, tty->driver->name, info->count ); + if (info->serial_signals & SerialSignal_DCD) + return 1; + return 0; +} - if (!retval) - info->flags |= ASYNC_NORMAL_ACTIVE; +static void raise_dtr_rts(struct tty_port *port) +{ + MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); + unsigned long flags; - return retval; + spin_lock_irqsave(&info->lock,flags); + info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; + set_signals(info); + spin_unlock_irqrestore(&info->lock,flags); } + static int mgslpc_open(struct tty_struct *tty, struct file * filp) { MGSLPC_INFO *info; + struct tty_port *port; int retval, line; unsigned long flags; @@ -2691,23 +2561,24 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp) if (mgslpc_paranoia_check(info, tty->name, "mgslpc_open")) return -ENODEV; + port = &info->port; tty->driver_data = info; - info->tty = tty; + tty_port_tty_set(port, tty); if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_open(%s), old ref count = %d\n", - __FILE__,__LINE__,tty->driver->name, info->count); + __FILE__,__LINE__,tty->driver->name, port->count); /* If port is closing, signal caller to try again */ - if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){ - if (info->flags & ASYNC_CLOSING) - interruptible_sleep_on(&info->close_wait); - retval = ((info->flags & ASYNC_HUP_NOTIFY) ? + if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){ + if (port->flags & ASYNC_CLOSING) + interruptible_sleep_on(&port->close_wait); + retval = ((port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); goto cleanup; } - info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; + tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; spin_lock_irqsave(&info->netlock, flags); if (info->netcount) { @@ -2715,17 +2586,19 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp) spin_unlock_irqrestore(&info->netlock, flags); goto cleanup; } - info->count++; + spin_lock(&port->lock); + port->count++; + spin_unlock(&port->lock); spin_unlock_irqrestore(&info->netlock, flags); - if (info->count == 1) { + if (port->count == 1) { /* 1st open on this device, init hardware */ - retval = startup(info); + retval = startup(info, tty); if (retval < 0) goto cleanup; } - retval = block_til_ready(tty, filp, info); + retval = tty_port_block_til_ready(&info->port, tty, filp); if (retval) { if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):block_til_ready(%s) returned %d\n", @@ -2739,13 +2612,6 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp) retval = 0; cleanup: - if (retval) { - if (tty->count == 1) - info->tty = NULL; /* tty layer will release tty struct */ - if(info->count) - info->count--; - } - return retval; } @@ -3500,7 +3366,7 @@ static void rx_start(MGSLPC_INFO *info) info->rx_enabled = true; } -static void tx_start(MGSLPC_INFO *info) +static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty) { if (debug_level >= DEBUG_LEVEL_ISR) printk("%s(%d):tx_start(%s)\n", @@ -3524,11 +3390,11 @@ static void tx_start(MGSLPC_INFO *info) if (info->params.mode == MGSL_MODE_ASYNC) { if (!info->tx_active) { info->tx_active = true; - tx_ready(info); + tx_ready(info, tty); } } else { info->tx_active = true; - tx_ready(info); + tx_ready(info, tty); mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(5000)); } @@ -3849,13 +3715,12 @@ static void rx_reset_buffers(MGSLPC_INFO *info) * * Returns true if frame returned, otherwise false */ -static bool rx_get_frame(MGSLPC_INFO *info) +static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty) { unsigned short status; RXBUF *buf; unsigned int framesize = 0; unsigned long flags; - struct tty_struct *tty = info->tty; bool return_frame = false; if (info->rx_frame_count == 0) @@ -4075,7 +3940,11 @@ static void tx_timeout(unsigned long context) hdlcdev_tx_done(info); else #endif - bh_transmit(info); + { + struct tty_struct *tty = tty_port_tty_get(&info->port); + bh_transmit(info, tty); + tty_kref_put(tty); + } } #if SYNCLINK_GENERIC_HDLC @@ -4094,11 +3963,12 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding, unsigned short parity) { MGSLPC_INFO *info = dev_to_port(dev); + struct tty_struct *tty; unsigned char new_encoding; unsigned short new_crctype; /* return error if TTY interface open */ - if (info->count) + if (info->port.count) return -EBUSY; switch (encoding) @@ -4123,8 +3993,11 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding, info->params.crc_type = new_crctype; /* if network interface up, reprogram hardware */ - if (info->netcount) - mgslpc_program_hw(info); + if (info->netcount) { + tty = tty_port_tty_get(&info->port); + mgslpc_program_hw(info, tty); + tty_kref_put(tty); + } return 0; } @@ -4165,8 +4038,11 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev) /* start hardware transmitter if necessary */ spin_lock_irqsave(&info->lock,flags); - if (!info->tx_active) - tx_start(info); + if (!info->tx_active) { + struct tty_struct *tty = tty_port_tty_get(&info->port); + tx_start(info, tty); + tty_kref_put(tty); + } spin_unlock_irqrestore(&info->lock,flags); return 0; @@ -4183,6 +4059,7 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev) static int hdlcdev_open(struct net_device *dev) { MGSLPC_INFO *info = dev_to_port(dev); + struct tty_struct *tty; int rc; unsigned long flags; @@ -4195,7 +4072,7 @@ static int hdlcdev_open(struct net_device *dev) /* arbitrate between network and tty opens */ spin_lock_irqsave(&info->netlock, flags); - if (info->count != 0 || info->netcount != 0) { + if (info->port.count != 0 || info->netcount != 0) { printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name); spin_unlock_irqrestore(&info->netlock, flags); return -EBUSY; @@ -4203,17 +4080,19 @@ static int hdlcdev_open(struct net_device *dev) info->netcount=1; spin_unlock_irqrestore(&info->netlock, flags); + tty = tty_port_tty_get(&info->port); /* claim resources and init adapter */ - if ((rc = startup(info)) != 0) { + if ((rc = startup(info, tty)) != 0) { + tty_kref_put(tty); spin_lock_irqsave(&info->netlock, flags); info->netcount=0; spin_unlock_irqrestore(&info->netlock, flags); return rc; } - /* assert DTR and RTS, apply hardware settings */ info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; - mgslpc_program_hw(info); + mgslpc_program_hw(info, tty); + tty_kref_put(tty); /* enable network layer transmit */ dev->trans_start = jiffies; @@ -4241,6 +4120,7 @@ static int hdlcdev_open(struct net_device *dev) static int hdlcdev_close(struct net_device *dev) { MGSLPC_INFO *info = dev_to_port(dev); + struct tty_struct *tty = tty_port_tty_get(&info->port); unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) @@ -4249,8 +4129,8 @@ static int hdlcdev_close(struct net_device *dev) netif_stop_queue(dev); /* shutdown adapter and release resources */ - shutdown(info); - + shutdown(info, tty); + tty_kref_put(tty); hdlc_close(dev); spin_lock_irqsave(&info->netlock, flags); @@ -4281,7 +4161,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name); /* return error if TTY interface open */ - if (info->count) + if (info->port.count) return -EBUSY; if (cmd != SIOCWANDEV) @@ -4354,8 +4234,11 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) info->params.clock_speed = 0; /* if network interface up, reprogram hardware */ - if (info->netcount) - mgslpc_program_hw(info); + if (info->netcount) { + struct tty_struct *tty = tty_port_tty_get(&info->port); + mgslpc_program_hw(info, tty); + tty_kref_put(tty); + } return 0; default: -- cgit v1.2.3 From c847d47cb7b2fa78b17c9e17ed3fbd010ee3d3ca Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Fri, 2 Jan 2009 13:50:07 +0000 Subject: drivers/char/cyclades.c: cy_pci_probe: fix error path We forgot to release resources in one case. Addresses http://bugzilla.kernel.org/show_bug.cgi?id=12137 Reported-by: Florian Lohoff Signed-off-by: Andrew Morton Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/cyclades.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c index 5e5b1dc1a0a..6a59f72a9c2 100644 --- a/drivers/char/cyclades.c +++ b/drivers/char/cyclades.c @@ -5010,7 +5010,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev, if (nchan == 0) { dev_err(&pdev->dev, "Cyclom-Y PCI host card with no " "Serial-Modules\n"); - return -EIO; + goto err_unmap; } } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) { struct RUNTIME_9060 __iomem *ctl_addr; -- cgit v1.2.3 From 7ab21a8692094872298df172f54d55cba72fd308 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Fri, 2 Jan 2009 16:19:13 +0000 Subject: i8k: Enable i8k on Dell Precision Systems Patch to enable i8k on Dell Precisions. Signed-off-by: Andy Spencer Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/i8k.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/char') diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c index b60d425ce8d..099fc89a5bd 100644 --- a/drivers/char/i8k.c +++ b/drivers/char/i8k.c @@ -485,6 +485,13 @@ static struct dmi_system_id __initdata i8k_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "MP061"), }, }, + { + .ident = "Dell Precision", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Precision"), + }, + }, { } }; -- cgit v1.2.3 From bef2a508b4276fd7897b2cb27df037d26361842c Mon Sep 17 00:00:00 2001 From: Federico Heinz Date: Fri, 2 Jan 2009 16:19:23 +0000 Subject: i8k: Add Dell Vostro systems This trivial patch adds support for i8k on the new Dell Vostro models. I tested it on my Vostro 1400, and it works. It does print a warning when loading the module: i8k: unable to get SMM BIOS version But I couldn't figure out how to fix that. The module seems to work fine, anyway... Signed-off-by: Federico Heinz Signed-off-by: Alan Cox Signed-off-by: Linus Torvalds --- drivers/char/i8k.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c index 099fc89a5bd..fc8cf7ac7f2 100644 --- a/drivers/char/i8k.c +++ b/drivers/char/i8k.c @@ -492,7 +492,14 @@ static struct dmi_system_id __initdata i8k_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Precision"), }, }, - { } + { + .ident = "Dell Vostro", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"), + }, + }, + { } }; /* -- cgit v1.2.3 From 2f983570010a0dcb26d988da02d7ccfad00c807c Mon Sep 17 00:00:00 2001 From: Yinghai Lu Date: Sat, 3 Jan 2009 00:06:34 -0800 Subject: sparseirq: move set/get_timer_rand_state back to .c those two functions only used in that C file Signed-off-by: Yinghai Lu Signed-off-by: Linus Torvalds --- drivers/char/random.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/random.c b/drivers/char/random.c index d26891bfcd4..c7afc068c28 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -559,7 +559,40 @@ struct timer_rand_state { }; #ifndef CONFIG_SPARSE_IRQ -struct timer_rand_state *irq_timer_state[NR_IRQS]; + +static struct timer_rand_state *irq_timer_state[NR_IRQS]; + +static struct timer_rand_state *get_timer_rand_state(unsigned int irq) +{ + return irq_timer_state[irq]; +} + +static void set_timer_rand_state(unsigned int irq, + struct timer_rand_state *state) +{ + irq_timer_state[irq] = state; +} + +#else + +static struct timer_rand_state *get_timer_rand_state(unsigned int irq) +{ + struct irq_desc *desc; + + desc = irq_to_desc(irq); + + return desc->timer_rand_state; +} + +static void set_timer_rand_state(unsigned int irq, + struct timer_rand_state *state) +{ + struct irq_desc *desc; + + desc = irq_to_desc(irq); + + desc->timer_rand_state = state; +} #endif static struct timer_rand_state input_timer_state; @@ -919,11 +952,6 @@ void rand_initialize_irq(int irq) { struct timer_rand_state *state; -#ifndef CONFIG_SPARSE_IRQ - if (irq >= nr_irqs) - return; -#endif - state = get_timer_rand_state(irq); if (state) -- cgit v1.2.3 From 0211a9c8508b2183e0e539509aad60414f1c3813 Mon Sep 17 00:00:00 2001 From: Frederik Schwarzer Date: Mon, 29 Dec 2008 22:14:56 +0100 Subject: trivial: fix an -> a typos in documentation and comments It is always "an" if there is a vowel _spoken_ (not written). So it is: "an hour" (spoken vowel) but "a uniform" (spoken 'j') Signed-off-by: Frederik Schwarzer Signed-off-by: Jiri Kosina --- drivers/char/epca.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/epca.c b/drivers/char/epca.c index 39ad820b235..af7c13ca949 100644 --- a/drivers/char/epca.c +++ b/drivers/char/epca.c @@ -769,7 +769,7 @@ static int pc_open(struct tty_struct *tty, struct file *filp) /* Check status of board configured in system. */ /* - * I check to see if the epca_setup routine detected an user error. It + * I check to see if the epca_setup routine detected a user error. It * might be better to put this in pc_init, but for the moment it goes * here. */ -- cgit v1.2.3 From 24d254759dc4eb59b47317790c05569f732a2577 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Tue, 6 Jan 2009 10:44:38 -0800 Subject: mwave: struct device - replace bus_id with dev_name(), dev_set_name() Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/char/mwave/mwavedd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/mwave/mwavedd.c b/drivers/char/mwave/mwavedd.c index 4f8d67fed29..94ad2c3bfc4 100644 --- a/drivers/char/mwave/mwavedd.c +++ b/drivers/char/mwave/mwavedd.c @@ -663,7 +663,7 @@ static int __init mwave_init(void) #if 0 /* sysfs */ memset(&mwave_device, 0, sizeof (struct device)); - snprintf(mwave_device.bus_id, BUS_ID_SIZE, "mwave"); + dev_set_name(&mwave_device, "mwave"); if (device_register(&mwave_device)) goto cleanup_error; -- cgit v1.2.3 From 3f4528d6e91cffde49894f5252e6657d420d3d74 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Tue, 6 Jan 2009 13:20:38 -0800 Subject: sparc64: Fix unsigned long long warnings in drivers. Fix warnings caused by the unsigned long long usage in sparc specific drivers. The drivers were considered sparc specific more or less from the filename alone. Signed-off-by: Sam Ravnborg Signed-off-by: Andrew Morton Signed-off-by: David S. Miller --- drivers/char/hw_random/n2-drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index 8859aeac2d2..9b3e09cd41f 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c @@ -482,7 +482,7 @@ static void n2rng_dump_test_buffer(struct n2rng *np) int i; for (i = 0; i < SELFTEST_BUFFER_WORDS; i++) - dev_err(&np->op->dev, "Test buffer slot %d [0x%016lx]\n", + dev_err(&np->op->dev, "Test buffer slot %d [0x%016llx]\n", i, np->test_buffer[i]); } -- cgit v1.2.3 From 69beeb1d3428424fbc7546f85e5cd7ac4119c09d Mon Sep 17 00:00:00 2001 From: KOSAKI Motohiro Date: Tue, 6 Jan 2009 14:39:46 -0800 Subject: mm: make vread() and vwrite() declaration Sparse output following warnings. mm/vmalloc.c:1436:6: warning: symbol 'vread' was not declared. Should it be static? mm/vmalloc.c:1474:6: warning: symbol 'vwrite' was not declared. Should it be static? However, it is used by /dev/kmem. fixed here. Signed-off-by: KOSAKI Motohiro Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/mem.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 6431f6921a6..3586b3b3df3 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -425,9 +425,6 @@ static ssize_t read_oldmem(struct file *file, char __user *buf, } #endif -extern long vread(char *buf, char *addr, unsigned long count); -extern long vwrite(char *buf, char *addr, unsigned long count); - #ifdef CONFIG_DEVKMEM /* * This function reads the *virtual* memory as seen by the kernel. -- cgit v1.2.3 From 208b95ce3afbc2f4ef0a84b8cfdd7a8b94d17a5a Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Tue, 6 Jan 2009 14:41:13 -0800 Subject: sysrq: more explicit, less terse help messages Eliminate sysrq terse help mode; make sysrq help messages more meaningful (more explicit/verbose). Make the sysrq action letter clearer by listing it explicitly in more sysrq help messages (when it is not simple/clear). The SysRq help message now looks like this: SysRq : HELP : loglevel(0-9) reBoot terminate-all-tasks(E) memory-full-oom-kill(F) kill-all-tasks(I) saK show-backtrace-all-active-cpus(L) show-memory-usage(M) nice-all-RT-tasks(N) powerOff show-registers(P) show-all-timers(Q) unRaw Sync show-task-states(T) Unmount show-blocked-tasks(W) Addresses http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=330403. Signed-off-by: Randy Dunlap Cc: Cc: <330403@bugs.debian.org> Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/sysrq.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c index 94966edfb44..d41b9f6f790 100644 --- a/drivers/char/sysrq.c +++ b/drivers/char/sysrq.c @@ -82,7 +82,7 @@ static void sysrq_handle_loglevel(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_loglevel_op = { .handler = sysrq_handle_loglevel, - .help_msg = "loglevel0-8", + .help_msg = "loglevel(0-9)", .action_msg = "Changing Loglevel", .enable_mask = SYSRQ_ENABLE_LOG, }; @@ -233,7 +233,7 @@ static void sysrq_handle_showallcpus(int key, struct tty_struct *tty) static struct sysrq_key_op sysrq_showallcpus_op = { .handler = sysrq_handle_showallcpus, - .help_msg = "aLlcpus", + .help_msg = "show-backtrace-all-active-cpus(L)", .action_msg = "Show backtrace of all active CPUs", .enable_mask = SYSRQ_ENABLE_DUMP, }; @@ -247,7 +247,7 @@ static void sysrq_handle_showregs(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_showregs_op = { .handler = sysrq_handle_showregs, - .help_msg = "showPc", + .help_msg = "show-registers(P)", .action_msg = "Show Regs", .enable_mask = SYSRQ_ENABLE_DUMP, }; @@ -258,7 +258,7 @@ static void sysrq_handle_showstate(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_showstate_op = { .handler = sysrq_handle_showstate, - .help_msg = "showTasks", + .help_msg = "show-task-states(T)", .action_msg = "Show State", .enable_mask = SYSRQ_ENABLE_DUMP, }; @@ -269,7 +269,7 @@ static void sysrq_handle_showstate_blocked(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_showstate_blocked_op = { .handler = sysrq_handle_showstate_blocked, - .help_msg = "shoW-blocked-tasks", + .help_msg = "show-blocked-tasks(W)", .action_msg = "Show Blocked State", .enable_mask = SYSRQ_ENABLE_DUMP, }; @@ -297,7 +297,7 @@ static void sysrq_handle_showmem(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_showmem_op = { .handler = sysrq_handle_showmem, - .help_msg = "showMem", + .help_msg = "show-memory-usage(M)", .action_msg = "Show Memory", .enable_mask = SYSRQ_ENABLE_DUMP, }; @@ -323,7 +323,7 @@ static void sysrq_handle_term(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_term_op = { .handler = sysrq_handle_term, - .help_msg = "tErm", + .help_msg = "terminate-all-tasks(E)", .action_msg = "Terminate All Tasks", .enable_mask = SYSRQ_ENABLE_SIGNAL, }; @@ -341,7 +341,7 @@ static void sysrq_handle_moom(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_moom_op = { .handler = sysrq_handle_moom, - .help_msg = "Full", + .help_msg = "memory-full-oom-kill(F)", .action_msg = "Manual OOM execution", .enable_mask = SYSRQ_ENABLE_SIGNAL, }; @@ -353,7 +353,7 @@ static void sysrq_handle_kill(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_kill_op = { .handler = sysrq_handle_kill, - .help_msg = "kIll", + .help_msg = "kill-all-tasks(I)", .action_msg = "Kill All Tasks", .enable_mask = SYSRQ_ENABLE_SIGNAL, }; @@ -364,7 +364,7 @@ static void sysrq_handle_unrt(int key, struct tty_struct *tty) } static struct sysrq_key_op sysrq_unrt_op = { .handler = sysrq_handle_unrt, - .help_msg = "Nice", + .help_msg = "nice-all-RT-tasks(N)", .action_msg = "Nice All RT Tasks", .enable_mask = SYSRQ_ENABLE_RTNICE, }; -- cgit v1.2.3 From 103d6d9170e3ecd9cefee9406bf928e1fcc45cc5 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 6 Jan 2009 14:42:10 -0800 Subject: genrtc: disable genrtc on Blackfin systems Blackfin platforms do not support the hardware which this driver drives. Signed-off-by: Mike Frysinger Signed-off-by: Bryan Wu Acked-by: Alessandro Zummo Cc: David Brownell Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 1697043119b..35914b6e1d2 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -841,7 +841,7 @@ config JS_RTC config GEN_RTC tristate "Generic /dev/rtc emulation" - depends on RTC!=y && !IA64 && !ARM && !M32R && !MIPS && !SPARC && !FRV && !S390 && !SUPERH && !AVR32 + depends on RTC!=y && !IA64 && !ARM && !M32R && !MIPS && !SPARC && !FRV && !S390 && !SUPERH && !AVR32 && !BLACKFIN ---help--- If you say Y here and create a character special file /dev/rtc with major number 10 and minor number 135 using mknod ("man mknod"), you -- cgit v1.2.3 From 71183c94804e8e19be32acccc8a019ffb445ec2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Tue, 6 Jan 2009 14:42:54 -0800 Subject: consolemap: indentation & braces disagree - reindent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ilpo Järvinen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/consolemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/consolemap.c b/drivers/char/consolemap.c index 4246b8e36cb..45d3e80156d 100644 --- a/drivers/char/consolemap.c +++ b/drivers/char/consolemap.c @@ -554,7 +554,7 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) __get_user(fontpos, &list->fontpos); if ((err1 = con_insert_unipair(p, unicode,fontpos)) != 0) err = err1; - list++; + list++; } if (con_unify_unimap(vc, p)) -- cgit v1.2.3 From cda796a3d572059d64f5429dfc1d00ca6fcbaf8d Mon Sep 17 00:00:00 2001 From: Matt Mackall Date: Tue, 6 Jan 2009 14:42:55 -0800 Subject: random: don't try to look at entropy_count outside the lock As a non-atomic value, it's only safe to look at entropy_count when the pool lock is held, so we move the BUG_ON inside the lock for correctness. Also remove the spurious comment. It's ok for entropy_count to temporarily exceed POOLBITS so long as it's left in a consistent state when the lock is released. This is a more correct, simple, and idiomatic fix for the bug in 8b76f46a2db. I've left the reorderings introduced by that patch in place as they're harmless, even though they don't properly deal with potential atomicity issues. Signed-off-by: Matt Mackall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/random.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/random.c b/drivers/char/random.c index c7afc068c28..7c13581ca9c 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -407,7 +407,7 @@ struct entropy_store { /* read-write data: */ spinlock_t lock; unsigned add_ptr; - int entropy_count; /* Must at no time exceed ->POOLBITS! */ + int entropy_count; int input_rotate; }; @@ -767,11 +767,10 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min, { unsigned long flags; - BUG_ON(r->entropy_count > r->poolinfo->POOLBITS); - /* Hold lock while accounting */ spin_lock_irqsave(&r->lock, flags); + BUG_ON(r->entropy_count > r->poolinfo->POOLBITS); DEBUG_ENT("trying to extract %d bits from %s\n", nbytes * 8, r->name); -- cgit v1.2.3 From d2b4397bf87cf6547ca9fa75b6b84eada96c0848 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Tue, 6 Jan 2009 05:57:24 +0000 Subject: powerpc: Fix iseries drivers build failure without CONFIG_VIOPATH iSeries dependent drivers fail to build, when CONFIG_VIOPATH is disabled. Fix the problem by making those drivers select it. Signed-off-by: Kamalesh Babulal Signed-off-by: Benjamin Herrenschmidt --- drivers/char/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 35914b6e1d2..f5be8081cd8 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -616,6 +616,7 @@ config HVC_ISERIES default y select HVC_DRIVER select HVC_IRQ + select VIOPATH help iSeries machines support a hypervisor virtual console. -- cgit v1.2.3 From 19b0bd025d6647549e07becf02b99e5168c17432 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Tue, 6 Jan 2009 14:01:23 +0000 Subject: powerpc/cell: Use correct types in beat files Only pass the address of a u64 if that is what the function requires. [Split out of a larger patch - sfr] [update comment - sfr] Signed-off-by: Ingo Molnar Signed-off-by: Stephen Rothwell Signed-off-by: Benjamin Herrenschmidt --- drivers/char/hvc_beat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c index 91cdb35a920..0afc8b82212 100644 --- a/drivers/char/hvc_beat.c +++ b/drivers/char/hvc_beat.c @@ -44,7 +44,7 @@ static int hvc_beat_get_chars(uint32_t vtermno, char *buf, int cnt) static unsigned char q[sizeof(unsigned long) * 2] __attribute__((aligned(sizeof(unsigned long)))); static int qlen = 0; - unsigned long got; + u64 got; again: if (qlen) { @@ -63,7 +63,7 @@ again: } } if (beat_get_term_char(vtermno, &got, - ((unsigned long *)q), ((unsigned long *)q) + 1) == 0) { + ((u64 *)q), ((u64 *)q) + 1) == 0) { qlen = got; goto again; } -- cgit v1.2.3 From 09f50c95425318232c534d931d8c28b96a3ce2c5 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 7 Jan 2009 18:08:57 -0800 Subject: tpm: clean up tpm_nsc driver for platform_device suspend/resume compliance Signed-off-by: Marcel Selhorst Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_nsc.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index ab18c1e7b11..70efba2ee05 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -273,12 +273,23 @@ static void tpm_nsc_remove(struct device *dev) } } -static struct device_driver nsc_drv = { - .name = "tpm_nsc", - .bus = &platform_bus_type, - .owner = THIS_MODULE, - .suspend = tpm_pm_suspend, - .resume = tpm_pm_resume, +static int tpm_nsc_suspend(struct platform_device *dev, pm_message_t msg) +{ + return tpm_pm_suspend(&dev->dev, msg); +} + +static int tpm_nsc_resume(struct platform_device *dev) +{ + return tpm_pm_resume(&dev->dev); +} + +static struct platform_driver nsc_drv = { + .suspend = tpm_nsc_suspend, + .resume = tpm_nsc_resume, + .driver = { + .name = "tpm_nsc", + .owner = THIS_MODULE, + }, }; static int __init init_nsc(void) @@ -297,7 +308,7 @@ static int __init init_nsc(void) return -ENODEV; } - err = driver_register(&nsc_drv); + err = platform_driver_register(&nsc_drv); if (err) return err; @@ -308,17 +319,15 @@ static int __init init_nsc(void) /* enable the DPM module */ tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); - pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL); + pdev = platform_device_alloc("tpm_nscl0", -1); if (!pdev) { rc = -ENOMEM; goto err_unreg_drv; } - pdev->name = "tpm_nscl0"; - pdev->id = -1; pdev->num_resources = 0; + pdev->dev.driver = &nsc_drv.driver; pdev->dev.release = tpm_nsc_remove; - pdev->dev.driver = &nsc_drv; if ((rc = platform_device_register(pdev)) < 0) goto err_free_dev; @@ -377,7 +386,7 @@ err_unreg_dev: err_free_dev: kfree(pdev); err_unreg_drv: - driver_unregister(&nsc_drv); + platform_driver_unregister(&nsc_drv); return rc; } @@ -390,7 +399,7 @@ static void __exit cleanup_nsc(void) pdev = NULL; } - driver_unregister(&nsc_drv); + platform_driver_unregister(&nsc_drv); } module_init(init_nsc); -- cgit v1.2.3 From da2bdf9a6ff40b10d77620d0d76b02a738c103cb Mon Sep 17 00:00:00 2001 From: Roel Kluin Date: Wed, 7 Jan 2009 18:09:15 -0800 Subject: Make various things static Building an allnoconfig kernel, sparse asked whether these could be static, so I checked, and they are only used in the file where they are declared. Signed-off-by: Roel Kluin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/pty.c | 2 +- drivers/char/vt.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 112a6ba9a96..146c97613da 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c @@ -32,7 +32,7 @@ /* These are global because they are accessed in tty_io.c */ #ifdef CONFIG_UNIX98_PTYS -struct tty_driver *ptm_driver; +static struct tty_driver *ptm_driver; static struct tty_driver *pts_driver; #endif diff --git a/drivers/char/vt.c b/drivers/char/vt.c index 80014213fb5..7900bd63b36 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -969,8 +969,7 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) * Takes the console sem and the called methods then take the tty * termios_mutex and the tty ctrl_lock in that order. */ - -int vt_resize(struct tty_struct *tty, struct winsize *ws) +static int vt_resize(struct tty_struct *tty, struct winsize *ws) { struct vc_data *vc = tty->driver_data; int ret; -- cgit v1.2.3 From 048cd5888f81713af4597bde5815f32d58fdf5b0 Mon Sep 17 00:00:00 2001 From: David John Date: Thu, 23 Oct 2008 13:55:56 +0530 Subject: RTC: Remove the BKL. Remove calls to the BKL since concurrent access is protected by the spin lock rtc_lock. Signed-off-by: David John Cc: Ingo Molnar Signed-off-by: Jonathan Corbet --- drivers/char/rtc.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c index 20d6efb6324..e0d0f8b2696 100644 --- a/drivers/char/rtc.c +++ b/drivers/char/rtc.c @@ -48,9 +48,10 @@ * CONFIG_HPET_EMULATE_RTC * 1.12a Maciej W. Rozycki: Handle memory-mapped chips properly. * 1.12ac Alan Cox: Allow read access to the day of week register + * 1.12b David John: Remove calls to the BKL. */ -#define RTC_VERSION "1.12ac" +#define RTC_VERSION "1.12b" /* * Note that *all* calls to CMOS_READ and CMOS_WRITE are done with @@ -73,7 +74,6 @@ #include #include #include -#include #include #include #include @@ -182,8 +182,8 @@ static int rtc_proc_open(struct inode *inode, struct file *file); /* * rtc_status is never changed by rtc_interrupt, and ioctl/open/close is - * protected by the big kernel lock. However, ioctl can still disable the timer - * in rtc_status and then with del_timer after the interrupt has read + * protected by the spin lock rtc_lock. However, ioctl can still disable the + * timer in rtc_status and then with del_timer after the interrupt has read * rtc_status but before mod_timer is called, which would then reenable the * timer (but you would need to have an awful timing before you'd trip on it) */ @@ -720,9 +720,7 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel) static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long ret; - lock_kernel(); ret = rtc_do_ioctl(cmd, arg, 0); - unlock_kernel(); return ret; } @@ -731,12 +729,8 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) * Also clear the previous interrupt data on an open, and clean * up things on a close. */ - -/* We use rtc_lock to protect against concurrent opens. So the BKL is not - * needed here. Or anywhere else in this driver. */ static int rtc_open(struct inode *inode, struct file *file) { - lock_kernel(); spin_lock_irq(&rtc_lock); if (rtc_status & RTC_IS_OPEN) @@ -746,12 +740,10 @@ static int rtc_open(struct inode *inode, struct file *file) rtc_irq_data = 0; spin_unlock_irq(&rtc_lock); - unlock_kernel(); return 0; out_busy: spin_unlock_irq(&rtc_lock); - unlock_kernel(); return -EBUSY; } @@ -800,7 +792,6 @@ no_irq: } #ifdef RTC_IRQ -/* Called without the kernel lock - fine */ static unsigned int rtc_poll(struct file *file, poll_table *wait) { unsigned long l; -- cgit v1.2.3