Mercurial > mplayer.hg
annotate vidix/pm2_vid.c @ 23059:7d3914646699
declare variables as static
author | ben |
---|---|
date | Sun, 22 Apr 2007 15:41:17 +0000 |
parents | 82216ef041e0 |
children | 91ad6d4d6a54 |
rev | line source |
---|---|
23046
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
1 /* |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
2 * VIDIX driver for 3DLabs Permedia 2 chipsets. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
3 * Copyright (C) 2002 Måns Rullgård |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
4 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
5 * This file is part of MPlayer. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
6 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
10 * (at your option) any later version. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
11 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
15 * GNU General Public License for more details. |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
16 * |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
18 * along with MPlayer; if not, write to the Free Software |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
82216ef041e0
updated vidix files headers whenever it's possible to have a clear GPL statement
ben
parents:
23040
diff
changeset
|
20 */ |
22974 | 21 |
22 #include <errno.h> | |
23 #include <stdio.h> | |
24 #include <stdlib.h> | |
25 #include <string.h> | |
26 #include <inttypes.h> | |
27 #include <sys/types.h> | |
28 #include <unistd.h> | |
29 | |
30 #include "vidix.h" | |
31 #include "vidixlib.h" | |
32 #include "fourcc.h" | |
33 #include "dha.h" | |
34 #include "pci_ids.h" | |
35 #include "pci_names.h" | |
36 #include "config.h" | |
37 | |
38 #include "glint_regs.h" | |
39 | |
40 /* MBytes of video memory to use */ | |
41 #define PM2_VIDMEM 6 | |
42 | |
43 #if 0 | |
44 #define TRACE_ENTER() fprintf(stderr, "%s: enter\n", __FUNCTION__) | |
45 #define TRACE_EXIT() fprintf(stderr, "%s: exit\n", __FUNCTION__) | |
46 #else | |
47 #define TRACE_ENTER() | |
48 #define TRACE_EXIT() | |
49 #endif | |
50 | |
51 #define WRITE_REG(offset,val) \ | |
23040 | 52 *(volatile unsigned long *)(((unsigned char *)(pm2_reg_base)) + offset) = (val) |
22974 | 53 #define READ_REG(offset) \ |
54 *(volatile unsigned long *)(((unsigned char *)(pm2_reg_base)) + offset) | |
55 | |
56 static pciinfo_t pci_info; | |
57 | |
58 static void *pm2_reg_base; | |
59 static void *pm2_mem; | |
60 | |
61 static int pm2_vidmem = PM2_VIDMEM; | |
62 | |
63 static vidix_capability_t pm2_cap = | |
64 { | |
65 "3DLabs Permedia2 driver", | |
66 "Måns Rullgård <mru@users.sf.net>", | |
67 TYPE_OUTPUT, | |
68 { 0, 0, 0, 0 }, | |
69 2048, | |
70 2048, | |
71 4, | |
72 4, | |
73 -1, | |
74 FLAG_UPSCALER|FLAG_DOWNSCALER, | |
75 VENDOR_3DLABS, | |
76 -1, | |
77 { 0, 0, 0, 0 } | |
78 }; | |
79 | |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
80 static unsigned int pm2_card_ids[] = |
22974 | 81 { |
82 (VENDOR_3DLABS << 16) | DEVICE_3DLABS_PERMEDIA2, | |
83 (VENDOR_TEXAS << 16) | DEVICE_TEXAS_TVP4020_PERMEDIA_2 | |
84 }; | |
85 | |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
86 static int find_chip(unsigned int vendor, uint32_t chip_id) |
22974 | 87 { |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
88 unsigned int vci = (vendor << 16) | chip_id; |
22974 | 89 unsigned i; |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
90 for(i = 0; i < sizeof(pm2_card_ids)/sizeof(unsigned int); i++){ |
22974 | 91 if(vci == pm2_card_ids[i]) return i; |
92 } | |
93 return -1; | |
94 } | |
95 | |
96 static int pm2_probe(int verbose, int force __attribute__ ((unused))) | |
97 { | |
98 pciinfo_t lst[MAX_PCI_DEVICES]; | |
99 unsigned i,num_pci; | |
100 int err; | |
101 | |
102 err = pci_scan(lst,&num_pci); | |
103 if(err) | |
104 { | |
105 printf("[pm2] Error occurred during pci scan: %s\n",strerror(err)); | |
106 return err; | |
107 } | |
108 else | |
109 { | |
110 err = ENXIO; | |
111 for(i=0; i < num_pci; i++) | |
112 { | |
113 int idx; | |
114 const char *dname; | |
115 idx = find_chip(lst[i].vendor, lst[i].device); | |
116 if(idx == -1) | |
117 continue; | |
118 dname = pci_device_name(lst[i].vendor, lst[i].device); | |
119 dname = dname ? dname : "Unknown chip"; | |
120 printf("[pm2] Found chip: %s\n", dname); | |
121 pm2_cap.device_id = lst[i].device; | |
122 err = 0; | |
123 memcpy(&pci_info, &lst[i], sizeof(pciinfo_t)); | |
124 break; | |
125 } | |
126 } | |
127 if(err && verbose) printf("[pm2] Can't find chip.\n"); | |
128 return err; | |
129 } | |
130 | |
131 #define PRINT_REG(reg) \ | |
132 { \ | |
133 long _foo = READ_REG(reg); \ | |
134 printf("[pm2] " #reg " (%x) = %#lx (%li)\n", reg, _foo, _foo); \ | |
135 } | |
136 | |
22984 | 137 static int pm2_init(void) |
22974 | 138 { |
139 char *vm; | |
140 pm2_reg_base = map_phys_mem(pci_info.base0, 0x10000); | |
141 pm2_mem = map_phys_mem(pci_info.base1, 1 << 23); | |
142 if((vm = getenv("PM2_VIDMEM"))){ | |
143 pm2_vidmem = strtol(vm, NULL, 0); | |
144 } | |
145 return 0; | |
146 } | |
147 | |
148 static void pm2_destroy(void) | |
149 { | |
150 unmap_phys_mem(pm2_reg_base, 0x10000); | |
151 unmap_phys_mem(pm2_mem, 1 << 23); | |
152 } | |
153 | |
154 static int pm2_get_caps(vidix_capability_t *to) | |
155 { | |
156 memcpy(to, &pm2_cap, sizeof(vidix_capability_t)); | |
157 return 0; | |
158 } | |
159 | |
160 static int is_supported_fourcc(uint32_t fourcc) | |
161 { | |
162 switch(fourcc){ | |
163 case IMGFMT_YUY2: | |
164 return 1; | |
165 default: | |
166 return 0; | |
167 } | |
168 } | |
169 | |
170 static int pm2_query_fourcc(vidix_fourcc_t *to) | |
171 { | |
172 if(is_supported_fourcc(to->fourcc)) | |
173 { | |
174 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
175 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
176 VID_DEPTH_12BPP| VID_DEPTH_15BPP| | |
177 VID_DEPTH_16BPP| VID_DEPTH_24BPP| | |
178 VID_DEPTH_32BPP; | |
179 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; | |
180 return 0; | |
181 } | |
182 else to->depth = to->flags = 0; | |
183 return ENOSYS; | |
184 } | |
185 | |
186 #define FORMAT_YUV422 ((1 << 6) | 3 | (1 << 4)) | |
187 | |
188 #define PPROD(a,b,c) (a | (b << 3) | (c << 6)) | |
189 | |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
190 static unsigned int ppcodes[][2] = { |
22974 | 191 {0, 0}, |
192 {32, PPROD(1, 0, 0)}, | |
193 {64, PPROD(1, 1, 0)}, | |
194 {96, PPROD(1, 1, 1)}, | |
195 {128, PPROD(2, 1, 1)}, | |
196 {160, PPROD(2, 2, 1)}, | |
197 {192, PPROD(2, 2, 2)}, | |
198 {224, PPROD(3, 2, 1)}, | |
199 {256, PPROD(3, 2, 2)}, | |
200 {288, PPROD(3, 3, 1)}, | |
201 {320, PPROD(3, 3, 2)}, | |
202 {384, PPROD(3, 3, 3)}, | |
203 {416, PPROD(4, 3, 1)}, | |
204 {448, PPROD(4, 3, 2)}, | |
205 {512, PPROD(4, 3, 3)}, | |
206 {544, PPROD(4, 4, 1)}, | |
207 {576, PPROD(4, 4, 2)}, | |
208 {640, PPROD(4, 4, 3)}, | |
209 {768, PPROD(4, 4, 4)}, | |
210 {800, PPROD(5, 4, 1)}, | |
211 {832, PPROD(5, 4, 2)}, | |
212 {896, PPROD(5, 4, 3)}, | |
213 {1024, PPROD(5, 4, 4)}, | |
214 {1056, PPROD(5, 5, 1)}, | |
215 {1088, PPROD(5, 5, 2)}, | |
216 {1152, PPROD(5, 5, 3)}, | |
217 {1280, PPROD(5, 5, 4)}, | |
218 {1536, PPROD(5, 5, 5)}, | |
219 {1568, PPROD(6, 5, 1)}, | |
220 {1600, PPROD(6, 5, 2)}, | |
221 {1664, PPROD(6, 5, 3)}, | |
222 {1792, PPROD(6, 5, 4)}, | |
223 {2048, PPROD(6, 5, 5)} | |
224 }; | |
225 | |
226 static int frames[VID_PLAY_MAXFRAMES]; | |
227 | |
228 static int pm2_config_playback(vidix_playback_t *info) | |
229 { | |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
230 unsigned int src_w, drw_w; |
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
231 unsigned int src_h, drw_h; |
22974 | 232 long base0; |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
233 unsigned int stride, sstr; |
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
234 unsigned int format; |
22974 | 235 unsigned int i; |
23037
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
236 unsigned int ppcode = 0, sppc = 0; |
c2c2bc418257
better fix for r23001, u_int becomes unsigned int, dont force it to uin32_t
ben
parents:
22984
diff
changeset
|
237 unsigned int pitch = 0; |
22974 | 238 |
239 TRACE_ENTER(); | |
240 | |
241 switch(info->fourcc){ | |
242 case IMGFMT_YUY2: | |
243 format = FORMAT_YUV422; | |
244 break; | |
245 default: | |
246 return -1; | |
247 } | |
248 | |
249 src_w = info->src.w; | |
250 src_h = info->src.h; | |
251 | |
252 drw_w = info->dest.w; | |
253 drw_h = info->dest.h; | |
254 | |
255 sstr = READ_REG(PMScreenStride) * 2; | |
256 | |
257 stride = 0; | |
258 for(i = 1; i < sizeof(ppcodes) / sizeof(ppcodes[0]); i++){ | |
259 if((!stride) && (ppcodes[i][0] >= src_w)){ | |
260 stride = ppcodes[i][0]; | |
261 ppcode = ppcodes[i][1]; | |
262 pitch = ppcodes[i][0] - ppcodes[i-1][0]; | |
263 } | |
264 if(ppcodes[i][0] == sstr) | |
265 sppc = ppcodes[i][1]; | |
266 } | |
267 | |
268 if(!stride) | |
269 return -1; | |
270 | |
271 info->num_frames = pm2_vidmem*1024*1024 / (stride * src_h * 2); | |
272 if(info->num_frames > VID_PLAY_MAXFRAMES) | |
273 info->num_frames = VID_PLAY_MAXFRAMES; | |
274 | |
275 /* Use end of video memory. Assume the card has 8 MB */ | |
276 base0 = (8 - pm2_vidmem)*1024*1024; | |
277 info->dga_addr = pm2_mem + base0; | |
278 | |
279 info->dest.pitch.y = pitch*2; | |
280 info->dest.pitch.u = 0; | |
281 info->dest.pitch.v = 0; | |
282 info->offset.y = 0; | |
283 info->offset.v = 0; | |
284 info->offset.u = 0; | |
285 info->frame_size = stride * src_h * 2; | |
286 | |
287 for(i = 0; i < info->num_frames; i++){ | |
288 info->offsets[i] = info->frame_size * i; | |
289 frames[i] = (base0 + info->offsets[i]) >> 1; | |
290 } | |
291 | |
292 WRITE_REG(WindowOrigin, 0); | |
293 WRITE_REG(dY, 1 << 16); | |
294 WRITE_REG(RasterizerMode, 0); | |
295 WRITE_REG(ScissorMode, 0); | |
296 WRITE_REG(AreaStippleMode, 0); | |
297 WRITE_REG(StencilMode, 0); | |
298 WRITE_REG(TextureAddressMode, 1); | |
299 | |
300 WRITE_REG(dSdyDom, 0); | |
301 WRITE_REG(dTdx, 0); | |
302 | |
303 WRITE_REG(PMTextureMapFormat, (1 << 19) | ppcode); | |
304 WRITE_REG(PMTextureDataFormat, format); | |
305 WRITE_REG(PMTextureReadMode, (1 << 17) | /* FilterMode */ | |
306 (11 << 13) | (11 << 9) /* TextureSize log2 */ | 1); | |
307 WRITE_REG(ColorDDAMode, 0); | |
308 WRITE_REG(TextureColorMode, (0 << 4) /* RGB */ | (3 << 1) /* Copy */ | 1); | |
309 WRITE_REG(AlphaBlendMode, 0); | |
310 WRITE_REG(DitherMode, (1 << 10) | 1); | |
311 WRITE_REG(LogicalOpMode, 0); | |
312 WRITE_REG(FBReadMode, sppc); | |
313 WRITE_REG(FBHardwareWriteMask, 0xFFFFFFFF); | |
314 WRITE_REG(FBWriteMode, 1); | |
315 WRITE_REG(YUVMode, 1); | |
316 | |
317 WRITE_REG(SStart, 0); | |
318 WRITE_REG(TStart, 0); | |
319 | |
320 WRITE_REG(dSdx, (src_w << 20) / drw_w); | |
321 WRITE_REG(dTdyDom, (src_h << 20) / drw_h); | |
322 WRITE_REG(RectangleOrigin, info->dest.x | (info->dest.y << 16)); | |
323 WRITE_REG(RectangleSize, (drw_h << 16) | drw_w); | |
324 | |
325 TRACE_EXIT(); | |
326 return 0; | |
327 } | |
328 | |
329 static int pm2_playback_on(void) | |
330 { | |
331 TRACE_ENTER(); | |
332 | |
333 TRACE_EXIT(); | |
334 return 0; | |
335 } | |
336 | |
337 static int pm2_playback_off(void) | |
338 { | |
339 WRITE_REG(YUVMode, 0); | |
340 WRITE_REG(TextureColorMode, 0); | |
341 WRITE_REG(TextureAddressMode, 0); | |
342 WRITE_REG(TextureReadMode, 0); | |
343 return 0; | |
344 } | |
345 | |
346 static int pm2_frame_select(unsigned int frame) | |
347 { | |
348 WRITE_REG(PMTextureBaseAddress, frames[frame]); | |
349 WRITE_REG(Render, PrimitiveRectangle | XPositive | YPositive | | |
350 TextureEnable); | |
351 return 0; | |
352 } | |
353 | |
354 VDXDriver pm2_drv = { | |
355 "pm2", | |
356 NULL, | |
357 .probe = pm2_probe, | |
358 .get_caps = pm2_get_caps, | |
359 .query_fourcc = pm2_query_fourcc, | |
360 .init = pm2_init, | |
361 .destroy = pm2_destroy, | |
362 .config_playback = pm2_config_playback, | |
363 .playback_on = pm2_playback_on, | |
364 .playback_off = pm2_playback_off, | |
365 .frame_sel = pm2_frame_select, | |
366 }; |