Fix fprintf 64-bit format specifiers
[grub-extras.git] / 915resolution / 915resolution.c
blob9a73d5fb1e772cd0b7593d23da666d10f7333e04
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, ...) grub_printf(__VA_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 CT_GM45, CT_GMA3150, CT_HD3000
115 } chipset_type;
117 const char *const chipset_type_names[] = {
118 "UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",
119 "946GZ", "G965", "Q965", "965GM", "G33", "Q33", "Q35", "500GMA",
120 "GM45", "GMA3150", "HD3000"
123 typedef enum {
124 BT_UNKWN, BT_1, BT_2, BT_3
125 } bios_type;
127 const char *const bios_type_names[] = {"UNKNOWN", "TYPE 1", "TYPE 2", "TYPE 3"};
129 int freqs[] = { 60, 75, 85 };
131 typedef struct {
132 byte mode;
133 byte bits_per_pixel;
134 word resolution;
135 byte unknown;
136 } __attribute__((packed)) vbios_mode;
138 typedef struct {
139 byte unknow1[2];
140 byte x1;
141 byte x_total;
142 byte x2;
143 byte y1;
144 byte y_total;
145 byte y2;
146 } __attribute__((packed)) vbios_resolution_type1;
148 typedef struct {
149 unsigned long clock;
151 word x1;
152 word htotal;
153 word x2;
154 word hblank;
155 word hsyncstart;
156 word hsyncend;
158 word y1;
159 word vtotal;
160 word y2;
161 word vblank;
162 word vsyncstart;
163 word vsyncend;
164 } __attribute__((packed)) vbios_modeline_type2;
166 typedef struct {
167 byte xchars;
168 byte ychars;
169 byte unknown[4];
171 vbios_modeline_type2 modelines[];
172 } __attribute__((packed)) vbios_resolution_type2;
174 typedef struct {
175 unsigned long clock;
177 word x1;
178 word htotal;
179 word x2;
180 word hblank;
181 word hsyncstart;
182 word hsyncend;
184 word y1;
185 word vtotal;
186 word y2;
187 word vblank;
188 word vsyncstart;
189 word vsyncend;
191 word timing_h;
192 word timing_v;
194 byte unknown[6];
195 } __attribute__((packed)) vbios_modeline_type3;
197 typedef struct {
198 unsigned char unknown[6];
200 vbios_modeline_type3 modelines[];
201 } __attribute__((packed)) vbios_resolution_type3;
204 typedef struct {
205 cardinal chipset_id;
206 chipset_type chipset;
207 bios_type bios;
209 int bios_fd;
210 address bios_ptr;
212 vbios_mode * mode_table;
213 cardinal mode_table_size;
215 byte b1, b2;
217 boolean unlocked;
218 } vbios_map;
221 static cardinal get_chipset_id(void) {
222 outl(0x80000000, 0xcf8);
223 return inl(0xcfc);
226 static chipset_type get_chipset(cardinal id) {
227 chipset_type type;
229 switch (id) {
230 case 0x35758086:
231 type = CT_830;
232 break;
234 case 0x25608086:
235 type = CT_845G;
236 break;
238 case 0x35808086:
239 type = CT_855GM;
240 break;
242 case 0x25708086:
243 type = CT_865G;
244 break;
246 case 0x25808086:
247 type = CT_915G;
248 break;
250 case 0x25908086:
251 type = CT_915GM;
252 break;
254 case 0x27708086:
255 type = CT_945G;
256 break;
258 case 0x27a08086:
259 type = CT_945GM;
260 break;
262 case 0x27ac8086:
263 type = CT_945GME;
264 break;
266 case 0x29708086:
267 type = CT_946GZ;
268 break;
270 case 0x29a08086:
271 type = CT_G965;
272 break;
274 case 0x29908086:
275 type = CT_Q965;
276 break;
278 case 0x2a008086:
279 type = CT_965GM;
280 break;
282 case 0x29c08086:
283 type = CT_G33;
284 break;
286 case 0x29b08086:
287 type = CT_Q35;
288 break;
290 case 0x29d08086:
291 type = CT_Q33;
292 break;
294 case 0x81008086:
295 type = CT_500GMA;
296 break;
298 case 0xa0008086:
299 type = CT_GMA3150;
300 break;
302 case 0xa0108086:
303 type = CT_GMA3150;
304 break;
306 case 0x01048086:
307 type = CT_HD3000;
308 break;
310 case 0x2a408086:
311 type = CT_GM45;
312 break;
314 case 0x2a018086:
315 type = CT_965GM;
316 break;
318 case 0x2a028086:
319 type = CT_965GM;
320 break;
322 default:
323 type = CT_UNKWN;
324 break;
327 return type;
331 static vbios_resolution_type1 * map_type1_resolution(vbios_map * map, word res) {
332 vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res));
333 return ptr;
336 static vbios_resolution_type2 * map_type2_resolution(vbios_map * map, word res) {
337 vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res));
338 return ptr;
341 static vbios_resolution_type3 * map_type3_resolution(vbios_map * map, word res) {
342 vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res));
343 return ptr;
347 static boolean detect_bios_type(vbios_map * map, int entry_size) {
348 unsigned i;
349 short int r1, r2;
351 r1 = r2 = 32000;
353 for (i=0; i < map->mode_table_size; i++) {
354 if (map->mode_table[i].resolution <= r1) {
355 r1 = map->mode_table[i].resolution;
357 else {
358 if (map->mode_table[i].resolution <= r2) {
359 r2 = map->mode_table[i].resolution;
363 /*printf("r1 = %d r2 = %d\n", r1, r2);*/
366 return (r2-r1-6) % entry_size == 0;
370 static void close_vbios(vbios_map * map);
373 static vbios_map * open_vbios(chipset_type forced_chipset) {
374 vbios_map * map = NEW(vbios_map);
375 memset (map, 0, sizeof(vbios_map));
378 * Determine chipset
381 if (forced_chipset == CT_UNKWN) {
382 map->chipset_id = get_chipset_id();
384 map->chipset = get_chipset(map->chipset_id);
386 else if (forced_chipset != CT_UNKWN) {
387 map->chipset = forced_chipset;
389 else {
390 map->chipset = CT_915GM;
394 * Map the video bios to memory
397 map->bios_ptr = (unsigned char *) VBIOS_START;
399 #if 0
401 * check if we have ATI Radeon
404 if (memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE1, strlen(ATI_SIGNATURE1)) ||
405 memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE2, strlen(ATI_SIGNATURE2)) ) {
406 fprintf(stderr, "ATI chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
407 close(map->bios_fd);
408 exit(2);
412 * check if we have NVIDIA
415 if (memmem(map->bios_ptr, VBIOS_SIZE, NVIDIA_SIGNATURE, strlen(NVIDIA_SIGNATURE))) {
416 fprintf(stderr, "NVIDIA chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
417 close(map->bios_fd);
418 exit(2);
422 * check if we have Intel
425 if (map->chipset == CT_UNKWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) {
426 fprintf(stderr, "Intel chipset detected. However, 915resolution was unable to determine the chipset type.\n");
428 fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
430 fprintf(stderr, "Please report this problem to stomljen@yahoo.com\n");
432 close_vbios(map);
433 exit(2);
435 #endif
438 * check for others
441 if (map->chipset == CT_UNKWN) {
442 fprintf(stderr, "Unknown chipset type and unrecognized bios.\n");
443 fprintf(stderr, "915resolution only works with Intel 800/900 series graphic chipsets.\n");
445 fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
446 close_vbios(map);
447 return 0;
451 * Figure out where the mode table is
455 address p = map->bios_ptr + 16;
456 address limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));
458 while (p < limit && map->mode_table == 0) {
459 vbios_mode * mode_ptr = (vbios_mode *) p;
461 if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&
462 ((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30)) {
464 map->mode_table = mode_ptr;
467 p++;
470 if (map->mode_table == 0) {
471 fprintf(stderr, "Unable to locate the mode table.\n");
472 fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
473 fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
475 fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
476 close_vbios(map);
477 return 0;
482 * Determine size of mode table
486 vbios_mode * mode_ptr = map->mode_table;
488 while (mode_ptr->mode != 0xff) {
489 map->mode_table_size++;
490 mode_ptr++;
495 * Figure out what type of bios we have
496 * order of detection is important
499 if (detect_bios_type(map, sizeof(vbios_modeline_type3))) {
500 map->bios = BT_3;
502 else if (detect_bios_type(map, sizeof(vbios_modeline_type2))) {
503 map->bios = BT_2;
505 else if (detect_bios_type(map, sizeof(vbios_resolution_type1))) {
506 map->bios = BT_1;
508 else {
509 fprintf(stderr, "Unable to determine bios type.\n");
510 fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
511 fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
513 fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
514 fprintf(stderr, "Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
515 fprintf(stderr, "Mode Table Entries: %u\n", map->mode_table_size);
516 return 0;
519 return map;
522 static void close_vbios(vbios_map * map) {
523 assert(!map->unlocked);
525 FREE(map);
528 static void unlock_vbios(vbios_map * map) {
530 assert(!map->unlocked);
532 map->unlocked = TRUE;
534 switch (map->chipset) {
535 case CT_UNKWN:
536 break;
537 case CT_830:
538 case CT_855GM:
539 outl(0x8000005a, 0xcf8);
540 map->b1 = inb(0xcfe);
542 outl(0x8000005a, 0xcf8);
543 outb(0x33, 0xcfe);
544 break;
545 case CT_845G:
546 case CT_865G:
547 case CT_915G:
548 case CT_915GM:
549 case CT_945G:
550 case CT_945GM:
551 case CT_945GME:
552 case CT_946GZ:
553 case CT_G965:
554 case CT_Q965:
555 case CT_965GM:
556 case CT_G33:
557 case CT_Q35:
558 case CT_Q33:
559 case CT_500GMA:
560 case CT_GM45:
561 case CT_GMA3150:
562 case CT_HD3000:
563 outl(0x80000090, 0xcf8);
564 map->b1 = inb(0xcfd);
565 map->b2 = inb(0xcfe);
567 outl(0x80000090, 0xcf8);
568 outb(0x33, 0xcfd);
569 outb(0x33, 0xcfe);
570 break;
573 #if DEBUG
575 cardinal t = inl(0xcfc);
576 printf("unlock PAM: (0x%08x)\n", t);
578 #endif
581 static void relock_vbios(vbios_map * map) {
583 assert(map->unlocked);
584 map->unlocked = FALSE;
586 switch (map->chipset) {
587 case CT_UNKWN:
588 break;
589 case CT_830:
590 case CT_855GM:
591 outl(0x8000005a, 0xcf8);
592 outb(map->b1, 0xcfe);
593 break;
594 case CT_845G:
595 case CT_865G:
596 case CT_915G:
597 case CT_915GM:
598 case CT_945G:
599 case CT_945GM:
600 case CT_945GME:
601 case CT_946GZ:
602 case CT_G965:
603 case CT_Q965:
604 case CT_965GM:
605 case CT_G33:
606 case CT_Q35:
607 case CT_Q33:
608 case CT_500GMA:
609 case CT_GM45:
610 case CT_GMA3150:
611 case CT_HD3000:
612 outl(0x80000090, 0xcf8);
613 outb(map->b1, 0xcfd);
614 outb(map->b2, 0xcfe);
615 break;
618 #if DEBUG
620 cardinal t = inl(0xcfc);
621 printf("relock PAM: (0x%08x)\n", t);
623 #endif
627 static void list_modes(vbios_map *map, cardinal raw) {
628 cardinal i, x, y;
630 for (i=0; i < map->mode_table_size; i++) {
631 switch(map->bios) {
632 case BT_1:
634 vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
636 x = ((((cardinal) res->x2) & 0xf0) << 4) | res->x1;
637 y = ((((cardinal) res->y2) & 0xf0) << 4) | res->y1;
639 if (x != 0 && y != 0) {
640 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
643 if (raw)
645 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);
649 break;
650 case BT_2:
652 vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
654 x = res->modelines[0].x1+1;
655 y = res->modelines[0].y1+1;
657 if (x != 0 && y != 0) {
658 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
661 break;
662 case BT_3:
664 vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
666 x = res->modelines[0].x1+1;
667 y = res->modelines[0].y1+1;
669 if (x != 0 && y != 0) {
670 printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
673 break;
674 case BT_UNKWN:
675 break;
680 static void gtf_timings(int x, int y, int freq,
681 unsigned long *clock,
682 word *hsyncstart, word *hsyncend, word *hblank,
683 word *vsyncstart, word *vsyncend, word *vblank)
685 int hbl, vbl, vfreq;
688 (y+1)/(20000.0/(11*freq) - 1) + 0.5
689 = ((y+1) * (11*freq))/(20000.0 - (11*freq)) + 0.5
690 = ((y+1) * (11*freq) + 10000.0 - (11*freq) / 2)/(20000.0 - (11*freq))
691 = ((y+1) * (11*freq) + 10000.0 - 5 * freq - (freq + 1) / 2)/(20000.0 - (11*freq))
693 vbl = y + 1 +
694 grub_divmod64 (((y+1) * (11*(long long)freq) + 10000 - 5 * (long long)freq
695 - (freq + 1) / 2),
696 (20000 - (11*(long long)freq)), 0);
697 vfreq = vbl * freq;
699 (x * (30.0 - 300000.0 / vfreq) /
700 (70.0 + 300000.0 / vfreq) / 16.0 + 0.5)
701 = ((x * (30.0 - 300000.0 / vfreq) /
702 (70.0 + 300000.0 / vfreq) + 8) / 16)
703 = ((x * (30.0 * vfreq - 300000.0) /
704 (70.0 * vfreq + 300000.0) + 8) / 16)
705 = (((x * (30 * vfreq - 300000)) /
706 (70 * vfreq + 300000) + 8) / 16)
708 hbl = 16 * (int)((grub_divmod64((x * (30 * (long long)vfreq - 300000)),
709 (70 * (long long)vfreq + 300000), 0)
710 + 8) / 16);
712 *vsyncstart = y;
713 *vsyncend = y + 3;
714 *vblank = vbl - 1;
715 *hsyncstart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 - 1;
716 *hsyncend = x + hbl / 2 - 1;
717 *hblank = x + hbl - 1;
718 *clock = (x + hbl) * vfreq / 1000;
721 static void set_mode(vbios_map * map, cardinal mode, cardinal x, cardinal y, cardinal bp, cardinal htotal, cardinal vtotal) {
722 int xprev, yprev;
723 cardinal i, j;
725 for (i=0; i < map->mode_table_size; i++) {
726 if (map->mode_table[i].mode == mode) {
727 switch(map->bios) {
728 case BT_1:
730 vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
732 if (bp) {
733 map->mode_table[i].bits_per_pixel = bp;
736 res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0);
737 res->x1 = (x & 0xff);
739 res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0);
740 res->y1 = (y & 0xff);
741 if (htotal)
742 res->x_total = ((htotal-x) & 0xff);
744 if (vtotal)
745 res->y_total = ((vtotal-y) & 0xff);
747 break;
748 case BT_2:
750 vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
752 res->xchars = x / 8;
753 res->ychars = y / 16 - 1;
754 xprev = res->modelines[0].x1;
755 yprev = res->modelines[0].y1;
757 for(j=0; j < 3; j++) {
758 vbios_modeline_type2 * modeline = &res->modelines[j];
760 if (modeline->x1 == xprev && modeline->y1 == yprev) {
761 modeline->x1 = modeline->x2 = x-1;
762 modeline->y1 = modeline->y2 = y-1;
764 gtf_timings(x, y, freqs[j], &modeline->clock,
765 &modeline->hsyncstart, &modeline->hsyncend,
766 &modeline->hblank, &modeline->vsyncstart,
767 &modeline->vsyncend, &modeline->vblank);
769 if (htotal)
770 modeline->htotal = htotal;
771 else
772 modeline->htotal = modeline->hblank;
774 if (vtotal)
775 modeline->vtotal = vtotal;
776 else
777 modeline->vtotal = modeline->vblank;
781 break;
782 case BT_3:
784 vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
786 xprev = res->modelines[0].x1;
787 yprev = res->modelines[0].y1;
789 for (j=0; j < 3; j++) {
790 vbios_modeline_type3 * modeline = &res->modelines[j];
792 if (modeline->x1 == xprev && modeline->y1 == yprev) {
793 modeline->x1 = modeline->x2 = x-1;
794 modeline->y1 = modeline->y2 = y-1;
796 gtf_timings(x, y, freqs[j], &modeline->clock,
797 &modeline->hsyncstart, &modeline->hsyncend,
798 &modeline->hblank, &modeline->vsyncstart,
799 &modeline->vsyncend, &modeline->vblank);
800 if (htotal)
801 modeline->htotal = htotal;
802 else
803 modeline->htotal = modeline->hblank;
804 if (vtotal)
805 modeline->vtotal = vtotal;
806 else
807 modeline->vtotal = modeline->vblank;
809 modeline->timing_h = y-1;
810 modeline->timing_v = x-1;
814 break;
815 case BT_UNKWN:
816 break;
822 static void display_map_info(vbios_map * map) {
823 printf("Chipset: %s\n", chipset_type_names[map->chipset]);
824 printf("BIOS: %s\n", bios_type_names[map->bios]);
826 printf("Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
827 printf("Mode Table Entries: %u\n", map->mode_table_size);
831 static int parse_args(cardinal argc, char *argv[], chipset_type *forced_chipset,
832 cardinal *list, cardinal *mode, cardinal *x, cardinal *y,
833 cardinal *bp, cardinal *raw, cardinal *htotal,
834 cardinal *vtotal, cardinal *quiet) {
835 cardinal index = 0;
837 *list = *mode = *x = *y = *raw = *htotal = *vtotal = 0;
838 *bp = 0;
839 *quiet = 0;
841 *forced_chipset = CT_UNKWN;
843 if ((argc > index) && !strcmp(argv[index], "-q")) {
844 *quiet = 1;
845 index++;
847 if(argc<=index) {
848 return 0;
852 if ((argc > index) && !strcmp(argv[index], "-c")) {
853 index++;
855 if(argc<=index) {
856 return 0;
859 if (!strcmp(argv[index], "845")) {
860 *forced_chipset = CT_845G;
862 else if (!strcmp(argv[index], "855")) {
863 *forced_chipset = CT_855GM;
865 else if (!strcmp(argv[index], "865")) {
866 *forced_chipset = CT_865G;
868 else if (!strcmp(argv[index], "915G")) {
869 *forced_chipset = CT_915G;
871 else if (!strcmp(argv[index], "915GM")) {
872 *forced_chipset = CT_915GM;
874 else if (!strcmp(argv[index], "945G")) {
875 *forced_chipset = CT_945G;
877 else if (!strcmp(argv[index], "945GM")) {
878 *forced_chipset = CT_945GM;
880 else if (!strcmp(argv[index], "945GME")) {
881 *forced_chipset = CT_945GME;
883 else if (!strcmp(argv[index], "946GZ")) {
884 *forced_chipset = CT_946GZ;
886 else if (!strcmp(argv[index], "G965")) {
887 *forced_chipset = CT_G965;
889 else if (!strcmp(argv[index], "Q965")) {
890 *forced_chipset = CT_Q965;
892 else if (!strcmp(argv[index], "965GM")) {
893 *forced_chipset = CT_965GM;
895 else if (!strcmp(argv[index], "G33")) {
896 *forced_chipset = CT_G33;
898 else if (!strcmp(argv[index], "Q35")) {
899 *forced_chipset = CT_Q35;
901 else if (!strcmp(argv[index], "Q33")) {
902 *forced_chipset = CT_Q33;
904 else if (!strcmp(argv[index], "500GMA")) {
905 *forced_chipset = CT_500GMA;
907 else if (!strcmp(argv[index], "GM45")) {
908 *forced_chipset = CT_GM45;
910 else if (!strcmp(argv[index], "GMA3150")) {
911 *forced_chipset = CT_GMA3150;
913 else if (!strcmp(argv[index], "HD3000")) {
914 *forced_chipset = CT_HD3000;
916 else {
917 *forced_chipset = CT_UNKWN;
920 index++;
922 if (argc<=index) {
923 return 0;
927 if ((argc > index) && !strcmp(argv[index], "-l")) {
928 *list = 1;
929 index++;
931 if(argc<=index) {
932 return 0;
936 if ((argc > index) && !strcmp(argv[index], "-r")) {
937 *raw = 1;
938 index++;
940 if(argc<=index) {
941 return 0;
945 if (argc-index < 3 || argc-index > 6) {
946 return -1;
949 *mode = (cardinal) strtol(argv[index], NULL, 16);
950 *x = (cardinal)atoi(argv[index+1]);
951 *y = (cardinal)atoi(argv[index+2]);
954 if (argc-index > 3) {
955 *bp = (cardinal)atoi(argv[index+3]);
957 else {
958 *bp = 0;
961 if (argc-index > 4) {
962 *htotal = (cardinal)atoi(argv[index+4]);
964 else {
965 *htotal = 0;
968 if (argc-index > 5) {
969 *vtotal = (cardinal)atoi(argv[index+5]);
971 else {
972 *vtotal = 0;
975 return 0;
978 static void usage(void) {
979 printf("Usage: 915resolution [-q] [-c chipset] [-l] [mode X Y] [bits/pixel] [htotal] [vtotal]\n");
980 printf(" Set the resolution to XxY for a video mode\n");
981 printf(" Bits per pixel are optional. htotal/vtotal settings are additionally optional.\n");
982 printf(" Options:\n");
983 printf(" -q don't show any normal messages\n");
984 printf(" -c force chipset type (THIS IS USED FOR DEBUG PURPOSES)\n");
985 printf(" -l display the modes found in the video BIOS\n");
986 printf(" -r display the modes found in the video BIOS in raw mode (THIS IS USED FOR DEBUG PURPOSES)\n");
989 static int main_915 (int argc, char *argv[])
991 vbios_map * map;
992 cardinal list, mode, x, y, bp, raw, htotal, vtotal;
993 cardinal quiet;
994 chipset_type forced_chipset;
996 if (parse_args(argc, argv, &forced_chipset, &list, &mode,
997 &x, &y, &bp, &raw, &htotal, &vtotal, &quiet) == -1) {
998 printf("Intel 800/900 Series VBIOS Hack : version %s\n\n",
999 RES915_VERSION);
1000 usage();
1001 return 2;
1004 if (!quiet)
1005 printf("Intel 800/900 Series VBIOS Hack : version %s\n\n",
1006 RES915_VERSION);
1008 map = open_vbios(forced_chipset);
1009 if (!quiet)
1011 display_map_info(map);
1012 printf("\n");
1015 if (list) {
1016 list_modes(map, raw);
1019 if (mode!=0 && x!=0 && y!=0) {
1020 unlock_vbios(map);
1022 set_mode(map, mode, x, y, bp, htotal, vtotal);
1024 relock_vbios(map);
1026 printf("Patch mode %02x to resolution %dx%d complete\n", mode, x, y);
1028 if (list) {
1029 list_modes(map, raw);
1033 close_vbios(map);
1035 return 0;
1042 static grub_err_t
1043 grub_cmd_915resolution (grub_command_t cmd __attribute__ ((unused)),
1044 int argc, char *argv[])
1046 return main_915 (argc, argv);
1049 static grub_command_t cmd;
1051 GRUB_MOD_INIT(915resolution)
1053 cmd = grub_register_command ("915resolution", grub_cmd_915resolution,
1054 "915resolution", "Intel VBE editor");
1057 GRUB_MOD_FINI(915resolution)
1059 grub_unregister_command (cmd);