2 Haiku ATI video driver adapted from the X.org ATI driver.
4 Copyright 1999, 2000 ATI Technologies Inc., Markham, Ontario,
5 Precision Insight, Inc., Cedar Park, Texas, and
6 VA Linux Systems Inc., Fremont, California.
8 Copyright 2009 Haiku, Inc. All rights reserved.
9 Distributed under the terms of the MIT license.
16 #include "accelerant.h"
25 // Flush all dirty data in the Pixel Cache to memory.
27 OUTREGM(R128_PC_NGUI_CTLSTAT
, R128_PC_FLUSH_ALL
, R128_PC_FLUSH_ALL
);
29 for (int i
= 0; i
< R128_TIMEOUT
; i
++) {
30 if ( ! (INREG(R128_PC_NGUI_CTLSTAT
) & R128_PC_BUSY
))
39 // Reset graphics card to known state.
41 Rage128_EngineFlush();
43 uint32 clockCntlIndex
= INREG(R128_CLOCK_CNTL_INDEX
);
44 uint32 mclkCntl
= GetPLLReg(R128_MCLK_CNTL
);
46 SetPLLReg(R128_MCLK_CNTL
, mclkCntl
| R128_FORCE_GCP
| R128_FORCE_PIPE3D_CP
);
48 uint32 genResetCntl
= INREG(R128_GEN_RESET_CNTL
);
50 OUTREG(R128_GEN_RESET_CNTL
, genResetCntl
| R128_SOFT_RESET_GUI
);
51 INREG(R128_GEN_RESET_CNTL
);
52 OUTREG(R128_GEN_RESET_CNTL
, genResetCntl
& ~R128_SOFT_RESET_GUI
);
53 INREG(R128_GEN_RESET_CNTL
);
55 SetPLLReg(R128_MCLK_CNTL
, mclkCntl
);
56 OUTREG(R128_CLOCK_CNTL_INDEX
, clockCntlIndex
);
57 OUTREG(R128_GEN_RESET_CNTL
, genResetCntl
);
62 Rage128_EngineInit(const DisplayModeEx
& mode
)
64 // Initialize the acceleration hardware.
66 SharedInfo
& si
= *gInfo
.sharedInfo
;
68 TRACE("Rage128_EngineInit() bits/pixel: %d\n", mode
.bitsPerPixel
);
70 OUTREG(R128_SCALE_3D_CNTL
, 0);
71 Rage128_EngineReset();
75 switch (mode
.bitsPerPixel
) {
89 TRACE("Unsupported color depth: %d bits/pixel\n", mode
.bitsPerPixel
);
93 OUTREG(R128_DEFAULT_OFFSET
, gInfo
.sharedInfo
->frameBufferOffset
);
94 OUTREG(R128_DEFAULT_PITCH
, mode
.timing
.h_display
/ 8);
97 OUTREG(R128_AUX_SC_CNTL
, 0);
98 OUTREG(R128_DEFAULT_SC_BOTTOM_RIGHT
, (R128_DEFAULT_SC_RIGHT_MAX
99 | R128_DEFAULT_SC_BOTTOM_MAX
));
100 OUTREG(R128_SC_TOP_LEFT
, 0);
101 OUTREG(R128_SC_BOTTOM_RIGHT
, (R128_DEFAULT_SC_RIGHT_MAX
102 | R128_DEFAULT_SC_BOTTOM_MAX
));
104 si
.r128_dpGuiMasterCntl
= ((dataType
<< R128_GMC_DST_DATATYPE_SHIFT
)
105 | R128_GMC_CLR_CMP_CNTL_DIS
106 | R128_GMC_AUX_CLIP_DIS
);
107 gInfo
.WaitForFifo(1);
108 OUTREG(R128_DP_GUI_MASTER_CNTL
, (si
.r128_dpGuiMasterCntl
109 | R128_GMC_BRUSH_SOLID_COLOR
110 | R128_GMC_SRC_DATATYPE_COLOR
));
112 gInfo
.WaitForFifo(8);
113 OUTREG(R128_DST_BRES_ERR
, 0);
114 OUTREG(R128_DST_BRES_INC
, 0);
115 OUTREG(R128_DST_BRES_DEC
, 0);
116 OUTREG(R128_DP_BRUSH_FRGD_CLR
, 0xffffffff);
117 OUTREG(R128_DP_BRUSH_BKGD_CLR
, 0x00000000);
118 OUTREG(R128_DP_SRC_FRGD_CLR
, 0xffffffff);
119 OUTREG(R128_DP_SRC_BKGD_CLR
, 0x00000000);
120 OUTREG(R128_DP_WRITE_MASK
, 0xffffffff);
122 gInfo
.WaitForFifo(1);
123 OUTREGM(R128_DP_DATATYPE
, 0, R128_HOST_BIG_ENDIAN_EN
);
130 Rage128_FillRectangle(engine_token
*et
, uint32 color
, fill_rect_params
*pList
, uint32 count
)
132 (void)et
; // avoid compiler warning for unused arg
134 gInfo
.WaitForFifo(3);
135 OUTREG(R128_DP_GUI_MASTER_CNTL
, (gInfo
.sharedInfo
->r128_dpGuiMasterCntl
136 | R128_GMC_BRUSH_SOLID_COLOR
137 | R128_GMC_SRC_DATATYPE_COLOR
138 | R128_ROP3_P
)); // use GXcopy for rop
140 OUTREG(R128_DP_BRUSH_FRGD_CLR
, color
);
141 OUTREG(R128_DP_CNTL
, R128_DST_X_LEFT_TO_RIGHT
| R128_DST_Y_TOP_TO_BOTTOM
);
146 int w
= pList
->right
- x
+ 1;
147 int h
= pList
->bottom
- y
+ 1;
149 gInfo
.WaitForFifo(2);
150 OUTREG(R128_DST_Y_X
, (y
<< 16) | x
);
151 OUTREG(R128_DST_WIDTH_HEIGHT
, (w
<< 16) | h
);
159 Rage128_FillSpan(engine_token
*et
, uint32 color
, uint16
*pList
, uint32 count
)
161 (void)et
; // avoid compiler warning for unused arg
163 gInfo
.WaitForFifo(2);
164 OUTREG(R128_DP_GUI_MASTER_CNTL
, (gInfo
.sharedInfo
->r128_dpGuiMasterCntl
165 | R128_GMC_BRUSH_SOLID_COLOR
166 | R128_GMC_SRC_DATATYPE_COLOR
167 | R128_ROP3_P
)); // use GXcopy for rop
169 OUTREG(R128_DP_BRUSH_FRGD_CLR
, color
);
174 int w
= *pList
++ - x
+ 1;
177 continue; // discard span with zero or negative width
179 gInfo
.WaitForFifo(2);
180 OUTREG(R128_DST_Y_X
, (y
<< 16) | x
);
181 OUTREG(R128_DST_WIDTH_HEIGHT
, (w
<< 16) | 1);
187 Rage128_InvertRectangle(engine_token
*et
, fill_rect_params
*pList
, uint32 count
)
189 (void)et
; // avoid compiler warning for unused arg
191 gInfo
.WaitForFifo(2);
192 OUTREG(R128_DP_GUI_MASTER_CNTL
, (gInfo
.sharedInfo
->r128_dpGuiMasterCntl
193 | R128_GMC_BRUSH_NONE
194 | R128_GMC_SRC_DATATYPE_COLOR
195 | R128_DP_SRC_SOURCE_MEMORY
196 | R128_ROP3_Dn
)); // use GXinvert for rop
198 OUTREG(R128_DP_CNTL
, R128_DST_X_LEFT_TO_RIGHT
| R128_DST_Y_TOP_TO_BOTTOM
);
203 int w
= pList
->right
- x
+ 1;
204 int h
= pList
->bottom
- y
+ 1;
206 gInfo
.WaitForFifo(2);
207 OUTREG(R128_DST_Y_X
, (y
<< 16) | x
);
208 OUTREG(R128_DST_WIDTH_HEIGHT
, (w
<< 16) | h
);
216 Rage128_ScreenToScreenBlit(engine_token
*et
, blit_params
*pList
, uint32 count
)
218 (void)et
; // avoid compiler warning for unused arg
220 gInfo
.WaitForFifo(1);
221 OUTREG(R128_DP_GUI_MASTER_CNTL
, (gInfo
.sharedInfo
->r128_dpGuiMasterCntl
222 | R128_GMC_BRUSH_NONE
223 | R128_GMC_SRC_DATATYPE_COLOR
224 | R128_DP_SRC_SOURCE_MEMORY
225 | R128_ROP3_S
)); // use GXcopy for rop
229 int src_x
= pList
->src_left
;
230 int src_y
= pList
->src_top
;
231 int dest_x
= pList
->dest_left
;
232 int dest_y
= pList
->dest_top
;
233 int width
= pList
->width
;
234 int height
= pList
->height
;
236 if (dest_x
<= src_x
) {
237 cmd
|= R128_DST_X_LEFT_TO_RIGHT
;
243 if (dest_y
<= src_y
) {
244 cmd
|= R128_DST_Y_TOP_TO_BOTTOM
;
250 gInfo
.WaitForFifo(4);
251 OUTREG(R128_DP_CNTL
, cmd
);
252 OUTREG(R128_SRC_Y_X
, (src_y
<< 16) | src_x
);
253 OUTREG(R128_DST_Y_X
, (dest_y
<< 16) | dest_x
);
254 OUTREG(R128_DST_HEIGHT_WIDTH
, ((height
+ 1) << 16) | (width
+ 1));