Example: bankruptcy

Linux-PCI Support Programming PCI-Devices …

Intendedtobea ..PCI-BridgePCI-BusPCI#0 PCI#nPCI#1 Figure1:TheArchitectureofthePCIS ubsystemThePeripheralComponentInterconne ct-Bus(PCI)todayis presentina widevarietyof thecom-pleteseparationof , specialcasesonlyonestartad-dressis transferredfollowedbya determinetheaddressforeachsingledata-wor dthePCI-BridgeandthePCI-Adapterincrement internalcounters, burst cy-clespeedsupthetransfersigni cantly(upto266 Mbyte/secfora 64bitdata-transfer).Thankstotheintellige nthandlingof schematicviewof thePCIsubsystemis usea Memoryforcon beplacedin therightplaces,soIRQor addresscon ictsarenolongera commonlyknownasPlug& ( ) linux -PCIS upportFirstContactwiththePCIsubsystemTo getanimpressionhowlinuxseesthePCIbusinyo urcomputertrygettingthePCIbuscon gurationfromthekernelwithcat /proc/pci. If everythingworksOKyouwill(hopefully)see:P CI devicesfound:Bus0, device12, function0:SCSI storagecontroller:AdaptecAIC-7881U(rev0) .

Linux-PCI Support First Contact with the PCI subsystem To get an impression how linux sees the PCI bus in your computer try getting the PCI bus conguration from the kernel with cat /proc/pci.

Tags:

  Devices, Linux, Programming, Support, Pci support programming pci devices

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Linux-PCI Support Programming PCI-Devices …

1 Intendedtobea ..PCI-BridgePCI-BusPCI#0 PCI#nPCI#1 Figure1:TheArchitectureofthePCIS ubsystemThePeripheralComponentInterconne ct-Bus(PCI)todayis presentina widevarietyof thecom-pleteseparationof , specialcasesonlyonestartad-dressis transferredfollowedbya determinetheaddressforeachsingledata-wor dthePCI-BridgeandthePCI-Adapterincrement internalcounters, burst cy-clespeedsupthetransfersigni cantly(upto266 Mbyte/secfora 64bitdata-transfer).Thankstotheintellige nthandlingof schematicviewof thePCIsubsystemis usea Memoryforcon beplacedin therightplaces,soIRQor addresscon ictsarenolongera commonlyknownasPlug& ( ) linux -PCIS upportFirstContactwiththePCIsubsystemTo getanimpressionhowlinuxseesthePCIbusinyo urcomputertrygettingthePCIbuscon gurationfromthekernelwithcat /proc/pci. If everythingworksOKyouwill(hopefully)see:P CI devicesfound:Bus0, device12, function0:SCSI storagecontroller:AdaptecAIC-7881U(rev0) .

2 Gnt= at bit memoryat , device11, function0:VGA compatiblecontroller:S3 (rev0). bit memoryat , device10, function0:Ethernetcontroller:3 Com3C59010bT(rev0). Gnt= at , device7, function2:Unknownclass:IntelUnknowndevic e(rev0).Vendorid= 9. at , device7, function1:IDE interface:Intel82371 SBTritonII PIIX(rev0). at , device7, function0:ISA bridge:Intel82371 SBTritonII PIIX(rev0). , device0, function0:Hostbridge:Intel82439 HXTritonII (rev1). Eachdevicecon- gurationblockis assignedto a deviceanda identifya certaindevicewhiledriverwritingyouwillat leasthaveto knowthevendor- andthedevice-idthatis staticallystoredinthedevicecon gura-tionblock(asdiscussedlateron). 'sordeviceclass eldsthatcannotberesolvedwithinthelinuxPC I-subsystemareprintedasplainvalues,sodri verwritershavea simplechancetoidentifytheircardofchoicew ithoutwrit-inga specialtoolto gurationBlockAsmentionedaboveeachPCI-dev icehasitsownassigned256bytesPCI-con gurationmemoryblockthatis rst64bytesofthisreservedspaceareusedto identifyandcon gura-tionblockarereplacedfromthePlug&Pla yBIOS thatcon g-urationblocksofthePCIsubsystemcanbeacc essedthroughtheCONFIGADDRESSTheLinuxLabP rojectwhitepapers11/1996( ) linux -PCIS upport(0xcf8)andtheCONFIGDATA(0xcfc)

