2N/A/* videoinfo.c - command to list video modes. */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2005,2007,2008,2009,2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/video.h>
2N/A#include <grub/dl.h>
2N/A#include <grub/env.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/mm.h>
2N/A#include <grub/command.h>
2N/A#include <grub/i18n.h>
2N/A
2N/AGRUB_MOD_LICENSE ("GPLv3+");
2N/A
2N/Astatic unsigned height, width, depth;
2N/Astatic struct grub_video_mode_info *current_mode;
2N/A
2N/Astatic int
2N/Ahook (const struct grub_video_mode_info *info)
2N/A{
2N/A if (height && width && (info->width != width || info->height != height))
2N/A return 0;
2N/A
2N/A if (depth && info->bpp != depth)
2N/A return 0;
2N/A
2N/A if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
2N/A grub_printf (" ");
2N/A else
2N/A {
2N/A if (current_mode && info->mode_number == current_mode->mode_number)
2N/A grub_printf ("*");
2N/A else
2N/A grub_printf (" ");
2N/A grub_printf (" 0x%03x ", info->mode_number);
2N/A }
2N/A grub_printf ("%4d x %4d x %2d ", info->width, info->height, info->bpp);
2N/A
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT)
2N/A grub_xputs (_("Text-only "));
2N/A /* Show mask and position details for direct color modes. */
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_RGB)
2N/A grub_printf_ (N_("Direct, mask: %d/%d/%d/%d pos: %d/%d/%d/%d"),
2N/A info->red_mask_size,
2N/A info->green_mask_size,
2N/A info->blue_mask_size,
2N/A info->reserved_mask_size,
2N/A info->red_field_pos,
2N/A info->green_field_pos,
2N/A info->blue_field_pos,
2N/A info->reserved_field_pos);
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
2N/A grub_xputs (_("Packed "));
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_YUV)
2N/A grub_xputs (_("YUV "));
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PLANAR)
2N/A grub_xputs (_("Planar "));
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_HERCULES)
2N/A grub_xputs (_("Hercules "));
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_CGA)
2N/A grub_xputs (_("CGA "));
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_NONCHAIN4)
2N/A grub_xputs (_("Non-chain 4 "));
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP)
2N/A grub_xputs (_("Monochrome "));
2N/A if (info->mode_type & GRUB_VIDEO_MODE_TYPE_UNKNOWN)
2N/A grub_xputs (_("Unknown "));
2N/A
2N/A grub_xputs ("\n");
2N/A
2N/A return 0;
2N/A}
2N/A
2N/Astatic void
2N/Aprint_edid (struct grub_video_edid_info *edid_info)
2N/A{
2N/A unsigned int edid_width, edid_height;
2N/A
2N/A if (grub_video_edid_checksum (edid_info))
2N/A {
2N/A grub_puts_ (N_(" EDID checksum invalid"));
2N/A grub_errno = GRUB_ERR_NONE;
2N/A return;
2N/A }
2N/A
2N/A grub_printf_ (N_(" EDID version: %u.%u\n"),
2N/A edid_info->version, edid_info->revision);
2N/A if (grub_video_edid_preferred_mode (edid_info, &edid_width, &edid_height)
2N/A == GRUB_ERR_NONE)
2N/A grub_printf_ (N_(" Preferred mode: %ux%u\n"), edid_width, edid_height);
2N/A else
2N/A {
2N/A grub_printf_ (N_(" No preferred mode available\n"));
2N/A grub_errno = GRUB_ERR_NONE;
2N/A }
2N/A}
2N/A
2N/Astatic grub_err_t
2N/Agrub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
2N/A int argc, char **args)
2N/A{
2N/A grub_video_adapter_t adapter;
2N/A grub_video_driver_id_t id;
2N/A
2N/A height = width = depth = 0;
2N/A if (argc)
2N/A {
2N/A char *ptr;
2N/A ptr = args[0];
2N/A width = grub_strtoul (ptr, &ptr, 0);
2N/A if (grub_errno)
2N/A return grub_errno;
2N/A if (*ptr != 'x')
2N/A return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid mode specification");
2N/A ptr++;
2N/A height = grub_strtoul (ptr, &ptr, 0);
2N/A if (grub_errno)
2N/A return grub_errno;
2N/A if (*ptr == 'x')
2N/A {
2N/A ptr++;
2N/A depth = grub_strtoul (ptr, &ptr, 0);
2N/A if (grub_errno)
2N/A return grub_errno;
2N/A }
2N/A }
2N/A
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A if (grub_strcmp (cmd->name, "vbeinfo") == 0)
2N/A grub_dl_load ("vbe");
2N/A#endif
2N/A
2N/A id = grub_video_get_driver_id ();
2N/A
2N/A grub_puts_ (N_("List of supported video modes:"));
2N/A grub_puts_ (N_("Legend: P=Packed pixel, D=Direct color, "
2N/A "mask/pos=R/G/B/reserved"));
2N/A
2N/A FOR_VIDEO_ADAPTERS (adapter)
2N/A {
2N/A struct grub_video_mode_info info;
2N/A struct grub_video_edid_info edid_info;
2N/A
2N/A grub_printf_ (N_("Adapter '%s':\n"), adapter->name);
2N/A
2N/A if (!adapter->iterate)
2N/A {
2N/A grub_puts_ (N_(" No info available"));
2N/A continue;
2N/A }
2N/A
2N/A current_mode = NULL;
2N/A
2N/A if (adapter->id == id)
2N/A {
2N/A if (grub_video_get_info (&info) == GRUB_ERR_NONE)
2N/A current_mode = &info;
2N/A else
2N/A /* Don't worry about errors. */
2N/A grub_errno = GRUB_ERR_NONE;
2N/A }
2N/A else
2N/A {
2N/A if (adapter->init ())
2N/A {
2N/A grub_puts_ (N_(" Failed"));
2N/A grub_errno = GRUB_ERR_NONE;
2N/A continue;
2N/A }
2N/A }
2N/A
2N/A if (adapter->print_adapter_specific_info)
2N/A adapter->print_adapter_specific_info ();
2N/A
2N/A adapter->iterate (hook);
2N/A
2N/A if (adapter->get_edid && adapter->get_edid (&edid_info) == GRUB_ERR_NONE)
2N/A print_edid (&edid_info);
2N/A else
2N/A grub_errno = GRUB_ERR_NONE;
2N/A
2N/A current_mode = NULL;
2N/A
2N/A if (adapter->id != id)
2N/A {
2N/A if (adapter->fini ())
2N/A {
2N/A grub_errno = GRUB_ERR_NONE;
2N/A continue;
2N/A }
2N/A }
2N/A }
2N/A return GRUB_ERR_NONE;
2N/A}
2N/A
2N/Astatic grub_command_t cmd;
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/Astatic grub_command_t cmd_vbe;
2N/A#endif
2N/A
2N/AGRUB_MOD_INIT(videoinfo)
2N/A{
2N/A cmd = grub_register_command ("videoinfo", grub_cmd_videoinfo, N_("[WxH[xD]]"),
2N/A N_("List available video modes. If "
2N/A "resolution is given show only modes"
2N/A " matching it."));
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
2N/A N_("[WxH[xD]]"),
2N/A N_("List available video modes. If "
2N/A "resolution is given show only modes"
2N/A " matching it."));
2N/A#endif
2N/A}
2N/A
2N/AGRUB_MOD_FINI(videoinfo)
2N/A{
2N/A grub_unregister_command (cmd);
2N/A#ifdef GRUB_MACHINE_PCBIOS
2N/A grub_unregister_command (cmd_vbe);
2N/A#endif
2N/A}
2N/A