Fix warnings
[grub-extras.git] / 915resolution.c
blob6e38c43cf92ade2494981e39cf3822174c059bf8
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 GRUB_MOD_LICENSE ("GPLv3+");
69 #define printf grub_printf
70 #define malloc grub_malloc
71 #define free grub_free
72 #define strcmp grub_strcmp
73 #define fprintf(stream,template,args...) grub_printf(template, ## args)
74 #define strtol(x,y,z) grub_strtoul(x,y,z)
75 #define atoi(x) grub_strtoul(x,NULL,10)
76 #define assert(x)
77 #define memset grub_memset
78 #define outl grub_outl
79 #define outb grub_outb
80 #define inl grub_inl
81 #define inb grub_inb
83 #define NEW(a) ((a *)(malloc(sizeof(a))))
84 #define FREE(a) (free(a))
86 #define VBIOS_START 0xc0000
87 #define VBIOS_SIZE 0x10000
89 #define VBIOS_FILE "/dev/mem"
91 #define FALSE 0
92 #define TRUE 1
94 #define MODE_TABLE_OFFSET_845G 617
96 #define RES915_VERSION "0.5.3"
98 #define ATI_SIGNATURE1 "ATI MOBILITY RADEON"
99 #define ATI_SIGNATURE2 "ATI Technologies Inc"
100 #define NVIDIA_SIGNATURE "NVIDIA Corp"
101 #define INTEL_SIGNATURE "Intel Corp"
103 #define DEBUG 0
105 typedef unsigned char * address;
106 typedef unsigned char byte;
107 typedef unsigned short word;
108 typedef unsigned char boolean;
109 typedef unsigned int cardinal;
111 typedef enum {
112 CT_UNKWN, CT_830, CT_845G, CT_855GM, CT_865G, CT_915G, CT_915GM, CT_945G, CT_945GM, CT_945GME,
113 CT_946GZ, CT_G965, CT_Q965, CT_965GM, CT_G33, CT_Q33, CT_Q35, CT_500GMA
114 } chipset_type;
116 const char *const chipset_type_names[] = {
117 "UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",
118 "946GZ", "G965", "Q965", "965GM", "G33", "Q33", "Q35", "500GMA"
121 typedef enum {
122 BT_UNKWN, BT_1, BT_2, BT_3
123 } bios_type;
125 const char *const bios_type_names[] = {"UNKNOWN", "TYPE 1", "TYPE 2", "TYPE 3"};
127 int freqs[] = { 60, 75, 85 };
129 typedef struct {
130 byte mode;
131 byte bits_per_pixel;
132 word resolution;
133 byte unknown;
134 } __attribute__((packed)) vbios_mode;
136 typedef struct {
137 byte unknow1[2];
138 byte x1;
139 byte x_total;
140 byte x2;
141 byte y1;
142 byte y_total;
143 byte y2;
144 } __attribute__((packed)) vbios_resolution_type1;
146 typedef struct {
147 unsigned long clock;
149 word x1;
150 word htotal;
151 word x2;
152 word hblank;
153 word hsyncstart;
154 word hsyncend;
156 word y1;
157 word vtotal;
158 word y2;
159 word vblank;
160 word vsyncstart;
161 word vsyncend;
162 } __attribute__((packed)) vbios_modeline_type2;
164 typedef struct {
165 byte xchars;
166 byte ychars;
167 byte unknown[4];
169 vbios_modeline_type2 modelines[];
170 } __attribute__((packed)) vbios_resolution_type2;
172 typedef struct {
173 unsigned long clock;
175 word x1;
176 word htotal;
177 word x2;
178 word hblank;
179 word hsyncstart;
180 word hsyncend;
182 word y1;
183 word vtotal;
184 word y2;
185 word vblank;
186 word vsyncstart;
187 word vsyncend;
189 word timing_h;
190 word timing_v;
192 byte unknown[6];
193 } __attribute__((packed)) vbios_modeline_type3;
195 typedef struct {
196 unsigned char unknown[6];
198 vbios_modeline_type3 modelines[];
199 } __attribute__((packed)) vbios_resolution_type3;
202 typedef struct {
203 cardinal chipset_id;
204 chipset_type chipset;
205 bios_type bios;
207 int bios_fd;
208 address bios_ptr;
210 vbios_mode * mode_table;
211 cardinal mode_table_size;
213 byte b1, b2;
215 boolean unlocked;
216 } vbios_map;
219 static cardinal get_chipset_id(void) {
220 outl(0x80000000, 0xcf8);
221 return inl(0xcfc);
224 static chipset_type get_chipset(cardinal id) {
225 chipset_type type;
227 switch (id) {
228 case 0x35758086:
229 type = CT_830;
230 break;
232 case 0x25608086:
233 type = CT_845G;
234 break;
236 case 0x35808086:
237 type = CT_855GM;
238 break;
240 case 0x25708086:
241 type = CT_865G;
242 break;
244 case 0x25808086:
245 type = CT_915G;
246 break;
248 case 0x25908086:
249 type = CT_915GM;
250 break;
252 case 0x27708086:
253 type = CT_945G;
254 break;
256 case 0x27a08086:
257 type = CT_945GM;
258 break;
260 case 0x27ac8086:
261 type = CT_945GME;
262 break;
264 case 0x29708086:
265 type = CT_946GZ;
266 break;
268 case 0x29a08086:
269 type = CT_G965;
270 break;
272 case 0x29908086:
273 type = CT_Q965;
274 break;
276 case 0x2a008086:
277 type = CT_965GM;
278 break;
280 case 0x29c08086:
281 type = CT_G33;
282 break;
284 case 0x29b08086:
285 type = CT_Q35;
286 break;
288 case 0x29d08086:
289 type = CT_Q33;
290 break;
292 case 0x81008086:
293 type = CT_500GMA;
294 break;
296 default:
297 type = CT_UNKWN;
298 break;
301 return type;
305 static vbios_resolution_type1 * map_type1_resolution(vbios_map * map, word res) {
306 vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res));
307 return ptr;
310 static vbios_resolution_type2 * map_type2_resolution(vbios_map * map, word res) {
311 vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res));
312 return ptr;
315 static vbios_resolution_type3 * map_type3_resolution(vbios_map * map, word res) {
316 vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res));
317 return ptr;
321 static boolean detect_bios_type(vbios_map * map, int entry_size) {
322 unsigned i;
323 short int r1, r2;
325 r1 = r2 = 32000;
327 for (i=0; i < map->mode_table_size; i++) {
328 if (map->mode_table[i].resolution <= r1) {
329 r1 = map->mode_table[i].resolution;
331 else {
332 if (map->mode_table[i].resolution <= r2) {
333 r2 = map->mode_table[i].resolution;
337 /*printf("r1 = %d r2 = %d\n", r1, r2);*/
340 return (r2-r1-6) % entry_size == 0;
344 static void close_vbios(vbios_map * map);
347 static vbios_map * open_vbios(chipset_type forced_chipset) {
348 vbios_map * map = NEW(vbios_map);
349 memset (map, 0, sizeof(vbios_map));
352 * Determine chipset
355 if (forced_chipset == CT_UNKWN) {
356 map->chipset_id = get_chipset_id();
358 map->chipset = get_chipset(map->chipset_id);
360 else if (forced_chipset != CT_UNKWN) {
361 map->chipset = forced_chipset;
363 else {
364 map->chipset = CT_915GM;
368 * Map the video bios to memory
371 map->bios_ptr = (unsigned char *) VBIOS_START;
373 #if 0
375 * check if we have ATI Radeon
378 if (memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE1, strlen(ATI_SIGNATURE1)) ||
379 memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE2, strlen(ATI_SIGNATURE2)) ) {
380 fprintf(stderr, "ATI chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
381 close(map->bios_fd);
382 exit(2);
386 * check if we have NVIDIA
389 if (memmem(map->bios_ptr, VBIOS_SIZE, NVIDIA_SIGNATURE, strlen(NVIDIA_SIGNATURE))) {
390 fprintf(stderr, "NVIDIA chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
391 close(map->bios_fd);
392 exit(2);
396 * check if we have Intel
399 if (map->chipset == CT_UNKWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) {
400 fprintf(stderr, "Intel chipset detected. However, 915resolution was unable to determine the chipset type.\n");
402 fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
404 fprintf(stderr, "Please report this problem to stomljen@yahoo.com\n");
406 close_vbios(map);
407 exit(2);
409 #endif
412 * check for others
415 if (map->chipset == CT_UNKWN) {
416 fprintf(stderr, "Unknown chipset type and unrecognized bios.\n");
417 fprintf(stderr, "915resolution only works with Intel 800/900 series graphic chipsets.\n");
419 fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
420 close_vbios(map);
421 return 0;
425 * Figure out where the mode table is
429 address p = map->bios_ptr + 16;
430 address limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));
432 while (p < limit && map->mode_table == 0) {
433 vbios_mode * mode_ptr = (vbios_mode *) p;
435 if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&
436 ((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30)) {
438 map->mode_table = mode_ptr;
441 p++;
444 if (map->mode_table == 0) {
445 fprintf(stderr, "Unable to locate the mode table.\n");
446 fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
447 fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
449 fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
450 close_vbios(map);
451 return 0;
456 * Determine size of mode table
460 vbios_mode * mode_ptr = map->mode_table;
462 while (mode_ptr->mode != 0xff) {
463 map->mode_table_size++;
464 mode_ptr++;
469 * Figure out what type of bios we have
470 * order of detection is important
473 if (detect_bios_type(map, sizeof(vbios_modeline_type3))) {
474 map->bios = BT_3;
476 else if (detect_bios_type(map, sizeof(vbios_modeline_type2))) {
477 map->bios = BT_2;
479 else if (detect_bios_type(map, sizeof(vbios_resolution_type1))) {
480 map->bios = BT_1;
482 else {
483 fprintf(stderr, "Unable to determine bios type.\n");
484 fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
485 fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
487 fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
488 fprintf(stderr, "Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
489 fprintf(stderr, "Mode Table Entries: %u\n", map->mode_table_size);
490 return 0;
493 return map;
496 static void close_vbios(vbios_map * map) {
497 assert(!map->unlocked);
499 FREE(map);
502 static void unlock_vbios(vbios_map * map) {
504 assert(!map->unlocked);
506 map->unlocked = TRUE;
508 switch (map->chipset) {
509 case CT_UNKWN:
510 break;
511 case CT_830:
512 case CT_855GM:
513 outl(0x8000005a, 0xcf8);
514 map->b1 = inb(0xcfe);
516 outl(0x8000005a, 0xcf8);
517 outb(0x33, 0xcfe);
518 break;
519 case CT_845G:
520 case CT_865G:
521 case CT_915G:
522 case CT_915GM:
523 case CT_945G:
524 case CT_945GM:
525 case CT_945GME:
526 case CT_946GZ:
527 case CT_G965:
528 case CT_Q965:
529 case CT_965GM:
530 case CT_G33:
531 case CT_Q35:
532 case CT_Q33:
533 case CT_500GMA:
534 outl(0x80000090, 0xcf8);
535 map->b1 = inb(0xcfd);
536 map->b2 = inb(0xcfe);
538 outl(0x80000090, 0xcf8);
539 outb(0x33, 0xcfd);
540 outb(0x33, 0xcfe);
541 break;
544 #if DEBUG
546 cardinal t = inl(0xcfc);
547 printf("unlock PAM: (0x%08x)\n", t);
549 #endif
552 static void relock_vbios(vbios_map * map) {
554 assert(map->unlocked);
555 map->unlocked = FALSE;
557 switch (map->chipset) {
558 case CT_UNKWN:
559 break;
560 case CT_830:
561 case CT_855GM:
562 outl(0x8000005a, 0xcf8);
563 outb(map->b1, 0xcfe);
564 break;
565 case CT_845G:
566 case CT_865G:
567 case CT_915G:
568 case CT_915GM:
569 case CT_945G:
570 case CT_945GM:
571 case CT_945GME:
572 case CT_946GZ:
573 case CT_G965:
574 case CT_Q965:
575 case CT_965GM:
576 case CT_G33:
577 case CT_Q35:
578 case CT_Q33:
579 case CT_500GMA:
580 outl(0x80000090, 0xcf8);
581 outb(map->b1, 0xcfd);
582 outb(map->b2, 0xcfe);
583 break;
586 #if DEBUG
588 cardinal t = inl(0xcfc);
589 printf("relock PAM: (0x%08x)\n", t);
591 #endif
595 static void list_modes(vbios_map *map, cardinal raw) {
596 cardinal i, x, y;
598 for (i=0; i < map->mode_table_size; i++) {
599 switch(map->bios) {
600 case BT_1:
602 vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
604 x = ((((cardinal) res->x2) & 0xf0) << 4) | res->x1;
605 y = ((((cardinal) res->y2) & 0xf0) << 4) | res->y1;
607 if (x != 0 && y != 0) {
608 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
611 if (raw)
613 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);
617 break;
618 case BT_2:
620 vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
622 x = res->modelines[0].x1+1;
623 y = res->modelines[0].y1+1;
625 if (x != 0 && y != 0) {
626 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
629 break;
630 case BT_3:
632 vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
634 x = res->modelines[0].x1+1;
635 y = res->modelines[0].y1+1;
637 if (x != 0 && y != 0) {
638 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
641 break;
642 case BT_UNKWN:
643 break;
648 static void gtf_timings(int x, int y, int freq,
649 unsigned long *clock,
650 word *hsyncstart, word *hsyncend, word *hblank,
651 word *vsyncstart, word *vsyncend, word *vblank)
653 int hbl, vbl, vfreq;
655 vbl = y + (y+1)/(20000.0/(11*freq) - 1) + 1.5;
656 vfreq = vbl * freq;
657 hbl = 16 * (int)(x * (30.0 - 300000.0 / vfreq) /
658 (70.0 + 300000.0 / vfreq) / 16.0 + 0.5);
660 *vsyncstart = y;
661 *vsyncend = y + 3;
662 *vblank = vbl - 1;
663 *hsyncstart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 - 1;
664 *hsyncend = x + hbl / 2 - 1;
665 *hblank = x + hbl - 1;
666 *clock = (x + hbl) * vfreq / 1000;
669 static void set_mode(vbios_map * map, cardinal mode, cardinal x, cardinal y, cardinal bp, cardinal htotal, cardinal vtotal) {
670 int xprev, yprev;
671 cardinal i, j;
673 for (i=0; i < map->mode_table_size; i++) {
674 if (map->mode_table[i].mode == mode) {
675 switch(map->bios) {
676 case BT_1:
678 vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
680 if (bp) {
681 map->mode_table[i].bits_per_pixel = bp;
684 res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0);
685 res->x1 = (x & 0xff);
687 res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0);
688 res->y1 = (y & 0xff);
689 if (htotal)
690 res->x_total = ((htotal-x) & 0xff);
692 if (vtotal)
693 res->y_total = ((vtotal-y) & 0xff);
695 break;
696 case BT_2:
698 vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
700 res->xchars = x / 8;
701 res->ychars = y / 16 - 1;
702 xprev = res->modelines[0].x1;
703 yprev = res->modelines[0].y1;
705 for(j=0; j < 3; j++) {
706 vbios_modeline_type2 * modeline = &res->modelines[j];
708 if (modeline->x1 == xprev && modeline->y1 == yprev) {
709 modeline->x1 = modeline->x2 = x-1;
710 modeline->y1 = modeline->y2 = y-1;
712 gtf_timings(x, y, freqs[j], &modeline->clock,
713 &modeline->hsyncstart, &modeline->hsyncend,
714 &modeline->hblank, &modeline->vsyncstart,
715 &modeline->vsyncend, &modeline->vblank);
717 if (htotal)
718 modeline->htotal = htotal;
719 else
720 modeline->htotal = modeline->hblank;
722 if (vtotal)
723 modeline->vtotal = vtotal;
724 else
725 modeline->vtotal = modeline->vblank;
729 break;
730 case BT_3:
732 vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
734 xprev = res->modelines[0].x1;
735 yprev = res->modelines[0].y1;
737 for (j=0; j < 3; j++) {
738 vbios_modeline_type3 * modeline = &res->modelines[j];
740 if (modeline->x1 == xprev && modeline->y1 == yprev) {
741 modeline->x1 = modeline->x2 = x-1;
742 modeline->y1 = modeline->y2 = y-1;
744 gtf_timings(x, y, freqs[j], &modeline->clock,
745 &modeline->hsyncstart, &modeline->hsyncend,
746 &modeline->hblank, &modeline->vsyncstart,
747 &modeline->vsyncend, &modeline->vblank);
748 if (htotal)
749 modeline->htotal = htotal;
750 else
751 modeline->htotal = modeline->hblank;
752 if (vtotal)
753 modeline->vtotal = vtotal;
754 else
755 modeline->vtotal = modeline->vblank;
757 modeline->timing_h = y-1;
758 modeline->timing_v = x-1;
762 break;
763 case BT_UNKWN:
764 break;
770 static void display_map_info(vbios_map * map) {
771 printf("Chipset: %s\n", chipset_type_names[map->chipset]);
772 printf("BIOS: %s\n", bios_type_names[map->bios]);
774 printf("Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
775 printf("Mode Table Entries: %u\n", map->mode_table_size);
779 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) {
780 cardinal index = 0;
782 *list = *mode = *x = *y = *raw = *htotal = *vtotal = 0;
783 *bp = 0;
785 *forced_chipset = CT_UNKWN;
788 if ((argc > index) && !strcmp(argv[index], "-c")) {
789 index++;
791 if(argc<=index) {
792 return 0;
795 if (!strcmp(argv[index], "845")) {
796 *forced_chipset = CT_845G;
798 else if (!strcmp(argv[index], "855")) {
799 *forced_chipset = CT_855GM;
801 else if (!strcmp(argv[index], "865")) {
802 *forced_chipset = CT_865G;
804 else if (!strcmp(argv[index], "915G")) {
805 *forced_chipset = CT_915G;
807 else if (!strcmp(argv[index], "915GM")) {
808 *forced_chipset = CT_915GM;
810 else if (!strcmp(argv[index], "945G")) {
811 *forced_chipset = CT_945G;
813 else if (!strcmp(argv[index], "945GM")) {
814 *forced_chipset = CT_945GM;
816 else if (!strcmp(argv[index], "945GME")) {
817 *forced_chipset = CT_945GME;
819 else if (!strcmp(argv[index], "946GZ")) {
820 *forced_chipset = CT_946GZ;
822 else if (!strcmp(argv[index], "G965")) {
823 *forced_chipset = CT_G965;
825 else if (!strcmp(argv[index], "Q965")) {
826 *forced_chipset = CT_Q965;
828 else if (!strcmp(argv[index], "965GM")) {
829 *forced_chipset = CT_965GM;
831 else if (!strcmp(argv[index], "G33")) {
832 *forced_chipset = CT_G33;
834 else if (!strcmp(argv[index], "Q35")) {
835 *forced_chipset = CT_Q35;
837 else if (!strcmp(argv[index], "Q33")) {
838 *forced_chipset = CT_Q33;
840 else if (!strcmp(argv[index], "500GMA")) {
841 *forced_chipset = CT_500GMA;
843 else {
844 *forced_chipset = CT_UNKWN;
847 index++;
849 if (argc<=index) {
850 return 0;
854 if ((argc > index) && !strcmp(argv[index], "-l")) {
855 *list = 1;
856 index++;
858 if(argc<=index) {
859 return 0;
863 if ((argc > index) && !strcmp(argv[index], "-r")) {
864 *raw = 1;
865 index++;
867 if(argc<=index) {
868 return 0;
872 if (argc-index < 3 || argc-index > 6) {
873 return -1;
876 *mode = (cardinal) strtol(argv[index], NULL, 16);
877 *x = (cardinal)atoi(argv[index+1]);
878 *y = (cardinal)atoi(argv[index+2]);
881 if (argc-index > 3) {
882 *bp = (cardinal)atoi(argv[index+3]);
884 else {
885 *bp = 0;
888 if (argc-index > 4) {
889 *htotal = (cardinal)atoi(argv[index+4]);
891 else {
892 *htotal = 0;
895 if (argc-index > 5) {
896 *vtotal = (cardinal)atoi(argv[index+5]);
898 else {
899 *vtotal = 0;
902 return 0;
905 static void usage(void) {
906 printf("Usage: 915resolution [-c chipset] [-l] [mode X Y] [bits/pixel] [htotal] [vtotal]\n");
907 printf(" Set the resolution to XxY for a video mode\n");
908 printf(" Bits per pixel are optional. htotal/vtotal settings are additionally optional.\n");
909 printf(" Options:\n");
910 printf(" -c force chipset type (THIS IS USED FOR DEBUG PURPOSES)\n");
911 printf(" -l display the modes found in the video BIOS\n");
912 printf(" -r display the modes found in the video BIOS in raw mode (THIS IS USED FOR DEBUG PURPOSES)\n");
915 static int main_915 (int argc, char *argv[])
917 vbios_map * map;
918 cardinal list, mode, x, y, bp, raw, htotal, vtotal;
919 chipset_type forced_chipset;
921 printf("Intel 800/900 Series VBIOS Hack : version %s\n\n", RES915_VERSION);
923 if (parse_args(argc, argv, &forced_chipset, &list, &mode, &x, &y, &bp, &raw, &htotal, &vtotal) == -1) {
924 usage();
925 return 2;
928 map = open_vbios(forced_chipset);
929 display_map_info(map);
931 printf("\n");
933 if (list) {
934 list_modes(map, raw);
937 if (mode!=0 && x!=0 && y!=0) {
938 unlock_vbios(map);
940 set_mode(map, mode, x, y, bp, htotal, vtotal);
942 relock_vbios(map);
944 printf("Patch mode %02x to resolution %dx%d complete\n", mode, x, y);
946 if (list) {
947 list_modes(map, raw);
951 close_vbios(map);
953 return 0;
960 static grub_err_t
961 grub_cmd_915resolution (grub_command_t cmd __attribute__ ((unused)),
962 int argc, char *argv[])
964 return main_915 (argc, argv);
967 static grub_command_t cmd;
969 GRUB_MOD_INIT(915resolution)
971 cmd = grub_register_command ("915resolution", grub_cmd_915resolution,
972 "915resolution", "Intel VBE editor");
975 GRUB_MOD_FINI(915resolution)
977 grub_unregister_command (cmd);