]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/MAI/bios_emulator/scitech/src/pm/tests/showpci.c
* Code cleanup:
[people/ms/u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / tests / showpci.c
1 /****************************************************************************
2 *
3 * SciTech OS Portability Manager Library
4 *
5 * ========================================================================
6 *
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
16 *
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
21 *
22 * ========================================================================
23 *
24 * Language: ANSI C
25 * Environment: any
26 *
27 * Description: Test program to test the PCI library functions.
28 *
29 ****************************************************************************/
30
31 #include "pmapi.h"
32 #include "pcilib.h"
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdarg.h>
37
38 /*------------------------- Global Variables ------------------------------*/
39
40 static int NumPCI = -1;
41 static PCIDeviceInfo *PCI;
42 static int *BridgeIndex;
43 static int *DeviceIndex;
44 static int NumBridges;
45 static PCIDeviceInfo *AGPBridge = NULL;
46 static int NumDevices;
47
48 /*-------------------------- Implementation -------------------------------*/
49
50 /****************************************************************************
51 REMARKS:
52 Enumerates the PCI bus and dumps the PCI configuration information to the
53 log file.
54 ****************************************************************************/
55 static void EnumeratePCI(void)
56 {
57 int i,index;
58 PCIDeviceInfo *info;
59
60 printf("Displaying enumeration of PCI bus (%d devices, %d display devices)\n",
61 NumPCI, NumDevices);
62 for (index = 0; index < NumDevices; index++)
63 printf(" Display device %d is PCI device %d\n",index,DeviceIndex[index]);
64 printf("\n");
65 printf("Bus Slot Fnc DeviceID SubSystem Rev Class IRQ Int Cmd\n");
66 for (i = 0; i < NumPCI; i++) {
67 printf("%2d %2d %2d %04X:%04X %04X:%04X %02X %02X:%02X %02X %02X %04X ",
68 PCI[i].slot.p.Bus,
69 PCI[i].slot.p.Device,
70 PCI[i].slot.p.Function,
71 PCI[i].VendorID,
72 PCI[i].DeviceID,
73 PCI[i].u.type0.SubSystemVendorID,
74 PCI[i].u.type0.SubSystemID,
75 PCI[i].RevID,
76 PCI[i].BaseClass,
77 PCI[i].SubClass,
78 PCI[i].u.type0.InterruptLine,
79 PCI[i].u.type0.InterruptPin,
80 PCI[i].Command);
81 for (index = 0; index < NumDevices; index++) {
82 if (DeviceIndex[index] == i)
83 break;
84 }
85 if (index < NumDevices)
86 printf("<- %d\n", index);
87 else
88 printf("\n");
89 }
90 printf("\n");
91 printf("DeviceID Stat Ifc Cch Lat Hdr BIST\n");
92 for (i = 0; i < NumPCI; i++) {
93 printf("%04X:%04X %04X %02X %02X %02X %02X %02X ",
94 PCI[i].VendorID,
95 PCI[i].DeviceID,
96 PCI[i].Status,
97 PCI[i].Interface,
98 PCI[i].CacheLineSize,
99 PCI[i].LatencyTimer,
100 PCI[i].HeaderType,
101 PCI[i].BIST);
102 for (index = 0; index < NumDevices; index++) {
103 if (DeviceIndex[index] == i)
104 break;
105 }
106 if (index < NumDevices)
107 printf("<- %d\n", index);
108 else
109 printf("\n");
110 }
111 printf("\n");
112 printf("DeviceID Base10h Base14h Base18h Base1Ch Base20h Base24h ROMBase\n");
113 for (i = 0; i < NumPCI; i++) {
114 printf("%04X:%04X %08lX %08lX %08lX %08lX %08lX %08lX %08lX ",
115 PCI[i].VendorID,
116 PCI[i].DeviceID,
117 PCI[i].u.type0.BaseAddress10,
118 PCI[i].u.type0.BaseAddress14,
119 PCI[i].u.type0.BaseAddress18,
120 PCI[i].u.type0.BaseAddress1C,
121 PCI[i].u.type0.BaseAddress20,
122 PCI[i].u.type0.BaseAddress24,
123 PCI[i].u.type0.ROMBaseAddress);
124 for (index = 0; index < NumDevices; index++) {
125 if (DeviceIndex[index] == i)
126 break;
127 }
128 if (index < NumDevices)
129 printf("<- %d\n", index);
130 else
131 printf("\n");
132 }
133 printf("\n");
134 printf("DeviceID BAR10Len BAR14Len BAR18Len BAR1CLen BAR20Len BAR24Len ROMLen\n");
135 for (i = 0; i < NumPCI; i++) {
136 printf("%04X:%04X %08lX %08lX %08lX %08lX %08lX %08lX %08lX ",
137 PCI[i].VendorID,
138 PCI[i].DeviceID,
139 PCI[i].u.type0.BaseAddress10Len,
140 PCI[i].u.type0.BaseAddress14Len,
141 PCI[i].u.type0.BaseAddress18Len,
142 PCI[i].u.type0.BaseAddress1CLen,
143 PCI[i].u.type0.BaseAddress20Len,
144 PCI[i].u.type0.BaseAddress24Len,
145 PCI[i].u.type0.ROMBaseAddressLen);
146 for (index = 0; index < NumDevices; index++) {
147 if (DeviceIndex[index] == i)
148 break;
149 }
150 if (index < NumDevices)
151 printf("<- %d\n", index);
152 else
153 printf("\n");
154 }
155 printf("\n");
156 printf("Displaying enumeration of %d bridge devices\n",NumBridges);
157 printf("\n");
158 printf("DeviceID P# S# B# IOB IOL MemBase MemLimit PreBase PreLimit Ctrl\n");
159 for (i = 0; i < NumBridges; i++) {
160 info = (PCIDeviceInfo*)&PCI[BridgeIndex[i]];
161 printf("%04X:%04X %02X %02X %02X %04X %04X %08X %08X %08X %08X %04X\n",
162 info->VendorID,
163 info->DeviceID,
164 info->u.type1.PrimaryBusNumber,
165 info->u.type1.SecondayBusNumber,
166 info->u.type1.SubordinateBusNumber,
167 ((u16)info->u.type1.IOBase << 8) & 0xF000,
168 info->u.type1.IOLimit ?
169 ((u16)info->u.type1.IOLimit << 8) | 0xFFF : 0,
170 ((u32)info->u.type1.MemoryBase << 16) & 0xFFF00000,
171 info->u.type1.MemoryLimit ?
172 ((u32)info->u.type1.MemoryLimit << 16) | 0xFFFFF : 0,
173 ((u32)info->u.type1.PrefetchableMemoryBase << 16) & 0xFFF00000,
174 info->u.type1.PrefetchableMemoryLimit ?
175 ((u32)info->u.type1.PrefetchableMemoryLimit << 16) | 0xFFFFF : 0,
176 info->u.type1.BridgeControl);
177 }
178 printf("\n");
179 }
180
181 /****************************************************************************
182 RETURNS:
183 Number of display devices found.
184
185 REMARKS:
186 This function enumerates the number of available display devices on the
187 PCI bus, and returns the number found.
188 ****************************************************************************/
189 static int PCI_enumerateDevices(void)
190 {
191 int i,j;
192 PCIDeviceInfo *info;
193
194 /* If this is the first time we have been called, enumerate all */
195 /* devices on the PCI bus. */
196 if (NumPCI == -1) {
197 if ((NumPCI = PCI_getNumDevices()) == 0)
198 return -1;
199 PCI = malloc(NumPCI * sizeof(PCI[0]));
200 BridgeIndex = malloc(NumPCI * sizeof(BridgeIndex[0]));
201 DeviceIndex = malloc(NumPCI * sizeof(DeviceIndex[0]));
202 if (!PCI || !BridgeIndex || !DeviceIndex)
203 return -1;
204 for (i = 0; i < NumPCI; i++)
205 PCI[i].dwSize = sizeof(PCI[i]);
206 if (PCI_enumerate(PCI) == 0)
207 return -1;
208
209 /* Build a list of all PCI bridge devices */
210 for (i = 0,NumBridges = 0,BridgeIndex[0] = -1; i < NumPCI; i++) {
211 if (PCI[i].BaseClass == PCI_BRIDGE_CLASS)
212 BridgeIndex[NumBridges++] = i;
213 }
214
215 /* Now build a list of all display class devices */
216 for (i = 0,NumDevices = 1,DeviceIndex[0] = -1; i < NumPCI; i++) {
217 if (PCI_IS_DISPLAY_CLASS(&PCI[i])) {
218 if ((PCI[i].Command & 0x3) == 0x3)
219 DeviceIndex[0] = i;
220 else
221 DeviceIndex[NumDevices++] = i;
222 if (PCI[i].slot.p.Bus != 0) {
223 /* This device is on a different bus than the primary */
224 /* PCI bus, so it is probably an AGP device. Find the */
225 /* AGP bus device that controls that bus so we can */
226 /* control it. */
227 for (j = 0; j < NumBridges; j++) {
228 info = (PCIDeviceInfo*)&PCI[BridgeIndex[j]];
229 if (info->u.type1.SecondayBusNumber == PCI[i].slot.p.Bus) {
230 AGPBridge = info;
231 break;
232 }
233 }
234 }
235 }
236 }
237
238 /* Enumerate all PCI and bridge devices to standard output */
239 EnumeratePCI();
240 }
241 return NumDevices;
242 }
243
244 int main(void)
245 {
246 /* Enumerate all PCI devices */
247 PM_init();
248 if (PCI_enumerateDevices() < 1) {
249 printf("No PCI display devices found!\n");
250 return -1;
251 }
252 return 0;
253 }