History log of /freebsd-current/sys/kern/kern_cons.c
Revision Date Author Comments
# 9b1de7e4 24-May-2024 Ed Maste <emaste@FreeBSD.org>

vt/sc: retire logic to select vt(4) by default for UEFI boot

We previously defaulted to using sc(4) with a special case to prefer
vt(4) when booted via UEFI. As vt(4) is now always the default we can
simplify this.

Reviewed by: imp, kevans
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45356


# 2cb49090 30-Apr-2024 Justin Hibbits <jhibbits@FreeBSD.org>

cons: Add boot option to mute boot messages after banner

This is useful for embedded systems, where it provides feedback that the
kernel has booted, but avoids printing the probe messages. If both
mutemsgs and verbose are set, verbose cancels the mute.

Additionally, this unmutes the console on panic, so a user can see what
happened leading up to the panic.

Obtained from: Juniper Networks, Inc.


# 20289092 08-Jan-2024 Andrew Turner <andrew@FreeBSD.org>

sys: Simplify enabling EARLY_PRINTF uarts

Support selecting the early uart with "options EARLY_PRINTF=foo" in
the kernel configuration file. This allows us to not have to change
source files when enabling EARLY_PRINTF, simplifying enabling it.

New uart drivers can be enabled by defining a new early_printf_foo
value to be unique, then using "#if CHECK_EARLY_PRINTF(foo)" to decide
when to enable the uart.

While here add pl011 early printf support.

Reviewed by: imp (earlier version)
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D43360


# a68d5a66 05-Jan-2024 Kyle Evans <kevans@FreeBSD.org>

Revert "kern: console: make /dev/console backing console more predictable"

This accidentally snuck into a different branch, and has not been
reviewed for sanity yet..

This reverts commit 8ec6d7be2e27622b8b9e192b4da9ce88a4118636.


# 8ec6d7be 04-Jan-2024 Kyle Evans <kevans@FreeBSD.org>

kern: console: make /dev/console backing console more predictable

Specifically, altering the console list with conscontrol has some weird
behavior:

1. If you remove the first configured console, /dev/console will become
unconfigured
2. Any console added becomes the /dev/console

In a multicons situation, #1 is clearly a bug and #2 is perhaps slightly
less clear. If we have ttyu0, ttyv0, then it seems obvious that one
would want ttyv0 to take over the console if ttyu0 is removed. If we
add ttyu0 back in, then it's debatable whether it should take over the
console or not.

Fix it now to make the /dev/console selection more FIFO-ish, with
respect to how conscontrol affects it. A `primary` verb for
conscontrol(8) might be a good addition.


# 29363fb4 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 0a713948 22-Nov-2023 Alexander Motin <mav@FreeBSD.org>

Replace random sbuf_printf() with cheaper cat/putc.


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 9d6ae1e3 04-Jun-2023 Colin Percival <cperciva@FreeBSD.org>

Revert "Revert "tslog: Annotate some early boot functions""

Now that <sys/tslog.h> is wrapped in #ifdef _KERNEL, it's safe to have
tslog annotations in files which might be built from userland (i.e. in
subr_boot.c, which is built as part of the boot loader).

This reverts commit 59588a546f55523d6fd37ab42eb08b719311d7d6.


# 59588a54 04-Jun-2023 Colin Percival <cperciva@FreeBSD.org>

Revert "tslog: Annotate some early boot functions"

The change to subr_boot.c broke the libsa build because the TSLOG
macros have their own definitions for the boot loader -- I didn't
realize that the loader code used subr_boot.c.

I'm currently testing a fix and I'll revert this revert once I'm
satisfied that everything works, but I don't want to leave the
tree broken for too long.

This reverts commit 469cfa3c30ee7a5ddeb597d0a8c3e7cac909b27a.


# 469cfa3c 22-May-2023 Colin Percival <cperciva@FreeBSD.org>

tslog: Annotate some early boot functions

