Re: serial driver changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is second stab at the ussp driver.
I'm not sure about the TTY_NORMAL that was in port->tty->flip.flag_buf_ptr under the USSP_READ - should this flag character be inserted into the flip buffer after the data bytes, as seen in the patch?

Thanks,
Hinko

-- 
ČETRTA POT, d.o.o., Kranj
Planina 3
4000 Kranj
Slovenia, Europe
Tel. +386 (0) 4 280 66 03
E-mail: hinko.kocevar@xxxxxxxxxxxx
Http: www.cetrtapot.si

diff -urN ussp26-10/Makefile ussp26-26/Makefile
--- ussp26-10/Makefile	2005-03-08 23:08:01.000000000 +0100
+++ ussp26-26/Makefile	2008-07-08 13:23:02.000000000 +0200
@@ -1,6 +1,7 @@
 obj-m += ussp.o
 default:
-	make -C /lib/modules/$(shell uname -r)/build/ SUBDIRS=$(PWD) modules
+	make -C $(shell pwd)/../linux-2.6/ SUBDIRS=$(PWD) modules
 clean:
 	rm ussp.o ussp.ko ussp.mod* .ussp.*
 	rm -r .tmp_versions
+	rm -f [Mm]odule*
diff -urN ussp26-10/ussp.c ussp26-26/ussp.c
--- ussp26-10/ussp.c	2005-03-08 22:46:08.000000000 +0100
+++ ussp26-26/ussp.c	2008-07-09 09:22:27.000000000 +0200
@@ -53,7 +53,7 @@
 #define RCS_ID "$Id: ussp.c,v 1.5 2005/03/08 22:00:02 jth Exp $"
 #define RCS_REV "$Revision: 1.5 $"
 
-#include <linux/config.h>
+//#include <linux/config.h>
 #include <linux/ctype.h>
 
 #if 0
@@ -66,6 +66,7 @@
 #endif
 
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/kdev_t.h>
 #include <asm/io.h>
 #include <linux/kernel.h>
@@ -115,8 +116,8 @@
 /* Configurable options:
    (Don't be too sure that it'll work if you toggle them) */
 
-MODULE_PARM(ussp_debug, "i");
-MODULE_PARM(ussp_set_lowlatency, "i");
+module_param(ussp_debug, int, 0);
+module_param(ussp_set_lowlatency, int, 0);
 
 MODULE_AUTHOR("R.E.Wolff@xxxxxxxxxxxx, patrick@xxxxxxxxxxxx");
 MODULE_DESCRIPTION("User Space Serial Ports");
@@ -224,14 +225,14 @@
 static void ussp_tty_close          (struct tty_struct *, struct file *);
 static int ussp_tty_write_room      (struct tty_struct * );
 static int ussp_tty_chars_in_buffer (struct tty_struct * );
-static void ussp_tty_put_char       (struct tty_struct *, unsigned char);
+static int ussp_tty_put_char       (struct tty_struct *, unsigned char);
 
 void ussp_tty_flush_buffer          (struct tty_struct *tty);
 void ussp_tty_flush_chars           (struct tty_struct *tty);
 void ussp_tty_stop                  (struct tty_struct *tty);
 void ussp_tty_start                 (struct tty_struct *tty);
 void ussp_tty_set_termios           (struct tty_struct * tty,
-                                     struct termios * old_termios);
+                                     struct ktermios * old_termios);
 void ussp_tty_hangup                (struct tty_struct *tty);
 
 struct ussp_port ussp_ports[USSP_MAX_PORTS];
@@ -240,8 +241,8 @@
 
 static struct tty_driver   ussp_driver;
 static struct tty_struct * ussp_table[USSP_MAX_PORTS] = { NULL, };
