diff --git a/stand/defaults/loader.conf b/stand/defaults/loader.conf index 08406aa43bc8..e0062bbc8149 100644 --- a/stand/defaults/loader.conf +++ b/stand/defaults/loader.conf @@ -1,178 +1,178 @@ # This is loader.conf - a file full of useful variables that you can # set to change the default load behavior of your system. You should # not edit this file! Put any overrides into one of the # loader_conf_files instead and you will be able to update these # defaults later without spamming your local configuration information. # # All arguments must be in double quotes. # ### Basic configuration options ############################ exec="echo Loading /boot/defaults/loader.conf" kernel="kernel" # /boot sub-directory containing kernel and modules bootfile="kernel" # Kernel name (possibly absolute path) kernel_options="" # Flags to be passed to the kernel loader_conf_files="/boot/device.hints /boot/loader.conf /boot/loader.conf.local" loader_conf_dirs="/boot/loader.conf.d" nextboot_conf="/boot/nextboot.conf" verbose_loading="NO" # Set to YES for verbose loader output ### Splash screen configuration ############################ splash_bmp_load="NO" # Set this to YES for bmp splash screen! splash_pcx_load="NO" # Set this to YES for pcx splash screen! splash_txt_load="NO" # Set this to YES for TheDraw splash screen! vesa_load="NO" # Set this to YES to load the vesa module bitmap_load="NO" # Set this to YES if you want splash screen! bitmap_name="splash.bmp" # Set this to the name of the file bitmap_type="splash_image_data" # and place it on the module_path ### Screen saver modules ################################### # This is best done in rc.conf screensave_load="NO" # Set to YES to load a screensaver module screensave_name="green_saver" # Set to the name of the screensaver module ### Early hostid configuration ############################ hostuuid_load="YES" hostuuid_name="/etc/hostid" hostuuid_type="hostuuid" ### Random number generator configuration ################## # See rc.conf(5). The entropy_boot_file config variable must agree with the # settings below. entropy_cache_load="YES" # Set this to NO to disable loading # cached entropy at boot time entropy_cache_name="/boot/entropy" # Set this to the name of the file entropy_cache_type="boot_entropy_cache" # Required for the kernel to find # the boot-time entropy cache. This # must not change value even if the # _name above does change! entropy_efi_seed="YES" # Set this to NO to disable loading # entropy from the UEFI hardware random number generator API ### RAM Blacklist configuration ############################ ram_blacklist_load="NO" # Set this to YES to load a file # containing a list of addresses to # exclude from the running system. ram_blacklist_name="/boot/blacklist.txt" # Set this to the name of the file ram_blacklist_type="ram_blacklist" # Required for the kernel to find # the blacklist module ### Microcode loading configuration ######################## cpu_microcode_load="NO" # Set this to YES to load and apply a # microcode update file during boot. cpu_microcode_name="/boot/firmware/ucode.bin" # Set this to the microcode # update file path. cpu_microcode_type="cpu_microcode" # Required for the kernel to find # the microcode update file. ### ACPI settings ########################################## acpi_dsdt_load="NO" # DSDT Overriding acpi_dsdt_type="acpi_dsdt" # Don't change this acpi_dsdt_name="/boot/acpi_dsdt.aml" # Override DSDT in BIOS by this file acpi_video_load="NO" # Load the ACPI video extension driver ### Audit settings ######################################### audit_event_load="NO" # Preload audit_event config audit_event_name="/etc/security/audit_event" audit_event_type="etc_security_audit_event" ### Initial memory disk settings ########################### #mdroot_load="YES" # The "mdroot" prefix is arbitrary. #mdroot_type="md_image" # Create md(4) disk at boot. #mdroot_name="/boot/root.img" # Path to a file containing the image. #rootdev="ufs:/dev/md0" # Set the root filesystem to md(4) device. ### Loader settings ######################################## #loader_delay="3" # Delay in seconds before loading anything. # Default is unset and disabled (no delay). #autoboot_delay="10" # Delay in seconds before autobooting, # -1 for no user interrupts, NO to disable #password="" # Prevent changes to boot options #bootlock_password="" # Prevent booting (see check-password.4th(8)) #geom_eli_passphrase_prompt="NO" # Prompt for geli(8) passphrase to mount root bootenv_autolist="YES" # Auto populate the list of ZFS Boot Environments #beastie_disable="NO" # Turn the beastie boot menu on and off efi_max_resolution="1x1" # Set the max resolution for EFI loader to use: - # 480p, 720p, 1080p, 2160p/4k, 5k, or specify + # 480p, 720p, 1080p, 1440p, 2160p/4k, 5k, or # WidthxHeight (e.g. 1920x1080) #kernels="kernel kernel.old" # Kernels to display in the boot menu kernels_autodetect="YES" # Auto-detect kernel directories in /boot #loader_logo="orbbw" # Desired logo: orbbw, orb, fbsdbw, beastiebw, beastie, none #comconsole_speed="115200" # Set the current serial console speed #console="vidconsole" # A comma separated list of console(s) #currdev="disk1s1a" # Set the current device module_path="/boot/modules;/boot/dtb;/boot/dtb/overlays" # Set the module search path module_blacklist="drm drm2 radeonkms i915kms amdgpu" # Loader module blacklist #prompt="\\${interpret}" # Set the command prompt #root_disk_unit="0" # Force the root disk unit number #rootdev="disk1s1a" # Set the root filesystem #dumpdev="disk1s1b" # Set a dump device early in the boot process #tftp.blksize="1428" # Set the RFC 2348 TFTP block size. # If the TFTP server does not support RFC 2348, # the block size is set to 512. Valid: (8,9007) #twiddle_divisor="16" # >16 slows down the progress indicator; # <16 speeds up the progress indicator. ### Kernel settings ######################################## # The following boot_ variables are enabled by setting them to any value. # Their presence in the kernel environment (see kenv(1)) has the same # effect as setting the given boot flag (see boot(8)). #boot_askname="" # -a: Prompt the user for the name of the root device #boot_cdrom="" # -C: Attempt to mount root file system from CD-ROM #boot_ddb="" # -d: Instructs the kernel to start in the DDB debugger #boot_dfltroot="" # -r: Use the statically configured root file system #boot_gdb="" # -g: Selects gdb-remote mode for the kernel debugger #boot_multicons="" # -D: Use multiple consoles #boot_mute="" # -m: Mute the console #boot_pause="" # -p: Pause after each line during device probing #boot_serial="" # -h: Use serial console #boot_single="" # -s: Start system in single-user mode #boot_verbose="" # -v: Causes extra debugging information to be printed #init_path="/sbin/init:/sbin/oinit:/sbin/init.bak:/rescue/init" # Sets the list of init candidates #init_shell="/bin/sh" # The shell binary used by init(8). #init_script="" # Initial script to run by init(8) before chrooting. #init_chroot="" # Directory for init(8) to chroot into. ### Kernel tunables ######################################## #hw.physmem="1G" # Limit physical memory. See loader(8) #kern.dfldsiz="" # Set the initial data size limit #kern.dflssiz="" # Set the initial stack size limit #kern.hz="100" # Set the kernel interval timer rate #kern.maxbcache="" # Set the max buffer cache KVA storage #kern.maxdsiz="" # Set the max data size #kern.maxfiles="" # Set the sys. wide open files limit #kern.maxproc="" # Set the maximum # of processes #kern.maxssiz="" # Set the max stack size #kern.maxswzone="" # Set the max swmeta KVA storage #kern.maxtsiz="" # Set the max text size #kern.maxusers="32" # Set size of various static tables #kern.msgbufsize="65536" # Set size of kernel message buffer #kern.nbuf="" # Set the number of buffer headers #kern.ncallout="" # Set the maximum # of timer events #kern.ngroups="1023" # Set the maximum # of supplemental groups #kern.sgrowsiz="" # Set the amount to grow stack #kern.cam.boot_delay="10000" # Delay (in ms) of root mount for CAM bus # registration, useful for USB sticks as root #kern.cam.scsi_delay="2000" # Delay (in ms) before probing SCSI #kern.ipc.maxsockets="" # Set the maximum number of sockets available #kern.ipc.nmbclusters="" # Set the number of mbuf clusters #kern.ipc.nsfbufs="" # Set the number of sendfile(2) bufs #net.inet.tcp.tcbhashsize="" # Set the value of TCBHASHSIZE #vfs.root.mountfrom="" # Specify root partition #vm.kmem_size="" # Sets the size of kernel memory (bytes) #debug.kdb.break_to_debugger="0" # Allow console to break into debugger. #debug.ktr.cpumask="0xf" # Bitmask of CPUs to enable KTR on #debug.ktr.mask="0x1200" # Bitmask of KTR events to enable #debug.ktr.verbose="1" # Enable console dump of KTR events ### Module loading syntax example ########################## #module_load="YES" # loads module "module" #module_name="realname" # uses "realname" instead of "module" #module_type="type" # passes "-t type" to load #module_flags="flags" # passes "flags" to the module #module_before="cmd" # executes "cmd" before loading the module #module_after="cmd" # executes "cmd" after loading the module #module_error="cmd" # executes "cmd" if load fails diff --git a/stand/defaults/loader.conf.5 b/stand/defaults/loader.conf.5 index 8b7508c8a5b2..42e5712d93b8 100644 --- a/stand/defaults/loader.conf.5 +++ b/stand/defaults/loader.conf.5 @@ -1,458 +1,459 @@ .\" Copyright (c) 1999 Daniel C. Sobral .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. -.Dd December 20, 2023 +.Dd January 10, 2024 .Dt LOADER.CONF 5 .Os .Sh NAME .Nm loader.conf .Nd "system bootstrap configuration information" .Sh DESCRIPTION The file .Nm contains descriptive information on bootstrapping the system. Through it you can specify the kernel to be booted, parameters to be passed to it, and additional modules to be loaded; and generally set all variables described in .Xr loader 8 . .Sh SYNTAX Though .Nm Ns 's format was defined explicitly to resemble .Xr rc.conf 5 , and can be sourced by .Xr sh 1 , some settings are treated in a special fashion. Also, the behavior of some settings is defined by the setting's suffix; the prefix identifies which module the setting controls. .Pp The general parsing rules are: .Bl -bullet .It Spaces and empty lines are ignored. .It A # sign will mark the remainder of the line as a comment. .It Only one setting can be present on each line. .El .Pp All settings have the following format: .Pp .Dl variable="value" .Pp Unless it belongs to one of the classes of settings that receive special treatment, a setting will set the value of a .Xr loader 8 environment variable. The settings that receive special treatment are listed below. Settings beginning with .Qq * below define the modules to be loaded and may have any prefix; the prefix identifies a module. All such settings sharing a common prefix refer to the same module. .Bl -tag -width Ar .It Ar autoboot_delay Delay in seconds before automatically booting. A user with console access will be able to interrupt the .Ic autoboot process and escape into the interactive mode by pressing a key on the console during this delay. .Pp If set to .Dq Li NO , no .Ic autoboot is automatically attempted after processing .Pa /boot/loader.rc , though explicit .Ic autoboot Ns 's are processed normally, using a 10 second delay. .Pp If set to .Dq Li 0 , no delay is inserted, but any keys pressed while the kernel and modules are loaded will enter interactive mode. .Pp If set to .Dq Li -1 , no delay will be inserted and .Nm starts interactive mode only if .Ic autoboot has failed. In combination with the .Va beastie_disable option, this option prevents users with console access from being able to interrupt the .Ic autoboot process and escape to the loader prompt. To use the .Va autoboot_delay option in this manner, .Va beastie_disable must be set to .Dq Li YES . .It Ar exec Immediately executes a .Xr loader 8 command. This type of setting cannot be processed by programs other than .Xr loader 8 , so its use should be avoided. Multiple instances of it will be processed independently. .It Ar loader_conf_dirs Space separated list of directories to process for configuration files. The lua-based loader will process files with a .Dq .conf suffix that are placed in these directories. .It Ar loader_conf_files Defines additional configuration files to be processed right after the present file. .Ar loader_conf_files should be treated as write-only. One cannot depend on any value remaining in the loader environment or carried over into the kernel environment. .It Ar kernel Name of the kernel to be loaded. If no kernel name is set, no additional modules will be loaded. The name must be a subdirectory of .Pa /boot that contains a kernel. .It Ar kernel_options Flags to be passed to the kernel. .It Ar vfs.root.mountfrom Specify the root partition to mount. For example: .Pp .Dl vfs.root.mountfrom="ufs:/dev/da0s1a" .Pp .Xr loader 8 automatically calculates the value of this tunable from .Pa /etc/fstab from the partition the kernel was loaded from. The calculated value might be calculated incorrectly when .Pa /etc/fstab is not available during .Xr loader 8 startup (as during diskless booting from NFS), or if a different device is desired by the user. The preferred value can be set in .Pa /loader.conf . .Pp The value can also be overridden from the .Xr loader 8 command line. This is useful for system recovery when .Pa /etc/fstab is damaged, lost, or read from the wrong partition. .It Ar password Protect boot menu with a password without interrupting .Ic autoboot process. The password should be in clear text format. If a password is set, boot menu will not appear until any key is pressed during countdown period specified by .Va autoboot_delay variable or .Ic autoboot process fails. In both cases user should provide specified password to be able to access boot menu. .It Ar bootlock_password Provides a password to be required by check-password before execution is allowed to continue. The password should be in clear text format. If a password is set, the user must provide specified password to boot. .It Ar verbose_loading If set to .Dq YES , module names will be displayed as they are loaded. .It Ar module_blacklist Blacklist of modules. Modules specified in the blacklist may not be loaded automatically with a .Ar *_load directive, but they may be loaded directly at the .Xr loader 8 prompt. Blacklisted modules may still be loaded indirectly as dependencies of other modules. .It Ar *_load If set to .Dq YES , that module will be loaded. If no name is defined (see below), the module's name is taken to be the same as the prefix. .It Ar *_name Defines the name of the module. .It Ar *_type Defines the module's type. If none is given, it defaults to a kld module. .It Ar *_flags Flags and parameters to be passed to the module. .It Ar *_before Commands to be executed before the module is loaded. Use of this setting should be avoided. .It Ar *_after Commands to be executed after the module is loaded. Use of this setting should be avoided. .It Ar *_error Commands to be executed if the loading of a module fails. Except for the special value .Dq abort , which aborts the bootstrap process, use of this setting should be avoided. .El .Pp .Em WARNING : developers should never use these suffixes for any kernel environment variables (tunables) or conflicts will result. .Sh DEFAULT SETTINGS Most of .Nm Ns 's default settings can be ignored. The few of them which are important or useful are: .Bl -tag -width bootfile -offset indent .It Va bitmap_load .Pq Dq NO If set to .Dq YES , a bitmap will be loaded to be displayed on screen while booting. .It Va bitmap_name .Pq Dq Pa /boot/splash.bmp Name of the bitmap to be loaded. Any other name can be used. .It Va comconsole_speed .Dq ( 115200 or the value of the .Va BOOT_COMCONSOLE_SPEED variable when .Xr loader 8 was compiled). Sets the speed of the serial console. If the previous boot loader stage specified that a serial console is in use then the default speed is determined from the current serial port speed setting. .It Va console .Pq Dq vidconsole .Dq comconsole selects serial console, .Dq vidconsole selects the video console, .Dq efi selects the EFI console, .Dq nullconsole selects a mute console (useful for systems with neither a video console nor a serial port), and .Dq spinconsole selects the video console which prevents any input and hides all output replacing it with .Dq spinning character (useful for embedded products and such). .It Va screen.font Set font size for framebuffer mode. Default font size is selected based on screen resolution, to achieve terminal dimensions 80x24. .It Va screen.textmode Value .Dq 0 will trigger BIOS loader to switch to use VESA BIOS Extension (VBE) frame buffer mode for console. The same effect can be achieved by setting .Va vbe_max_resolution . .Pp Value .Dq 1 will force BIOS loader to use VGA text mode. .Pp If .Va vbe_max_resolution is not set, the loader will try to set screen resolution based on EDID information. If EDID is not available, the default resolution is 800x600 (if available). .It Va screen.height .It Va screen.width .It Va screen.depth .Va screen.height , .Va screen.width , .Va screen.depth are set by loader when loader is using framebuffer mode to draw the screen. .It Va efi_max_resolution .It Va vbe_max_resolution Specify the maximum desired resolution for the EFI or VBE framebuffer console. The following values are accepted: .Bl -column "WidthxHeight" .It Sy Value Ta Sy Resolution .It 480p Ta 640x480 .It 720p Ta 1280x720 .It 1080p Ta 1920x1080 +.It 1440p Ta 2560x1440 .It 2160p Ta 3840x2160 .It 4k Ta 3840x2160 .It 5k Ta 5120x2880 .It Va Width Ns x Ns Va Height Ta Va Width Ns x Ns Va Height .El .It Va kernel .Pq Dq kernel .It Va kernels .Pq Dq kernel kernel.old Space or comma separated list of kernels to present in the boot menu. .It Va loader_conf_files .Pq Dq Pa /boot/loader.conf /boot/loader.conf.local .It Va loader_conf_dirs .Pq Dq Pa /boot/loader.conf.d .It Va splash_bmp_load .Pq Dq NO If set to .Dq YES , will load the splash screen module, making it possible to display a bmp image on the screen while booting. .It Va splash_pcx_load .Pq Dq NO If set to .Dq YES , will load the splash screen module, making it possible to display a pcx image on the screen while booting. .It Va vesa_load .Pq Dq NO If set to .Dq YES , the vesa module will be loaded, enabling bitmaps above VGA resolution to be displayed. .It Va beastie_disable If set to .Dq YES , the beastie boot menu will be skipped. .It Va loader_logo Pq Dq Li orbbw Selects a desired logo in the beastie boot menu. Possible values are: .Dq Li orbbw , .Dq Li orb , .Dq Li fbsdbw , .Dq Li beastiebw , .Dq Li beastie , and .Dq Li none . .It Va loader_color If set to .Dq NO , the beastie boot menu will be displayed without ANSI coloring. .It Va entropy_cache_load .Pq Dq YES If set to .Dq NO , the very early boot-time entropy file will not be loaded. See the entropy entries in .Xr rc.conf 5 . .It Va entropy_cache_name .Pq Dq /boot/entropy The name of the very early boot-time entropy cache file. .It Va cpu_microcode_load .Pq Dq NO If set to .Dq YES , the microcode update file specified by .Va cpu_microcode_name will be loaded and applied very early during boot. This provides functionality similar to .Xr cpucontrol 8 but ensures that CPU features enabled by microcode updates can be used by the kernel. The update will be re-applied automatically when resuming from an ACPI sleep state. If the update file contains updates for multiple processor models, the kernel will search for and extract a matching update. Currently this setting is supported only on Intel .Dv i386 and .Dv amd64 processors. It has no effect on other processor types. .It Va cpu_microcode_name A path to a microcode update file. .El .Sh OTHER SETTINGS Other settings that may be used in .Nm that have no default value: .Bl -tag -width bootfile -offset indent .It Va fdt_overlays Specifies a comma-delimited list of FDT overlays to apply. .Pa /boot/dtb/overlays is created by default for overlays to be placed in. .It Va kernels_autodetect If set to .Dq YES , attempt to auto-detect kernels installed in .Pa /boot . This is an option specific to the Lua-based loader. It is not available in the default Forth-based loader. .El .Sh FILES .Bl -tag -width /boot/defaults/loader.conf -compact .It Pa /boot/defaults/loader.conf default settings \(em do not change this file. .It Pa /boot/loader.conf user defined settings. .It Pa /boot/loader.conf.lua user defined settings written in lua. .It Pa /boot/loader.conf.local machine-specific settings for sites with a common loader.conf. .El .Sh SEE ALSO .Xr kenv 1 , .Xr loader.conf.lua 5 , .Xr rc.conf 5 , .Xr boot 8 , .Xr cpucontrol 8 , .Xr loader 8 , .Xr loader.4th 8 .Sh HISTORY The file .Nm first appeared in .Fx 3.2 . .Sh AUTHORS This manual page was written by .An Daniel C. Sobral Aq dcs@FreeBSD.org . .Sh BUGS The .Xr loader 8 stops reading .Nm when it encounters a syntax error, so any options which are vital for booting a particular system (i.e., .Dq Va hw.ata.ata_dma Ns "=0" ) should precede any experimental additions to .Nm . diff --git a/stand/efi/loader/framebuffer.c b/stand/efi/loader/framebuffer.c index b8e61dc73acf..56693187b576 100644 --- a/stand/efi/loader/framebuffer.c +++ b/stand/efi/loader/framebuffer.c @@ -1,954 +1,959 @@ /*- * Copyright (c) 2013 The FreeBSD Foundation * * This software was developed by Benno Rice under sponsorship from * the FreeBSD Foundation. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "bootstrap.h" #include "framebuffer.h" static EFI_GUID conout_guid = EFI_CONSOLE_OUT_DEVICE_GUID; EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; static EFI_GUID pciio_guid = EFI_PCI_IO_PROTOCOL_GUID; static EFI_GUID uga_guid = EFI_UGA_DRAW_PROTOCOL_GUID; static EFI_GUID active_edid_guid = EFI_EDID_ACTIVE_PROTOCOL_GUID; static EFI_GUID discovered_edid_guid = EFI_EDID_DISCOVERED_PROTOCOL_GUID; static EFI_HANDLE gop_handle; /* Cached EDID. */ struct vesa_edid_info *edid_info = NULL; static EFI_GRAPHICS_OUTPUT *gop; static EFI_UGA_DRAW_PROTOCOL *uga; static struct named_resolution { const char *name; const char *alias; unsigned int width; unsigned int height; } resolutions[] = { { .name = "480p", .width = 640, .height = 480, }, { .name = "720p", .width = 1280, .height = 720, }, { .name = "1080p", .width = 1920, .height = 1080, }, + { + .name = "1440p", + .width = 2560, + .height = 1440, + }, { .name = "2160p", .alias = "4k", .width = 3840, .height = 2160, }, { .name = "5k", .width = 5120, .height = 2880, } }; static u_int efifb_color_depth(struct efi_fb *efifb) { uint32_t mask; u_int depth; mask = efifb->fb_mask_red | efifb->fb_mask_green | efifb->fb_mask_blue | efifb->fb_mask_reserved; if (mask == 0) return (0); for (depth = 1; mask != 1; depth++) mask >>= 1; return (depth); } static int efifb_mask_from_pixfmt(struct efi_fb *efifb, EFI_GRAPHICS_PIXEL_FORMAT pixfmt, EFI_PIXEL_BITMASK *pixinfo) { int result; result = 0; switch (pixfmt) { case PixelRedGreenBlueReserved8BitPerColor: case PixelBltOnly: efifb->fb_mask_red = 0x000000ff; efifb->fb_mask_green = 0x0000ff00; efifb->fb_mask_blue = 0x00ff0000; efifb->fb_mask_reserved = 0xff000000; break; case PixelBlueGreenRedReserved8BitPerColor: efifb->fb_mask_red = 0x00ff0000; efifb->fb_mask_green = 0x0000ff00; efifb->fb_mask_blue = 0x000000ff; efifb->fb_mask_reserved = 0xff000000; break; case PixelBitMask: efifb->fb_mask_red = pixinfo->RedMask; efifb->fb_mask_green = pixinfo->GreenMask; efifb->fb_mask_blue = pixinfo->BlueMask; efifb->fb_mask_reserved = pixinfo->ReservedMask; break; default: result = 1; break; } return (result); } static int efifb_from_gop(struct efi_fb *efifb, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info) { int result; efifb->fb_addr = mode->FrameBufferBase; efifb->fb_size = mode->FrameBufferSize; efifb->fb_height = info->VerticalResolution; efifb->fb_width = info->HorizontalResolution; efifb->fb_stride = info->PixelsPerScanLine; result = efifb_mask_from_pixfmt(efifb, info->PixelFormat, &info->PixelInformation); return (result); } static ssize_t efifb_uga_find_pixel(EFI_UGA_DRAW_PROTOCOL *uga, u_int line, EFI_PCI_IO_PROTOCOL *pciio, uint64_t addr, uint64_t size) { EFI_UGA_PIXEL pix0, pix1; uint8_t *data1, *data2; size_t count, maxcount = 1024; ssize_t ofs; EFI_STATUS status; u_int idx; status = uga->Blt(uga, &pix0, EfiUgaVideoToBltBuffer, 0, line, 0, 0, 1, 1, 0); if (EFI_ERROR(status)) { printf("UGA BLT operation failed (video->buffer)"); return (-1); } pix1.Red = ~pix0.Red; pix1.Green = ~pix0.Green; pix1.Blue = ~pix0.Blue; pix1.Reserved = 0; data1 = calloc(maxcount, 2); if (data1 == NULL) { printf("Unable to allocate memory"); return (-1); } data2 = data1 + maxcount; ofs = 0; while (size > 0) { count = min(size, maxcount); status = pciio->Mem.Read(pciio, EfiPciIoWidthUint32, EFI_PCI_IO_PASS_THROUGH_BAR, addr + ofs, count >> 2, data1); if (EFI_ERROR(status)) { printf("Error reading frame buffer (before)"); goto fail; } status = uga->Blt(uga, &pix1, EfiUgaBltBufferToVideo, 0, 0, 0, line, 1, 1, 0); if (EFI_ERROR(status)) { printf("UGA BLT operation failed (modify)"); goto fail; } status = pciio->Mem.Read(pciio, EfiPciIoWidthUint32, EFI_PCI_IO_PASS_THROUGH_BAR, addr + ofs, count >> 2, data2); if (EFI_ERROR(status)) { printf("Error reading frame buffer (after)"); goto fail; } status = uga->Blt(uga, &pix0, EfiUgaBltBufferToVideo, 0, 0, 0, line, 1, 1, 0); if (EFI_ERROR(status)) { printf("UGA BLT operation failed (restore)"); goto fail; } for (idx = 0; idx < count; idx++) { if (data1[idx] != data2[idx]) { free(data1); return (ofs + (idx & ~3)); } } ofs += count; size -= count; } printf("No change detected in frame buffer"); fail: printf(" -- error %lu\n", EFI_ERROR_CODE(status)); free(data1); return (-1); } static EFI_PCI_IO_PROTOCOL * efifb_uga_get_pciio(void) { EFI_PCI_IO_PROTOCOL *pciio; EFI_HANDLE *buf, *hp; EFI_STATUS status; UINTN bufsz; /* Get all handles that support the UGA protocol. */ bufsz = 0; status = BS->LocateHandle(ByProtocol, &uga_guid, NULL, &bufsz, NULL); if (status != EFI_BUFFER_TOO_SMALL) return (NULL); buf = malloc(bufsz); status = BS->LocateHandle(ByProtocol, &uga_guid, NULL, &bufsz, buf); if (status != EFI_SUCCESS) { free(buf); return (NULL); } bufsz /= sizeof(EFI_HANDLE); /* Get the PCI I/O interface of the first handle that supports it. */ pciio = NULL; for (hp = buf; hp < buf + bufsz; hp++) { status = OpenProtocolByHandle(*hp, &pciio_guid, (void **)&pciio); if (status == EFI_SUCCESS) { free(buf); return (pciio); } } free(buf); return (NULL); } static EFI_STATUS efifb_uga_locate_framebuffer(EFI_PCI_IO_PROTOCOL *pciio, uint64_t *addrp, uint64_t *sizep) { uint8_t *resattr; uint64_t addr, size; EFI_STATUS status; u_int bar; if (pciio == NULL) return (EFI_DEVICE_ERROR); /* Attempt to get the frame buffer address (imprecise). */ *addrp = 0; *sizep = 0; for (bar = 0; bar < 6; bar++) { status = pciio->GetBarAttributes(pciio, bar, NULL, (void **)&resattr); if (status != EFI_SUCCESS) continue; /* XXX magic offsets and constants. */ if (resattr[0] == 0x87 && resattr[3] == 0) { /* 32-bit address space descriptor (MEMIO) */ addr = le32dec(resattr + 10); size = le32dec(resattr + 22); } else if (resattr[0] == 0x8a && resattr[3] == 0) { /* 64-bit address space descriptor (MEMIO) */ addr = le64dec(resattr + 14); size = le64dec(resattr + 38); } else { addr = 0; size = 0; } BS->FreePool(resattr); if (addr == 0 || size == 0) continue; /* We assume the largest BAR is the frame buffer. */ if (size > *sizep) { *addrp = addr; *sizep = size; } } return ((*addrp == 0 || *sizep == 0) ? EFI_DEVICE_ERROR : 0); } static int efifb_from_uga(struct efi_fb *efifb) { EFI_PCI_IO_PROTOCOL *pciio; char *ev, *p; EFI_STATUS status; ssize_t offset; uint64_t fbaddr; uint32_t horiz, vert, stride; uint32_t np, depth, refresh; status = uga->GetMode(uga, &horiz, &vert, &depth, &refresh); if (EFI_ERROR(status)) return (1); efifb->fb_height = vert; efifb->fb_width = horiz; /* Paranoia... */ if (efifb->fb_height == 0 || efifb->fb_width == 0) return (1); /* The color masks are fixed AFAICT. */ efifb_mask_from_pixfmt(efifb, PixelBlueGreenRedReserved8BitPerColor, NULL); /* pciio can be NULL on return! */ pciio = efifb_uga_get_pciio(); /* Try to find the frame buffer. */ status = efifb_uga_locate_framebuffer(pciio, &efifb->fb_addr, &efifb->fb_size); if (EFI_ERROR(status)) { efifb->fb_addr = 0; efifb->fb_size = 0; } /* * There's no reliable way to detect the frame buffer or the * offset within the frame buffer of the visible region, nor * the stride. Our only option is to look at the system and * fill in the blanks based on that. Luckily, UGA was mostly * only used on Apple hardware. */ offset = -1; ev = getenv("smbios.system.maker"); if (ev != NULL && !strcmp(ev, "Apple Inc.")) { ev = getenv("smbios.system.product"); if (ev != NULL && !strcmp(ev, "iMac7,1")) { /* These are the expected values we should have. */ horiz = 1680; vert = 1050; fbaddr = 0xc0000000; /* These are the missing bits. */ offset = 0x10000; stride = 1728; } else if (ev != NULL && !strcmp(ev, "MacBook3,1")) { /* These are the expected values we should have. */ horiz = 1280; vert = 800; fbaddr = 0xc0000000; /* These are the missing bits. */ offset = 0x0; stride = 2048; } } /* * If this is hardware we know, make sure that it looks familiar * before we accept our hardcoded values. */ if (offset >= 0 && efifb->fb_width == horiz && efifb->fb_height == vert && efifb->fb_addr == fbaddr) { efifb->fb_addr += offset; efifb->fb_size -= offset; efifb->fb_stride = stride; return (0); } else if (offset >= 0) { printf("Hardware make/model known, but graphics not " "as expected.\n"); printf("Console may not work!\n"); } /* * The stride is equal or larger to the width. Often it's the * next larger power of two. We'll start with that... */ efifb->fb_stride = efifb->fb_width; do { np = efifb->fb_stride & (efifb->fb_stride - 1); if (np) { efifb->fb_stride |= (np - 1); efifb->fb_stride++; } } while (np); ev = getenv("hw.efifb.address"); if (ev == NULL) { if (efifb->fb_addr == 0) { printf("Please set hw.efifb.address and " "hw.efifb.stride.\n"); return (1); } /* * The visible part of the frame buffer may not start at * offset 0, so try to detect it. Note that we may not * always be able to read from the frame buffer, which * means that we may not be able to detect anything. In * that case, we would take a long time scanning for a * pixel change in the frame buffer, which would have it * appear that we're hanging, so we limit the scan to * 1/256th of the frame buffer. This number is mostly * based on PR 202730 and the fact that on a MacBoook, * where we can't read from the frame buffer the offset * of the visible region is 0. In short: we want to scan * enough to handle all adapters that have an offset * larger than 0 and we want to scan as little as we can * to not appear to hang when we can't read from the * frame buffer. */ offset = efifb_uga_find_pixel(uga, 0, pciio, efifb->fb_addr, efifb->fb_size >> 8); if (offset == -1) { printf("Unable to reliably detect frame buffer.\n"); } else if (offset > 0) { efifb->fb_addr += offset; efifb->fb_size -= offset; } } else { offset = 0; efifb->fb_size = efifb->fb_height * efifb->fb_stride * 4; efifb->fb_addr = strtoul(ev, &p, 0); if (*p != '\0') return (1); } ev = getenv("hw.efifb.stride"); if (ev == NULL) { if (pciio != NULL && offset != -1) { /* Determine the stride. */ offset = efifb_uga_find_pixel(uga, 1, pciio, efifb->fb_addr, horiz * 8); if (offset != -1) efifb->fb_stride = offset >> 2; } else { printf("Unable to reliably detect the stride.\n"); } } else { efifb->fb_stride = strtoul(ev, &p, 0); if (*p != '\0') return (1); } /* * We finalized on the stride, so recalculate the size of the * frame buffer. */ efifb->fb_size = efifb->fb_height * efifb->fb_stride * 4; return (0); } /* * Fetch EDID info. Caller must free the buffer. */ static struct vesa_edid_info * efifb_gop_get_edid(EFI_HANDLE h) { const uint8_t magic[] = EDID_MAGIC; EFI_EDID_ACTIVE_PROTOCOL *edid; struct vesa_edid_info *edid_infop; EFI_GUID *guid; EFI_STATUS status; size_t size; guid = &active_edid_guid; status = BS->OpenProtocol(h, guid, (void **)&edid, IH, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (status != EFI_SUCCESS || edid->SizeOfEdid == 0) { guid = &discovered_edid_guid; status = BS->OpenProtocol(h, guid, (void **)&edid, IH, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (status != EFI_SUCCESS || edid->SizeOfEdid == 0) return (NULL); } size = MAX(sizeof(*edid_infop), edid->SizeOfEdid); edid_infop = calloc(1, size); if (edid_infop == NULL) return (NULL); memcpy(edid_infop, edid->Edid, edid->SizeOfEdid); /* Validate EDID */ if (memcmp(edid_infop, magic, sizeof (magic)) != 0) goto error; if (edid_infop->header.version != 1) goto error; return (edid_infop); error: free(edid_infop); return (NULL); } static bool efifb_get_edid(edid_res_list_t *res) { bool rv = false; if (edid_info == NULL) edid_info = efifb_gop_get_edid(gop_handle); if (edid_info != NULL) rv = gfx_get_edid_resolution(edid_info, res); return (rv); } bool efi_has_gop(void) { EFI_STATUS status; EFI_HANDLE *hlist; UINTN hsize; hsize = 0; hlist = NULL; status = BS->LocateHandle(ByProtocol, &gop_guid, NULL, &hsize, hlist); return (status == EFI_BUFFER_TOO_SMALL); } int efi_find_framebuffer(teken_gfx_t *gfx_state) { EFI_HANDLE *hlist; UINTN nhandles, i, hsize; struct efi_fb efifb; EFI_STATUS status; int rv; gfx_state->tg_fb_type = FB_TEXT; hsize = 0; hlist = NULL; status = BS->LocateHandle(ByProtocol, &gop_guid, NULL, &hsize, hlist); if (status == EFI_BUFFER_TOO_SMALL) { hlist = malloc(hsize); if (hlist == NULL) return (ENOMEM); status = BS->LocateHandle(ByProtocol, &gop_guid, NULL, &hsize, hlist); if (EFI_ERROR(status)) free(hlist); } if (EFI_ERROR(status)) return (efi_status_to_errno(status)); nhandles = hsize / sizeof(*hlist); /* * Search for ConOut protocol, if not found, use first handle. */ gop_handle = NULL; for (i = 0; i < nhandles; i++) { EFI_GRAPHICS_OUTPUT *tgop; void *dummy; status = OpenProtocolByHandle(hlist[i], &gop_guid, (void **)&tgop); if (status != EFI_SUCCESS) continue; if (tgop->Mode->Info->PixelFormat == PixelBltOnly || tgop->Mode->Info->PixelFormat >= PixelFormatMax) continue; status = OpenProtocolByHandle(hlist[i], &conout_guid, &dummy); if (status == EFI_SUCCESS) { gop_handle = hlist[i]; gop = tgop; break; } else if (gop_handle == NULL) { gop_handle = hlist[i]; gop = tgop; } } free(hlist); if (gop_handle != NULL) { gfx_state->tg_fb_type = FB_GOP; gfx_state->tg_private = gop; if (edid_info == NULL) edid_info = efifb_gop_get_edid(gop_handle); } else { status = BS->LocateProtocol(&uga_guid, NULL, (VOID **)&uga); if (status == EFI_SUCCESS) { gfx_state->tg_fb_type = FB_UGA; gfx_state->tg_private = uga; } else { return (1); } } switch (gfx_state->tg_fb_type) { case FB_GOP: rv = efifb_from_gop(&efifb, gop->Mode, gop->Mode->Info); break; case FB_UGA: rv = efifb_from_uga(&efifb); break; default: return (1); } gfx_state->tg_fb.fb_addr = efifb.fb_addr; gfx_state->tg_fb.fb_size = efifb.fb_size; gfx_state->tg_fb.fb_height = efifb.fb_height; gfx_state->tg_fb.fb_width = efifb.fb_width; gfx_state->tg_fb.fb_stride = efifb.fb_stride; gfx_state->tg_fb.fb_mask_red = efifb.fb_mask_red; gfx_state->tg_fb.fb_mask_green = efifb.fb_mask_green; gfx_state->tg_fb.fb_mask_blue = efifb.fb_mask_blue; gfx_state->tg_fb.fb_mask_reserved = efifb.fb_mask_reserved; gfx_state->tg_fb.fb_bpp = fls(efifb.fb_mask_red | efifb.fb_mask_green | efifb.fb_mask_blue | efifb.fb_mask_reserved); if (gfx_state->tg_shadow_fb != NULL) BS->FreePages((EFI_PHYSICAL_ADDRESS)gfx_state->tg_shadow_fb, gfx_state->tg_shadow_sz); gfx_state->tg_shadow_sz = EFI_SIZE_TO_PAGES(efifb.fb_height * efifb.fb_width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); status = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, gfx_state->tg_shadow_sz, (EFI_PHYSICAL_ADDRESS *)&gfx_state->tg_shadow_fb); if (status != EFI_SUCCESS) gfx_state->tg_shadow_fb = NULL; return (0); } static void print_efifb(int mode, struct efi_fb *efifb, int verbose) { u_int depth; if (mode >= 0) printf("mode %d: ", mode); depth = efifb_color_depth(efifb); printf("%ux%ux%u, stride=%u", efifb->fb_width, efifb->fb_height, depth, efifb->fb_stride); if (verbose) { printf("\n frame buffer: address=%jx, size=%jx", (uintmax_t)efifb->fb_addr, (uintmax_t)efifb->fb_size); printf("\n color mask: R=%08x, G=%08x, B=%08x\n", efifb->fb_mask_red, efifb->fb_mask_green, efifb->fb_mask_blue); } } static bool efi_resolution_compare(struct named_resolution *res, const char *cmp) { if (strcasecmp(res->name, cmp) == 0) return (true); if (res->alias != NULL && strcasecmp(res->alias, cmp) == 0) return (true); return (false); } static void efi_get_max_resolution(int *width, int *height) { struct named_resolution *res; char *maxres; char *height_start, *width_start; int idx; *width = *height = 0; maxres = getenv("efi_max_resolution"); /* No max_resolution set? Bail out; choose highest resolution */ if (maxres == NULL) return; /* See if it matches one of our known resolutions */ for (idx = 0; idx < nitems(resolutions); ++idx) { res = &resolutions[idx]; if (efi_resolution_compare(res, maxres)) { *width = res->width; *height = res->height; return; } } /* Not a known resolution, try to parse it; make a copy we can modify */ maxres = strdup(maxres); if (maxres == NULL) return; height_start = strchr(maxres, 'x'); if (height_start == NULL) { free(maxres); return; } width_start = maxres; *height_start++ = 0; /* Errors from this will effectively mean "no max" */ *width = (int)strtol(width_start, NULL, 0); *height = (int)strtol(height_start, NULL, 0); free(maxres); } static int gop_autoresize(void) { struct efi_fb efifb; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; EFI_STATUS status; UINTN infosz; UINT32 best_mode, currdim, maxdim, mode; int height, max_height, max_width, width; best_mode = maxdim = 0; efi_get_max_resolution(&max_width, &max_height); for (mode = 0; mode < gop->Mode->MaxMode; mode++) { status = gop->QueryMode(gop, mode, &infosz, &info); if (EFI_ERROR(status)) continue; efifb_from_gop(&efifb, gop->Mode, info); width = info->HorizontalResolution; height = info->VerticalResolution; currdim = width * height; if (currdim > maxdim) { if ((max_width != 0 && width > max_width) || (max_height != 0 && height > max_height)) continue; maxdim = currdim; best_mode = mode; } } if (maxdim != 0) { status = gop->SetMode(gop, best_mode); if (EFI_ERROR(status)) { snprintf(command_errbuf, sizeof(command_errbuf), "gop_autoresize: Unable to set mode to %u (error=%lu)", mode, EFI_ERROR_CODE(status)); return (CMD_ERROR); } (void) cons_update_mode(true); } return (CMD_OK); } static int text_autoresize() { SIMPLE_TEXT_OUTPUT_INTERFACE *conout; EFI_STATUS status; UINTN i, max_dim, best_mode, cols, rows; conout = ST->ConOut; max_dim = best_mode = 0; for (i = 0; i < conout->Mode->MaxMode; i++) { status = conout->QueryMode(conout, i, &cols, &rows); if (EFI_ERROR(status)) continue; if (cols * rows > max_dim) { max_dim = cols * rows; best_mode = i; } } if (max_dim > 0) conout->SetMode(conout, best_mode); (void) cons_update_mode(true); return (CMD_OK); } static int uga_autoresize(void) { return (text_autoresize()); } COMMAND_SET(efi_autoresize, "efi-autoresizecons", "EFI Auto-resize Console", command_autoresize); static int command_autoresize(int argc, char *argv[]) { char *textmode; textmode = getenv("hw.vga.textmode"); /* If it's set and non-zero, we'll select a console mode instead */ if (textmode != NULL && strcmp(textmode, "0") != 0) return (text_autoresize()); if (gop != NULL) return (gop_autoresize()); if (uga != NULL) return (uga_autoresize()); snprintf(command_errbuf, sizeof(command_errbuf), "%s: Neither Graphics Output Protocol nor Universal Graphics Adapter present", argv[0]); /* * Default to text_autoresize if we have neither GOP or UGA. This won't * give us the most ideal resolution, but it will at least leave us * functional rather than failing the boot for an objectively bad * reason. */ return (text_autoresize()); } COMMAND_SET(gop, "gop", "graphics output protocol", command_gop); static int command_gop(int argc, char *argv[]) { struct efi_fb efifb; EFI_STATUS status; u_int mode; if (gop == NULL) { snprintf(command_errbuf, sizeof(command_errbuf), "%s: Graphics Output Protocol not present", argv[0]); return (CMD_ERROR); } if (argc < 2) goto usage; if (!strcmp(argv[1], "set")) { char *cp; if (argc != 3) goto usage; mode = strtol(argv[2], &cp, 0); if (cp[0] != '\0') { sprintf(command_errbuf, "mode is an integer"); return (CMD_ERROR); } status = gop->SetMode(gop, mode); if (EFI_ERROR(status)) { snprintf(command_errbuf, sizeof(command_errbuf), "%s: Unable to set mode to %u (error=%lu)", argv[0], mode, EFI_ERROR_CODE(status)); return (CMD_ERROR); } (void) cons_update_mode(true); } else if (strcmp(argv[1], "off") == 0) { (void) cons_update_mode(false); } else if (strcmp(argv[1], "get") == 0) { edid_res_list_t res; if (argc != 2) goto usage; TAILQ_INIT(&res); efifb_from_gop(&efifb, gop->Mode, gop->Mode->Info); if (efifb_get_edid(&res)) { struct resolution *rp; printf("EDID"); while ((rp = TAILQ_FIRST(&res)) != NULL) { printf(" %dx%d", rp->width, rp->height); TAILQ_REMOVE(&res, rp, next); free(rp); } printf("\n"); } else { printf("no EDID information\n"); } print_efifb(gop->Mode->Mode, &efifb, 1); printf("\n"); } else if (!strcmp(argv[1], "list")) { EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; UINTN infosz; if (argc != 2) goto usage; pager_open(); for (mode = 0; mode < gop->Mode->MaxMode; mode++) { status = gop->QueryMode(gop, mode, &infosz, &info); if (EFI_ERROR(status)) continue; efifb_from_gop(&efifb, gop->Mode, info); print_efifb(mode, &efifb, 0); if (pager_output("\n")) break; } pager_close(); } return (CMD_OK); usage: snprintf(command_errbuf, sizeof(command_errbuf), "usage: %s [list | get | set | off]", argv[0]); return (CMD_ERROR); } COMMAND_SET(uga, "uga", "universal graphics adapter", command_uga); static int command_uga(int argc, char *argv[]) { struct efi_fb efifb; if (uga == NULL) { snprintf(command_errbuf, sizeof(command_errbuf), "%s: UGA Protocol not present", argv[0]); return (CMD_ERROR); } if (argc != 1) goto usage; if (efifb_from_uga(&efifb) != CMD_OK) { snprintf(command_errbuf, sizeof(command_errbuf), "%s: Unable to get UGA information", argv[0]); return (CMD_ERROR); } print_efifb(-1, &efifb, 1); printf("\n"); return (CMD_OK); usage: snprintf(command_errbuf, sizeof(command_errbuf), "usage: %s", argv[0]); return (CMD_ERROR); } diff --git a/stand/i386/libi386/vbe.c b/stand/i386/libi386/vbe.c index 8fbfaa9a3475..61339a1e7911 100644 --- a/stand/i386/libi386/vbe.c +++ b/stand/i386/libi386/vbe.c @@ -1,1270 +1,1275 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2009 Jared D. McNeill * All rights reserved. * Copyright 2020 Toomas Soome * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include "libi386.h" #include "vbe.h" /* * VESA BIOS Extensions routines */ static struct vbeinfoblock *vbe; static struct modeinfoblock *vbe_mode; static uint16_t *vbe_mode_list; static size_t vbe_mode_list_size; struct vesa_edid_info *edid_info = NULL; /* The default VGA color palette format is 6 bits per primary color. */ int palette_format = 6; #define VESA_MODE_BASE 0x100 /* * palette array for 8-bit indexed colors. In this case, cmap does store * index and pe8 does store actual RGB. This is needed because we may * not be able to read palette data from hardware. */ struct paletteentry *pe8 = NULL; static struct named_resolution { const char *name; const char *alias; unsigned int width; unsigned int height; } resolutions[] = { { .name = "480p", .width = 640, .height = 480, }, { .name = "720p", .width = 1280, .height = 720, }, { .name = "1080p", .width = 1920, .height = 1080, }, + { + .name = "1440p", + .width = 2560, + .height = 1440, + }, { .name = "2160p", .alias = "4k", .width = 3840, .height = 2160, }, { .name = "5k", .width = 5120, .height = 2880, } }; static bool vbe_resolution_compare(struct named_resolution *res, const char *cmp) { if (strcasecmp(res->name, cmp) == 0) return (true); if (res->alias != NULL && strcasecmp(res->alias, cmp) == 0) return (true); return (false); } static void vbe_get_max_resolution(int *width, int *height) { struct named_resolution *res; char *maxres; char *height_start, *width_start; int idx; *width = *height = 0; maxres = getenv("vbe_max_resolution"); /* No max_resolution set? Bail out; choose highest resolution */ if (maxres == NULL) return; /* See if it matches one of our known resolutions */ for (idx = 0; idx < nitems(resolutions); ++idx) { res = &resolutions[idx]; if (vbe_resolution_compare(res, maxres)) { *width = res->width; *height = res->height; return; } } /* Not a known resolution, try to parse it; make a copy we can modify */ maxres = strdup(maxres); if (maxres == NULL) return; height_start = strchr(maxres, 'x'); if (height_start == NULL) { free(maxres); return; } width_start = maxres; *height_start++ = 0; /* Errors from this will effectively mean "no max" */ *width = (int)strtol(width_start, NULL, 0); *height = (int)strtol(height_start, NULL, 0); free(maxres); } int vga_get_reg(int reg, int index) { return (inb(reg + index)); } int vga_get_atr(int reg, int i) { int ret; (void) inb(reg + VGA_GEN_INPUT_STAT_1); outb(reg + VGA_AC_WRITE, i); ret = inb(reg + VGA_AC_READ); (void) inb(reg + VGA_GEN_INPUT_STAT_1); return (ret); } void vga_set_atr(int reg, int i, int v) { (void) inb(reg + VGA_GEN_INPUT_STAT_1); outb(reg + VGA_AC_WRITE, i); outb(reg + VGA_AC_WRITE, v); (void) inb(reg + VGA_GEN_INPUT_STAT_1); } void vga_set_indexed(int reg, int indexreg, int datareg, uint8_t index, uint8_t val) { outb(reg + indexreg, index); outb(reg + datareg, val); } int vga_get_indexed(int reg, int indexreg, int datareg, uint8_t index) { outb(reg + indexreg, index); return (inb(reg + datareg)); } int vga_get_crtc(int reg, int i) { return (vga_get_indexed(reg, VGA_CRTC_ADDRESS, VGA_CRTC_DATA, i)); } void vga_set_crtc(int reg, int i, int v) { vga_set_indexed(reg, VGA_CRTC_ADDRESS, VGA_CRTC_DATA, i, v); } int vga_get_seq(int reg, int i) { return (vga_get_indexed(reg, VGA_SEQ_ADDRESS, VGA_SEQ_DATA, i)); } void vga_set_seq(int reg, int i, int v) { vga_set_indexed(reg, VGA_SEQ_ADDRESS, VGA_SEQ_DATA, i, v); } int vga_get_grc(int reg, int i) { return (vga_get_indexed(reg, VGA_GC_ADDRESS, VGA_GC_DATA, i)); } void vga_set_grc(int reg, int i, int v) { vga_set_indexed(reg, VGA_GC_ADDRESS, VGA_GC_DATA, i, v); } /* * Return true when this controller is VGA compatible. */ bool vbe_is_vga(void) { if (vbe == NULL) return (false); return ((vbe->Capabilities & VBE_CAP_NONVGA) == 0); } /* Actually assuming mode 3. */ void bios_set_text_mode(int mode) { int atr; if (vbe->Capabilities & VBE_CAP_DAC8) { int m; /* * The mode change should reset the palette format to * 6 bits, but apparently some systems do fail with 8-bit * palette, so we switch to 6-bit here. */ m = 0x0600; (void) biosvbe_palette_format(&m); palette_format = m; } v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = mode; /* set VGA text mode */ v86int(); atr = vga_get_atr(VGA_REG_BASE, VGA_AC_MODE_CONTROL); atr &= ~VGA_AC_MC_BI; atr &= ~VGA_AC_MC_ELG; vga_set_atr(VGA_REG_BASE, VGA_AC_MODE_CONTROL, atr); gfx_state.tg_mode = mode; gfx_state.tg_fb_type = FB_TEXT; gfx_state.tg_fb.fb_height = TEXT_ROWS; gfx_state.tg_fb.fb_width = TEXT_COLS; gfx_state.tg_fb.fb_mask_red = (1 << palette_format) - 1 << 16; gfx_state.tg_fb.fb_mask_green = (1 << palette_format) - 1 << 8; gfx_state.tg_fb.fb_mask_blue = (1 << palette_format) - 1 << 0; gfx_state.tg_ctype = CT_INDEXED; env_setenv("screen.textmode", EV_VOLATILE | EV_NOHOOK, "1", NULL, NULL); } /* Function 00h - Return VBE Controller Information */ static int biosvbe_info(struct vbeinfoblock *vbep) { struct vbeinfoblock *rvbe; int ret; if (vbep == NULL) return (VBE_FAILED); rvbe = bio_alloc(sizeof(*rvbe)); if (rvbe == NULL) return (VBE_FAILED); /* Now check if we have vesa. */ memset(rvbe, 0, sizeof (*vbe)); memcpy(rvbe->VbeSignature, "VBE2", 4); v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f00; v86.es = VTOPSEG(rvbe); v86.edi = VTOPOFF(rvbe); v86int(); ret = v86.eax & 0xffff; if (ret != VBE_SUCCESS) goto done; if (memcmp(rvbe->VbeSignature, "VESA", 4) != 0) { ret = VBE_NOTSUP; goto done; } bcopy(rvbe, vbep, sizeof(*vbep)); done: bio_free(rvbe, sizeof(*rvbe)); return (ret); } /* Function 01h - Return VBE Mode Information */ static int biosvbe_get_mode_info(int mode, struct modeinfoblock *mi) { struct modeinfoblock *rmi; int ret; rmi = bio_alloc(sizeof(*rmi)); if (rmi == NULL) return (VBE_FAILED); v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f01; v86.ecx = mode; v86.es = VTOPSEG(rmi); v86.edi = VTOPOFF(rmi); v86int(); ret = v86.eax & 0xffff; if (ret != VBE_SUCCESS) goto done; bcopy(rmi, mi, sizeof(*rmi)); done: bio_free(rmi, sizeof(*rmi)); return (ret); } /* Function 02h - Set VBE Mode */ static int biosvbe_set_mode(int mode, struct crtciinfoblock *ci) { int rv; if (vbe->Capabilities & VBE_CAP_DAC8) { int m; /* * The mode change should reset the palette format to * 6 bits, but apparently some systems do fail with 8-bit * palette, so we switch to 6-bit here. */ m = 0x0600; if (biosvbe_palette_format(&m) == VBE_SUCCESS) palette_format = m; } v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f02; v86.ebx = mode | 0x4000; /* set linear FB bit */ v86.es = VTOPSEG(ci); v86.edi = VTOPOFF(ci); v86int(); rv = v86.eax & 0xffff; if (vbe->Capabilities & VBE_CAP_DAC8) { int m; /* Switch to 8-bits per primary color. */ m = 0x0800; if (biosvbe_palette_format(&m) == VBE_SUCCESS) palette_format = m; } env_setenv("screen.textmode", EV_VOLATILE | EV_NOHOOK, "0", NULL, NULL); return (rv); } /* Function 03h - Get VBE Mode */ static int biosvbe_get_mode(int *mode) { v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f03; v86int(); *mode = v86.ebx & 0x3fff; /* Bits 0-13 */ return (v86.eax & 0xffff); } /* Function 08h - Set/Get DAC Palette Format */ int biosvbe_palette_format(int *format) { v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f08; v86.ebx = *format; v86int(); *format = (v86.ebx >> 8) & 0xff; return (v86.eax & 0xffff); } /* Function 09h - Set/Get Palette Data */ static int biosvbe_palette_data(int mode, int reg, struct paletteentry *pe) { v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f09; v86.ebx = mode; v86.edx = reg; v86.ecx = 1; v86.es = VTOPSEG(pe); v86.edi = VTOPOFF(pe); v86int(); return (v86.eax & 0xffff); } /* * Function 15h BL=00h - Report VBE/DDC Capabilities * * int biosvbe_ddc_caps(void) * return: VBE/DDC capabilities */ static int biosvbe_ddc_caps(void) { v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f15; /* display identification extensions */ v86.ebx = 0; /* report DDC capabilities */ v86.ecx = 0; /* controller unit number (00h = primary) */ v86.es = 0; v86.edi = 0; v86int(); if (VBE_ERROR(v86.eax & 0xffff)) return (0); return (v86.ebx & 0xffff); } /* Function 11h BL=01h - Flat Panel status */ static int biosvbe_ddc_read_flat_panel_info(void *buf) { v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f11; /* Flat Panel Interface extensions */ v86.ebx = 1; /* Return Flat Panel Information */ v86.es = VTOPSEG(buf); v86.edi = VTOPOFF(buf); v86int(); return (v86.eax & 0xffff); } /* Function 15h BL=01h - Read EDID */ static int biosvbe_ddc_read_edid(int blockno, void *buf) { v86.ctl = V86_FLAGS; v86.addr = 0x10; v86.eax = 0x4f15; /* display identification extensions */ v86.ebx = 1; /* read EDID */ v86.ecx = 0; /* controller unit number (00h = primary) */ v86.edx = blockno; v86.es = VTOPSEG(buf); v86.edi = VTOPOFF(buf); v86int(); return (v86.eax & 0xffff); } static int vbe_mode_is_supported(struct modeinfoblock *mi) { if ((mi->ModeAttributes & 0x01) == 0) return (0); /* mode not supported by hardware */ if ((mi->ModeAttributes & 0x08) == 0) return (0); /* linear fb not available */ if ((mi->ModeAttributes & 0x10) == 0) return (0); /* text mode */ if (mi->NumberOfPlanes != 1) return (0); /* planar mode not supported */ if (mi->MemoryModel != 0x04 /* Packed pixel */ && mi->MemoryModel != 0x06 /* Direct Color */) return (0); /* unsupported pixel format */ return (1); } static bool vbe_check(void) { if (vbe == NULL) { printf("VBE not available\n"); return (false); } return (true); } static int mode_set(struct env_var *ev, int flags __unused, const void *value) { int mode; if (strcmp(ev->ev_name, "screen.textmode") == 0) { unsigned long v; char *end; if (value == NULL) return (0); errno = 0; v = strtoul(value, &end, 0); if (errno != 0 || *(char *)value == '\0' || *end != '\0' || (v != 0 && v != 1)) return (EINVAL); env_setenv("screen.textmode", EV_VOLATILE | EV_NOHOOK, value, NULL, NULL); if (v == 1) { reset_font_flags(); bios_text_font(true); bios_set_text_mode(VGA_TEXT_MODE); (void) cons_update_mode(false); return (0); } } else if (strcmp(ev->ev_name, "vbe_max_resolution") == 0) { env_setenv("vbe_max_resolution", EV_VOLATILE | EV_NOHOOK, value, NULL, NULL); } else { return (EINVAL); } mode = vbe_default_mode(); if (gfx_state.tg_mode != mode) { reset_font_flags(); bios_text_font(false); vbe_set_mode(mode); cons_update_mode(true); } return (0); } static void * vbe_farptr(uint32_t farptr) { return (PTOV((((farptr & 0xffff0000) >> 12) + (farptr & 0xffff)))); } void vbe_init(void) { uint16_t *p, *ml; /* First set FB for text mode. */ gfx_state.tg_fb_type = FB_TEXT; gfx_state.tg_fb.fb_height = TEXT_ROWS; gfx_state.tg_fb.fb_width = TEXT_COLS; gfx_state.tg_ctype = CT_INDEXED; gfx_state.tg_mode = 3; env_setenv("screen.textmode", EV_VOLATILE, "1", mode_set, env_nounset); env_setenv("vbe_max_resolution", EV_VOLATILE, NULL, mode_set, env_nounset); if (vbe == NULL) { vbe = malloc(sizeof(*vbe)); if (vbe == NULL) return; } if (vbe_mode == NULL) { vbe_mode = malloc(sizeof(*vbe_mode)); if (vbe_mode == NULL) { free(vbe); vbe = NULL; } } if (biosvbe_info(vbe) != VBE_SUCCESS) { free(vbe); vbe = NULL; free(vbe_mode); vbe_mode = NULL; return; } /* * Copy mode list. We must do this because some systems do * corrupt the provided list (vbox 6.1 is one example). */ p = ml = vbe_farptr(vbe->VideoModePtr); while(*p++ != 0xFFFF) ; vbe_mode_list_size = (uintptr_t)p - (uintptr_t)ml; /* * Since vbe_init() is used only once at very start of the loader, * we assume malloc will not fail there, but in case it does, * we point vbe_mode_list to memory pointed by VideoModePtr. */ vbe_mode_list = malloc(vbe_mode_list_size); if (vbe_mode_list == NULL) vbe_mode_list = ml; else bcopy(ml, vbe_mode_list, vbe_mode_list_size); /* reset VideoModePtr, to make sure, we only do use vbe_mode_list. */ vbe->VideoModePtr = 0; /* vbe_set_mode() will set up the rest. */ } bool vbe_available(void) { return (gfx_state.tg_fb_type == FB_VBE); } int vbe_set_palette(const struct paletteentry *entry, size_t slot) { struct paletteentry pe; int mode, ret; if (!vbe_check() || (vbe->Capabilities & VBE_CAP_DAC8) == 0) return (1); if (gfx_state.tg_ctype != CT_INDEXED) { return (1); } pe.Blue = entry->Blue; pe.Green = entry->Green; pe.Red = entry->Red; pe.Reserved = entry->Reserved; if (vbe->Capabilities & VBE_CAP_SNOW) mode = 0x80; else mode = 0; ret = biosvbe_palette_data(mode, slot, &pe); return (ret == VBE_SUCCESS ? 0 : 1); } int vbe_get_mode(void) { return (gfx_state.tg_mode); } int vbe_set_mode(int modenum) { struct modeinfoblock mi; int bpp, ret; if (!vbe_check()) return (1); ret = biosvbe_get_mode_info(modenum, &mi); if (VBE_ERROR(ret)) { printf("mode 0x%x invalid\n", modenum); return (1); } if (!vbe_mode_is_supported(&mi)) { printf("mode 0x%x not supported\n", modenum); return (1); } /* calculate bytes per pixel */ switch (mi.BitsPerPixel) { case 32: case 24: case 16: case 15: case 8: break; default: printf("BitsPerPixel %d is not supported\n", mi.BitsPerPixel); return (1); } ret = biosvbe_set_mode(modenum, NULL); if (VBE_ERROR(ret)) { printf("mode 0x%x could not be set\n", modenum); return (1); } gfx_state.tg_mode = modenum; gfx_state.tg_fb_type = FB_VBE; /* make sure we have current MI in vbestate */ memcpy(vbe_mode, &mi, sizeof (*vbe_mode)); gfx_state.tg_fb.fb_addr = (uint64_t)mi.PhysBasePtr & 0xffffffff; gfx_state.tg_fb.fb_height = mi.YResolution; gfx_state.tg_fb.fb_width = mi.XResolution; gfx_state.tg_fb.fb_bpp = mi.BitsPerPixel; free(gfx_state.tg_shadow_fb); gfx_state.tg_shadow_fb = malloc(mi.YResolution * mi.XResolution * sizeof(struct paletteentry)); /* Bytes per pixel */ bpp = roundup2(mi.BitsPerPixel, NBBY) / NBBY; /* vbe_mode_is_supported() excludes the rest */ switch (mi.MemoryModel) { case 0x4: gfx_state.tg_ctype = CT_INDEXED; break; case 0x6: gfx_state.tg_ctype = CT_RGB; break; } #define COLOR_MASK(size, pos) (((1 << size) - 1) << pos) if (gfx_state.tg_ctype == CT_INDEXED) { gfx_state.tg_fb.fb_mask_red = COLOR_MASK(palette_format, 16); gfx_state.tg_fb.fb_mask_green = COLOR_MASK(palette_format, 8); gfx_state.tg_fb.fb_mask_blue = COLOR_MASK(palette_format, 0); } else if (vbe->VbeVersion >= 0x300) { gfx_state.tg_fb.fb_mask_red = COLOR_MASK(mi.LinRedMaskSize, mi.LinRedFieldPosition); gfx_state.tg_fb.fb_mask_green = COLOR_MASK(mi.LinGreenMaskSize, mi.LinGreenFieldPosition); gfx_state.tg_fb.fb_mask_blue = COLOR_MASK(mi.LinBlueMaskSize, mi.LinBlueFieldPosition); } else { gfx_state.tg_fb.fb_mask_red = COLOR_MASK(mi.RedMaskSize, mi.RedFieldPosition); gfx_state.tg_fb.fb_mask_green = COLOR_MASK(mi.GreenMaskSize, mi.GreenFieldPosition); gfx_state.tg_fb.fb_mask_blue = COLOR_MASK(mi.BlueMaskSize, mi.BlueFieldPosition); } gfx_state.tg_fb.fb_mask_reserved = ~(gfx_state.tg_fb.fb_mask_red | gfx_state.tg_fb.fb_mask_green | gfx_state.tg_fb.fb_mask_blue); if (vbe->VbeVersion >= 0x300) gfx_state.tg_fb.fb_stride = mi.LinBytesPerScanLine / bpp; else gfx_state.tg_fb.fb_stride = mi.BytesPerScanLine / bpp; gfx_state.tg_fb.fb_size = mi.YResolution * gfx_state.tg_fb.fb_stride * bpp; return (0); } /* * Verify existence of mode number or find mode by * dimensions. If depth is not given, walk values 32, 24, 16, 8. */ static int vbe_find_mode_xydm(int x, int y, int depth, int m) { struct modeinfoblock mi; uint16_t *farptr; uint16_t mode; int idx, nentries, i; memset(vbe, 0, sizeof (*vbe)); if (biosvbe_info(vbe) != VBE_SUCCESS) return (0); if (m != -1) i = 8; else if (depth == -1) i = 32; else i = depth; nentries = vbe_mode_list_size / sizeof(*vbe_mode_list); while (i > 0) { for (idx = 0; idx < nentries; idx++) { mode = vbe_mode_list[idx]; if (mode == 0xffff) break; if (biosvbe_get_mode_info(mode, &mi) != VBE_SUCCESS) { continue; } /* we only care about linear modes here */ if (vbe_mode_is_supported(&mi) == 0) continue; if (m != -1) { if (m == mode) return (mode); else continue; } if (mi.XResolution == x && mi.YResolution == y && mi.BitsPerPixel == i) return (mode); } if (depth != -1) break; i -= 8; } return (0); } static int vbe_find_mode(char *str) { int x, y, depth; if (!gfx_parse_mode_str(str, &x, &y, &depth)) return (0); return (vbe_find_mode_xydm(x, y, depth, -1)); } static void vbe_dump_mode(int modenum, struct modeinfoblock *mi) { printf("0x%x=%dx%dx%d", modenum, mi->XResolution, mi->YResolution, mi->BitsPerPixel); } static bool vbe_get_edid(edid_res_list_t *res) { struct vesa_edid_info *edidp; const uint8_t magic[] = EDID_MAGIC; int ddc_caps; bool ret = false; if (edid_info != NULL) return (gfx_get_edid_resolution(edid_info, res)); ddc_caps = biosvbe_ddc_caps(); if (ddc_caps == 0) { return (ret); } edidp = bio_alloc(sizeof(*edidp)); if (edidp == NULL) return (ret); memset(edidp, 0, sizeof(*edidp)); if (VBE_ERROR(biosvbe_ddc_read_edid(0, edidp))) goto done; if (memcmp(edidp, magic, sizeof(magic)) != 0) goto done; /* Unknown EDID version. */ if (edidp->header.version != 1) goto done; ret = gfx_get_edid_resolution(edidp, res); edid_info = malloc(sizeof(*edid_info)); if (edid_info != NULL) memcpy(edid_info, edidp, sizeof (*edid_info)); done: bio_free(edidp, sizeof(*edidp)); return (ret); } static bool vbe_get_flatpanel(uint32_t *pwidth, uint32_t *pheight) { struct vesa_flat_panel_info *fp_info; bool ret = false; fp_info = bio_alloc(sizeof (*fp_info)); if (fp_info == NULL) return (ret); memset(fp_info, 0, sizeof (*fp_info)); if (VBE_ERROR(biosvbe_ddc_read_flat_panel_info(fp_info))) goto done; *pwidth = fp_info->HSize; *pheight = fp_info->VSize; ret = true; done: bio_free(fp_info, sizeof (*fp_info)); return (ret); } static void vbe_print_memory(unsigned vmem) { char unit = 'K'; vmem /= 1024; if (vmem >= 10240000) { vmem /= 1048576; unit = 'G'; } else if (vmem >= 10000) { vmem /= 1024; unit = 'M'; } printf("Total memory: %u%cB\n", vmem, unit); } static void vbe_print_vbe_info(struct vbeinfoblock *vbep) { char *oemstring = ""; char *oemvendor = "", *oemproductname = "", *oemproductrev = ""; if (vbep->OemStringPtr != 0) oemstring = vbe_farptr(vbep->OemStringPtr); if (vbep->OemVendorNamePtr != 0) oemvendor = vbe_farptr(vbep->OemVendorNamePtr); if (vbep->OemProductNamePtr != 0) oemproductname = vbe_farptr(vbep->OemProductNamePtr); if (vbep->OemProductRevPtr != 0) oemproductrev = vbe_farptr(vbep->OemProductRevPtr); printf("VESA VBE Version %d.%d\n%s\n", vbep->VbeVersion >> 8, vbep->VbeVersion & 0xF, oemstring); if (vbep->OemSoftwareRev != 0) { printf("OEM Version %d.%d, %s (%s, %s)\n", vbep->OemSoftwareRev >> 8, vbep->OemSoftwareRev & 0xF, oemvendor, oemproductname, oemproductrev); } vbe_print_memory(vbep->TotalMemory << 16); printf("Number of Image Pages: %d\n", vbe_mode->LinNumberOfImagePages); } /* List available modes, filter by depth. If depth is -1, list all. */ void vbe_modelist(int depth) { struct modeinfoblock mi; uint16_t mode; int nmodes, idx, nentries; int ddc_caps; uint32_t width, height; bool edid = false; edid_res_list_t res; struct resolution *rp; if (!vbe_check()) return; ddc_caps = biosvbe_ddc_caps(); if (ddc_caps & 3) { printf("DDC"); if (ddc_caps & 1) printf(" [DDC1]"); if (ddc_caps & 2) printf(" [DDC2]"); TAILQ_INIT(&res); edid = vbe_get_edid(&res); if (edid) { printf(": EDID"); while ((rp = TAILQ_FIRST(&res)) != NULL) { printf(" %dx%d", rp->width, rp->height); TAILQ_REMOVE(&res, rp, next); free(rp); } printf("\n"); } else { printf(": no EDID information\n"); } } if (!edid) if (vbe_get_flatpanel(&width, &height)) printf(": Panel %dx%d\n", width, height); nmodes = 0; memset(vbe, 0, sizeof (*vbe)); memcpy(vbe->VbeSignature, "VBE2", 4); if (biosvbe_info(vbe) != VBE_SUCCESS) goto done; if (memcmp(vbe->VbeSignature, "VESA", 4) != 0) goto done; vbe_print_vbe_info(vbe); printf("Modes: "); nentries = vbe_mode_list_size / sizeof(*vbe_mode_list); for (idx = 0; idx < nentries; idx++) { mode = vbe_mode_list[idx]; if (mode == 0xffff) break; if (biosvbe_get_mode_info(mode, &mi) != VBE_SUCCESS) continue; /* we only care about linear modes here */ if (vbe_mode_is_supported(&mi) == 0) continue; /* apply requested filter */ if (depth != -1 && mi.BitsPerPixel != depth) continue; if (nmodes % 4 == 0) printf("\n"); else printf(" "); vbe_dump_mode(mode, &mi); nmodes++; } done: if (nmodes == 0) printf("none found"); printf("\n"); } static void vbe_print_mode(bool verbose __unused) { int nc, mode, i, rc; nc = NCOLORS; memset(vbe, 0, sizeof (*vbe)); if (biosvbe_info(vbe) != VBE_SUCCESS) return; vbe_print_vbe_info(vbe); if (biosvbe_get_mode(&mode) != VBE_SUCCESS) { printf("Error getting current VBE mode\n"); return; } if (biosvbe_get_mode_info(mode, vbe_mode) != VBE_SUCCESS || vbe_mode_is_supported(vbe_mode) == 0) { printf("VBE mode (0x%x) is not framebuffer mode\n", mode); return; } printf("\nCurrent VBE mode: "); vbe_dump_mode(mode, vbe_mode); printf("\n"); printf("%ux%ux%u, stride=%u\n", gfx_state.tg_fb.fb_width, gfx_state.tg_fb.fb_height, gfx_state.tg_fb.fb_bpp, gfx_state.tg_fb.fb_stride * (roundup2(gfx_state.tg_fb.fb_bpp, NBBY) / NBBY)); printf(" frame buffer: address=%jx, size=%jx\n", (uintmax_t)gfx_state.tg_fb.fb_addr, (uintmax_t)gfx_state.tg_fb.fb_size); if (vbe_mode->MemoryModel == 0x6) { printf(" color mask: R=%08x, G=%08x, B=%08x\n", gfx_state.tg_fb.fb_mask_red, gfx_state.tg_fb.fb_mask_green, gfx_state.tg_fb.fb_mask_blue); pager_open(); for (i = 0; i < nc; i++) { printf("%d: R=%02x, G=%02x, B=%02x %08x", i, (cmap[i] & gfx_state.tg_fb.fb_mask_red) >> ffs(gfx_state.tg_fb.fb_mask_red) - 1, (cmap[i] & gfx_state.tg_fb.fb_mask_green) >> ffs(gfx_state.tg_fb.fb_mask_green) - 1, (cmap[i] & gfx_state.tg_fb.fb_mask_blue) >> ffs(gfx_state.tg_fb.fb_mask_blue) - 1, cmap[i]); if (pager_output("\n") != 0) break; } pager_close(); return; } mode = 1; /* get DAC palette width */ rc = biosvbe_palette_format(&mode); if (rc != VBE_SUCCESS) return; printf(" palette format: %x bits per primary\n", mode); if (pe8 == NULL) return; pager_open(); for (i = 0; i < nc; i++) { printf("%d: R=%02x, G=%02x, B=%02x", i, pe8[i].Red, pe8[i].Green, pe8[i].Blue); if (pager_output("\n") != 0) break; } pager_close(); } /* * Try EDID preferred mode, if EDID or the suggested mode is not available, * then try flat panel information. * Fall back to VBE_DEFAULT_MODE. */ int vbe_default_mode(void) { edid_res_list_t res; struct resolution *rp; int modenum; uint32_t width, height; modenum = 0; vbe_get_max_resolution(&width, &height); if (width != 0 && height != 0) modenum = vbe_find_mode_xydm(width, height, -1, -1); TAILQ_INIT(&res); if (vbe_get_edid(&res)) { while ((rp = TAILQ_FIRST(&res)) != NULL) { if (modenum == 0) { modenum = vbe_find_mode_xydm( rp->width, rp->height, -1, -1); } TAILQ_REMOVE(&res, rp, next); free(rp); } } if (modenum == 0 && vbe_get_flatpanel(&width, &height)) { modenum = vbe_find_mode_xydm(width, height, -1, -1); } /* Still no mode? Fall back to default. */ if (modenum == 0) modenum = vbe_find_mode(VBE_DEFAULT_MODE); return (modenum); } COMMAND_SET(vbe, "vbe", "vesa framebuffer mode management", command_vesa); int command_vesa(int argc, char *argv[]) { char *arg, *cp; int modenum = -1, n; if (!vbe_check()) return (CMD_OK); if (argc < 2) goto usage; if (strcmp(argv[1], "list") == 0) { n = -1; if (argc != 2 && argc != 3) goto usage; if (argc == 3) { arg = argv[2]; errno = 0; n = strtoul(arg, &cp, 0); if (errno != 0 || *arg == '\0' || cp[0] != '\0') { snprintf(command_errbuf, sizeof (command_errbuf), "depth should be an integer"); return (CMD_ERROR); } } vbe_modelist(n); return (CMD_OK); } if (strcmp(argv[1], "get") == 0) { bool verbose = false; if (argc != 2) { if (argc > 3 || strcmp(argv[2], "-v") != 0) goto usage; verbose = true; } vbe_print_mode(verbose); return (CMD_OK); } if (strcmp(argv[1], "off") == 0) { if (argc != 2) goto usage; if (gfx_state.tg_mode == VGA_TEXT_MODE) return (CMD_OK); reset_font_flags(); bios_text_font(true); bios_set_text_mode(VGA_TEXT_MODE); cons_update_mode(false); return (CMD_OK); } if (strcmp(argv[1], "on") == 0) { if (argc != 2) goto usage; modenum = vbe_default_mode(); if (modenum == 0) { snprintf(command_errbuf, sizeof (command_errbuf), "%s: no suitable VBE mode number found", argv[0]); return (CMD_ERROR); } } else if (strcmp(argv[1], "set") == 0) { if (argc != 3) goto usage; if (strncmp(argv[2], "0x", 2) == 0) { arg = argv[2]; errno = 0; n = strtoul(arg, &cp, 0); if (errno != 0 || *arg == '\0' || cp[0] != '\0') { snprintf(command_errbuf, sizeof (command_errbuf), "mode should be an integer"); return (CMD_ERROR); } modenum = vbe_find_mode_xydm(0, 0, 0, n); } else if (strchr(argv[2], 'x') != NULL) { modenum = vbe_find_mode(argv[2]); } } else { goto usage; } if (modenum == 0) { snprintf(command_errbuf, sizeof (command_errbuf), "%s: mode %s not supported by firmware\n", argv[0], argv[2]); return (CMD_ERROR); } if (modenum >= VESA_MODE_BASE) { if (gfx_state.tg_mode != modenum) { reset_font_flags(); bios_text_font(false); vbe_set_mode(modenum); cons_update_mode(true); } return (CMD_OK); } else { snprintf(command_errbuf, sizeof (command_errbuf), "%s: mode %s is not framebuffer mode\n", argv[0], argv[2]); return (CMD_ERROR); } usage: snprintf(command_errbuf, sizeof (command_errbuf), "usage: %s on | off | get | list [depth] | " "set ", argv[0]); return (CMD_ERROR); }