cregit-Linux how code gets into the kernel

Release 4.11 drivers/input/serio/serport.c

/*
 * Input device TTY line discipline
 *
 * Copyright (c) 1999-2002 Vojtech Pavlik
 *
 * This is a module that converts a tty line into a much simpler
 * 'serial io port' abstraction that the input device drivers use.
 */

/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */

#include <linux/uaccess.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/serio.h>
#include <linux/tty.h>
#include <linux/compat.h>

MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_DESCRIPTION("Input device TTY line discipline");
MODULE_LICENSE("GPL");

MODULE_ALIAS_LDISC(N_MOUSE);


#define SERPORT_BUSY	1

#define SERPORT_ACTIVE	2

#define SERPORT_DEAD	3


struct serport {
	
struct tty_struct *tty;
	
wait_queue_head_t wait;
	
struct serio *serio;
	
struct serio_device_id id;
	
spinlock_t lock;
	
unsigned long flags;
};

/*
 * Callback functions from the serio code.
 */


static int serport_serio_write(struct serio *serio, unsigned char data) { struct serport *serport = serio->port_data; return -(serport->tty->ops->write(serport->tty, &data, 1) != 1); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4593.75%125.00%
Dmitry Torokhov12.08%125.00%
Al Viro12.08%125.00%
Alan Cox12.08%125.00%
Total48100.00%4100.00%


static int serport_serio_open(struct serio *serio) { struct serport *serport = serio->port_data; unsigned long flags; spin_lock_irqsave(&serport->lock, flags); set_bit(SERPORT_ACTIVE, &serport->flags); spin_unlock_irqrestore(&serport->lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov57100.00%1100.00%
Total57100.00%1100.00%


static void serport_serio_close(struct serio *serio) { struct serport *serport = serio->port_data; unsigned long flags; spin_lock_irqsave(&serport->lock, flags); clear_bit(SERPORT_ACTIVE, &serport->flags); spin_unlock_irqrestore(&serport->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov3259.26%360.00%
Linus Torvalds (pre-git)1935.19%120.00%
Vojtech Pavlik35.56%120.00%
Total54100.00%5100.00%

/* * serport_ldisc_open() is the routine that is called upon setting our line * discipline on a tty. It prepares the serio struct. */
static int serport_ldisc_open(struct tty_struct *tty) { struct serport *serport; if (!capable(CAP_SYS_ADMIN)) return -EPERM; serport = kzalloc(sizeof(struct serport), GFP_KERNEL); if (!serport) return -ENOMEM; serport->tty = tty; spin_lock_init(&serport->lock); init_waitqueue_head(&serport->wait); tty->disc_data = serport; tty->receive_room = 256; set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3637.11%112.50%
Dmitry Torokhov3435.05%225.00%
Vojtech Pavlik1515.46%225.00%
Alan Cox66.19%112.50%
Christoph Hellwig55.15%112.50%
Pekka J Enberg11.03%112.50%
Total97100.00%8100.00%

/* * serport_ldisc_close() is the opposite of serport_ldisc_open() */
static void serport_ldisc_close(struct tty_struct *tty) { struct serport *serport = (struct serport *) tty->disc_data; kfree(serport); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)30100.00%1100.00%
Total30100.00%1100.00%

/* * serport_ldisc_receive() is called by the low level tty driver when characters * are ready for us. We forward the characters and flags, one by one to the * 'interrupt' routine. */
static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) { struct serport *serport = (struct serport*) tty->disc_data; unsigned long flags; unsigned int ch_flags = 0; int i; spin_lock_irqsave(&serport->lock, flags); if (!test_bit(SERPORT_ACTIVE, &serport->flags)) goto out; for (i = 0; i < count; i++) { if (fp) { switch (fp[i]) { case TTY_FRAME: ch_flags = SERIO_FRAME; break; case TTY_PARITY: ch_flags = SERIO_PARITY; break; default: ch_flags = 0; break; } } serio_interrupt(serport->serio, cp[i], ch_flags); } out: spin_unlock_irqrestore(&serport->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)6541.94%116.67%
Dmitry Torokhov4227.10%116.67%
David Engraf3824.52%116.67%
Peter Hurley85.16%116.67%
Linus Torvalds10.65%116.67%
Vojtech Pavlik10.65%116.67%
Total155100.00%6100.00%

/* * serport_ldisc_read() just waits indefinitely if everything goes well. * However, when the serio driver closes the serio port, it finishes, * returning 0 characters. */
static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, unsigned char __user * buf, size_t nr) { struct serport *serport = (struct serport*) tty->disc_data; struct serio *serio; if (test_and_set_bit(SERPORT_BUSY, &serport->flags)) return -EBUSY; serport->serio = serio = kzalloc(sizeof(struct serio), GFP_KERNEL); if (!serio) return -ENOMEM; strlcpy(serio->name, "Serial port", sizeof(serio->name)); snprintf(serio->phys, sizeof(serio->phys), "%s/serio0", tty_name(tty)); serio->id = serport->id; serio->id.type = SERIO_RS232; serio->write = serport_serio_write; serio->open = serport_serio_open; serio->close = serport_serio_close; serio->port_data = serport; serio->dev.parent = tty->dev; serio_register_port(serport->serio); printk(KERN_INFO "serio: Serial port %s\n", tty_name(tty)); wait_event_interruptible(serport->wait, test_bit(SERPORT_DEAD, &serport->flags)); serio_unregister_port(serport->serio); serport->serio = NULL; clear_bit(SERPORT_DEAD, &serport->flags); clear_bit(SERPORT_BUSY, &serport->flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov13053.28%112.50%
Linus Torvalds (pre-git)7430.33%112.50%
Vojtech Pavlik239.43%225.00%
Dmitry Baryshkov104.10%112.50%
Linus Torvalds52.05%112.50%
Al Viro10.41%112.50%
Pekka J Enberg10.41%112.50%
Total244100.00%8100.00%


static void serport_set_type(struct tty_struct *tty, unsigned long type) { struct serport *serport = tty->disc_data; serport->id.proto = type & 0x000000ff; serport->id.id = (type & 0x0000ff00) >> 8; serport->id.extra = (type & 0x00ff0000) >> 16; }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov3861.29%250.00%
Linus Torvalds (pre-git)2032.26%125.00%
John Sung46.45%125.00%
Total62100.00%4100.00%

/* * serport_ldisc_ioctl() allows to set the port protocol, and device ID */
static int serport_ldisc_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { if (cmd == SPIOCSTYPE) { unsigned long type; if (get_user(type, (unsigned long __user *) arg)) return -EFAULT; serport_set_type(tty, type); return 0; } return -EINVAL; }

Contributors

PersonTokensPropCommitsCommitProp
John Sung6086.96%133.33%
Linus Torvalds (pre-git)68.70%133.33%
Dmitry Torokhov34.35%133.33%
Total69100.00%3100.00%

#ifdef CONFIG_COMPAT #define COMPAT_SPIOCSTYPE _IOW('q', 0x01, compat_ulong_t)
static long serport_ldisc_compat_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { if (cmd == COMPAT_SPIOCSTYPE) { void __user *uarg = compat_ptr(arg); compat_ulong_t compat_type; if (get_user(compat_type, (compat_ulong_t __user *)uarg)) return -EFAULT; serport_set_type(tty, compat_type); return 0; } return -EINVAL; }

Contributors

PersonTokensPropCommitsCommitProp
John Sung77100.00%1100.00%
Total77100.00%1100.00%

#endif
static int serport_ldisc_hangup(struct tty_struct *tty) { struct serport *serport = (struct serport *) tty->disc_data; unsigned long flags; spin_lock_irqsave(&serport->lock, flags); set_bit(SERPORT_DEAD, &serport->flags); spin_unlock_irqrestore(&serport->lock, flags); wake_up_interruptible(&serport->wait); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Hans Verkuil70100.00%1100.00%
Total70100.00%1100.00%


static void serport_ldisc_write_wakeup(struct tty_struct * tty) { struct serport *serport = (struct serport *) tty->disc_data; unsigned long flags; spin_lock_irqsave(&serport->lock, flags); if (test_bit(SERPORT_ACTIVE, &serport->flags)) serio_drv_write_wakeup(serport->serio); spin_unlock_irqrestore(&serport->lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov3957.35%266.67%
Vojtech Pavlik2942.65%133.33%
Total68100.00%3100.00%

/* * The line discipline structure. */ static struct tty_ldisc_ops serport_ldisc = { .owner = THIS_MODULE, .name = "input", .open = serport_ldisc_open, .close = serport_ldisc_close, .read = serport_ldisc_read, .ioctl = serport_ldisc_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = serport_ldisc_compat_ioctl, #endif .receive_buf = serport_ldisc_receive, .hangup = serport_ldisc_hangup, .write_wakeup = serport_ldisc_write_wakeup }; /* * The functions for insering/removing us as a module. */
static int __init serport_init(void) { int retval; retval = tty_register_ldisc(N_MOUSE, &serport_ldisc); if (retval) printk(KERN_ERR "serport.c: Error registering line discipline.\n"); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2468.57%133.33%
Randy Dunlap1028.57%133.33%
Christoph Hellwig12.86%133.33%
Total35100.00%3100.00%


static void __exit serport_exit(void) { tty_unregister_ldisc(N_MOUSE); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1285.71%133.33%
Christoph Hellwig17.14%133.33%
Alexey Dobriyan17.14%133.33%
Total14100.00%3100.00%

module_init(serport_init); module_exit(serport_exit);

Overall Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)40532.17%13.12%
Dmitry Torokhov39331.22%618.75%
John Sung16413.03%13.12%
Vojtech Pavlik1149.05%515.62%
Hans Verkuil755.96%13.12%
David Engraf393.10%13.12%
Christoph Hellwig120.95%13.12%
Randy Dunlap100.79%13.12%
Dmitry Baryshkov100.79%13.12%
Linus Torvalds80.64%412.50%
Alan Cox80.64%39.38%
Peter Hurley80.64%13.12%
Andrew Morton50.40%13.12%
Alexey Dobriyan40.32%26.25%
Pekka J Enberg20.16%13.12%
Al Viro20.16%26.25%
Total1259100.00%32100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.