1 | /* |
---|
2 | * Copyright (c) 1992-1998 Michael A. Cooper. |
---|
3 | * This software may be freely used and distributed provided it is not |
---|
4 | * sold for profit or used in part or in whole for commercial gain |
---|
5 | * without prior written agreement, and the author is credited |
---|
6 | * appropriately. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef lint |
---|
10 | static char *RCSid = "$Revision: 1.1.1.1 $"; |
---|
11 | #endif |
---|
12 | |
---|
13 | /* |
---|
14 | * General PCI functions |
---|
15 | */ |
---|
16 | |
---|
17 | #include "defs.h" |
---|
18 | #include "probe.h" |
---|
19 | |
---|
20 | /* |
---|
21 | * Set what PCI Device info we can by looking things up in pci.cf |
---|
22 | */ |
---|
23 | extern void PCIsetDeviceInfo(Info) |
---|
24 | PCIinfo_t *Info; |
---|
25 | { |
---|
26 | DevInfo_t *DevInfo = NULL; |
---|
27 | DevType_t *DevType = NULL; |
---|
28 | ClassType_t *ClassType = NULL; |
---|
29 | Define_t *Define; |
---|
30 | static char Buff[256]; |
---|
31 | static char Query[64]; |
---|
32 | int Len; |
---|
33 | PCIid_t VendorID; |
---|
34 | PCIid_t DeviceID; |
---|
35 | |
---|
36 | /* |
---|
37 | * Ok for empty DeviceID |
---|
38 | */ |
---|
39 | if (!Info || !Info->VendorID) |
---|
40 | return; |
---|
41 | |
---|
42 | VendorID = Info->VendorID; |
---|
43 | DeviceID = Info->DeviceID; |
---|
44 | if (Info->DevInfo) |
---|
45 | DevInfo = Info->DevInfo; |
---|
46 | else |
---|
47 | DevInfo = Info->DevInfo = NewDevInfo(NULL); |
---|
48 | |
---|
49 | /* See if we can find the Vendor */ |
---|
50 | Define = DefGet("PCIvendor", NULL, VendorID); |
---|
51 | if (!Define) { |
---|
52 | /* |
---|
53 | * The VendorID is unknown so use the ID numbers. |
---|
54 | */ |
---|
55 | SImsg(SIM_UNKN, "PCI Vendor=0x%04x Device=0x%04x", VendorID, DeviceID); |
---|
56 | } else { |
---|
57 | /* |
---|
58 | * We found the vendor |
---|
59 | */ |
---|
60 | DevInfo->Vendor = Define->ValStr1; |
---|
61 | |
---|
62 | /* Now see if we can find a device from the vendor */ |
---|
63 | (void) snprintf(Query, sizeof(Query), "PCIdevice0x%04x", VendorID); |
---|
64 | if (Define = DefGet(Query, NULL, DeviceID)) { |
---|
65 | /* |
---|
66 | * We found the Device! |
---|
67 | */ |
---|
68 | DevInfo->Model = Define->ValStr1; |
---|
69 | |
---|
70 | if (Define->ValStr2) |
---|
71 | /* |
---|
72 | * See if we can determine the DevType |
---|
73 | */ |
---|
74 | if (DevType = TypeGetByName(Define->ValStr2)) |
---|
75 | DevInfo->Type = DevType->Type; |
---|
76 | if (Define->ValStr3) { |
---|
77 | /* |
---|
78 | * Now see if we can find the ClassType for this DevType |
---|
79 | */ |
---|
80 | if (DevType) { |
---|
81 | if (ClassType = ClassTypeGetByName(DevType->Type, |
---|
82 | Define->ValStr3)) |
---|
83 | DevInfo->ClassType = ClassType->Type; |
---|
84 | } |
---|
85 | if (!ClassType) |
---|
86 | /* Couldn't find the class type so use the name we have */ |
---|
87 | DevInfo->ModelDesc = Define->ValStr3; |
---|
88 | } |
---|
89 | } else { |
---|
90 | SImsg(SIM_UNKN, "PCI device 0x%04x from %s (0x%04x)", |
---|
91 | DeviceID, DevInfo->Vendor, VendorID); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | if (!DevType && !DevInfo->Model && !DevInfo->ModelDesc && |
---|
96 | !DevInfo->ClassType) |
---|
97 | DevInfo->ModelDesc = "PCI"; |
---|
98 | |
---|
99 | if (Info->Bus >= 0 && Info->Unit >= 0 && Info->SubUnit >= 0) { |
---|
100 | (void) snprintf(Buff, sizeof(Buff), "pci%d:%d:%d", |
---|
101 | Info->Bus, Info->Unit, Info->SubUnit); |
---|
102 | AddDevDesc(DevInfo, Buff, "PCI Name", DA_APPEND); |
---|
103 | } |
---|
104 | if (VendorID) { |
---|
105 | (void) snprintf(Buff, sizeof(Buff), "0x%04x", VendorID); |
---|
106 | AddDevDesc(DevInfo, Buff, "PCI Vendor ID", DA_APPEND); |
---|
107 | } |
---|
108 | if (DeviceID) { |
---|
109 | (void) snprintf(Buff, sizeof(Buff), "0x%04x", DeviceID); |
---|
110 | AddDevDesc(DevInfo, Buff, "PCI Device ID", DA_APPEND); |
---|
111 | } |
---|
112 | #define VI(i) ( (PCIid_t)(i) != 0 && (PCIid_t)(i) != (PCIid_t)-1 ) |
---|
113 | if (VI(Info->Class)) { |
---|
114 | (void) snprintf(Buff, sizeof(Buff), "0x%06x", Info->Class); |
---|
115 | AddDevDesc(DevInfo, Buff, "PCI Device Class", DA_APPEND); |
---|
116 | } |
---|
117 | if (VI(Info->SubDeviceID)) { |
---|
118 | (void) snprintf(Buff, sizeof(Buff), "0x%08lx", Info->SubDeviceID); |
---|
119 | AddDevDesc(DevInfo, Buff, "PCI Device Sub Vendor ID", DA_APPEND); |
---|
120 | } |
---|
121 | if (VI(Info->Revision)) { |
---|
122 | (void) snprintf(Buff, sizeof(Buff), "0x%02x", Info->Revision); |
---|
123 | AddDevDesc(DevInfo, Buff, "PCI Device Revision", DA_APPEND); |
---|
124 | } |
---|
125 | if (VI(Info->Header)) { |
---|
126 | (void) snprintf(Buff, sizeof(Buff), "0x%02x", Info->Header); |
---|
127 | AddDevDesc(DevInfo, Buff, "PCI Device Header", DA_APPEND); |
---|
128 | } |
---|
129 | #undef VI |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | * Create and return a new PCInfo_t |
---|
134 | */ |
---|
135 | extern PCIinfo_t *PCInewInfo(Info) |
---|
136 | PCIinfo_t *Info; |
---|
137 | { |
---|
138 | PCIinfo_t *New; |
---|
139 | |
---|
140 | if (Info) { |
---|
141 | (void) memset(Info, 0, sizeof(PCIinfo_t)); |
---|
142 | New = Info; |
---|
143 | } else |
---|
144 | New = (PCIinfo_t *) xcalloc(1, sizeof(PCIinfo_t)); |
---|
145 | |
---|
146 | New->Bus = New->Unit = New->SubUnit = -1; |
---|
147 | New->Header = New->Revision = New->Class = New->SubDeviceID = -1; |
---|
148 | |
---|
149 | return(New); |
---|
150 | } |
---|