cregit-Linux how code gets into the kernel

Release 4.7 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 <asm/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
pre-gitpre-git4593.75%125.00%
dmitry torokhovdmitry torokhov12.08%125.00%
alan coxalan cox12.08%125.00%
al viroal viro12.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 torokhovdmitry 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); set_bit(SERPORT_DEAD, &serport->flags); spin_unlock_irqrestore(&serport->lock, flags); wake_up_interruptible(&serport->wait); }

Contributors

PersonTokensPropCommitsCommitProp
dmitry torokhovdmitry torokhov4258.33%360.00%
pre-gitpre-git2737.50%120.00%
vojtech pavlikvojtech pavlik34.17%120.00%
Total72100.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
pre-gitpre-git3637.11%112.50%
dmitry torokhovdmitry torokhov3435.05%225.00%
vojtech pavlikvojtech pavlik1515.46%225.00%
alan coxalan cox66.19%112.50%
christoph hellwigchristoph hellwig55.15%112.50%
pekka j enbergpekka 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
pre-gitpre-git30100.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
pre-gitpre-git6541.94%116.67%
dmitry torokhovdmitry torokhov4227.10%116.67%
david engrafdavid engraf3824.52%116.67%
peter hurleypeter hurley85.16%116.67%
linus torvaldslinus torvalds10.65%116.67%
vojtech pavlikvojtech 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 torokhovdmitry torokhov13053.28%112.50%
pre-gitpre-git7430.33%112.50%
vojtech pavlikvojtech pavlik239.43%225.00%
dmitry eremin-baryshkovdmitry eremin-baryshkov104.10%112.50%
linus torvaldslinus torvalds52.05%112.50%
pekka j enbergpekka j enberg10.41%112.50%
al viroal viro10.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 torokhovdmitry torokhov3861.29%250.00%
pre-gitpre-git2032.26%125.00%
john sungjohn 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 sungjohn sung6086.96%133.33%
pre-gitpre-git68.70%133.33%
dmitry torokhovdmitry 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 sungjohn sung77100.00%1100.00%
Total77100.00%1100.00%

#endif
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 torokhovdmitry torokhov3957.35%266.67%
vojtech pavlikvojtech 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, .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
pre-gitpre-git2468.57%133.33%
randy dunlaprandy dunlap1028.57%133.33%
christoph hellwigchristoph hellwig12.86%133.33%
Total35100.00%3100.00%


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

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1285.71%133.33%
alexey dobriyanalexey dobriyan17.14%133.33%
christoph hellwigchristoph hellwig17.14%133.33%
Total14100.00%3100.00%

module_init(serport_init); module_exit(serport_exit);

Overall Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git41434.44%13.33%
dmitry torokhovdmitry torokhov40333.53%620.00%
john sungjohn sung16413.64%13.33%
vojtech pavlikvojtech pavlik1149.48%516.67%
david engrafdavid engraf393.24%13.33%
christoph hellwigchristoph hellwig121.00%13.33%
dmitry eremin-baryshkovdmitry eremin-baryshkov100.83%13.33%
randy dunlaprandy dunlap100.83%13.33%
peter hurleypeter hurley80.67%13.33%
alan coxalan cox80.67%310.00%
linus torvaldslinus torvalds70.58%310.00%
andrew mortonandrew morton50.42%13.33%
alexey dobriyanalexey dobriyan40.33%26.67%
pekka j enbergpekka j enberg20.17%13.33%
al viroal viro20.17%26.67%
Total1202100.00%30100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}