Lines Matching +full:wait +full:- +full:on +full:- +full:read
1 // SPDX-License-Identifier: GPL-2.0-only
4 * serio port. Closely emulates behavior of pre-2.6 /dev/psaux device
18 #include <linux/wait.h>
36 wait_queue_head_t wait; member
55 static int serio_raw_fasync(int fd, struct file *file, int on) in serio_raw_fasync() argument
57 struct serio_raw_client *client = file->private_data; in serio_raw_fasync()
59 return fasync_helper(fd, file, on, &client->fasync); in serio_raw_fasync()
67 if (serio_raw->dev.minor == minor) in serio_raw_locate()
82 return -ENODEV; in serio_raw_open()
84 if (serio_raw->dead) in serio_raw_open()
85 return -ENODEV; in serio_raw_open()
89 return -ENOMEM; in serio_raw_open()
91 client->serio_raw = serio_raw; in serio_raw_open()
92 file->private_data = client; in serio_raw_open()
94 kref_get(&serio_raw->kref); in serio_raw_open()
96 scoped_guard(serio_pause_rx, serio_raw->serio) in serio_raw_open()
97 list_add_tail(&client->node, &serio_raw->client_list); in serio_raw_open()
102 return -EINTR; in serio_raw_open()
110 put_device(&serio_raw->serio->dev); in serio_raw_free()
116 struct serio_raw_client *client = file->private_data; in serio_raw_release()
117 struct serio_raw *serio_raw = client->serio_raw; in serio_raw_release()
119 scoped_guard(serio_pause_rx, serio_raw->serio) in serio_raw_release()
120 list_del(&client->node); in serio_raw_release()
124 kref_put(&serio_raw->kref, serio_raw_free); in serio_raw_release()
131 guard(serio_pause_rx)(serio_raw->serio); in serio_raw_fetch_byte()
133 if (serio_raw->head == serio_raw->tail) in serio_raw_fetch_byte()
136 *c = serio_raw->queue[serio_raw->tail]; in serio_raw_fetch_byte()
137 serio_raw->tail = (serio_raw->tail + 1) % SERIO_RAW_QUEUE_LEN; in serio_raw_fetch_byte()
145 struct serio_raw_client *client = file->private_data; in serio_raw_read()
146 struct serio_raw *serio_raw = client->serio_raw; in serio_raw_read()
148 ssize_t read = 0; in serio_raw_read() local
152 if (serio_raw->dead) in serio_raw_read()
153 return -ENODEV; in serio_raw_read()
155 if (serio_raw->head == serio_raw->tail && in serio_raw_read()
156 (file->f_flags & O_NONBLOCK)) in serio_raw_read()
157 return -EAGAIN; in serio_raw_read()
162 while (read < count && serio_raw_fetch_byte(serio_raw, &c)) { in serio_raw_read()
164 return -EFAULT; in serio_raw_read()
165 read++; in serio_raw_read()
168 if (read) in serio_raw_read()
171 if (!(file->f_flags & O_NONBLOCK)) { in serio_raw_read()
172 error = wait_event_interruptible(serio_raw->wait, in serio_raw_read()
173 serio_raw->head != serio_raw->tail || in serio_raw_read()
174 serio_raw->dead); in serio_raw_read()
180 return read; in serio_raw_read()
186 struct serio_raw_client *client = file->private_data; in serio_raw_write()
187 struct serio_raw *serio_raw = client->serio_raw; in serio_raw_write()
192 if (serio_raw->dead) in serio_raw_write()
193 return -ENODEV; in serio_raw_write()
198 while (count--) { in serio_raw_write()
200 return -EFAULT; in serio_raw_write()
202 if (serio_write(serio_raw->serio, c)) { in serio_raw_write()
204 return written ?: -EIO; in serio_raw_write()
213 return -EINTR; in serio_raw_write()
216 static __poll_t serio_raw_poll(struct file *file, poll_table *wait) in serio_raw_poll() argument
218 struct serio_raw_client *client = file->private_data; in serio_raw_poll()
219 struct serio_raw *serio_raw = client->serio_raw; in serio_raw_poll()
222 poll_wait(file, &serio_raw->wait, wait); in serio_raw_poll()
224 mask = serio_raw->dead ? EPOLLHUP | EPOLLERR : EPOLLOUT | EPOLLWRNORM; in serio_raw_poll()
225 if (serio_raw->head != serio_raw->tail) in serio_raw_poll()
235 .read = serio_raw_read,
252 unsigned int head = serio_raw->head; in serio_raw_interrupt()
254 /* we are holding serio->lock here so we are protected */ in serio_raw_interrupt()
255 serio_raw->queue[head] = data; in serio_raw_interrupt()
257 if (likely(head != serio_raw->tail)) { in serio_raw_interrupt()
258 serio_raw->head = head; in serio_raw_interrupt()
259 list_for_each_entry(client, &serio_raw->client_list, node) in serio_raw_interrupt()
260 kill_fasync(&client->fasync, SIGIO, POLL_IN); in serio_raw_interrupt()
261 wake_up_interruptible(&serio_raw->wait); in serio_raw_interrupt()
269 static atomic_t serio_raw_no = ATOMIC_INIT(-1); in serio_raw_connect()
275 dev_dbg(&serio->dev, "can't allocate memory for a device\n"); in serio_raw_connect()
276 return -ENOMEM; in serio_raw_connect()
279 snprintf(serio_raw->name, sizeof(serio_raw->name), in serio_raw_connect()
281 kref_init(&serio_raw->kref); in serio_raw_connect()
282 INIT_LIST_HEAD(&serio_raw->client_list); in serio_raw_connect()
283 init_waitqueue_head(&serio_raw->wait); in serio_raw_connect()
285 serio_raw->serio = serio; in serio_raw_connect()
286 get_device(&serio->dev); in serio_raw_connect()
298 list_add_tail(&serio_raw->node, &serio_raw_list); in serio_raw_connect()
301 serio_raw->dev.minor = PSMOUSE_MINOR; in serio_raw_connect()
302 serio_raw->dev.name = serio_raw->name; in serio_raw_connect()
303 serio_raw->dev.parent = &serio->dev; in serio_raw_connect()
304 serio_raw->dev.fops = &serio_raw_fops; in serio_raw_connect()
306 err = misc_register(&serio_raw->dev); in serio_raw_connect()
308 serio_raw->dev.minor = MISC_DYNAMIC_MINOR; in serio_raw_connect()
309 err = misc_register(&serio_raw->dev); in serio_raw_connect()
313 dev_err(&serio->dev, in serio_raw_connect()
315 serio->phys); in serio_raw_connect()
319 dev_info(&serio->dev, "raw access enabled on %s (%s, minor %d)\n", in serio_raw_connect()
320 serio->phys, serio_raw->name, serio_raw->dev.minor); in serio_raw_connect()
324 list_del_init(&serio_raw->node); in serio_raw_connect()
329 kref_put(&serio_raw->kref, serio_raw_free); in serio_raw_connect()
336 struct serio_driver *drv = serio->drv; in serio_raw_reconnect()
339 dev_dbg(&serio->dev, in serio_raw_reconnect()
341 return -1; in serio_raw_reconnect()
359 scoped_guard(serio_pause_rx, serio_raw->serio) { in serio_raw_hangup()
360 list_for_each_entry(client, &serio_raw->client_list, node) in serio_raw_hangup()
361 kill_fasync(&client->fasync, SIGIO, POLL_HUP); in serio_raw_hangup()
364 wake_up_interruptible(&serio_raw->wait); in serio_raw_hangup()
372 misc_deregister(&serio_raw->dev); in serio_raw_disconnect()
375 serio_raw->dead = true; in serio_raw_disconnect()
376 list_del_init(&serio_raw->node); in serio_raw_disconnect()
382 kref_put(&serio_raw->kref, serio_raw_free); in serio_raw_disconnect()