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+");
32 unsigned height
, width
, depth
;
33 struct grub_video_mode_info
*current_mode
;
37 hook (const struct grub_video_mode_info
*info
, void *hook_arg
)
39 struct hook_ctx
*ctx
= hook_arg
;
41 if (ctx
->height
&& ctx
->width
&& (info
->width
!= ctx
->width
|| info
->height
!= ctx
->height
))
44 if (ctx
->depth
&& info
->bpp
!= ctx
->depth
)
47 if (info
->mode_number
== GRUB_VIDEO_MODE_NUMBER_INVALID
)
51 if (ctx
->current_mode
&& info
->mode_number
== ctx
->current_mode
->mode_number
)
55 grub_printf (" 0x%03x ", info
->mode_number
);
57 grub_printf ("%4d x %4d x %2d (%4d) ", info
->width
, info
->height
, info
->bpp
,
60 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_PURE_TEXT
)
61 grub_xputs (_("Text-only "));
62 /* Show mask and position details for direct color modes. */
63 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_RGB
)
64 /* TRANSLATORS: "Direct color" is a mode when the color components
65 are written dirrectly into memory. */
66 grub_printf_ (N_("Direct color, mask: %d/%d/%d/%d pos: %d/%d/%d/%d"),
68 info
->green_mask_size
,
70 info
->reserved_mask_size
,
72 info
->green_field_pos
,
74 info
->reserved_field_pos
);
75 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_INDEX_COLOR
)
76 /* TRANSLATORS: In "paletted color" mode you write the index of the color
77 in the palette. Synonyms include "packed pixel". */
78 grub_xputs (_("Paletted "));
79 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_YUV
)
80 grub_xputs (_("YUV "));
81 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_PLANAR
)
82 /* TRANSLATORS: "Planar" is the video memory where you have to write
83 in several different banks "plans" to control the different color
84 components of the same pixel. */
85 grub_xputs (_("Planar "));
86 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_HERCULES
)
87 grub_xputs (_("Hercules "));
88 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_CGA
)
89 grub_xputs (_("CGA "));
90 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_NONCHAIN4
)
91 /* TRANSLATORS: Non-chain 4 is a 256-color planar
92 (unchained) video memory mode. */
93 grub_xputs (_("Non-chain 4 "));
94 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP
)
95 grub_xputs (_("Monochrome "));
96 if (info
->mode_type
& GRUB_VIDEO_MODE_TYPE_UNKNOWN
)
97 grub_xputs (_("Unknown video mode "));
105 print_edid (struct grub_video_edid_info
*edid_info
)
107 unsigned int edid_width
, edid_height
;
109 if (grub_video_edid_checksum (edid_info
))
111 grub_puts_ (N_(" EDID checksum invalid"));
112 grub_errno
= GRUB_ERR_NONE
;
116 grub_printf_ (N_(" EDID version: %u.%u\n"),
117 edid_info
->version
, edid_info
->revision
);
118 if (grub_video_edid_preferred_mode (edid_info
, &edid_width
, &edid_height
)
120 grub_printf_ (N_(" Preferred mode: %ux%u\n"), edid_width
, edid_height
);
123 grub_printf_ (N_(" No preferred mode available\n"));
124 grub_errno
= GRUB_ERR_NONE
;
129 grub_cmd_videoinfo (grub_command_t cmd
__attribute__ ((unused
)),
130 int argc
, char **args
)
132 grub_video_adapter_t adapter
;
133 grub_video_driver_id_t id
;
136 ctx
.height
= ctx
.width
= ctx
.depth
= 0;
141 ctx
.width
= grub_strtoul (ptr
, &ptr
, 0);
145 return grub_error (GRUB_ERR_BAD_ARGUMENT
,
146 N_("invalid video mode specification `%s'"),
149 ctx
.height
= grub_strtoul (ptr
, &ptr
, 0);
155 ctx
.depth
= grub_strtoul (ptr
, &ptr
, 0);
161 #ifdef GRUB_MACHINE_PCBIOS
162 if (grub_strcmp (cmd
->name
, "vbeinfo") == 0)
163 grub_dl_load ("vbe");
166 id
= grub_video_get_driver_id ();
168 grub_puts_ (N_("List of supported video modes:"));
169 grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
171 FOR_VIDEO_ADAPTERS (adapter
)
173 struct grub_video_mode_info info
;
174 struct grub_video_edid_info edid_info
;
176 grub_printf_ (N_("Adapter `%s':\n"), adapter
->name
);
178 if (!adapter
->iterate
)
180 grub_puts_ (N_(" No info available"));
184 ctx
.current_mode
= NULL
;
186 if (adapter
->id
== id
)
188 if (grub_video_get_info (&info
) == GRUB_ERR_NONE
)
189 ctx
.current_mode
= &info
;
191 /* Don't worry about errors. */
192 grub_errno
= GRUB_ERR_NONE
;
196 if (adapter
->init ())
198 grub_puts_ (N_(" Failed to initialize video adapter"));
199 grub_errno
= GRUB_ERR_NONE
;
204 if (adapter
->print_adapter_specific_info
)
205 adapter
->print_adapter_specific_info ();
207 adapter
->iterate (hook
, &ctx
);
209 if (adapter
->get_edid
&& adapter
->get_edid (&edid_info
) == GRUB_ERR_NONE
)
210 print_edid (&edid_info
);
212 grub_errno
= GRUB_ERR_NONE
;
214 ctx
.current_mode
= NULL
;
216 if (adapter
->id
!= id
)
218 if (adapter
->fini ())
220 grub_errno
= GRUB_ERR_NONE
;
225 return GRUB_ERR_NONE
;
228 static grub_command_t cmd
;
229 #ifdef GRUB_MACHINE_PCBIOS
230 static grub_command_t cmd_vbe
;
233 GRUB_MOD_INIT(videoinfo
)
235 cmd
= grub_register_command ("videoinfo", grub_cmd_videoinfo
,
236 /* TRANSLATORS: "x" has to be entered in,
237 like an identifier, so please don't
238 use better Unicode codepoints. */
240 N_("List available video modes. If "
241 "resolution is given show only modes"
243 #ifdef GRUB_MACHINE_PCBIOS
244 cmd_vbe
= grub_register_command ("vbeinfo", grub_cmd_videoinfo
,
245 /* TRANSLATORS: "x" has to be entered in,
246 like an identifier, so please don't
247 use better Unicode codepoints. */
249 N_("List available video modes. If "
250 "resolution is given show only modes"
255 GRUB_MOD_FINI(videoinfo
)
257 grub_unregister_command (cmd
);
258 #ifdef GRUB_MACHINE_PCBIOS
259 grub_unregister_command (cmd_vbe
);