Booting an amd64 kernel on Firecracker with 1 CPU and 128 MB of RAM,
hammer_time takes roughly 2740 us:
* 55 us in xen_pvh_parse_preload_data
* 20 us in boot_parse_cmdline_delim
* 20 us in boot_env_to_howto
* 15 us in identify_hypervisor
* 1320 us in link_elf_reloc
* 1310 us in relocate_file1 handling ef->rela
* 25 us in init_param1
* 30 us in dpcpu_init
* 355 us in initializecpu
* 255 us in initializecpu calling load_cr4
* 425 us in getmemsize
* 280 us in pmap_bootstrap
* 205 us in create_pagetables
* 10 us in init_param2
* 25 us in pci_early_quirks
* 60 us in cninit
* 90 us in kdb_init
* 105 us in msgbufinit
* 20 us in fpuinit
* 205 us elsewhere in hammer_time

Some of these are unavoidable (e.g. identify_hypervisor uses CPUID and
load_cr4 loads the CR4 register, both of which trap to the hypervisor)
but others may deserve attention.

Sponsored by: https://www.patreon.com/cperciva
Differential Revision: https://reviews.freebsd.org/D40325


# 9806e82a 26-Jul-2022 Dimitry Andric <dim@FreeBSD.org>

Adjust function definitions in kern_cons.c to avoid clang 15 warnings

With clang 15, the following -Werror warnings are produced:

sys/kern/kern_cons.c:201:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
cninit_finish()
^
void
sys/kern/kern_cons.c:376:7: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
cngrab()
^
void
sys/kern/kern_cons.c:389:9: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
cnungrab()
^
void
sys/kern/kern_cons.c:402:9: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
cnresume()
^
void

This is because cninit_finish(), cngrab(), cnungrab(), and cnresume()
are declared with (void) argument lists, but defined with empty argument
lists. Make the definitions match the declarations.

MFC after: 3 days


# 2bfdc1ee 24-Feb-2022 Warner Losh <imp@FreeBSD.org>

cons: Use bool for boolean variables

MFC After: 3 days
Sponsored by: Netflix


# 072d5b98 03-Nov-2021 Warner Losh <imp@FreeBSD.org>

sysbeep: Adjust interface to take a duration as a sbt

Change the 'period' argument to 'duration' and change its type to
sbintime_t so we can more easily express different durations.

Reviewed by: tsoome, glebius
Differential Revision: https://reviews.freebsd.org/D32619


# bd6085c6 03-Sep-2021 Alexander Motin <mav@FreeBSD.org>

Re-implement virtual console (constty).

Protect conscallout with tty lock instead of Giant. In addition to
Giant removal it also closes race on console unset.

Introduce additional lock to protect against concurrent console sets.

Remove consbuf free on console unset as unsafe, making impossible to
change buffer size after first allocation. Instead increase default
buffer size from 8KB to 64KB and processing rate from 5Hz to 10-15Hz
to make the output more smooth.

MFC after: 1 month


# 780766eb 05-Oct-2020 Mark Johnston <markj@FreeBSD.org>

Remove sysctl_kern_consmute()

It is a trivial wrapper for sysctl_handle_int() since r184521. Also
remove the NEEDGIANT flag, cn_mute is accessed locklessly.

MFC after: 1 week


# 6fed89b1 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

kern: clean up empty lines in .c and .h files


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# fe20aaec 22-Feb-2020 Ryan Libby <rlibby@FreeBSD.org>

sys/kern: quiet -Wwrite-strings

Quiet a variety of Wwrite-strings warnings in sys/kern at low-impact
sites. This patch avoids addressing certain others which would need to
plumb const through structure definitions.

Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D23798


# f46412c0 26-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

kern_cons: add a stub kbdinit for configs with no keyboard/console drivers

A weak symbol here is decidedly cleaner than any #ifdef soup or relocating
kbdinit, the former leading to maintenance required on addition of any
console/keyboard drivers and the latter pushing kbd init bits away from
where they're used.


# 3ed7166a 26-Dec-2019 Kyle Evans <kevans@FreeBSD.org>

kbd: merge linker set drivers into standard kbd driver list

This leads to the revert of r355806; this reduces duplication in keyboard
registration and driver switch lookup and leaves us with one authoritative
source for currently registered drivers. The reduced duplication later is
nice as we have more procedure involved in keyboard setup.

