1 | /*␊ |
2 | * nvidia_resolution.c␊ |
3 | * ␊ |
4 | *␊ |
5 | * Created by Le Bidou on 19/03/10.␊ |
6 | * Copyright 2010 ---. All rights reserved.␊ |
7 | *␊ |
8 | */␊ |
9 | ␊ |
10 | #include "nvidia_resolution.h"␊ |
11 | ␊ |
12 | vbios_map * open_nvidia_vbios(vbios_map *map)␊ |
13 | {␊ |
14 | ␉unsigned short nv_data_table_offset = 0;␊ |
15 | ␉unsigned short nv_modeline_2_offset = 0;␊ |
16 | ␉unsigned short * nv_data_table = NULL;␊ |
17 | ␉NV_VESA_TABLE * std_vesa;␊ |
18 | ␉␊ |
19 | ␉/*␊ |
20 | ␉ * Locate the VESA Tables␊ |
21 | ␉ */␊ |
22 | ␉␊ |
23 | ␉int i = 0;␊ |
24 | ␉␊ |
25 | ␉while (i < 0x300) { //We don't need to look for the table in the whole bios, the 768 first bytes only␊ |
26 | ␉␉if ((map->bios_ptr[i] == 0x44) ␊ |
27 | ␉␉␉&& (map->bios_ptr[i+1] == 0x01) ␊ |
28 | ␉␉␉&& (map->bios_ptr[i+2] == 0x04) ␊ |
29 | ␉␉␉&& (map->bios_ptr[i+3] == 0x00)) {␊ |
30 | ␉␉␉nv_data_table_offset = (unsigned short) (map->bios_ptr[i+4] | (map->bios_ptr[i+5] << 8));␊ |
31 | ␉␉␉break;␊ |
32 | ␉␉}␊ |
33 | ␉␉i++;␊ |
34 | ␉}␊ |
35 | ␉//Second VESA Table on some nVidia 8xxx 9xxx and GT␊ |
36 | ␉while (i < VBIOS_SIZE) { //We don't know how to locate it other way␊ |
37 | ␉␉if ((map->bios_ptr[i] == 0x40) && (map->bios_ptr[i+1] == 0x01) //this is the first 320x200 modeline.␊ |
38 | ␉␉␉&& (map->bios_ptr[i+2] == 0xC8) && (map->bios_ptr[i+3] == 0x00)␊ |
39 | ␉␉␉&& (map->bios_ptr[i+4] == 0x28)␊ |
40 | ␉␉␉&& (map->bios_ptr[i+5] == 0x18)␊ |
41 | ␉␉␉&& (map->bios_ptr[i+6] == 0x08)␊ |
42 | ␉␉␉&& (map->bios_ptr[i+7] == 0x08)) {␊ |
43 | ␉␉␉nv_modeline_2_offset = (unsigned short) i;␊ |
44 | ␉␉␉break;␊ |
45 | ␉␉}␊ |
46 | ␉␉i++;␊ |
47 | ␉}␊ |
48 | ␉␊ |
49 | ␉nv_data_table = (unsigned short *) (map->bios_ptr + (nv_data_table_offset + OFFSET_TO_VESA_TABLE_INDEX));␊ |
50 | ␉std_vesa = (NV_VESA_TABLE *) (map->bios_ptr + *nv_data_table);␊ |
51 | ␉map->mode_table = (char *) std_vesa->sModelines;␊ |
52 | ␉PRINT("First Standard VESA Table at offset 0x%x\n", *nv_data_table);␊ |
53 | ␉␊ |
54 | ␉if (nv_modeline_2_offset == (VBIOS_SIZE-1) || nv_modeline_2_offset == 0) {␊ |
55 | ␉␉map->nv_mode_table_2 = NULL;␊ |
56 | ␉␉PRINT("There is no Second Standard VESA Table to patch\n");␊ |
57 | ␉} else {␊ |
58 | ␉␉map->nv_mode_table_2 = (char*) map->bios_ptr + nv_modeline_2_offset;␊ |
59 | ␉␉PRINT("Second Standard VESA Table at offset 0x%x\n", nv_modeline_2_offset);␊ |
60 | ␉}␊ |
61 | ␉␊ |
62 | ␉if (map->mode_table == NULL) {␊ |
63 | ␉␉PRINT("Unable to locate the mode table.\n");␊ |
64 | ␉␉PRINT("Please run the program 'dump_bios' as root and\n");␊ |
65 | ␉␉PRINT("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");␊ |
66 | ␉␉␊ |
67 | ␉␉close_vbios(map);␊ |
68 | ␉␉return 0;␊ |
69 | ␉}␊ |
70 | ␉␊ |
71 | ␉␉/*␊ |
72 | ␉ * Having trouble determining the number of table␊ |
73 | ␉ * so it's hardcode to 16 and 31 for the First VESA table␊ |
74 | ␉ * and the Second Vesa Table respectively␊ |
75 | ␉␉ ␉ */␊ |
76 | ␉␉␊ |
77 | ␉map->modeline_num = 16;␊ |
78 | ␉map->nv_modeline_num_2 = 31;␊ |
79 | ␉␊ |
80 | ␉/*NV_MODELINE_2 *␉mode_2_ptr =␉(NV_MODELINE_2 *)␉map->nv_mode_table_2;␊ |
81 | ␉␉map->modeline_num = map->nv_modeline_num_2 = 0;␊ |
82 | ␉␉␊ |
83 | ␉␉//First Table␊ |
84 | ␉map->modeline_num = std_vesa->sHeader.usTableSize;␊ |
85 | ␉␉␊ |
86 | ␉PRINT("First VESA Table has %d modes\n",map->modeline_num);␊ |
87 | ␉␉if (map->modeline_num == 0) {␊ |
88 | ␉␉PRINT("%d is incorrect, make it a 16\n",map->modeline_num);␊ |
89 | ␉␉␉␉map->modeline_num = 16;␊ |
90 | ␉␉␉}␊ |
91 | ␉␉map->mode_table_size = map->modeline_num * sizeof(NV_MODELINE);␊ |
92 | ␉␉␊ |
93 | ␉␉//Second Table␊ |
94 | ␉map->nv_modeline_num_2 = *((UInt8 *)(mode_2_ptr - 2)) - 32;␊ |
95 | ␉␉␊ |
96 | ␉PRINT("Second VESA Table has %d modes\n",map->nv_modeline_num_2);␊ |
97 | ␉␉if (map->nv_modeline_num_2 == 0) {␊ |
98 | ␉␉PRINT("%d is incorrect, make it a 32\n",map->nv_modeline_num_2);␊ |
99 | ␉␉␉␉map->nv_modeline_num_2 = 32;␊ |
100 | ␉␉␉}␊ |
101 | ␉map->nv_mode_table_2_size = map->nv_modeline_num_2 * sizeof(NV_MODELINE_2);*/␊ |
102 | ␉␊ |
103 | ␉return map;␊ |
104 | }␊ |
105 | ␊ |
106 | bool nvidia_set_mode(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y, char Type)␊ |
107 | {␊ |
108 | ␉if (Type == MAIN_VESA_TABLE) {␊ |
109 | ␉␉NV_MODELINE * mode_timing = (NV_MODELINE *) map->mode_table;␊ |
110 | ␉␉␊ |
111 | ␉␉if ((*x != 0) && (*y != 0) && ( mode_timing[idx].usH_Active >= 640 )) {␊ |
112 | ␉␉␉␊ |
113 | ␉␉␉PRINT("Mode %dx%d -> %dx%d ", mode_timing[idx].usH_Active, mode_timing[idx].usV_Active,␊ |
114 | ␉␉␉␉␉*x, *y);␊ |
115 | ␉␉␉␊ |
116 | ␉␉␉generic_modeline modeline;␊ |
117 | ␉␉␉␊ |
118 | ␉␉␉cvt_timings(*x, *y, 60, &modeline.clock,␊ |
119 | ␉␉␉␉␉␉&modeline.hsyncstart, &modeline.hsyncend,␊ |
120 | ␉␉␉␉␉␉&modeline.htotal, &modeline.vsyncstart,␊ |
121 | ␉␉␉␉␉␉&modeline.vsyncend, &modeline.vtotal, FALSE);␊ |
122 | ␉␉␉␊ |
123 | ␉␉␉mode_timing[idx].usH_Active = *x;␊ |
124 | ␉␉␉mode_timing[idx].usH_Active_minus_One = *x - 1;␊ |
125 | ␉␉␉mode_timing[idx].usH_Active_minus_One_ = *x - 1;␊ |
126 | ␉␉␉␊ |
127 | ␉␉␉mode_timing[idx].usV_Active = *y;␊ |
128 | ␉␉␉mode_timing[idx].usV_Active_minus_One = *y - 1;␊ |
129 | ␉␉␉mode_timing[idx].usV_Active_minus_One_ = *y - 1;␊ |
130 | ␉␉␉␊ |
131 | ␉␉␉mode_timing[idx].usH_Total = modeline.htotal;␊ |
132 | ␉␉␉mode_timing[idx].usH_SyncStart = modeline.hsyncstart;␊ |
133 | ␉␉␉mode_timing[idx].usH_SyncEnd = modeline.hsyncend;␊ |
134 | ␉␉␉␊ |
135 | ␉␉␉mode_timing[idx].usV_Total = modeline.vtotal;␊ |
136 | ␉␉␉mode_timing[idx].usV_SyncStart = modeline.vsyncstart;␊ |
137 | ␉␉␉mode_timing[idx].usV_SyncEnd = modeline.vsyncend;␊ |
138 | ␉␉␉␊ |
139 | ␉␉␉mode_timing[idx].usPixel_Clock = modeline.clock;␊ |
140 | ␉␉}␊ |
141 | ␉␉␊ |
142 | ␉␉*x = mode_timing[idx + 1].usH_Active;␊ |
143 | ␉␉*y = mode_timing[idx + 1].usV_Active;␊ |
144 | ␉}␊ |
145 | ␉␊ |
146 | ␉if (Type == SECOND_VESA_TABLE) {␊ |
147 | ␉␉NV_MODELINE_2 * mode_timing = (NV_MODELINE_2 *) map->nv_mode_table_2;␊ |
148 | ␉␉␊ |
149 | ␉␉if (mode_timing[idx].h_disp > 0x800) return FALSE;␊ |
150 | ␉␉␊ |
151 | ␉␉if ((*x != 0) && (*y != 0) && ( mode_timing[idx].h_disp >= 640 )) {␊ |
152 | ␉␉␉␊ |
153 | ␉␉␉PRINT("Mode %dx%d -> %dx%d ", mode_timing[idx].h_disp, mode_timing[idx].v_disp,␊ |
154 | ␉␉␉␉␉*x, *y);␊ |
155 | ␉␉␉␊ |
156 | ␉␉␉generic_modeline modeline;␊ |
157 | ␉␉␉␊ |
158 | ␉␉␉cvt_timings(*x, *y, 60, &modeline.clock,␊ |
159 | ␉␉␉␉␉␉&modeline.hsyncstart, &modeline.hsyncend,␊ |
160 | ␉␉␉␉␉␉&modeline.htotal, &modeline.vsyncstart,␊ |
161 | ␉␉␉␉␉␉&modeline.vsyncend, &modeline.vtotal, TRUE);␊ |
162 | ␉␉␉␊ |
163 | ␉␉␉mode_timing[idx].h_disp = *x;␊ |
164 | ␉␉␉mode_timing[idx].v_disp = *y;␊ |
165 | ␉␉␉mode_timing[idx].h_blank = modeline.htotal - *x;␊ |
166 | ␉␉␉mode_timing[idx].h_syncoffset = modeline.hsyncstart - *x;␊ |
167 | ␉␉␉mode_timing[idx].h_syncwidth = modeline.hsyncend - modeline.hsyncstart;␊ |
168 | ␉␉␉mode_timing[idx].v_blank = modeline.vtotal - *y;␊ |
169 | ␉␉}␊ |
170 | ␉␉␊ |
171 | ␉␉*x = mode_timing[idx + 1].h_disp;␊ |
172 | ␉␉*y = mode_timing[idx + 1].v_disp;␊ |
173 | ␉}␊ |
174 | ␉return TRUE;␊ |
175 | }␊ |
176 | |