Port to 1.99 extras build system.
[grub-extras.git] / 915resolution.c
blob96df6ae1285397643a10d147a1d48c5ac63a203a
1 /* 915resolution - Utility to change vbemodes on the intel
2 * integrated video chipset */
4 /*
5 * Based on Nathan Coulson's http://nathancoulson.com/proj/eee/grub-1.96-915resolution-0.5.2-3.patch
6 * Oct 10, 2008, Released as 915
7 * Oct 10, 2008, Updated to include support for 945GM thanks to Scot Doyle
8 */
10 /* Copied from 915 resolution created by steve tomjenovic
11 * 915 resolution was in the public domain.
13 * All I have done, was make the above program run within
14 * the grub2 environment.
16 * Some of the checks are still commented, as I did not find
17 * easy replacement for memmem.
19 * Slightly edited by Nathan Coulson (conathan@gmail.com)
23 * GRUB -- GRand Unified Bootloader
24 * Copyright (C) 2003,2007 Free Software Foundation, Inc.
25 * Copyright (C) 2003 NIIBE Yutaka <gniibe@m17n.org>
27 * GRUB is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
32 * GRUB is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
42 /* 915 resolution by steve tomljenovic
44 * This was tested only on Sony VGN-FS550. Use at your own risk
46 * This code is based on the techniques used in :
48 * - 855patch. Many thanks to Christian Zietz (czietz gmx net)
49 * for demonstrating how to shadow the VBIOS into system RAM
50 * and then modify it.
52 * - 1280patch by Andrew Tipton (andrewtipton null li).
54 * - 855resolution by Alain Poirier
56 * This source code is into the public domain.
59 #include <grub/types.h>
60 #include <grub/misc.h>
61 #include <grub/mm.h>
62 #include <grub/err.h>
63 #include <grub/dl.h>
64 #include <grub/normal.h>
65 #include <grub/i386/io.h>
67 #define printf grub_printf
68 #define malloc grub_malloc
69 #define free grub_free
70 #define strcmp grub_strcmp
71 #define fprintf(stream,template,args...) grub_printf(template, ## args)
72 #define strtol(x,y,z) grub_strtoul(x,y,z)
73 #define atoi(x) grub_strtoul(x,NULL,10)
74 #define assert(x)
75 #define memset grub_memset
76 #define outl grub_outl
77 #define outb grub_outb
78 #define inl grub_inl
79 #define inb grub_inb
81 #define NEW(a) ((a *)(malloc(sizeof(a))))
82 #define FREE(a) (free(a))
84 #define VBIOS_START 0xc0000
85 #define VBIOS_SIZE 0x10000
87 #define VBIOS_FILE "/dev/mem"
89 #define FALSE 0
90 #define TRUE 1
92 #define MODE_TABLE_OFFSET_845G 617
94 #define RES915_VERSION "0.5.3"
96 #define ATI_SIGNATURE1 "ATI MOBILITY RADEON"
97 #define ATI_SIGNATURE2 "ATI Technologies Inc"
98 #define NVIDIA_SIGNATURE "NVIDIA Corp"
99 #define INTEL_SIGNATURE "Intel Corp"
101 #define DEBUG 0
103 typedef unsigned char * address;
104 typedef unsigned char byte;
105 typedef unsigned short word;
106 typedef unsigned char boolean;
107 typedef unsigned int cardinal;
109 typedef enum {
110 CT_UNKWN, CT_830, CT_845G, CT_855GM, CT_865G, CT_915G, CT_915GM, CT_945G, CT_945GM, CT_945GME,
111 CT_946GZ, CT_G965, CT_Q965, CT_965GM, CT_G33, CT_Q33, CT_Q35, CT_500GMA
112 } chipset_type;
114 char * chipset_type_names[] = {
115 "UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",
116 "946GZ", "G965", "Q965", "965GM", "G33", "Q33", "Q35", "500GMA"
119 typedef enum {
120 BT_UNKWN, BT_1, BT_2, BT_3
121 } bios_type;
123 char * bios_type_names[] = {"UNKNOWN", "TYPE 1", "TYPE 2", "TYPE 3"};
125 int freqs[] = { 60, 75, 85 };
127 typedef struct {
128 byte mode;
129 byte bits_per_pixel;
130 word resolution;
131 byte unknown;
132 } __attribute__((packed)) vbios_mode;
134 typedef struct {
135 byte unknow1[2];
136 byte x1;
137 byte x_total;
138 byte x2;
139 byte y1;
140 byte y_total;
141 byte y2;
142 } __attribute__((packed)) vbios_resolution_type1;
144 typedef struct {
145 unsigned long clock;
147 word x1;
148 word htotal;
149 word x2;
150 word hblank;
151 word hsyncstart;
152 word hsyncend;
154 word y1;
155 word vtotal;
156 word y2;
157 word vblank;
158 word vsyncstart;
159 word vsyncend;
160 } __attribute__((packed)) vbios_modeline_type2;
162 typedef struct {
163 byte xchars;
164 byte ychars;
165 byte unknown[4];
167 vbios_modeline_type2 modelines[];
168 } __attribute__((packed)) vbios_resolution_type2;
170 typedef struct {
171 unsigned long clock;
173 word x1;
174 word htotal;
175 word x2;
176 word hblank;
177 word hsyncstart;
178 word hsyncend;
180 word y1;
181 word vtotal;
182 word y2;
183 word vblank;
184 word vsyncstart;
185 word vsyncend;
187 word timing_h;
188 word timing_v;
190 byte unknown[6];
191 } __attribute__((packed)) vbios_modeline_type3;
193 typedef struct {
194 unsigned char unknown[6];
196 vbios_modeline_type3 modelines[];
197 } __attribute__((packed)) vbios_resolution_type3;
200 typedef struct {
201 cardinal chipset_id;
202 chipset_type chipset;
203 bios_type bios;
205 int bios_fd;
206 address bios_ptr;
208 vbios_mode * mode_table;
209 cardinal mode_table_size;
211 byte b1, b2;
213 boolean unlocked;
214 } vbios_map;
217 static cardinal get_chipset_id(void) {
218 outl(0x80000000, 0xcf8);
219 return inl(0xcfc);
222 static chipset_type get_chipset(cardinal id) {
223 chipset_type type;
225 switch (id) {
226 case 0x35758086:
227 type = CT_830;
228 break;
230 case 0x25608086:
231 type = CT_845G;
232 break;
234 case 0x35808086:
235 type = CT_855GM;
236 break;
238 case 0x25708086:
239 type = CT_865G;
240 break;
242 case 0x25808086:
243 type = CT_915G;
244 break;
246 case 0x25908086:
247 type = CT_915GM;
248 break;
250 case 0x27708086:
251 type = CT_945G;
252 break;
254 case 0x27a08086:
255 type = CT_945GM;
256 break;
258 case 0x27ac8086:
259 type = CT_945GME;
260 break;
262 case 0x29708086:
263 type = CT_946GZ;
264 break;
266 case 0x29a08086:
267 type = CT_G965;
268 break;
270 case 0x29908086:
271 type = CT_Q965;
272 break;
274 case 0x2a008086:
275 type = CT_965GM;
276 break;
278 case 0x29c08086:
279 type = CT_G33;
280 break;
282 case 0x29b08086:
283 type = CT_Q35;
284 break;
286 case 0x29d08086:
287 type = CT_Q33;
288 break;
290 case 0x81008086:
291 type = CT_500GMA;
292 break;
294 default:
295 type = CT_UNKWN;
296 break;
299 return type;
303 static vbios_resolution_type1 * map_type1_resolution(vbios_map * map, word res) {
304 vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res));
305 return ptr;
308 static vbios_resolution_type2 * map_type2_resolution(vbios_map * map, word res) {
309 vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res));
310 return ptr;
313 static vbios_resolution_type3 * map_type3_resolution(vbios_map * map, word res) {
314 vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res));
315 return ptr;
319 static boolean detect_bios_type(vbios_map * map, int entry_size) {
320 unsigned i;
321 short int r1, r2;
323 r1 = r2 = 32000;
325 for (i=0; i < map->mode_table_size; i++) {
326 if (map->mode_table[i].resolution <= r1) {
327 r1 = map->mode_table[i].resolution;
329 else {
330 if (map->mode_table[i].resolution <= r2) {
331 r2 = map->mode_table[i].resolution;
335 /*printf("r1 = %d r2 = %d\n", r1, r2);*/
338 return (r2-r1-6) % entry_size == 0;
342 static void close_vbios(vbios_map * map);
345 static vbios_map * open_vbios(chipset_type forced_chipset) {
346 vbios_map * map = NEW(vbios_map);
347 memset (map, 0, sizeof(vbios_map));
350 * Determine chipset
353 if (forced_chipset == CT_UNKWN) {
354 map->chipset_id = get_chipset_id();
356 map->chipset = get_chipset(map->chipset_id);
358 else if (forced_chipset != CT_UNKWN) {
359 map->chipset = forced_chipset;
361 else {
362 map->chipset = CT_915GM;
366 * Map the video bios to memory
369 map->bios_ptr = (unsigned char *) VBIOS_START;
371 #if 0
373 * check if we have ATI Radeon
376 if (memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE1, strlen(ATI_SIGNATURE1)) ||
377 memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE2, strlen(ATI_SIGNATURE2)) ) {
378 fprintf(stderr, "ATI chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
379 close(map->bios_fd);
380 exit(2);
384 * check if we have NVIDIA
387 if (memmem(map->bios_ptr, VBIOS_SIZE, NVIDIA_SIGNATURE, strlen(NVIDIA_SIGNATURE))) {
388 fprintf(stderr, "NVIDIA chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
389 close(map->bios_fd);
390 exit(2);
394 * check if we have Intel
397 if (map->chipset == CT_UNKWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) {
398 fprintf(stderr, "Intel chipset detected. However, 915resolution was unable to determine the chipset type.\n");
400 fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
402 fprintf(stderr, "Please report this problem to stomljen@yahoo.com\n");
404 close_vbios(map);
405 exit(2);
407 #endif
410 * check for others
413 if (map->chipset == CT_UNKWN) {
414 fprintf(stderr, "Unknown chipset type and unrecognized bios.\n");
415 fprintf(stderr, "915resolution only works with Intel 800/900 series graphic chipsets.\n");
417 fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
418 close_vbios(map);
419 return 0;
423 * Figure out where the mode table is
427 address p = map->bios_ptr + 16;
428 address limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));
430 while (p < limit && map->mode_table == 0) {
431 vbios_mode * mode_ptr = (vbios_mode *) p;
433 if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&
434 ((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30)) {
436 map->mode_table = mode_ptr;
439 p++;
442 if (map->mode_table == 0) {
443 fprintf(stderr, "Unable to locate the mode table.\n");
444 fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
445 fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
447 fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
448 close_vbios(map);
449 return 0;
454 * Determine size of mode table
458 vbios_mode * mode_ptr = map->mode_table;
460 while (mode_ptr->mode != 0xff) {
461 map->mode_table_size++;
462 mode_ptr++;
467 * Figure out what type of bios we have
468 * order of detection is important
471 if (detect_bios_type(map, sizeof(vbios_modeline_type3))) {
472 map->bios = BT_3;
474 else if (detect_bios_type(map, sizeof(vbios_modeline_type2))) {
475 map->bios = BT_2;
477 else if (detect_bios_type(map, sizeof(vbios_resolution_type1))) {
478 map->bios = BT_1;
480 else {
481 fprintf(stderr, "Unable to determine bios type.\n");
482 fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
483 fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
485 fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
486 fprintf(stderr, "Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
487 fprintf(stderr, "Mode Table Entries: %u\n", map->mode_table_size);
488 return 0;
491 return map;
494 static void close_vbios(vbios_map * map) {
495 assert(!map->unlocked);
497 FREE(map);
500 static void unlock_vbios(vbios_map * map) {
502 assert(!map->unlocked);
504 map->unlocked = TRUE;
506 switch (map->chipset) {
507 case CT_UNKWN:
508 break;
509 case CT_830:
510 case CT_855GM:
511 outl(0x8000005a, 0xcf8);
512 map->b1 = inb(0xcfe);
514 outl(0x8000005a, 0xcf8);
515 outb(0x33, 0xcfe);
516 break;
517 case CT_845G:
518 case CT_865G:
519 case CT_915G:
520 case CT_915GM:
521 case CT_945G:
522 case CT_945GM:
523 case CT_945GME:
524 case CT_946GZ:
525 case CT_G965:
526 case CT_Q965:
527 case CT_965GM:
528 case CT_G33:
529 case CT_Q35:
530 case CT_Q33:
531 case CT_500GMA:
532 outl(0x80000090, 0xcf8);
533 map->b1 = inb(0xcfd);
534 map->b2 = inb(0xcfe);
536 outl(0x80000090, 0xcf8);
537 outb(0x33, 0xcfd);
538 outb(0x33, 0xcfe);
539 break;
542 #if DEBUG
544 cardinal t = inl(0xcfc);
545 printf("unlock PAM: (0x%08x)\n", t);
547 #endif
550 static void relock_vbios(vbios_map * map) {
552 assert(map->unlocked);
553 map->unlocked = FALSE;
555 switch (map->chipset) {
556 case CT_UNKWN:
557 break;
558 case CT_830:
559 case CT_855GM:
560 outl(0x8000005a, 0xcf8);
561 outb(map->b1, 0xcfe);
562 break;
563 case CT_845G:
564 case CT_865G:
565 case CT_915G:
566 case CT_915GM:
567 case CT_945G:
568 case CT_945GM:
569 case CT_945GME:
570 case CT_946GZ:
571 case CT_G965:
572 case CT_Q965:
573 case CT_965GM:
574 case CT_G33:
575 case CT_Q35:
576 case CT_Q33:
577 case CT_500GMA:
578 outl(0x80000090, 0xcf8);
579 outb(map->b1, 0xcfd);
580 outb(map->b2, 0xcfe);
581 break;
584 #if DEBUG
586 cardinal t = inl(0xcfc);
587 printf("relock PAM: (0x%08x)\n", t);
589 #endif
593 static void list_modes(vbios_map *map, cardinal raw) {
594 cardinal i, x, y;
596 for (i=0; i < map->mode_table_size; i++) {
597 switch(map->bios) {
598 case BT_1:
600 vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
602 x = ((((cardinal) res->x2) & 0xf0) << 4) | res->x1;
603 y = ((((cardinal) res->y2) & 0xf0) << 4) | res->y1;
605 if (x != 0 && y != 0) {
606 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
609 if (raw)
611 printf("Mode %02x (raw) :\n\t%02x %02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n", map->mode_table[i].mode, res->unknow1[0],res->unknow1[1], res->x1,res->x_total,res->x2,res->y1,res->y_total,res->y2);
615 break;
616 case BT_2:
618 vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
620 x = res->modelines[0].x1+1;
621 y = res->modelines[0].y1+1;
623 if (x != 0 && y != 0) {
624 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
627 break;
628 case BT_3:
630 vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
632 x = res->modelines[0].x1+1;
633 y = res->modelines[0].y1+1;
635 if (x != 0 && y != 0) {
636 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
639 break;
640 case BT_UNKWN:
641 break;
646 static void gtf_timings(int x, int y, int freq,
647 unsigned long *clock,
648 word *hsyncstart, word *hsyncend, word *hblank,
649 word *vsyncstart, word *vsyncend, word *vblank)
651 int hbl, vbl, vfreq;
653 vbl = y + (y+1)/(20000.0/(11*freq) - 1) + 1.5;
654 vfreq = vbl * freq;
655 hbl = 16 * (int)(x * (30.0 - 300000.0 / vfreq) /
656 (70.0 + 300000.0 / vfreq) / 16.0 + 0.5);
658 *vsyncstart = y;
659 *vsyncend = y + 3;
660 *vblank = vbl - 1;
661 *hsyncstart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 - 1;
662 *hsyncend = x + hbl / 2 - 1;
663 *hblank = x + hbl - 1;
664 *clock = (x + hbl) * vfreq / 1000;
667 static void set_mode(vbios_map * map, cardinal mode, cardinal x, cardinal y, cardinal bp, cardinal htotal, cardinal vtotal) {
668 int xprev, yprev;
669 cardinal i, j;
671 for (i=0; i < map->mode_table_size; i++) {
672 if (map->mode_table[i].mode == mode) {
673 switch(map->bios) {
674 case BT_1:
676 vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
678 if (bp) {
679 map->mode_table[i].bits_per_pixel = bp;
682 res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0);
683 res->x1 = (x & 0xff);
685 res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0);
686 res->y1 = (y & 0xff);
687 if (htotal)
688 res->x_total = ((htotal-x) & 0xff);
690 if (vtotal)
691 res->y_total = ((vtotal-y) & 0xff);
693 break;
694 case BT_2:
696 vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
698 res->xchars = x / 8;
699 res->ychars = y / 16 - 1;
700 xprev = res->modelines[0].x1;
701 yprev = res->modelines[0].y1;
703 for(j=0; j < 3; j++) {
704 vbios_modeline_type2 * modeline = &res->modelines[j];
706 if (modeline->x1 == xprev && modeline->y1 == yprev) {
707 modeline->x1 = modeline->x2 = x-1;
708 modeline->y1 = modeline->y2 = y-1;
710 gtf_timings(x, y, freqs[j], &modeline->clock,
711 &modeline->hsyncstart, &modeline->hsyncend,
712 &modeline->hblank, &modeline->vsyncstart,
713 &modeline->vsyncend, &modeline->vblank);
715 if (htotal)
716 modeline->htotal = htotal;
717 else
718 modeline->htotal = modeline->hblank;
720 if (vtotal)
721 modeline->vtotal = vtotal;
722 else
723 modeline->vtotal = modeline->vblank;
727 break;
728 case BT_3:
730 vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
732 xprev = res->modelines[0].x1;
733 yprev = res->modelines[0].y1;
735 for (j=0; j < 3; j++) {
736 vbios_modeline_type3 * modeline = &res->modelines[j];
738 if (modeline->x1 == xprev && modeline->y1 == yprev) {
739 modeline->x1 = modeline->x2 = x-1;
740 modeline->y1 = modeline->y2 = y-1;
742 gtf_timings(x, y, freqs[j], &modeline->clock,
743 &modeline->hsyncstart, &modeline->hsyncend,
744 &modeline->hblank, &modeline->vsyncstart,
745 &modeline->vsyncend, &modeline->vblank);
746 if (htotal)
747 modeline->htotal = htotal;
748 else
749 modeline->htotal = modeline->hblank;
750 if (vtotal)
751 modeline->vtotal = vtotal;
752 else
753 modeline->vtotal = modeline->vblank;
755 modeline->timing_h = y-1;
756 modeline->timing_v = x-1;
760 break;
761 case BT_UNKWN:
762 break;
768 static void display_map_info(vbios_map * map) {
769 printf("Chipset: %s\n", chipset_type_names[map->chipset]);
770 printf("BIOS: %s\n", bios_type_names[map->bios]);
772 printf("Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
773 printf("Mode Table Entries: %u\n", map->mode_table_size);
777 static int parse_args(cardinal argc, char *argv[], chipset_type *forced_chipset, cardinal *list, cardinal *mode, cardinal *x, cardinal *y, cardinal *bp, cardinal *raw, cardinal *htotal, cardinal *vtotal) {
778 cardinal index = 0;
780 *list = *mode = *x = *y = *raw = *htotal = *vtotal = 0;
781 *bp = 0;
783 *forced_chipset = CT_UNKWN;
786 if ((argc > index) && !strcmp(argv[index], "-c")) {
787 index++;
789 if(argc<=index) {
790 return 0;
793 if (!strcmp(argv[index], "845")) {
794 *forced_chipset = CT_845G;
796 else if (!strcmp(argv[index], "855")) {
797 *forced_chipset = CT_855GM;
799 else if (!strcmp(argv[index], "865")) {
800 *forced_chipset = CT_865G;
802 else if (!strcmp(argv[index], "915G")) {
803 *forced_chipset = CT_915G;
805 else if (!strcmp(argv[index], "915GM")) {
806 *forced_chipset = CT_915GM;
808 else if (!strcmp(argv[index], "945G")) {
809 *forced_chipset = CT_945G;
811 else if (!strcmp(argv[index], "945GM")) {
812 *forced_chipset = CT_945GM;
814 else if (!strcmp(argv[index], "945GME")) {
815 *forced_chipset = CT_945GME;
817 else if (!strcmp(argv[index], "946GZ")) {
818 *forced_chipset = CT_946GZ;
820 else if (!strcmp(argv[index], "G965")) {
821 *forced_chipset = CT_G965;
823 else if (!strcmp(argv[index], "Q965")) {
824 *forced_chipset = CT_Q965;
826 else if (!strcmp(argv[index], "965GM")) {
827 *forced_chipset = CT_965GM;
829 else if (!strcmp(argv[index], "G33")) {
830 *forced_chipset = CT_G33;
832 else if (!strcmp(argv[index], "Q35")) {
833 *forced_chipset = CT_Q35;
835 else if (!strcmp(argv[index], "Q33")) {
836 *forced_chipset = CT_Q33;
838 else if (!strcmp(argv[index], "500GMA")) {
839 *forced_chipset = CT_500GMA;
841 else {
842 *forced_chipset = CT_UNKWN;
845 index++;
847 if (argc<=index) {
848 return 0;
852 if ((argc > index) && !strcmp(argv[index], "-l")) {
853 *list = 1;
854 index++;
856 if(argc<=index) {
857 return 0;
861 if ((argc > index) && !strcmp(argv[index], "-r")) {
862 *raw = 1;
863 index++;
865 if(argc<=index) {
866 return 0;
870 if (argc-index < 3 || argc-index > 6) {
871 return -1;
874 *mode = (cardinal) strtol(argv[index], NULL, 16);
875 *x = (cardinal)atoi(argv[index+1]);
876 *y = (cardinal)atoi(argv[index+2]);
879 if (argc-index > 3) {
880 *bp = (cardinal)atoi(argv[index+3]);
882 else {
883 *bp = 0;
886 if (argc-index > 4) {
887 *htotal = (cardinal)atoi(argv[index+4]);
889 else {
890 *htotal = 0;
893 if (argc-index > 5) {
894 *vtotal = (cardinal)atoi(argv[index+5]);
896 else {
897 *vtotal = 0;
900 return 0;
903 static void usage(void) {
904 printf("Usage: 915resolution [-c chipset] [-l] [mode X Y] [bits/pixel] [htotal] [vtotal]\n");
905 printf(" Set the resolution to XxY for a video mode\n");
906 printf(" Bits per pixel are optional. htotal/vtotal settings are additionally optional.\n");
907 printf(" Options:\n");
908 printf(" -c force chipset type (THIS IS USED FOR DEBUG PURPOSES)\n");
909 printf(" -l display the modes found in the video BIOS\n");
910 printf(" -r display the modes found in the video BIOS in raw mode (THIS IS USED FOR DEBUG PURPOSES)\n");
913 static int main (int argc, char *argv[])
915 vbios_map * map;
916 cardinal list, mode, x, y, bp, raw, htotal, vtotal;
917 chipset_type forced_chipset;
919 printf("Intel 800/900 Series VBIOS Hack : version %s\n\n", RES915_VERSION);
921 if (parse_args(argc, argv, &forced_chipset, &list, &mode, &x, &y, &bp, &raw, &htotal, &vtotal) == -1) {
922 usage();
923 return 2;
926 map = open_vbios(forced_chipset);
927 display_map_info(map);
929 printf("\n");
931 if (list) {
932 list_modes(map, raw);
935 if (mode!=0 && x!=0 && y!=0) {
936 unlock_vbios(map);
938 set_mode(map, mode, x, y, bp, htotal, vtotal);
940 relock_vbios(map);
942 printf("Patch mode %02x to resolution %dx%d complete\n", mode, x, y);
944 if (list) {
945 list_modes(map, raw);
949 close_vbios(map);
951 return 0;
958 static grub_err_t
959 grub_cmd_915resolution (grub_command_t cmd __attribute__ ((unused)),
960 int argc, char *argv[])
962 return main (argc, argv);
965 static grub_command_t cmd;
967 GRUB_MOD_INIT(915resolution)
969 cmd = grub_register_command ("915resolution", grub_cmd_915resolution,
970 "915resolution", "Intel VBE editor");
973 GRUB_MOD_FINI(915resolution)
975 grub_unregister_command (cmd);