keyboard_driver->flags is used to more quickly detect bogus adds/removes.
From KPI consumers' perspective, nothing changes- kbd_add_driver of an
already-registered driver will succeed, and a single kbd_delete_driver will
later remove it as expected. In contrast to historical behavior,
kbd_delete_driver on a driver registered via linker set will now actually
de-register the driver so that it may not be used -- e.g. if kbdmux's
MOD_LOAD handler fails somewhere.

Detection for already-registered drivers in kbd_add_driver has improved, as
the previous SLIST_NEXT(driver) != NULL check would not have caught a driver
that's at the tail end.

kbdinit is now called from cninit() rather than via SYSINIT so that keyboard
drivers are available as early as console drivers. This is particularly
important as cnprobe will, in both syscons and vt, attempt to do any early
configuration of keyboard drivers built-in (see: kbd_configure).

Reviewed by: imp (earlier version, pre-cninit change)
Differential Revision: https://reviews.freebsd.org/D22835


# 6858c2cc 20-Oct-2018 Conrad Meyer <cem@FreeBSD.org>

Replace ttyprintf with sbuf_printf and tty drain routine

Add string variants of cnputc and tty_putchar, and use them from the tty
sbuf drain routine.

Suggested by: ed@
Sponsored by: Dell EMC Isilon


# ec6faf94 29-May-2018 Andriy Gapon <avg@FreeBSD.org>

add support for console resuming, implement it for uart, use on x86

This change adds a new optional console method cn_resume and a kernel
console interface cnresume. Consoles that may need to re-initialize
their hardware after suspend (e.g., because firmware does not care to do
it) will implement cn_resume. Note that it is called in rather early
environment not unlike early boot, so the same restrictions apply.
Platform specific code, for platforms that support hardware suspend,
should call cnresume early after resume, before any console output is
expected.

This change fixes a problem with a system of mine failing to resume when
a serial console is used. I found that the serial port was in a strange
configuration and an attempt to write to it likely resulted in an
infinite loop.

To avoid adding cn_resume method to every console driver, CONSOLE_DRIVER
macro has been extended to support optional methods.

Reviewed by: imp, mav
MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D15552


# 51369649 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 69a28758 15-Sep-2016 Ed Maste <emaste@FreeBSD.org>

Renumber license clauses in sys/kern to avoid skipping #3


# fd90e2ed 22-May-2015 Jung-uk Kim <jkim@FreeBSD.org>

CALLOUT_MPSAFE has lost its meaning since r141428, i.e., for more than ten
years for head. However, it is continuously misused as the mpsafe argument
for callout_init(9). Deprecate the flag and clean up callout_init() calls
to make them more consistent.

Differential Revision: https://reviews.freebsd.org/D2613
Reviewed by: jhb
MFC after: 2 weeks


# 657282e0 14-Mar-2015 Ian Lepore <ian@FreeBSD.org>

Include the nulterm byte in the sysctl string.

PR: 195668


# 04a8159d 03-Jan-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Rework r276532 a bit. Always avoid recursing into the console drivers
clients, hence they might not handle it very well. This change allows
debugging mutex problems with kernel console drivers when
"debug.witness.skipspin=0" is set in the boot environment.

MFC after: 1 week


# 2029b6c9 02-Jan-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

The "cnputs_mtx" mutex must be allowed to recurse. Debug prints and/or
witness printouts in the console driver clients can cause this mutex
to recurse by calls to "printf()" from witness for example. In
particular this can happen if "debug.witness.skipspin=0" is set in the
boot environment.

MFC after: 1 week


# dc61566f 19-Nov-2014 Zbigniew Bodek <zbb@FreeBSD.org>

Stop using early_putc immediately after configuring console with cninit()

Early UART should be released right after system console initialization is
completed. Otherwise, after cninit() both early and system console coexist
what may lead to various issues (i.a. writing to unmapped early
UART address). This cannot be done in cninit_finish() since it can be
called late at the end of MI configuration.

Obtained from: Semihalf
Reviewed by: andrew
Sponsored by: The FreeBSD Foundation


# 2d6f6d63 04-Nov-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

Enable vt(4) by default

vt(4) is a new console driver which brings features such as:
o Support for Unicode and double-width characters
o Integration with the KMS kernel video drivers
o Support for UEFI

