2 Haiku ATI video driver adapted from the X.org ATI driver.
4 Copyright 1992,1993,1994,1995,1996,1997 by Kevin E. Martin, Chapel Hill, North Carolina.
5 Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
7 Copyright 2009 Haiku, Inc. All rights reserved.
8 Distributed under the terms of the MIT license.
15 #include "accelerant.h"
21 Mach64_InitDSPParams()
23 // Initialize global variables used to set DSP registers on a VT-B or later.
25 SharedInfo
& si
= *gInfo
.sharedInfo
;
26 M64_Params
& params
= si
.m64Params
;
28 // Retrieve XCLK settings.
30 uint8 ioValue
= Mach64_GetPLLReg(PLL_XCLK_CNTL
);
31 params
.xClkPostDivider
= ioValue
& 0x7;
33 switch (params
.xClkPostDivider
) {
38 params
.xClkRefDivider
= 1;
42 params
.xClkRefDivider
= 3;
43 params
.xClkPostDivider
= 0;
47 TRACE("Unsupported XCLK source: %d.\n", params
.xClkPostDivider
);
51 if (ioValue
& PLL_MFB_TIMES_4_2B
)
52 params
.xClkPostDivider
--;
54 // Compute maximum RAS delay and related params.
56 uint32 memCntl
= INREG(MEM_CNTL
);
57 int trp
= GetBits(memCntl
, CTL_MEM_TRP
);
58 params
.xClkPageFaultDelay
= GetBits(memCntl
, CTL_MEM_TRCD
) +
59 GetBits(memCntl
, CTL_MEM_TCRD
) + trp
+ 2;
60 params
.xClkMaxRASDelay
= GetBits(memCntl
, CTL_MEM_TRAS
) + trp
+ 2;
62 params
.displayFIFODepth
= 32;
64 if (si
.chipType
< MACH64_264VT4
) {
65 params
.xClkPageFaultDelay
+= 2;
66 params
.xClkMaxRASDelay
+= 3;
67 params
.displayFIFODepth
= 24;
70 // Determine type of memory used with the chip.
72 int memType
= INREG(CONFIG_STAT0
) & 0x7;
73 TRACE("Memory type: %d\n", memType
);
77 if (si
.videoMemSize
<= 1024 * 1024) {
78 params
.displayLoopLatency
= 10;
80 params
.displayLoopLatency
= 8;
81 params
.xClkPageFaultDelay
+= 2;
87 if (si
.videoMemSize
<= 1024 * 1024) {
88 params
.displayLoopLatency
= 9;
90 params
.displayLoopLatency
= 8;
91 params
.xClkPageFaultDelay
++;
96 if (si
.videoMemSize
<= 1024 * 1024) {
97 params
.displayLoopLatency
= 11;
99 params
.displayLoopLatency
= 10;
100 params
.xClkPageFaultDelay
++;
105 params
.displayLoopLatency
= 8;
106 params
.xClkPageFaultDelay
+= 3;
109 default: /* Set maximums */
110 params
.displayLoopLatency
= 11;
111 params
.xClkPageFaultDelay
+= 3;
115 if (params
.xClkMaxRASDelay
<= params
.xClkPageFaultDelay
)
116 params
.xClkMaxRASDelay
= params
.xClkPageFaultDelay
+ 1;
118 uint32 dspConfig
= INREG(DSP_CONFIG
);
120 params
.displayLoopLatency
= GetBits(dspConfig
, DSP_LOOP_LATENCY
);
127 Mach64_GetColorSpaceParams(int colorSpace
, uint8
& bitsPerPixel
, uint32
& maxPixelClock
)
129 // Get parameters for a color space which is supported by the Mach64 chips.
130 // Argument maxPixelClock is in KHz.
131 // Return true if the color space is supported; else return false.
133 SharedInfo
& si
= *gInfo
.sharedInfo
;
135 switch (colorSpace
) {
149 TRACE("Unsupported color space: 0x%X\n", colorSpace
);
153 if (si
.chipType
>= MACH64_264VTB
) {
154 if ((si
.chipType
>= MACH64_264VT4
) && (si
.chipType
!= MACH64_264LTPRO
))
155 maxPixelClock
= 230000;
156 else if (si
.chipType
>= MACH64_264VT3
)
157 maxPixelClock
= 200000;
159 maxPixelClock
= 170000;
161 if (bitsPerPixel
== 8)
162 maxPixelClock
= 135000;
164 maxPixelClock
= 80000;
175 TRACE("Mach64_Init()\n");
177 SharedInfo
& si
= *gInfo
.sharedInfo
;
179 static const int videoRamSizes
[] =
180 { 512, 1024, 2*1024, 4*1024, 6*1024, 8*1024, 12*1024, 16*1024 };
182 uint32 memCntl
= INREG(MEM_CNTL
);
183 if (si
.chipType
< MACH64_264VTB
) {
184 si
.videoMemSize
= videoRamSizes
[memCntl
& 0x7] * 1024;
186 uint32 ioValue
= (memCntl
& 0xf);
188 si
.videoMemSize
= (ioValue
+ 1) * 512 * 1024;
189 else if (ioValue
< 12)
190 si
.videoMemSize
= (ioValue
- 3) * 1024 * 1024;
192 si
.videoMemSize
= (ioValue
- 7) * 2048 * 1024;
195 si
.cursorOffset
= (si
.videoMemSize
- CURSOR_BYTES
) & ~0xfff; // align to 4k boundary
196 si
.frameBufferOffset
= 0;
197 si
.maxFrameBufferSize
= si
.cursorOffset
- si
.frameBufferOffset
;
199 TRACE("Video Memory size: %d MB frameBufferOffset: 0x%x cursorOffset: 0x%x\n",
200 si
.videoMemSize
/ 1024 / 1024, si
.frameBufferOffset
, si
.cursorOffset
);
202 // 264VT-B's and later have DSP registers.
204 if ((si
.chipType
>= MACH64_264VTB
) && !Mach64_InitDSPParams())
207 // Determine if the LCD display of a laptop computer is active.
209 si
.displayType
= MT_VGA
;
211 if (si
.chipType
== MACH64_MOBILITY
&& si
.panelX
> 0 && si
.panelY
> 0) {
212 if (Mach64_GetLCDReg(LCD_GEN_CNTL
) & LCD_ON
)
213 si
.displayType
= MT_LAPTOP
;
216 // Set up the array of color spaces supported by the Mach64 chips.
218 si
.colorSpaces
[0] = B_CMAP8
;
219 si
.colorSpaces
[1] = B_RGB15
;
220 si
.colorSpaces
[2] = B_RGB16
;
221 si
.colorSpaces
[3] = B_RGB32
;
222 si
.colorSpaceCount
= 4;
224 // Setup the mode list.
226 return CreateModeList(IsModeUsable
);
231 Mach64_WaitForFifo(uint32 entries
)
233 // The FIFO has 16 slots. This routines waits until at least `entries'
234 // of these slots are empty.
236 while ((INREG(FIFO_STAT
) & 0xffff) > (0x8000ul
>> entries
)) ;
243 // Wait for the graphics engine to be completely idle. That is, the FIFO
244 // has drained, the Pixel Cache is flushed, and the engine is idle. This
245 // is a standard "sync" function that will make the hardware "quiescent".
247 Mach64_WaitForFifo(16);
249 while (INREG(GUI_STAT
) & ENGINE_BUSY
) ;
254 Mach64_SetFunctionPointers(void)
256 // Setting the function pointers must be done prior to first ModeInit call
257 // or any accel activity.
259 gInfo
.WaitForFifo
= Mach64_WaitForFifo
;
260 gInfo
.WaitForIdle
= Mach64_WaitForIdle
;
262 gInfo
.DPMSCapabilities
= Mach64_DPMSCapabilities
;
263 gInfo
.GetDPMSMode
= Mach64_GetDPMSMode
;
264 gInfo
.SetDPMSMode
= Mach64_SetDPMSMode
;
266 gInfo
.LoadCursorImage
= Mach64_LoadCursorImage
;
267 gInfo
.SetCursorPosition
= Mach64_SetCursorPosition
;
268 gInfo
.ShowCursor
= Mach64_ShowCursor
;
270 gInfo
.FillRectangle
= Mach64_FillRectangle
;
271 gInfo
.FillSpan
= Mach64_FillSpan
;
272 gInfo
.InvertRectangle
= Mach64_InvertRectangle
;
273 gInfo
.ScreenToScreenBlit
= Mach64_ScreenToScreenBlit
;
275 gInfo
.AdjustFrame
= Mach64_AdjustFrame
;
276 gInfo
.ChipInit
= Mach64_Init
;
277 gInfo
.GetColorSpaceParams
= Mach64_GetColorSpaceParams
;
278 gInfo
.SetDisplayMode
= Mach64_SetDisplayMode
;
279 gInfo
.SetIndexedColors
= Mach64_SetIndexedColors
;