-static struct termios    * ussp_termios[USSP_MAX_PORTS];
-static struct termios    * ussp_termios_locked[USSP_MAX_PORTS];
+static struct ktermios    * ussp_termios[USSP_MAX_PORTS];
+static struct ktermios    * ussp_termios_locked[USSP_MAX_PORTS];
 
 #define D_DATA_AVAILABLE(port) ((port->daemon_head - port->daemon_tail) & (PAGE_SIZE-1))
 #define TTY_DATA_AVAILABLE(port) ((port->tty_head - port->tty_tail) & (PAGE_SIZE-1))
@@ -312,6 +313,24 @@
 
 
 
+static struct tty_operations ttyops = {
+	.open         = ussp_tty_open,
+	.close                = ussp_tty_close,
+	.write                = ussp_tty_write,
+	.put_char             = ussp_tty_put_char,
+	.flush_chars          = ussp_tty_flush_chars,
+	.write_room           = ussp_tty_write_room,
+	.chars_in_buffer      = ussp_tty_chars_in_buffer,
+	.flush_buffer         = ussp_tty_flush_buffer,
+	.ioctl                = ussp_tty_ioctl,
+	.throttle             = ussp_dummy,
+	.unthrottle           = ussp_dummy,
+	.set_termios          = ussp_tty_set_termios,
+	.stop                 = ussp_tty_stop,
+	.start                = ussp_tty_start,
+	.hangup               = ussp_tty_hangup,
+};
+
 int ussp_init (void)
 {
 	int status;
@@ -340,21 +359,7 @@
 	ussp_driver.termios              = ussp_termios;
 	ussp_driver.termios_locked       = ussp_termios_locked;
 
-	ussp_driver.open	         = ussp_tty_open;
-	ussp_driver.close                = ussp_tty_close;
-	ussp_driver.write                = ussp_tty_write;
-	ussp_driver.put_char             = ussp_tty_put_char;
-	ussp_driver.flush_chars          = ussp_tty_flush_chars;
-	ussp_driver.write_room           = ussp_tty_write_room;
-	ussp_driver.chars_in_buffer      = ussp_tty_chars_in_buffer;
-	ussp_driver.flush_buffer         = ussp_tty_flush_buffer;
-	ussp_driver.ioctl                = ussp_tty_ioctl;
-	ussp_driver.throttle             = ussp_dummy;
-	ussp_driver.unthrottle           = ussp_dummy;
-	ussp_driver.set_termios          = ussp_tty_set_termios;
-	ussp_driver.stop                 = ussp_tty_stop;
-	ussp_driver.start                = ussp_tty_start;
-	ussp_driver.hangup               = ussp_tty_hangup;
+	ussp_driver.ops = &ttyops;
 
 	status = tty_register_driver (&ussp_driver);
 	//printk (KERN_INFO "Return value registering: %d\n", status);
@@ -547,7 +552,7 @@
 
 
 void ussp_tty_set_termios (struct tty_struct * tty,
-                           struct termios * old_termios)
+                           struct ktermios * old_termios)
 {
 	func_enter ();
 
@@ -579,7 +584,7 @@
 }
 
 
-static void ussp_tty_put_char (struct tty_struct * tty, unsigned char ch)
+static int ussp_tty_put_char (struct tty_struct * tty, unsigned char ch)
 {
 	char tempchar = ch;
 	int count;
@@ -591,7 +596,7 @@
 	count = ussp_tty_write (tty, &tempchar, 1);
 	ussp_dprintk (DEBUG_WRITE_TO_CTL, "writing char: %c %d\n", ch, count);
 	func_exit ();
-	return;
+	return count;
 }
 
 
@@ -672,15 +677,6 @@
 		return -EINTR;
 	}
 
-	ussp_dprintk (DEBUG_OPEN, "current->signal->leader: %d current->signal->tty: %d tty->session: %d\n", (int)current->signal->leader, (int)current->signal->tty, (int)tty->session);
-	if (current->signal->leader && !current->signal->tty && tty->session == 0){
-		ussp_dprintk (DEBUG_OPEN, "setting!\n");
-		current->signal->tty = tty;
-		current->signal->tty_old_pgrp = 0;
-		tty->session = current->signal->session;
-		tty->pgrp = process_group(current);
-	}
-
 	func_exit();
 	return op.arg;
 }
