PCISpecirev2.3FRAME#isdrivenbythemastertoindicatethebeginningandendofatransaction.IRDY#isdrivenbythemastertoindicatethatitisreadytotransferdata.TRDY#isdrivenbythetargettoindicatethatitisreadytotransferdata.IDSELinInitializationDeviceSelectisusedasachipselectduringconfigurationreadandwritetransactions.STOP#s/t/sStopindicatesthecurrenttargetisrequestingthemastertostopthecurrenttransaction.Inallcases,dataisonlytransferredwhenIRDY#andTRDY#arebothassertedonthesamerisingclockedge.只有当IRDY#andTRDY#都有效时,数据才能传输。3.2.2.AddressingPCItargets(excepthostbusbridges)arerequiredtoimplementBaseAddressregister(s)torequestarangeofaddresseswhichcanbeusedtoprovideaccesstointernalregistersorfunctions(refertoChapter6formoredetails).TheconfigurationsoftwareusestheBaseAddressregistertodeterminehowmuchspaceadevicerequiresinagivenaddressspaceandthenassigns(ifpossible)whereinthatspacethedevicewillreside.BAR确定一个设备需要多少空间。AdevicemaymapitsinternalregisterintobothMemorySpaceandoptionallyI/OSpacebyusingtwoBaseAddressregisters,oneforI/OandtheotherforMemory.Whenatransactionisinitiatedontheinterface,eachpotentialtargetcomparestheaddresswithitsBaseAddressregister(s)todetermineifitisthetargetofthecurrenttransaction.Ifitisthetarget,thedeviceassertsDEVSEL#toclaimtheaccess.FormoredetailsaboutDEVSEL#generation,refertoSection3.2.2.3.2.Howatargetcompletesaddressdecodeineachaddressspaceisdiscussedinthefollowingsections.当一个交易初始后,每个潜在设备将自己的BAR与总线上的地址比较,来确定自己是不是当前交易的目标。3.2.2.1.I/OSpaceDecodingIntheI/OAddressSpace,all32ADlinesareusedtoprovideafullbyteaddress.ThemasterthatinitiatesanI/OtransactionisrequiredtoensurethatAD[1::0]indicatetheleastsignificantvalidbyteforthetransaction.ThebyteenablesindicatethesizeofthetransferandtheaffectedbyteswithintheDWORDandmustbeconsistentwithAD[1::0].Table3-1liststhevalidcombinationsforAD[1::0]andthebyteenablesfortheinitialdataphase.3.2.2.2.MemorySpaceDecodingIntheMemoryAddressSpace,theAD[31::02]busprovidesaDWORDalignedaddress.AD[1::0]arenotpartoftheaddressdecode.However,AD[1::0]indicatetheorderinwhichthemasterisrequestingthedatatobetransferred.3.2.2.3.ConfigurationSpaceDecodingIntheConfigurationAddressSpace,eachfunctionisassignedaunique256-bytespacethatisaccesseddifferentlythanI/OorMemoryAddressSpaces.TosupporthierarchicalPCIbuses,twotypesofconfigurationtransactionsareused.TheyhavetheformatsillustratedinFigure3-1,whichshowstheinterpretationofADlinesduringtheaddressphaseofaconfigurationtransaction.Type1andType0configurationtransactionsaredifferentiatedbythevaluesonAD[1::0].AType0configurationtransaction(whenAD[1::0]=00)isusedtoselectadeviceonthebuswherethetransactionisbeingrun.AType1configurationtransaction(whenAD[1::0]=01)isusedtopassaconfigurationrequesttoanotherbussegment.3.2.2.3.2.SoftwareGenerationofConfigurationTransactionsTwoDWORDI/OlocationsareusedtogenerateconfigurationtransactionsforPC-ATcompatiblesystems.ThefirstDWORDlocation(CF8h)referencesaread/writeregisterthatisnamedCONFIG_ADDRESS.ThesecondDWORDaddress(CFCh)referencesaread/writeregisternamedCONFIG_DATA.TheCONFIG_ADDRESSregisteris32bitswiththeformatshowninFigure3-2.Bit31isanenableflagfordeterminingwhenaccessestoCONFIG_DATAaretobetranslatedtoconfigurationtransactionsonthePCIbus.Bits30to24arereserved,read-only,andmustreturn0'swhenread.Bits23through16chooseaspecificPCIbusinthesystem.Bits15through11chooseaspecificdeviceonthebus.Bits10through8chooseaspecificfunctioninadevice(ifthedevicesupportsmultiplefunctions).Bits7through2chooseaDWORDinthedevice'sConfigurationSpace.Bits1and0areread-onlyandmustreturn0'swhenread.AnytimeahostbridgeseesafullDWORDI/OwritefromthehosttoCONFIG_ADDRESS,thebridgemustlatchthedataintoitsCONFIG_ADDRESSregister.OnfullDWORDI/OreadstoCONFIG_ADDRESS,thebridgemustreturnthedatainCONFIG_ADDRESS.配置空间的读写是通过读写两个IO端口实现的。3.2.2.3.4.SelectionofaDevice’sConfigurationSpaceAsinglefunctiondeviceassertsDEVSEL#toclaimaconfigurationtransactionwhen:aconfigurationcommandisdecoded;thedevice’sIDSELisasserted;andAD[1::0]is00(Type0ConfigurationCommand)duringtheAddressPhase.有PCI系统的PC-AT系统,有2套总线系统,一套为PC-AT的总线,一套为PCIlocalbus的总线。PC向IO端口CF8H和CFCH写数据,是通过PC-AT的总线写入CONFIG_ADDRESS和CONFIG_DATA的寄存器,然后PCIlocalbus根据CONFIG_ADDRESS和CONFIG_DATA的寄存器的值,产生PCIlocalbus的时序,诸如AD,CMB,FRAME等。PCI配置空间有6个BAR,这些BAR既提供大小又提供数据类型信息。ifrst='0'thenbasereg0=11111111111111111111111100000001;elsifrising_edge(clk)thenif(cfgwr='1'andbase0='1'andwrsel='1')thenbasereg0(31downto8)=wrreg(31downto8);basereg0(7downto0)=00000001;endif;endif;ifrst='0'thenbasereg1=11111111110000000000000000000000;elsifrising_edge(clk)thenif(cfgwr='1'andbase1='1'andwrsel='1')thenbasereg1(31downto22)=wrreg(31downto22);basereg1(21downto0)=0000000000000000000000;endif;endif;以上代码是张森丰PCIE开发板代码。Base0的7-0位和Base1的21-0位是不能写的,PC机对其不能控制,第一位不是0的数的权值代表需要分配的大小。所以,IOspace要求分配的大小为2^8=256byte,Memoryspace要求分配的大小为2^22=4Mbyte6.2.5.BaseAddressesOneofthemostimportantfunctionsforenablingsuperiorconfigurabilityandeaseofuseistheabilitytorelocatePCIdevicesintheaddressspaces.可以把PCI设备地址重映射是PCI的一个优点之一。Power-upsoftware(BIOS?)needstobuildaconsistentaddres