xref: /haiku/src/add-ons/accelerants/nvidia/ProposeDisplayMode.c (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 /*
2 	Copyright 1999, Be Incorporated.   All Rights Reserved.
3 	This file may be used under the terms of the Be Sample Code License.
4 
5 	Other authors for NV driver:
6 	Mark Watson,
7 	Rudolf Cornelissen 9/2002-4/2004
8 */
9 
10 #define MODULE_BIT 0x00400000
11 
12 #include "acc_std.h"
13 
14 #define	T_POSITIVE_SYNC	(B_POSITIVE_HSYNC | B_POSITIVE_VSYNC)
15 /* mode flags will be setup as status info by PROPOSEMODE! */
16 #define MODE_FLAGS 0
17 #define MODE_COUNT (sizeof (mode_list) / sizeof (display_mode))
18 
19 /*some monitors only handle a fixed set of modes*/
20 #include "valid_mode_list"
21 
22 /*Standard VESA modes*/
23 static const display_mode mode_list[] = {
24 { { 25175, 640, 656, 752, 800, 480, 490, 492, 525, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(640X480X8.Z1) */
25 { { 27500, 640, 672, 768, 864, 480, 488, 494, 530, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* 640X480X60Hz */
26 { { 30500, 640, 672, 768, 864, 480, 517, 523, 588, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* SVGA_640X480X60HzNI */
27 { { 31500, 640, 664, 704, 832, 480, 489, 492, 520, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(640X480X8.Z1) */
28 { { 31500, 640, 656, 720, 840, 480, 481, 484, 500, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(640X480X8.Z1) */
29 { { 36000, 640, 696, 752, 832, 480, 481, 484, 509, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(640X480X8.Z1) */
30 { { 36000, 800, 824, 896, 1024, 600, 601, 603, 625, 0}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@56Hz_(800X600) from Be, Inc. driver + XFree86 */
31 { { 38100, 800, 832, 960, 1088, 600, 602, 606, 620, 0}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* SVGA_800X600X56HzNI */
32 { { 40000, 800, 840, 968, 1056, 600, 601, 605, 628, T_POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(800X600X8.Z1) + XFree86 */
33 { { 49500, 800, 816, 896, 1056, 600, 601, 604, 625, T_POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(800X600X8.Z1) + XFree86 */
34 { { 50000, 800, 856, 976, 1040, 600, 637, 643, 666, T_POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(800X600X8.Z1) + XFree86 */
35 { { 56250, 800, 832, 896, 1048, 600, 601, 604, 631, T_POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(800X600X8.Z1) + XFree86 */
36 { { 65000, 1024, 1048, 1184, 1344, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1024X768X8.Z1) + XFree86 */
37 { { 75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(1024X768X8.Z1) + XFree86 */
38 { { 78750, 1024, 1040, 1136, 1312, 768, 769, 772, 800, T_POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1024X768X8.Z1) + XFree86 */
39 { { 94500, 1024, 1072, 1168, 1376, 768, 769, 772, 808, T_POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1024X768X8.Z1) + XFree86 */
40 { { 94200, 1152, 1184, 1280, 1472, 864, 865, 868, 914, T_POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1152X864X8.Z1) */
41 { { 97800, 1152, 1216, 1344, 1552, 864, 865, 868, 900, T_POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1152X864X8.Z1) */
42 { { 108000, 1152, 1216, 1344, 1600, 864, 865, 868, 900, T_POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1152X864X8.Z1) + XFree86 */
43 { { 121500, 1152, 1216, 1344, 1568, 864, 865, 868, 911, T_POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1152X864X8.Z1) */
44 { { 108000, 1280, 1328, 1440, 1688, 1024, 1025, 1028, 1066, T_POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1280X1024) from Be, Inc. driver + XFree86 */
45 { { 135000, 1280, 1296, 1440, 1688, 1024, 1025, 1028, 1066, T_POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1280X1024X8.Z1) + XFree86 */
46 { { 157500, 1280, 1344, 1504, 1728, 1024, 1025, 1028, 1072, T_POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1280X1024X8.Z1) + XFree86 */
47 { { 162000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1600X1200X8.Z1) + XFree86 */
48 /* identical lines to above one, apart from refreshrate.. */
49 { { 175500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@65Hz_(1600X1200X8.Z1) + XFree86 */
50 { { 189000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1600X1200X8.Z1) + XFree86 */
51 { { 202500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1600X1200X8.Z1) + XFree86 */
52 { { 216000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@80Hz_(1600X1200X8.Z1) */
53 { { 229500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS},  /* Vesa_Monitor_@85Hz_(1600X1200X8.Z1) + XFree86 */
54 /* end identical lines. */
55 { { 204750, 1792, 1920, 2120, 2448, 1344, 1345, 1348, 1394, B_POSITIVE_VSYNC}, B_CMAP8, 1792, 1344, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1792X1344) from Be, Inc. driver + XFree86 */
56 { { 261000, 1792, 1888, 2104, 2456, 1344, 1345, 1348, 1417, B_POSITIVE_VSYNC}, B_CMAP8, 1792, 1344, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1792X1344) from Be, Inc. driver + XFree86 */
57 { { 218250, 1856, 1952, 2176, 2528, 1392, 1393, 1396, 1439, B_POSITIVE_VSYNC}, B_CMAP8, 1856, 1392, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1856X1392) from Be, Inc. driver + XFree86 */
58 { { 288000, 1856, 1984, 2208, 2560, 1392, 1393, 1396, 1500, B_POSITIVE_VSYNC}, B_CMAP8, 1856, 1392, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1856X1392) from Be, Inc. driver + XFree86 */
59 { { 234000, 1920, 2048, 2256, 2600, 1440, 1441, 1444, 1500, B_POSITIVE_VSYNC}, B_CMAP8, 1920, 1440, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1920X1440) from Be, Inc. driver + XFree86 */
60 { { 297000, 1920, 2064, 2288, 2640, 1440, 1441, 1444, 1500, B_POSITIVE_VSYNC}, B_CMAP8, 1920, 1440, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1920X1440) from Be, Inc. driver + XFree86 */
61 { { 266950, 2048, 2200, 2424, 2800, 1536, 1537, 1540, 1589, B_POSITIVE_VSYNC}, B_CMAP8, 2048, 1536, 0, 0, MODE_FLAGS}, /* From XFree86 posting @60Hz + XFree86 */
62 };
63 
64 /*
65 Check mode is between low and high limits
66 returns:
67 	B_OK - found one
68 	B_BAD_VALUE - mode can be made, but outside limits
69 	B_ERROR - not possible
70 */
71 /* BOUNDS WARNING:
72  * BeOS (tested R5.0.3PE) is failing BWindowScreen.SetFrameBuffer() if PROPOSEMODE
73  * returns B_BAD_VALUE. It's called by the OS with target, low and high set to
74  * have the same settings for BWindowScreen!
75  * Which means we should not return B_BAD_VALUE on anything except for deviations on:
76  * display_mode.virtual_width;
77  * display_mode.virtual_height;
78  * display_mode.timing.h_display;
79  * display_mode.timing.v_display;
80  */
81 /* Note:
82  * The target mode should be modified to correspond to the mode as it can be made. */
83 status_t PROPOSE_DISPLAY_MODE(display_mode *target, const display_mode *low, const display_mode *high)
84 {
85 	status_t status = B_OK;
86 	float pix_clock_found;
87 	uint8 m,n,p, bpp;
88 	status_t result;
89 	uint32 max_vclk, row_bytes, pointer_reservation;
90 	bool acc_mode;
91 	double target_refresh = ((double)target->timing.pixel_clock * 1000.0) /
92 			(
93 				(double)target->timing.h_total *
94 				(double)target->timing.v_total
95 			);
96 	bool
97 		want_same_width = target->timing.h_display == target->virtual_width,
98 		want_same_height = target->timing.v_display == target->virtual_height;
99 
100 	LOG(1, ("PROPOSEMODE: (ENTER) requested virtual_width %d, virtual_height %d\n",
101 									target->virtual_width, target->virtual_height));
102 
103 	/*check valid list:
104 		if (VALID_REQUIRED is set)
105 		{
106 			if (find modes with same size)
107 			{
108 				pick one with nearest pixel clock
109 			}
110 			else
111 			{
112 				pick next largest with nearest pixel clock and modify visible portion as far as possible
113 			}
114 		}
115 	*/
116 	#ifdef VALID_MODE_REQUIRED
117 	{
118 		int i;
119 		int closest_mode_ptr;
120 		uint32 closest_mode_clock;
121 
122 		LOG(1, ("PROPOSEMODE: valid mode required!\n"));
123 
124 		closest_mode_ptr = 0xbad;
125 		closest_mode_clock = 0;
126 		for (i=0;i<VALID_MODES;i++)
127 		{
128 			/*check size is ok and clock is better than any found before*/
129 			if(
130 				target->timing.h_display==valid_mode_list[i].h_display &&
131 				target->timing.v_display==valid_mode_list[i].v_display
132 			)
133 			{
134 				if (
135 					abs(valid_mode_list[i].pixel_clock-target->timing.pixel_clock)<
136 					abs(closest_mode_clock-target->timing.pixel_clock)
137 				)
138 				{
139 					closest_mode_clock=valid_mode_list[i].pixel_clock;
140 					closest_mode_ptr=i;
141 				}
142 			}
143 		}
144 
145 		if (closest_mode_ptr==0xbad)/*if no modes of correct size*/
146 		{
147 			LOG(4, ("PROPOSEMODE: no valid mode found, aborted.\n"));
148 			return B_ERROR;
149 		}
150 		else
151 		{
152 			target->timing=valid_mode_list[closest_mode_ptr];
153 			target_refresh = ((double)target->timing.pixel_clock * 1000.0) /  /*I require this refresh*/
154 			((double)target->timing.h_total * (double)target->timing.v_total);
155 		}
156 	}
157 	#endif
158 
159 	/*find a nearby valid timing from that given*/
160 	result = nv_crtc_validate_timing
161 	(
162 		&target->timing.h_display, &target->timing.h_sync_start, &target->timing.h_sync_end, &target->timing.h_total,
163 		&target->timing.v_display, &target->timing.v_sync_start, &target->timing.v_sync_end, &target->timing.v_total
164 	);
165 	if (result == B_ERROR)
166 	{
167 		LOG(4, ("PROPOSEMODE: could not validate timing, aborted.\n"));
168 		return result;
169 	}
170 
171 	/* validate display vs. virtual */
172 	if ((target->timing.h_display > target->virtual_width) || want_same_width)
173 		target->virtual_width = target->timing.h_display;
174 	if ((target->timing.v_display > target->virtual_height) || want_same_height)
175 		target->virtual_height = target->timing.v_display;
176 
177 	/* nail virtual size and 'subsequently' calculate rowbytes */
178 	result = nv_general_validate_pic_size (target, &row_bytes, &acc_mode);
179 	if (result == B_ERROR)
180 	{
181 		LOG(4, ("PROPOSEMODE: could not validate virtual picture size, aborted.\n"));
182 		return result;
183 	}
184 
185 	/*check if virtual_width is still within the requested limits*/
186 	if ((target->virtual_width < low->virtual_width) ||
187 		(target->virtual_width > high->virtual_width))
188 	{
189 		status = B_BAD_VALUE;
190 		LOG(4, ("PROPOSEMODE: WARNING: virtual_width deviates too much\n"));
191 	}
192 
193 	/*check if timing found is within the requested horizontal limits*/
194 	if ((target->timing.h_display < low->timing.h_display) ||
195 		(target->timing.h_display > high->timing.h_display) ||
196 		(target->timing.h_sync_start < low->timing.h_sync_start) ||
197 		(target->timing.h_sync_start > high->timing.h_sync_start) ||
198 		(target->timing.h_sync_end < low->timing.h_sync_end) ||
199 		(target->timing.h_sync_end > high->timing.h_sync_end) ||
200 		(target->timing.h_total < low->timing.h_total) ||
201 		(target->timing.h_total > high->timing.h_total))
202 	{
203 		/* BWindowScreen workaround: we accept everything except h_display deviations */
204 		if ((target->timing.h_display < low->timing.h_display) ||
205 			(target->timing.h_display > high->timing.h_display))
206 		{
207 			status = B_BAD_VALUE;
208 		}
209 		else
210 		{
211 			status = B_OK;
212 		}
213 		LOG(4, ("PROPOSEMODE: WARNING: horizontal timing deviates too much\n"));
214 	}
215 
216 	/*check if timing found is within the requested vertical limits*/
217 	if (
218 		(target->timing.v_display < low->timing.v_display) ||
219 		(target->timing.v_display > high->timing.v_display) ||
220 		(target->timing.v_sync_start < low->timing.v_sync_start) ||
221 		(target->timing.v_sync_start > high->timing.v_sync_start) ||
222 		(target->timing.v_sync_end < low->timing.v_sync_end) ||
223 		(target->timing.v_sync_end > high->timing.v_sync_end) ||
224 		(target->timing.v_total < low->timing.v_total) ||
225 		(target->timing.v_total > high->timing.v_total)
226 	)
227 	{
228 		/* BWindowScreen workaround: we accept everything except v_display deviations */
229 		if ((target->timing.v_display < low->timing.v_display) ||
230 			(target->timing.v_display > high->timing.v_display))
231 		{
232 			status = B_BAD_VALUE;
233 		}
234 		else
235 		{
236 			status = B_OK;
237 		}
238 		LOG(4, ("PROPOSEMODE: WARNING: vertical timing deviates too much\n"));
239 	}
240 
241 	/* adjust pixelclock for possible timing modifications done above */
242 	target->timing.pixel_clock = target_refresh * ((double)target->timing.h_total) * ((double)target->timing.v_total) / 1000.0;
243 
244 	/* Now find the nearest valid pixelclock we actually can setup for the target mode,
245 	 * this also makes sure we don't generate more pixel bandwidth than the device can handle */
246 	/* calculate settings, but do not actually test anything (that costs too much time!) */
247 	result = nv_dac_pix_pll_find(*target,&pix_clock_found,&m,&n,&p,0);
248 	/* update the target mode */
249 	target->timing.pixel_clock = (pix_clock_found * 1000);
250 
251 	/* note if we fell outside the limits */
252 	if ((target->timing.pixel_clock < low->timing.pixel_clock) ||
253 		(target->timing.pixel_clock > high->timing.pixel_clock)
254 	)
255 	{
256 		/* BWindowScreen workaround: we accept deviations <= 1Mhz */
257 		if ((target->timing.pixel_clock < (low->timing.pixel_clock - 1000)) ||
258 			(target->timing.pixel_clock > (high->timing.pixel_clock + 1000)))
259 		{
260 			status = B_BAD_VALUE;
261 		}
262 		else
263 		{
264 			status = B_OK;
265 		}
266 		LOG(4, ("PROPOSEMODE: WARNING: pixelclock deviates too much\n"));
267 	}
268 
269 	/* checkout space needed for hardcursor (if any) */
270 	pointer_reservation = 0;
271 	if (si->settings.hardcursor) pointer_reservation = 2048;
272 	/* memory requirement for frame buffer */
273 	if ((row_bytes * target->virtual_height) >
274 		((si->ps.memory_size * 1024 * 1024) - pointer_reservation))
275 	{
276 		target->virtual_height =
277 			((si->ps.memory_size * 1024 * 1024) - pointer_reservation) / row_bytes;
278 	}
279 	if (target->virtual_height < target->timing.v_display)
280 	{
281 		LOG(4,("PROPOSEMODE: not enough memory for current mode, aborted.\n"));
282 		return B_ERROR;
283 	}
284 	LOG(4,("PROPOSEMODE: validated virtual_width %d, virtual_height %d pixels\n",
285 		target->virtual_width, target->virtual_height));
286 
287 	if ((target->virtual_height < low->virtual_height) ||
288 		(target->virtual_height > high->virtual_height))
289 	{
290 		status = B_BAD_VALUE;
291 		LOG(4, ("PROPOSEMODE: WARNING: virtual_height deviates too much\n"));
292 	}
293 
294 	/* setup status flags */
295 	LOG(1, ("PROPOSEMODE: initial modeflags: $%08x\n", target->flags));
296 	/* preset to singlehead card without TVout, no overlay support and no hardcursor.
297 	 * also advice system that app_server and acc engine may touch the framebuffer
298 	 * simultaneously (fixed). */
299 	target->flags &=
300 		~(DUALHEAD_CAPABLE | TV_CAPABLE | B_SUPPORTS_OVERLAYS | B_HARDWARE_CURSOR | B_IO_FB_NA);
301 	/* we always allow parallel access (fixed), the DAC is always in 'enhanced'
302 	 * mode (fixed), and all modes support DPMS (fixed);
303 	 * We support scrolling and panning in every mode, so we 'send a signal' to
304 	 * BWindowScreen.CanControlFrameBuffer() by setting B_SCROLL.  */
305 	/* BTW: B_PARALLEL_ACCESS in combination with a hardcursor enables
306 	 * BDirectWindow windowed modes. */
307 	target->flags |= (B_PARALLEL_ACCESS | B_8_BIT_DAC | B_DPMS | B_SCROLL);
308 
309 	/* determine the 'would be' max. pixelclock for the second DAC for the current videomode if dualhead were activated */
310 	switch (target->space)
311 	{
312 		case B_CMAP8:
313 			max_vclk = si->ps.max_dac2_clock_8;
314 			bpp = 1;
315 			break;
316 		case B_RGB15_LITTLE:
317 		case B_RGB16_LITTLE:
318 			max_vclk = si->ps.max_dac2_clock_16;
319 			bpp = 2;
320 			break;
321 		case B_RGB24_LITTLE:
322 			max_vclk = si->ps.max_dac2_clock_24;
323 			bpp = 3;
324 			break;
325 		case B_RGB32_LITTLE:
326 			max_vclk = si->ps.max_dac2_clock_32dh;
327 			bpp = 4;
328 			break;
329 		default:
330 			/* use fail-safe value */
331 			max_vclk = si->ps.max_dac2_clock_32dh;
332 			bpp = 4;
333 			break;
334 	}
335 
336 	/* set DUALHEAD_CAPABLE if suitable */
337 	//fixme: update for independant secondary head use! (reserve fixed memory then)
338 	if (si->ps.secondary_head && (target->timing.pixel_clock <= (max_vclk * 1000)))
339 	{
340 		switch (target->flags & DUALHEAD_BITS)
341 		{
342 		case DUALHEAD_ON:
343 		case DUALHEAD_SWITCH:
344 			if ((((si->ps.memory_size * 1024 * 1024) - pointer_reservation) >=
345 					(row_bytes * target->virtual_height)) &&
346 			 	((uint16)(row_bytes / bpp) >= (target->timing.h_display * 2)))
347 			{
348 				target->flags |= DUALHEAD_CAPABLE;
349 			}
350 			break;
351 		case DUALHEAD_CLONE:
352 			if (((si->ps.memory_size * 1024 * 1024) - pointer_reservation) >=
353 					(row_bytes * target->virtual_height))
354 			{
355 				target->flags |= DUALHEAD_CAPABLE;
356 			}
357 			break;
358 		case DUALHEAD_OFF:
359 			if (((si->ps.memory_size * 1024 * 1024) - pointer_reservation) >=
360 					(row_bytes * target->virtual_height * 2))
361 			{
362 				target->flags |= DUALHEAD_CAPABLE;
363 			}
364 			break;
365 		}
366 	}
367 
368 	/* set TV_CAPABLE if suitable: pixelclock is not important (defined by TVstandard) */
369 	//fixme: modify for G100 and G200 TVout later on...
370 	if (target->flags & DUALHEAD_CAPABLE)
371 	{
372 		if (si->ps.tvout &&
373 			(target->timing.h_display <= 1024) &&
374 			(target->timing.v_display <= 768))
375 		{
376 			target->flags |= TV_CAPABLE;
377 		}
378 	}
379 
380 	/* set HARDWARE_CURSOR mode if suitable */
381 	if (si->settings.hardcursor)
382 		target->flags |= B_HARDWARE_CURSOR;
383 
384 	/* set SUPPORTS_OVERLAYS */
385 	target->flags |= B_SUPPORTS_OVERLAYS;
386 
387 	LOG(1, ("PROPOSEMODE: validated status modeflags: $%08x\n", target->flags));
388 
389 	/* overrule timing command flags to be (fixed) blank_pedestal = 0.0IRE,
390 	 * progressive scan (fixed), and setup sync_on_green flag according to
391 	 * nv.settings options file */
392 	target->timing.flags &= ~(B_BLANK_PEDESTAL | B_TIMING_INTERLACED | B_SYNC_ON_GREEN);
393 	if (si->settings.greensync)
394 		target->timing.flags |= B_SYNC_ON_GREEN;
395 	/* The HSYNC and VSYNC command flags are actually executed by the driver. */
396 
397 	if (status == B_OK)	LOG(4, ("PROPOSEMODE: completed successfully.\n"));
398 	else LOG(4, ("PROPOSEMODE: mode can be made, but outside given limits.\n"));
399 	return status;
400 }
401 
402 /* Return the number of modes this device will return from GET_MODE_LIST().
403 	This is precalculated in create_mode_list (called from InitAccelerant stuff)
404 */
405 uint32 ACCELERANT_MODE_COUNT(void)
406 {
407 	LOG(1, ("ACCELERANT_MODE_COUNT: the modelist contains %d modes\n",si->mode_count));
408 
409 	return si->mode_count;
410 }
411 
412 /* Copy the list of guaranteed supported video modes to the location provided.*/
413 status_t GET_MODE_LIST(display_mode *dm)
414 {
415 	LOG(1, ("GET_MODE_LIST: exporting the modelist created before.\n"));
416 
417 	memcpy(dm, my_mode_list, si->mode_count * sizeof(display_mode));
418 	return B_OK;
419 }
420 
421 /* Create a list of display_modes to pass back to the caller.*/
422 status_t create_mode_list(void) {
423 	size_t max_size;
424 	uint32
425 		i, j,
426 		pix_clk_range;
427 	const display_mode
428 		*src;
429 	display_mode
430 		*dst,
431 		low,
432 		high;
433 
434 	color_space spaces[4] = {B_RGB32_LITTLE,B_RGB16_LITTLE,B_RGB15_LITTLE,B_CMAP8};
435 
436 	/* figure out how big the list could be, and adjust up to nearest multiple of B_PAGE_SIZE */
437 	/* note: two extra modes might be added for flatpanels */
438 	max_size = ((((MODE_COUNT + 2) * 4) * sizeof(display_mode)) + (B_PAGE_SIZE-1)) & ~(B_PAGE_SIZE-1);
439 	/* create an area to hold the info */
440 	si->mode_area = my_mode_list_area =
441 		create_area("NV accelerant mode info", (void **)&my_mode_list, B_ANY_ADDRESS, max_size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
442 	if (my_mode_list_area < B_OK) return my_mode_list_area;
443 
444 	/* walk through our predefined list and see which modes fit this device */
445 	src = mode_list;
446 	dst = my_mode_list;
447 	si->mode_count = 0;
448 	for (i = 0; i < MODE_COUNT; i++) {
449 		/* set ranges for acceptable values */
450 		low = high = *src;
451 		/* range is 6.25% of default clock: arbitrarily picked */
452 		pix_clk_range = low.timing.pixel_clock >> 5;
453 		low.timing.pixel_clock -= pix_clk_range;
454 		high.timing.pixel_clock += pix_clk_range;
455 		/* 'some cards need wider virtual widths for certain modes':
456 		 * Not true. They might need a wider pitch, but this is _not_ reflected in
457 		 * virtual_width, but in fbc.bytes_per_row. */
458 		//So disable next line:
459 		//high.virtual_width = 4096;
460 		/* do it once for each depth we want to support */
461 		for (j = 0; j < (sizeof(spaces) / sizeof(color_space)); j++)
462 		{
463 			/* set target values */
464 			*dst = *src;
465 			/* poke the specific space */
466 			dst->space = low.space = high.space = spaces[j];
467 			/* ask for a compatible mode */
468 			/* We have to check for B_OK, because otherwise the pix_clk_range
469 			 * won't be taken into account!! */
470 			//So don't do this:
471 			//if (PROPOSE_DISPLAY_MODE(dst, &low, &high) != B_ERROR) {
472 			//Instead, do this:
473 			if (PROPOSE_DISPLAY_MODE(dst, &low, &high) == B_OK) {
474 				/* count it, and move on to next mode */
475 				dst++;
476 				si->mode_count++;
477 			}
478 		}
479 		/* advance to next mode */
480 		src++;
481 	}
482 
483 	/* add flatpanel native modes if panel(s) found */
484 	{
485 		bool pan1 = FALSE, pan2 = FALSE;
486 		display_mode p1, p2;
487 		get_panel_modelines(&p1, &p2, &pan1, &pan2);
488 
489 		if (pan1)
490 		{
491 			/* set ranges for acceptable values */
492 			low = high = p1;
493 			/* range is 6.25% of default clock: arbitrarily picked */
494 			pix_clk_range = low.timing.pixel_clock >> 5;
495 			low.timing.pixel_clock -= pix_clk_range;
496 			high.timing.pixel_clock += pix_clk_range;
497 			/* 'some cards need wider virtual widths for certain modes':
498 			 * Not true. They might need a wider pitch, but this is _not_ reflected in
499 			 * virtual_width, but in fbc.bytes_per_row. */
500 			//So disable next line:
501 			//high.virtual_width = 4096;
502 			/* do it once for each depth we want to support */
503 			for (j = 0; j < (sizeof(spaces) / sizeof(color_space)); j++)
504 			{
505 				/* set target values */
506 				*dst = p1;
507 				/* poke the specific space */
508 				dst->space = low.space = high.space = spaces[j];
509 				/* ask for a compatible mode */
510 				/* We have to check for B_OK, because otherwise the pix_clk_range
511 				 * won't be taken into account!! */
512 				//So don't do this:
513 				//if (PROPOSE_DISPLAY_MODE(dst, &low, &high) != B_ERROR) {
514 				//Instead, do this:
515 				if (PROPOSE_DISPLAY_MODE(dst, &low, &high) == B_OK)
516 				{
517 					/* count it, and move on to next mode */
518 					dst++;
519 					si->mode_count++;
520 				}
521 			}
522 		}
523 
524 		if (pan2)
525 		{
526 			/* set ranges for acceptable values */
527 			low = high = p2;
528 			/* range is 6.25% of default clock: arbitrarily picked */
529 			pix_clk_range = low.timing.pixel_clock >> 5;
530 			low.timing.pixel_clock -= pix_clk_range;
531 			high.timing.pixel_clock += pix_clk_range;
532 			/* 'some cards need wider virtual widths for certain modes':
533 			 * Not true. They might need a wider pitch, but this is _not_ reflected in
534 			 * virtual_width, but in fbc.bytes_per_row. */
535 			//So disable next line:
536 			//high.virtual_width = 4096;
537 			/* do it once for each depth we want to support */
538 			for (j = 0; j < (sizeof(spaces) / sizeof(color_space)); j++)
539 			{
540 				/* set target values */
541 				*dst = p2;
542 				/* poke the specific space */
543 				dst->space = low.space = high.space = spaces[j];
544 				/* ask for a compatible mode */
545 				/* We have to check for B_OK, because otherwise the pix_clk_range
546 				 * won't be taken into account!! */
547 				//So don't do this:
548 				//if (PROPOSE_DISPLAY_MODE(dst, &low, &high) != B_ERROR) {
549 				//Instead, do this:
550 				if (PROPOSE_DISPLAY_MODE(dst, &low, &high) == B_OK)
551 				{
552 					/* count it, and move on to next mode */
553 					dst++;
554 					si->mode_count++;
555 				}
556 			}
557 		}
558 	}
559 
560 	return B_OK;
561 }
562