3 RegistersTheLinuxPCI-biossupportisimple- mentedontopof theBios32routinesandde nessomeusefulroutinesto handlethePCIcon gurationblockandcon runonmanyhardwarearchitec-turesit is recommendedtousethisfunc-tionsinsteadofa ccessingthecon PCI-boardcanbeused,thedriverhasto determinetheboardspeci cparam-etersfromthecon donebyaautodetectroutinein thekerneldriverthatperformsthefollowingt asks: Checkif thePCI-BiosSupportis en-abledinthekernelandtheBIOS ispresentwithpcibiospresent() Getthecon gurationblockforthedesireddeviceusingpci biosfinddevice() Getthedesiredparametersfromthecon gurationblockus-ingpcibiosreadconfigbyte (),pcibiosreadconfigword()orpcibiosreadc onfigdword()toget8,16or32bitparameterval ues. Setthedesiredparametersinthecon gurationblockusingpcibioswriteconfigbyte (),pcibioswriteconfigword()orpcibioswrit econfigdword()Thefollowingexamplefromthe ne2000clonedrivershowshowthistaskisper-f ormedin a realkernelnetworkdriver.

4 #if defined(CONFIG_PCI)if (pcibios_present()){int pci_index;for (pci_index= 0; pci_index< 8; pci_index++){unsignedcharpci_bus,pci_dev ice_fn;unsignedint pci_ioaddr;/* CurrentlyonlyRealtekare makingPCI ne2kclones.*/if (pcibios_find_device(PCI_VENDOR_ID_REALT EK,PCI_DEVICE_ID_REALTEK_8029,pci_index, &pci_bus,&pci_device_fn)!= 0)break;/* OK, now try to probefor card*/pcibios_read_config_byte(pci_bus,p ci_device_fn,PCI_INTERRUPT_LINE,&pci_irq _line);pcibios_read_config_dword(pci_bus ,pci_device_fn,PCI_BASE_ADDRESS_0,&pci_i oaddr);/* Stripthe I/O addressout of the returnedvalue*/pci_ioaddr&= PCI_BASE_ADDRESS_IO_MASK;/* Avoidalreadyfoundcardsfrompreviousne_pro be()calls*/if (check_region(pci_ioaddr,NE_IO_EXTENT))c ontinue;printk(" :PCI BIOS reportsne2000cloneat i/o %#x,irq %d.\n",pci_ioaddr,pci_irq_line);if (ne_probe1(dev,pci_ioaddr)!= 0) {/* Shouldn'thappen.*/printk(KERN_ERR" :Probeof PCI cardat %#x failed.)}}}

5 \n",pci_ioaddr);break;/* Hrmm,try to probefor ISA */}TheLinuxLabProjectwhitepapers11/1996( ) linux -PCIS upportpci_irq_line= 0;return0;}}#endif/* defined(CONFIG_PCI)*/ThiscardusesoneIRQa ndonebasead-dressinI/Ospacetocommunicate withthedriver. Thelowerbitsofthereturnedbaseaddresshave differentmeaningsde-pendingif theaddressisanI/Oaddressora memorymappedareais isalways1 andbit2 memorymappedaddresstypethelower4 bitshavethefol-lowingmeanings:BitDescrip tion0alwayszero1-2adresstype:00=arbitrar y32bit,01=below1M,10=arbitrary64-bit3pre fetchableTo keepthingssimpleLinuxde thePCI-bridgeisallowedtoreadthememoryblo ckina prefetchbufferwith-outproblems,thisis normallythecaseifthememoryblockis a memoryareaonthePCI-device,if wholebunchofothersetableandreadableparam etersinthecon gura-tionblock,thatcanbeaccessedthrought helinuxpcibiosXXX() nessomeusefulMnemonicstogainsimpleaccess tothecon gurationblockparametervaluesthatarede nedininclude/ ,2and3 willdescribetheMacrosin deviceReadingandwritingtoa PCIdeviceis aseasyasreadingandwritingto anISAboardorreadingandwritingtoa memoryareadependingonthebaseaddresstypeo f thedeviceusesanI/Otypebasead-dress,norma lI/Ocanbeperformedusingtheusualinb()/out b(),inw()/outw()orthe32bitinl()/outl() ()/writeb(),readw()/writew()orthelongwor dreadl()/writel()rou-tinestoreadorwritet oa singlelocation(seeinclude/ ).