@@ -754,13 +750,10 @@
 
 		break;
 	case TIOCSSOFTCAR:
-		if ((rc = verify_area(VERIFY_READ, (void *) arg,
-		                      sizeof(int))) == 0) {
-			get_user(ival, (unsigned int *) arg);
-			tty->termios->c_cflag =
-				(tty->termios->c_cflag & ~CLOCAL) |
-				(ival ? CLOCAL : 0);
-		}
+		get_user(ival, (unsigned int *) arg);
+		tty->termios->c_cflag =
+			(tty->termios->c_cflag & ~CLOCAL) |
+			(ival ? CLOCAL : 0);
 		break;
 	case TIOCMGET:
 		ussp_dprintk (DEBUG_IOCTL, "TIOCMGET\n");
@@ -794,6 +787,10 @@
 			rc = -EFAULT;
 		break;
 
+	case TCSETS:
+		ussp_dprintk (DEBUG_IOCTL, "TCSETS -- what to do here!?\n");
+		break;
+		
 	default:
 		printk (KERN_DEBUG "illegal ioctl: %x (mget = %x)\n",
 			cmd, TIOCMGET);
@@ -977,6 +974,7 @@
 	int rc;
 	struct ussp_operation op;
 	struct ussp_port *port;
+	char *buff;
 	func_enter();
 
 	port = filp->private_data;
@@ -1011,13 +1009,20 @@
 		break;
 	case USSP_READ:
 		ussp_dprintk (DEBUG_IOCTL, "USSP_READ %d\n", (int)op.len);
-		rc = copy_from_user (port->tty->flip.char_buf_ptr, buf + sizeof(struct ussp_operation), op.len);
-		memset(port->tty->flip.flag_buf_ptr, TTY_NORMAL, op.len);
-		port->tty->flip.count += op.len;
-		port->tty->flip.char_buf_ptr += op.len;
-		port->tty->flip.flag_buf_ptr += op.len;
+		buff = kmalloc((int)op.len, GFP_KERNEL);
+		rc = copy_from_user (buff, buf + sizeof(struct ussp_operation), op.len);
+		if (rc)
+		{
+			kfree(buff);
+			return -ENOMEM;
+		}
+		rc = tty_buffer_request_room(port->tty, (int)op.len);
+		if (rc > 0)
+			tty_insert_flip_string(port->tty, buff, (int)op.len);
+		tty_insert_flip_char(port->tty, 0, TTY_NORMAL);
 		tty_flip_buffer_push (port->tty);
 		port->stats.rxcount += op.len;
+		kfree(buff);
 		break;
 	case USSP_FORCE_CLOSE:
 		ussp_dprintk (USSP_CLOSE, "USSP_FORCE_CLOSE %d\n", (int)op.arg);
@@ -1145,6 +1150,7 @@
 	if (tty_unregister_driver(&ussp_driver) < 0) {
 		printk (KERN_INFO "ussp:  couldn't deregister tty device.\n");
 	}
+	printk(KERN_INFO "USSP driver de-registered.\n");
 	func_exit();
 }
 
diff -urN ussp26-10/ussp.h ussp26-26/ussp.h
--- ussp26-10/ussp.h	2004-04-21 18:55:10.000000000 +0200
+++ ussp26-26/ussp.h	2008-07-08 11:44:11.000000000 +0200
@@ -74,8 +74,8 @@
   struct stats            stats;
   int                     deamon_pid;
 
-  struct termios          normal_termios;
-  struct termios          callout_termios;
+  struct ktermios          normal_termios;
+  struct ktermios          callout_termios;
   struct tty_struct      *tty;
 };
 #endif

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux