Mercurial > mplayer.hg
annotate vidix/drivers/mach64_vid.c @ 5689:2077782d0ca9
add prev/next title feature for gui dvd support
author | pontscho |
---|---|
date | Thu, 18 Apr 2002 18:24:08 +0000 |
parents | 85df37cde3d3 |
children | 56983ecb89aa |
rev | line source |
---|---|
4691 | 1 /* |
2 mach64_vid - VIDIX based video driver for Mach64 and 3DRage chips | |
3 Copyrights 2002 Nick Kurshev. This file is based on sources from | |
4 GATOS (gatos.sf.net) and X11 (www.xfree86.org) | |
5 Licence: GPL | |
4866 | 6 WARNING: THIS DRIVER IS IN BETTA STAGE |
4691 | 7 */ |
8 #include <errno.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <math.h> | |
13 #include <inttypes.h> | |
14 #include <fcntl.h> | |
15 | |
16 #include "../vidix.h" | |
17 #include "../fourcc.h" | |
18 #include "../../libdha/libdha.h" | |
19 #include "../../libdha/pci_ids.h" | |
20 #include "../../libdha/pci_names.h" | |
21 | |
22 #include "mach64.h" | |
5641
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
23 #include "../../version.h" |
4691 | 24 |
25 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */ | |
26 | |
27 static void *mach64_mmio_base = 0; | |
28 static void *mach64_mem_base = 0; | |
4721 | 29 static int32_t mach64_overlay_offset = 0; |
4691 | 30 static uint32_t mach64_ram_size = 0; |
4866 | 31 static uint32_t mach64_buffer_base[10][3]; |
32 static int num_mach64_buffers=-1; | |
4876 | 33 static int supports_planar=0; |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
34 static int supports_lcd_v_stretch=0; |
4691 | 35 |
36 pciinfo_t pci_info; | |
37 static int probed = 0; | |
38 static int __verbose = 0; | |
4721 | 39 |
4758 | 40 #define VERBOSE_LEVEL 1 |
41 | |
4721 | 42 typedef struct bes_registers_s |
43 { | |
44 /* base address of yuv framebuffer */ | |
45 uint32_t yuv_base; | |
46 uint32_t fourcc; | |
47 /* YUV BES registers */ | |
48 uint32_t reg_load_cntl; | |
49 uint32_t scale_inc; | |
50 uint32_t y_x_start; | |
51 uint32_t y_x_end; | |
52 uint32_t vid_buf_pitch; | |
53 uint32_t height_width; | |
54 | |
55 uint32_t scale_cntl; | |
56 uint32_t exclusive_horz; | |
57 uint32_t auto_flip_cntl; | |
58 uint32_t filter_cntl; | |
59 uint32_t key_cntl; | |
60 uint32_t test; | |
61 /* Configurable stuff */ | |
62 | |
63 int brightness; | |
64 int saturation; | |
65 | |
66 int ckey_on; | |
67 uint32_t graphics_key_clr; | |
68 uint32_t graphics_key_msk; | |
69 | |
70 int deinterlace_on; | |
71 uint32_t deinterlace_pattern; | |
72 | |
73 } bes_registers_t; | |
74 | |
75 static bes_registers_t besr; | |
76 | |
77 typedef struct video_registers_s | |
78 { | |
79 const char * sname; | |
80 uint32_t name; | |
81 uint32_t value; | |
82 }video_registers_t; | |
83 | |
84 static bes_registers_t besr; | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
85 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
86 /* Graphic keys */ |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
87 static vidix_grkey_t mach64_grkey; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
88 |
4721 | 89 #define DECLARE_VREG(name) { #name, name, 0 } |
90 static video_registers_t vregs[] = | |
91 { | |
92 DECLARE_VREG(OVERLAY_SCALE_INC), | |
93 DECLARE_VREG(OVERLAY_Y_X_START), | |
94 DECLARE_VREG(OVERLAY_Y_X_END), | |
95 DECLARE_VREG(OVERLAY_SCALE_CNTL), | |
96 DECLARE_VREG(OVERLAY_EXCLUSIVE_HORZ), | |
97 DECLARE_VREG(OVERLAY_EXCLUSIVE_VERT), | |
98 DECLARE_VREG(OVERLAY_TEST), | |
99 DECLARE_VREG(SCALER_BUF_PITCH), | |
100 DECLARE_VREG(SCALER_HEIGHT_WIDTH), | |
101 DECLARE_VREG(SCALER_BUF0_OFFSET), | |
102 DECLARE_VREG(SCALER_BUF0_OFFSET_U), | |
103 DECLARE_VREG(SCALER_BUF0_OFFSET_V), | |
104 DECLARE_VREG(SCALER_BUF1_OFFSET), | |
105 DECLARE_VREG(SCALER_BUF1_OFFSET_U), | |
106 DECLARE_VREG(SCALER_BUF1_OFFSET_V), | |
107 DECLARE_VREG(SCALER_H_COEFF0), | |
108 DECLARE_VREG(SCALER_H_COEFF1), | |
109 DECLARE_VREG(SCALER_H_COEFF2), | |
110 DECLARE_VREG(SCALER_H_COEFF3), | |
111 DECLARE_VREG(SCALER_H_COEFF4), | |
112 DECLARE_VREG(SCALER_COLOUR_CNTL), | |
113 DECLARE_VREG(SCALER_THRESHOLD), | |
114 DECLARE_VREG(VIDEO_FORMAT), | |
115 DECLARE_VREG(VIDEO_CONFIG), | |
116 DECLARE_VREG(VIDEO_SYNC_TEST), | |
117 DECLARE_VREG(VIDEO_SYNC_TEST_B) | |
118 }; | |
119 | |
4691 | 120 /* VIDIX exports */ |
121 | |
122 /* MMIO space*/ | |
123 #define GETREG(TYPE,PTR,OFFZ) (*((volatile TYPE*)((PTR)+(OFFZ)))) | |
124 #define SETREG(TYPE,PTR,OFFZ,VAL) (*((volatile TYPE*)((PTR)+(OFFZ))))=VAL | |
125 | |
4721 | 126 #define INREG8(addr) GETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2) |
127 #define OUTREG8(addr,val) SETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val) | |
128 #define INREG(addr) GETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2) | |
129 #define OUTREG(addr,val) SETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val) | |
4691 | 130 |
131 #define OUTREGP(addr,val,mask) \ | |
132 do { \ | |
133 unsigned int _tmp = INREG(addr); \ | |
134 _tmp &= (mask); \ | |
135 _tmp |= (val); \ | |
136 OUTREG(addr, _tmp); \ | |
137 } while (0) | |
138 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
139 static __inline__ int ATIGetMach64LCDReg(int _Index) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
140 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
141 OUTREG8(LCD_INDEX, _Index); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
142 return INREG(LCD_DATA); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
143 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
144 |
4691 | 145 static __inline__ uint32_t INPLL(uint32_t addr) |
146 { | |
4721 | 147 uint32_t res; |
148 | |
149 /* write addr byte */ | |
150 OUTREG8(CLOCK_CNTL + 1, (addr << 2)); | |
151 /* read the register value */ | |
152 res = INREG(CLOCK_CNTL + 2); | |
153 return res; | |
4691 | 154 } |
155 | |
4721 | 156 static __inline__ void OUTPLL(uint32_t addr,uint32_t val) |
157 { | |
158 /* write addr byte */ | |
159 OUTREG8(CLOCK_CNTL + 1, (addr << 2) | PLL_WR_EN); | |
160 /* write the register value */ | |
161 OUTREG(CLOCK_CNTL + 2, val); | |
162 OUTREG8(CLOCK_CNTL + 1, (addr << 2) & ~PLL_WR_EN); | |
163 } | |
164 | |
4691 | 165 #define OUTPLLP(addr,val,mask) \ |
166 do { \ | |
167 unsigned int _tmp = INPLL(addr); \ | |
168 _tmp &= (mask); \ | |
169 _tmp |= (val); \ | |
170 OUTPLL(addr, _tmp); \ | |
171 } while (0) | |
172 | |
4721 | 173 static void mach64_fifo_wait(unsigned n) |
174 { | |
175 while ((INREG(FIFO_STAT) & 0xffff) > ((uint32_t)(0x8000 >> n))); | |
176 } | |
177 | |
178 static void mach64_wait_for_idle( void ) | |
179 { | |
180 mach64_fifo_wait(16); | |
181 while ((INREG(GUI_STAT) & 1)!= 0); | |
182 } | |
183 | |
4876 | 184 static void mach64_wait_vsync( void ) |
185 { | |
186 int i; | |
187 | |
188 for(i=0; i<2000000; i++) | |
189 if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK)==0 ) break; | |
190 for(i=0; i<2000000; i++) | |
191 if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK) ) break; | |
192 | |
193 } | |
194 | |
4691 | 195 static vidix_capability_t mach64_cap = |
196 { | |
197 "BES driver for Mach64/3DRage cards", | |
4872 | 198 "Nick Kurshev and Michael Niedermayer", |
4691 | 199 TYPE_OUTPUT, |
200 { 0, 0, 0, 0 }, | |
201 2048, | |
202 2048, | |
203 4, | |
204 4, | |
205 -1, | |
206 FLAG_UPSCALER|FLAG_DOWNSCALER, | |
207 VENDOR_ATI, | |
208 -1, | |
209 { 0, 0, 0, 0 } | |
210 }; | |
211 | |
4721 | 212 static uint32_t mach64_vid_get_dbpp( void ) |
213 { | |
214 uint32_t dbpp,retval; | |
215 dbpp = (INREG(CRTC_GEN_CNTL)>>8)& 0x7; | |
216 switch(dbpp) | |
217 { | |
218 case 1: retval = 4; break; | |
219 case 2: retval = 8; break; | |
220 case 3: retval = 15; break; | |
221 case 4: retval = 16; break; | |
222 case 5: retval = 24; break; | |
223 default: retval=32; break; | |
224 } | |
225 return retval; | |
226 } | |
227 | |
228 static int mach64_is_dbl_scan( void ) | |
229 { | |
230 return INREG(CRTC_GEN_CNTL) & CRTC_DBL_SCAN_EN; | |
231 } | |
232 | |
233 static int mach64_is_interlace( void ) | |
234 { | |
235 return INREG(CRTC_GEN_CNTL) & CRTC_INTERLACE_EN; | |
236 } | |
237 | |
238 static uint32_t mach64_get_xres( void ) | |
239 { | |
240 /* FIXME: currently we extract that from CRTC!!!*/ | |
241 uint32_t xres,h_total; | |
242 h_total = INREG(CRTC_H_TOTAL_DISP); | |
243 xres = (h_total >> 16) & 0xffff; | |
244 return (xres + 1)*8; | |
245 } | |
246 | |
247 static uint32_t mach64_get_yres( void ) | |
248 { | |
249 /* FIXME: currently we extract that from CRTC!!!*/ | |
250 uint32_t yres,v_total; | |
251 v_total = INREG(CRTC_V_TOTAL_DISP); | |
252 yres = (v_total >> 16) & 0xffff; | |
253 return yres + 1; | |
254 } | |
255 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
256 // returns the verical stretch factor in 16.16 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
257 static int mach64_get_vert_stretch(void) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
258 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
259 int lcd_index; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
260 int lcd_gen_ctrl; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
261 int vert_stretching; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
262 int ext_vert_stretch; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
263 int ret; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
264 int yres= mach64_get_yres(); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
265 |
5641
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
266 if(!supports_lcd_v_stretch){ |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
267 if(__verbose>0) printf("[mach64] vertical stretching not supported\n"); |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
268 return 1<<16; |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
269 } |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
270 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
271 lcd_index= INREG(LCD_INDEX); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
272 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
273 vert_stretching= ATIGetMach64LCDReg(LCD_VERT_STRETCHING); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
274 if(!(vert_stretching&VERT_STRETCH_EN)) ret= 1<<16; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
275 else |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
276 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
277 int panel_size; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
278 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
279 ext_vert_stretch= ATIGetMach64LCDReg(LCD_EXT_VERT_STRETCH); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
280 panel_size= (ext_vert_stretch&VERT_PANEL_SIZE)>>11; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
281 panel_size++; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
282 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
283 ret= ((yres<<16) + (panel_size>>1))/panel_size; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
284 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
285 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
286 // lcd_gen_ctrl = ATIGetMach64LCDReg(LCD_GEN_CNTL); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
287 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
288 OUTREG(LCD_INDEX, lcd_index); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
289 |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
290 if(__verbose>0) printf("[mach64] vertical stretching factor= %d\n", ret); |
4872 | 291 |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
292 return ret; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
293 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
294 |
4721 | 295 static void mach64_vid_make_default() |
296 { | |
4872 | 297 mach64_fifo_wait(5); |
4761 | 298 OUTREG(SCALER_COLOUR_CNTL,0x00101000); |
4872 | 299 |
300 besr.ckey_on=0; | |
301 besr.graphics_key_msk=0; | |
302 besr.graphics_key_clr=0; | |
303 | |
304 OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk); | |
305 OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr); | |
306 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND); | |
307 | |
4721 | 308 } |
309 | |
310 static void mach64_vid_dump_regs( void ) | |
311 { | |
312 size_t i; | |
313 printf("[mach64] *** Begin of DRIVER variables dump ***\n"); | |
314 printf("[mach64] mach64_mmio_base=%p\n",mach64_mmio_base); | |
315 printf("[mach64] mach64_mem_base=%p\n",mach64_mem_base); | |
316 printf("[mach64] mach64_overlay_off=%08X\n",mach64_overlay_offset); | |
317 printf("[mach64] mach64_ram_size=%08X\n",mach64_ram_size); | |
318 printf("[mach64] video mode: %ux%u@%u\n",mach64_get_xres(),mach64_get_yres(),mach64_vid_get_dbpp()); | |
319 printf("[mach64] *** Begin of OV0 registers dump ***\n"); | |
320 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++) | |
321 { | |
322 mach64_wait_for_idle(); | |
323 printf("[mach64] %s = %08X\n",vregs[i].sname,INREG(vregs[i].name)); | |
324 } | |
325 printf("[mach64] *** End of OV0 registers dump ***\n"); | |
326 } | |
327 | |
328 | |
4691 | 329 unsigned int vixGetVersion(void) |
330 { | |
331 return(VIDIX_VERSION); | |
332 } | |
333 | |
334 static unsigned short ati_card_ids[] = | |
335 { | |
336 DEVICE_ATI_215CT_MACH64_CT, | |
337 DEVICE_ATI_210888CX_MACH64_CX, | |
338 DEVICE_ATI_210888ET_MACH64_ET, | |
339 DEVICE_ATI_MACH64_VT, | |
340 DEVICE_ATI_210888GX_MACH64_GX, | |
341 DEVICE_ATI_264LT_MACH64_LT, | |
342 DEVICE_ATI_264VT_MACH64_VT, | |
343 DEVICE_ATI_264VT3_MACH64_VT3, | |
344 DEVICE_ATI_264VT4_MACH64_VT4, | |
345 /**/ | |
346 DEVICE_ATI_3D_RAGE_PRO, | |
347 DEVICE_ATI_3D_RAGE_PRO2, | |
348 DEVICE_ATI_3D_RAGE_PRO3, | |
349 DEVICE_ATI_3D_RAGE_PRO4, | |
350 DEVICE_ATI_RAGE_XC, | |
351 DEVICE_ATI_RAGE_XL_AGP, | |
352 DEVICE_ATI_RAGE_XC_AGP, | |
353 DEVICE_ATI_RAGE_XL, | |
354 DEVICE_ATI_3D_RAGE_PRO5, | |
355 DEVICE_ATI_3D_RAGE_PRO6, | |
356 DEVICE_ATI_RAGE_XL2, | |
357 DEVICE_ATI_RAGE_XC2, | |
358 DEVICE_ATI_3D_RAGE_I_II, | |
359 DEVICE_ATI_3D_RAGE_II, | |
360 DEVICE_ATI_3D_RAGE_IIC, | |
361 DEVICE_ATI_3D_RAGE_IIC2, | |
362 DEVICE_ATI_3D_RAGE_IIC3, | |
363 DEVICE_ATI_3D_RAGE_IIC4, | |
364 DEVICE_ATI_3D_RAGE_LT, | |
365 DEVICE_ATI_3D_RAGE_LT2, | |
366 DEVICE_ATI_3D_RAGE_LT_G, | |
367 DEVICE_ATI_3D_RAGE_LT3, | |
368 DEVICE_ATI_RAGE_MOBILITY_P_M, | |
369 DEVICE_ATI_RAGE_MOBILITY_L, | |
370 DEVICE_ATI_3D_RAGE_LT4, | |
371 DEVICE_ATI_3D_RAGE_LT5, | |
372 DEVICE_ATI_RAGE_MOBILITY_P_M2, | |
373 DEVICE_ATI_RAGE_MOBILITY_L2 | |
374 }; | |
375 | |
376 static int find_chip(unsigned chip_id) | |
377 { | |
378 unsigned i; | |
379 for(i = 0;i < sizeof(ati_card_ids)/sizeof(unsigned short);i++) | |
380 { | |
381 if(chip_id == ati_card_ids[i]) return i; | |
382 } | |
383 return -1; | |
384 } | |
385 | |
386 int vixProbe(int verbose,int force) | |
387 { | |
388 pciinfo_t lst[MAX_PCI_DEVICES]; | |
389 unsigned i,num_pci; | |
390 int err; | |
391 __verbose = verbose; | |
392 err = pci_scan(lst,&num_pci); | |
393 if(err) | |
394 { | |
395 printf("[mach64] Error occured during pci scan: %s\n",strerror(err)); | |
396 return err; | |
397 } | |
398 else | |
399 { | |
400 err = ENXIO; | |
401 for(i=0;i<num_pci;i++) | |
402 { | |
403 if(lst[i].vendor == VENDOR_ATI) | |
404 { | |
405 int idx; | |
406 const char *dname; | |
407 idx = find_chip(lst[i].device); | |
408 if(idx == -1 && force == PROBE_NORMAL) continue; | |
409 dname = pci_device_name(VENDOR_ATI,lst[i].device); | |
410 dname = dname ? dname : "Unknown chip"; | |
411 printf("[mach64] Found chip: %s\n",dname); | |
412 if(force > PROBE_NORMAL) | |
413 { | |
414 printf("[mach64] Driver was forced. Was found %sknown chip\n",idx == -1 ? "un" : ""); | |
415 if(idx == -1) | |
416 printf("[mach64] Assuming it as Mach64\n"); | |
417 } | |
418 mach64_cap.device_id = lst[i].device; | |
419 err = 0; | |
420 memcpy(&pci_info,&lst[i],sizeof(pciinfo_t)); | |
421 probed=1; | |
422 break; | |
423 } | |
424 } | |
425 } | |
426 if(err && verbose) printf("[mach64] Can't find chip\n"); | |
427 return err; | |
428 } | |
429 | |
4721 | 430 static void reset_regs( void ) |
431 { | |
432 size_t i; | |
433 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++) | |
434 { | |
435 mach64_fifo_wait(2); | |
4758 | 436 OUTREG(vregs[i].name,0); |
4721 | 437 } |
438 } | |
439 | |
440 | |
4691 | 441 int vixInit(void) |
442 { | |
443 int err; | |
444 if(!probed) | |
445 { | |
446 printf("[mach64] Driver was not probed but is being initializing\n"); | |
447 return EINTR; | |
448 } | |
5641
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
449 if(__verbose>0) printf("[mach64] version %s\n", VERSION); |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
450 |
4721 | 451 if((mach64_mmio_base = map_phys_mem(pci_info.base2,0x4000))==(void *)-1) return ENOMEM; |
452 mach64_wait_for_idle(); | |
4691 | 453 mach64_ram_size = INREG(MEM_CNTL) & CTL_MEM_SIZEB; |
454 if (mach64_ram_size < 8) mach64_ram_size = (mach64_ram_size + 1) * 512; | |
455 else if (mach64_ram_size < 12) mach64_ram_size = (mach64_ram_size - 3) * 1024; | |
456 else mach64_ram_size = (mach64_ram_size - 7) * 2048; | |
457 mach64_ram_size *= 0x400; /* KB -> bytes */ | |
458 if((mach64_mem_base = map_phys_mem(pci_info.base0,mach64_ram_size))==(void *)-1) return ENOMEM; | |
4758 | 459 memset(&besr,0,sizeof(bes_registers_t)); |
4691 | 460 printf("[mach64] Video memory = %uMb\n",mach64_ram_size/0x100000); |
461 err = mtrr_set_type(pci_info.base0,mach64_ram_size,MTRR_TYPE_WRCOMB); | |
462 if(!err) printf("[mach64] Set write-combining type of video memory\n"); | |
4876 | 463 |
464 /* check if planar formats are supported */ | |
465 supports_planar=0; | |
466 mach64_wait_for_idle(); | |
467 mach64_fifo_wait(2); | |
468 if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1; | |
469 else | |
470 { | |
471 OUTREG(SCALER_BUF0_OFFSET_U, -1); | |
472 | |
473 mach64_wait_vsync(); | |
474 mach64_wait_for_idle(); | |
475 mach64_fifo_wait(2); | |
476 | |
477 if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1; | |
478 } | |
479 if(supports_planar) printf("[mach64] Planar YUV formats are supported :)\n"); | |
480 else printf("[mach64] Planar YUV formats are not supported :(\n"); | |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
481 |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
482 if( mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_P_M |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
483 || mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_P_M2 |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
484 || mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_L |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
485 || mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_L2) |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
486 supports_lcd_v_stretch=1; |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
487 else |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
488 supports_lcd_v_stretch=0; |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
489 |
4721 | 490 reset_regs(); |
4761 | 491 mach64_vid_make_default(); |
4876 | 492 |
4758 | 493 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4691 | 494 return 0; |
495 } | |
496 | |
497 void vixDestroy(void) | |
498 { | |
499 unmap_phys_mem(mach64_mem_base,mach64_ram_size); | |
4721 | 500 unmap_phys_mem(mach64_mmio_base,0x4000); |
4691 | 501 } |
502 | |
503 int vixGetCapability(vidix_capability_t *to) | |
504 { | |
505 memcpy(to, &mach64_cap, sizeof(vidix_capability_t)); | |
506 return 0; | |
507 } | |
508 | |
4721 | 509 static unsigned mach64_query_pitch(unsigned fourcc,const vidix_yuv_t *spitch) |
510 { | |
511 unsigned pitch,spy,spv,spu; | |
512 spy = spv = spu = 0; | |
513 switch(spitch->y) | |
514 { | |
515 case 16: | |
516 case 32: | |
517 case 64: | |
518 case 128: | |
519 case 256: spy = spitch->y; break; | |
520 default: break; | |
521 } | |
522 switch(spitch->u) | |
523 { | |
524 case 16: | |
525 case 32: | |
526 case 64: | |
527 case 128: | |
528 case 256: spu = spitch->u; break; | |
529 default: break; | |
530 } | |
531 switch(spitch->v) | |
532 { | |
533 case 16: | |
534 case 32: | |
535 case 64: | |
536 case 128: | |
537 case 256: spv = spitch->v; break; | |
538 default: break; | |
539 } | |
540 switch(fourcc) | |
541 { | |
542 /* 4:2:0 */ | |
543 case IMGFMT_IYUV: | |
544 case IMGFMT_YV12: | |
545 case IMGFMT_I420: | |
546 if(spy > 16 && spu == spy/2 && spv == spy/2) pitch = spy; | |
547 else pitch = 32; | |
548 break; | |
4872 | 549 case IMGFMT_YVU9: |
550 if(spy > 32 && spu == spy/4 && spv == spy/4) pitch = spy; | |
551 else pitch = 64; | |
552 break; | |
4721 | 553 default: |
4722
39f3bfae472c
Direct rendering with dshow codecs support. (Was untested but should work)
nick
parents:
4721
diff
changeset
|
554 if(spy >= 16) pitch = spy; |
39f3bfae472c
Direct rendering with dshow codecs support. (Was untested but should work)
nick
parents:
4721
diff
changeset
|
555 else pitch = 16; |
4721 | 556 break; |
557 } | |
558 return pitch; | |
559 } | |
560 | |
561 static void mach64_compute_framesize(vidix_playback_t *info) | |
562 { | |
563 unsigned pitch,awidth; | |
564 pitch = mach64_query_pitch(info->fourcc,&info->src.pitch); | |
565 switch(info->fourcc) | |
566 { | |
567 case IMGFMT_I420: | |
568 case IMGFMT_YV12: | |
569 case IMGFMT_IYUV: | |
570 awidth = (info->src.w + (pitch-1)) & ~(pitch-1); | |
571 info->frame_size = awidth*(info->src.h+info->src.h/2); | |
572 break; | |
4872 | 573 case IMGFMT_YVU9: |
574 awidth = (info->src.w + (pitch-1)) & ~(pitch-1); | |
575 info->frame_size = awidth*(info->src.h+info->src.h/8); | |
576 break; | |
577 // case IMGFMT_RGB32: | |
4721 | 578 case IMGFMT_BGR32: |
579 awidth = (info->src.w*4 + (pitch-1)) & ~(pitch-1); | |
580 info->frame_size = (awidth*info->src.h); | |
581 break; | |
582 /* YUY2 YVYU, RGB15, RGB16 */ | |
583 default: | |
584 awidth = (info->src.w*2 + (pitch-1)) & ~(pitch-1); | |
585 info->frame_size = (awidth*info->src.h); | |
586 break; | |
587 } | |
4872 | 588 info->frame_size+=256; // so we have some space for alignment & such |
589 info->frame_size&=~16; | |
4721 | 590 } |
591 | |
592 static void mach64_vid_stop_video( void ) | |
593 { | |
594 mach64_fifo_wait(14); | |
595 OUTREG(OVERLAY_SCALE_CNTL, 0x80000000); | |
596 OUTREG(OVERLAY_EXCLUSIVE_HORZ, 0); | |
597 OUTREG(OVERLAY_EXCLUSIVE_VERT, 0); | |
598 OUTREG(SCALER_H_COEFF0, 0x00002000); | |
599 OUTREG(SCALER_H_COEFF1, 0x0D06200D); | |
600 OUTREG(SCALER_H_COEFF2, 0x0D0A1C0D); | |
601 OUTREG(SCALER_H_COEFF3, 0x0C0E1A0C); | |
602 OUTREG(SCALER_H_COEFF4, 0x0C14140C); | |
603 OUTREG(VIDEO_FORMAT, 0xB000B); | |
604 OUTREG(OVERLAY_TEST, 0x0); | |
605 } | |
606 | |
607 static void mach64_vid_display_video( void ) | |
608 { | |
609 uint32_t vf; | |
610 mach64_fifo_wait(14); | |
611 | |
612 OUTREG(OVERLAY_Y_X_START, besr.y_x_start); | |
613 OUTREG(OVERLAY_Y_X_END, besr.y_x_end); | |
614 OUTREG(OVERLAY_SCALE_INC, besr.scale_inc); | |
615 OUTREG(SCALER_BUF_PITCH, besr.vid_buf_pitch); | |
616 OUTREG(SCALER_HEIGHT_WIDTH, besr.height_width); | |
4866 | 617 OUTREG(SCALER_BUF0_OFFSET, mach64_buffer_base[0][0]); |
618 OUTREG(SCALER_BUF0_OFFSET_U, mach64_buffer_base[0][1]); | |
619 OUTREG(SCALER_BUF0_OFFSET_V, mach64_buffer_base[0][2]); | |
620 OUTREG(SCALER_BUF1_OFFSET, mach64_buffer_base[0][0]); | |
621 OUTREG(SCALER_BUF1_OFFSET_U, mach64_buffer_base[0][1]); | |
622 OUTREG(SCALER_BUF1_OFFSET_V, mach64_buffer_base[0][2]); | |
4876 | 623 mach64_wait_vsync(); |
624 | |
625 mach64_fifo_wait(4); | |
4758 | 626 OUTREG(OVERLAY_SCALE_CNTL, 0xC4000003); |
4760 | 627 // OVERLAY_SCALE_CNTL bits & what they seem to affect |
628 // bit 0 no effect | |
629 // bit 1 yuv2rgb coeff related | |
630 // bit 2 horizontal interpolation if 0 | |
631 // bit 3 vertical interpolation if 0 | |
4847 | 632 // bit 4 chroma encoding (0-> 128=neutral / 1-> 0->neutral) |
4760 | 633 // bit 5-6 gamma correction |
634 // bit 7 nothing visible if set | |
635 // bit 8-27 no effect | |
636 // bit 28-31 nothing interresting just crashed my system when i played with them :( | |
4847 | 637 |
4721 | 638 mach64_wait_for_idle(); |
639 vf = INREG(VIDEO_FORMAT); | |
4751 | 640 |
641 // Bits 16-19 seem to select the format | |
4769 | 642 // 0x0 dunno behaves strange |
643 // 0x1 dunno behaves strange | |
644 // 0x2 dunno behaves strange | |
645 // 0x3 BGR15 | |
646 // 0x4 BGR16 | |
647 // 0x5 BGR16 (hmm, that need investigation, 2 BGR16 formats, i guess 1 will have only 5bits for green) | |
648 // 0x6 BGR32 | |
649 // 0x7 BGR32 with somehow mixed even / odd pixels ? | |
650 // 0x8 YYYYUVUV | |
651 // 0x9 YVU9 | |
652 // 0xA YV12 | |
653 // 0xB YUY2 | |
654 // 0xC UYVY | |
4847 | 655 // 0xD UYVY (no difference is visible if i switch between C/D for every even/odd frame) |
4769 | 656 // 0xE dunno behaves strange |
657 // 0xF dunno behaves strange | |
658 // Bit 28 all values are assumed to be 7 bit with chroma=64 for black (tested with YV12 & YUY2) | |
4751 | 659 // the remaining bits seem to have no effect |
660 | |
4769 | 661 |
4721 | 662 switch(besr.fourcc) |
663 { | |
4769 | 664 /* BGR formats */ |
665 case IMGFMT_BGR15: OUTREG(VIDEO_FORMAT, 0x00030000); break; | |
666 case IMGFMT_BGR16: OUTREG(VIDEO_FORMAT, 0x00040000); break; | |
667 case IMGFMT_BGR32: OUTREG(VIDEO_FORMAT, 0x00060000); break; | |
4721 | 668 /* 4:2:0 */ |
669 case IMGFMT_IYUV: | |
670 case IMGFMT_I420: | |
4769 | 671 case IMGFMT_YV12: OUTREG(VIDEO_FORMAT, 0x000A0000); break; |
4872 | 672 |
673 case IMGFMT_YVU9: OUTREG(VIDEO_FORMAT, 0x00090000); break; | |
4721 | 674 /* 4:2:2 */ |
675 case IMGFMT_YVYU: | |
4769 | 676 case IMGFMT_UYVY: OUTREG(VIDEO_FORMAT, 0x000C0000); break; |
4721 | 677 case IMGFMT_YUY2: |
4769 | 678 default: OUTREG(VIDEO_FORMAT, 0x000B0000); break; |
4721 | 679 } |
4758 | 680 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4721 | 681 } |
682 | |
683 static int mach64_vid_init_video( vidix_playback_t *config ) | |
684 { | |
4758 | 685 uint32_t src_w,src_h,dest_w,dest_h,pitch,h_inc,v_inc,left,leftUV,top,ecp,y_pos; |
4721 | 686 int is_420,best_pitch,mpitch; |
4866 | 687 int src_offset_y, src_offset_u, src_offset_v; |
688 unsigned int i; | |
4872 | 689 |
4721 | 690 mach64_vid_stop_video(); |
4866 | 691 /* warning, if left or top are != 0 this will fail, as the framesize is too small then */ |
692 left = config->src.x; | |
693 top = config->src.y; | |
4721 | 694 src_h = config->src.h; |
695 src_w = config->src.w; | |
696 is_420 = 0; | |
697 if(config->fourcc == IMGFMT_YV12 || | |
698 config->fourcc == IMGFMT_I420 || | |
699 config->fourcc == IMGFMT_IYUV) is_420 = 1; | |
700 best_pitch = mach64_query_pitch(config->fourcc,&config->src.pitch); | |
701 mpitch = best_pitch-1; | |
702 switch(config->fourcc) | |
703 { | |
4872 | 704 case IMGFMT_YVU9: |
4721 | 705 /* 4:2:0 */ |
706 case IMGFMT_IYUV: | |
707 case IMGFMT_YV12: | |
708 case IMGFMT_I420: pitch = (src_w + mpitch) & ~mpitch; | |
709 config->dest.pitch.y = | |
710 config->dest.pitch.u = | |
711 config->dest.pitch.v = best_pitch; | |
4769 | 712 besr.vid_buf_pitch= pitch; |
4721 | 713 break; |
714 /* RGB 4:4:4:4 */ | |
715 case IMGFMT_RGB32: | |
716 case IMGFMT_BGR32: pitch = (src_w*4 + mpitch) & ~mpitch; | |
717 config->dest.pitch.y = | |
718 config->dest.pitch.u = | |
719 config->dest.pitch.v = best_pitch; | |
4769 | 720 besr.vid_buf_pitch= pitch>>2; |
4721 | 721 break; |
722 /* 4:2:2 */ | |
723 default: /* RGB15, RGB16, YVYU, UYVY, YUY2 */ | |
724 pitch = ((src_w*2) + mpitch) & ~mpitch; | |
725 config->dest.pitch.y = | |
726 config->dest.pitch.u = | |
727 config->dest.pitch.v = best_pitch; | |
4769 | 728 besr.vid_buf_pitch= pitch>>1; |
4721 | 729 break; |
730 } | |
731 dest_w = config->dest.w; | |
732 dest_h = config->dest.h; | |
733 besr.fourcc = config->fourcc; | |
734 ecp = (INPLL(PLL_VCLK_CNTL) & PLL_ECP_DIV) >> 4; | |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
735 if(__verbose>0) printf("[mach64] ecp: %d\n", ecp); |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
736 v_inc = src_h * mach64_get_vert_stretch(); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
737 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
738 if(mach64_is_interlace()) v_inc<<=1; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
739 if(mach64_is_dbl_scan() ) v_inc>>=1; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
740 v_inc>>=4; // convert 16.16 -> 20.12 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
741 v_inc/= dest_h; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
742 |
5589 | 743 h_inc = (src_w << 12) / dest_w; |
4721 | 744 /* keep everything in 16.16 */ |
745 config->offsets[0] = 0; | |
4866 | 746 for(i=1; i<config->num_frames; i++) |
747 config->offsets[i] = config->offsets[i-1] + config->frame_size; | |
748 | |
4872 | 749 /*FIXME the left / top stuff is broken (= zoom a src rectangle from a larger one) |
750 1. the framesize isnt known as the outer src rectangle dimensions arent known | |
751 2. the mach64 needs aligned addresses so it cant work anyway | |
752 -> so we could shift the outer buffer to compensate that but that would mean | |
753 alignment problems for the code which writes into it | |
754 */ | |
755 | |
4721 | 756 if(is_420) |
757 { | |
4866 | 758 config->offset.y= 0; |
4872 | 759 config->offset.u= (pitch*src_h + 15)&~15; |
760 config->offset.v= (config->offset.u + (pitch*src_h>>2) + 15)&~15; | |
761 | |
4866 | 762 src_offset_y= config->offset.y + top*pitch + left; |
763 src_offset_u= config->offset.u + (top*pitch>>2) + (left>>1); | |
764 src_offset_v= config->offset.v + (top*pitch>>2) + (left>>1); | |
4872 | 765 |
4721 | 766 if(besr.fourcc == IMGFMT_I420 || besr.fourcc == IMGFMT_IYUV) |
767 { | |
768 uint32_t tmp; | |
769 tmp = config->offset.u; | |
770 config->offset.u = config->offset.v; | |
771 config->offset.v = tmp; | |
772 } | |
773 } | |
4872 | 774 else if(besr.fourcc == IMGFMT_YVU9) |
775 { | |
776 config->offset.y= 0; | |
777 config->offset.u= (pitch*src_h + 15)&~15; | |
778 config->offset.v= (config->offset.u + (pitch*src_h>>4) + 15)&~15; | |
779 | |
780 src_offset_y= config->offset.y + top*pitch + left; | |
781 src_offset_u= config->offset.u + (top*pitch>>4) + (left>>1); | |
782 src_offset_v= config->offset.v + (top*pitch>>4) + (left>>1); | |
783 } | |
4866 | 784 else if(besr.fourcc == IMGFMT_BGR32) |
785 { | |
786 config->offset.y = config->offset.u = config->offset.v = 0; | |
4872 | 787 src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 2); |
4866 | 788 } |
4721 | 789 else |
790 { | |
4866 | 791 config->offset.y = config->offset.u = config->offset.v = 0; |
4872 | 792 src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 1); |
4866 | 793 } |
794 | |
795 num_mach64_buffers= config->num_frames; | |
796 for(i=0; i<config->num_frames; i++) | |
797 { | |
798 mach64_buffer_base[i][0]= (mach64_overlay_offset + config->offsets[i] + src_offset_y)&~15; | |
799 mach64_buffer_base[i][1]= (mach64_overlay_offset + config->offsets[i] + src_offset_u)&~15; | |
800 mach64_buffer_base[i][2]= (mach64_overlay_offset + config->offsets[i] + src_offset_v)&~15; | |
4721 | 801 } |
802 | |
803 leftUV = (left >> 17) & 15; | |
804 left = (left >> 16) & 15; | |
805 besr.scale_inc = ( h_inc << 16 ) | v_inc; | |
4758 | 806 y_pos = config->dest.y; |
807 if(mach64_is_dbl_scan()) y_pos*=2; | |
808 else | |
809 if(mach64_is_interlace()) y_pos/=2; | |
810 besr.y_x_start = y_pos | (config->dest.x << 16); | |
811 y_pos =config->dest.y + dest_h; | |
812 if(mach64_is_dbl_scan()) y_pos*=2; | |
813 else | |
814 if(mach64_is_interlace()) y_pos/=2; | |
815 besr.y_x_end = y_pos | ((config->dest.x + dest_w) << 16); | |
4721 | 816 besr.height_width = ((src_w - left)<<16) | (src_h - top); |
4769 | 817 |
4721 | 818 return 0; |
819 } | |
820 | |
4876 | 821 static int is_supported_fourcc(uint32_t fourcc) |
4721 | 822 { |
4876 | 823 switch(fourcc) |
824 { | |
825 case IMGFMT_YV12: | |
826 case IMGFMT_I420: | |
827 case IMGFMT_YVU9: | |
828 case IMGFMT_IYUV: | |
829 return supports_planar; | |
830 case IMGFMT_YUY2: | |
831 case IMGFMT_UYVY: | |
832 case IMGFMT_BGR15: | |
833 case IMGFMT_BGR16: | |
834 case IMGFMT_BGR32: | |
835 return 1; | |
836 default: | |
837 return 0; | |
838 } | |
4721 | 839 } |
840 | |
4691 | 841 int vixQueryFourcc(vidix_fourcc_t *to) |
842 { | |
4721 | 843 if(is_supported_fourcc(to->fourcc)) |
844 { | |
845 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
846 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
847 VID_DEPTH_12BPP| VID_DEPTH_15BPP| | |
848 VID_DEPTH_16BPP| VID_DEPTH_24BPP| | |
849 VID_DEPTH_32BPP; | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
850 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; |
4721 | 851 return 0; |
852 } | |
853 else to->depth = to->flags = 0; | |
4691 | 854 return ENOSYS; |
855 } | |
856 | |
857 int vixConfigPlayback(vidix_playback_t *info) | |
858 { | |
4721 | 859 if(!is_supported_fourcc(info->fourcc)) return ENOSYS; |
4866 | 860 |
4721 | 861 mach64_compute_framesize(info); |
4894
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
862 |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
863 if(info->num_frames>4) info->num_frames=4; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
864 for(;info->num_frames>0; info->num_frames--) |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
865 { |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
866 mach64_overlay_offset = mach64_ram_size - info->frame_size*info->num_frames; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
867 mach64_overlay_offset &= 0xffff0000; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
868 if(mach64_overlay_offset>0) break; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
869 } |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
870 if(info->num_frames <= 0) return EINVAL; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
871 |
4721 | 872 info->dga_addr = (char *)mach64_mem_base + mach64_overlay_offset; |
873 mach64_vid_init_video(info); | |
874 return 0; | |
4691 | 875 } |
876 | |
877 int vixPlaybackOn(void) | |
878 { | |
4721 | 879 mach64_vid_display_video(); |
880 return 0; | |
4691 | 881 } |
882 | |
883 int vixPlaybackOff(void) | |
884 { | |
4721 | 885 mach64_vid_stop_video(); |
886 return 0; | |
887 } | |
888 | |
4691 | 889 int vixPlaybackFrameSelect(unsigned int frame) |
890 { | |
4721 | 891 uint32_t off[6]; |
4866 | 892 int i; |
893 int last_frame= (frame-1+num_mach64_buffers) % num_mach64_buffers; | |
894 //printf("Selecting frame %d\n", frame); | |
4721 | 895 /* |
896 buf3-5 always should point onto second buffer for better | |
897 deinterlacing and TV-in | |
898 */ | |
4866 | 899 if(num_mach64_buffers==1) return 0; |
900 | |
901 for(i=0; i<3; i++) | |
4721 | 902 { |
4866 | 903 off[i] = mach64_buffer_base[frame][i]; |
904 off[i+3]= mach64_buffer_base[last_frame][i]; | |
905 } | |
4769 | 906 |
4847 | 907 #if 0 // delay routine so the individual frames can be ssen better |
908 { | |
909 volatile int i=0; | |
910 for(i=0; i<10000000; i++); | |
911 } | |
912 #endif | |
4721 | 913 |
914 mach64_wait_for_idle(); | |
915 mach64_fifo_wait(7); | |
4847 | 916 |
4721 | 917 OUTREG(SCALER_BUF0_OFFSET, off[0]); |
918 OUTREG(SCALER_BUF0_OFFSET_U, off[1]); | |
919 OUTREG(SCALER_BUF0_OFFSET_V, off[2]); | |
920 OUTREG(SCALER_BUF1_OFFSET, off[3]); | |
921 OUTREG(SCALER_BUF1_OFFSET_U, off[4]); | |
922 OUTREG(SCALER_BUF1_OFFSET_V, off[5]); | |
4866 | 923 if(num_mach64_buffers==2) mach64_wait_vsync(); //only wait for vsync if we do double buffering |
924 | |
4758 | 925 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4721 | 926 return 0; |
4691 | 927 } |
4721 | 928 |
929 vidix_video_eq_t equal = | |
930 { | |
931 VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | |
932 , | |
933 0, 0, 0, 0, 0, 0, 0, 0 }; | |
934 | |
935 int vixPlaybackGetEq( vidix_video_eq_t * eq) | |
936 { | |
937 memcpy(eq,&equal,sizeof(vidix_video_eq_t)); | |
938 return 0; | |
939 } | |
940 | |
941 int vixPlaybackSetEq( const vidix_video_eq_t * eq) | |
942 { | |
943 int br,sat; | |
944 if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness; | |
945 if(eq->cap & VEQ_CAP_CONTRAST) equal.contrast = eq->contrast; | |
946 if(eq->cap & VEQ_CAP_SATURATION) equal.saturation = eq->saturation; | |
947 if(eq->cap & VEQ_CAP_HUE) equal.hue = eq->hue; | |
948 if(eq->cap & VEQ_CAP_RGB_INTENSITY) | |
949 { | |
950 equal.red_intensity = eq->red_intensity; | |
951 equal.green_intensity = eq->green_intensity; | |
952 equal.blue_intensity = eq->blue_intensity; | |
953 } | |
954 equal.flags = eq->flags; | |
955 br = equal.brightness * 64 / 1000; | |
956 if(br < -64) br = -64; if(br > 63) br = 63; | |
957 sat = (equal.saturation + 1000) * 16 / 1000; | |
958 if(sat < 0) sat = 0; if(sat > 31) sat = 31; | |
959 OUTREG(SCALER_COLOUR_CNTL, (br & 0x7f) | (sat << 8) | (sat << 16)); | |
960 return 0; | |
961 } | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
962 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
963 int vixGetGrKeys(vidix_grkey_t *grkey) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
964 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
965 memcpy(grkey, &mach64_grkey, sizeof(vidix_grkey_t)); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
966 return(0); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
967 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
968 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
969 int vixSetGrKeys(const vidix_grkey_t *grkey) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
970 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
971 memcpy(&mach64_grkey, grkey, sizeof(vidix_grkey_t)); |
4872 | 972 |
973 if(mach64_grkey.ckey.op == CKEY_TRUE) | |
974 { | |
975 besr.ckey_on=1; | |
976 | |
977 switch(mach64_vid_get_dbpp()) | |
978 { | |
979 case 15: | |
980 besr.graphics_key_msk=0x7FFF; | |
981 besr.graphics_key_clr= | |
982 ((mach64_grkey.ckey.blue &0xF8)>>3) | |
983 | ((mach64_grkey.ckey.green&0xF8)<<2) | |
984 | ((mach64_grkey.ckey.red &0xF8)<<7); | |
985 break; | |
986 case 16: | |
987 besr.graphics_key_msk=0xFFFF; | |
988 besr.graphics_key_clr= | |
989 ((mach64_grkey.ckey.blue &0xF8)>>3) | |
990 | ((mach64_grkey.ckey.green&0xFC)<<3) | |
991 | ((mach64_grkey.ckey.red &0xF8)<<8); | |
992 break; | |
993 case 24: | |
994 besr.graphics_key_msk=0xFFFFFF; | |
995 besr.graphics_key_clr= | |
996 ((mach64_grkey.ckey.blue &0xFF)) | |
997 | ((mach64_grkey.ckey.green&0xFF)<<8) | |
998 | ((mach64_grkey.ckey.red &0xFF)<<16); | |
999 break; | |
1000 case 32: | |
1001 besr.graphics_key_msk=0xFFFFFF; | |
1002 besr.graphics_key_clr= | |
1003 ((mach64_grkey.ckey.blue &0xFF)) | |
1004 | ((mach64_grkey.ckey.green&0xFF)<<8) | |
1005 | ((mach64_grkey.ckey.red &0xFF)<<16); | |
1006 break; | |
1007 default: | |
1008 besr.ckey_on=0; | |
1009 besr.graphics_key_msk=0; | |
1010 besr.graphics_key_clr=0; | |
1011 } | |
1012 } | |
1013 else | |
1014 { | |
1015 besr.ckey_on=0; | |
1016 besr.graphics_key_msk=0; | |
1017 besr.graphics_key_clr=0; | |
1018 } | |
1019 | |
1020 mach64_fifo_wait(4); | |
1021 OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk); | |
1022 OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr); | |
1023 // OUTREG(OVERLAY_VIDEO_KEY_MSK, 0); | |
1024 // OUTREG(OVERLAY_VIDEO_KEY_CLR, 0); | |
1025 if(besr.ckey_on) | |
1026 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND); | |
1027 else | |
1028 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_TRUE|CMP_MIX_AND); | |
1029 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
1030 return(0); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
1031 } |