Mercurial > mplayer.hg
annotate vidix/drivers/nvidia_vid.c @ 16382:5dcfda676742
synced with 1.1084
author | gpoirier |
---|---|
date | Sun, 04 Sep 2005 10:21:38 +0000 |
parents | 73afe41bb7c3 |
children | fa804efbfaf6 |
rev | line source |
---|---|
10954 | 1 /* |
2 nvidia_vid - VIDIX based video driver for NVIDIA chips | |
11902 | 3 Copyrights 2003 - 2004 Sascha Sommer. This file is based on sources from |
10954 | 4 RIVATV (rivatv.sf.net) |
5 Licence: GPL | |
11159 | 6 WARNING: THIS DRIVER IS IN BETA STAGE |
10954 | 7 |
11086 | 8 multi buffer support and TNT2 fixes by Dmitry Baryshkov |
10954 | 9 */ |
10 | |
11 | |
12 #include <errno.h> | |
13 #include <stdio.h> | |
14 #include <stdlib.h> | |
15 #include <string.h> | |
16380 | 16 #include <math.h> |
10954 | 17 #include <inttypes.h> |
18 #include <unistd.h> | |
19 | |
20 | |
21 #include "../vidix.h" | |
22 #include "../fourcc.h" | |
23 #include "../../libdha/libdha.h" | |
24 #include "../../libdha/pci_ids.h" | |
25 #include "../../libdha/pci_names.h" | |
26 #include "../../config.h" | |
27 #include "../../bswap.h" | |
28 | |
29 | |
30 pciinfo_t pci_info; | |
31 | |
32 | |
33 #define MAX_FRAMES 3 | |
34 #define NV04_BES_SIZE 1024*2000*4 | |
35 | |
36 | |
37 static vidix_capability_t nvidia_cap = { | |
38 "NVIDIA RIVA OVERLAY DRIVER", | |
39 "Sascha Sommer <saschasommer@freenet.de>", | |
40 TYPE_OUTPUT, | |
41 { 0, 0, 0, 0 }, | |
10957
4d4d0c1c7142
according to xfree cvs maximum overlay size is only 2046x2046
atmos4
parents:
10954
diff
changeset
|
42 2046, |
4d4d0c1c7142
according to xfree cvs maximum overlay size is only 2046x2046
atmos4
parents:
10954
diff
changeset
|
43 2046, |
10954 | 44 4, |
45 4, | |
46 -1, | |
47 FLAG_UPSCALER|FLAG_DOWNSCALER, | |
48 VENDOR_NVIDIA2, | |
49 -1, | |
50 { 0, 0, 0, 0 } | |
51 }; | |
52 | |
53 | |
54 unsigned int vixGetVersion(void){ | |
55 return(VIDIX_VERSION); | |
56 } | |
57 | |
58 | |
59 #define NV_ARCH_03 0x03 | |
60 #define NV_ARCH_04 0x04 | |
61 #define NV_ARCH_10 0x10 | |
62 #define NV_ARCH_20 0x20 | |
63 #define NV_ARCH_30 0x30 | |
64 | |
16380 | 65 // since no useful information whatsoever is passed |
66 // to the equalizer functions we need this | |
67 static struct { | |
68 uint32_t lum; // luminance (brightness + contrast) | |
69 uint32_t chrom; // chrominance (saturation + hue) | |
70 vidix_video_eq_t vals; | |
71 } eq; | |
72 | |
10954 | 73 struct nvidia_cards { |
74 unsigned short chip_id; | |
75 unsigned short arch; | |
76 }; | |
77 | |
78 | |
79 static struct nvidia_cards nvidia_card_ids[] = { | |
11073 | 80 /*NV03*/ |
10954 | 81 {DEVICE_NVIDIA2_RIVA128, NV_ARCH_03}, |
11073 | 82 {DEVICE_NVIDIA2_RIVA128ZX,NV_ARCH_03}, |
83 /*NV04*/ | |
84 {DEVICE_NVIDIA_NV4_RIVA_TNT,NV_ARCH_04}, | |
85 {DEVICE_NVIDIA_NV5_RIVA_TNT2,NV_ARCH_04}, | |
86 {DEVICE_NVIDIA_NV5_RIVA_TNT22,NV_ARCH_04}, | |
87 {DEVICE_NVIDIA_NV5_RIVA_TNT23,NV_ARCH_04}, | |
88 {DEVICE_NVIDIA_NV5_RIVA_TNT24,NV_ARCH_04}, | |
89 {DEVICE_NVIDIA_NV6_VANTA,NV_ARCH_04}, | |
10954 | 90 {DEVICE_NVIDIA_RIVA_TNT2_MODEL,NV_ARCH_04}, |
11073 | 91 {DEVICE_NVIDIA_NV6_VANTA2,NV_ARCH_04}, |
92 {DEVICE_NVIDIA_NV6_VANTA3,NV_ARCH_04}, | |
93 {DEVICE_NVIDIA_NV5_RIVA_TNT25,NV_ARCH_04}, | |
10954 | 94 {DEVICE_NVIDIA2_TNT,NV_ARCH_04}, |
11073 | 95 {DEVICE_NVIDIA2_TNT2,NV_ARCH_04}, |
96 {DEVICE_NVIDIA2_VTNT2,NV_ARCH_04}, | |
10954 | 97 {DEVICE_NVIDIA2_UTNT2 ,NV_ARCH_04}, |
98 {DEVICE_NVIDIA2_ITNT2,NV_ARCH_04}, | |
11073 | 99 /*NV10*/ |
100 {DEVICE_NVIDIA_NV10_GEFORCE_256,NV_ARCH_10}, | |
101 {DEVICE_NVIDIA_NV10_GEFORCE_2562,NV_ARCH_10}, | |
102 {DEVICE_NVIDIA_NV11_GEFORCE2_MX,NV_ARCH_10}, | |
103 {DEVICE_NVIDIA_NV11_GEFORCE2_MX2,NV_ARCH_10}, | |
104 {DEVICE_NVIDIA_NV11_GEFORCE2_GO,NV_ARCH_10}, | |
105 {DEVICE_NVIDIA_NV11_GEFORCE2_MXR ,NV_ARCH_10}, | |
106 {DEVICE_NVIDIA_NV15_GEFORCE2_GTS,NV_ARCH_10}, | |
107 {DEVICE_NVIDIA_NV15_GEFORCE2_TI,NV_ARCH_10}, | |
108 {DEVICE_NVIDIA_NV15_GEFORCE2_ULTRA,NV_ARCH_10}, | |
109 {DEVICE_NVIDIA_NV17_GEFORCE4_MX460,NV_ARCH_10}, | |
110 {DEVICE_NVIDIA_NV17_GEFORCE4_MX440,NV_ARCH_10}, | |
111 {DEVICE_NVIDIA_NV17_GEFORCE4_MX420,NV_ARCH_10}, | |
112 {DEVICE_NVIDIA_NV17_GEFORCE4_440,NV_ARCH_10}, | |
113 {DEVICE_NVIDIA_NV17_GEFORCE4_420,NV_ARCH_10}, | |
114 {DEVICE_NVIDIA_NV17_GEFORCE4_4202,NV_ARCH_10}, | |
115 {DEVICE_NVIDIA_NV17_GEFORCE4_4402,NV_ARCH_10}, | |
116 {DEVICE_NVIDIA_NV18_GEFORCE4_MX440,NV_ARCH_10}, | |
117 {DEVICE_NVIDIA_NV15_GEFORCE2,NV_ARCH_10}, | |
118 /*NV20*/ | |
119 {DEVICE_NVIDIA_NV20_GEFORCE3,NV_ARCH_20}, | |
120 {DEVICE_NVIDIA_NV20_GEFORCE3_TI200,NV_ARCH_20}, | |
121 {DEVICE_NVIDIA_NV20_GEFORCE3_TI500,NV_ARCH_20}, | |
122 {DEVICE_NVIDIA_NV25_GEFORCE4_TI4600,NV_ARCH_20}, | |
123 {DEVICE_NVIDIA_NV25_GEFORCE4_TI4400,NV_ARCH_20}, | |
124 {DEVICE_NVIDIA_NV25_GEFORCE4_TI4200,NV_ARCH_20}, | |
11895
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
125 {DEVICE_NVIDIA_QUADRO4_900XGL,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
126 {DEVICE_NVIDIA_QUADRO4_750XGL,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
127 {DEVICE_NVIDIA_QUADRO4_700XGL,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
128 {DEVICE_NVIDIA_NV28_GEFORCE4_TI,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
129 {DEVICE_NVIDIA_NV28_GEFORCE4_TI2,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
130 {DEVICE_NVIDIA_NV28_GEFORCE4_TI3,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
131 {DEVICE_NVIDIA_NV28_GEFORCE4_TI4,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
132 {DEVICE_NVIDIA_NV28GL_QUADRO4_980,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
133 {DEVICE_NVIDIA_NV28GL_QUADRO4_780,NV_ARCH_20}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
134 /*NV30*/ |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
135 {DEVICE_NVIDIA_NV30_GEFORCE_FX,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
136 {DEVICE_NVIDIA_NV30_GEFORCE_FX2,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
137 {DEVICE_NVIDIA_NV30_GEFORCE_FX3,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
138 {DEVICE_NVIDIA_NV30GL_QUADRO_FX,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
139 {DEVICE_NVIDIA_NV30GL_QUADRO_FX2,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
140 {DEVICE_NVIDIA_NV31_GEFORCE_FX,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
141 {DEVICE_NVIDIA_NV31_GEFORCE_FX2,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
142 {DEVICE_NVIDIA_NV34_GEFORCE_FX,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
143 {DEVICE_NVIDIA_NV34_GEFORCE_FX2,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
144 {DEVICE_NVIDIA_NV34GL_QUADRO_FX,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
145 {DEVICE_NVIDIA_NV35_GEFORCE_FX,NV_ARCH_30}, |
d9489d5581d0
a few more nvidia cards (only tested card is GeForceFX 5200)
faust3
parents:
11783
diff
changeset
|
146 {DEVICE_NVIDIA_NV35_GEFORCE_FX2,NV_ARCH_30}, |
16376 | 147 {DEVICE_NVIDIA_NV35GL_QUADRO_FX,NV_ARCH_30}, |
148 {DEVICE_NVIDIA_NV36_GEFORCE_FX,NV_ARCH_30}, | |
10954 | 149 }; |
150 | |
151 | |
152 static int find_chip(unsigned chip_id){ | |
153 unsigned i; | |
154 for(i = 0;i < sizeof(nvidia_card_ids)/sizeof(struct nvidia_cards);i++) | |
155 { | |
156 if(chip_id == nvidia_card_ids[i].chip_id)return i; | |
157 } | |
158 return -1; | |
159 } | |
160 | |
161 int vixProbe(int verbose, int force){ | |
162 pciinfo_t lst[MAX_PCI_DEVICES]; | |
163 unsigned i,num_pci; | |
164 int err; | |
165 | |
166 if (force) | |
167 printf("[nvidia_vid]: warning: forcing not supported yet!\n"); | |
168 err = pci_scan(lst,&num_pci); | |
169 if(err){ | |
11678
972d1998bde9
occured --> occurred typo patch by Clinton Roy <croy@dstc.edu.au>
diego
parents:
11233
diff
changeset
|
170 printf("[nvidia_vid] Error occurred during pci scan: %s\n",strerror(err)); |
10954 | 171 return err; |
172 } | |
173 else { | |
174 err = ENXIO; | |
175 for(i=0; i < num_pci; i++){ | |
176 if(lst[i].vendor == VENDOR_NVIDIA2 || lst[i].vendor == VENDOR_NVIDIA){ | |
177 int idx; | |
178 const char *dname; | |
179 idx = find_chip(lst[i].device); | |
180 if(idx == -1) | |
181 continue; | |
182 dname = pci_device_name(lst[i].vendor, lst[i].device); | |
183 dname = dname ? dname : "Unknown chip"; | |
184 printf("[nvidia_vid] Found chip: %s\n", dname); | |
185 if ((lst[i].command & PCI_COMMAND_IO) == 0){ | |
186 printf("[nvidia_vid] Device is disabled, ignoring\n"); | |
187 continue; | |
188 } | |
189 nvidia_cap.device_id = lst[i].device; | |
190 err = 0; | |
191 memcpy(&pci_info, &lst[i], sizeof(pciinfo_t)); | |
192 break; | |
193 } | |
194 } | |
195 } | |
196 if(err && verbose) printf("[nvidia_vid] Can't find chip\n"); | |
197 return err; | |
198 } | |
199 | |
200 | |
201 | |
202 | |
203 /* | |
204 * PCI-Memory IO access macros. | |
205 */ | |
206 | |
207 #define MEM_BARRIER() __asm__ __volatile__ ("" : : : "memory") | |
208 | |
209 #undef VID_WR08 | |
210 #define VID_WR08(p,i,val) ({ MEM_BARRIER(); ((uint8_t *)(p))[(i)]=(val); }) | |
211 #undef VID_RD08 | |
212 #define VID_RD08(p,i) ({ MEM_BARRIER(); ((uint8_t *)(p))[(i)]; }) | |
213 | |
214 #undef VID_WR32 | |
16371 | 215 #define VID_WR32(p,i,val) ({ MEM_BARRIER(); ((uint32_t *)(p))[(i)/4]=le2me_32(val); }) |
10954 | 216 #undef VID_RD32 |
16371 | 217 #define VID_RD32(p,i) ({ MEM_BARRIER(); le2me_32(((uint32_t *)(p))[(i)/4]); }) |
10954 | 218 |
219 #define VID_AND32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)&(val)) | |
220 #define VID_OR32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)|(val)) | |
221 #define VID_XOR32(p,i,val) VID_WR32(p,i,VID_RD32(p,i)^(val)) | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 struct rivatv_chip { | |
229 volatile uint32_t *PMC; /* general control */ | |
230 volatile uint32_t *PME; /* multimedia port */ | |
231 volatile uint32_t *PFB; /* framebuffer control */ | |
232 volatile uint32_t *PVIDEO; /* overlay control */ | |
233 volatile uint8_t *PCIO; /* SVGA (CRTC, ATTR) registers */ | |
234 volatile uint8_t *PVIO; /* SVGA (MISC, GRAPH, SEQ) registers */ | |
235 volatile uint32_t *PRAMIN; /* instance memory */ | |
236 volatile uint32_t *PRAMHT; /* hash table */ | |
237 volatile uint32_t *PRAMFC; /* fifo context table */ | |
238 volatile uint32_t *PRAMRO; /* fifo runout table */ | |
239 volatile uint32_t *PFIFO; /* fifo control region */ | |
240 volatile uint32_t *FIFO; /* fifo channels (USER) */ | |
241 volatile uint32_t *PGRAPH; /* graphics engine */ | |
242 | |
243 unsigned long fbsize; /* framebuffer size */ | |
244 int arch; /* compatible NV_ARCH_XX define */ | |
245 int realarch; /* real architecture */ | |
246 void (* lock) (struct rivatv_chip *, int); | |
247 }; | |
248 typedef struct rivatv_chip rivatv_chip; | |
249 | |
250 | |
11086 | 251 struct rivatv_info { |
252 unsigned int use_colorkey; | |
10954 | 253 unsigned int colorkey; /* saved xv colorkey*/ |
254 unsigned int vidixcolorkey; /*currently used colorkey*/ | |
255 unsigned int depth; | |
256 unsigned int format; | |
257 unsigned int pitch; | |
258 unsigned int width,height; | |
259 unsigned int d_width,d_height; /*scaled width && height*/ | |
260 unsigned int wx,wy; /*window x && y*/ | |
261 unsigned int screen_x; /*screen width*/ | |
11085 | 262 unsigned int screen_y; /*screen height*/ |
10954 | 263 unsigned long buffer_size; /* size of the image buffer */ |
264 struct rivatv_chip chip; /* NV architecture structure */ | |
265 void* video_base; /* virtual address of control region */ | |
266 void* control_base; /* virtual address of fb region */ | |
16378 | 267 void* picture_base; /* direct pointer to video picture */ |
10954 | 268 unsigned long picture_offset; /* offset of video picture in frame buffer */ |
269 // struct rivatv_dma dma; /* DMA structure */ | |
11783 | 270 unsigned int cur_frame; |
10954 | 271 unsigned int num_frames; /* number of buffers */ |
11783 | 272 int bps; /* bytes per line */ |
10954 | 273 }; |
274 typedef struct rivatv_info rivatv_info; | |
275 | |
276 //framebuffer size funcs | |
277 static unsigned long rivatv_fbsize_nv03 (struct rivatv_chip *chip){ | |
278 if (VID_RD32 (chip->PFB, 0) & 0x00000020) { | |
279 if (((VID_RD32 (chip->PMC, 0) & 0xF0) == 0x20) | |
280 && ((VID_RD32 (chip->PMC, 0) & 0x0F) >= 0x02)) { | |
281 /* SDRAM 128 ZX. */ | |
282 return ((1 << (VID_RD32 (chip->PFB, 0) & 0x03)) * 1024 * 1024); | |
283 } | |
284 else { | |
285 return 1024 * 1024 * 8; | |
286 } | |
287 } | |
288 else { | |
289 /* SGRAM 128. */ | |
16371 | 290 switch (VID_RD32(chip->PFB, 0) & 0x00000003) { |
10954 | 291 case 0: |
292 return 1024 * 1024 * 8; | |
293 break; | |
294 case 2: | |
295 return 1024 * 1024 * 4; | |
296 break; | |
297 default: | |
298 return 1024 * 1024 * 2; | |
299 break; | |
300 } | |
301 } | |
302 } | |
303 static unsigned long rivatv_fbsize_nv04 (struct rivatv_chip *chip){ | |
304 if (VID_RD32 (chip->PFB, 0) & 0x00000100) { | |
305 return ((VID_RD32 (chip->PFB, 0) >> 12) & 0x0F) * 1024 * 1024 * 2 | |
306 + 1024 * 1024 * 2; | |
307 } else { | |
308 switch (VID_RD32 (chip->PFB, 0) & 0x00000003) { | |
309 case 0: | |
310 return 1024 * 1024 * 32; | |
311 break; | |
312 case 1: | |
313 return 1024 * 1024 * 4; | |
314 break; | |
315 case 2: | |
316 return 1024 * 1024 * 8; | |
317 break; | |
318 case 3: | |
319 default: | |
320 return 1024 * 1024 * 16; | |
321 break; | |
322 } | |
323 } | |
324 } | |
325 | |
326 static unsigned long rivatv_fbsize_nv10 (struct rivatv_chip *chip){ | |
327 return ((VID_RD32 (chip->PFB, 0x20C) >> 20) & 0x000000FF) * 1024 * 1024; | |
328 } | |
329 | |
330 //lock funcs | |
331 static void rivatv_lock_nv03 (struct rivatv_chip *chip, int LockUnlock){ | |
332 VID_WR08 (chip->PVIO, 0x3C4, 0x06); | |
333 VID_WR08 (chip->PVIO, 0x3C5, LockUnlock ? 0x99 : 0x57); | |
334 } | |
335 | |
336 static void rivatv_lock_nv04 (struct rivatv_chip *chip, int LockUnlock){ | |
337 VID_WR08 (chip->PCIO, 0x3C4, 0x06); | |
338 VID_WR08 (chip->PCIO, 0x3C5, LockUnlock ? 0x99 : 0x57); | |
339 VID_WR08 (chip->PCIO, 0x3D4, 0x1F); | |
340 VID_WR08 (chip->PCIO, 0x3D5, LockUnlock ? 0x99 : 0x57); | |
341 } | |
342 | |
343 | |
344 | |
345 | |
346 /* Enable PFB (Framebuffer), PVIDEO (Overlay unit) and PME (Mediaport) if neccessary. */ | |
347 static void rivatv_enable_PMEDIA (struct rivatv_info *info){ | |
348 uint32_t reg; | |
349 | |
350 /* switch off interrupts once for a while */ | |
351 // VID_WR32 (info->chip.PME, 0x200140, 0x00); | |
352 // VID_WR32 (info->chip.PMC, 0x000140, 0x00); | |
353 | |
354 reg = VID_RD32 (info->chip.PMC, 0x000200); | |
355 | |
356 /* NV3 (0x10100010): NV03_PMC_ENABLE_PMEDIA, NV03_PMC_ENABLE_PFB, NV03_PMC_ENABLE_PVIDEO */ | |
357 | |
358 if ((reg & 0x10100010) != 0x10100010) { | |
359 printf("PVIDEO and PFB disabled, enabling...\n"); | |
360 VID_OR32 (info->chip.PMC, 0x000200, 0x10100010); | |
361 } | |
362 | |
363 /* save the current colorkey */ | |
364 switch (info->chip.arch ) { | |
365 case NV_ARCH_10: | |
366 case NV_ARCH_20: | |
367 case NV_ARCH_30: | |
368 /* NV_PVIDEO_COLOR_KEY */ | |
369 info->colorkey = VID_RD32 (info->chip.PVIDEO, 0xB00); | |
370 break; | |
371 case NV_ARCH_03: | |
372 case NV_ARCH_04: | |
373 /* NV_PVIDEO_KEY */ | |
374 info->colorkey = VID_RD32 (info->chip.PVIDEO, 0x240); | |
375 break; | |
376 } | |
377 | |
378 | |
379 /* re-enable interrupts again */ | |
380 // VID_WR32 (info->chip.PMC, 0x000140, 0x01); | |
381 // VID_WR32 (info->chip.PME, 0x200140, 0x01); | |
382 } | |
383 | |
384 /* Stop overlay video. */ | |
385 void rivatv_overlay_stop (struct rivatv_info *info) { | |
386 switch (info->chip.arch ) { | |
387 case NV_ARCH_10: | |
388 case NV_ARCH_20: | |
389 case NV_ARCH_30: | |
390 /* NV_PVIDEO_COLOR_KEY */ | |
391 /* Xv-Extension-Hack: Restore previously saved value. */ | |
392 VID_WR32 (info->chip.PVIDEO, 0xB00, info->colorkey); | |
393 /* NV_PVIDEO_STOP */ | |
394 VID_OR32 (info->chip.PVIDEO, 0x704, 0x11); | |
395 /* NV_PVIDEO_BUFFER */ | |
396 VID_AND32 (info->chip.PVIDEO, 0x700, ~0x11); | |
397 /* NV_PVIDEO_INTR_EN_BUFFER */ | |
11086 | 398 // VID_AND32 (info->chip.PVIDEO, 0x140, ~0x11); |
10954 | 399 break; |
400 case NV_ARCH_03: | |
401 case NV_ARCH_04: | |
402 /* NV_PVIDEO_KEY */ | |
403 VID_WR32 (info->chip.PVIDEO, 0x240, info->colorkey); | |
404 /* NV_PVIDEO_OVERLAY_VIDEO_OFF */ | |
405 VID_AND32 (info->chip.PVIDEO, 0x244, ~0x01); | |
406 /* NV_PVIDEO_INTR_EN_0_NOTIFY */ | |
11086 | 407 // VID_AND32 (info->chip.PVIDEO, 0x140, ~0x01); |
10954 | 408 /* NV_PVIDEO_OE_STATE */ |
409 VID_WR32 (info->chip.PVIDEO, 0x224, 0); | |
410 /* NV_PVIDEO_SU_STATE */ | |
411 VID_WR32 (info->chip.PVIDEO, 0x228, 0); | |
412 /* NV_PVIDEO_RM_STATE */ | |
413 VID_WR32 (info->chip.PVIDEO, 0x22C, 0); | |
414 break; | |
415 } | |
416 } | |
417 | |
418 /* Get pan offset of the physical screen. */ | |
419 static uint32_t rivatv_overlay_pan (struct rivatv_info *info){ | |
420 uint32_t pan; | |
421 info->chip.lock (&info->chip, 0); | |
422 VID_WR08 (info->chip.PCIO, 0x3D4, 0x0D); | |
423 pan = VID_RD08 (info->chip.PCIO, 0x3D5); | |
424 VID_WR08 (info->chip.PCIO, 0x3D4, 0x0C); | |
425 pan |= VID_RD08 (info->chip.PCIO, 0x3D5) << 8; | |
426 VID_WR08 (info->chip.PCIO, 0x3D4, 0x19); | |
427 pan |= (VID_RD08 (info->chip.PCIO, 0x3D5) & 0x1F) << 16; | |
428 VID_WR08 (info->chip.PCIO, 0x3D4, 0x2D); | |
429 pan |= (VID_RD08 (info->chip.PCIO, 0x3D5) & 0x60) << 16; | |
430 return pan << 2; | |
431 } | |
432 | |
433 /* Compute and set colorkey depending on the colour depth. */ | |
434 static void rivatv_overlay_colorkey (rivatv_info* info, unsigned int chromakey){ | |
435 uint32_t r, g, b, key = 0; | |
11159 | 436 |
10954 | 437 r = (chromakey & 0x00FF0000) >> 16; |
438 g = (chromakey & 0x0000FF00) >> 8; | |
439 b = chromakey & 0x000000FF; | |
440 switch (info->depth) { | |
441 case 15: | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
442 key = ((r >> 3) << 10) | ((g >> 3) << 5) | ((b >> 3)); |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
443 #ifndef WIN32 |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
444 key = key | 0x00008000; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
445 #endif |
10954 | 446 break; |
11118
344052fdfc4a
Fix colorkey for xvidix, tested on Riva128 4MB X@15/16/24bpp (aka 15/15/32 in nvidia_vid)
atmos4
parents:
11086
diff
changeset
|
447 case 16: // XXX unchecked |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
448 key = ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3)); |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
449 #ifndef WIN32 |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
450 key = key | 0x00008000; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
451 #endif |
10954 | 452 break; |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
453 case 24: // XXX unchecked, maybe swap order of masking - FIXME Can the card be in 24 bit mode anyway? |
11118
344052fdfc4a
Fix colorkey for xvidix, tested on Riva128 4MB X@15/16/24bpp (aka 15/15/32 in nvidia_vid)
atmos4
parents:
11086
diff
changeset
|
454 key = (chromakey & 0x00FFFFFF) | 0x00800000; |
10954 | 455 break; |
456 case 32: | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
457 key = chromakey; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
458 #ifndef WIN32 |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
459 key = key | 0x80000000; |
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
460 #endif |
10954 | 461 break; |
462 } | |
11118
344052fdfc4a
Fix colorkey for xvidix, tested on Riva128 4MB X@15/16/24bpp (aka 15/15/32 in nvidia_vid)
atmos4
parents:
11086
diff
changeset
|
463 //printf("[nvidia_vid] depth=%d %08X \n", info->depth, chromakey); |
10954 | 464 switch (info->chip.arch) { |
465 case NV_ARCH_10: | |
466 case NV_ARCH_20: | |
467 case NV_ARCH_30: | |
468 VID_WR32 (info->chip.PVIDEO, 0xB00, key); | |
469 break; | |
470 case NV_ARCH_03: | |
471 case NV_ARCH_04: | |
472 VID_WR32 (info->chip.PVIDEO, 0x240, key); | |
473 break; | |
474 } | |
475 } | |
476 | |
11085 | 477 static void nv_getscreenproperties(struct rivatv_info *info){ |
478 uint32_t bpp=0; | |
479 info->chip.lock(&info->chip, 0); | |
480 /*get screen depth*/ | |
481 VID_WR08(info->chip.PCIO, 0x03D4,0x28); | |
11783 | 482 bpp = VID_RD08(info->chip.PCIO,0x03D5)&0x3; |
11085 | 483 if(bpp==3)bpp=4; |
16371 | 484 if((bpp == 2) && (VID_RD32(info->chip.PVIDEO,0x600) & 0x00001000) == 0x0)info->depth=15; |
11085 | 485 else info->depth = bpp*8; |
16370 | 486 info->bps=bpp; |
11085 | 487 /*get screen width*/ |
488 VID_WR08(info->chip.PCIO, 0x03D4, 0x1); | |
489 info->screen_x = (1 + VID_RD08(info->chip.PCIO, 0x3D5)) * 8; | |
490 /*get screen height*/ | |
491 /* get first 8 bits in VT_DISPLAY_END*/ | |
492 VID_WR08(info->chip.PCIO, 0x03D4, 0x12); | |
493 info->screen_y = VID_RD08(info->chip.PCIO,0x03D5); | |
494 VID_WR08(info->chip.PCIO,0x03D4,0x07); | |
495 /* get 9th bit in CRTC_OVERFLOW*/ | |
496 info->screen_y |= (VID_RD08(info->chip.PCIO,0x03D5) &0x02)<<7; | |
497 /* and the 10th in CRTC_OVERFLOW*/ | |
498 info->screen_y |=(VID_RD08(info->chip.PCIO,0x03D5) &0x40)<<3; | |
499 ++info->screen_y; | |
500 } | |
501 | |
502 | |
503 | |
10954 | 504 |
505 /* Start overlay video. */ | |
506 void rivatv_overlay_start (struct rivatv_info *info,int bufno){ | |
11085 | 507 uint32_t base, size, offset, xscale, yscale, pan; |
11086 | 508 uint32_t value; |
16367 | 509 int x=info->wx, y=info->wy; |
10954 | 510 int lwidth=info->d_width, lheight=info->d_height; |
511 | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
512 size = info->buffer_size; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
513 base = info->picture_offset; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
514 offset = bufno*size; |
10954 | 515 /*update depth & dimensions here because it may change with vo vesa or vo fbdev*/ |
11085 | 516 nv_getscreenproperties(info); |
517 | |
518 if(info->depth){ | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
519 /* get pan offset of the physical screen */ |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
520 pan = rivatv_overlay_pan (info); |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
521 /* adjust window position depending on the pan offset */ |
16370 | 522 if (info->bps != 0) |
11783 | 523 { |
16370 | 524 x = info->wx - (pan % info->bps) * 8 / info->depth; |
525 y = info->wy - (pan / info->bps); | |
11783 | 526 } |
16367 | 527 } else { |
528 // we can't adjust the window position correctly in textmode | |
529 // setting y to 8 seems to work ok, though | |
530 if(!y)y = info->wy+8; | |
11783 | 531 } |
532 | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
533 /* adjust negative output window variables */ |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
534 if (x < 0) { |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
535 lwidth = info->d_width + x; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
536 offset += (-x * info->width / info->d_width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
537 // offset += (-window->x * port->vld_width / window->width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
538 x = 0; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
539 } |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
540 if (y < 0) { |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
541 lheight = info->d_height + y; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
542 offset += (-y * info->height / info->d_height * info->width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
543 // offset += (-window->y * port->vld_height / window->height * port->org_width) << 1; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
544 y = 0; |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
545 } |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
546 |
10954 | 547 switch (info->chip.arch) { |
548 case NV_ARCH_10: | |
549 case NV_ARCH_20: | |
550 case NV_ARCH_30: | |
551 | |
552 /* NV_PVIDEO_BASE */ | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
553 VID_WR32 (info->chip.PVIDEO, 0x900 + 0, base + offset); |
10954 | 554 //VID_WR32 (info->chip.PVIDEO, 0x900 + 4, base); |
555 /* NV_PVIDEO_LIMIT */ | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
556 VID_WR32 (info->chip.PVIDEO, 0x908 + 0, base + offset + size - 1); |
10954 | 557 //VID_WR32 (info->chip.PVIDEO, 0x908 + 4, base + size - 1); |
558 | |
559 /* extra code for NV20 && NV30 architectures */ | |
560 if (info->chip.arch == NV_ARCH_20 || info->chip.arch == NV_ARCH_30) { | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
561 VID_WR32 (info->chip.PVIDEO, 0x800 + 0, base + offset); |
10954 | 562 //VID_WR32 (info->chip.PVIDEO, 0x800 + 4, base); |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
563 VID_WR32 (info->chip.PVIDEO, 0x808 + 0, base + offset + size - 1); |
10954 | 564 //VID_WR32 (info->chip.PVIDEO, 0x808 + 4, base + size - 1); |
565 } | |
566 | |
567 /* NV_PVIDEO_LUMINANCE */ | |
16380 | 568 VID_WR32 (info->chip.PVIDEO, 0x910 + 0, eq.lum); |
10954 | 569 //VID_WR32 (info->chip.PVIDEO, 0x910 + 4, 0x00001000); |
570 /* NV_PVIDEO_CHROMINANCE */ | |
16380 | 571 VID_WR32 (info->chip.PVIDEO, 0x918 + 0, eq.chrom); |
10954 | 572 //VID_WR32 (info->chip.PVIDEO, 0x918 + 4, 0x00001000); |
573 | |
574 /* NV_PVIDEO_OFFSET */ | |
11160
b5a3ef555164
double buffering fix for cards > NV04 && windows colorkeying fix
faust3
parents:
11159
diff
changeset
|
575 VID_WR32 (info->chip.PVIDEO, 0x920 + 0, 0x0); |
10954 | 576 //VID_WR32 (info->chip.PVIDEO, 0x920 + 4, offset + pitch); |
577 /* NV_PVIDEO_SIZE_IN */ | |
578 VID_WR32 (info->chip.PVIDEO, 0x928 + 0, ((info->height) << 16) | info->width); | |
579 //VID_WR32 (info->chip.PVIDEO, 0x928 + 4, ((port->org_height/2) << 16) | port->org_width); | |
580 /* NV_PVIDEO_POINT_IN */ | |
581 VID_WR32 (info->chip.PVIDEO, 0x930 + 0, 0x00000000); | |
582 //VID_WR32 (info->chip.PVIDEO, 0x930 + 4, 0x00000000); | |
583 /* NV_PVIDEO_DS_DX_RATIO */ | |
584 VID_WR32 (info->chip.PVIDEO, 0x938 + 0, (info->width << 20) / info->d_width); | |
585 //VID_WR32 (info->chip.PVIDEO, 0x938 + 4, (port->org_width << 20) / window->width); | |
586 /* NV_PVIDEO_DT_DY_RATIO */ | |
587 VID_WR32 (info->chip.PVIDEO, 0x940 + 0, ((info->height) << 20) / info->d_height); | |
588 //VID_WR32 (info->chip.PVIDEO, 0x940 + 4, ((port->org_height/2) << 20) / window->height); | |
589 | |
590 /* NV_PVIDEO_POINT_OUT */ | |
591 VID_WR32 (info->chip.PVIDEO, 0x948 + 0, ((y + 0) << 16) | x); | |
592 //VID_WR32 (info->chip.PVIDEO, 0x948 + 4, ((y + 0) << 16) | x); | |
593 /* NV_PVIDEO_SIZE_OUT */ | |
594 VID_WR32 (info->chip.PVIDEO, 0x950 + 0, (lheight << 16) | lwidth); | |
595 //VID_WR32 (info->chip.PVIDEO, 0x950 + 4, (height << 16) | width); | |
596 | |
597 /* NV_PVIDEO_FORMAT */ | |
11086 | 598 value = info->pitch; |
599 if(info->use_colorkey)value |= 1 << 20; | |
600 if(info->format == IMGFMT_YUY2)value |= 1 << 16; | |
601 VID_WR32 (info->chip.PVIDEO, 0x958 + 0, value); | |
602 //VID_WR32 (info->chip.PVIDEO, 0x958 + 4, (pitch << 1) | 0x00100000); | |
10954 | 603 |
604 /* NV_PVIDEO_INTR_EN_BUFFER */ | |
11086 | 605 // VID_OR32 (info->chip.PVIDEO, 0x140, 0x01/*0x11*/); |
10954 | 606 /* NV_PVIDEO_STOP */ |
11086 | 607 VID_WR32 (info->chip.PVIDEO, 0x704,0x0); |
10954 | 608 /* NV_PVIDEO_BUFFER */ |
11086 | 609 VID_WR32 (info->chip.PVIDEO, 0x700, 0x01/*0x11*/); |
10954 | 610 break; |
611 | |
612 case NV_ARCH_03: | |
613 case NV_ARCH_04: | |
614 | |
615 | |
616 /* NV_PVIDEO_OE_STATE */ | |
617 VID_WR32 (info->chip.PVIDEO, 0x224, 0); | |
618 /* NV_PVIDEO_SU_STATE */ | |
619 VID_WR32 (info->chip.PVIDEO, 0x228, 0); | |
620 /* NV_PVIDEO_RM_STATE */ | |
621 VID_WR32 (info->chip.PVIDEO, 0x22C, 0); | |
622 | |
623 /* NV_PVIDEO_BUFF0_START_ADDRESS */ | |
624 VID_WR32 (info->chip.PVIDEO, 0x20C + 0, base + offset + 0); | |
625 VID_WR32 (info->chip.PVIDEO, 0x20C + 4, base + offset + 0); | |
626 /* NV_PVIDEO_BUFF0_PITCH_LENGTH */ | |
627 VID_WR32 (info->chip.PVIDEO, 0x214 + 0, info->pitch); | |
628 VID_WR32 (info->chip.PVIDEO, 0x214 + 4, info->pitch); | |
629 | |
630 /* NV_PVIDEO_WINDOW_START */ | |
631 VID_WR32 (info->chip.PVIDEO, 0x230, (y << 16) | x); | |
632 /* NV_PVIDEO_WINDOW_SIZE */ | |
633 VID_WR32 (info->chip.PVIDEO, 0x234, (lheight << 16) | lwidth); | |
634 /* NV_PVIDEO_STEP_SIZE */ | |
635 yscale = ((info->height - 1) << 11) / (info->d_height - 1); | |
636 xscale = ((info->width - 1) << 11) / (info->d_width - 1); | |
637 VID_WR32 (info->chip.PVIDEO, 0x200, (yscale << 16) | xscale); | |
638 | |
639 /* NV_PVIDEO_RED_CSC_OFFSET */ | |
640 VID_WR32 (info->chip.PVIDEO, 0x280, 0x69); | |
641 /* NV_PVIDEO_GREEN_CSC_OFFSET */ | |
642 VID_WR32 (info->chip.PVIDEO, 0x284, 0x3e); | |
643 /* NV_PVIDEO_BLUE_CSC_OFFSET */ | |
644 VID_WR32 (info->chip.PVIDEO, 0x288, 0x89); | |
645 /* NV_PVIDEO_CSC_ADJUST */ | |
646 VID_WR32 (info->chip.PVIDEO, 0x28C, 0x00000); /* No colour correction! */ | |
647 | |
648 /* NV_PVIDEO_CONTROL_Y (BLUR_ON, LINE_HALF) */ | |
649 VID_WR32 (info->chip.PVIDEO, 0x204, 0x001); | |
650 /* NV_PVIDEO_CONTROL_X (WEIGHT_HEAVY, SHARPENING_ON, SMOOTHING_ON) */ | |
11086 | 651 VID_WR32 (info->chip.PVIDEO, 0x208, 0x111); /*directx overlay 0x110 */ |
10954 | 652 |
653 /* NV_PVIDEO_FIFO_BURST_LENGTH */ | |
654 VID_WR32 (info->chip.PVIDEO, 0x23C, 0x03); | |
655 /* NV_PVIDEO_FIFO_THRES_SIZE */ | |
656 VID_WR32 (info->chip.PVIDEO, 0x238, 0x38); /*windows uses 0x40*/ | |
657 | |
658 /* NV_PVIDEO_BUFF0_OFFSET */ | |
659 VID_WR32 (info->chip.PVIDEO, 0x21C + 0, 0); | |
660 VID_WR32 (info->chip.PVIDEO, 0x21C + 4, 0); | |
661 | |
662 /* NV_PVIDEO_INTR_EN_0_NOTIFY_ENABLED */ | |
663 // VID_OR32 (info->chip.PVIDEO, 0x140, 0x01); | |
11086 | 664 |
10954 | 665 /* NV_PVIDEO_OVERLAY (KEY_ON, VIDEO_ON, FORMAT_CCIR) */ |
11086 | 666 value = 0x1; /*video on*/ |
667 if(info->format==IMGFMT_YUY2)value |= 0x100; | |
668 if(info->use_colorkey)value |=0x10; | |
669 VID_WR32 (info->chip.PVIDEO, 0x244, value); | |
670 | |
10954 | 671 /* NV_PVIDEO_SU_STATE */ |
672 VID_XOR32 (info->chip.PVIDEO, 0x228, 1 << 16); | |
673 break; | |
674 } | |
675 /*set colorkey*/ | |
676 rivatv_overlay_colorkey(info,info->vidixcolorkey); | |
677 | |
678 } | |
679 | |
680 | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
681 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
682 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
683 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
684 |
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
685 |
10954 | 686 static rivatv_info* info; |
687 | |
688 | |
689 | |
690 | |
691 int vixInit(void){ | |
692 int mtrr; | |
693 info = (rivatv_info*)calloc(1,sizeof(rivatv_info)); | |
694 info->control_base = map_phys_mem(pci_info.base0, 0x00C00000 + 0x00008000); | |
695 info->chip.arch = nvidia_card_ids[find_chip(pci_info.device)].arch; | |
16378 | 696 printf("[nvidia_vid] arch %x register base %p\n",info->chip.arch,info->control_base); |
10954 | 697 info->chip.PFIFO = (uint32_t *) (info->control_base + 0x00002000); |
698 info->chip.FIFO = (uint32_t *) (info->control_base + 0x00800000); | |
699 info->chip.PMC = (uint32_t *) (info->control_base + 0x00000000); | |
700 info->chip.PFB = (uint32_t *) (info->control_base + 0x00100000); | |
701 info->chip.PME = (uint32_t *) (info->control_base + 0x00000000); | |
702 info->chip.PCIO = (uint8_t *) (info->control_base + 0x00601000); | |
703 info->chip.PVIO = (uint8_t *) (info->control_base + 0x000C0000); | |
704 info->chip.PGRAPH = (uint32_t *) (info->control_base + 0x00400000); | |
705 /* setup chip specific functions */ | |
706 switch (info->chip.arch) { | |
707 case NV_ARCH_03: | |
708 info->chip.lock = rivatv_lock_nv03; | |
709 info->chip.fbsize = rivatv_fbsize_nv03 (&info->chip); | |
710 info->chip.PVIDEO = (uint32_t *) (info->control_base + 0x00680000); | |
711 break; | |
712 case NV_ARCH_04: | |
713 info->chip.lock = rivatv_lock_nv04; | |
714 info->chip.fbsize = rivatv_fbsize_nv04 (&info->chip); | |
715 info->chip.PRAMIN = (uint32_t *) (info->control_base + 0x00700000); | |
716 info->chip.PVIDEO = (uint32_t *) (info->control_base + 0x00680000); | |
717 break; | |
718 case NV_ARCH_10: | |
719 case NV_ARCH_20: | |
720 case NV_ARCH_30: | |
721 info->chip.lock = rivatv_lock_nv04; | |
722 info->chip.fbsize = rivatv_fbsize_nv10 (&info->chip); | |
723 info->chip.PRAMIN = (uint32_t *) (info->control_base + 0x00700000); | |
724 info->chip.PVIDEO = (uint32_t *) (info->control_base + 0x00008000); | |
725 break; | |
726 } | |
727 switch (info->chip.arch) { | |
728 case NV_ARCH_03: | |
729 { | |
730 /* This maps framebuffer @6MB, thus 2MB are left for video. */ | |
731 info->video_base = map_phys_mem(pci_info.base1, info->chip.fbsize); | |
732 /* This may trash your screen for resolutions greater than 1024x768, sorry. */ | |
10977
3da6b1de1c33
make it work in textmode again && support for nv03 with 4MB RAM
faust3
parents:
10970
diff
changeset
|
733 info->picture_offset = 1024*768* 4 * ((info->chip.fbsize > 4194304)?2:1); |
16378 | 734 info->picture_base = info->video_base + info->picture_offset; |
10954 | 735 info->chip.PRAMIN = (uint32_t *) (info->video_base + 0x00C00000); |
736 break; | |
737 } | |
738 case NV_ARCH_04: | |
739 case NV_ARCH_10: | |
740 case NV_ARCH_20: | |
741 case NV_ARCH_30: | |
742 { | |
743 info->video_base = map_phys_mem(pci_info.base1, info->chip.fbsize); | |
744 info->picture_offset = info->chip.fbsize - NV04_BES_SIZE; | |
745 // info->picture_base = (unsigned long)map_phys_mem(pci_info.base1+info->picture_offset,NV04_BES_SIZE); | |
16378 | 746 info->picture_base = info->video_base + info->picture_offset; |
10954 | 747 break; |
748 } | |
749 } | |
750 | |
751 printf("[nvidia_vid] detected memory size %u MB\n",(uint32_t)(info->chip.fbsize /1024/1024)); | |
752 | |
753 if ((mtrr = mtrr_set_type(pci_info.base1, info->chip.fbsize, MTRR_TYPE_WRCOMB))!= 0) | |
11085 | 754 printf("[nvidia_vid] unable to setup MTRR: %s\n", strerror(mtrr)); |
10954 | 755 else |
11085 | 756 printf("[nvidia_vid] MTRR set up\n"); |
10954 | 757 |
11085 | 758 nv_getscreenproperties(info); |
759 if(!info->depth)printf("[nvidia_vid] text mode: %ux%u\n",info->screen_x,info->screen_y); | |
760 else printf("[nvidia_vid] video mode: %ux%u@%u\n",info->screen_x,info->screen_y, info->depth); | |
761 | |
10954 | 762 |
763 rivatv_enable_PMEDIA(info); | |
11783 | 764 info->cur_frame = 0; |
11159 | 765 info->use_colorkey = 0; |
11783 | 766 |
16380 | 767 eq.lum = 0x00001000; |
768 eq.chrom = 0x00001000; | |
769 memset(&eq.vals, 0, sizeof(vidix_video_eq_t)); | |
770 eq.vals.cap = VEQ_CAP_BRIGHTNESS | VEQ_CAP_CONTRAST | | |
771 VEQ_CAP_SATURATION | VEQ_CAP_HUE; | |
10954 | 772 return 0; |
773 } | |
774 | |
775 void vixDestroy(void){ | |
776 unmap_phys_mem(info->control_base ,0x00C00000 + 0x00008000); | |
777 unmap_phys_mem(info->video_base, info->chip.fbsize); | |
778 free(info); | |
779 } | |
780 | |
781 int vixGetCapability(vidix_capability_t *to){ | |
782 memcpy(to, &nvidia_cap, sizeof(vidix_capability_t)); | |
783 return 0; | |
784 } | |
785 | |
786 inline static int is_supported_fourcc(uint32_t fourcc) | |
787 { | |
11086 | 788 if (fourcc == IMGFMT_UYVY || fourcc == IMGFMT_YUY2) |
10954 | 789 return 1; |
790 else | |
791 return 0; | |
792 } | |
793 | |
794 int vixQueryFourcc(vidix_fourcc_t *to){ | |
795 if(is_supported_fourcc(to->fourcc)){ | |
796 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
797 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
798 VID_DEPTH_12BPP| VID_DEPTH_15BPP| | |
799 VID_DEPTH_16BPP| VID_DEPTH_24BPP| | |
800 VID_DEPTH_32BPP; | |
801 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; | |
802 return 0; | |
803 } | |
804 else to->depth = to->flags = 0; | |
805 return ENOSYS; | |
806 } | |
807 | |
808 int vixConfigPlayback(vidix_playback_t *vinfo){ | |
809 uint32_t i; | |
810 printf("called %s\n", __FUNCTION__); | |
811 if (! is_supported_fourcc(vinfo->fourcc)) | |
812 return ENOSYS; | |
813 | |
814 info->width = vinfo->src.w; | |
815 info->height = vinfo->src.h; | |
816 | |
817 info->d_width = vinfo->dest.w; | |
818 info->d_height = vinfo->dest.h; | |
819 info->wx = vinfo->dest.x; | |
820 info->wy = vinfo->dest.y; | |
821 info->format = vinfo->fourcc; | |
822 | |
823 printf("[nvidia_vid] setting up a %dx%d-%dx%d video window (src %dx%d), format 0x%X\n", | |
824 info->d_width, info->d_height, info->wx, info->wy, info->width, info->height, vinfo->fourcc); | |
825 | |
826 | |
16378 | 827 vinfo->dga_addr=info->picture_base; |
10954 | 828 |
829 switch (vinfo->fourcc) | |
830 { | |
831 case IMGFMT_YUY2: | |
832 case IMGFMT_UYVY: | |
833 | |
11086 | 834 vinfo->dest.pitch.y = 16; |
10954 | 835 vinfo->dest.pitch.u = 0; |
836 vinfo->dest.pitch.v = 0; | |
837 | |
838 vinfo->offset.y = 0; | |
839 vinfo->offset.v = 0; | |
840 vinfo->offset.u = 0; | |
11902 | 841 info->pitch = ((info->width << 1) + (vinfo->dest.pitch.y-1)) & ~(vinfo->dest.pitch.y-1); |
10954 | 842 vinfo->frame_size = info->pitch * info->height; |
843 break; | |
844 } | |
845 info->buffer_size = vinfo->frame_size; | |
846 info->num_frames = vinfo->num_frames= (info->chip.fbsize - info->picture_offset)/vinfo->frame_size; | |
847 if(vinfo->num_frames > MAX_FRAMES)vinfo->num_frames = MAX_FRAMES; | |
848 // vinfo->num_frames = 1; | |
849 // printf("[nvidia_vid] Number of frames %i\n",vinfo->num_frames); | |
850 for(i=0;i <vinfo->num_frames;i++)vinfo->offsets[i] = vinfo->frame_size*i; | |
851 return 0; | |
852 } | |
853 | |
854 int vixPlaybackOn(void){ | |
11783 | 855 rivatv_overlay_start(info,info->cur_frame); |
10954 | 856 return 0; |
857 } | |
858 | |
859 int vixPlaybackOff(void){ | |
860 rivatv_overlay_stop(info); | |
861 return 0; | |
862 } | |
863 | |
864 int vixSetGrKeys( const vidix_grkey_t * grkey){ | |
11159 | 865 if (grkey->ckey.op == CKEY_FALSE) |
866 { | |
867 info->use_colorkey = 0; | |
868 printf("[nvidia_vid] colorkeying disabled\n"); | |
869 } | |
11165 | 870 else { |
11159 | 871 info->use_colorkey = 1; |
10954 | 872 info->vidixcolorkey = ((grkey->ckey.red<<16)|(grkey->ckey.green<<8)|grkey->ckey.blue); |
873 printf("[nvidia_vid] set colorkey 0x%x\n",info->vidixcolorkey); | |
11165 | 874 } |
11210 | 875 if(info->d_width && info->d_height)rivatv_overlay_start(info,0); |
10954 | 876 return 0; |
877 } | |
878 | |
879 int vixPlaybackFrameSelect(unsigned int frame){ | |
880 // printf("selecting buffer %d\n", frame); | |
881 rivatv_overlay_start(info, frame); | |
882 if (info->num_frames >= 1) | |
11783 | 883 info->cur_frame = frame/*(frame+1)%info->num_frames*/; |
10954 | 884 return 0; |
885 } | |
16380 | 886 |
887 int vixPlaybackSetEq(const vidix_video_eq_t *eq_parm) { | |
888 double angle; | |
889 int16_t chrom_cos, chrom_sin; | |
890 vidix_video_eq_t new_eq; | |
891 vixPlaybackGetEq(&new_eq); | |
892 if (eq_parm->cap & VEQ_CAP_BRIGHTNESS) | |
893 new_eq.brightness = eq_parm->brightness; | |
894 if (eq_parm->cap & VEQ_CAP_CONTRAST) | |
895 new_eq.contrast = eq_parm->contrast; | |
896 if (eq_parm->cap & VEQ_CAP_SATURATION) | |
897 new_eq.saturation = eq_parm->saturation; | |
898 if (eq_parm->cap & VEQ_CAP_HUE) | |
899 new_eq.hue = eq_parm->hue; | |
900 eq.lum = (((new_eq.brightness * 512 + 500) / 1000) << 16) | | |
901 ((((new_eq.contrast + 1000) * 8191 + 1000) / 2000) & 0xffff); | |
902 angle = (double)new_eq.hue / 1000.0 * 3.1415927; | |
903 chrom_cos = ((new_eq.saturation + 1000) * 8191 * cos(angle) + 1000) / 2000; | |
904 chrom_sin = ((new_eq.saturation + 1000) * 8191 * sin(angle) + 1000) / 2000; | |
905 eq.chrom = chrom_sin << 16 | chrom_cos; | |
906 return 0; | |
907 } | |
908 | |
909 int vixPlaybackGetEq(vidix_video_eq_t *eq_parm) { | |
910 memcpy(eq_parm, &eq.vals, sizeof(vidix_video_eq_t)); | |
911 return 0; | |
912 } | |
913 |