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