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