1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
4 * Copyright (C) 2001 Paul Mackerras <paulus@au.ibm.com>, IBM
5 * Copyright (C) 2004 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
6 * Copyright (C) 2004 IBM Corporation
8 * Additional Author(s):
9 * Ryan S. Arnold <rsa@us.ibm.com>
12 #include <linux/console.h>
13 #include <linux/cpumask.h>
14 #include <linux/init.h>
15 #include <linux/kbd_kern.h>
16 #include <linux/kernel.h>
17 #include <linux/kthread.h>
18 #include <linux/list.h>
19 #include <linux/major.h>
20 #include <linux/atomic.h>
21 #include <linux/sysrq.h>
22 #include <linux/tty.h>
23 #include <linux/tty_flip.h>
24 #include <linux/sched.h>
25 #include <linux/spinlock.h>
26 #include <linux/delay.h>
27 #include <linux/freezer.h>
28 #include <linux/slab.h>
29 #include <linux/serial_core.h>
31 #include <linux/uaccess.h>
33 #include "hvc_console.h"
39 * Wait this long per iteration while trying to push buffered data to the
40 * hypervisor before allowing the tty to complete a close operation.
42 #define HVC_CLOSE_WAIT (HZ/100) /* 1/10 of a second */
44 static struct tty_driver *hvc_driver;
45 static struct task_struct *hvc_task;
47 /* Picks up late kicks after list walk but before schedule() */
48 static int hvc_kicked;
50 /* hvc_init is triggered from hvc_alloc, i.e. only when actually used */
51 static atomic_t hvc_needs_init __read_mostly = ATOMIC_INIT(-1);
53 static int hvc_init(void);
55 #ifdef CONFIG_MAGIC_SYSRQ
56 static int sysrq_pressed;
59 /* dynamic list of hvc_struct instances */
60 static LIST_HEAD(hvc_structs);
63 * Protect the list of hvc_struct instances from inserts and removals during
66 static DEFINE_MUTEX(hvc_structs_mutex);
69 * This value is used to assign a tty->index value to a hvc_struct based
70 * upon order of exposure via hvc_probe(), when we can not match it to
71 * a console candidate registered with hvc_instantiate().
73 static int last_hvc = -1;
76 * Do not call this function with either the hvc_structs_mutex or the hvc_struct
77 * lock held. If successful, this function increments the kref reference
78 * count against the target hvc_struct so it should be released when finished.
80 static struct hvc_struct *hvc_get_by_index(int index)
82 struct hvc_struct *hp;
85 mutex_lock(&hvc_structs_mutex);
87 list_for_each_entry(hp, &hvc_structs, next) {
88 spin_lock_irqsave(&hp->lock, flags);
89 if (hp->index == index) {
90 tty_port_get(&hp->port);
91 spin_unlock_irqrestore(&hp->lock, flags);
92 mutex_unlock(&hvc_structs_mutex);
95 spin_unlock_irqrestore(&hp->lock, flags);
98 mutex_unlock(&hvc_structs_mutex);
103 static int __hvc_flush(const struct hv_ops *ops, uint32_t vtermno, bool wait)
109 return ops->flush(vtermno, wait);
113 static int hvc_console_flush(const struct hv_ops *ops, uint32_t vtermno)
115 return __hvc_flush(ops, vtermno, false);
119 * Wait for the console to flush before writing more to it. This sleeps.
121 static int hvc_flush(struct hvc_struct *hp)
123 return __hvc_flush(hp->ops, hp->vtermno, true);
127 * Initial console vtermnos for console API usage prior to full console
128 * initialization. Any vty adapter outside this range will not have usable
129 * console interfaces but can still be used as a tty device. This has to be
130 * static because kmalloc will not work during early console init.
132 static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
133 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
134 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
135 static struct hvc_struct *cons_hvcs[MAX_NR_HVC_CONSOLES];
138 * Console APIs, NOT TTY. These APIs are available immediately when
139 * hvc_console_setup() finds adapters.
142 static void hvc_console_print(struct console *co, const char *b,
146 unsigned i = 0, n = 0;
147 int r, donecr = 0, index = co->index;
149 struct hvc_struct *hp;
151 /* Console access attempt outside of acceptable console range. */
152 if (index >= MAX_NR_HVC_CONSOLES)
155 /* This console adapter was removed so it is not usable. */
156 if (vtermnos[index] == -1)
159 hp = cons_hvcs[index];
165 spin_lock_irqsave(&hp->cons_outbuf_lock, flags);
166 while (count > 0 || i > 0) {
167 if (count > 0 && i < sizeof(c)) {
168 if (b[n] == '\n' && !donecr) {
177 r = cons_ops[index]->put_chars(vtermnos[index], c, i);
179 /* throw away characters on error
180 * but spin in case of -EAGAIN */
184 hvc_console_flush(cons_ops[index],
194 spin_unlock_irqrestore(&hp->cons_outbuf_lock, flags);
195 hvc_console_flush(cons_ops[index], vtermnos[index]);
198 static struct tty_driver *hvc_console_device(struct console *c, int *index)
200 if (vtermnos[c->index] == -1)
207 static int hvc_console_setup(struct console *co, char *options)
209 if (co->index < 0 || co->index >= MAX_NR_HVC_CONSOLES)
212 if (vtermnos[co->index] == -1)
218 static struct console hvc_console = {
220 .write = hvc_console_print,
221 .device = hvc_console_device,
222 .setup = hvc_console_setup,
223 .flags = CON_PRINTBUFFER,
228 * Early console initialization. Precedes driver initialization.
230 * (1) we are first, and the user specified another driver
231 * -- index will remain -1
232 * (2) we are first and the user specified no driver
233 * -- index will be set to 0, then we will fail setup.
234 * (3) we are first and the user specified our driver
235 * -- index will be set to user specified driver, and we will fail
236 * (4) we are after driver, and this initcall will register us
237 * -- if the user didn't specify a driver then the console will match
239 * Note that for cases 2 and 3, we will match later when the io driver
240 * calls hvc_instantiate() and call register again.
242 static int __init hvc_console_init(void)
244 register_console(&hvc_console);
247 console_initcall(hvc_console_init);
249 /* callback when the kboject ref count reaches zero. */
250 static void hvc_port_destruct(struct tty_port *port)
252 struct hvc_struct *hp = container_of(port, struct hvc_struct, port);
255 mutex_lock(&hvc_structs_mutex);
257 spin_lock_irqsave(&hp->lock, flags);
258 list_del(&(hp->next));
259 spin_unlock_irqrestore(&hp->lock, flags);
261 mutex_unlock(&hvc_structs_mutex);
266 static void hvc_check_console(int index)
268 /* Already enabled, bail out */
269 if (hvc_console.flags & CON_ENABLED)
272 /* If this index is what the user requested, then register
273 * now (setup won't fail at this point). It's ok to just
274 * call register again if previously .setup failed.
276 if (index == hvc_console.index)
277 register_console(&hvc_console);
281 * hvc_instantiate() is an early console discovery method which locates
282 * consoles * prior to the vio subsystem discovering them. Hotplugged
283 * vty adapters do NOT get an hvc_instantiate() callback since they
284 * appear after early console init.
286 int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
288 struct hvc_struct *hp;
290 if (index < 0 || index >= MAX_NR_HVC_CONSOLES)
293 if (vtermnos[index] != -1)
296 /* make sure no tty has been registered in this index */
297 hp = hvc_get_by_index(index);
299 tty_port_put(&hp->port);
303 vtermnos[index] = vtermno;
304 cons_ops[index] = ops;
306 /* check if we need to re-register the kernel console */
307 hvc_check_console(index);
311 EXPORT_SYMBOL_GPL(hvc_instantiate);
313 /* Wake the sleeping khvcd */
317 wake_up_process(hvc_task);
319 EXPORT_SYMBOL_GPL(hvc_kick);
321 static void hvc_unthrottle(struct tty_struct *tty)
326 static int hvc_install(struct tty_driver *driver, struct tty_struct *tty)
328 struct hvc_struct *hp;
331 /* Auto increments kref reference if found. */
332 hp = hvc_get_by_index(tty->index);
336 tty->driver_data = hp;
338 rc = tty_port_install(&hp->port, driver, tty);
340 tty_port_put(&hp->port);
345 * The TTY interface won't be used until after the vio layer has exposed the vty
346 * adapter to the kernel.
348 static int hvc_open(struct tty_struct *tty, struct file * filp)
350 struct hvc_struct *hp = tty->driver_data;
354 spin_lock_irqsave(&hp->port.lock, flags);
355 /* Check and then increment for fast path open. */
356 if (hp->port.count++ > 0) {
357 spin_unlock_irqrestore(&hp->port.lock, flags);
360 } /* else count == 0 */
361 spin_unlock_irqrestore(&hp->port.lock, flags);
363 tty_port_tty_set(&hp->port, tty);
365 if (hp->ops->notifier_add)
366 rc = hp->ops->notifier_add(hp, hp->data);
369 * If the notifier fails we return an error. The tty layer
370 * will call hvc_close() after a failed open but we don't want to clean
371 * up there so we'll clean up here and clear out the previously set
372 * tty fields and return the kref reference.
375 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);
377 /* We are ready... raise DTR/RTS */
379 if (hp->ops->dtr_rts)
380 hp->ops->dtr_rts(hp, 1);
381 tty_port_set_initialized(&hp->port, true);
384 /* Force wakeup of the polling thread */
390 static void hvc_close(struct tty_struct *tty, struct file * filp)
392 struct hvc_struct *hp = tty->driver_data;
395 if (tty_hung_up_p(filp))
398 spin_lock_irqsave(&hp->port.lock, flags);
400 if (--hp->port.count == 0) {
401 spin_unlock_irqrestore(&hp->port.lock, flags);
402 /* We are done with the tty pointer now. */
403 tty_port_tty_set(&hp->port, NULL);
405 if (!tty_port_initialized(&hp->port))
409 if (hp->ops->dtr_rts)
410 hp->ops->dtr_rts(hp, 0);
412 if (hp->ops->notifier_del)
413 hp->ops->notifier_del(hp, hp->data);
415 /* cancel pending tty resize work */
416 cancel_work_sync(&hp->tty_resize);
419 * Chain calls chars_in_buffer() and returns immediately if
420 * there is no buffered data otherwise sleeps on a wait queue
421 * waking periodically to check chars_in_buffer().
423 tty_wait_until_sent(tty, HVC_CLOSE_WAIT);
424 tty_port_set_initialized(&hp->port, false);
426 if (hp->port.count < 0)
427 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
428 hp->vtermno, hp->port.count);
429 spin_unlock_irqrestore(&hp->port.lock, flags);
433 static void hvc_cleanup(struct tty_struct *tty)
435 struct hvc_struct *hp = tty->driver_data;
437 tty_port_put(&hp->port);
440 static void hvc_hangup(struct tty_struct *tty)
442 struct hvc_struct *hp = tty->driver_data;
448 /* cancel pending tty resize work */
449 cancel_work_sync(&hp->tty_resize);
451 spin_lock_irqsave(&hp->port.lock, flags);
454 * The N_TTY line discipline has problems such that in a close vs
455 * open->hangup case this can be called after the final close so prevent
456 * that from happening for now.
458 if (hp->port.count <= 0) {
459 spin_unlock_irqrestore(&hp->port.lock, flags);
464 spin_unlock_irqrestore(&hp->port.lock, flags);
465 tty_port_tty_set(&hp->port, NULL);
469 if (hp->ops->notifier_hangup)
470 hp->ops->notifier_hangup(hp, hp->data);
474 * Push buffered characters whether they were just recently buffered or waiting
475 * on a blocked hypervisor. Call this function with hp->lock held.
477 static int hvc_push(struct hvc_struct *hp)
481 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
483 if (n == 0 || n == -EAGAIN) {
487 /* throw away output on error; this happens when
488 there is no session connected to the vterm. */
492 if (hp->n_outbuf > 0)
493 memmove(hp->outbuf, hp->outbuf + n, hp->n_outbuf);
500 static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count)
502 struct hvc_struct *hp = tty->driver_data;
504 int rsize, written = 0;
506 /* This write was probably executed during a tty close. */
510 /* FIXME what's this (unprotected) check for? */
511 if (hp->port.count <= 0)
517 spin_lock_irqsave(&hp->lock, flags);
519 rsize = hp->outbuf_size - hp->n_outbuf;
524 memcpy(hp->outbuf + hp->n_outbuf, buf, rsize);
527 hp->n_outbuf += rsize;
531 if (hp->n_outbuf > 0)
534 spin_unlock_irqrestore(&hp->lock, flags);
540 if (hp->n_outbuf > 0)
547 * Racy, but harmless, kick thread if there is still pending data.
556 * hvc_set_winsz() - Resize the hvc tty terminal window.
557 * @work: work structure.
559 * The routine shall not be called within an atomic context because it
564 static void hvc_set_winsz(struct work_struct *work)
566 struct hvc_struct *hp;
567 unsigned long hvc_flags;
568 struct tty_struct *tty;
571 hp = container_of(work, struct hvc_struct, tty_resize);
573 tty = tty_port_tty_get(&hp->port);
577 spin_lock_irqsave(&hp->lock, hvc_flags);
579 spin_unlock_irqrestore(&hp->lock, hvc_flags);
581 tty_do_resize(tty, &ws);
586 * This is actually a contract between the driver and the tty layer outlining
587 * how much write room the driver can guarantee will be sent OR BUFFERED. This
588 * driver MUST honor the return value.
590 static unsigned int hvc_write_room(struct tty_struct *tty)
592 struct hvc_struct *hp = tty->driver_data;
597 return hp->outbuf_size - hp->n_outbuf;
600 static unsigned int hvc_chars_in_buffer(struct tty_struct *tty)
602 struct hvc_struct *hp = tty->driver_data;
610 * timeout will vary between the MIN and MAX values defined here. By default
611 * and during console activity we will use a default MIN_TIMEOUT of 10. When
612 * the console is idle, we increase the timeout value on each pass through
613 * msleep until we reach the max. This may be noticeable as a brief (average
614 * one second) delay on the console before the console responds to input when
615 * there has been no input for some time.
617 #define MIN_TIMEOUT (10)
618 #define MAX_TIMEOUT (2000)
619 static u32 timeout = MIN_TIMEOUT;
622 * Maximum number of bytes to get from the console driver if hvc_poll is
623 * called from driver (and can't sleep). Any more than this and we break
624 * and start polling with khvcd. This value was derived from an OpenBMC
625 * console with the OPAL driver that results in about 0.25ms interrupts off
628 #define HVC_ATOMIC_READ_MAX 128
630 #define HVC_POLL_READ 0x00000001
631 #define HVC_POLL_WRITE 0x00000002
633 static int __hvc_poll(struct hvc_struct *hp, bool may_sleep)
635 struct tty_struct *tty;
636 int i, n, count, poll_mask = 0;
637 char buf[N_INBUF] __ALIGNED__;
640 int written_total = 0;
642 spin_lock_irqsave(&hp->lock, flags);
644 /* Push pending writes */
645 if (hp->n_outbuf > 0)
646 written_total = hvc_push(hp);
648 /* Reschedule us if still some write pending */
649 if (hp->n_outbuf > 0) {
650 poll_mask |= HVC_POLL_WRITE;
651 /* If hvc_push() was not able to write, sleep a few msecs */
652 timeout = (written_total) ? 0 : MIN_TIMEOUT;
656 spin_unlock_irqrestore(&hp->lock, flags);
658 spin_lock_irqsave(&hp->lock, flags);
661 /* No tty attached, just skip */
662 tty = tty_port_tty_get(&hp->port);
666 /* Now check if we can get data (are we throttled ?) */
667 if (tty_throttled(tty))
670 /* If we aren't notifier driven and aren't throttled, we always
671 * request a reschedule
673 if (!hp->irq_requested)
674 poll_mask |= HVC_POLL_READ;
677 /* Read data if any */
678 count = tty_buffer_request_room(&hp->port, N_INBUF);
680 /* If flip is full, just reschedule a later read */
682 poll_mask |= HVC_POLL_READ;
686 n = hp->ops->get_chars(hp->vtermno, buf, count);
688 /* Hangup the tty when disconnected from host */
690 spin_unlock_irqrestore(&hp->lock, flags);
692 spin_lock_irqsave(&hp->lock, flags);
693 } else if ( n == -EAGAIN ) {
695 * Some back-ends can only ensure a certain min
696 * num of bytes read, which may be > 'count'.
697 * Let the tty clear the flip buff to make room.
699 poll_mask |= HVC_POLL_READ;
704 for (i = 0; i < n; ++i) {
705 #ifdef CONFIG_MAGIC_SYSRQ
706 if (hp->index == hvc_console.index) {
707 /* Handle the SysRq Hack */
708 /* XXX should support a sequence */
709 if (buf[i] == '\x0f') { /* ^O */
710 /* if ^O is pressed again, reset
711 * sysrq_pressed and flip ^O char */
712 sysrq_pressed = !sysrq_pressed;
715 } else if (sysrq_pressed) {
716 handle_sysrq(buf[i]);
721 #endif /* CONFIG_MAGIC_SYSRQ */
722 tty_insert_flip_char(&hp->port, buf[i], 0);
727 /* Keep going until the flip is full */
728 spin_unlock_irqrestore(&hp->lock, flags);
730 spin_lock_irqsave(&hp->lock, flags);
732 } else if (read_total < HVC_ATOMIC_READ_MAX) {
733 /* Break and defer if it's a large read in atomic */
738 * Latency break, schedule another poll immediately.
740 poll_mask |= HVC_POLL_READ;
743 /* Wakeup write queue if necessary */
749 spin_unlock_irqrestore(&hp->lock, flags);
752 /* Activity is occurring, so reset the polling backoff value to
753 a minimum for performance. */
754 timeout = MIN_TIMEOUT;
756 tty_flip_buffer_push(&hp->port);
763 int hvc_poll(struct hvc_struct *hp)
765 return __hvc_poll(hp, false);
767 EXPORT_SYMBOL_GPL(hvc_poll);
770 * __hvc_resize() - Update terminal window size information.
771 * @hp: HVC console pointer
772 * @ws: Terminal window size structure
774 * Stores the specified window size information in the hvc structure of @hp.
775 * The function schedule the tty resize update.
777 * Locking: Locking free; the function MUST be called holding hp->lock
779 void __hvc_resize(struct hvc_struct *hp, struct winsize ws)
782 schedule_work(&hp->tty_resize);
784 EXPORT_SYMBOL_GPL(__hvc_resize);
787 * This kthread is either polling or interrupt driven. This is determined by
788 * calling hvc_poll() who determines whether a console adapter support
791 static int khvcd(void *unused)
794 struct hvc_struct *hp;
802 if (!cpus_are_in_xmon()) {
803 mutex_lock(&hvc_structs_mutex);
804 list_for_each_entry(hp, &hvc_structs, next) {
805 poll_mask |= __hvc_poll(hp, true);
808 mutex_unlock(&hvc_structs_mutex);
810 poll_mask |= HVC_POLL_READ;
813 set_current_state(TASK_INTERRUPTIBLE);
818 unsigned long j_timeout;
820 if (timeout < MAX_TIMEOUT)
821 timeout += (timeout >> 6) + 1;
824 * We don't use msleep_interruptible otherwise
825 * "kick" will fail to wake us up
827 j_timeout = msecs_to_jiffies(timeout) + 1;
828 schedule_timeout_interruptible(j_timeout);
831 __set_current_state(TASK_RUNNING);
832 } while (!kthread_should_stop());
837 static int hvc_tiocmget(struct tty_struct *tty)
839 struct hvc_struct *hp = tty->driver_data;
841 if (!hp || !hp->ops->tiocmget)
843 return hp->ops->tiocmget(hp);
846 static int hvc_tiocmset(struct tty_struct *tty,
847 unsigned int set, unsigned int clear)
849 struct hvc_struct *hp = tty->driver_data;
851 if (!hp || !hp->ops->tiocmset)
853 return hp->ops->tiocmset(hp, set, clear);
856 #ifdef CONFIG_CONSOLE_POLL
857 static int hvc_poll_init(struct tty_driver *driver, int line, char *options)
862 static int hvc_poll_get_char(struct tty_driver *driver, int line)
864 struct tty_struct *tty = driver->ttys[0];
865 struct hvc_struct *hp = tty->driver_data;
869 n = hp->ops->get_chars(hp->vtermno, &ch, 1);
877 static void hvc_poll_put_char(struct tty_driver *driver, int line, char ch)
879 struct tty_struct *tty = driver->ttys[0];
880 struct hvc_struct *hp = tty->driver_data;
885 spin_lock_irqsave(&hp->cons_outbuf_lock, flags);
886 hp->cons_outbuf[0] = ch;
887 n = hp->ops->put_chars(hp->vtermno, &hp->cons_outbuf[0], 1);
888 spin_unlock_irqrestore(&hp->cons_outbuf_lock, flags);
893 static const struct tty_operations hvc_ops = {
894 .install = hvc_install,
897 .cleanup = hvc_cleanup,
899 .hangup = hvc_hangup,
900 .unthrottle = hvc_unthrottle,
901 .write_room = hvc_write_room,
902 .chars_in_buffer = hvc_chars_in_buffer,
903 .tiocmget = hvc_tiocmget,
904 .tiocmset = hvc_tiocmset,
905 #ifdef CONFIG_CONSOLE_POLL
906 .poll_init = hvc_poll_init,
907 .poll_get_char = hvc_poll_get_char,
908 .poll_put_char = hvc_poll_put_char,
912 static const struct tty_port_operations hvc_port_ops = {
913 .destruct = hvc_port_destruct,
916 struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
917 const struct hv_ops *ops,
920 struct hvc_struct *hp;
923 /* We wait until a driver actually comes along */
924 if (atomic_inc_not_zero(&hvc_needs_init)) {
925 int err = hvc_init();
930 hp = kzalloc(struct_size(hp, outbuf, outbuf_size), GFP_KERNEL);
932 return ERR_PTR(-ENOMEM);
934 hp->vtermno = vtermno;
937 hp->outbuf_size = outbuf_size;
939 tty_port_init(&hp->port);
940 hp->port.ops = &hvc_port_ops;
942 INIT_WORK(&hp->tty_resize, hvc_set_winsz);
943 spin_lock_init(&hp->lock);
944 spin_lock_init(&hp->cons_outbuf_lock);
945 mutex_lock(&hvc_structs_mutex);
949 * see if this vterm id matches one registered for console.
951 for (i=0; i < MAX_NR_HVC_CONSOLES; i++)
952 if (vtermnos[i] == hp->vtermno &&
953 cons_ops[i] == hp->ops)
956 if (i >= MAX_NR_HVC_CONSOLES) {
958 /* find 'empty' slot for console */
959 for (i = 0; i < MAX_NR_HVC_CONSOLES && vtermnos[i] != -1; i++) {
962 /* no matching slot, just use a counter */
963 if (i == MAX_NR_HVC_CONSOLES)
964 i = ++last_hvc + MAX_NR_HVC_CONSOLES;
968 if (i < MAX_NR_HVC_CONSOLES) {
970 vtermnos[i] = vtermno;
974 list_add_tail(&(hp->next), &hvc_structs);
975 mutex_unlock(&hvc_structs_mutex);
977 /* check if we need to re-register the kernel console */
978 hvc_check_console(i);
982 EXPORT_SYMBOL_GPL(hvc_alloc);
984 int hvc_remove(struct hvc_struct *hp)
987 struct tty_struct *tty;
989 tty = tty_port_tty_get(&hp->port);
992 spin_lock_irqsave(&hp->lock, flags);
993 if (hp->index < MAX_NR_HVC_CONSOLES) {
994 vtermnos[hp->index] = -1;
995 cons_ops[hp->index] = NULL;
996 cons_hvcs[hp->index] = NULL;
999 /* Don't whack hp->irq because tty_hangup() will need to free the irq. */
1001 spin_unlock_irqrestore(&hp->lock, flags);
1005 * We 'put' the instance that was grabbed when the kref instance
1006 * was initialized using kref_init(). Let the last holder of this
1007 * kref cause it to be removed, which will probably be the tty_vhangup
1010 tty_port_put(&hp->port);
1013 * This function call will auto chain call hvc_hangup.
1021 EXPORT_SYMBOL_GPL(hvc_remove);
1023 /* Driver initialization: called as soon as someone uses hvc_alloc(). */
1024 static int hvc_init(void)
1026 struct tty_driver *drv;
1029 /* We need more than hvc_count adapters due to hotplug additions. */
1030 drv = tty_alloc_driver(HVC_ALLOC_TTY_ADAPTERS, TTY_DRIVER_REAL_RAW |
1031 TTY_DRIVER_RESET_TERMIOS);
1037 drv->driver_name = "hvc";
1039 drv->major = HVC_MAJOR;
1040 drv->minor_start = HVC_MINOR;
1041 drv->type = TTY_DRIVER_TYPE_SYSTEM;
1042 drv->init_termios = tty_std_termios;
1043 tty_set_operations(drv, &hvc_ops);
1045 /* Always start the kthread because there can be hotplug vty adapters
1047 hvc_task = kthread_run(khvcd, NULL, "khvcd");
1048 if (IS_ERR(hvc_task)) {
1049 printk(KERN_ERR "Couldn't create kthread for console.\n");
1050 err = PTR_ERR(hvc_task);
1054 err = tty_register_driver(drv);
1056 printk(KERN_ERR "Couldn't register hvc console driver\n");
1061 * Make sure tty is fully registered before allowing it to be
1062 * found by hvc_console_device.
1069 kthread_stop(hvc_task);
1072 tty_driver_kref_put(drv);