Lines Matching +full:console +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0+
12 #include <linux/console.h>
46 * native transfer size. We could make them selectable in the
61 static atomic_t hvc_needs_init __read_mostly = ATOMIC_INIT(-1);
79 * This value is used to assign a tty->index value to a hvc_struct based
81 * a console candidate registered with hvc_instantiate().
83 static int last_hvc = -1;
98 spin_lock_irqsave(&hp->lock, flags); in hvc_get_by_index()
99 if (hp->index == index) { in hvc_get_by_index()
100 tty_port_get(&hp->port); in hvc_get_by_index()
101 spin_unlock_irqrestore(&hp->lock, flags); in hvc_get_by_index()
105 spin_unlock_irqrestore(&hp->lock, flags); in hvc_get_by_index()
118 if (ops->flush) in __hvc_flush()
119 return ops->flush(vtermno, wait); in __hvc_flush()
129 * Wait for the console to flush before writing more to it. This sleeps.
133 return __hvc_flush(hp->ops, hp->vtermno, true); in hvc_flush()
137 * Initial console vtermnos for console API usage prior to full console
139 * console interfaces but can still be used as a tty device. This has to be
140 * static because kmalloc will not work during early console init.
144 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
147 * Console APIs, NOT TTY. These APIs are available immediately when
151 static void hvc_console_print(struct console *co, const char *b, in hvc_console_print()
156 int r, donecr = 0, index = co->index; in hvc_console_print()
158 /* Console access attempt outside of acceptable console range. */ in hvc_console_print()
162 /* This console adapter was removed so it is not usable. */ in hvc_console_print()
163 if (vtermnos[index] == -1) in hvc_console_print()
174 --count; in hvc_console_print()
177 r = cons_ops[index]->put_chars(vtermnos[index], c, i); in hvc_console_print()
180 * but spin in case of -EAGAIN */ in hvc_console_print()
181 if (r != -EAGAIN) { in hvc_console_print()
188 i -= r; in hvc_console_print()
197 static struct tty_driver *hvc_console_device(struct console *c, int *index) in hvc_console_device()
199 if (vtermnos[c->index] == -1) in hvc_console_device()
202 *index = c->index; in hvc_console_device()
206 static int hvc_console_setup(struct console *co, char *options) in hvc_console_setup()
208 if (co->index < 0 || co->index >= MAX_NR_HVC_CONSOLES) in hvc_console_setup()
209 return -ENODEV; in hvc_console_setup()
211 if (vtermnos[co->index] == -1) in hvc_console_setup()
212 return -ENODEV; in hvc_console_setup()
217 static struct console hvc_console = {
223 .index = -1,
227 * Early console initialization. Precedes driver initialization.
230 * -- index will remain -1
232 * -- index will be set to 0, then we will fail setup.
234 * -- index will be set to user specified driver, and we will fail
236 * -- if the user didn't specify a driver then the console will match
256 spin_lock_irqsave(&hp->lock, flags); in hvc_port_destruct()
257 list_del(&(hp->next)); in hvc_port_destruct()
258 spin_unlock_irqrestore(&hp->lock, flags); in hvc_port_destruct()
280 * hvc_instantiate() is an early console discovery method which locates
283 * appear after early console init.
290 return -1; in hvc_instantiate()
292 if (vtermnos[index] != -1) in hvc_instantiate()
293 return -1; in hvc_instantiate()
298 tty_port_put(&hp->port); in hvc_instantiate()
299 return -1; in hvc_instantiate()
305 /* check if we need to re-register the kernel console */ in hvc_instantiate()
331 hp = hvc_get_by_index(tty->index); in hvc_install()
333 return -ENODEV; in hvc_install()
335 tty->driver_data = hp; in hvc_install()
337 rc = tty_port_install(&hp->port, driver, tty); in hvc_install()
339 tty_port_put(&hp->port); in hvc_install()
349 struct hvc_struct *hp = tty->driver_data; in hvc_open()
353 spin_lock_irqsave(&hp->port.lock, flags); in hvc_open()
355 if (hp->port.count++ > 0) { in hvc_open()
356 spin_unlock_irqrestore(&hp->port.lock, flags); in hvc_open()
360 spin_unlock_irqrestore(&hp->port.lock, flags); in hvc_open()
362 tty_port_tty_set(&hp->port, tty); in hvc_open()
364 if (hp->ops->notifier_add) in hvc_open()
365 rc = hp->ops->notifier_add(hp, hp->data); in hvc_open()
378 if (hp->ops->dtr_rts) in hvc_open()
379 hp->ops->dtr_rts(hp, 1); in hvc_open()
380 tty_port_set_initialized(&hp->port, true); in hvc_open()
391 struct hvc_struct *hp = tty->driver_data; in hvc_close()
397 spin_lock_irqsave(&hp->port.lock, flags); in hvc_close()
399 if (--hp->port.count == 0) { in hvc_close()
400 spin_unlock_irqrestore(&hp->port.lock, flags); in hvc_close()
402 tty_port_tty_set(&hp->port, NULL); in hvc_close()
404 if (!tty_port_initialized(&hp->port)) in hvc_close()
408 if (hp->ops->dtr_rts) in hvc_close()
409 hp->ops->dtr_rts(hp, 0); in hvc_close()
411 if (hp->ops->notifier_del) in hvc_close()
412 hp->ops->notifier_del(hp, hp->data); in hvc_close()
415 cancel_work_sync(&hp->tty_resize); in hvc_close()
423 tty_port_set_initialized(&hp->port, false); in hvc_close()
425 if (hp->port.count < 0) in hvc_close()
427 hp->vtermno, hp->port.count); in hvc_close()
428 spin_unlock_irqrestore(&hp->port.lock, flags); in hvc_close()
434 struct hvc_struct *hp = tty->driver_data; in hvc_cleanup()
436 tty_port_put(&hp->port); in hvc_cleanup()
441 struct hvc_struct *hp = tty->driver_data; in hvc_hangup()
448 cancel_work_sync(&hp->tty_resize); in hvc_hangup()
450 spin_lock_irqsave(&hp->port.lock, flags); in hvc_hangup()
454 * open->hangup case this can be called after the final close so prevent in hvc_hangup()
457 if (hp->port.count <= 0) { in hvc_hangup()
458 spin_unlock_irqrestore(&hp->port.lock, flags); in hvc_hangup()
462 hp->port.count = 0; in hvc_hangup()
463 spin_unlock_irqrestore(&hp->port.lock, flags); in hvc_hangup()
464 tty_port_tty_set(&hp->port, NULL); in hvc_hangup()
466 hp->n_outbuf = 0; in hvc_hangup()
468 if (hp->ops->notifier_hangup) in hvc_hangup()
469 hp->ops->notifier_hangup(hp, hp->data); in hvc_hangup()
474 * on a blocked hypervisor. Call this function with hp->lock held.
480 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf); in hvc_push()
482 if (n == 0 || n == -EAGAIN) { in hvc_push()
483 hp->do_wakeup = 1; in hvc_push()
488 hp->n_outbuf = 0; in hvc_push()
490 hp->n_outbuf -= n; in hvc_push()
491 if (hp->n_outbuf > 0) in hvc_push()
492 memmove(hp->outbuf, hp->outbuf + n, hp->n_outbuf); in hvc_push()
494 hp->do_wakeup = 1; in hvc_push()
501 struct hvc_struct *hp = tty->driver_data; in hvc_write()
507 return -EPIPE; in hvc_write()
510 if (hp->port.count <= 0) in hvc_write()
511 return -EIO; in hvc_write()
516 spin_lock_irqsave(&hp->lock, flags); in hvc_write()
518 rsize = hp->outbuf_size - hp->n_outbuf; in hvc_write()
523 memcpy(hp->outbuf + hp->n_outbuf, buf, rsize); in hvc_write()
524 count -= rsize; in hvc_write()
526 hp->n_outbuf += rsize; in hvc_write()
530 if (hp->n_outbuf > 0) in hvc_write()
533 spin_unlock_irqrestore(&hp->lock, flags); in hvc_write()
539 if (hp->n_outbuf > 0) in hvc_write()
548 if (hp->n_outbuf) in hvc_write()
555 * hvc_set_winsz() - Resize the hvc tty terminal window.
561 * Locking: hp->lock
572 tty = tty_port_tty_get(&hp->port); in hvc_set_winsz()
576 spin_lock_irqsave(&hp->lock, hvc_flags); in hvc_set_winsz()
577 ws = hp->ws; in hvc_set_winsz()
578 spin_unlock_irqrestore(&hp->lock, hvc_flags); in hvc_set_winsz()
591 struct hvc_struct *hp = tty->driver_data; in hvc_write_room()
596 return hp->outbuf_size - hp->n_outbuf; in hvc_write_room()
601 struct hvc_struct *hp = tty->driver_data; in hvc_chars_in_buffer()
605 return hp->n_outbuf; in hvc_chars_in_buffer()
610 * and during console activity we will use a default MIN_TIMEOUT of 10. When
611 * the console is idle, we increase the timeout value on each pass through
613 * one second) delay on the console before the console responds to input when
621 * Maximum number of bytes to get from the console driver if hvc_poll is
624 * console with the OPAL driver that results in about 0.25ms interrupts off
641 spin_lock_irqsave(&hp->lock, flags); in __hvc_poll()
644 if (hp->n_outbuf > 0) in __hvc_poll()
648 if (hp->n_outbuf > 0) { in __hvc_poll()
655 spin_unlock_irqrestore(&hp->lock, flags); in __hvc_poll()
657 spin_lock_irqsave(&hp->lock, flags); in __hvc_poll()
661 tty = tty_port_tty_get(&hp->port); in __hvc_poll()
672 if (!hp->irq_requested) in __hvc_poll()
677 count = tty_buffer_request_room(&hp->port, N_INBUF); in __hvc_poll()
685 n = hp->ops->get_chars(hp->vtermno, buf, count); in __hvc_poll()
688 if (n == -EPIPE) { in __hvc_poll()
689 spin_unlock_irqrestore(&hp->lock, flags); in __hvc_poll()
691 spin_lock_irqsave(&hp->lock, flags); in __hvc_poll()
692 } else if ( n == -EAGAIN ) { in __hvc_poll()
694 * Some back-ends can only ensure a certain min in __hvc_poll()
705 if (hp->index == hvc_console.index) { in __hvc_poll()
721 tty_insert_flip_char(&hp->port, buf[i], 0); in __hvc_poll()
727 spin_unlock_irqrestore(&hp->lock, flags); in __hvc_poll()
729 spin_lock_irqsave(&hp->lock, flags); in __hvc_poll()
743 if (hp->do_wakeup) { in __hvc_poll()
744 hp->do_wakeup = 0; in __hvc_poll()
748 spin_unlock_irqrestore(&hp->lock, flags); in __hvc_poll()
755 tty_flip_buffer_push(&hp->port); in __hvc_poll()
769 * __hvc_resize() - Update terminal window size information.
770 * @hp: HVC console pointer
771 * @ws: Terminal window size structure
773 * Stores the specified window size information in the hvc structure of @hp.
776 * Locking: Locking free; the function MUST be called holding hp->lock
780 hp->ws = ws; in __hvc_resize()
781 schedule_work(&hp->tty_resize); in __hvc_resize()
787 * calling hvc_poll() who determines whether a console adapter support
838 struct hvc_struct *hp = tty->driver_data; in hvc_tiocmget()
840 if (!hp || !hp->ops->tiocmget) in hvc_tiocmget()
841 return -EINVAL; in hvc_tiocmget()
842 return hp->ops->tiocmget(hp); in hvc_tiocmget()
848 struct hvc_struct *hp = tty->driver_data; in hvc_tiocmset()
850 if (!hp || !hp->ops->tiocmset) in hvc_tiocmset()
851 return -EINVAL; in hvc_tiocmset()
852 return hp->ops->tiocmset(hp, set, clear); in hvc_tiocmset()
863 struct tty_struct *tty = driver->ttys[0]; in hvc_poll_get_char()
864 struct hvc_struct *hp = tty->driver_data; in hvc_poll_get_char()
868 n = hp->ops->get_chars(hp->vtermno, &ch, 1); in hvc_poll_get_char()
878 struct tty_struct *tty = driver->ttys[0]; in hvc_poll_put_char()
879 struct hvc_struct *hp = tty->driver_data; in hvc_poll_put_char()
883 n = hp->ops->put_chars(hp->vtermno, &ch, 1); in hvc_poll_put_char()
928 return ERR_PTR(-ENOMEM); in hvc_alloc()
930 hp->vtermno = vtermno; in hvc_alloc()
931 hp->data = data; in hvc_alloc()
932 hp->ops = ops; in hvc_alloc()
933 hp->outbuf_size = outbuf_size; in hvc_alloc()
934 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; in hvc_alloc()
936 tty_port_init(&hp->port); in hvc_alloc()
937 hp->port.ops = &hvc_port_ops; in hvc_alloc()
939 INIT_WORK(&hp->tty_resize, hvc_set_winsz); in hvc_alloc()
940 spin_lock_init(&hp->lock); in hvc_alloc()
945 * see if this vterm id matches one registered for console. in hvc_alloc()
948 if (vtermnos[i] == hp->vtermno && in hvc_alloc()
949 cons_ops[i] == hp->ops) in hvc_alloc()
954 /* find 'empty' slot for console */ in hvc_alloc()
955 for (i = 0; i < MAX_NR_HVC_CONSOLES && vtermnos[i] != -1; i++) { in hvc_alloc()
963 hp->index = i; in hvc_alloc()
969 list_add_tail(&(hp->next), &hvc_structs); in hvc_alloc()
972 /* check if we need to re-register the kernel console */ in hvc_alloc()
984 tty = tty_port_tty_get(&hp->port); in hvc_remove()
987 spin_lock_irqsave(&hp->lock, flags); in hvc_remove()
988 if (hp->index < MAX_NR_HVC_CONSOLES) { in hvc_remove()
989 vtermnos[hp->index] = -1; in hvc_remove()
990 cons_ops[hp->index] = NULL; in hvc_remove()
993 /* Don't whack hp->irq because tty_hangup() will need to free the irq. */ in hvc_remove()
995 spin_unlock_irqrestore(&hp->lock, flags); in hvc_remove()
1004 tty_port_put(&hp->port); in hvc_remove()
1031 drv->driver_name = "hvc"; in hvc_init()
1032 drv->name = "hvc"; in hvc_init()
1033 drv->major = HVC_MAJOR; in hvc_init()
1034 drv->minor_start = HVC_MINOR; in hvc_init()
1035 drv->type = TTY_DRIVER_TYPE_SYSTEM; in hvc_init()
1036 drv->init_termios = tty_std_termios; in hvc_init()
1043 printk(KERN_ERR "Couldn't create kthread for console.\n"); in hvc_init()
1050 printk(KERN_ERR "Couldn't register hvc console driver\n"); in hvc_init()