//(c)Copyright2009聳2009Xilinx,Inc.Allrightsreserved.////Thisfilecontainsconfidentialandproprietaryinformation//ofXilinx,Inc.andisprotectedunderU.S.and//internationalcopyrightandotherintellectualproperty//laws.////DISCLAIMER//Thisdisclaimerisnotalicenseanddoesnotgrantany//rightstothematerialsdistributedherewith.Exceptas//otherwiseprovidedinavalidlicenseissuedtoyouby//Xilinx,andtothemaximumextentpermittedbyapplicable//law:(1)THESEMATERIALSAREMADEAVAILABLEASISAND//WITHALLFAULTS,ANDXILINXHEREBYDISCLAIMSALLWARRANTIES//ANDCONDITIONS,EXPRESS,IMPLIED,ORSTATUTORY,INCLUDING//BUTNOTLIMITEDTOWARRANTIESOFMERCHANTABILITY,NON-//INFRINGEMENT,ORFITNESSFORANYPARTICULARPURPOSE;and//(2)Xilinxshallnotbeliable(whetherincontractortort,//includingnegligence,orunderanyothertheoryof//liability)foranylossordamageofanykindornature//relatedto,arisingunderorinconnectionwiththese//materials,includingforanydirect,oranyindirect,//special,incidental,orconsequentiallossordamage//(includinglossofdata,profits,goodwill,oranytypeof//lossordamagesufferedasaresultofanyactionbrought//byathirdparty)evenifsuchdamageorlosswas//reasonablyforeseeableorXilinxhadbeenadvisedofthe//possibilityofthesame.////CRITICALAPPLICATIONS//Xilinxproductsarenotdesignedorintendedtobefail-//safe,orforuseinanyapplicationrequiringfail-safe//performance,suchaslife-supportorsafetydevicesor//systems,ClassIIImedicaldevices,nuclearfacilities,//applicationsrelatedtothedeploymentofairbags,orany//otherapplicationsthatcouldleadtodeath,personal//injury,orseverepropertyorenvironmentaldamage//(individuallyandcollectively,Critical//Applications).Customerassumesthesoleriskand//liabilityofanyuseofXilinxproductsinCritical//Applications,subjectonlytoapplicablelawsand//regulationsgoverninglimitationsonproductliability.////THISCOPYRIGHTNOTICEANDDISCLAIMERMUSTBERETAINEDAS//PARTOFTHISFILEATALLTIMES.//--------------------------------------------------------------------------------//--Filename:xbmd.c//--//--Description:XBMDdevicedriver.//--//--XBMDisanexampleRedHatdevicedriverwhichexercisesXBMDdesign//--DevicedriverhasbeentestedonRedHatFedoraFC92.6.15.//--------------------------------------------------------------------------------#includelinux/init.h#includelinux/module.h#includelinux/pci.h#includelinux/interrupt.h#includelinux/fs.h//#includelinux/pci-aspm.h//#includelinux/pci_regs.h#includeasm/uaccess.h/*copy_to_user*/#includexbmd.h//semaphoresenum{SEM_READ,SEM_WRITE,SEM_WRITEREG,SEM_READREG,SEM_WAITFOR,SEM_DMA,NUM_SEMS};#defineSUCCESS0#defineCRIT_ERR-1//Debug-definewilloutputmoreinfo#defineVerbose1//MaxDMABufferSize#defineBUF_SIZE(4096*1024)enum{INITCARD,//0INITRST,DISPREGS,RDDCSR,RDDDMACR,RDWDMATLPA,//5RDWDMATLPS,RDWDMATLPC,RDWDMATLPP,RDRDMATLPP,RDRDMATLPA,//10RDRDMATLPS,RDRDMATLPC,RDWDMAPERF,RDRDMAPERF,RDRDMASTAT,//15RDNRDCOMP,RDRCOMPDSIZE,RDDLWSTAT,RDDLTRSSTAT,RDDMISCCONT,//20RDDMISCONT,RDDLNKC,DFCCTL,DFCPINFO,DFCNPINFO,//25DFCINFO,RDCFGREG,WRCFGREG,RDBMDREG,WRBMDREG,//30WRDDMACR,WRWDMATLPS,WRWDMATLPC,WRWDMATLPP,WRRDMATLPS,WRRDMATLPC,WRRDMATLPP,WRDMISCCONT,WRDDLNKC,NUMCOMMANDS};//semaphoresstructsemaphoregSem[NUM_SEMS];MODULE_LICENSE(DualBSD/GPL);//DefinestheVendorID.MustbechangedifcoregenerateddidnotsettheVendorIDtothesamevalue#definePCI_VENDOR_ID_XILINX0x10ee//DefinestheDeviceID.MustbechangedifcoregenerateddidnotsettheDeviceIDtothesamevalue#definePCI_DEVICE_ID_XILINX_PCIE0x0007//Defining#defineXBMD_REGISTER_SIZE(4*8)//Thereareeightregisters,andeachis4byteswide.#defineHAVE_REGION0x01//I/OMemoryregion#defineHAVE_IRQ0x02//Interupt//StatusFlags://1=Resoucesuccessfullyacquired//0=Resourcenotacquired.#defineHAVE_REGION0x01//I/OMemoryregion#defineHAVE_IRQ0x02//Interupt#defineHAVE_KREG0x04//KernelregistrationintgDrvrMajor=241;//Majornumbernotdynamic.unsignedintgStatFlags=0x00;//Statusflagsusedforcleanup.unsignedlonggBaseHdwr;//Baseregisteraddress(Hardwareaddress)unsignedlonggBaseLen;//BaseregisteraddressLengthvoid*gBaseVirt=NULL;//Baseregisteraddress(Virtualaddress,forI/O).chargDrvrName[]=xbmd;//Nameofdriverinproc.structpci_dev*gDev=NULL;//PCIdevicestructure.intgIrq;//IRQassignedbyPCIsystem.char*gBufferUnaligned=NULL;//PointertoUnalignedDMAbuffer.char*gReadBuffer=NULL;//PointertodwordalignedDMAbuffer.char*gWriteBuffer=NULL;//PointertodwordalignedDMAbuffer.dma_addr_tgReadHWAddr;dma_addr_tgWriteHWAddr;unsignedlongSA_SHIRQ=0;unsignedlongSA_SAMPLE_RANDOM=0;intpos;//StructUsedforWritingCFGRegister.Holdsvalueandregistertobewrittentypedefstructcfgwrite{intreg;intvalue;}cfgwr;//StructUsedforWritingBMDRegister.Holdsvalueandregistertobewrittentypedefstructbmdwrite{intreg;intvalue;}bmdwr;//-----------------------------------------------------------------------------//Prototypes//-----------------------------------------------------------------------------voidXPCIe_IRQHandler(intirq,void*dev_id,structpt_regs*regs);u32XPCIe_ReadReg(u32dw_offset);voidXPCIe_WriteReg(u32dw_offset,u32val);voidXPCIe_InitCard(void);voidXPCIe_InitiatorReset(void);u32XPCIe_ReadCfgReg(u32byte);u32XPCIe_WriteCfgReg(u32