Commit 84d25c7d0f91f90e1343253a5826b37016822151
1 parent
c5a9bd66
Added parameter 'pairs' to select the number of pair of ports
Default value is 4
Showing
1 changed file
with
20 additions
and
7 deletions
module/tty0tty.c
| ... | ... | @@ -51,9 +51,12 @@ MODULE_AUTHOR( DRIVER_AUTHOR ); |
| 51 | 51 | MODULE_DESCRIPTION( DRIVER_DESC ); |
| 52 | 52 | MODULE_LICENSE("GPL"); |
| 53 | 53 | |
| 54 | +short pairs = 4; //Default number of pairs of devices | |
| 55 | +module_param(pairs, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); | |
| 56 | +MODULE_PARM_DESC(pairs, "Number of pairs of devices to be created, maximum of 128"); | |
| 57 | + | |
| 54 | 58 | |
| 55 | 59 | #define TTY0TTY_MAJOR 240 /* experimental range */ |
| 56 | -#define TTY0TTY_MINORS 8 /* device number, always even*/ | |
| 57 | 60 | |
| 58 | 61 | /* fake UART values */ |
| 59 | 62 | //out |
| ... | ... | @@ -67,7 +70,7 @@ MODULE_LICENSE("GPL"); |
| 67 | 70 | #define MSR_RI 0x80 |
| 68 | 71 | |
| 69 | 72 | |
| 70 | -static struct tty_port tport[TTY0TTY_MINORS]; | |
| 73 | +static struct tty_port *tport; | |
| 71 | 74 | |
| 72 | 75 | struct tty0tty_serial { |
| 73 | 76 | struct tty_struct *tty; /* pointer to the tty for this device */ |
| ... | ... | @@ -85,7 +88,7 @@ struct tty0tty_serial { |
| 85 | 88 | |
| 86 | 89 | }; |
| 87 | 90 | |
| 88 | -static struct tty0tty_serial *tty0tty_table[TTY0TTY_MINORS]; /* initially all NULL */ | |
| 91 | +static struct tty0tty_serial **tty0tty_table; /* initially all NULL */ | |
| 89 | 92 | |
| 90 | 93 | |
| 91 | 94 | static int tty0tty_open(struct tty_struct *tty, struct file *file) |
| ... | ... | @@ -623,12 +626,20 @@ static int __init tty0tty_init(void) |
| 623 | 626 | { |
| 624 | 627 | int retval; |
| 625 | 628 | int i; |
| 629 | + if (pairs > 128) pairs = 128; | |
| 630 | + if (pairs < 1) pairs = 1; | |
| 631 | + tport = kmalloc(2*pairs*sizeof(struct tty_port),GFP_KERNEL); | |
| 632 | + tty0tty_table = kmalloc(2*pairs*sizeof(struct tty0tty_serial*),GFP_KERNEL); | |
| 626 | 633 | |
| 634 | + for(i=0;i<2*pairs;i++) | |
| 635 | + { | |
| 636 | + tty0tty_table[i] = NULL; | |
| 637 | + } | |
| 627 | 638 | #ifdef SCULL_DEBUG |
| 628 | 639 | printk(KERN_DEBUG "%s - \n", __FUNCTION__); |
| 629 | 640 | #endif |
| 630 | 641 | /* allocate the tty driver */ |
| 631 | - tty0tty_tty_driver = alloc_tty_driver(TTY0TTY_MINORS); | |
| 642 | + tty0tty_tty_driver = alloc_tty_driver(2*pairs); | |
| 632 | 643 | if (!tty0tty_tty_driver) |
| 633 | 644 | return -ENOMEM; |
| 634 | 645 | |
| ... | ... | @@ -653,7 +664,7 @@ static int __init tty0tty_init(void) |
| 653 | 664 | |
| 654 | 665 | tty_set_operations(tty0tty_tty_driver, &serial_ops); |
| 655 | 666 | |
| 656 | - for(i=0;i<TTY0TTY_MINORS;i++) | |
| 667 | + for(i=0;i<2*pairs;i++) | |
| 657 | 668 | { |
| 658 | 669 | tty_port_init(&tport[i]); |
| 659 | 670 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) |
| ... | ... | @@ -680,7 +691,7 @@ static void __exit tty0tty_exit(void) |
| 680 | 691 | #ifdef SCULL_DEBUG |
| 681 | 692 | printk(KERN_DEBUG "%s - \n", __FUNCTION__); |
| 682 | 693 | #endif |
| 683 | - for (i = 0; i < TTY0TTY_MINORS; ++i) | |
| 694 | + for (i = 0; i < 2*pairs; ++i) | |
| 684 | 695 | { |
| 685 | 696 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) |
| 686 | 697 | tty_port_destroy(&tport[i]); |
| ... | ... | @@ -690,7 +701,7 @@ static void __exit tty0tty_exit(void) |
| 690 | 701 | tty_unregister_driver(tty0tty_tty_driver); |
| 691 | 702 | |
| 692 | 703 | /* shut down all of the timers and free the memory */ |
| 693 | - for (i = 0; i < TTY0TTY_MINORS; ++i) { | |
| 704 | + for (i = 0; i < 2*pairs; ++i) { | |
| 694 | 705 | tty0tty = tty0tty_table[i]; |
| 695 | 706 | if (tty0tty) { |
| 696 | 707 | /* close the port */ |
| ... | ... | @@ -702,6 +713,8 @@ static void __exit tty0tty_exit(void) |
| 702 | 713 | tty0tty_table[i] = NULL; |
| 703 | 714 | } |
| 704 | 715 | } |
| 716 | + kfree(tport); | |
| 717 | + kfree(tty0tty_table); | |
| 705 | 718 | } |
| 706 | 719 | |
| 707 | 720 | module_init(tty0tty_init); | ... | ... |