4126
|
1 #include <errno.h>
|
|
2 #include <stdio.h>
|
|
3 #include <stdlib.h>
|
|
4 #include <string.h>
|
|
5 #include <math.h>
|
|
6 #include <inttypes.h>
|
|
7
|
|
8 #include "../vidix.h"
|
|
9 #include "../fourcc.h"
|
|
10 #include "../../libdha/libdha.h"
|
|
11 #include "../../libdha/pci_ids.h"
|
|
12 #include "../../libdha/pci_names.h"
|
|
13
|
4327
|
14 #include "nvidia.h"
|
4126
|
15
|
4327
|
16 static void *ctrl_base = 0;
|
|
17 static void *fb_base = 0;
|
4126
|
18 static int32_t overlay_offset = 0;
|
|
19 static uint32_t ram_size = 0;
|
|
20
|
4327
|
21 static unsigned int *PFB;
|
|
22 static unsigned int *PCIO;
|
|
23 static unsigned int *PGRAPH;
|
|
24 static unsigned int *PRAMIN;
|
|
25 static unsigned int *FIFO;
|
|
26 static unsigned int *PMC;
|
|
27
|
|
28 typedef unsigned char U008;
|
|
29
|
|
30 #define NV_WR08(p,i,d) (((U008 *)(p))[i]=(d))
|
|
31
|
|
32 unsigned int nv_fifo_space = 0;
|
|
33
|
|
34 void CRTCout(unsigned char index, unsigned char val)
|
|
35 {
|
|
36 NV_WR08(PCIO, 0x3d4, index);
|
|
37 NV_WR08(PCIO, 0x3d5, val);
|
|
38 }
|
|
39
|
|
40 volatile RivaScaledImage *ScaledImage;
|
|
41
|
4175
|
42 #define CARD_FLAGS_NONE 0x00
|
|
43 #define CARD_FLAGS_NOTSUPPORTED 0x01
|
|
44
|
4126
|
45 struct nv_card_id_s
|
|
46 {
|
|
47 const unsigned int id ;
|
4191
|
48 const char name[32];
|
4175
|
49 const int core;
|
|
50 const int flags;
|
4126
|
51 };
|
|
52
|
4327
|
53 static const struct nv_card_id_s nv_card_id;
|
|
54
|
4126
|
55 static const struct nv_card_id_s nv_card_ids[]=
|
|
56 {
|
4175
|
57 { DEVICE_NVIDIA_RIVA_TNT2_NV5, "nVidia TNT2 (NV5) ", 5, CARD_FLAGS_NOTSUPPORTED},
|
|
58 { DEVICE_NVIDIA_VANTA_NV6, "nVidia Vanta (NV6.1)", 6, CARD_FLAGS_NOTSUPPORTED},
|
4191
|
59 { DEVICE_NVIDIA_VANTA_NV62, "nVidia Vanta (NV6.2)", 6, CARD_FLAGS_NOTSUPPORTED}
|
4126
|
60 };
|
|
61
|
|
62 static int find_chip(unsigned int chip_id)
|
|
63 {
|
|
64 unsigned int i;
|
|
65
|
|
66 for (i = 0; i < sizeof(nv_card_ids)/sizeof(struct nv_card_id_s); i++)
|
|
67 if (chip_id == nv_card_ids[i].id)
|
|
68 return(i);
|
|
69 return(-1);
|
|
70 }
|
|
71
|
|
72 static pciinfo_t pci_info;
|
|
73 static int probed = 0;
|
|
74
|
|
75 /* VIDIX exports */
|
|
76
|
|
77 static vidix_capability_t nvidia_cap =
|
|
78 {
|
|
79 "NVIDIA driver for VIDIX",
|
4327
|
80 "alex",
|
4126
|
81 TYPE_OUTPUT,
|
4191
|
82 { 0, 0, 0, 0 },
|
4327
|
83 2046,
|
|
84 2047,
|
4126
|
85 4,
|
|
86 4,
|
|
87 -1,
|
|
88 FLAG_NONE,
|
|
89 VENDOR_NVIDIA,
|
|
90 0,
|
|
91 { 0, 0, 0, 0 }
|
|
92 };
|
|
93
|
|
94 unsigned int vixGetVersion(void)
|
|
95 {
|
|
96 return(VIDIX_VERSION);
|
|
97 }
|
|
98
|
4191
|
99 int vixProbe(int verbose,int force)
|
4126
|
100 {
|
|
101 pciinfo_t lst[MAX_PCI_DEVICES];
|
|
102 unsigned int i, num_pci;
|
|
103 int err;
|
|
104
|
|
105 printf("[nvidia] probe\n");
|
|
106
|
|
107 err = pci_scan(lst, &num_pci);
|
|
108 if (err)
|
|
109 {
|
|
110 printf("Error occured during pci scan: %s\n", strerror(err));
|
|
111 return err;
|
|
112 }
|
|
113 else
|
|
114 {
|
|
115 err = ENXIO;
|
|
116
|
|
117 for (i = 0; i < num_pci; i++)
|
|
118 {
|
|
119 if (lst[i].vendor == VENDOR_NVIDIA)
|
|
120 {
|
|
121 int idx;
|
|
122
|
|
123 idx = find_chip(lst[i].device);
|
|
124 if (idx == -1)
|
|
125 continue;
|
4175
|
126 if (nv_card_ids[idx].flags & CARD_FLAGS_NOTSUPPORTED)
|
|
127 {
|
|
128 printf("Found chip: %s, but not supported!\n",
|
|
129 nv_card_ids[idx].name);
|
|
130 continue;
|
|
131 }
|
|
132 else
|
|
133
|
|
134 printf("Found chip: %s\n", nv_card_ids[idx].name);
|
4327
|
135
|
|
136 memcpy(&nv_card_id, &nv_card_ids[idx], sizeof(struct nv_card_id_s));
|
4126
|
137 nvidia_cap.device_id = nv_card_ids[idx].id;
|
|
138 err = 0;
|
|
139 memcpy(&pci_info, &lst[i], sizeof(pciinfo_t));
|
|
140 probed = 1;
|
|
141
|
|
142 printf("bus:card:func = %x:%x:%x\n",
|
|
143 pci_info.bus, pci_info.card, pci_info.func);
|
|
144 printf("vendor:device = %x:%x\n",
|
|
145 pci_info.vendor, pci_info.device);
|
|
146 printf("base0:base1:base2:baserom = %x:%x:%x:%x\n",
|
|
147 pci_info.base0, pci_info.base1, pci_info.base2,
|
|
148 pci_info.baserom);
|
|
149 break;
|
|
150 }
|
|
151 }
|
|
152 }
|
|
153
|
|
154 if (err)
|
|
155 printf("No chip found\n");
|
|
156 return(err);
|
|
157 }
|
|
158
|
|
159 int vixInit(void)
|
|
160 {
|
4327
|
161 int card_option;
|
|
162
|
4126
|
163 printf("[nvidia] init\n");
|
|
164
|
4327
|
165 pci_config_read(pci_info.bus, pci_info.card, pci_info.func, 0x40,
|
|
166 4, &card_option);
|
|
167 printf("card_option: %x\n", card_option);
|
|
168
|
4126
|
169 if (!probed)
|
|
170 {
|
|
171 printf("Driver was not probed but is being initialized\n");
|
|
172 return(EINTR);
|
|
173 }
|
|
174
|
4327
|
175 ctrl_base = map_phys_mem(pci_info.base0, 0x00800000);
|
|
176 if (ctrl_base == (void *)-1)
|
|
177 return(ENOMEM);
|
|
178 fb_base = map_phys_mem(pci_info.base1, 0x01000000);
|
|
179 if (fb_base == (void *)-1)
|
4126
|
180 return(ENOMEM);
|
|
181
|
4327
|
182 printf("ctrl_base: %p, fb_base: %p\n", ctrl_base, fb_base);
|
|
183
|
|
184 PFB = ctrl_base+0x00100000;
|
|
185 PGRAPH = ctrl_base+0x00400000;
|
|
186 PRAMIN = ctrl_base+0x00710000;
|
|
187 FIFO = ctrl_base+0x00800000;
|
|
188 PCIO = ctrl_base+0x00601000;
|
|
189 PMC = ctrl_base+0x00000000;
|
|
190 printf("pfb: %p, pgraph: %p, pramin: %p, fifo: %p, pcio: %p\n",
|
|
191 PFB, PGRAPH, PRAMIN, FIFO, PCIO);
|
|
192
|
|
193 ScaledImage = FIFO+0x8000/4;
|
|
194 printf("ScaledImage: %p\n", ScaledImage);
|
|
195
|
|
196 /* unlock */
|
|
197 CRTCout(0x11, 0xff);
|
|
198
|
|
199 printf("fifo_free: %d\n", ScaledImage->fifo_free);
|
|
200
|
|
201 RIVA_FIFO_FREE(ScaledImage, 10);
|
|
202
|
|
203 dump_scaledimage(ScaledImage);
|
|
204
|
|
205 /* create scaled image object */
|
|
206 *(PRAMIN+0x518) = 0x0100A037;
|
|
207 *(PRAMIN+0x519) = 0x00000C02;
|
|
208
|
|
209 /* put scaled image object into subchannel */
|
|
210 *(FIFO+0x2000) = 0x80000011;
|
|
211
|
|
212 /* ram size detection */
|
|
213 switch(nv_card_id.core)
|
|
214 {
|
|
215 case 5:
|
|
216 {
|
|
217 if (*(PFB+0x0) & 0x00000100)
|
|
218 {
|
|
219 printf("first ver\n");
|
|
220 ram_size = ((*(PFB+0x0) >> 12) & 0x0f) * 1024 * 2 + 1024 * 2;
|
|
221 }
|
|
222 else
|
|
223 {
|
|
224 printf("second ver (code: %d)\n",
|
|
225 *(PFB+0x0) & 0x00000003);
|
|
226 switch(*(PFB+0x0) & 0x00000003)
|
|
227 {
|
|
228 case 0:
|
|
229 ram_size = 1024*32;
|
|
230 break;
|
|
231 case 1:
|
|
232 ram_size = 1024*4;
|
|
233 break;
|
|
234 case 2:
|
|
235 ram_size = 1024*8;
|
|
236 break;
|
|
237 case 3:
|
|
238 ram_size = 1024*16;
|
|
239 break;
|
|
240 default:
|
|
241 printf("Unknown ram size code: %d\n",
|
|
242 *(PFB+0x0) & 0x00000003);
|
|
243 break;
|
|
244 }
|
|
245 }
|
|
246 break;
|
|
247 }
|
|
248 default:
|
|
249 printf("Unknown core: %d\n", nv_card_id.core);
|
|
250 }
|
|
251
|
|
252 printf("ram_size: %d\n", ram_size);
|
|
253 return 0;
|
4126
|
254 }
|
|
255
|
|
256 void vixDestroy(void)
|
|
257 {
|
|
258 printf("[nvidia] destory\n");
|
|
259 }
|
|
260
|
|
261 int vixGetCapability(vidix_capability_t *to)
|
|
262 {
|
|
263 memcpy(to, &nvidia_cap, sizeof(vidix_capability_t));
|
|
264 return(0);
|
|
265 }
|
|
266
|
|
267 int vixQueryFourcc(vidix_fourcc_t *to)
|
|
268 {
|
|
269 printf("[nvidia] query fourcc (%x)\n", to->fourcc);
|
4327
|
270 to->flags = 0;
|
|
271 to->depth = VID_DEPTH_32BPP;
|
4126
|
272 return 0;
|
|
273 }
|
|
274
|
|
275 int vixConfigPlayback(vidix_playback_t *info)
|
|
276 {
|
4327
|
277 int fb_pixel_size = 32/8;
|
|
278 int fb_line_len = 1280*4;
|
|
279 char buffer = 0;
|
|
280 int offset = 0;
|
|
281 int x,y,h,w;
|
|
282 int bpp = 32 >> 3;
|
|
283 int size;
|
|
284
|
4126
|
285 printf("[nvidia] config playback\n");
|
|
286
|
4327
|
287 x = info->src.x;
|
|
288 y = info->src.y;
|
|
289 h = info->src.h;
|
|
290 w = info->src.w;
|
|
291
|
|
292 w = (w + 1) & ~1;
|
|
293
|
|
294 size = h * (((w << 1) + 63) & ~63) / bpp;
|
|
295
|
|
296
|
|
297 PMC[(0x8900/4)+buffer] = offset;
|
|
298 PMC[(0x8928/4)+buffer] = (h << 16) | w;
|
|
299 PMC[(0x8930/4)+buffer] = ((y << 4) & 0xffff0000) | (x >> 12);
|
|
300 PMC[(0x8938/4)+buffer] = (w << 20) / info->dest.w;
|
|
301 PMC[(0x8938/4)+buffer] = (h << 20) / info->dest.h;
|
|
302
|
|
303 info->dga_addr = fb_base + (info->dest.w - info->src.w) * fb_pixel_size /
|
|
304 2 + (info->dest.h - info->src.h) * fb_line_len / 2;
|
|
305
|
|
306 info->num_frames = 1;
|
4126
|
307 info->frame_size = info->src.w*info->src.h+(info->src.w*info->src.h)/2;
|
4327
|
308 info->offsets[0] = 0;
|
|
309 info->offset.y = 0;
|
|
310 info->offset.v = ((info->src.w + 31) & ~31) * info->src.h;
|
|
311 info->offset.u = info->offset.v+((info->src.w + 31) & ~31) * info->src.h / 4;
|
|
312 // info->dga_addr = malloc(info->num_frames*info->frame_size);
|
4126
|
313 return 0;
|
|
314 }
|
|
315
|
|
316 int vixPlaybackOn(void)
|
|
317 {
|
|
318 printf("[nvidia] playback on\n");
|
|
319 return 0;
|
|
320 }
|
|
321
|
|
322 int vixPlaybackOff(void)
|
|
323 {
|
|
324 printf("[nvidia] playback off\n");
|
|
325 return 0;
|
|
326 }
|