tcp: Add APICall trace entry and move TRACEs into locked parts.
[haiku.git] / src / add-ons / accelerants / et6x00 / ProposeDisplayMode.c
blob3e478b292b9161efb616998efa057eb650dff5f1
1 /*****************************************************************************\
2 * Tseng Labs ET6000, ET6100 and ET6300 graphics driver for BeOS 5.
3 * Copyright (c) 2003-2004, Evgeniy Vladimirovich Bobkov.
4 \*****************************************************************************/
6 #include "GlobalData.h"
7 #include "generic.h"
8 #include <string.h>
9 #include <sys/ioctl.h>
12 /*****************************************************************************/
13 #define T_POSITIVE_SYNC (B_POSITIVE_HSYNC | B_POSITIVE_VSYNC)
14 #define MODE_FLAGS (B_SCROLL | B_8_BIT_DAC | B_PARALLEL_ACCESS)
15 #define MODE_COUNT (sizeof (modesList) / sizeof (display_mode))
16 /*****************************************************************************/
17 static const display_mode modesList[] = {
18 { { 25175, 640, 656, 752, 800, 480, 490, 492, 525, 0}, B_RGB24, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(640X480X8.Z1) */
19 { { 27500, 640, 672, 768, 864, 480, 488, 494, 530, 0}, B_RGB24, 640, 480, 0, 0, MODE_FLAGS}, /* 640X480X60Hz */
20 { { 30500, 640, 672, 768, 864, 480, 517, 523, 588, 0}, B_RGB24, 640, 480, 0, 0, MODE_FLAGS}, /* SVGA_640X480X60HzNI */
21 { { 31500, 640, 664, 704, 832, 480, 489, 492, 520, 0}, B_RGB24, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(640X480X8.Z1) */
22 { { 31500, 640, 656, 720, 840, 480, 481, 484, 500, 0}, B_RGB24, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(640X480X8.Z1) */
23 { { 36000, 640, 696, 752, 832, 480, 481, 484, 509, 0}, B_RGB24, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(640X480X8.Z1) */
24 { { 38100, 800, 832, 960, 1088, 600, 602, 606, 620, 0}, B_RGB24, 800, 600, 0, 0, MODE_FLAGS}, /* SVGA_800X600X56HzNI */
25 { { 40000, 800, 840, 968, 1056, 600, 601, 605, 628, T_POSITIVE_SYNC}, B_RGB24, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(800X600X8.Z1) */
26 { { 49500, 800, 816, 896, 1056, 600, 601, 604, 625, T_POSITIVE_SYNC}, B_RGB24, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(800X600X8.Z1) */
27 { { 50000, 800, 856, 976, 1040, 600, 637, 643, 666, T_POSITIVE_SYNC}, B_RGB24, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(800X600X8.Z1) */
28 { { 56250, 800, 832, 896, 1048, 600, 601, 604, 631, T_POSITIVE_SYNC}, B_RGB24, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(800X600X8.Z1) */
29 { { 65000, 1024, 1048, 1184, 1344, 768, 771, 777, 806, 0}, B_RGB24, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1024X768X8.Z1) */
30 { { 75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806, 0}, B_RGB24, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70-72Hz_(1024X768X8.Z1) */
31 { { 78750, 1024, 1040, 1136, 1312, 768, 769, 772, 800, T_POSITIVE_SYNC}, B_RGB24, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1024X768X8.Z1) */
32 { { 94500, 1024, 1072, 1168, 1376, 768, 769, 772, 808, T_POSITIVE_SYNC}, B_RGB24, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1024X768X8.Z1) */
33 { { 94200, 1152, 1184, 1280, 1472, 864, 865, 868, 914, T_POSITIVE_SYNC}, B_RGB24, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1152X864X8.Z1) */
34 { { 108000, 1152, 1216, 1344, 1600, 864, 865, 868, 900, T_POSITIVE_SYNC}, B_RGB24, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1152X864X8.Z1) */
35 { { 121500, 1152, 1216, 1344, 1568, 864, 865, 868, 911, T_POSITIVE_SYNC}, B_RGB24, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1152X864X8.Z1) */
36 { { 108000, 1280, 1328, 1440, 1688, 1024, 1025, 1028, 1066, T_POSITIVE_SYNC}, B_RGB24, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1280X1024X8.Z1) */
37 { { 135000, 1280, 1296, 1440, 1688, 1024, 1025, 1028, 1066, T_POSITIVE_SYNC}, B_RGB24, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1280X1024X8.Z1) */
38 { { 157500, 1280, 1344, 1504, 1728, 1024, 1025, 1028, 1072, T_POSITIVE_SYNC}, B_RGB24, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@85Hz_(1280X1024X8.Z1) */
39 { { 162000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_RGB24, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@60Hz_(1600X1200X8.Z1) */
40 { { 175500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_RGB24, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@65Hz_(1600X1200X8.Z1) */
41 { { 189000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_RGB24, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@70Hz_(1600X1200X8.Z1) */
42 { { 202500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_RGB24, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@75Hz_(1600X1200X8.Z1) */
43 { { 216000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_RGB24, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_@80Hz_(1600X1200X8.Z1) */
44 { { 229500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, T_POSITIVE_SYNC}, B_RGB24, 1600, 1200, 0, 0, MODE_FLAGS} /* Vesa_Monitor_@85Hz_(1600X1200X8.Z1) */
46 /*****************************************************************************/
48 * Validate a target display mode is both
49 * a) a valid display mode for this device and
50 * b) falls between the contraints imposed by "low" and "high"
52 * If the mode is not (or cannot) be made valid for this device, return B_ERROR.
53 * If a valid mode can be constructed, but it does not fall within the limits,
54 * return B_BAD_VALUE.
55 * If the mode is both valid AND falls within the limits, return B_OK.
57 status_t PROPOSE_DISPLAY_MODE(display_mode *target,
58 const display_mode *low,
59 const display_mode *high)
61 ET6000DisplayMode mode;
63 mode.magic = ET6000_PRIVATE_DATA_MAGIC;
64 mode.mode = *target;
65 mode.memSize = si->memSize;
67 return ioctl(fd, ET6000_PROPOSE_DISPLAY_MODE, &mode, sizeof(mode));
69 /*****************************************************************************/
71 * Return the number of modes this device will return from GET_MODE_LIST().
73 uint32 ACCELERANT_MODE_COUNT(void) {
74 /* return the number of 'built-in' display modes */
75 return si->modesNum;
77 /*****************************************************************************/
79 * Copy the list of guaranteed supported video modes to the location provided.
81 status_t GET_MODE_LIST(display_mode *dm) {
82 /* copy them to the buffer pointed at by *dm */
83 memcpy(dm, et6000ModesList, si->modesNum * sizeof(display_mode));
84 return B_OK;
86 /*****************************************************************************/
88 * Create a list of display_modes to pass back to the caller.
90 status_t createModesList(void) {
91 size_t maxSize;
92 uint32 i, j, pixelClockRange;
93 const display_mode *src;
94 display_mode *dst, low, high;
95 color_space spaces[] = {B_RGB15_LITTLE, B_RGB16_LITTLE, B_RGB24_LITTLE};
98 /* figure out how big the list could be, and adjust up to nearest multiple of B_PAGE_SIZE */
99 maxSize = (((MODE_COUNT * 3) * sizeof(display_mode)) + (B_PAGE_SIZE-1)) & ~(B_PAGE_SIZE-1);
101 /* Create an area to hold the info */
102 si->modesArea = et6000ModesListArea =
103 create_area("ET6000 accelerant mode info", (void **)&et6000ModesList,
104 B_ANY_ADDRESS, maxSize, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
106 if (et6000ModesListArea < B_OK)
107 return et6000ModesListArea;
109 /* walk through our predefined list and see which modes fit this device */
110 src = modesList;
111 dst = et6000ModesList;
112 si->modesNum = 0;
113 for (i = 0; i < MODE_COUNT; i++) {
114 /* set ranges for acceptable values */
115 low = high = *src;
116 /* range is 6.25% of default clock: arbitrarily picked */
117 pixelClockRange = low.timing.pixel_clock >> 5;
118 low.timing.pixel_clock -= pixelClockRange;
119 high.timing.pixel_clock += pixelClockRange;
120 /* some cards need wider virtual widths for certain modes */
121 high.virtual_width = 2048;
122 /* do it once for each depth we want to support */
123 for (j = 0; j < (sizeof(spaces) / sizeof(color_space)); j++) {
124 /* set target values */
125 *dst = *src;
126 /* poke the specific space */
127 dst->space = low.space = high.space = spaces[j];
128 /* ask for a compatible mode */
129 if (PROPOSE_DISPLAY_MODE(dst, &low, &high) != B_ERROR) {
130 /* count it, and move on to next mode */
131 dst++;
132 si->modesNum++;
135 /* advance to next mode */
136 src++;
139 return B_OK;
141 /*****************************************************************************/