History log of /freebsd-current/sys/dev/vt/hw/vga/vt_vga.c
Revision Date Author Comments
# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


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

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

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


# 3af6e882 06-May-2022 John Baldwin <jhb@FreeBSD.org>

vt: Remove unused devclass argument to DRIVER_MODULE.


# 05188320 24-Feb-2022 Roger Pau Monné <royger@FreeBSD.org>

vt/vga: ignore ACPI_FADT_NO_VGA unless running virtualized

There's too many broken hardware out there that wrongly has the
ACPI_FADT_NO_VGA bit set. Ignore it unless running as a virtualized
guest, as then the expectation would be that the hypervisor does
provide correct ACPI tables.

Reviewed by: emaste, 0mp, eugen
MFC: 3 days
Sponsored by: Citrix Systems R&D
PR: 230172
Differential revision: https://reviews.freebsd.org/D34392


# f266082f 02-Mar-2022 Ed Maste <emaste@FreeBSD.org>

vt_vga: fix colour in pixel blocks with more than 4 colours

VGA hardware provides many different graphics and data access modes,
each with different capabilities and limitations.

VGA vt(4) graphics mode operates on blocks of pixels at a time. When a
given pixel block contains only two colours the vt_vga driver uses write
mode 3. When the block contains more than two colours it uses write
mode 0. This is done because two-colour write mode 3 is much more
efficient.

In practice write mode 3 is used most of the time, as there is often a
single foreground colour and single background colour across the entire
console. One common exception requiring the use of mode 0 is when the
mouse cursor is drawn over a background other than black, as we need
black and white for the cursor in addition to the background colour.

VGA's default 16-colour palette provides the same set of colours as the
system console, but in a different order. Previously we configured a
non-default VGA palette that had the same colours at the same indexes.
However, this caused anything drawn before the kernel started (drawn by
the loader, for instance) to change colours once the kernel configured
the new, non-default palette.

In 5e251aec8636 we switched to leaving the default VGA palette in place,
translating console colour indexes to VGA colour indexes as necessary.
This translation was missed for the write mode 0 case for pixel blocks
with more than two colours.

PR: 261751
Reviewed by: adrian
MFC after: 1 week
Fixes: 5e251aec8636 ("vt(4): Use default VGA palette")
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34412


# 731a929a 02-Mar-2022 Ed Maste <emaste@FreeBSD.org>

vt_vga: Correct "plane" spelling

I suspect the variable names and comments were accidentally French.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation


# dbc7ca59 22-Sep-2021 Ed Maste <emaste@FreeBSD.org>

vt: bound buffer access in redraw optimization

PR: 248628
Reported by: oleg
Reviewed by: cem, oleg (both earlier)
Fixes: ee97b2336aa4 ("Speed up vt(4) by keeping...")
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32059


# ee97b233 25-Aug-2018 Colin Percival <cperciva@FreeBSD.org>

Speed up vt(4) by keeping a record of the most recently drawn character and
the foreground and background colours. In bitblt_text functions, compare
values to this cache and don't re-draw the characters if they haven't changed.
When invalidating the display, clear this cache in order to force characters
to be redrawn; also force full redraws between suspend/resume pairs since odd
artifacts can otherwise result.

When scrolling the display (which is where most time is spent within the vt
driver) this yields a significant performance improvement if most lines are
less than the width of the terminal, since this avoids re-drawing blanks on
top of blanks.

(Note that "re-drawing" here includes writing to the VGA text mode buffer; on
virtualized systems this can be extremely slow since it triggers a glyph
being rendered onto a 640x480 screen).

On a c5.4xlarge EC2 instance (with emulated text mode VGA) this cuts the time
spent in vt(4) during the kernel boot from 1200 ms to 700ms; on my laptop
(with a 3200x1800 display) the corresponding time is reduced from 970 ms down
to 155 ms.

Reviewed by: imp, cem
Approved by: re (gjb)
Relnotes: Significant speedup in vt(4) and the system boot generally.
Differential Revision: https://reviews.freebsd.org/D16723


# 0b4d5eb8 07-Aug-2018 Colin Percival <cperciva@FreeBSD.org>

Replace a pair of 8-bit writes to VGA memory with a single 16-bit write.

The VGA "text mode" buffer has a pair of bytes for each character: One
byte for the character symbol, and an "attribute" byte encoding the
foreground and background colours. When updating the screen, we were
writing these two bytes separately.

On some virtualized systems, every write results in a glyph being redrawn
into a (graphical) virtual screen; writing these two bytes separately
results in twice as much work being done to draw characters, whereas if
we perform a single 16-bit write instead, the character only needs to be
redrawn once.

On an EC2 c5.4xlarge instance, this change cuts 1.30s from the kernel boot,
speeding it up from 8.90s to 7.60s.

MFC after: 1 week


