Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / commands / videoinfo.c
blob4a11576154d996f6ecc8ee34d6562f6a14d94164
1 /* videoinfo.c - command to list video modes. */
2 /*
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>
21 #include <grub/dl.h>
22 #include <grub/env.h>
23 #include <grub/misc.h>
24 #include <grub/mm.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;
33 static int
34 hook (const struct grub_video_mode_info *info)
36 if (height && width && (info->width != width || info->height != height))
37 return 0;
39 if (depth && info->bpp != depth)
40 return 0;
42 if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
43 grub_printf (" ");
44 else
46 if (current_mode && info->mode_number == current_mode->mode_number)
47 grub_printf ("*");
48 else
49 grub_printf (" ");
50 grub_printf (" 0x%03x ", info->mode_number);
52 grub_printf ("%4d x %4d x %2d (%4d) ", info->width, info->height, info->bpp,
53 info->pitch);
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"),
62 info->red_mask_size,
63 info->green_mask_size,
64 info->blue_mask_size,
65 info->reserved_mask_size,
66 info->red_field_pos,
67 info->green_field_pos,
68 info->blue_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 "));
94 grub_xputs ("\n");
96 return 0;
99 static void
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;
108 return;
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)
114 == GRUB_ERR_NONE)
115 grub_printf_ (N_(" Preferred mode: %ux%u\n"), edid_width, edid_height);
116 else
118 grub_printf_ (N_(" No preferred mode available\n"));
119 grub_errno = GRUB_ERR_NONE;
123 static grub_err_t
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;
131 if (argc)
133 char *ptr;
134 ptr = args[0];
135 width = grub_strtoul (ptr, &ptr, 0);
136 if (grub_errno)
137 return grub_errno;
138 if (*ptr != 'x')
139 return grub_error (GRUB_ERR_BAD_ARGUMENT,
140 N_("invalid video mode specification `%s'"),
141 args[0]);
142 ptr++;
143 height = grub_strtoul (ptr, &ptr, 0);
144 if (grub_errno)
145 return grub_errno;
146 if (*ptr == 'x')
148 ptr++;
149 depth = grub_strtoul (ptr, &ptr, 0);
150 if (grub_errno)
151 return grub_errno;
155 #ifdef GRUB_MACHINE_PCBIOS
156 if (grub_strcmp (cmd->name, "vbeinfo") == 0)
157 grub_dl_load ("vbe");
158 #endif
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"));
175 continue;
178 current_mode = NULL;
180 if (adapter->id == id)
182 if (grub_video_get_info (&info) == GRUB_ERR_NONE)
183 current_mode = &info;
184 else
185 /* Don't worry about errors. */
186 grub_errno = GRUB_ERR_NONE;
188 else
190 if (adapter->init ())
192 grub_puts_ (N_(" Failed to initialize video adapter"));
193 grub_errno = GRUB_ERR_NONE;
194 continue;
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);
205 else
206 grub_errno = GRUB_ERR_NONE;
208 current_mode = NULL;
210 if (adapter->id != id)
212 if (adapter->fini ())
214 grub_errno = GRUB_ERR_NONE;
215 continue;
219 return GRUB_ERR_NONE;
222 static grub_command_t cmd;
223 #ifdef GRUB_MACHINE_PCBIOS
224 static grub_command_t cmd_vbe;
225 #endif
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. */
233 N_("[WxH[xD]]"),
234 N_("List available video modes. If "
235 "resolution is given show only modes"
236 " matching it."));
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. */
242 N_("[WxH[xD]]"),
243 N_("List available video modes. If "
244 "resolution is given show only modes"
245 " matching it."));
246 #endif
249 GRUB_MOD_FINI(videoinfo)
251 grub_unregister_command (cmd);
252 #ifdef GRUB_MACHINE_PCBIOS
253 grub_unregister_command (cmd_vbe);
254 #endif