drivers/tty/tty_ldisc.c

Source file repositories/reference/linux-study-clean/drivers/tty/tty_ldisc.c

File Facts

System
Linux kernel
Corpus path
drivers/tty/tty_ldisc.c
Extension
.c
Size
20841 bytes
Lines
825
Domain
Driver Families
Bucket
drivers/tty
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret) {
			ret = __tty_ldisc_lock_nested(tty2, timeout);
			if (!ret)
				__tty_ldisc_unlock(tty);
		}
	} else {
		/* if this is possible, it has lots of implications */
		WARN_ON_ONCE(tty == tty2);
		if (tty2 && tty != tty2) {
			ret = __tty_ldisc_lock(tty2, timeout);
			if (ret) {
				ret = __tty_ldisc_lock_nested(tty, timeout);
				if (!ret)
					__tty_ldisc_unlock(tty2);
			}
		} else
			ret = __tty_ldisc_lock(tty, timeout);
	}

	if (!ret)
		return -EBUSY;

	set_bit(TTY_LDISC_HALTED, &tty->flags);
	if (tty2)
		set_bit(TTY_LDISC_HALTED, &tty2->flags);
	return 0;
}

static void tty_ldisc_lock_pair(struct tty_struct *tty, struct tty_struct *tty2)
{
	tty_ldisc_lock_pair_timeout(tty, tty2, MAX_SCHEDULE_TIMEOUT);
}

static void tty_ldisc_unlock_pair(struct tty_struct *tty,
				  struct tty_struct *tty2)
{
	__tty_ldisc_unlock(tty);
	if (tty2)
		__tty_ldisc_unlock(tty2);
}

/**
 * tty_ldisc_flush		-	flush line discipline queue
 * @tty: tty to flush ldisc for
 *
 * Flush the line discipline queue (if any) and the tty flip buffers for this
 * @tty.
 */
void tty_ldisc_flush(struct tty_struct *tty)
{
	struct tty_ldisc *ld = tty_ldisc_ref(tty);

	tty_buffer_flush(tty, ld);
	if (ld)
		tty_ldisc_deref(ld);
}
EXPORT_SYMBOL_GPL(tty_ldisc_flush);

/**
 * tty_set_termios_ldisc	-	set ldisc field
 * @tty: tty structure
 * @disc: line discipline number
 *
 * This is probably overkill for real world processors but they are not on hot
 * paths so a little discipline won't do any harm.
 *
 * The line discipline-related tty_struct fields are reset to prevent the ldisc
 * driver from re-using stale information for the new ldisc instance.
 *
 * Locking: takes termios_rwsem
 */
static void tty_set_termios_ldisc(struct tty_struct *tty, int disc)
{
	down_write(&tty->termios_rwsem);
	tty->termios.c_line = disc;
	up_write(&tty->termios_rwsem);

	tty->disc_data = NULL;
	tty->receive_room = 0;
}

/**
 * tty_ldisc_open		-	open a line discipline
 * @tty: tty we are opening the ldisc on
 * @ld: discipline to open
 *
 * A helper opening method. Also a convenient debugging and check point.
 *
 * Locking: always called with BTM already held.
 */

Annotation

Implementation Notes