1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/scanpci/xf86ScanPci.c,v 1.13 2003/08/24 17:37:10 dawes Exp $ */
/*
* Display the Subsystem Vendor Id and Subsystem Id in order to identify
* the cards installed in this computer
*
* A lot of this comes from Robin Cutshaw's scanpci
*
*/
/*
* Copyright (c) 1995-2002 by The XFree86 Project, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of the copyright holder(s)
* and author(s) shall not be used in advertising or otherwise to promote
* the sale, use or other dealings in this Software without prior written
* authorization from the copyright holder(s) and author(s).
*/
/*
* This file is used to build both the scanpci and pcidata modules.
* The interfaces have changed compared with XFree86 4.2.0 and earlier.
* The data is no longer exported directly. Lookup functions are provided.
* This means that the data format can change in the future without affecting
* the exported interfaces.
*
* The namespaces for pcidata and scanpci clash, so both modules can't be
* loaded at the same time. The X server should only load the scanpci module
* when run with the '-scanpci' flag. The main difference between the
* two modules is size. pcidata only holds the subset of data that is
* "interesting" to the X server. "Interesting" is determined by the
* PCI_VENDOR_* defines in ../common/xf86PciInfo.h.
*/
/* XXX This is including a lot of stuff that modules should not include! */
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include <X11/X.h>
#include "os.h"
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86Pci.h"
#include "xf86_OSproc.h"
#ifndef IN_MODULE
#include <ctype.h>
#include <stdlib.h>
#else
#include <xf86_ansic.h>
#endif
#ifndef PCIDATA
#define VENDOR_INCLUDE_NONVIDEO
#endif
#define INIT_SUBSYS_INFO
#define INIT_VENDOR_SUBSYS_INFO
#include "xf86PciStr.h"
#include "xf86PciIds.h"
#include "xf86ScanPci.h"
/*
* PCI classes that have messages printed always. The others are only
* have a message printed when the vendor/dev IDs are recognised.
*/
#define PCIALWAYSPRINTCLASSES(b,s) \
(((b) == PCI_CLASS_PREHISTORIC && (s) == PCI_SUBCLASS_PREHISTORIC_VGA) || \
((b) == PCI_CLASS_DISPLAY) || \
((b) == PCI_CLASS_MULTIMEDIA && (s) == PCI_SUBCLASS_MULTIMEDIA_VIDEO))
#ifdef XFree86LOADER
#include "xf86Module.h"
#ifdef PCIDATA
static XF86ModuleVersionInfo pciDataVersRec = {
"pcidata",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XORG_VERSION_CURRENT,
1, 0, 0,
ABI_CLASS_VIDEODRV,
ABI_VIDEODRV_VERSION,
NULL,
{0, 0, 0, 0}
};
XF86ModuleData pcidataModuleData = { &pciDataVersRec, NULL, NULL };
#else
static XF86ModuleVersionInfo scanPciVersRec = {
"scanpci",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XORG_VERSION_CURRENT,
1, 0, 0,
ABI_CLASS_VIDEODRV,
ABI_VIDEODRV_VERSION,
NULL,
{0, 0, 0, 0}
};
XF86ModuleData scanpciModuleData = { &scanPciVersRec, NULL, NULL };
#endif /* PCIDATA */
#endif /* XFree86LOADER */
/* Initialisation/Close hooks, in case they're ever needed. */
Bool
ScanPciSetupPciIds(void)
{
return TRUE;
}
void
ScanPciClosePciIds(void)
{
return;
}
/*
* The return value is the number of strings found, or -1 for an error.
* Requested strings that aren't found are set to NULL.
*/
int
ScanPciFindPciNamesByDevice(unsigned short vendor, unsigned short device,
unsigned short svendor, unsigned short subsys,
const char **vname, const char **dname,
const char **svname, const char **sname)
{
int i, j, k;
const pciDeviceInfo **pDev;
const pciSubsystemInfo **pSub;
/* It's an error to not provide the Vendor */
if (vendor == NOVENDOR)
return -1;
/* Initialise returns requested/provided to NULL */
if (vname)
*vname = NULL;
if (device != NODEVICE && dname)
*dname = NULL;
if (svendor != NOVENDOR && svname)
*svname = NULL;
if (subsys != NOSUBSYS && sname)
*sname = NULL;
for (i = 0; pciVendorInfoList[i].VendorName; i++) {
if (vendor == pciVendorInfoList[i].VendorID) {
if (vname) {
*vname = pciVendorInfoList[i].VendorName;
}
if (device == NODEVICE) {
return 1;
}
pDev = pciVendorInfoList[i].Device;
if (!pDev) {
return 1;
}
for (j = 0; pDev[j]; j++) {
if (device == pDev[j]->DeviceID) {
if (dname) {
*dname = pDev[j]->DeviceName;
}
if (svendor == NOVENDOR) {
return 2;
}
for (k = 0; pciVendorInfoList[k].VendorName; k++) {
if (svendor &&
svendor == pciVendorInfoList[k].VendorID) {
if (svname) {
*svname = pciVendorInfoList[k].VendorName;
}
if (subsys == NOSUBSYS) {
return 3;
}
break;
}
}
if (!pciVendorInfoList[k].VendorName) {
return 2;
}
pSub = pDev[j]->Subsystem;
if (!pSub) {
return 3;
}
for (k = 0; pSub[k]; k++) {
if (svendor == pSub[k]->VendorID &&
subsys == pSub[k]->SubsystemID) {
if (sname)
*sname = pSub[k]->SubsystemName;
return 4;
}
}
/* No vendor/subsys match */
return 3;
}
}
/* No device match */
return 1;
}
}
/* No vendor match */
return 0;
}
Bool
ScanPciFindPciNamesBySubsys(unsigned short svendor, unsigned short subsys,
const char **svname, const char **sname)
{
int i, j;
const pciSubsystemInfo **pSub;
/* It's an error to not provide the Vendor */
if (svendor == NOVENDOR)
return -1;
/* Initialise returns requested/provided to NULL */
if (svname)
*svname = NULL;
if (subsys != NOSUBSYS && sname)
*sname = NULL;
for (i = 0; pciVendorSubsysInfoList[i].VendorName; i++) {
if (svendor == pciVendorSubsysInfoList[i].VendorID) {
if (svname) {
*svname = pciVendorSubsysInfoList[i].VendorName;
}
if (subsys == NOSUBSYS) {
return 1;
}
pSub = pciVendorSubsysInfoList[i].Subsystem;
if (!pSub) {
return 1;
}
for (j = 0; pSub[j]; j++) {
if (subsys == pSub[j]->SubsystemID) {
if (sname) {
*sname = pSub[j]->SubsystemName;
}
}
}
/* No subsys match */
return 1;
}
}
/* No vendor match */
return 0;
}
CARD32
ScanPciFindPciClassBySubsys(unsigned short vendor, unsigned short subsys)
{
int i, j;
const pciSubsystemInfo **pSub;
if (vendor == NOVENDOR || subsys == NOSUBSYS)
return 0;
for (i = 0; pciVendorSubsysInfoList[i].VendorName; i++) {
if (vendor == pciVendorSubsysInfoList[i].VendorID) {
pSub = pciVendorSubsysInfoList[i].Subsystem;
if (!pSub) {
return 0;
}
for (j = 0; pSub[j]; j++) {
if (subsys == pSub[j]->SubsystemID) {
return pSub[j]->class;
}
}
break;
}
}
return 0;
}
CARD32
ScanPciFindPciClassByDevice(unsigned short vendor, unsigned short device)
{
int i, j;
const pciDeviceInfo **pDev;
if (vendor == NOVENDOR || device == NODEVICE)
return 0;
for (i = 0; pciVendorInfoList[i].VendorName; i++) {
if (vendor == pciVendorInfoList[i].VendorID) {
pDev = pciVendorInfoList[i].Device;
if (!pDev) {
return 0;
}
for (j = 0; pDev[j]; j++) {
if (device == pDev[j]->DeviceID) {
return pDev[j]->class;
}
}
break;
}
}
return 0;
}
#ifndef PCIDATA
void
ScanPciDisplayPCICardInfo(int verbosity)
{
pciConfigPtr pcrp, *pcrpp;
int i;
xf86EnableIO();
pcrpp = xf86scanpci(0);
if (pcrpp == NULL) {
xf86MsgVerb(X_NONE,0,"No PCI info available\n");
return;
}
xf86MsgVerb(X_NONE,0,"Probing for PCI devices (Bus:Device:Function)\n\n");
for (i = 0; (pcrp = pcrpp[i]); i++) {
const char *svendorname = NULL, *subsysname = NULL;
const char *vendorname = NULL, *devicename = NULL;
Bool noCard = FALSE;
const char *prefix1 = "", *prefix2 = "";
xf86MsgVerb(X_NONE, -verbosity, "(%d:%d:%d) ",
pcrp->busnum, pcrp->devnum, pcrp->funcnum);
/*
* Lookup as much as we can about the device.
*/
if (pcrp->pci_subsys_vendor || pcrp->pci_subsys_card) {
ScanPciFindPciNamesByDevice(pcrp->pci_vendor, pcrp->pci_device,
NOVENDOR, NOSUBSYS,
&vendorname, &devicename, NULL, NULL);
} else {
ScanPciFindPciNamesByDevice(pcrp->pci_vendor, pcrp->pci_device,
pcrp->pci_subsys_vendor,
pcrp->pci_subsys_card,
&vendorname, &devicename,
&svendorname, &subsysname);
}
if (svendorname)
xf86MsgVerb(X_NONE, -verbosity, "%s ", svendorname);
if (subsysname)
xf86MsgVerb(X_NONE, -verbosity, "%s ", subsysname);
if (svendorname && !subsysname) {
if (pcrp->pci_subsys_card && pcrp->pci_subsys_card != NOSUBSYS) {
xf86MsgVerb(X_NONE, -verbosity, "unknown card (0x%04x) ",
pcrp->pci_subsys_card);
} else {
xf86MsgVerb(X_NONE, -verbosity, "card ");
}
}
if (!svendorname && !subsysname) {
/*
* We didn't find a text representation of the information
* about the card.
*/
if (pcrp->pci_subsys_vendor || pcrp->pci_subsys_card) {
/*
* If there was information and we just couldn't interpret
* it, print it out as unknown, anyway.
*/
xf86MsgVerb(X_NONE, -verbosity,
"unknown card (0x%04x/0x%04x) ",
pcrp->pci_subsys_vendor, pcrp->pci_subsys_card);
} else
noCard = TRUE;
}
if (!noCard) {
prefix1 = "using a ";
prefix2 = "using an ";
}
if (vendorname && devicename) {
xf86MsgVerb(X_NONE, -verbosity,"%s%s %s\n", prefix1, vendorname,
devicename);
} else if (vendorname) {
xf86MsgVerb(X_NONE, -verbosity,
"%sunknown chip (DeviceId 0x%04x) from %s\n",
prefix2, pcrp->pci_device, vendorname);
} else {
xf86MsgVerb(X_NONE, -verbosity,
"%sunknown chipset(0x%04x/0x%04x)\n",
prefix2, pcrp->pci_vendor, pcrp->pci_device);
}
}
}
#endif
|