You may need to update your console settings in /etc/rc.conf, most
probably the keymap. During boot, /etc/rc.d/syscons will indicate what
you need to do.

vt(4) still has issues and lacks some features compared to syscons(4).
See the wiki for up-to-date information:
https://wiki.freebsd.org/Newcons

If you want to keep using syscons(4), you can do so by adding the
following line to /boot/loader.conf:
kern.vty=sc

Differential Revision: https://reviews.freebsd.org/D1005
Discussed with: emaste@, nwhitehorn@, ray@
Relnotes: yes


# fadf3fb9 22-Sep-2014 John Baldwin <jhb@FreeBSD.org>

Convert from timeout(9) to callout(9).


# 969d3cc2 02-Jul-2014 Ed Maste <emaste@FreeBSD.org>

Fix typos in VTY constant names from r268158


# 018147ee 02-Jul-2014 Ed Maste <emaste@FreeBSD.org>

Prefer vt(4) for UEFI boot

The UEFI framebuffer driver vt_efifb requires vt(4), so add a mechanism
for the startup routine to set the preferred console. This change is
ugly because console init happens very early in the boot, making a
cleaner interface difficult. This change is intended only to facilitate
the sc(4) / vt(4) transition, and can be reverted once vt(4) is the
default.


# af3b2549 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Pull in r267961 and r267973 again. Fix for issues reported will follow.


# 37a107a4 27-Jun-2014 Glen Barber <gjb@FreeBSD.org>

Revert r267961, r267973:

These changes prevent sysctl(8) from returning proper output,
such as:

1) no output from sysctl(8)
2) erroneously returning ENOMEM with tools like truss(1)
or uname(1)
truss: can not get etype: Cannot allocate memory


# 6ac6c9d5 27-Jun-2014 Ed Maste <emaste@FreeBSD.org>

Add CTLFLAG_NOFETCH flag; console vty code runs before tunable fetch

Also remove redundant "" assignment for string in BSS.

Submitted by: hselasky@


# 59644098 27-Jun-2014 Ed Maste <emaste@FreeBSD.org>

Use a common tunable to choose between vt(4)/sc(4)

With this change and previous work from ray@ it will be possible to put
both in GENERIC, and have one enabled by default, but allow the other to
be selected via the loader.

(The previous implementation had separate kern.vt.disable and
hw.syscons.disable tunables, and would panic if both drivers were
compiled in and neither was explicitly disabled.)

MFC after: 1 week
Sponsored by: The FreeBSD Foundation


# 42c8459b 11-Feb-2014 Ian Lepore <ian@FreeBSD.org>

Rework the EARLY_PRINTF mechanism. Instead of defining a special eprintf()
routine, now a platform can provide a pointer to an early_putc() routine
which is used instead of cn_putc(). Control can be handed off from early
printf support to standard console support by NULLing out the pointer
during standard console init.

This leverages all the existing error reporting that uses printf calls,
such as panic() which can now be usefully employed even in early
platform init code (useful at least to those who maintain that code and
build kernels with EARLY_PRINTF defined).

Reviewed by: imp, eadler


# 9520f952 30-Dec-2013 Warner Losh <imp@FreeBSD.org>

Delete echoed doesn't rub out the previous character, so always
use <backspace> <space> <backspace> instead. This fixes hitting
DELETE instead of BACKSPACE at mountroot> prompt.


# 298fbd16 06-Oct-2012 Andriy Gapon <avg@FreeBSD.org>

cngetc: use cpu_spinwait to ease the cncheckc loop a tiny bit

Reviewed by: julian
MFC after: 10 days


# f389bc95 17-Dec-2011 Andriy Gapon <avg@FreeBSD.org>

belatedly transfer copyrights from libkern/gets.c to kern_cons.c

MFC after: 2 months
MFC with: r228642


# 8e628542 17-Dec-2011 Andriy Gapon <avg@FreeBSD.org>

introduce cngets, a method for kernel to read a string from console

This is intended as a replacement for libkern's gets and mostly borrows
its implementation. It uses cngrab/cnungrab to delimit kernel's access
to console input.

