xref: /haiku/src/add-ons/accelerants/nvidia/GetModeInfo.c (revision 9eb55bc1d104b8fda80898f8b25c94d8000c8255)
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:
6 	Mark Watson
7 	Rudolf Cornelissen 9-11/2002
8 */
9 
10 #define MODULE_BIT 0x02000000
11 
12 #include "acc_std.h"
13 
14 /*
15 	Return the current display mode.  The only time you might return an
16 	error is if a mode hasn't been set. Or if the system hands you a NULL pointer.
17 */
18 status_t GET_DISPLAY_MODE(display_mode *current_mode)
19 {
20 	/* check for NULL pointer */
21 	if (current_mode == NULL) return B_ERROR;
22 
23 	*current_mode = si->dm;
24 	return B_OK;
25 }
26 
27 /* Return the frame buffer configuration information. */
28 status_t GET_FRAME_BUFFER_CONFIG(frame_buffer_config *afb)
29 {
30 	/* check for NULL pointer */
31 	if (afb == NULL) return B_ERROR;
32 
33 	*afb = si->fbc;
34 	return B_OK;
35 }
36 
37 /* Return the maximum and minium pixelclock limits for the specified mode. */
38 /* Rewritten / fixed by Rudolf */
39 /* NOTE:
40  * Due to BeOS constraints output for all heads will be limited to the head with
41  * the least capabilities. (BeOS should ask for seperate constraints for all heads.) */
42 status_t GET_PIXEL_CLOCK_LIMITS(display_mode *dm, uint32 *low, uint32 *high)
43 {
44 	uint32 max_pclk = 0;
45 	uint32 min_pclk = 0;
46 
47 	/* check for NULL pointers */
48 	if ((dm == NULL) || (low == NULL) || (high == NULL)) return B_ERROR;
49 
50 	/* specify requested info */
51 	if (dm->flags & DUALHEAD_BITS)
52 	{
53 		/* dualhead mode */
54 		/* find min. value */
55 		switch (si->ps.card_type)
56 		{
57 			default:
58 				*low = ((si->ps.min_video_vco * 1000) / 16);
59 				break;
60 		}
61 		/* find max. value */
62 		switch (dm->space)
63 		{
64 			case B_CMAP8:
65 				max_pclk = si->ps.max_dac2_clock_8;
66 				break;
67 			case B_RGB15_LITTLE:
68 			case B_RGB16_LITTLE:
69 				max_pclk = si->ps.max_dac2_clock_16;
70 				break;
71 			case B_RGB24_LITTLE:
72 				max_pclk = si->ps.max_dac2_clock_24;
73 				break;
74 			case B_RGB32_LITTLE:
75 				/* specially noted because of RAM speed constraints! */
76 				max_pclk = si->ps.max_dac2_clock_32dh;
77 				break;
78 			default:
79 				/* use fail-safe value */
80 				max_pclk = si->ps.max_dac2_clock_32dh;
81 				break;
82 		}
83 		/* return values in kHz */
84 		*high = max_pclk * 1000;
85 	}
86 	else
87 	{
88 		/* singlehead mode */
89 		/* find min. value */
90 		switch (si->ps.card_type)
91 		{
92 			default:
93 				*low = ((si->ps.min_pixel_vco * 1000) / 16);
94 				break;
95 		}
96 		/* find max. value */
97 		switch (dm->space)
98 		{
99 			case B_CMAP8:
100 				max_pclk = si->ps.max_dac1_clock_8;
101 				break;
102 			case B_RGB15_LITTLE:
103 			case B_RGB16_LITTLE:
104 				max_pclk = si->ps.max_dac1_clock_16;
105 				break;
106 			case B_RGB24_LITTLE:
107 				max_pclk = si->ps.max_dac1_clock_24;
108 				break;
109 			case B_RGB32_LITTLE:
110 				max_pclk = si->ps.max_dac1_clock_32;
111 				break;
112 			default:
113 				/* use fail-safe value */
114 				max_pclk = si->ps.max_dac1_clock_32;
115 				break;
116 		}
117 		/* return values in kHz */
118 		*high = max_pclk * 1000;
119 	}
120 
121 	/* clamp lower limit to 48Hz vertical refresh for now.
122 	 * Apparantly the BeOS screenprefs app does limit the upper refreshrate to 90Hz,
123 	 * while it does not limit the lower refreshrate. */
124 	min_pclk = ((uint32)dm->timing.h_total * (uint32)dm->timing.v_total * 48) / 1000;
125 	if (min_pclk > *low) *low = min_pclk;
126 
127 	return B_OK;
128 }
129 
130 /* Return the semaphore id that will be used to signal a vertical sync occured.  */
131 sem_id ACCELERANT_RETRACE_SEMAPHORE(void)
132 {
133 	return si->vblank;
134 }
135