# 28ebccd5 25-Jun-2018 Konstantin Belousov <kib@FreeBSD.org>

Fix compilation.

Pointy hat to: me
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 7705dd4d 25-Jun-2018 Konstantin Belousov <kib@FreeBSD.org>

Provide a helper function acpi_get_fadt_bootflags() to fetch the FADT
x86 boot flags.

Reviewed by: royger
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D16004
MFC after: 1 week


# 120186ad 25-Jun-2018 Konstantin Belousov <kib@FreeBSD.org>

Always initialize the ignore local variable.

Reviewed by: royger
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D16004


# 8f62926e 25-Jun-2018 Roger Pau Monné <royger@FreeBSD.org>

vt: add option to ignore NO_VGA flag in ACPI

To workaround buggy firmware that sets this flag when there's actually
a VGA present.

Reported and tested by: Yasuhiro KIMURA <yasu@utahime.org>
Sponsored by: Citrix Systems R&D
Reviewed by: kib
Differential revision: https://reviews.freebsd.org/D16003


# 649d7b46 17-May-2018 Ed Maste <emaste@FreeBSD.org>

vt: add more cp437 mappings for vga textmode

In UTF-8 locales mandoc uses a number of characters outside of the Basic
Latin group, e.g. from general punctuation or miscellaneous mathematical
symbols, and these rendered as ? in text mode.

This change adds (char, replacement, code point, description):

¦ | U+00A6 Broken bar
✓ √ U+2713 Checkmark

Sponsored by: The FreeBSD Foundation


# 5e251aec 10-May-2018 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Use default VGA palette

