1 /* videoinfo.c - command to list video modes. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2007,2008,2009,2010 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/video.h>
23 #include <grub/misc.h>
25 #include <grub/command.h>
26 #include <grub/i18n.h>
28 GRUB_MOD_LICENSE ("GPLv3+");
30 static unsigned height
, width
, depth
;
31 static struct grub_video_mode_info
*current_mode
;
34 hook (const struct grub_video_mode_info
*info
)
36 if (height
&& width
&& (info
->width
!= width
|| info
->height
!= height
))
39 if (depth
&& info
->bpp
!= depth
)
42 if (info
->mode_number
== GRUB_VIDEO_MODE_NUMBER_INVALID
)
46 if (current_mode
&& info
->mode_number
== current_mode
->mode_number
)
50 grub_printf (" 0x%03x ", info
->mode_number
);
52 grub_printf ("%4d x %4d x %2d (%4d) ", info
->width
, info
->height
, info
->bpp
,
55 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_PURE_TEXT
)
56 grub_xputs (_("Text-only "));
57 /* Show mask and position details for direct color modes. */
58 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_RGB
)
59 /* TRANSLATORS: "Direct color" is a mode when the color components
60 are written dirrectly into memory. */
61 grub_printf_ (N_("Direct color, mask: %d/%d/%d/%d pos: %d/%d/%d/%d"),
63 info
->green_mask_size
,
65 info
->reserved_mask_size
,
67 info
->green_field_pos
,
69 info
->reserved_field_pos
);
70 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_INDEX_COLOR
)
71 /* TRANSLATORS: In "packed pixel" mode you write the index of the color
72 in the palette. Synonyms include "paletted color". */
73 grub_xputs (_("Packed pixel "));
74 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_YUV
)
75 grub_xputs (_("YUV "));
76 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_PLANAR
)
77 /* TRANSLATORS: "Planar" is the video memory where you have to write
78 in several different banks "plans" to control the different color
79 components of the same pixel. */
80 grub_xputs (_("Planar "));
81 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_HERCULES
)
82 grub_xputs (_("Hercules "));
83 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_CGA
)
84 grub_xputs (_("CGA "));
85 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_NONCHAIN4
)
86 /* TRANSLATORS: Non-chain 4 is a 256-color planar
87 (unchained) video memory mode. */
88 grub_xputs (_("Non-chain 4 "));
89 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP
)
90 grub_xputs (_("Monochrome "));
91 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_UNKNOWN
)
92 grub_xputs (_("Unknown video mode "));
100 print_edid (struct grub_video_edid_info
*edid_info
)
102 unsigned int edid_width
, edid_height
;
104 if (grub_video_edid_checksum (edid_info
))
106 grub_puts_ (N_(" EDID checksum invalid"));
107 grub_errno
= GRUB_ERR_NONE
;
111 grub_printf_ (N_(" EDID version: %u.%u\n"),
112 edid_info
->version
, edid_info
->revision
);
113 if (grub_video_edid_preferred_mode (edid_info
, &edid_width
, &edid_height
)
115 grub_printf_ (N_(" Preferred mode: %ux%u\n"), edid_width
, edid_height
);
118 grub_printf_ (N_(" No preferred mode available\n"));
119 grub_errno
= GRUB_ERR_NONE
;
124 grub_cmd_videoinfo (grub_command_t cmd
__attribute__ ((unused
)),
125 int argc
, char **args
)
127 grub_video_adapter_t adapter
;
128 grub_video_driver_id_t id
;
130 height
= width
= depth
= 0;
135 width
= grub_strtoul (ptr
, &ptr
, 0);
139 return grub_error (GRUB_ERR_BAD_ARGUMENT
,
140 N_("invalid video mode specification `%s'"),
143 height
= grub_strtoul (ptr
, &ptr
, 0);
149 depth
= grub_strtoul (ptr
, &ptr
, 0);
155 #ifdef GRUB_MACHINE_PCBIOS
156 if (grub_strcmp (cmd
->name
, "vbeinfo") == 0)
157 grub_dl_load ("vbe");
160 id
= grub_video_get_driver_id ();
162 grub_puts_ (N_("List of supported video modes:"));
163 grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
165 FOR_VIDEO_ADAPTERS (adapter
)
167 struct grub_video_mode_info info
;
168 struct grub_video_edid_info edid_info
;
170 grub_printf_ (N_("Adapter `%s':\n"), adapter
->name
);
172 if (!adapter
->iterate
)
174 grub_puts_ (N_(" No info available"));
180 if (adapter
->id
== id
)
182 if (grub_video_get_info (&info
) == GRUB_ERR_NONE
)
183 current_mode
= &info
;
185 /* Don't worry about errors. */
186 grub_errno
= GRUB_ERR_NONE
;
190 if (adapter
->init ())
192 grub_puts_ (N_(" Failed to initialize video adapter"));
193 grub_errno
= GRUB_ERR_NONE
;
198 if (adapter
->print_adapter_specific_info
)
199 adapter
->print_adapter_specific_info ();
201 adapter
->iterate (hook
);
203 if (adapter
->get_edid
&& adapter
->get_edid (&edid_info
) == GRUB_ERR_NONE
)
204 print_edid (&edid_info
);
206 grub_errno
= GRUB_ERR_NONE
;
210 if (adapter
->id
!= id
)
212 if (adapter
->fini ())
214 grub_errno
= GRUB_ERR_NONE
;
219 return GRUB_ERR_NONE
;
222 static grub_command_t cmd
;
223 #ifdef GRUB_MACHINE_PCBIOS
224 static grub_command_t cmd_vbe
;
227 GRUB_MOD_INIT(videoinfo
)
229 cmd
= grub_register_command ("videoinfo", grub_cmd_videoinfo
,
230 /* TRANSLATORS: "x" has to be entered in,
231 like an identifier, so please don't
232 use better Unicode codepoints. */
234 N_("List available video modes. If "
235 "resolution is given show only modes"
237 #ifdef GRUB_MACHINE_PCBIOS
238 cmd_vbe
= grub_register_command ("vbeinfo", grub_cmd_videoinfo
,
239 /* TRANSLATORS: "x" has to be entered in,
240 like an identifier, so please don't
241 use better Unicode codepoints. */
243 N_("List available video modes. If "
244 "resolution is given show only modes"
249 GRUB_MOD_FINI(videoinfo
)
251 grub_unregister_command (cmd
);
252 #ifdef GRUB_MACHINE_PCBIOS
253 grub_unregister_command (cmd_vbe
);