wok-tiny view linux/stuff/linux-2.6.20-jsclipboard.u @ rev 174

Up linux 2.6.20 (avoid 386 & 486 problems)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 14 14:20:00 2021 +0000 (2021-07-14)
parents
children
line source
1 --- drivers/char/Kconfig
2 +++ drivers/char/Kconfig
3 @@ -1030,5 +1030,11 @@
4 sysfs directory, /sys/devices/platform/telco_clock, with a number of
5 files for controlling the behavior of this hardware.
7 +config JSCLIPBOARD
8 + tristate "Javascript clipboard support (JS/Linux device)"
9 + default n
10 + help
11 + Javascript clipboard support for JS/Linux
12 +
13 endmenu
15 --- drivers/char/Makefile
16 +++ drivers/char/Makefile
17 @@ -90,6 +90,7 @@
18 obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
19 obj-$(CONFIG_TANBAC_TB0219) += tb0219.o
20 obj-$(CONFIG_TELCLOCK) += tlclk.o
21 +obj-$(CONFIG_JSCLIPBOARD) += jsclipboard.o
23 obj-$(CONFIG_WATCHDOG) += watchdog/
24 obj-$(CONFIG_MWAVE) += mwave/
25 --- /dev/null
26 +++ drivers/char/jsclipboard.c
27 @@ -0,0 +1,174 @@
28 +/*
29 + JS clipboard support for JS/Linux
30 + (c) 2011 Fabrice Bellard
31 +*/
32 +#include <linux/interrupt.h>
33 +#include <linux/module.h>
34 +#include <linux/kernel.h>
35 +#include <linux/types.h>
36 +#include <linux/miscdevice.h>
37 +#include <linux/ioport.h>
38 +#include <linux/fcntl.h>
39 +#include <linux/mc146818rtc.h>
40 +#include <linux/init.h>
41 +#include <linux/poll.h>
42 +#include <linux/proc_fs.h>
43 +#include <linux/seq_file.h>
44 +#include <linux/spinlock.h>
45 +#include <linux/sysctl.h>
46 +#include <linux/wait.h>
47 +#include <linux/bcd.h>
48 +#include <linux/delay.h>
49 +
50 +#include <asm/current.h>
51 +#include <asm/uaccess.h>
52 +#include <asm/system.h>
53 +
54 +#define JSCLIPBOARD_MINOR 231
55 +
56 +#define JSCLIPBOARD_PORT 0x3c0
57 +
58 +static int io_port = JSCLIPBOARD_PORT;
59 +static int minor = JSCLIPBOARD_MINOR;
60 +static struct semaphore open_sem;
61 +static int need_cache_sync;
62 +
63 +module_param(io_port, int, 0);
64 +MODULE_PARM_DESC(io_port, "IO port");
65 +
66 +module_param(minor, int, 0);
67 +MODULE_PARM_DESC(minor, "minor number");
68 +
69 +static ssize_t jsclipboard_read(struct file *file, char __user *buf,
70 + size_t count1, loff_t *ppos)
71 +{
72 + uint32_t pos, total_length, v;
73 + uint8_t b;
74 + size_t count, l;
75 +
76 + /* set read position */
77 + pos = *ppos;
78 + outl(pos, io_port + 4);
79 + total_length = inl(io_port + 0);
80 +
81 + if (!access_ok(VERIFY_WRITE, buf, count1))
82 + return -EFAULT;
83 +
84 + if (pos < total_length)
85 + l = total_length - pos;
86 + else
87 + l = 0;
88 + if (count1 > l)
89 + count1 = l;
90 + count = count1;
91 + while (count >= 4) {
92 + v = inl(io_port + 8);
93 + if (__put_user(v, (uint32_t *)buf))
94 + return -EFAULT;
95 + buf += 4;
96 + count -= 4;
97 + }
98 +
99 + while (count != 0) {
100 + b = inb(io_port + 8);
101 + if (__put_user(b, buf))
102 + return -EFAULT;
103 + buf++;
104 + count--;
105 + }
106 +
107 + *ppos = pos + count1;
108 +
109 + return count1;
110 +}
111 +
112 +static ssize_t jsclipboard_write(struct file *file, const char *buf,
113 + size_t count1, loff_t *ppos)
114 +{
115 + size_t count;
116 + uint8_t b;
117 + uint32_t v;
118 +
119 + if (!access_ok(VERIFY_READ, buf, count1))
120 + return -EFAULT;
121 + if (*ppos == 0) {
122 + /* flush clipboard */
123 + outl(0, io_port);
124 + }
125 +
126 + need_cache_sync = 1;
127 +
128 + count = count1;
129 + while (count >= 4) {
130 + if (__get_user(v, (uint32_t *)buf))
131 + return -EFAULT;
132 + outl(v, io_port + 8);
133 + buf += 4;
134 + count -= 4;
135 + }
136 +
137 + while (count != 0) {
138 + if (__get_user(b, buf))
139 + return -EFAULT;
140 + outb(b, io_port + 8);
141 + buf++;
142 + count--;
143 + }
144 + *ppos += count1;
145 + return count1;
146 +}
147 +
148 +static int jsclipboard_open(struct inode *inode, struct file *file)
149 +{
150 + if (down_trylock(&open_sem))
151 + return -EBUSY;
152 + need_cache_sync = 0;
153 + return 0;
154 +}
155 +
156 +static int jsclipboard_release(struct inode *inode, struct file *file)
157 +{
158 + if (need_cache_sync) {
159 + outl(0, io_port + 12);
160 + }
161 + up(&open_sem);
162 + return 0;
163 +}
164 +
165 +static const struct file_operations jsclipboard_fops = {
166 + .owner = THIS_MODULE,
167 + .read = jsclipboard_read,
168 + .write = jsclipboard_write,
169 + .open = jsclipboard_open,
170 + .release = jsclipboard_release,
171 +};
172 +
173 +static struct miscdevice jsclipboard_dev = {
174 + .minor = JSCLIPBOARD_MINOR,
175 + .name = "jsclipboard",
176 + .fops = &jsclipboard_fops,
177 +};
178 +
179 +static int __init jsclipboard_init(void)
180 +{
181 + if (!request_region(io_port, 16, "jsclipboard"))
182 + return -ENODEV;
183 + sema_init(&open_sem, 1);
184 + if (misc_register(&jsclipboard_dev)) {
185 + return -ENODEV;
186 + }
187 + printk(KERN_INFO "JS clipboard: I/O at 0x%04x\n", io_port);
188 + return 0;
189 +}
190 +
191 +static void __exit jsclipboard_exit (void)
192 +{
193 + misc_deregister(&jsclipboard_dev);
194 + release_region(io_port, 16);
195 +}
196 +
197 +module_init(jsclipboard_init);
198 +module_exit(jsclipboard_exit);
199 +
200 +MODULE_AUTHOR("Fabrice Bellard");
201 +MODULE_LICENSE("GPL");
202 --- drivers/serial/8250.c
203 +++ drivers/serial/8250.c
204 @@ -70,7 +70,7 @@
205 #define DEBUG_INTR(fmt...) do { } while (0)
206 #endif
208 -#define PASS_LIMIT 256
209 +#define PASS_LIMIT (256 * 100)
211 /*
212 * We default to IRQ0 for the "no irq" hack. Some