serial driver changes

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

 



Hi all,

I've stumbled across serial port driver that was written for 2.6.10 kernel [1]. 
Since the time that 2.6.10 was released a lot of changes in serial / tty layers were committed to the mainline.

I've managed to make a initial port to 2.6.26, but I'm not sure if I made (all) the changes that were needed. I've attached the patch for you to review - any comments are welcomed.

Best regards,
Hinko

[1]: http://koti.mbnet.fi/toukka/ussp26-10.tar.gz

-- 
Č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-08 13:25:02.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,11 @@
 /* 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_PARM(ussp_debug, "i");
+//MODULE_PARM(ussp_set_lowlatency, "i");
+/* what is wrong with this lines ??? */
+//module_parm(ussp_debug, int, 0);
+//module_parm(ussp_set_lowlatency, int, 0);
 
 MODULE_AUTHOR("R.E.Wolff@xxxxxxxxxxxx, patrick@xxxxxxxxxxxx");
 MODULE_DESCRIPTION("User Space Serial Ports");
@@ -145,7 +149,6 @@
 	release: ussp_ctl_close
 };
 
-
 struct miscdevice ussp_ctl_device = {
 	USSPCTL_MISC_MINOR, "ussp_ctl", &ussp_ctl_fops
 };
@@ -224,14 +227,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 +243,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 +315,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,7 +361,7 @@
 	ussp_driver.termios              = ussp_termios;
 	ussp_driver.termios_locked       = ussp_termios_locked;
 
-	ussp_driver.open	         = ussp_tty_open;
+/*	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;
@@ -355,6 +376,8 @@
 	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 +570,7 @@
 
 
 void ussp_tty_set_termios (struct tty_struct * tty,
-                           struct termios * old_termios)
+                           struct ktermios * old_termios)
 {
 	func_enter ();
 
@@ -579,7 +602,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 +614,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;
 }
 
 
@@ -671,7 +694,8 @@
 		ussp_dprintk(DEBUG_OPEN, "Daemon returned error.\n");
 		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");
@@ -680,7 +704,7 @@
 		tty->session = current->signal->session;
 		tty->pgrp = process_group(current);
 	}
-
+*/
 	func_exit();
 	return op.arg;
 }
@@ -754,13 +778,15 @@
 
 		break;
 	case TIOCSSOFTCAR:
-		if ((rc = verify_area(VERIFY_READ, (void *) arg,
+		/*  verify_area() function will go away soon - use access_ok() instead */
+/*		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);
 		}
+*/
 		break;
 	case TIOCMGET:
 		ussp_dprintk (DEBUG_IOCTL, "TIOCMGET\n");
@@ -977,6 +1003,7 @@
 	int rc;
 	struct ussp_operation op;
 	struct ussp_port *port;
+	char *buff;
 	func_enter();
 
 	port = filp->private_data;
@@ -1011,13 +1038,19 @@
 		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 (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;
+		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);
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