This source file includes following definitions.
- pci_lookup_dev
- pci_strclass
- pci_strvendor
- pci_strdev
- burst_bridge
- sprint_dev_config
- get_pci_list
- pci_malloc
- scan_bus
- pci_init
1
2
3
4
5
6
7
8
9 #include <linux/config.h>
10 #include <linux/ptrace.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/bios32.h>
14 #include <linux/pci.h>
15 #include <linux/string.h>
16
17 #include <asm/page.h>
18
19 struct pci_bus pci_root;
20 struct pci_dev *pci_devices = 0;
21
22
23
24
25
26
27
28
29
30
31
32 #define DEVICE(vid,did,name) \
33 {PCI_VENDOR_ID_##vid, PCI_DEVICE_ID_##did, (name), 0xff}
34
35 #define BRIDGE(vid,did,name,bridge) \
36 {PCI_VENDOR_ID_##vid, PCI_DEVICE_ID_##did, (name), (bridge)}
37
38
39
40
41
42
43 struct pci_dev_info dev_info[] = {
44 DEVICE( COMPAQ, COMPAQ_1280, "QVision 1280/p"),
45 DEVICE( NCR, NCR_53C810, "53c810"),
46 DEVICE( NCR, NCR_53C820, "53c820"),
47 DEVICE( NCR, NCR_53C825, "53c825"),
48 DEVICE( NCR, NCR_53C815, "53c815"),
49 DEVICE( ATI, ATI_68800, "68800AX"),
50 DEVICE( ATI, ATI_215CT222, "215CT222"),
51 DEVICE( ATI, ATI_210888CX, "210888CX"),
52 DEVICE( ATI, ATI_210888GX, "210888GX"),
53 DEVICE( VLSI, VLSI_82C592, "82C592-FC1"),
54 DEVICE( VLSI, VLSI_82C593, "82C593-FC1"),
55 DEVICE( ADL, ADL_2301, "2301"),
56 DEVICE( NS, NS_87410, "87410"),
57 DEVICE( TSENG, TSENG_W32P_2, "ET4000W32P"),
58 DEVICE( TSENG, TSENG_W32P_b, "ET4000W32P rev B"),
59 DEVICE( TSENG, TSENG_W32P_c, "ET4000W32P rev C"),
60 DEVICE( TSENG, TSENG_W32P_d, "ET4000W32P rev D"),
61 DEVICE( WEITEK, WEITEK_P9000, "P9000"),
62 DEVICE( WEITEK, WEITEK_P9100, "P9100"),
63 BRIDGE( DEC, DEC_BRD, "DC21050", 0x00),
64 DEVICE( DEC, DEC_TULIP, "DC21040"),
65 DEVICE( DEC, DEC_TGA, "DC21030"),
66 DEVICE( DEC, DEC_TULIP_FAST, "DC21140"),
67 DEVICE( DEC, DEC_FDDI, "DEFPA"),
68 DEVICE( DEC, DEC_TULIP_PLUS, "DC21041"),
69 DEVICE( CIRRUS, CIRRUS_5430, "GD 5430"),
70 DEVICE( CIRRUS, CIRRUS_5434_4, "GD 5434"),
71 DEVICE( CIRRUS, CIRRUS_5434_8, "GD 5434"),
72 DEVICE( CIRRUS, CIRRUS_5436, "GD 5436"),
73 DEVICE( CIRRUS, CIRRUS_6729, "CL 6729"),
74 DEVICE( CIRRUS, CIRRUS_7542, "CL 7542"),
75 DEVICE( CIRRUS, CIRRUS_7543, "CL 7543"),
76 DEVICE( WD, WD_7197, "WD 7197"),
77 DEVICE( AMD, AMD_LANCE, "79C970"),
78 DEVICE( AMD, AMD_SCSI, "53C974"),
79 DEVICE( TRIDENT, TRIDENT_9420, "TG 9420"),
80 DEVICE( TRIDENT, TRIDENT_9440, "TG 9440"),
81 DEVICE( TRIDENT, TRIDENT_9660, "TG 9660"),
82 DEVICE( AI, AI_M1435, "M1435"),
83 DEVICE( MATROX, MATROX_MGA_2, "Atlas PX2085"),
84 DEVICE( MATROX, MATROX_MIL ,"Millenium"),
85 DEVICE( MATROX, MATROX_MGA_IMP, "MGA Impression"),
86 DEVICE( CT, CT_65545, "65545"),
87 DEVICE( FD, FD_36C70, "TMC-18C30"),
88 DEVICE( SI, SI_6201, "6201"),
89 DEVICE( SI, SI_6202, "6202"),
90 DEVICE( SI, SI_503, "85C503"),
91 DEVICE( SI, SI_501, "85C501"),
92 DEVICE( SI, SI_496, "85C496"),
93 DEVICE( SI, SI_601, "85C601"),
94 DEVICE( SI, SI_5511, "85C5511"),
95 DEVICE( SI, SI_5513, "85C5513"),
96 DEVICE( HP, HP_J2585A, "J2585A"),
97 DEVICE( PCTECH, PCTECH_RZ1000, "RZ1000 (buggy)"),
98 DEVICE( DPT, DPT, "SmartCache/Raid"),
99 DEVICE( OPTI, OPTI_82C557, "82C557"),
100 DEVICE( OPTI, OPTI_82C558, "82C558"),
101 DEVICE( OPTI, OPTI_82C621, "82C621"),
102 DEVICE( OPTI, OPTI_82C822, "82C822"),
103 DEVICE( BUSLOGIC, BUSLOGIC_946C_2,"BT-946C"),
104 DEVICE( BUSLOGIC, BUSLOGIC_946C, "BT-946C"),
105 DEVICE( BUSLOGIC, BUSLOGIC_930, "BT-930"),
106 DEVICE( PROMISE, PROMISE_5300, "DC5030"),
107 DEVICE( N9, N9_I128, "Imagine 128"),
108 DEVICE( UMC, UMC_UM8673F, "UM8673F"),
109 BRIDGE( UMC, UMC_UM8891A, "UM8891A", 0x01),
110 DEVICE( UMC, UMC_UM8886BF, "UM8886BF"),
111 DEVICE( UMC, UMC_UM8886A, "UM8886A"),
112 BRIDGE( UMC, UMC_UM8881F, "UM8881F", 0x02),
113 DEVICE( UMC, UMC_UM8886F, "UM8886F"),
114 DEVICE( UMC, UMC_UM9017F, "UM9017F"),
115 DEVICE( UMC, UMC_UM8886N, "UM8886N"),
116 DEVICE( UMC, UMC_UM8891N, "UM8891N"),
117 DEVICE( X, X_AGX016, "ITT AGX016"),
118 DEVICE( QLOGIC, QLOGIC_ISP1020, "ISP1020"),
119 DEVICE( QLOGIC, QLOGIC_ISP1022, "ISP1022"),
120 DEVICE( LEADTEK, LEADTEK_805, "S3 805"),
121 DEVICE( CONTAQ, CONTAQ_82C599, "82C599"),
122 DEVICE( CMD, CMD_640, "640 (buggy)"),
123 DEVICE( CMD, CMD_646, "646"),
124 DEVICE( VISION, VISION_QD8500, "QD-8500"),
125 DEVICE( VISION, VISION_QD8580, "QD-8580"),
126 DEVICE( SIERRA, SIERRA_STB, "STB Horizon 64"),
127 DEVICE( WINBOND, WINBOND_83769, "W83769F"),
128 DEVICE( 3COM, 3COM_3C590, "3C590 10bT"),
129 DEVICE( 3COM, 3COM_3C595TX, "3C595 100bTX"),
130 DEVICE( 3COM, 3COM_3C595T4, "3C595 100bT4"),
131 DEVICE( 3COM, 3COM_3C595MII, "3C595 100b-MII"),
132 DEVICE( AL, AL_M1445, "M1445"),
133 DEVICE( AL, AL_M1449, "M1449"),
134 DEVICE( AL, AL_M1451, "M1451"),
135 DEVICE( AL, AL_M1461, "M1461"),
136 DEVICE( AL, AL_M1489, "M1489"),
137 DEVICE( AL, AL_M4803, "M4803"),
138 DEVICE( ASP, ASP_ABP940, "ABP940"),
139 DEVICE( IMS, IMS_8849, "8849"),
140 DEVICE( TEKRAM2, TEKRAM2_690c, "DC690c"),
141 DEVICE( REALTEK, REALTEK_8029, "8029"),
142 DEVICE( VIA, VIA_82C505, "VT 82C505"),
143 DEVICE( VIA, VIA_82C561, "VT 82C561"),
144 DEVICE( VIA, VIA_82C576, "VT 82C576 3V"),
145 DEVICE( VORTEX, VORTEX_GDT, "GDT 6000b"),
146 DEVICE( EF, EF_ATM_FPGA, "155P-MF1 (FPGA)"),
147 DEVICE( EF, EF_ATM_ASIC, "155P-MF1 (ASIC)"),
148 DEVICE( IMAGINGTECH, IMAGINGTECH_ICPCI, "MVC IC-PCI"),
149 DEVICE( PLX, PLX_9060, "PCI9060 i960 bridge"),
150 DEVICE( ALLIANCE, ALLIANCE_PROMOTIO, "Promotion-6410"),
151 DEVICE( ALLIANCE, ALLIANCE_PROVIDEO, "Provideo"),
152 DEVICE( MUTECH, MUTECH_MV1000, "MV-1000"),
153 DEVICE( ZEITNET, ZEITNET_1221, "1221"),
154 DEVICE( SPECIALIX, SPECIALIX_XIO, "XIO/SIO host"),
155 DEVICE( SPECIALIX, SPECIALIX_RIO, "RIO host"),
156 DEVICE( CYCLADES, CYCLADES_Y, "Cyclome-Y"),
157 DEVICE( SYMPHONY, SYMPHONY_101, "82C101"),
158 DEVICE( TEKRAM, TEKRAM_DC290, "DC-290"),
159 DEVICE( AVANCE, AVANCE_2302, "ALG-2302"),
160 DEVICE( S3, S3_811, "Trio32/Trio64"),
161 DEVICE( S3, S3_868, "Vision 868"),
162 DEVICE( S3, S3_928, "Vision 928-P"),
163 DEVICE( S3, S3_864_1, "Vision 864-P"),
164 DEVICE( S3, S3_864_2, "Vision 864-P"),
165 DEVICE( S3, S3_964_1, "Vision 964-P"),
166 DEVICE( S3, S3_964_2, "Vision 964-P"),
167 DEVICE( S3, S3_968, "Vision 968"),
168 DEVICE( INTEL, INTEL_82375, "82375EB"),
169 BRIDGE( INTEL, INTEL_82424, "82424ZX Saturn", 0x00),
170 DEVICE( INTEL, INTEL_82378, "82378IB"),
171 DEVICE( INTEL, INTEL_82430, "82430ZX Aries"),
172 BRIDGE( INTEL, INTEL_82434, "82434LX Mercury/Neptune", 0x00),
173 DEVICE( INTEL, INTEL_7116, "SAA7116"),
174 DEVICE( INTEL, INTEL_82596, "82596"),
175 DEVICE( INTEL, INTEL_82865, "82865"),
176 DEVICE( INTEL, INTEL_82557, "82557"),
177 DEVICE( INTEL, INTEL_82437, "82437"),
178 DEVICE( INTEL, INTEL_82371_0, "82371 Triton PIIX"),
179 DEVICE( INTEL, INTEL_82371_1, "82371 Triton PIIX"),
180 DEVICE( INTEL, INTEL_P6, "Orion P6"),
181 DEVICE( ADAPTEC, ADAPTEC_7850, "AIC-7850"),
182 DEVICE( ADAPTEC, ADAPTEC_7870, "AIC-7870"),
183 DEVICE( ADAPTEC, ADAPTEC_7871, "AIC-7871"),
184 DEVICE( ADAPTEC, ADAPTEC_7872, "AIC-7872"),
185 DEVICE( ADAPTEC, ADAPTEC_7873, "AIC-7873"),
186 DEVICE( ADAPTEC, ADAPTEC_7874, "AIC-7874"),
187 DEVICE( ADAPTEC, ADAPTEC_7880, "AIC-7880U"),
188 DEVICE( ADAPTEC, ADAPTEC_7881, "AIC-7881U"),
189 DEVICE( ADAPTEC, ADAPTEC_7882, "AIC-7882U"),
190 DEVICE( ADAPTEC, ADAPTEC_7883, "AIC-7883U"),
191 DEVICE( ADAPTEC, ADAPTEC_7884, "AIC-7884U"),
192 DEVICE( ATRONICS, ATRONICS_2015, "IDE-2015PL"),
193 DEVICE( HER, HER_STING, "Stingray"),
194 DEVICE( HER, HER_STINGARK, "Stingray ARK 2000PV")
195 };
196
197
198 #ifdef CONFIG_PCI_OPTIMIZE
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 struct optimization_type {
216 const char *type;
217 const char *off;
218 const char *on;
219 } bridge_optimization[] = {
220 {"Cache L2", "write trough", "write back"},
221 {"CPU-PCI posted write", "off", "on"},
222 {"CPU-Memory posted write", "off", "on"},
223 {"PCI-Memory posted write", "off", "on"},
224 {"PCI burst", "off", "on"}
225 };
226
227 #define NUM_OPTIMIZATIONS \
228 (sizeof(bridge_optimization) / sizeof(bridge_optimization[0]))
229
230 struct bridge_mapping_type {
231 unsigned char addr;
232 unsigned char mask;
233 unsigned char value;
234 } bridge_mapping[] = {
235
236
237
238
239
240
241
242 {0x0 ,0x02 ,0x02 },
243 {0x53 ,0x02 ,0x02 },
244 {0x53 ,0x01 ,0x01 },
245 {0x54 ,0x01 ,0x01 },
246 {0x54 ,0x02 ,0x02 },
247
248
249
250
251
252 {0x50 ,0x10 ,0x00 },
253 {0x51 ,0x40 ,0x40 },
254 {0x0 ,0x0 ,0x0 },
255 {0x0 ,0x0 ,0x0 },
256 {0x0 ,0x0 ,0x0 },
257
258
259
260
261
262
263 {0x0 ,0x1 ,0x1 },
264 {0x0 ,0x2 ,0x0 },
265 {0x0 ,0x0 ,0x0 },
266 {0x0 ,0x0 ,0x0 },
267 {0x0 ,0x0 ,0x0 }
268 };
269
270 #endif
271
272
273
274
275
276 struct pci_dev_info *pci_lookup_dev(unsigned int vendor, unsigned int dev)
277 {
278 int min = 0,
279 max = sizeof(dev_info)/sizeof(dev_info[0]) - 1;
280
281 for ( ; ; )
282 {
283 int i = (min + max) >> 1;
284 long order;
285
286 order = dev_info[i].vendor - (long) vendor;
287 if (!order)
288 order = dev_info[i].device - (long) dev;
289
290 if (order < 0)
291 {
292 min = i + 1;
293 if ( min > max )
294 return 0;
295 continue;
296 }
297
298 if (order > 0)
299 {
300 max = i - 1;
301 if ( min > max )
302 return 0;
303 continue;
304 }
305
306 return & dev_info[ i ];
307 }
308 }
309
310 const char *pci_strclass (unsigned int class)
311 {
312 switch (class >> 8) {
313 case PCI_CLASS_NOT_DEFINED: return "Non-VGA device";
314 case PCI_CLASS_NOT_DEFINED_VGA: return "VGA compatible device";
315
316 case PCI_CLASS_STORAGE_SCSI: return "SCSI storage controller";
317 case PCI_CLASS_STORAGE_IDE: return "IDE interface";
318 case PCI_CLASS_STORAGE_FLOPPY: return "Floppy disk controller";
319 case PCI_CLASS_STORAGE_IPI: return "IPI bus controller";
320 case PCI_CLASS_STORAGE_RAID: return "RAID bus controller";
321 case PCI_CLASS_STORAGE_OTHER: return "Unknown mass storage controller";
322
323 case PCI_CLASS_NETWORK_ETHERNET: return "Ethernet controller";
324 case PCI_CLASS_NETWORK_TOKEN_RING: return "Token ring network controller";
325 case PCI_CLASS_NETWORK_FDDI: return "FDDI network controller";
326 case PCI_CLASS_NETWORK_ATM: return "ATM network controller";
327 case PCI_CLASS_NETWORK_OTHER: return "Network controller";
328
329 case PCI_CLASS_DISPLAY_VGA: return "VGA compatible controller";
330 case PCI_CLASS_DISPLAY_XGA: return "XGA compatible controller";
331 case PCI_CLASS_DISPLAY_OTHER: return "Display controller";
332
333 case PCI_CLASS_MULTIMEDIA_VIDEO: return "Multimedia video controller";
334 case PCI_CLASS_MULTIMEDIA_AUDIO: return "Multimedia audio controller";
335 case PCI_CLASS_MULTIMEDIA_OTHER: return "Multimedia controller";
336
337 case PCI_CLASS_MEMORY_RAM: return "RAM memory";
338 case PCI_CLASS_MEMORY_FLASH: return "FLASH memory";
339 case PCI_CLASS_MEMORY_OTHER: return "Memory";
340
341 case PCI_CLASS_BRIDGE_HOST: return "Host bridge";
342 case PCI_CLASS_BRIDGE_ISA: return "ISA bridge";
343 case PCI_CLASS_BRIDGE_EISA: return "EISA bridge";
344 case PCI_CLASS_BRIDGE_MC: return "MicroChannel bridge";
345 case PCI_CLASS_BRIDGE_PCI: return "PCI bridge";
346 case PCI_CLASS_BRIDGE_PCMCIA: return "PCMCIA bridge";
347 case PCI_CLASS_BRIDGE_NUBUS: return "NuBus bridge";
348 case PCI_CLASS_BRIDGE_CARDBUS: return "CardBus bridge";
349 case PCI_CLASS_BRIDGE_OTHER: return "Bridge";
350
351 case PCI_CLASS_COMMUNICATION_SERIAL: return "Serial controller";
352 case PCI_CLASS_COMMUNICATION_PARALLEL: return "Parallel controller";
353 case PCI_CLASS_COMMUNICATION_OTHER: return "Communication controller";
354
355 case PCI_CLASS_SYSTEM_PIC: return "PIC";
356 case PCI_CLASS_SYSTEM_DMA: return "DMA controller";
357 case PCI_CLASS_SYSTEM_TIMER: return "Timer";
358 case PCI_CLASS_SYSTEM_RTC: return "RTC";
359 case PCI_CLASS_SYSTEM_OTHER: return "System peripheral";
360
361 case PCI_CLASS_INPUT_KEYBOARD: return "Keyboard controller";
362 case PCI_CLASS_INPUT_PEN: return "Digitizer Pen";
363 case PCI_CLASS_INPUT_MOUSE: return "Mouse controller";
364 case PCI_CLASS_INPUT_OTHER: return "Input device controller";
365
366 case PCI_CLASS_DOCKING_GENERIC: return "Generic Docking Station";
367 case PCI_CLASS_DOCKING_OTHER: return "Docking Station";
368
369 case PCI_CLASS_PROCESSOR_386: return "386";
370 case PCI_CLASS_PROCESSOR_486: return "486";
371 case PCI_CLASS_PROCESSOR_PENTIUM: return "Pentium";
372 case PCI_CLASS_PROCESSOR_ALPHA: return "Alpha";
373 case PCI_CLASS_PROCESSOR_POWERPC: return "Power PC";
374 case PCI_CLASS_PROCESSOR_CO: return "Co-processor";
375
376 case PCI_CLASS_SERIAL_FIREWIRE: return "FireWire (IEEE 1394)";
377 case PCI_CLASS_SERIAL_ACCESS: return "ACCESS Bus";
378 case PCI_CLASS_SERIAL_SSA: return "SSA";
379 case PCI_CLASS_SERIAL_FIBER: return "Fiber Channel";
380
381 default: return "Unknown class";
382 }
383 }
384
385
386 const char *pci_strvendor(unsigned int vendor)
387 {
388 switch (vendor) {
389 case PCI_VENDOR_ID_COMPAQ: return "Compaq";
390 case PCI_VENDOR_ID_NCR: return "NCR";
391 case PCI_VENDOR_ID_ATI: return "ATI";
392 case PCI_VENDOR_ID_VLSI: return "VLSI";
393 case PCI_VENDOR_ID_ADL: return "Advance Logic";
394 case PCI_VENDOR_ID_NS: return "NS";
395 case PCI_VENDOR_ID_TSENG: return "Tseng'Lab";
396 case PCI_VENDOR_ID_WEITEK: return "Weitek";
397 case PCI_VENDOR_ID_DEC: return "DEC";
398 case PCI_VENDOR_ID_CIRRUS: return "Cirrus Logic";
399 case PCI_VENDOR_ID_IBM: return "IBM";
400 case PCI_VENDOR_ID_WD: return "Western Digital";
401 case PCI_VENDOR_ID_AMD: return "AMD";
402 case PCI_VENDOR_ID_TRIDENT: return "Trident";
403 case PCI_VENDOR_ID_AI: return "Acer Incorporated";
404 case PCI_VENDOR_ID_MATROX: return "Matrox";
405 case PCI_VENDOR_ID_CT: return "Chips & Technologies";
406 case PCI_VENDOR_ID_FD: return "Future Domain";
407 case PCI_VENDOR_ID_SI: return "Silicon Integrated Systems";
408 case PCI_VENDOR_ID_HP: return "Hewlett Packard";
409 case PCI_VENDOR_ID_PCTECH: return "PCTECH";
410 case PCI_VENDOR_ID_DPT: return "DPT";
411 case PCI_VENDOR_ID_OPTI: return "OPTI";
412 case PCI_VENDOR_ID_BUSLOGIC: return "BusLogic";
413 case PCI_VENDOR_ID_PROMISE: return "Promise Technology";
414 case PCI_VENDOR_ID_N9: return "Number Nine";
415 case PCI_VENDOR_ID_UMC: return "UMC";
416 case PCI_VENDOR_ID_X: return "X TECHNOLOGY";
417 case PCI_VENDOR_ID_QLOGIC: return "Q Logic";
418 case PCI_VENDOR_ID_LEADTEK: return "Leadtek Research";
419 case PCI_VENDOR_ID_CONTAQ: return "Contaq";
420 case PCI_VENDOR_ID_FOREX: return "Forex";
421 case PCI_VENDOR_ID_OLICOM: return "Olicom";
422 case PCI_VENDOR_ID_CMD: return "CMD";
423 case PCI_VENDOR_ID_VISION: return "Vision";
424 case PCI_VENDOR_ID_SIERRA: return "Sierra";
425 case PCI_VENDOR_ID_ACC: return "ACC MICROELECTRONICS";
426 case PCI_VENDOR_ID_WINBOND: return "Winbond";
427 case PCI_VENDOR_ID_3COM: return "3Com";
428 case PCI_VENDOR_ID_AL: return "Acer Labs";
429 case PCI_VENDOR_ID_ASP: return "Advanced System Products";
430 case PCI_VENDOR_ID_IMS: return "IMS";
431 case PCI_VENDOR_ID_TEKRAM2: return "Tekram";
432 case PCI_VENDOR_ID_AMCC: return "AMCC";
433 case PCI_VENDOR_ID_REALTEK: return "Realtek";
434 case PCI_VENDOR_ID_VIA: return "VIA Technologies";
435 case PCI_VENDOR_ID_VORTEX: return "VORTEX";
436 case PCI_VENDOR_ID_EF: return "Efficient Networks";
437 case PCI_VENDOR_ID_IMAGINGTECH: return "Imaging Technology";
438 case PCI_VENDOR_ID_PLX: return "PLX";
439 case PCI_VENDOR_ID_ALLIANCE: return "Alliance";
440 case PCI_VENDOR_ID_MUTECH: return "Mutech";
441 case PCI_VENDOR_ID_ZEITNET: return "ZeitNet";
442 case PCI_VENDOR_ID_SPECIALIX: return "Specialix";
443 case PCI_VENDOR_ID_CYCLADES: return "Cyclades";
444 case PCI_VENDOR_ID_SYMPHONY: return "Symphony";
445 case PCI_VENDOR_ID_TEKRAM: return "Tekram";
446 case PCI_VENDOR_ID_AVANCE: return "Avance";
447 case PCI_VENDOR_ID_S3: return "S3 Inc.";
448 case PCI_VENDOR_ID_INTEL: return "Intel";
449 case PCI_VENDOR_ID_ADAPTEC: return "Adaptec";
450 case PCI_VENDOR_ID_ATRONICS: return "Atronics";
451 case PCI_VENDOR_ID_HER: return "Hercules";
452 default: return "Unknown vendor";
453 }
454 }
455
456
457 const char *pci_strdev(unsigned int vendor, unsigned int device)
458 {
459 struct pci_dev_info *info;
460
461 info = pci_lookup_dev(vendor, device);
462 return info ? info->name : "Unknown device";
463 }
464
465
466
467
468
469
470 static void burst_bridge(unsigned char bus, unsigned char devfn,
471 unsigned char pos, int turn_on)
472 {
473 #ifdef CONFIG_PCI_OPTIMIZE
474 struct bridge_mapping_type *bmap;
475 unsigned char val;
476 int i;
477
478 pos *= NUM_OPTIMIZATIONS;
479 printk("PCI bridge optimization.\n");
480 for (i = 0; i < NUM_OPTIMIZATIONS; i++) {
481 printk(" %s: ", bridge_optimization[i].type);
482 bmap = &bridge_mapping[pos + i];
483 if (!bmap->addr) {
484 printk("Not supported.");
485 } else {
486 pcibios_read_config_byte(bus, devfn, bmap->addr, &val);
487 if ((val & bmap->mask) == bmap->value) {
488 printk("%s.", bridge_optimization[i].on);
489 if (!turn_on) {
490 pcibios_write_config_byte(bus, devfn,
491 bmap->addr,
492 (val | bmap->mask)
493 - bmap->value);
494 printk("Changed! Now %s.", bridge_optimization[i].off);
495 }
496 } else {
497 printk("%s.", bridge_optimization[i].off);
498 if (turn_on) {
499 pcibios_write_config_byte(bus, devfn,
500 bmap->addr,
501 (val & (0xff - bmap->mask))
502 + bmap->value);
503 printk("Changed! Now %s.", bridge_optimization[i].on);
504 }
505 }
506 }
507 printk("\n");
508 }
509 #endif
510 }
511
512
513
514
515
516
517
518
519 static int sprint_dev_config(struct pci_dev *dev, char *buf, int size)
520 {
521 unsigned long base;
522 unsigned int l, class_rev, bus, devfn;
523 unsigned short vendor, device, status;
524 unsigned char bist, latency, min_gnt, max_lat;
525 int reg, len = 0;
526 const char *str;
527
528 bus = dev->bus->number;
529 devfn = dev->devfn;
530
531 pcibios_read_config_dword(bus, devfn, PCI_CLASS_REVISION, &class_rev);
532 pcibios_read_config_word (bus, devfn, PCI_VENDOR_ID, &vendor);
533 pcibios_read_config_word (bus, devfn, PCI_DEVICE_ID, &device);
534 pcibios_read_config_word (bus, devfn, PCI_STATUS, &status);
535 pcibios_read_config_byte (bus, devfn, PCI_BIST, &bist);
536 pcibios_read_config_byte (bus, devfn, PCI_LATENCY_TIMER, &latency);
537 pcibios_read_config_byte (bus, devfn, PCI_MIN_GNT, &min_gnt);
538 pcibios_read_config_byte (bus, devfn, PCI_MAX_LAT, &max_lat);
539 if (len + 80 > size) {
540 return -1;
541 }
542 len += sprintf(buf + len, " Bus %2d, device %3d, function %2d:\n",
543 bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
544
545 if (len + 80 > size) {
546 return -1;
547 }
548 len += sprintf(buf + len, " %s: %s %s (rev %d).\n ",
549 pci_strclass(class_rev >> 8), pci_strvendor(vendor),
550 pci_strdev(vendor, device), class_rev & 0xff);
551
552 if (!pci_lookup_dev(vendor, device)) {
553 len += sprintf(buf + len,
554 "Vendor id=%x. Device id=%x.\n ",
555 vendor, device);
556 }
557
558 str = 0;
559 switch (status & PCI_STATUS_DEVSEL_MASK) {
560 case PCI_STATUS_DEVSEL_FAST: str = "Fast devsel. "; break;
561 case PCI_STATUS_DEVSEL_MEDIUM: str = "Medium devsel. "; break;
562 case PCI_STATUS_DEVSEL_SLOW: str = "Slow devsel. "; break;
563 }
564 if (len + strlen(str) > size) {
565 return -1;
566 }
567 len += sprintf(buf + len, str);
568
569 if (status & PCI_STATUS_FAST_BACK) {
570 # define fast_b2b_capable "Fast back-to-back capable. "
571 if (len + strlen(fast_b2b_capable) > size) {
572 return -1;
573 }
574 len += sprintf(buf + len, fast_b2b_capable);
575 # undef fast_b2b_capable
576 }
577
578 if (bist & PCI_BIST_CAPABLE) {
579 # define BIST_capable "BIST capable. "
580 if (len + strlen(BIST_capable) > size) {
581 return -1;
582 }
583 len += sprintf(buf + len, BIST_capable);
584 # undef BIST_capable
585 }
586
587 if (dev->irq) {
588 if (len + 40 > size) {
589 return -1;
590 }
591 len += sprintf(buf + len, "IRQ %d. ", dev->irq);
592 }
593
594 if (dev->master) {
595 if (len + 80 > size) {
596 return -1;
597 }
598 len += sprintf(buf + len, "Master Capable. ");
599 if (latency)
600 len += sprintf(buf + len, "Latency=%d. ", latency);
601 else
602 len += sprintf(buf + len, "No bursts. ");
603 if (min_gnt)
604 len += sprintf(buf + len, "Min Gnt=%d.", min_gnt);
605 if (max_lat)
606 len += sprintf(buf + len, "Max Lat=%d.", max_lat);
607 }
608
609 for (reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4) {
610 if (len + 40 > size) {
611 return -1;
612 }
613 pcibios_read_config_dword(bus, devfn, reg, &l);
614 base = l;
615 if (!base) {
616 continue;
617 }
618
619 if (base & PCI_BASE_ADDRESS_SPACE_IO) {
620 len += sprintf(buf + len,
621 "\n I/O at 0x%lx.",
622 base & PCI_BASE_ADDRESS_IO_MASK);
623 } else {
624 const char *pref, *type = "unknown";
625
626 if (base & PCI_BASE_ADDRESS_MEM_PREFETCH) {
627 pref = "P";
628 } else {
629 pref = "Non-p";
630 }
631 switch (base & PCI_BASE_ADDRESS_MEM_TYPE_MASK) {
632 case PCI_BASE_ADDRESS_MEM_TYPE_32:
633 type = "32 bit"; break;
634 case PCI_BASE_ADDRESS_MEM_TYPE_1M:
635 type = "20 bit"; break;
636 case PCI_BASE_ADDRESS_MEM_TYPE_64:
637 type = "64 bit";
638
639 reg += 4;
640 pcibios_read_config_dword(bus, devfn, reg, &l);
641 base |= ((u64) l) << 32;
642 break;
643 }
644 len += sprintf(buf + len,
645 "\n %srefetchable %s memory at "
646 "0x%lx.", pref, type,
647 base & PCI_BASE_ADDRESS_MEM_MASK);
648 }
649 }
650
651 len += sprintf(buf + len, "\n");
652 return len;
653 }
654
655
656
657
658
659
660 int get_pci_list(char *buf)
661 {
662 int nprinted, len, size;
663 struct pci_dev *dev;
664 # define MSG "\nwarning: page-size limit reached!\n"
665
666
667 size = PAGE_SIZE - (strlen(MSG) + 1);
668 len = sprintf(buf, "PCI devices found:\n");
669
670 for (dev = pci_devices; dev; dev = dev->next) {
671 nprinted = sprint_dev_config(dev, buf + len, size - len);
672 if (nprinted < 0) {
673 return len + sprintf(buf + len, MSG);
674 }
675 len += nprinted;
676 }
677 return len;
678 }
679
680
681
682
683
684
685 static void *pci_malloc(long size, unsigned long *mem_startp)
686 {
687 void *mem;
688
689 #ifdef DEBUG
690 printk("...pci_malloc(size=%ld,mem=%p)", size, *mem_startp);
691 #endif
692 mem = (void*) *mem_startp;
693 *mem_startp += (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
694 memset(mem, 0, size);
695 return mem;
696 }
697
698
699 static unsigned int scan_bus(struct pci_bus *bus, unsigned long *mem_startp)
700 {
701 unsigned int devfn, l, max;
702 unsigned char cmd, tmp, hdr_type = 0;
703 struct pci_dev_info *info;
704 struct pci_dev *dev;
705 struct pci_bus *child;
706
707 #ifdef DEBUG
708 printk("...scan_bus(busno=%d,mem=%p)\n", bus->number, *mem_startp);
709 #endif
710
711 max = bus->secondary;
712 for (devfn = 0; devfn < 0xff; ++devfn) {
713 if (PCI_FUNC(devfn) == 0) {
714 pcibios_read_config_byte(bus->number, devfn,
715 PCI_HEADER_TYPE, &hdr_type);
716 } else if (!(hdr_type & 0x80)) {
717
718 continue;
719 }
720
721 pcibios_read_config_dword(bus->number, devfn, PCI_VENDOR_ID,
722 &l);
723
724 if (l == 0xffffffff || l == 0x00000000) {
725 hdr_type = 0;
726 continue;
727 }
728
729 dev = pci_malloc(sizeof(*dev), mem_startp);
730 dev->bus = bus;
731
732
733
734
735
736 dev->next = pci_devices;
737 pci_devices = dev;
738
739 dev->devfn = devfn;
740 dev->vendor = l & 0xffff;
741 dev->device = (l >> 16) & 0xffff;
742
743
744
745
746
747
748 info = pci_lookup_dev(dev->vendor, dev->device);
749 if (!info) {
750 printk("Warning : Unknown PCI device (%x:%x). Please read include/linux/pci.h \n",
751 dev->vendor, dev->device);
752 } else {
753
754 if (info->bridge_type != 0xff) {
755 burst_bridge(bus->number, devfn,
756 info->bridge_type, 1);
757 }
758 }
759
760
761 pcibios_read_config_byte(bus->number, devfn, PCI_COMMAND,
762 &cmd);
763 pcibios_write_config_byte(bus->number, devfn, PCI_COMMAND,
764 cmd | PCI_COMMAND_MASTER);
765 pcibios_read_config_byte(bus->number, devfn, PCI_COMMAND,
766 &tmp);
767 dev->master = ((tmp & PCI_COMMAND_MASTER) != 0);
768 pcibios_write_config_byte(bus->number, devfn, PCI_COMMAND,
769 cmd);
770
771
772 pcibios_read_config_byte(bus->number, devfn,
773 PCI_INTERRUPT_LINE, &dev->irq);
774
775
776 pcibios_read_config_dword(bus->number, devfn,
777 PCI_CLASS_REVISION, &l);
778 l = l >> 8;
779 dev->class = l;
780
781
782
783
784 dev->sibling = bus->devices;
785 bus->devices = dev;
786
787 if (dev->class >> 8 == PCI_CLASS_BRIDGE_PCI) {
788 unsigned int buses;
789 unsigned short cr;
790
791
792
793
794 child = pci_malloc(sizeof(*child), mem_startp);
795 child->next = bus->children;
796 bus->children = child;
797 child->self = dev;
798 child->parent = bus;
799
800
801
802
803
804 child->number = child->secondary = ++max;
805 child->primary = bus->secondary;
806 child->subordinate = 0xff;
807
808
809
810
811 pcibios_read_config_word(bus->number, devfn,
812 PCI_COMMAND, &cr);
813 pcibios_write_config_word(bus->number, devfn,
814 PCI_COMMAND, 0x0000);
815 pcibios_write_config_word(bus->number, devfn,
816 PCI_STATUS, 0xffff);
817
818
819
820 pcibios_read_config_dword(bus->number, devfn, 0x18,
821 &buses);
822 buses &= 0xff000000;
823 buses |= (((unsigned int)(child->primary) << 0) |
824 ((unsigned int)(child->secondary) << 8) |
825 ((unsigned int)(child->subordinate) << 16));
826 pcibios_write_config_dword(bus->number, devfn, 0x18,
827 buses);
828
829
830
831 max = scan_bus(child, mem_startp);
832
833
834
835
836 child->subordinate = max;
837 buses = (buses & 0xff00ffff)
838 | ((unsigned int)(child->subordinate) << 16);
839 pcibios_write_config_dword(bus->number, devfn, 0x18,
840 buses);
841 pcibios_write_config_word(bus->number, devfn,
842 PCI_COMMAND, cr);
843 }
844 }
845
846
847
848
849
850
851
852 return max;
853 }
854
855
856 unsigned long pci_init (unsigned long mem_start, unsigned long mem_end)
857 {
858 mem_start = pcibios_init(mem_start, mem_end);
859
860 if (!pcibios_present()) {
861 printk("pci_init: no BIOS32 detected\n");
862 return mem_start;
863 }
864
865 printk("Probing PCI hardware.\n");
866
867 memset(&pci_root, 0, sizeof(pci_root));
868 pci_root.subordinate = scan_bus(&pci_root, &mem_start);
869
870
871 mem_start = pcibios_fixup(mem_start, mem_end);
872
873 #ifdef DEBUG
874 {
875 int len = get_pci_list((char*)mem_start);
876 if (len) {
877 ((char *) mem_start)[len] = '\0';
878 printk("%s\n", (char *) mem_start);
879 }
880 }
881 #endif
882 return mem_start;
883 }