Mercurial > mplayer.hg
annotate vidix/savage_vid.c @ 23011:365eef1fc4f0
Disable caching of rotated glyphs.
The following commits will add perspective distortion to the glyphs rotated
with \frx and \fry. Somewhere along the way correct caching of such glyphs
will become impossible, but in the end everything will be fine.
author | eugeni |
---|---|
date | Fri, 20 Apr 2007 22:49:48 +0000 |
parents | f34e5d778267 |
children | 82216ef041e0 |
rev | line source |
---|---|
22850 | 1 /* |
2 Driver for S3 Savage Series | |
3 | |
4 Copyright (C) 2004 by Reza Jelveh | |
5 | |
6 Based on the X11 driver and nvidia vid | |
7 | |
8 Thanks to Alex Deucher for Support | |
9 | |
10 This program is free software; you can redistribute it and/or modify | |
11 it under the terms of the GNU General Public License as published by | |
12 the Free Software Foundation; either version 2 of the License, or | |
13 (at your option) any later version. | |
14 | |
15 This program is distributed in the hope that it will be useful, | |
16 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 GNU General Public License for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
21 along with this program; if not, write to the Free Software | |
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
23 | |
24 Changes: | |
25 2004-11-09 | |
26 Initial version | |
27 | |
28 To Do: | |
29 | |
30 */ | |
31 | |
32 | |
33 #include <errno.h> | |
34 #include <stdio.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 #include <inttypes.h> | |
38 #include <unistd.h> | |
39 #include <math.h> | |
40 | |
41 #include "vidix.h" | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
42 #include "vidixlib.h" |
22850 | 43 #include "fourcc.h" |
22901 | 44 #include "dha.h" |
22900
a9e111b88c4a
merged libdha and libvidix, moved all files from libdha to vidix directory
ben
parents:
22868
diff
changeset
|
45 #include "pci_ids.h" |
a9e111b88c4a
merged libdha and libvidix, moved all files from libdha to vidix directory
ben
parents:
22868
diff
changeset
|
46 #include "pci_names.h" |
22905 | 47 #include "config.h" |
22850 | 48 |
49 #include "savage_regs.h" | |
50 | |
51 | |
52 #define VF_STREAMS_ON 0x0001 | |
53 #define BASE_PAD 0xf | |
54 #define FRAMEBUFFER_SIZE 1024*2000*4 | |
55 /************************************** | |
56 S3 streams processor | |
57 **************************************/ | |
58 | |
59 #define EXT_MISC_CTRL2 0x67 | |
60 | |
61 /* New streams */ | |
62 | |
63 /* CR67[2] = 1 : enable stream 1 */ | |
64 #define ENABLE_STREAM1 0x04 | |
65 /* CR67[1] = 1 : enable stream 2 */ | |
66 #define ENABLE_STREAM2 0x02 | |
67 /* mask to clear CR67[2,1] */ | |
68 #define NO_STREAMS 0xF9 | |
69 /* CR67[3] = 1 : Mem-mapped regs */ | |
70 #define USE_MM_FOR_PRI_STREAM 0x08 | |
71 | |
72 #define HDM_SHIFT 16 | |
73 #define HDSCALE_4 (2 << HDM_SHIFT) | |
74 #define HDSCALE_8 (3 << HDM_SHIFT) | |
75 #define HDSCALE_16 (4 << HDM_SHIFT) | |
76 #define HDSCALE_32 (5 << HDM_SHIFT) | |
77 #define HDSCALE_64 (6 << HDM_SHIFT) | |
78 | |
79 /* Old Streams */ | |
80 | |
81 #define ENABLE_STREAMS_OLD 0x0c | |
82 #define NO_STREAMS_OLD 0xf3 | |
83 /* CR69[0] = 1 : Mem-mapped regs */ | |
84 #define USE_MM_FOR_PRI_STREAM_OLD 0x01 | |
85 | |
86 void SavageStreamsOn(void); | |
87 | |
88 /* | |
89 * There are two different streams engines used in the Savage line. | |
90 * The old engine is in the 3D, 4, Pro, and Twister. | |
91 * The new engine is in the 2000, MX, IX, and Super. | |
92 */ | |
93 | |
94 | |
95 /* streams registers for old engine */ | |
96 #define PSTREAM_CONTROL_REG 0x8180 | |
97 #define COL_CHROMA_KEY_CONTROL_REG 0x8184 | |
98 #define SSTREAM_CONTROL_REG 0x8190 | |
99 #define CHROMA_KEY_UPPER_BOUND_REG 0x8194 | |
100 #define SSTREAM_STRETCH_REG 0x8198 | |
101 #define COLOR_ADJUSTMENT_REG 0x819C | |
102 #define BLEND_CONTROL_REG 0x81A0 | |
103 #define PSTREAM_FBADDR0_REG 0x81C0 | |
104 #define PSTREAM_FBADDR1_REG 0x81C4 | |
105 #define PSTREAM_STRIDE_REG 0x81C8 | |
106 #define DOUBLE_BUFFER_REG 0x81CC | |
107 #define SSTREAM_FBADDR0_REG 0x81D0 | |
108 #define SSTREAM_FBADDR1_REG 0x81D4 | |
109 #define SSTREAM_STRIDE_REG 0x81D8 | |
110 #define SSTREAM_VSCALE_REG 0x81E0 | |
111 #define SSTREAM_VINITIAL_REG 0x81E4 | |
112 #define SSTREAM_LINES_REG 0x81E8 | |
113 #define STREAMS_FIFO_REG 0x81EC | |
114 #define PSTREAM_WINDOW_START_REG 0x81F0 | |
115 #define PSTREAM_WINDOW_SIZE_REG 0x81F4 | |
116 #define SSTREAM_WINDOW_START_REG 0x81F8 | |
117 #define SSTREAM_WINDOW_SIZE_REG 0x81FC | |
118 #define FIFO_CONTROL 0x8200 | |
119 #define PSTREAM_FBSIZE_REG 0x8300 | |
120 #define SSTREAM_FBSIZE_REG 0x8304 | |
121 #define SSTREAM_FBADDR2_REG 0x8308 | |
122 | |
123 #define OS_XY(x,y) (((x+1)<<16)|(y+1)) | |
124 #define OS_WH(x,y) (((x-1)<<16)|(y)) | |
125 | |
126 #define PCI_COMMAND_MEM 0x2 | |
127 #define MAX_FRAMES 3 | |
128 /** | |
129 * @brief Information on PCI device. | |
130 */ | |
131 pciinfo_t pci_info; | |
132 | |
133 uint8_t *vio; | |
134 uint8_t mclk_save[3]; | |
135 | |
136 #define outb(reg,val) OUTPORT8(reg,val) | |
137 #define inb(reg) INPORT8(reg) | |
138 #define outw(reg,val) OUTPORT16(reg,val) | |
139 #define inw(reg) INPORT16(reg) | |
140 #define outl(reg,val) OUTPORT32(reg,val) | |
141 #define inl(reg) INPORT32(reg) | |
142 | |
143 | |
144 /* | |
145 * PCI-Memory IO access macros. | |
146 */ | |
147 #define VID_WR08(p,i,val) (((uint8_t *)(p))[(i)]=(val)) | |
148 #define VID_RD08(p,i) (((uint8_t *)(p))[(i)]) | |
149 | |
150 #define VID_WR32(p,i,val) (((uint32_t *)(p))[(i)/4]=(val)) | |
151 #define VID_RD32(p,i) (((uint32_t *)(p))[(i)/4]) | |
152 | |
153 #ifndef USE_RMW_CYCLES | |
154 /* | |
155 * Can be used to inhibit READ-MODIFY-WRITE cycles. On by default. | |
156 */ | |
157 | |
158 #define MEM_BARRIER() __asm__ __volatile__ ("" : : : "memory") | |
159 | |
160 #undef VID_WR08 | |
161 #define VID_WR08(p,i,val) ({ MEM_BARRIER(); ((uint8_t *)(p))[(i)]=(val); }) | |
162 #undef VID_RD08 | |
163 #define VID_RD08(p,i) ({ MEM_BARRIER(); ((uint8_t *)(p))[(i)]; }) | |
164 | |
165 #undef VID_WR16 | |
166 #define VID_WR16(p,i,val) ({ MEM_BARRIER(); ((uint16_t *)(p))[(i)/2]=(val); }) | |
167 #undef VID_RD16 | |
168 #define VID_RD16(p,i) ({ MEM_BARRIER(); ((uint16_t *)(p))[(i)/2]; }) | |
169 | |
170 #undef VID_WR32 | |
171 #define VID_WR32(p,i,val) ({ MEM_BARRIER(); ((uint32_t *)(p))[(i)/4]=(val); }) | |
172 #undef VID_RD32 | |
173 #define VID_RD32(p,i) ({ MEM_BARRIER(); ((uint32_t *)(p))[(i)/4]; }) | |
174 #endif /* USE_RMW_CYCLES */ | |
175 | |
176 #define VID_AND32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)&(val)) | |
177 #define VID_OR32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)|(val)) | |
178 #define VID_XOR32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)^(val)) | |
179 | |
180 | |
181 /* from x driver */ | |
182 | |
183 #define VGAIN8(addr) VID_RD08(info->control_base+0x8000, addr) | |
184 #define VGAIN16(addr) VID_RD16(info->control_base+0x8000, addr) | |
185 #define VGAIN(addr) VID_RD32(info->control_base+0x8000, addr) | |
186 | |
187 #define VGAOUT8(addr,val) VID_WR08(info->control_base+0x8000, addr, val) | |
188 #define VGAOUT16(addr,val) VID_WR16(info->control_base+0x8000, addr, val) | |
189 #define VGAOUT(addr,val) VID_WR32(info->control_base+0x8000, addr, val) | |
190 | |
191 #define INREG(addr) VID_RD32(info->control_base, addr) | |
192 #define OUTREG(addr,val) VID_WR32(info->control_base, addr, val) | |
193 #define INREG8(addr) VID_RD08(info->control_base, addr) | |
194 #define OUTREG8(addr,val) VID_WR08(info->control_base, addr, val) | |
195 #define INREG16(addr) VID_RD16(info->control_base, addr) | |
196 #define OUTREG16(addr,val) VID_WR16(info->control_base, addr, val) | |
197 | |
198 #define ALIGN_TO(v, n) (((v) + (n-1)) & ~(n-1)) | |
199 | |
200 | |
201 void debugout(unsigned int addr, unsigned int val); | |
202 | |
203 | |
204 struct savage_chip { | |
205 volatile uint32_t *PMC; /* general control */ | |
206 volatile uint32_t *PME; /* multimedia port */ | |
207 volatile uint32_t *PFB; /* framebuffer control */ | |
208 volatile uint32_t *PVIDEO; /* overlay control */ | |
209 volatile uint8_t *PCIO; /* SVGA (CRTC, ATTR) registers */ | |
210 volatile uint8_t *PVIO; /* SVGA (MISC, GRAPH, SEQ) registers */ | |
211 volatile uint32_t *PRAMIN; /* instance memory */ | |
212 volatile uint32_t *PRAMHT; /* hash table */ | |
213 volatile uint32_t *PRAMFC; /* fifo context table */ | |
214 volatile uint32_t *PRAMRO; /* fifo runout table */ | |
215 volatile uint32_t *PFIFO; /* fifo control region */ | |
216 volatile uint32_t *FIFO; /* fifo channels (USER) */ | |
217 volatile uint32_t *PGRAPH; /* graphics engine */ | |
218 | |
219 int arch; /* compatible NV_ARCH_XX define */ | |
220 unsigned long fbsize; /* framebuffer size */ | |
221 void (* lock) (struct savage_chip *, int); | |
222 }; | |
223 typedef struct savage_chip savage_chip; | |
224 | |
225 | |
226 struct savage_info { | |
227 unsigned int use_colorkey; | |
228 unsigned int colorkey; /* saved xv colorkey*/ | |
229 unsigned int vidixcolorkey; /*currently used colorkey*/ | |
230 unsigned int depth; | |
231 unsigned int bpp; | |
232 unsigned int videoFlags; | |
233 unsigned int format; | |
234 unsigned int pitch; | |
235 unsigned int blendBase; | |
236 unsigned int lastKnownPitch; | |
237 unsigned int displayWidth, displayHeight; | |
238 unsigned int brightness,hue,saturation,contrast; | |
239 unsigned int src_w,src_h; | |
240 unsigned int drw_w,drw_h; /*scaled width && height*/ | |
241 unsigned int wx,wy; /*window x && y*/ | |
242 unsigned int screen_x; /*screen width*/ | |
243 unsigned int screen_y; /*screen height*/ | |
244 unsigned long buffer_size; /* size of the image buffer */ | |
245 struct savage_chip chip; /* NV architecture structure */ | |
246 void* video_base; /* virtual address of control region */ | |
247 void* control_base; /* virtual address of fb region */ | |
248 unsigned long picture_base; /* direct pointer to video picture */ | |
249 unsigned long picture_offset; /* offset of video picture in frame buffer */ | |
250 // struct savage_dma dma; /* DMA structure */ | |
251 unsigned int cur_frame; | |
252 unsigned int num_frames; /* number of buffers */ | |
253 int bps; /* bytes per line */ | |
254 void (*SavageWaitIdle) (); | |
255 void (*SavageWaitFifo) (int space); | |
256 }; | |
257 typedef struct savage_info savage_info; | |
258 | |
259 | |
260 static savage_info* info; | |
261 | |
262 | |
263 /** | |
264 * @brief Unichrome driver vidix capabilities. | |
265 */ | |
266 static vidix_capability_t savage_cap = { | |
267 "Savage/ProSavage/Twister vidix", | |
268 "Reza Jelveh <reza.jelveh@tuhh.de>", | |
269 TYPE_OUTPUT, | |
270 {0, 0, 0, 0}, | |
271 4096, | |
272 4096, | |
273 4, | |
274 4, | |
275 -1, | |
276 FLAG_UPSCALER | FLAG_DOWNSCALER, | |
277 VENDOR_S3_INC, | |
278 -1, | |
279 {0, 0, 0, 0} | |
280 }; | |
281 | |
282 struct savage_cards { | |
283 unsigned short chip_id; | |
284 unsigned short arch; | |
285 }; | |
286 | |
287 | |
288 static | |
289 unsigned int GetBlendForFourCC( int id ) | |
290 { | |
291 switch( id ) { | |
292 case IMGFMT_YUY2: | |
293 case IMGFMT_YV12: | |
294 case IMGFMT_I420: | |
295 return 1; | |
296 case IMGFMT_Y211: | |
297 return 4; | |
298 case IMGFMT_RGB15: | |
299 return 3; | |
300 case IMGFMT_RGB16: | |
301 return 5; | |
302 default: | |
303 return 0; | |
304 } | |
305 } | |
306 | |
307 /** | |
308 * @brief list of card IDs compliant with the Unichrome driver . | |
309 */ | |
310 static struct savage_cards savage_card_ids[] = { | |
311 /*[ProSavage PN133] AGP4X VGA Controller (Twister)*/ | |
312 { PCI_CHIP_S3TWISTER_P, S3_PROSAVAGE }, | |
313 /*[ProSavage KN133] AGP4X VGA Controller (TwisterK)*/ | |
314 { PCI_CHIP_S3TWISTER_K, S3_PROSAVAGE }, | |
315 /*ProSavage DDR*/ | |
316 { PCI_CHIP_PROSAVAGE_DDR , S3_PROSAVAGE }, | |
317 /*[ProSavageDDR P4M266 K] */ | |
318 { PCI_CHIP_PROSAVAGE_DDRK , S3_PROSAVAGE }, | |
319 }; | |
320 | |
321 static void SavageSetColorOld(void) | |
322 { | |
323 | |
324 | |
325 if( | |
326 (info->format == IMGFMT_RGB15) || | |
327 (info->format == IMGFMT_RGB16) | |
328 ) | |
329 { | |
330 OUTREG( COLOR_ADJUSTMENT_REG, 0 ); | |
331 } | |
332 else | |
333 { | |
334 /* Change 0..255 into 0..15 */ | |
335 long sat = info->saturation * 16 / 256; | |
336 double hue = info->hue * 0.017453292; | |
337 unsigned long hs1 = ((long)(sat * cos(hue))) & 0x1f; | |
338 unsigned long hs2 = ((long)(sat * sin(hue))) & 0x1f; | |
339 | |
340 OUTREG( COLOR_ADJUSTMENT_REG, | |
341 0x80008000 | | |
342 (info->brightness + 128) | | |
343 ((info->contrast & 0xf8) << (12-7)) | | |
344 (hs1 << 16) | | |
345 (hs2 << 24) | |
346 ); | |
347 debugout( COLOR_ADJUSTMENT_REG, | |
348 0x80008000 | | |
349 (info->brightness + 128) | | |
350 ((info->contrast & 0xf8) << (12-7)) | | |
351 (hs1 << 16) | | |
352 (hs2 << 24) | |
353 ); | |
354 | |
355 } | |
356 } | |
357 | |
358 static void SavageSetColorKeyOld(void) | |
359 { | |
360 int red, green, blue; | |
361 | |
362 /* Here, we reset the colorkey and all the controls. */ | |
363 | |
364 red = (info->vidixcolorkey & 0x00FF0000) >> 16; | |
365 green = (info->vidixcolorkey & 0x0000FF00) >> 8; | |
366 blue = info->vidixcolorkey & 0x000000FF; | |
367 | |
368 if( !info->vidixcolorkey ) { | |
369 printf("SavageSetColorKey disabling colorkey\n"); | |
370 OUTREG( COL_CHROMA_KEY_CONTROL_REG, 0 ); | |
371 OUTREG( CHROMA_KEY_UPPER_BOUND_REG, 0 ); | |
372 OUTREG( BLEND_CONTROL_REG, 0 ); | |
373 } | |
374 else { | |
375 switch (info->depth) { | |
376 // FIXME: isnt fixed yet | |
377 case 8: | |
378 OUTREG( COL_CHROMA_KEY_CONTROL_REG, | |
379 0x37000000 | (info->vidixcolorkey & 0xFF) ); | |
380 OUTREG( CHROMA_KEY_UPPER_BOUND_REG, | |
381 0x00000000 | (info->vidixcolorkey & 0xFF) ); | |
382 break; | |
383 case 15: | |
384 /* 15 bpp 555 */ | |
385 red&=0x1f; | |
386 green&=0x1f; | |
387 blue&=0x1f; | |
388 OUTREG( COL_CHROMA_KEY_CONTROL_REG, | |
389 0x05000000 | (red<<19) | (green<<11) | (blue<<3) ); | |
390 OUTREG( CHROMA_KEY_UPPER_BOUND_REG, | |
391 0x00000000 | (red<<19) | (green<<11) | (blue<<3) ); | |
392 break; | |
393 case 16: | |
394 /* 16 bpp 565 */ | |
395 red&=0x1f; | |
396 green&=0x3f; | |
397 blue&=0x1f; | |
398 OUTREG( COL_CHROMA_KEY_CONTROL_REG, | |
399 0x16000000 | (red<<19) | (green<<10) | (blue<<3) ); | |
400 OUTREG( CHROMA_KEY_UPPER_BOUND_REG, | |
401 0x00020002 | (red<<19) | (green<<10) | (blue<<3) ); | |
402 break; | |
403 case 24: | |
404 /* 24 bpp 888 */ | |
405 OUTREG( COL_CHROMA_KEY_CONTROL_REG, | |
406 0x17000000 | (red<<16) | (green<<8) | (blue) ); | |
407 OUTREG( CHROMA_KEY_UPPER_BOUND_REG, | |
408 0x00000000 | (red<<16) | (green<<8) | (blue) ); | |
409 break; | |
410 } | |
411 | |
412 /* We use destination colorkey */ | |
413 OUTREG( BLEND_CONTROL_REG, 0x05000000 ); | |
414 } | |
415 } | |
416 | |
417 | |
418 static void | |
419 SavageDisplayVideoOld(void) | |
420 { | |
421 int vgaCRIndex, vgaCRReg, vgaIOBase; | |
422 unsigned int ssControl; | |
423 int cr92; | |
424 | |
425 | |
426 vgaIOBase = 0x3d0; | |
427 vgaCRIndex = vgaIOBase + 4; | |
428 vgaCRReg = vgaIOBase + 5; | |
429 | |
430 // if( psav->videoFourCC != id ) | |
431 // SavageStreamsOff(pScrn); | |
432 | |
433 if( !info->videoFlags & VF_STREAMS_ON ) | |
434 { | |
435 SavageStreamsOn(); | |
436 // SavageResetVideo(); | |
437 SavageSetColorOld(); | |
438 SavageSetColorKeyOld(); | |
439 } | |
440 | |
441 | |
442 | |
443 | |
444 /* Set surface format. */ | |
445 | |
446 OUTREG(SSTREAM_CONTROL_REG,GetBlendForFourCC(info->format) << 24 | info->src_w); | |
447 | |
448 debugout(SSTREAM_CONTROL_REG,GetBlendForFourCC(info->format) << 24 | info->src_w); | |
449 | |
450 /* Calculate horizontal scale factor. */ | |
451 | |
452 //FIXME: enable scaling | |
453 OUTREG(SSTREAM_STRETCH_REG, (info->src_w << 15) / info->drw_w ); | |
454 // debugout(SSTREAM_STRETCH_REG, 1 << 15); | |
455 | |
456 OUTREG(SSTREAM_LINES_REG, info->src_h ); | |
457 debugout(SSTREAM_LINES_REG, info->src_h ); | |
458 | |
459 | |
460 OUTREG(SSTREAM_VINITIAL_REG, 0 ); | |
461 debugout(SSTREAM_VINITIAL_REG, 0 ); | |
462 /* Calculate vertical scale factor. */ | |
463 | |
464 // OUTREG(SSTREAM_VSCALE_REG, 1 << 15); | |
465 OUTREG(SSTREAM_VSCALE_REG, VSCALING(info->src_h,info->drw_h) ); | |
466 debugout(SSTREAM_VSCALE_REG, VSCALING(info->src_h,info->drw_h) ); | |
467 // OUTREG(SSTREAM_VSCALE_REG, (info->src_h << 15) / info->drw_h ); | |
468 | |
469 /* Set surface location and stride. */ | |
470 | |
471 OUTREG(SSTREAM_FBADDR0_REG, info->picture_offset ); | |
472 debugout(SSTREAM_FBADDR0_REG, info->picture_offset ); | |
473 | |
474 OUTREG(SSTREAM_FBADDR1_REG, 0 ); | |
475 debugout(SSTREAM_FBADDR1_REG, 0 ); | |
476 | |
477 OUTREG(SSTREAM_STRIDE_REG, info->pitch ); | |
478 debugout(SSTREAM_STRIDE_REG, info->pitch ); | |
479 | |
480 OUTREG(SSTREAM_WINDOW_START_REG, OS_XY(info->wx, info->wy) ); | |
481 debugout(SSTREAM_WINDOW_START_REG, OS_XY(info->wx, info->wy) ); | |
482 OUTREG(SSTREAM_WINDOW_SIZE_REG, OS_WH(info->drw_w, info->drw_h) ); | |
483 debugout(SSTREAM_WINDOW_SIZE_REG, OS_WH(info->drw_w, info->drw_h) ); | |
484 | |
485 | |
486 | |
487 ssControl = 0; | |
488 | |
489 if( info->src_w > (info->drw_w << 1) ) | |
490 { | |
491 /* BUGBUG shouldn't this be >=? */ | |
492 if( info->src_w <= (info->drw_w << 2) ) | |
493 ssControl |= HDSCALE_4; | |
494 else if( info->src_w > (info->drw_w << 3) ) | |
495 ssControl |= HDSCALE_8; | |
496 else if( info->src_w > (info->drw_w << 4) ) | |
497 ssControl |= HDSCALE_16; | |
498 else if( info->src_w > (info->drw_w << 5) ) | |
499 ssControl |= HDSCALE_32; | |
500 else if( info->src_w > (info->drw_w << 6) ) | |
501 ssControl |= HDSCALE_64; | |
502 } | |
503 | |
504 ssControl |= info->src_w; | |
505 ssControl |= (1 << 24); | |
506 | |
507 //FIXME: enable scaling | |
508 OUTREG(SSTREAM_CONTROL_REG, ssControl); | |
509 debugout(SSTREAM_CONTROL_REG, ssControl); | |
510 | |
511 // FIXME: this should actually be enabled | |
512 | |
513 info->pitch = (info->pitch + 7) / 8; | |
514 VGAOUT8(vgaCRIndex, 0x92); | |
515 cr92 = VGAIN8(vgaCRReg); | |
516 VGAOUT8(vgaCRReg, (cr92 & 0x40) | (info->pitch >> 8) | 0x80); | |
517 VGAOUT8(vgaCRIndex, 0x93); | |
518 VGAOUT8(vgaCRReg, info->pitch); | |
519 OUTREG(STREAMS_FIFO_REG, 2 | 25 << 5 | 32 << 11); | |
520 | |
521 | |
522 | |
523 | |
524 } | |
525 | |
526 static void SavageInitStreamsOld(void) | |
527 { | |
528 /*unsigned long jDelta;*/ | |
529 unsigned long format = 0; | |
530 | |
531 /* | |
532 * For the OLD streams engine, several of these registers | |
533 * cannot be touched unless streams are on. Seems backwards to me; | |
534 * I'd want to set 'em up, then cut 'em loose. | |
535 */ | |
536 | |
537 | |
538 /*jDelta = pScrn->displayWidth * (pScrn->bitsPerPixel + 7) / 8;*/ | |
539 switch( info->depth ) { | |
540 case 8: format = 0 << 24; break; | |
541 case 15: format = 3 << 24; break; | |
542 case 16: format = 5 << 24; break; | |
543 case 24: format = 7 << 24; break; | |
544 } | |
545 #warning enable this again | |
546 OUTREG(PSTREAM_FBSIZE_REG, | |
547 info->screen_y * info->screen_x * (info->bpp >> 3)); | |
548 | |
549 OUTREG( PSTREAM_WINDOW_START_REG, OS_XY(0,0) ); | |
550 OUTREG( PSTREAM_WINDOW_SIZE_REG, OS_WH(info->screen_x, info->screen_y) ); | |
551 OUTREG( PSTREAM_FBADDR1_REG, 0 ); | |
552 /*OUTREG( PSTREAM_STRIDE_REG, jDelta );*/ | |
553 OUTREG( PSTREAM_CONTROL_REG, format ); | |
554 OUTREG( PSTREAM_FBADDR0_REG, 0 ); | |
555 | |
556 /*OUTREG( PSTREAM_FBSIZE_REG, jDelta * pScrn->virtualY >> 3 );*/ | |
557 | |
558 OUTREG( COL_CHROMA_KEY_CONTROL_REG, 0 ); | |
559 OUTREG( SSTREAM_CONTROL_REG, 0 ); | |
560 OUTREG( CHROMA_KEY_UPPER_BOUND_REG, 0 ); | |
561 OUTREG( SSTREAM_STRETCH_REG, 0 ); | |
562 OUTREG( COLOR_ADJUSTMENT_REG, 0 ); | |
563 OUTREG( BLEND_CONTROL_REG, 1 << 24 ); | |
564 OUTREG( DOUBLE_BUFFER_REG, 0 ); | |
565 OUTREG( SSTREAM_FBADDR0_REG, 0 ); | |
566 OUTREG( SSTREAM_FBADDR1_REG, 0 ); | |
567 OUTREG( SSTREAM_FBADDR2_REG, 0 ); | |
568 OUTREG( SSTREAM_FBSIZE_REG, 0 ); | |
569 OUTREG( SSTREAM_STRIDE_REG, 0 ); | |
570 OUTREG( SSTREAM_VSCALE_REG, 0 ); | |
571 OUTREG( SSTREAM_LINES_REG, 0 ); | |
572 OUTREG( SSTREAM_VINITIAL_REG, 0 ); | |
573 #warning is this needed? | |
574 OUTREG( SSTREAM_WINDOW_START_REG, OS_XY(0xfffe, 0xfffe) ); | |
575 OUTREG( SSTREAM_WINDOW_SIZE_REG, OS_WH(10,2) ); | |
576 | |
577 } | |
578 | |
579 void | |
580 SavageStreamsOn(void) | |
581 { | |
582 unsigned char jStreamsControl; | |
583 unsigned short vgaCRIndex = 0x3d0 + 4; | |
584 unsigned short vgaCRReg = 0x3d0 + 5; | |
585 | |
586 // xf86ErrorFVerb(STREAMS_TRACE, "SavageStreamsOn\n" ); | |
587 | |
588 /* Sequence stolen from streams.c in M7 NT driver */ | |
589 | |
590 | |
591 enable_app_io (); | |
592 | |
593 /* Unlock extended registers. */ | |
594 | |
595 /* FIXME: it looks like mmaped io is broken with vgaout16 */ | |
596 VGAOUT16(vgaCRIndex, 0x4838 ); | |
597 VGAOUT16(vgaCRIndex, 0xa039); | |
598 VGAOUT16(0x3c4, 0x0608); | |
599 | |
600 | |
601 | |
602 VGAOUT8( vgaCRIndex, EXT_MISC_CTRL2 ); | |
603 | |
604 if( S3_SAVAGE_MOBILE_SERIES(info->chip.arch) ) | |
605 { | |
606 // SavageInitStreamsNew( pScrn ); | |
607 | |
608 jStreamsControl = VGAIN8( vgaCRReg ) | ENABLE_STREAM1; | |
609 | |
610 /* Wait for VBLANK. */ | |
611 VerticalRetraceWait(); | |
612 /* Fire up streams! */ | |
613 VGAOUT16( vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 ); | |
614 /* These values specify brightness, contrast, saturation and hue. */ | |
615 OUTREG( SEC_STREAM_COLOR_CONVERT1, 0x0000C892 ); | |
616 OUTREG( SEC_STREAM_COLOR_CONVERT2, 0x00039F9A ); | |
617 OUTREG( SEC_STREAM_COLOR_CONVERT3, 0x01F1547E ); | |
618 } | |
619 else if (info->chip.arch == S3_SAVAGE2000) | |
620 { | |
621 // SavageInitStreams2000( pScrn ); | |
622 | |
623 jStreamsControl = VGAIN8( vgaCRReg ) | ENABLE_STREAM1; | |
624 | |
625 /* Wait for VBLANK. */ | |
626 VerticalRetraceWait(); | |
627 /* Fire up streams! */ | |
628 VGAOUT16( vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 ); | |
629 /* These values specify brightness, contrast, saturation and hue. */ | |
630 OUTREG( SEC_STREAM_COLOR_CONVERT0_2000, 0x0000C892 ); | |
631 OUTREG( SEC_STREAM_COLOR_CONVERT1_2000, 0x00033400 ); | |
632 OUTREG( SEC_STREAM_COLOR_CONVERT2_2000, 0x000001CF ); | |
633 OUTREG( SEC_STREAM_COLOR_CONVERT3_2000, 0x01F1547E ); | |
634 } | |
635 else | |
636 { | |
637 jStreamsControl = VGAIN8( vgaCRReg ) | ENABLE_STREAMS_OLD; | |
638 | |
639 /* Wait for VBLANK. */ | |
640 | |
641 VerticalRetraceWait(); | |
642 | |
643 /* Fire up streams! */ | |
644 | |
645 VGAOUT16( vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 ); | |
646 | |
647 SavageInitStreamsOld( ); | |
648 } | |
649 | |
650 /* Wait for VBLANK. */ | |
651 | |
652 VerticalRetraceWait(); | |
653 | |
654 /* Turn on secondary stream TV flicker filter, once we support TV. */ | |
655 | |
656 /* SR70 |= 0x10 */ | |
657 | |
658 info->videoFlags |= VF_STREAMS_ON; | |
659 | |
660 } | |
661 | |
662 | |
663 | |
664 | |
665 static void savage_getscreenproperties(struct savage_info *info){ | |
666 unsigned char bpp=0; | |
667 | |
668 uint32_t vgaIOBase, vgaCRIndex, vgaCRReg; | |
669 | |
670 vgaIOBase = 0x3d0; | |
671 vgaCRIndex = vgaIOBase + 4; | |
672 vgaCRReg = vgaIOBase + 5; | |
673 | |
674 | |
675 /* a little reversed from x driver source code */ | |
676 VGAOUT8(vgaCRIndex, 0x67); | |
677 bpp = VGAIN8(vgaCRReg); | |
678 | |
679 | |
680 switch (bpp&0xf0) { | |
681 case 0x00: | |
682 case 0x10: | |
683 info->depth=8; | |
684 info->bpp=8; | |
685 break; | |
686 case 0x20: | |
687 case 0x30: | |
688 info->depth=15; | |
689 info->bpp=16; | |
690 break; | |
691 case 0x40: | |
692 case 0x50: | |
693 info->depth=16; | |
694 info->bpp=16; | |
695 break; | |
696 case 0x70: | |
697 case 0xd0: | |
698 info->depth=24; | |
699 info->bpp=32; | |
700 break; | |
701 | |
702 | |
703 } | |
704 | |
705 | |
706 VGAOUT8(vgaCRIndex, 0x1); | |
707 info->screen_x = (1 + VGAIN8(vgaCRReg)) <<3; | |
708 /*get screen height*/ | |
709 /* get first 8 bits in VT_DISPLAY_END*/ | |
710 VGAOUT8(0x03D4, 0x12); | |
711 info->screen_y = VGAIN8(0x03D5); | |
712 VGAOUT8(0x03D4,0x07); | |
713 /* get 9th bit in CRTC_OVERFLOW*/ | |
714 info->screen_y |= (VGAIN8(0x03D5) &0x02)<<7; | |
715 /* and the 10th in CRTC_OVERFLOW*/ | |
716 info->screen_y |=(VGAIN8(0x03D5) &0x40)<<3; | |
717 ++info->screen_y; | |
718 | |
719 printf("screen_x = %d, screen_y = %d, bpp = %d\n",info->screen_x,info->screen_y,info->bpp); | |
720 } | |
721 | |
722 | |
723 static void SavageStreamsOff(void) | |
724 { | |
725 unsigned char jStreamsControl; | |
726 unsigned short vgaCRIndex = 0x3d0 + 4; | |
727 unsigned short vgaCRReg = 0x3d0 + 5; | |
728 | |
729 | |
730 /* Unlock extended registers. */ | |
731 | |
732 VGAOUT16(vgaCRIndex, 0x4838); | |
733 VGAOUT16(vgaCRIndex, 0xa039); | |
734 VGAOUT16(0x3c4, 0x0608); | |
735 | |
736 VGAOUT8( vgaCRIndex, EXT_MISC_CTRL2 ); | |
737 if( S3_SAVAGE_MOBILE_SERIES(info->chip.arch) || | |
738 (info->chip.arch == S3_SUPERSAVAGE) || | |
739 (info->chip.arch == S3_SAVAGE2000) ) | |
740 jStreamsControl = VGAIN8( vgaCRReg ) & NO_STREAMS; | |
741 else | |
742 jStreamsControl = VGAIN8( vgaCRReg ) & NO_STREAMS_OLD; | |
743 | |
744 /* Wait for VBLANK. */ | |
745 | |
746 VerticalRetraceWait(); | |
747 | |
748 /* Kill streams. */ | |
749 | |
750 VGAOUT16(vgaCRIndex, (jStreamsControl << 8) | EXT_MISC_CTRL2 ); | |
751 | |
752 VGAOUT16(vgaCRIndex, 0x0093 ); | |
753 VGAOUT8( vgaCRIndex, 0x92 ); | |
754 VGAOUT8( vgaCRReg, VGAIN8(vgaCRReg) & 0x40 ); | |
755 | |
756 info->videoFlags &= ~VF_STREAMS_ON; | |
757 } | |
758 | |
759 /** | |
760 * @brief Find chip index in Unichrome compliant devices list. | |
761 * | |
762 * @param chip_id PCI device ID. | |
763 * | |
764 * @returns index position in savage_card_ids if successful. | |
765 * -1 if chip_id is not a compliant chipset ID. | |
766 */ | |
767 | |
768 static int find_chip(unsigned chip_id){ | |
769 unsigned i; | |
770 for(i = 0;i < sizeof(savage_card_ids)/sizeof(struct savage_cards);i++) | |
771 { | |
772 if(chip_id == savage_card_ids[i].chip_id)return i; | |
773 } | |
774 return -1; | |
775 } | |
776 | |
777 /** | |
778 * @brief Probe hardware to find some useable chipset. | |
779 * | |
780 * @param verbose specifies verbose level. | |
781 * @param force specifies force mode : driver should ignore | |
782 * device_id (danger but useful for new devices) | |
783 * | |
784 * @returns 0 if it can handle something in PC. | |
785 * a negative error code otherwise. | |
786 */ | |
787 | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
788 static int savage_probe(int verbose, int force){ |
22850 | 789 pciinfo_t lst[MAX_PCI_DEVICES]; |
790 unsigned i,num_pci; | |
791 int err; | |
792 | |
793 if (force) | |
794 printf("[savage_vid]: warning: forcing not supported yet!\n"); | |
795 err = pci_scan(lst,&num_pci); | |
796 if(err){ | |
797 printf("[savage_vid] Error occurred during pci scan: %s\n",strerror(err)); | |
798 return err; | |
799 } | |
800 else { | |
801 err = ENXIO; | |
802 for(i=0; i < num_pci; i++){ | |
803 if(lst[i].vendor == VENDOR_S3_INC) { | |
804 int idx; | |
805 const char *dname; | |
806 idx = find_chip(lst[i].device); | |
807 if(idx == -1) | |
808 continue; | |
809 dname = pci_device_name(lst[i].vendor, lst[i].device); | |
810 dname = dname ? dname : "Unknown chip"; | |
811 printf("[savage_vid] Found chip: %s\n", dname); | |
812 // FIXME: whats wrong here? | |
813 if ((lst[i].command & PCI_COMMAND_IO ) == 0){ | |
814 printf("[savage_vid] Device is disabled, ignoring\n"); | |
815 continue; | |
816 } | |
817 savage_cap.device_id = lst[i].device; | |
818 err = 0; | |
819 memcpy(&pci_info, &lst[i], sizeof(pciinfo_t)); | |
820 break; | |
821 } | |
822 } | |
823 } | |
824 if(err && verbose) printf("[savage_vid] Can't find chip\n"); | |
825 return err; | |
826 } | |
827 | |
828 /** | |
829 * @brief Initializes driver. | |
830 * | |
831 * @returns 0 if ok. | |
832 * a negative error code otherwise. | |
833 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
834 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
835 savage_init (void) |
22850 | 836 { |
837 int mtrr; | |
22868 | 838 unsigned char config1, tmp; |
22850 | 839 |
840 static unsigned char RamSavage3D[] = { 8, 4, 4, 2 }; | |
841 static unsigned char RamSavage4[] = { 2, 4, 8, 12, 16, 32, 64, 32 }; | |
842 static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 }; | |
843 static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 16, 2 }; | |
844 | |
22868 | 845 int videoRam; |
22850 | 846 |
847 uint32_t vgaIOBase, vgaCRIndex, vgaCRReg ; | |
848 | |
849 unsigned char val; | |
850 | |
851 vgaIOBase = 0x3d0; | |
852 vgaCRIndex = vgaIOBase + 4; | |
853 vgaCRReg = vgaIOBase + 5; | |
854 | |
855 fprintf(stderr, "vixInit enter \n"); | |
856 // //getc(stdin); | |
857 | |
858 info = calloc(1,sizeof(savage_info)); | |
859 | |
860 | |
861 /* need this if we want direct outb and inb access? */ | |
862 enable_app_io (); | |
863 | |
864 /* 12mb + 32kb ? */ | |
865 /* allocate some space for control registers */ | |
866 info->chip.arch = savage_card_ids[find_chip(pci_info.device)].arch; | |
867 | |
868 if (info->chip.arch == S3_SAVAGE3D) { | |
869 info->control_base = map_phys_mem(pci_info.base0+SAVAGE_NEWMMIO_REGBASE_S3, SAVAGE_NEWMMIO_REGSIZE); | |
870 } | |
871 else { | |
872 info->control_base = map_phys_mem(pci_info.base0+SAVAGE_NEWMMIO_REGBASE_S4, SAVAGE_NEWMMIO_REGSIZE); | |
873 } | |
874 | |
875 // info->chip.PCIO = (uint8_t *) (info->control_base + SAVAGE_NEWMMIO_VGABASE); | |
876 | |
877 // FIXME: enable mmio? | |
878 val = VGAIN8 (0x3c3); | |
879 VGAOUT8 (0x3c3, val | 0x01); | |
880 val = VGAIN8 (0x3cc); | |
881 VGAOUT8 (0x3c2, val | 0x01); | |
882 | |
883 if (info->chip.arch >= S3_SAVAGE4) | |
884 { | |
885 VGAOUT8 (0x3d4, 0x40); | |
886 val = VGAIN8 (0x3d5); | |
887 VGAOUT8 (0x3d5, val | 1); | |
888 } | |
889 | |
890 | |
891 | |
892 /* unprotect CRTC[0-7] */ | |
893 VGAOUT8(vgaCRIndex, 0x11); | |
894 tmp = VGAIN8(vgaCRReg); | |
895 // printf("$########## tmp = %d\n",tmp); | |
896 VGAOUT8(vgaCRReg, tmp & 0x7f); | |
897 | |
898 | |
899 /* unlock extended regs */ | |
900 VGAOUT16(vgaCRIndex, 0x4838); | |
901 VGAOUT16(vgaCRIndex, 0xa039); | |
902 VGAOUT16(0x3c4, 0x0608); | |
903 | |
904 VGAOUT8(vgaCRIndex, 0x40); | |
905 tmp = VGAIN8(vgaCRReg); | |
906 VGAOUT8(vgaCRReg, tmp & ~0x01); | |
907 | |
908 /* unlock sys regs */ | |
909 VGAOUT8(vgaCRIndex, 0x38); | |
910 VGAOUT8(vgaCRReg, 0x48); | |
911 | |
912 /* Unlock system registers. */ | |
913 VGAOUT16(vgaCRIndex, 0x4838); | |
914 | |
915 /* Next go on to detect amount of installed ram */ | |
916 | |
917 VGAOUT8(vgaCRIndex, 0x36); /* for register CR36 (CONFG_REG1), */ | |
918 config1 = VGAIN8(vgaCRReg); /* get amount of vram installed */ | |
919 | |
920 | |
921 switch( info->chip.arch ) { | |
922 case S3_SAVAGE3D: | |
923 videoRam = RamSavage3D[ (config1 & 0xC0) >> 6 ] * 1024; | |
924 break; | |
925 | |
926 case S3_SAVAGE4: | |
927 /* | |
928 * The Savage4 has one ugly special case to consider. On | |
929 * systems with 4 banks of 2Mx32 SDRAM, the BIOS says 4MB | |
930 * when it really means 8MB. Why do it the same when you | |
931 * can do it different... | |
932 */ | |
933 VGAOUT8(0x3d4, 0x68); /* memory control 1 */ | |
934 if( (VGAIN8(0x3d5) & 0xC0) == (0x01 << 6) ) | |
935 RamSavage4[1] = 8; | |
936 | |
937 /*FALLTHROUGH*/ | |
938 | |
939 case S3_SAVAGE2000: | |
940 videoRam = RamSavage4[ (config1 & 0xE0) >> 5 ] * 1024; | |
941 break; | |
942 | |
943 case S3_SAVAGE_MX: | |
944 videoRam = RamSavageMX[ (config1 & 0x0E) >> 1 ] * 1024; | |
945 break; | |
946 | |
947 case S3_PROSAVAGE: | |
948 videoRam = RamSavageNB[ (config1 & 0xE0) >> 5 ] * 1024; | |
949 break; | |
950 | |
951 default: | |
952 /* How did we get here? */ | |
953 videoRam = 0; | |
954 break; | |
955 } | |
956 | |
957 | |
958 printf("###### videoRam = %d\n",videoRam); | |
959 info->chip.fbsize = videoRam * 1024; | |
960 | |
961 | |
962 /* reset graphics engine to avoid memory corruption */ | |
963 /* VGAOUT8 (0x3d4, 0x66); | |
964 cr66 = VGAIN8 (0x3d5); | |
965 VGAOUT8 (0x3d5, cr66 | 0x02); | |
966 udelay (10000); | |
967 | |
968 VGAOUT8 (0x3d4, 0x66); | |
22868 | 969 VGAOUT8 (0x3d5, cr66 & ~0x02); */ // clear reset flag |
22850 | 970 /* udelay (10000); */ |
971 | |
972 /* This maps framebuffer @6MB, thus 2MB are left for video. */ | |
973 if (info->chip.arch == S3_SAVAGE3D) { | |
974 info->video_base = map_phys_mem(pci_info.base0, info->chip.fbsize); | |
975 info->picture_offset = 1024*768* 4 * ((info->chip.fbsize > 4194304)?2:1); | |
976 } | |
977 else { | |
978 info->video_base = map_phys_mem(pci_info.base1, info->chip.fbsize); | |
979 info->picture_offset = info->chip.fbsize - FRAMEBUFFER_SIZE; | |
980 // info->picture_offset = 1024*1024* 4 * 2; | |
981 } | |
22868 | 982 if ( info->video_base == NULL){ |
22850 | 983 printf("errno = %s\n", strerror(errno)); |
984 return -1; | |
985 } | |
986 | |
987 | |
988 info->picture_base = (uint32_t) info->video_base + info->picture_offset; | |
989 | |
990 if ( info->chip.arch == S3_SAVAGE3D ){ | |
991 mtrr = mtrr_set_type(pci_info.base0, info->chip.fbsize, MTRR_TYPE_WRCOMB); | |
992 } | |
993 else{ | |
994 mtrr = mtrr_set_type(pci_info.base1, info->chip.fbsize, MTRR_TYPE_WRCOMB); | |
995 } | |
996 | |
997 if (mtrr!= 0) | |
998 printf("[savage_vid] unable to setup MTRR: %s\n", strerror(mtrr)); | |
999 else | |
1000 printf("[savage_vid] MTRR set up\n"); | |
1001 | |
1002 /* This may trash your screen for resolutions greater than 1024x768, sorry. */ | |
1003 | |
1004 | |
1005 savage_getscreenproperties(info); | |
1006 // return -1; | |
1007 info->videoFlags = 0; | |
1008 | |
1009 SavageStreamsOn(); | |
1010 //getc(stdin); | |
1011 //FIXME ADD | |
1012 return 0; | |
1013 } | |
1014 | |
1015 /** | |
1016 * @brief Destroys driver. | |
1017 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1018 static void |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1019 savage_destroy (void) |
22850 | 1020 { |
1021 unmap_phys_mem(info->video_base, info->chip.fbsize); | |
1022 unmap_phys_mem(info->control_base, SAVAGE_NEWMMIO_REGSIZE); | |
1023 //FIXME ADD | |
1024 } | |
1025 | |
1026 /** | |
1027 * @brief Get chipset's hardware capabilities. | |
1028 * | |
1029 * @param to Pointer to the vidix_capability_t structure to be filled. | |
1030 * | |
1031 * @returns 0. | |
1032 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1033 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1034 savage_get_caps (vidix_capability_t * to) |
22850 | 1035 { |
1036 memcpy (to, &savage_cap, sizeof (vidix_capability_t)); | |
1037 return 0; | |
1038 } | |
1039 | |
1040 /** | |
1041 * @brief Report if the video FourCC is supported by hardware. | |
1042 * | |
1043 * @param fourcc input image format. | |
1044 * | |
1045 * @returns 1 if the fourcc is supported. | |
1046 * 0 otherwise. | |
1047 */ | |
1048 static int | |
1049 is_supported_fourcc (uint32_t fourcc) | |
1050 { | |
1051 switch (fourcc) | |
1052 { | |
1053 //FIXME: YV12 isnt working properly yet | |
1054 // case IMGFMT_YV12: | |
1055 // case IMGFMT_I420: | |
1056 case IMGFMT_UYVY: | |
1057 case IMGFMT_YVYU: | |
1058 case IMGFMT_YUY2: | |
1059 case IMGFMT_RGB15: | |
1060 case IMGFMT_RGB16: | |
1061 // case IMGFMT_BGR32: | |
1062 return 1; | |
1063 default: | |
1064 return 0; | |
1065 } | |
1066 } | |
1067 | |
1068 /** | |
1069 * @brief Try to configure video memory for given fourcc. | |
1070 * | |
1071 * @param to Pointer to the vidix_fourcc_t structure to be filled. | |
1072 * | |
1073 * @returns 0 if ok. | |
1074 * errno otherwise. | |
1075 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1076 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1077 savage_query_fourcc (vidix_fourcc_t * to) |
22850 | 1078 { |
1079 if (is_supported_fourcc (to->fourcc)) | |
1080 { | |
1081 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
1082 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
1083 VID_DEPTH_12BPP | VID_DEPTH_15BPP | | |
1084 VID_DEPTH_16BPP | VID_DEPTH_24BPP | VID_DEPTH_32BPP; | |
1085 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; | |
1086 return 0; | |
1087 } | |
1088 else | |
1089 to->depth = to->flags = 0; | |
1090 | |
1091 return ENOSYS; | |
1092 } | |
1093 | |
1094 /** | |
1095 * @brief Get the GrKeys | |
1096 * | |
1097 * @param grkey Pointer to the vidix_grkey_t structure to be filled by driver. | |
1098 * | |
1099 * @return 0. | |
1100 */ | |
1101 /*int | |
1102 vixGetGrKeys (vidix_grkey_t * grkey) | |
1103 { | |
1104 | |
1105 // if(info->d_width && info->d_height)savage_overlay_start(info,0); | |
1106 | |
1107 return (0); | |
1108 } | |
1109 * */ | |
1110 | |
1111 /** | |
1112 * @brief Set the GrKeys | |
1113 * | |
1114 * @param grkey Colorkey to be set. | |
1115 * | |
1116 * @return 0. | |
1117 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1118 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1119 savage_set_gkeys (const vidix_grkey_t * grkey) |
22850 | 1120 { |
1121 if (grkey->ckey.op == CKEY_FALSE) | |
1122 { | |
1123 info->use_colorkey = 0; | |
1124 info->vidixcolorkey=0; | |
1125 printf("[savage_vid] colorkeying disabled\n"); | |
1126 } | |
1127 else { | |
1128 info->use_colorkey = 1; | |
1129 info->vidixcolorkey = ((grkey->ckey.red<<16)|(grkey->ckey.green<<8)|grkey->ckey.blue); | |
1130 | |
1131 printf("[savage_vid] set colorkey 0x%x\n",info->vidixcolorkey); | |
1132 } | |
1133 //FIXME: freezes if streams arent enabled | |
1134 SavageSetColorKeyOld(); | |
1135 return (0); | |
1136 } | |
1137 | |
1138 /** | |
1139 * @brief Unichrome driver equalizer capabilities. | |
1140 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1141 static vidix_video_eq_t equal = { |
22850 | 1142 VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | VEQ_CAP_HUE, |
1143 300, 100, 0, 0, 0, 0, 0, 0 | |
1144 }; | |
1145 | |
1146 | |
1147 /** | |
1148 * @brief Get the equalizer capabilities. | |
1149 * | |
1150 * @param eq Pointer to the vidix_video_eq_t structure to be filled by driver. | |
1151 * | |
1152 * @return 0. | |
1153 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1154 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1155 savage_get_eq (vidix_video_eq_t * eq) |
22850 | 1156 { |
1157 memcpy (eq, &equal, sizeof (vidix_video_eq_t)); | |
1158 return 0; | |
1159 } | |
1160 | |
1161 /** | |
1162 * @brief Set the equalizer capabilities for color correction | |
1163 * | |
1164 * @param eq equalizer capabilities to be set. | |
1165 * | |
1166 * @return 0. | |
1167 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1168 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1169 savage_set_eq (const vidix_video_eq_t * eq) |
22850 | 1170 { |
1171 return 0; | |
1172 } | |
1173 | |
1174 /** | |
1175 * @brief Configure driver for playback. Driver should prepare BES. | |
1176 * | |
1177 * @param info configuration description for playback. | |
1178 * | |
1179 * @returns 0 in case of success. | |
1180 * -1 otherwise. | |
1181 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1182 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1183 savage_config_playback (vidix_playback_t * vinfo) |
22850 | 1184 { |
1185 int uv_size, swap_uv; | |
1186 unsigned int i; | |
1187 | |
1188 if (!is_supported_fourcc (vinfo->fourcc)) | |
1189 return -1; | |
1190 | |
1191 | |
1192 | |
1193 info->src_w = vinfo->src.w; | |
1194 info->src_h = vinfo->src.h; | |
1195 | |
1196 info->drw_w = vinfo->dest.w; | |
1197 info->drw_h = vinfo->dest.h; | |
1198 | |
1199 info->wx = vinfo->dest.x; | |
1200 info->wy = vinfo->dest.y; | |
1201 info->format = vinfo->fourcc; | |
1202 | |
1203 info->lastKnownPitch = 0; | |
1204 info->brightness = 0; | |
1205 info->contrast = 128; | |
1206 info->saturation = 128; | |
1207 info->hue = 0; | |
1208 | |
1209 | |
1210 vinfo->dga_addr=(void*)(info->picture_base); | |
1211 | |
1212 | |
1213 vinfo->offset.y = 0; | |
1214 vinfo->offset.v = 0; | |
1215 vinfo->offset.u = 0; | |
1216 | |
1217 vinfo->dest.pitch.y = 32; | |
1218 vinfo->dest.pitch.u = 32; | |
1219 vinfo->dest.pitch.v = 32; | |
1220 // vinfo->dest.pitch.u = 0; | |
1221 // vinfo->dest.pitch.v = 0; | |
1222 | |
1223 | |
1224 info->pitch = ((info->src_w << 1) + 15) & ~15; | |
1225 | |
1226 swap_uv = 0; | |
1227 switch (vinfo->fourcc) | |
1228 { | |
1229 case IMGFMT_YUY2: | |
1230 case IMGFMT_UYVY: | |
1231 | |
1232 info->pitch = ((info->src_w << 1) + (vinfo->dest.pitch.y-1)) & ~(vinfo->dest.pitch.y-1); | |
1233 | |
1234 info->pitch = info->src_w << 1; | |
1235 info->pitch = ALIGN_TO (info->src_w << 1, 32); | |
1236 uv_size = 0; | |
1237 break; | |
1238 case IMGFMT_YV12: | |
1239 swap_uv = 1; | |
1240 | |
1241 | |
1242 | |
1243 /* | |
1244 srcPitch = (info->src_w + 3) & ~3; | |
1245 vinfo->offset.u = srcPitch * info->src_h; | |
1246 srcPitch2 = ((info->src_w >> 1) + 3) & ~3; | |
1247 vinfo->offset.v = (srcPitch2 * (info->src_h >> 1)) + vinfo->offset.v; | |
1248 | |
1249 vinfo->dest.pitch.y=srcPitch ; | |
1250 vinfo->dest.pitch.v=srcPitch2 ; | |
1251 vinfo->dest.pitch.u=srcPitch2 ; | |
1252 */ | |
1253 | |
1254 | |
1255 info->pitch = ALIGN_TO (info->src_w, 32); | |
1256 uv_size = (info->pitch >> 1) * (info->src_h >> 1); | |
1257 | |
1258 vinfo->offset.y = 0; | |
1259 vinfo->offset.v = vinfo->offset.y + info->pitch * info->src_h; | |
1260 vinfo->offset.u = vinfo->offset.v + uv_size; | |
1261 vinfo->frame_size = vinfo->offset.u + uv_size; | |
1262 /* YOffs = info->offset.y; | |
1263 UOffs = (swap_uv ? vinfo->offset.v : vinfo->offset.u); | |
1264 VOffs = (swap_uv ? vinfo->offset.u : vinfo->offset.v); | |
1265 */ | |
1266 // vinfo->offset.y = info->src_w; | |
1267 // vinfo->offset.v = vinfo->offset.y + info->src_w /2 * info->src_h; | |
1268 // vinfo->offset.u = vinfo->offset.v + (info->src_w >> 1) * (info->src_h >> 1) ; | |
1269 | |
1270 break; | |
1271 } | |
1272 info->pitch |= ((info->pitch >> 1) << 16); | |
1273 | |
1274 vinfo->frame_size = info->pitch * info->src_h; | |
1275 | |
1276 printf("$#### destination pitch = %u\n", info->pitch&0xffff); | |
1277 | |
1278 | |
1279 | |
1280 | |
1281 info->buffer_size = vinfo->frame_size; | |
1282 info->num_frames = vinfo->num_frames= (info->chip.fbsize - info->picture_offset)/vinfo->frame_size; | |
1283 if(vinfo->num_frames > MAX_FRAMES)vinfo->num_frames = MAX_FRAMES; | |
1284 // vinfo->num_frames = 1; | |
1285 // printf("[nvidia_vid] Number of frames %i\n",vinfo->num_frames); | |
1286 for(i=0;i <vinfo->num_frames;i++)vinfo->offsets[i] = vinfo->frame_size*i; | |
1287 | |
1288 return 0; | |
1289 } | |
1290 | |
1291 /** | |
1292 * @brief Set playback on : driver should activate BES on this call. | |
1293 * | |
1294 * @return 0. | |
1295 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1296 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1297 savage_playback_on (void) |
22850 | 1298 { |
1299 // FIXME: enable | |
1300 SavageDisplayVideoOld(); | |
1301 //FIXME ADD | |
1302 return 0; | |
1303 } | |
1304 | |
1305 /** | |
1306 * @brief Set playback off : driver should deactivate BES on this call. | |
1307 * | |
1308 * @return 0. | |
1309 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1310 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1311 savage_playback_off (void) |
22850 | 1312 { |
1313 // otherwise we wont disable streams properly in new xorg | |
1314 // FIXME: shouldnt this be enabled? | |
1315 // SavageStreamsOn(); | |
1316 SavageStreamsOff(); | |
1317 // info->vidixcolorkey=0x0; | |
1318 | |
1319 // OUTREG( SSTREAM_WINDOW_START_REG, OS_XY(0xfffe, 0xfffe) ); | |
1320 // SavageSetColorKeyOld(); | |
1321 //FIXME ADD | |
1322 return 0; | |
1323 } | |
1324 | |
1325 /** | |
1326 * @brief Driver should prepare and activate corresponded frame. | |
1327 * | |
1328 * @param frame the frame index. | |
1329 * | |
1330 * @return 0. | |
1331 * | |
1332 * @note This function is used only for double and triple buffering | |
1333 * and never used for single buffering playback. | |
1334 */ | |
1335 #if 0 | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1336 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1337 savage_frame_select (unsigned int frame) |
22850 | 1338 { |
1339 ////FIXME ADD | |
1340 // savage_overlay_start(info, frame); | |
1341 //if (info->num_frames >= 1) | |
1342 // info->cur_frame = frame//(frame+1)%info->num_frames; | |
1343 // | |
1344 // savage4_waitidle(info); | |
1345 | |
1346 printf("vixPlaybackFrameSelect Leave\n" ); | |
1347 // FIXME: does this work to avoid tearing? | |
1348 // VerticalRetraceWait(); | |
1349 | |
1350 return 0; | |
1351 } | |
1352 | |
1353 #endif | |
1354 | |
1355 | |
1356 | |
1357 void debugout(unsigned int addr, unsigned int val){ | |
1358 return ; | |
1359 switch ( addr ){ | |
1360 case PSTREAM_CONTROL_REG: | |
1361 fprintf(stderr,"PSTREAM_CONTROL_REG"); | |
1362 break; | |
1363 case COL_CHROMA_KEY_CONTROL_REG: | |
1364 fprintf(stderr,"COL_CHROMA_KEY_CONTROL_REG"); | |
1365 break; | |
1366 case SSTREAM_CONTROL_REG: | |
1367 fprintf(stderr,"SSTREAM_CONTROL_REG"); | |
1368 break; | |
1369 case CHROMA_KEY_UPPER_BOUND_REG: | |
1370 fprintf(stderr,"CHROMA_KEY_UPPER_BOUND_REG"); | |
1371 break; | |
1372 case SSTREAM_STRETCH_REG: | |
1373 fprintf(stderr,"SSTREAM_STRETCH_REG"); | |
1374 break; | |
1375 case COLOR_ADJUSTMENT_REG: | |
1376 fprintf(stderr,"COLOR_ADJUSTMENT_REG"); | |
1377 break; | |
1378 case BLEND_CONTROL_REG: | |
1379 fprintf(stderr,"BLEND_CONTROL_REG"); | |
1380 break; | |
1381 case PSTREAM_FBADDR0_REG: | |
1382 fprintf(stderr,"PSTREAM_FBADDR0_REG"); | |
1383 break; | |
1384 case PSTREAM_FBADDR1_REG: | |
1385 fprintf(stderr,"PSTREAM_FBADDR1_REG"); | |
1386 break; | |
1387 case PSTREAM_STRIDE_REG: | |
1388 fprintf(stderr,"PSTREAM_STRIDE_REG"); | |
1389 break; | |
1390 case DOUBLE_BUFFER_REG: | |
1391 fprintf(stderr,"DOUBLE_BUFFER_REG"); | |
1392 break; | |
1393 case SSTREAM_FBADDR0_REG: | |
1394 fprintf(stderr,"SSTREAM_FBADDR0_REG"); | |
1395 break; | |
1396 case SSTREAM_FBADDR1_REG: | |
1397 fprintf(stderr,"SSTREAM_FBADDR1_REG"); | |
1398 break; | |
1399 case SSTREAM_STRIDE_REG: | |
1400 fprintf(stderr,"SSTREAM_STRIDE_REG"); | |
1401 break; | |
1402 case SSTREAM_VSCALE_REG: | |
1403 fprintf(stderr,"SSTREAM_VSCALE_REG"); | |
1404 break; | |
1405 case SSTREAM_VINITIAL_REG: | |
1406 fprintf(stderr,"SSTREAM_VINITIAL_REG"); | |
1407 break; | |
1408 case SSTREAM_LINES_REG: | |
1409 fprintf(stderr,"SSTREAM_LINES_REG"); | |
1410 break; | |
1411 case STREAMS_FIFO_REG: | |
1412 fprintf(stderr,"STREAMS_FIFO_REG"); | |
1413 break; | |
1414 case PSTREAM_WINDOW_START_REG: | |
1415 fprintf(stderr,"PSTREAM_WINDOW_START_REG"); | |
1416 break; | |
1417 case PSTREAM_WINDOW_SIZE_REG: | |
1418 fprintf(stderr,"PSTREAM_WINDOW_SIZE_REG"); | |
1419 break; | |
1420 case SSTREAM_WINDOW_START_REG: | |
1421 fprintf(stderr,"SSTREAM_WINDOW_START_REG"); | |
1422 break; | |
1423 case SSTREAM_WINDOW_SIZE_REG: | |
1424 fprintf(stderr,"SSTREAM_WINDOW_SIZE_REG"); | |
1425 break; | |
1426 case FIFO_CONTROL: | |
1427 fprintf(stderr,"FIFO_CONTROL"); | |
1428 break; | |
1429 case PSTREAM_FBSIZE_REG: | |
1430 fprintf(stderr,"PSTREAM_FBSIZE_REG"); | |
1431 break; | |
1432 case SSTREAM_FBSIZE_REG: | |
1433 fprintf(stderr,"SSTREAM_FBSIZE_REG"); | |
1434 break; | |
1435 case SSTREAM_FBADDR2_REG: | |
1436 fprintf(stderr,"SSTREAM_FBADDR2_REG"); | |
1437 break; | |
1438 | |
1439 } | |
1440 fprintf(stderr,":\t\t 0x%08X = %u\n",val,val); | |
1441 } | |
1442 | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1443 VDXDriver savage_drv = { |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1444 "savage", |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1445 NULL, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1446 .probe = savage_probe, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1447 .get_caps = savage_get_caps, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1448 .query_fourcc = savage_query_fourcc, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1449 .init = savage_init, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1450 .destroy = savage_destroy, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1451 .config_playback = savage_config_playback, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1452 .playback_on = savage_playback_on, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1453 .playback_off = savage_playback_off, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1454 #if 0 |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1455 .frame_sel = savage_frame_select, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1456 #endif |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1457 .get_eq = savage_get_eq, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1458 .set_eq = savage_set_eq, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1459 .set_gkey = savage_set_gkeys, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
1460 }; |