Note: libkern's gets obviously doesn't share any bits of implementation
iwth libc's gets. They also have different APIs and the former doesn't
have the overflow problems of the latter.

Inspired by: bde
MFC after: 2 months


# bf8696b4 17-Dec-2011 Andriy Gapon <avg@FreeBSD.org>

introduce cngrab/cnungrab stub calls in some places where they make sense

MFC after: 2 months


# 9976156f 17-Dec-2011 Andriy Gapon <avg@FreeBSD.org>

kern cons: introduce infrastructure for console grabbing by kernel

At the moment grab and ungrab methods of all console drivers are no-ops.

Current intended meaning of the calls is that the kernel takes control of
console input. In the future the semantics may be extended to mean that
the calling thread takes full ownership of the console (e.g. console
output from other threads could be suspended).

Inspired by: bde
MFC after: 2 months


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# a0c87b74 09-Aug-2010 Gavin Atkinson <gavin@FreeBSD.org>

Add descriptions to a handful of sysctl nodes.

PR: kern/148580
Submitted by: Galimov Albert <wtfcrap mail.ru>
MFC after: 1 week


# 2992abe0 24-Aug-2009 Ed Schouten <ed@FreeBSD.org>

Allow multiple console devices per driver without insane code duplication.

Say, a driver wants to have multiple console devices to pick from, you
would normally write down something like this:

CONSOLE_DRIVER(dev1);
CONSOLE_DRIVER(dev2);

Unfortunately, this means that you have to declare 10 cn routines,
instead of 5. It also isn't possible to initialize cn_arg on beforehand.

I noticed this restriction when I was implementing some of the console
bits for my vt(4) driver in my newcons branch. I have a single set of cn
routines (termcn_*) which are shared by all vt(4) console devices.

In order to solve this, I'm adding a separate consdev_ops structure,
which contains all the function pointers. This structure is referenced
through consdev's cn_ops field.

While there, I'm removing CONS_DRIVER() and cn_checkc, which have been
deprecated for years. They weren't used throughout the source, until the
Xen console driver showed up. CONSOLE_DRIVER() has been changed to do
the right thing. It now declares both the consdev and consdev_ops
structure and ties them together. In other words: this change doesn't
change the KPI for drivers that used the regular way of declaring
console devices.

If drivers want to use multiple console devices, they can do this as
follows:

static const struct consdev_ops mydriver_cnops = {
.cn_probe = mydriver_cnprobe,
...
};
static struct mydriver_softc cons0_softc = {
...
};
CONSOLE_DEVICE(cons0, mydriver_cnops, &cons0_softc);
static struct mydriver_softc cons1_softc = {
...
};
CONSOLE_DEVICE(cons1, mydriver_cnops, &cons1_softc);

Obtained from: //depot/user/ed/newcons/...


# 318b1c3f 26-Feb-2009 Ed Schouten <ed@FreeBSD.org>

Remove unneeded variable `ocn_mute'.

Found by: LLVM's scan-build


# c9dba40c 01-Nov-2008 Ed Schouten <ed@FreeBSD.org>

Reimplement the /dev/console device node.

One of the pieces of code that I had left alone during the development
of the MPSAFE TTY layer, was tty_cons.c. This file actually has two
different functions:

- It contains low-level console input/output routines (cnputc(), etc).

- It creates /dev/console and wraps all its cdevsw calls to the
appropriate TTY.

This commit reimplements the second set of functions by moving it
directly into the TTY layer. /dev/console is now a character device node
that's basically a regular TTY, but does a lookup of `si_drv1' each time
you open it. d_write has also been changed to call log_console().
d_close() is not present, because we must make sure we don't revoke the
TTY after writing a log message to it.

Even though I'm not convinced this is in line with the future directions
of our console code, it is a good move for now. It removes recursive
locking from the top half of the TTY layer. The previous implementation
called into the TTY layer with Giant held.

I'm renaming tty_cons.c to kern_cons.c now. The code hardly contains any
TTY related bits, so we'd better give it a less misleading name.

Tested by: Andrzej Tobola <ato iem pw edu pl>,
Carlos A.M. dos Santos <unixmania gmail com>,
Eygene Ryabinkin <rea-fbsd codelabs ru>