6 Memcpy()canalsobeusedtotransfera (onefortheBusside,onefortheCPUsubsystems ide)thatareusedto storetransferdatabeforea sendor receiveis thePREF(prefetchable)bitis setin thebaseaddressbit3, thememoryareaisnonprefetchable, intendedfordevicesthatmapsspecialregiste rsinamemoryareasotheCPUcanreadorwritethi sregisterswithouta controllercantransferitsdatatothememoryw ith-outanyCPUactionbydrivingtheap-propri atebus-linesona ( ) busmastertransferhasbeenabortedbythebusm asterdevice,thePCISTATUSRECMASTERABORT bitinthePCISTATUS registeris set,onthereceivingendanabortcanbenoti ( ) ThisIDis de nedbythePCIconsortiumPCIDEVICEID16bitUni queDeviceID( ) thisis de nedbythevendoruniqueforeachdevicePCICOMM AND16bitThis eldisusedfordevicespeci ccon gurationcommands(seetable2)PCISTATUS16bi tThisis usedforboardspeci cstatusresults(seetable3)PCICLASSREVISIO N32bitThehigh24bitsareusedtodeterminethe device'sclasstypethelow8bitforrevisionco dePCICLASSDEVICET hedevice'sclasscode( )PCIBIST8bitIfPCIBISTCAPABLEis setthedevicecanperforma Build-inselftestthatcanbestartedbywritin gPCIBISTSTART tothis estheLayouttypeforthefollowing48bytesin PCIcon guration(currentlyonly0x0)PCILATENCYTIME R8bitThisis themaximaltimea PCIcyclemayconsume(time=latency+8cycles) PCICACHELINESIZE8bitSpeci estheCache-LineSizeinunitsof 32bytes,PCIBASEADDRESS[0-5]32bitThisareu pto6 memorylocationsthedevicecanmapitsmemorya rea(s) bitsareusedto specifythetypeandtheaccessmodeof thestartaddressofthedevice'sROMarea.

7 (writebit1 to enableROM)PCIMINGNT8bitminimallatencytim e(vendorspeci c)PCIMINLAT8bitmaximallatencytime(vendor speci c)PCIINTERRUPTPIN8bitThisentrydenotesthe IRQpinthatshouldbeused1=INTA2=INTB0=disa bledPCIINTERRUPTLINE8bitThisentryspeci estheinterruptlineonwhichthedeviceIRQis mapped(usuallyIRQ0-15)Table1:TheLinuxPCI -Con gurationmacrosTheLinuxLabProjectwhitepap ers11/1996( ) linux -PCIS upportMacroDescriptionPCICOMMANDIOE nableI/OareaPCICOMMANDMEMORYE nableMemoryareaPCICOMMANDMASTERE nableBusmasteringPCICOMMANDSPECIALE nableresponseto specialcyclesPCICOMMANDINVALIDATEU sememorywriteandinvalidatePCICOMMANDVGAP ALETTEE nablevideopaletteaccessPCICOMMANDPARITYE nableparitycheckingPCICOMMANDWAITE nableaddress/datasteppingPCICOMMANDSERRE nableSERRPCICOMMANDFASTBACKE nableback-to-backwritesTable2 nableFeaturesPCISTATUSFASTBACKA cceptfast-backto backPCISTATUSPARITYD etectedparityerrorPCISTATUSDEVSEL[MASK|F AST|MEDIUM|SLOW]DEVSEL timingPCISTATUSSIGTARGETABORTS etontargetabortPCISTATUSRECTARGETABORTM asterackofPCISTATUSRECMASTERABORTS etonmasterabortPCISTATUSSIGSYSTEMERRORS etwhenwedriveSERRPCISTATUSDETECTEDPARITY S etonparityerrorTable3.

8 TheLinuxPCI-StatusBit-SettingsTheLinuxLa bProjectwhitepapers11/1996( )


Related search queries