Before this change, the VGA palette was configured to match the shell
palette (e.g. color #1 was red). There was one glitch early in boot when
the vt(4)'s VGA palette was loaded: the loader's logo would switch from
red to blue. Likewise for the "Booting..." message switching from blue
to red. That's because the loader's logo was drawed with the default VGA
palette where a few colors are swapped compared to the shell palette
(e.g. blue <-> red).

This change configures the default VGA palette during initialization and
converts input's colors from shell to VGA palette index.

There should be no visible changes, except the loader's logo which will
keep its original color.

Reviewed by: eadler


# 185aba2d 11-Apr-2018 Ed Maste <emaste@FreeBSD.org>

vt: add three more cp437 mappings for vga textmode

In UTF-8 locales mandoc uses a number of characters outside of the Basic
Latin group, e.g. from general punctuation or miscellaneous mathematical
symbols, and these rendered as ? in text mode.

This change adds (char, replacement, code point, description):

– - U+2013 En Dash
⟨ < U+27E8 Mathematical Left Angle Bracket
⟩ > U+27E9 Mathematical Right Angle Bracket

This change addresses some common cases; there are others that still
need to be added after a more thorough review.

PR: 227409
MFC after: 1 week
Sponsored by: The FreeBSD Foundation


# c2272faa 13-Mar-2018 Roger Pau Monné <royger@FreeBSD.org>

vt_vga: check if VGA is available from ACPI FADT table

On x86 the IA-PC Boot Flags in the FADT can signal whether VGA is
available or not.

Sponsored by: Citrix systems R&D
Reviewed by: marcel
Differential revision: https://reviews.freebsd.org/D14397


# e6b01ed7 13-Jun-2017 Enji Cooper <ngie@FreeBSD.org>

Use nitems(..) when computing `max` instead of the longhand version of
the same logic

MFC after: 1 month


# 4ed3c0e7 30-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys: Make use of our rounddown() macro when sys/param.h is available.

No functional change.


# 057b4402 26-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: extend use of the howmany() macro when available.

We have a howmany() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.


# 9a4a2c61 28-Mar-2016 Sepherosa Ziehau <sephe@FreeBSD.org>

vt: Use textmode when we're running on hypervisors

The graphic mode is noticeably slow on hypervisors, especially
on Hyper-V (1 second to each line).

Submitted by: Dexuan Cui <decui microsoft com>
Reviewed by: kib, sephe, royger (early loader version)
MFC after: 1 week
Sponsored by: Microsoft OSTC
Differential Revision: https://reviews.freebsd.org/D5739


# 6280434f 13-Aug-2015 Marcel Moolenaar <marcel@FreeBSD.org>

Fix text mode operation.

We first map 64KB at 0xA0000 and then determine whether to work
in text or graphics mode. When graphics mode, the mapping is
precisely what we need and everything is fine. But text mode,
has the frame buffer relocated to 0xB8000. We didn't map that
much to safely add 0x18000 bytes to the base address.

Now we first check whether to work in text or graphics mode and
then map the frame buffer at the right address and with the
right size (0xA0000+64KB for graphics, 0xB8000+32KB for text).

PR: 202276
Tested by: ed@


# 7ef5e8bc 12-Aug-2015 Marcel Moolenaar <marcel@FreeBSD.org>

Better support memory mapped console devices, such as VGA and EFI
frame buffers and memory mapped UARTs.

1. Delay calling cninit() until after pmap_bootstrap(). This makes
sure we have PMAP initialized enough to add translations. Keep
kdb_init() after cninit() so that we have console when we need
to break into the debugger on boot.
2. Unfortunately, the ATPIC code had be moved as well so as to
avoid a spurious trap #30. The reason for which is not known
at this time.
3. In pmap_mapdev_attr(), when we need to map a device prior to the
VM system being initialized, use virtual_avail as the KVA to map
the device at. In particular, avoid using the direct map on amd64
because we can't demote by virtue of not being able to allocate
yet. Keep track of the translation.
Re-use the translation after the VM has been initialized to not
waste KVA and to satisfy the assumption in uart(4) that the handle
returned for the low-level console is the same as later returned
when the device is probed and attached.
4. In pmap_unmapdev() remove the mapping from the table when called
pre-init. Otherwise keep the mapping. During bus probe and attach
device resources are mapped and unmapped multiple times, which
would have us destroy the mapping used by the low-level console.
5. In pmap_init(), set pmap_initialized to signal that we're not
pre-init anymore. On amd64, bring the direct map in sync with the
translations created at that time.
6. Implement bus_space_map() and bus_space_unmap() for real: when
the tag corresponds to memory space, call the corresponding
pmap_mapdev() and pmap_unmapdev() functions to construct and
actual handle.
7. In efifb.c and vt_vga.c, remove the crutches and hacks and simply
call pmap_mapdev_attr() or bus_space_map() as desired.

Notes:
1. uart(4) already used bus_space_map() during low-level console
setup but since serial ports have traditionally been I/O port
based, the lack of a proper implementation for said function
was not a problem. It has always supported memory mapped UARTs
for low-level consoles by setting hw.uart.console accordingly.
2. The use of the direct map on amd64 without setting caching
attributes has been a bigger problem than previously thought.
This change has the fortunate (and unexpected) side-effect of
fixing various EFI frame buffer problems (though not all).

PR: 191564, 194952

Special thanks to:
1. XipLink, Inc -- generously donated an Intel Bay Trail E3800
based eval board (ADLE3800PC).
2. The FreeBSD Foundation, in particular emaste@ -- for UEFI
support in general and testing.
3. Everyone who tested the proposed for PR 191564.
4. jhb@ and kib@ for being a soundboard and applying a clue bat
if so needed.


# f0e31fe0 28-Apr-2015 Roger Pau Monné <royger@FreeBSD.org>

vt_vga: add a timeout while waiting for vertical retrace

On one of my systems FreeBSD will fail to boot because vt_vga gets stuck
waiting for the vertical retrace if there's no monitor attached. Fix this by
adding a timeout and exiting if the vertical retrace times out.

Sponsored by: Citrix Systems R&D
Reviewed by: emaste, dumbbell
Differential Revision: https://reviews.freebsd.org/D2397


# 76e2f976 28-Feb-2015 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Add support to "downgrade" from eg. vt_fb to vt_vga

The main purpose of this feature is to be able to unload a KMS driver.

When going back from the current vt(4) backend to the previous backend,
the previous backend is reinitialized with the special VDF_DOWNGRADE
flag set. Then the current driver is terminated with the new "vd_fini"
callback.

In the case of vt_fb and vt_vga, this allows the former to pass the
vgapci device vt_fb used to vt_vga so the device can be rePOSTed.

Differential Revision: https://reviews.freebsd.org/D687


# bae1c14d 05-Feb-2015 Rui Paulo <rpaulo@FreeBSD.org>

vtvga: improve the device description.


# bc59086c 30-Dec-2014 Roger Pau Monné <royger@FreeBSD.org>

vt_vga: fix an off-by-one error

This correctly sets the end of the memory region registered by vt_vga.

Reported by: marius


# acb332a8 22-Dec-2014 Roger Pau Monné <royger@FreeBSD.org>

vt: register the memory regions used by the vt drivers

Current VT drivers don't register the memory regions they use with the
nexus. This patch makes vt_vga and vt_efifb register the memory regions they
use.

This is needed (at least) for Xen support, since the FreeBSD kernel will try
to use the holes in the memory map to map memory from other domains and
setup it's grant table.

Sponsored by: Citrix Systems R&D
Reported by: sbruno
Tested by: emaste
Reviewed by: ray
PR: 195537
Differential Revision: https://reviews.freebsd.org/D1291


# 6cbf3f62 05-Sep-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt_vga: vd_setpixel_t and vd_drawrect_t are noop in text mode

MFC after: 3 days


# af9f67ea 25-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt_vga: Use Write Mode 0 to draw group of 8 pixels using 3 or more colors

This replaces the method based on Write Mode 3, which required reads
from the video memory to load the latches.

MFC after: 1 week


# 83fbb296 25-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Store a rectangle for the drawable area, not just the top-left corner

This allows backends to verify they do not draw outside of this area.
This fixes a bug in vt_vga where the text was happily drawn over the
right and bottom margins, when using the Gallant font.

MFC after: 1 week


# 7e1770a7 24-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt_vga: Fix the display of the splash screen

MFC after: 1 week


# 631bb572 23-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Add vd_bitblt_bmp_t callback

The code was already there in all backends, we just expose it. This is
used to display the splash screen.

MFC after: 1 week


# 946d0288 23-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Fix cursor handling in vt_flush()

There were situations where the cursor was not erased/redrawn or its
position was marked as dirty even though it's not displayed. The code is
now more straightforward.

At the same, add a function to determine if the cursor covers a given
area. This is used by backends to know if they need to draw the cursor.

This new function should be paired with a new state in struct vt_device,
called vd_mshown, which indicates if the cursor should be displayed.
This again simplifies vd_bitblt_text_t callback's API.

MFC after: 1 week


# 81788a2b 23-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt_vga: Give only the character part of term_char_t to vga_get_cp437()

This fixes a bug where vga_get_cp437() was called with an invalid
argument. The screen was then filled with '?' instead of the actual
character.

MFC after: 1 week


# 523473b8 22-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt_vga: Remove a "FIXME" comment; the issue was solved in r270338

MFC after: 1 week


# ccd5615a 22-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): The offset to center the text area is per-window now

The previous global offset, based on the last loaded font, had no
meaning for other windows. This caused a shifted text area, often partly
out-of-screen.

MFC after: 1 week


# ab06c776 22-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Give the window to vd_bitblt_text_t callback

... instead of both the buffer and the font. Again, this simplifies the
API.

MFC after: 1 week


# 3235c9eb 22-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Store cursor bitmap & colors in struct vt_device

This removes the need to specify them to each call to vd_bitblt_text_t
and, therefore, simplifies the API.

MFC after: 1 week


# 37fcd291 22-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt_vga: Clip the draw area to never draw offscreen

This fixes a bug when two windows use different fonts, but a longer-term
solution is required. The dirty area should be stored as pixels, not
character cells, because such coordinates don't have the same meaning in
all windows, when using different fonts.

MFC after: 1 week


# bdcaf97c 22-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt(4): Add new vd_bitblt_text_t callback, and implement it for vt_vga

Compared to the deprecated vd_bitbltchr_t callback, vd_bitblt_text_t
receives:
o the whole text buffer
o the dirty area
o the mouse cursor (map, position, colors)

This allows the backend to perform optimization on how to draw things.
The goal is to remove vd_bitbltchr_t and vd_putchar_t, once all driver
are converted (only vt_vga is included in this commit).

In vt_vga, this allows to draw the text and the cursor in one pass,
without ever reading from video memory (because it has all the context).
The main benefit is the speed improvement: no more slideshow during
boot!

Other bugs fixed in vt_vga are:
o left-most characters are drawn properly (the left-most pixels were
missing with bold characters and some wide letters such as 'm')
o no more black square around the cursor
o no cursor flickering when the text is scrolling

There are still many problems to fix: the known issues are marked with
"FIXME" inside the code.

MFC after: 1 week


# 0c1c6af4 21-Aug-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

vt_vga: When clearing video memory, don't read from it

The goal is to clear the video memory, in case an application drew to
it. So the content shouldn't be loaded in the latches, it can't be
trusted anyway.

This improves a bit the window switch speed.

MFC after: 1 week


# 0f3ec4da 07-Aug-2014 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Retire vd_maskbitbltchr. The same functionality can be obtained by testing
for mask != NULL in vd_bitbltchr, which all implementations of vd_bitbltchr()
were doing anyway.


# 34cb8c9f 03-Aug-2014 Aleksandr Rybalko <ray@FreeBSD.org>

Fix vt_vga driver to draw not-8-bit-aligned fonts correctly.
Still one bug here: mouse left some gaps on track when moving left.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation


# e7d939bd 06-Jul-2014 Marcel Moolenaar <marcel@FreeBSD.org>

Remove ia64.

This includes:
o All directories named *ia64*
o All files named *ia64*
o All ia64-specific code guarded by __ia64__
o All ia64-specific makefile logic
o Mention of ia64 in comments and documentation

This excludes:
o Everything under contrib/
o Everything under crypto/
o sys/xen/interface
o sys/sys/elf_common.h

Discussed at: BSDcan


# a401c53a 18-Jun-2014 Aleksandr Rybalko <ray@FreeBSD.org>

Rename vt(4) vga module to dismiss interference with syscons(4) vga module.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation