root/drivers/pci/pci.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pci_lookup_dev
  2. pci_strbioserr
  3. pci_strclass
  4. pci_strvendor
  5. pci_strdev
  6. burst_bridge
  7. sprint_dev_config
  8. get_pci_list
  9. pci_malloc
  10. scan_bus
  11. pci_init

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

/* [previous][next][first][last][top][bottom][index][help] */