1 /*
2  * Copyright 2015 Patrick Rudolph <siro@das-labor.org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22 
23 #include <stdio.h>
24 #include <string.h>
25 #include "adapter9.h"
26 
27 #define DBG_CHANNEL DBG_ADAPTER
28 
29 /* prototypes */
30 void
31 d3d_match_vendor_id( D3DADAPTER_IDENTIFIER9* drvid,
32         unsigned fallback_ven,
33         unsigned fallback_dev,
34         const char* fallback_name );
35 void d3d_fill_driver_version(D3DADAPTER_IDENTIFIER9* drvid);
36 void d3d_fill_cardname(D3DADAPTER_IDENTIFIER9* drvid);
37 
38 enum d3d_vendor_id
39 {
40     HW_VENDOR_SOFTWARE              = 0x0000,
41     HW_VENDOR_AMD                   = 0x1002,
42     HW_VENDOR_NVIDIA                = 0x10de,
43     HW_VENDOR_VMWARE                = 0x15ad,
44     HW_VENDOR_INTEL                 = 0x8086,
45 };
46 
47 struct card_lookup_table {
48     const char *mesaname;
49     const char *d3d9name;
50 }
51 cards_amd[] = {
52     {"HAWAII",                      "AMD Radeon R9 290"},
53     {"KAVERI",                      "AMD Radeon(TM) R7 Graphics"},
54     {"KABINI",                      "AMD Radeon HD 8400 / R3 Series"},
55     {"BONAIRE",                     "AMD Radeon HD 8770"},
56     {"OLAND",                       "AMD Radeon HD 8670"},
57     {"HAINAN",                      "AMD Radeon HD 8600M Series"},
58     {"TAHITI",                      "AMD Radeon HD 7900 Series"},
59     {"PITCAIRN",                    "AMD Radeon HD 7800 Series"},
60     {"CAPE VERDE",                  "AMD Radeon HD 7700 Series"},
61     {"ARUBA",                       "AMD Radeon HD 7660D"},
62     {"CAYMAN",                      "AMD Radeon HD 6900 Series"},
63     {"BARTS",                       "AMD Radeon HD 6800 Series"},
64     {"TURKS",                       "AMD Radeon HD 6600 Series"},
65     {"SUMO2",                       "AMD Radeon HD 6410D"},
66     {"SUMO",                        "AMD Radeon HD 6550D"},
67     {"CAICOS",                      "AMD Radeon HD 6400 Series"},
68     {"PALM",                        "AMD Radeon HD 6300 series Graphics"},
69     {"HEMLOCK",                     "ATI Radeon HD 5900 Series"},
70     {"CYPRESS",                     "ATI Radeon HD 5800 Series"},
71     {"JUNIPER",                     "ATI Radeon HD 5700 Series"},
72     {"REDWOOD",                     "ATI Radeon HD 5600 Series"},
73     {"CEDAR",                       "ATI Radeon HD 5500 Series"},
74     {"R700",                        "ATI Radeon HD 4800 Series"},
75     {"RV790",                       "ATI Radeon HD 4800 Series"},
76     {"RV770",                       "ATI Radeon HD 4800 Series"},
77     {"RV740",                       "ATI Radeon HD 4700 Series"},
78     {"RV730",                       "ATI Radeon HD 4600 Series"},
79     {"RV710",                       "ATI Radeon HD 4350"},
80     {"RS880",                       "ATI Mobility Radeon HD 4200"},
81     {"RS780",                       "ATI Radeon HD 3200 Graphics"},
82     {"R680",                        "ATI Radeon HD 2900 XT"},
83     {"R600",                        "ATI Radeon HD 2900 XT"},
84     {"RV670",                       "ATI Radeon HD 2900 XT"},
85     {"RV635",                       "ATI Mobility Radeon HD 2600"},
86     {"RV630",                       "ATI Mobility Radeon HD 2600"},
87     {"RV620",                       "ATI Mobility Radeon HD 2350"},
88     {"RV610",                       "ATI Mobility Radeon HD 2350"},
89     {"R580",                        "ATI Radeon X1600 Series"},
90     {"R520",                        "ATI Radeon X1600 Series"},
91     {"RV570",                       "ATI Radeon X1600 Series"},
92     {"RV560",                       "ATI Radeon X1600 Series"},
93     {"RV535",                       "ATI Radeon X1600 Series"},
94     {"RV530",                       "ATI Radeon X1600 Series"},
95     {"RV516",                       "ATI Radeon X700 SE"},
96     {"RV515",                       "ATI Radeon X700 SE"},
97     {"R481",                        "ATI Radeon X700 SE"},
98     {"R480",                        "ATI Radeon X700 SE"},
99     {"R430",                        "ATI Radeon X700 SE"},
100     {"R423",                        "ATI Radeon X700 SE"},
101     {"R420",                        "ATI Radeon X700 SE"},
102     {"R410",                        "ATI Radeon X700 SE"},
103     {"RV410",                       "ATI Radeon X700 SE"},
104     {"RS740",                       "ATI RADEON XPRESS 200M Series"},
105     {"RS690",                       "ATI RADEON XPRESS 200M Series"},
106     {"RS600",                       "ATI RADEON XPRESS 200M Series"},
107     {"RS485",                       "ATI RADEON XPRESS 200M Series"},
108     {"RS482",                       "ATI RADEON XPRESS 200M Series"},
109     {"RS480",                       "ATI RADEON XPRESS 200M Series"},
110     {"RS400",                       "ATI RADEON XPRESS 200M Series"},
111     {"R360",                        "ATI Radeon 9500"},
112     {"R350",                        "ATI Radeon 9500"},
113     {"R300",                        "ATI Radeon 9500"},
114     {"RV370",                       "ATI Radeon 9500"},
115     {"RV360",                       "ATI Radeon 9500"},
116     {"RV351",                       "ATI Radeon 9500"},
117     {"RV350",                       "ATI Radeon 9500"},
118 },
119 cards_nvidia[] =
120 {
121     {"NV124",                       "NVIDIA GeForce GTX 970"},
122     {"NV117",                       "NVIDIA GeForce GTX 750"},
123     {"NVF1",                        "NVIDIA GeForce GTX 780 Ti"},
124     {"NVF0",                        "NVIDIA GeForce GTX 780"},
125     {"NVE6",                        "NVIDIA GeForce GTX 770M"},
126     {"NVE4",                        "NVIDIA GeForce GTX 680"},
127     {"NVD9",                        "NVIDIA GeForce GT 520"},
128     {"NVCF",                        "NVIDIA GeForce GTX 550 Ti"},
129     {"NVCE",                        "NVIDIA GeForce GTX 560"},
130     {"NVC8",                        "NVIDIA GeForce GTX 570"},
131     {"NVC4",                        "NVIDIA GeForce GTX 460"},
132     {"NVC3",                        "NVIDIA GeForce GT 440"},
133     {"NVC1",                        "NVIDIA GeForce GT 420"},
134     {"NVC0",                        "NVIDIA GeForce GTX 480"},
135     {"NVAF",                        "NVIDIA GeForce GT 320M"},
136     {"NVAC",                        "NVIDIA GeForce 8200"},
137     {"NVAA",                        "NVIDIA GeForce 8200"},
138     {"NVA8",                        "NVIDIA GeForce 210"},
139     {"NVA5",                        "NVIDIA GeForce GT 220"},
140     {"NVA3",                        "NVIDIA GeForce GT 240"},
141     {"NVA0",                        "NVIDIA GeForce GTX 280"},
142     {"NV98",                        "NVIDIA GeForce 9200"},
143     {"NV96",                        "NVIDIA GeForce 9400 GT"},
144     {"NV94",                        "NVIDIA GeForce 9600 GT"},
145     {"NV92",                        "NVIDIA GeForce 9800 GT"},
146     {"NV86",                        "NVIDIA GeForce 8500 GT"},
147     {"NV84",                        "NVIDIA GeForce 8600 GT"},
148     {"NV50",                        "NVIDIA GeForce 8800 GTX"},
149     {"NV68",                        "NVIDIA GeForce 6200"},
150     {"NV67",                        "NVIDIA GeForce 6200"},
151     {"NV63",                        "NVIDIA GeForce 6200"},
152     {"NV4E",                        "NVIDIA GeForce 6200"},
153     {"NV4C",                        "NVIDIA GeForce 6200"},
154     {"NV4B",                        "NVIDIA GeForce 7600 GT"},
155     {"NV4A",                        "NVIDIA GeForce 6200"},
156     {"NV49",                        "NVIDIA GeForce 7800 GT"},
157     {"NV47",                        "NVIDIA GeForce 7800 GT"},
158     {"NV46",                        "NVIDIA GeForce Go 7400",},
159     {"NV45",                        "NVIDIA GeForce 6800"},
160     {"NV44",                        "NVIDIA GeForce 6200"},
161     {"NV43",                        "NVIDIA GeForce 6600 GT"},
162     {"NV42",                        "NVIDIA GeForce 6800"},
163     {"NV41",                        "NVIDIA GeForce 6800"},
164     {"NV40",                        "NVIDIA GeForce 6800"},
165     {"NV38",                        "NVIDIA GeForce FX 5800"},
166     {"NV36",                        "NVIDIA GeForce FX 5800"},
167     {"NV35",                        "NVIDIA GeForce FX 5800"},
168     {"NV34",                        "NVIDIA GeForce FX 5200"},
169     {"NV31",                        "NVIDIA GeForce FX 5600"},
170     {"NV30",                        "NVIDIA GeForce FX 5800"},
171     {"nv28",                        "NVIDIA GeForce4 Ti 4200"},
172     {"nv25",                        "NVIDIA GeForce4 Ti 4200"},
173     {"nv20",                        "NVIDIA GeForce3"},
174     {"nv1F",                        "NVIDIA GeForce4 MX 460"},
175     {"nv1A",                        "NVIDIA GeForce2 GTS/GeForce2 Pro"},
176     {"nv18",                        "NVIDIA GeForce4 MX 460"},
177     {"nv17",                        "NVIDIA GeForce4 MX 460"},
178     {"nv16",                        "NVIDIA GeForce2 GTS/GeForce2 Pro"},
179     {"nv15",                        "NVIDIA GeForce2 GTS/GeForce2 Pro"},
180     {"nv11",                        "NVIDIA GeForce2 MX/MX 400"},
181     {"nv10",                        "NVIDIA GeForce 256"},
182 },
183 cards_vmware[] =
184 {
185     {"SVGA3D",                      "VMware SVGA 3D (Microsoft Corporation - WDDM)"},
186 },
187 cards_intel[] =
188 {
189     {"Haswell Mobile",              "Intel(R) Haswell Mobile"},
190     {"Ivybridge Server",            "Intel(R) Ivybridge Server"},
191     {"Ivybridge Mobile",            "Intel(R) Ivybridge Mobile"},
192     {"Ivybridge Desktop",           "Intel(R) Ivybridge Desktop"},
193     {"Sandybridge Server",          "Intel(R) Sandybridge Server"},
194     {"Sandybridge Mobile",          "Intel(R) Sandybridge Mobile"},
195     {"Sandybridge Desktop",         "Intel(R) Sandybridge Desktop"},
196     {"Ironlake Mobile",             "Intel(R) Ironlake Mobile"},
197     {"Ironlake Desktop",            "Intel(R) Ironlake Desktop"},
198     {"B43",                         "Intel(R) B43"},
199     {"G41",                         "Intel(R) G41"},
200     {"G45",                         "Intel(R) G45/G43"},
201     {"Q45",                         "Intel(R) Q45/Q43"},
202     {"Integrated Graphics Device",  "Intel(R) Integrated Graphics Device"},
203     {"GM45",                        "Mobile Intel(R) GM45 Express Chipset Family"},
204     {"965GME",                      "Intel(R) 965GME"},
205     {"965GM",                       "Mobile Intel(R) 965 Express Chipset Family"},
206     {"946GZ",                       "Intel(R) 946GZ"},
207     {"965G",                        "Intel(R) 965G"},
208     {"965Q",                        "Intel(R) 965Q"},
209     {"Pineview M",                  "Intel(R) IGD"},
210     {"Pineview G",                  "Intel(R) IGD"},
211     {"IGD",                         "Intel(R) IGD"},
212     {"Q33",                         "Intel(R) Q33"},
213     {"G33",                         "Intel(R) G33"},
214     {"Q35",                         "Intel(R) Q35"},
215     {"945GME",                      "Intel(R) 945GME"},
216     {"945GM",                       "Mobile Intel(R) 945GM Express Chipset Family"},
217     {"945G",                        "Intel(R) 945G"},
218     {"915GM",                       "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family"},
219     {"E7221G",                      "Intel(R) E7221G"},
220     {"915G",                        "Intel(R) 82915G/GV/910GL Express Chipset Family"},
221     {"865G",                        "Intel(R) 82865G Graphics Controller"},
222     {"845G",                        "Intel(R) 845G"},
223     {"855GM",                       "Intel(R) 82852/82855 GM/GME Graphics Controller"},
224     {"830M",                        "Intel(R) 82830M Graphics Controller"},
225 };
226 
227 /* override VendorId, DeviceId and Description for unknown vendors */
228 void
d3d_match_vendor_id(D3DADAPTER_IDENTIFIER9 * drvid,unsigned fallback_ven,unsigned fallback_dev,const char * fallback_name)229 d3d_match_vendor_id( D3DADAPTER_IDENTIFIER9* drvid,
230         unsigned fallback_ven,
231         unsigned fallback_dev,
232         const char* fallback_name )
233 {
234     if (drvid->VendorId == HW_VENDOR_INTEL ||
235         drvid->VendorId == HW_VENDOR_VMWARE ||
236         drvid->VendorId == HW_VENDOR_AMD ||
237         drvid->VendorId == HW_VENDOR_NVIDIA)
238         return;
239 
240     DBG("unknown vendor 0x4%x, emulating 0x4%x\n", drvid->VendorId, fallback_ven);
241     drvid->VendorId = fallback_ven;
242     drvid->DeviceId = fallback_dev;
243     snprintf(drvid->Description, sizeof(drvid->Description), "%s", fallback_name);
244 }
245 
246 /* fill in driver name and version */
d3d_fill_driver_version(D3DADAPTER_IDENTIFIER9 * drvid)247 void d3d_fill_driver_version(D3DADAPTER_IDENTIFIER9* drvid) {
248     switch (drvid->VendorId) {
249     case HW_VENDOR_INTEL:
250         drvid->DriverVersionLowPart = 0x000A0682;
251         drvid->DriverVersionHighPart = 0x0006000F;
252         strncpy(drvid->Driver, "igdumd32.dll", sizeof(drvid->Driver));
253         break;
254     case HW_VENDOR_VMWARE:
255         drvid->DriverVersionLowPart = 0x0001046E;
256         drvid->DriverVersionHighPart = 0x0006000E;
257         strncpy(drvid->Driver, "vm3dum.dll", sizeof(drvid->Driver));
258         break;
259     case HW_VENDOR_AMD:
260         drvid->DriverVersionLowPart = 0x000A0500;
261         drvid->DriverVersionHighPart = 0x00060011;
262         strncpy(drvid->Driver, "atiumdag.dll", sizeof(drvid->Driver));
263         break;
264     case HW_VENDOR_NVIDIA:
265         drvid->DriverVersionLowPart = 0x000D0FD4;
266         drvid->DriverVersionHighPart = 0x00060012;
267         strncpy(drvid->Driver, "nvd3dum.dll", sizeof(drvid->Driver));
268         break;
269     default:
270         break;
271     }
272 }
273 
274 /* try to match the device name and override it with Windows like device names */
d3d_fill_cardname(D3DADAPTER_IDENTIFIER9 * drvid)275 void d3d_fill_cardname(D3DADAPTER_IDENTIFIER9* drvid) {
276     unsigned i;
277     switch (drvid->VendorId) {
278     case HW_VENDOR_INTEL:
279         for (i = 0; i < sizeof(cards_intel) / sizeof(cards_intel[0]); i++) {
280             if (strstr(drvid->Description, cards_intel[i].mesaname)) {
281                 snprintf(drvid->Description, sizeof(drvid->Description),
282                          "%s", cards_intel[i].d3d9name);
283                 return;
284             }
285         }
286         /* use a fall-back if nothing matches */
287         DBG("Unknown card name %s!\n", drvid->DeviceName);
288         snprintf(drvid->Description, sizeof(drvid->Description),
289                  "%s", cards_intel[0].d3d9name);
290         break;
291     case HW_VENDOR_VMWARE:
292         for (i = 0; i < sizeof(cards_vmware) / sizeof(cards_vmware[0]); i++) {
293             if (strstr(drvid->Description, cards_vmware[i].mesaname)) {
294                 snprintf(drvid->Description, sizeof(drvid->Description),
295                          "%s", cards_vmware[i].d3d9name);
296                 return;
297             }
298         }
299         /* use a fall-back if nothing matches */
300         DBG("Unknown card name %s!\n", drvid->DeviceName);
301         snprintf(drvid->Description, sizeof(drvid->Description),
302                  "%s", cards_vmware[0].d3d9name);
303         break;
304     case HW_VENDOR_AMD:
305         for (i = 0; i < sizeof(cards_amd) / sizeof(cards_amd[0]); i++) {
306             if (strstr(drvid->Description, cards_amd[i].mesaname)) {
307                 snprintf(drvid->Description, sizeof(drvid->Description),
308                          "%s", cards_amd[i].d3d9name);
309                 return;
310             }
311         }
312         /* use a fall-back if nothing matches */
313         DBG("Unknown card name %s!\n", drvid->DeviceName);
314         snprintf(drvid->Description, sizeof(drvid->Description),
315                  "%s", cards_amd[0].d3d9name);
316         break;
317     case HW_VENDOR_NVIDIA:
318         for (i = 0; i < sizeof(cards_nvidia) / sizeof(cards_nvidia[0]); i++) {
319             if (strstr(drvid->Description, cards_nvidia[i].mesaname)) {
320                 snprintf(drvid->Description, sizeof(drvid->Description),
321                          "%s", cards_nvidia[i].d3d9name);
322                 return;
323             }
324         }
325         /* use a fall-back if nothing matches */
326         DBG("Unknown card name %s!\n", drvid->DeviceName);
327         snprintf(drvid->Description, sizeof(drvid->Description),
328                  "%s", cards_nvidia[0].d3d9name);
329         break;
330     default:
331         break;
332     }
333 }
334