pci.c
pci/pci.h
sys/io.h
ubixos/types.h
lib/kprintf.h
pci/pci.h
src/sys/pci/pci.c
ubixos/types.h
sys/_types.h
lib/kprintf.h
sys/io.h
int int pci_init () pci_init pciConfig::baseClass confadd::bus countof confadd::dev confadd::func pciConfig::interface pciConfig::irq kprintf name pciClasses pciProbe pciConfig::subClass TRUE
bool bool pciProbe (int bus, int dev, int func, struct pciConfig *cfg) pciProbe int bus int dev int func struct pciConfig * cfg pciConfig::base pciConfig::baseClass pciConfig::bist pciConfig::bus pciConfig::cacheLineSize pciConfig::command pciConfig::dev pciConfig::deviceId FALSE pciConfig::func pciConfig::headerType pciConfig::interface pciConfig::irq kprintf pciConfig::latencyTimer pciRead pciWrite pciConfig::size pciConfig::status pciConfig::subClass pciConfig::subsys pciConfig::subsysVendor TRUE pciConfig::vendorId x10 pci_init
uInt32 uInt32 pciRead (int bus, int dev, int func, int reg, int bytes) pciRead int bus int dev int func int reg int bytes inportByte inportDWord inportWord outportDWord pciProbe
void void pciWrite (int bus, int dev, int func, int reg, uInt32 v, int bytes) pciWrite int bus int dev int func int reg uInt32 v int bytes outportByte outportDWord outportWord pciProbe
uInt8 uInt8 baseClass baseClass
uInt8 uInt8 interface interface
const char * const char* name name def_ctls initHardDisk lookup pci_init
@7 struct @7 pciClasses[] [] pciClasses pci_init
uInt8 uInt8 subClass subClass

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: pci_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<pci/pci.h>
    #include<sys/io.h>
    #include<ubixos/types.h>
    #include<lib/kprintf.h>

    conststruct{
    uInt8baseClass;
    uInt8subClass;
    uInt8interface;
    constchar*name;
    }pciClasses[]={
    {0x00,0x00,0x00,"Undefined"},
    {0x00,0x01,0x00,"VGA"},

    {0x01,0x00,0x00,"SCSI"},
    {0x01,0x01,0x00,"IDE"},
    {0x01,0x01,0x8A,"IDE"},
    {0x01,0x02,0x00,"Floppy"},
    {0x01,0x03,0x00,"IPI"},
    {0x01,0x04,0x00,"RAID"},
    {0x01,0x80,0x00,"Other"},

    {0x02,0x00,0x00,"Ethernet"},
    {0x02,0x01,0x00,"TokenRing"},
    {0x02,0x02,0x00,"FDDI"},
    {0x02,0x03,0x00,"ATM"},
    {0x02,0x04,0x00,"ISDN"},
    {0x02,0x80,0x00,"Other"},

    {0x03,0x00,0x00,"VGA"},
    {0x03,0x00,0x01,"VGA+8514"},
    {0x03,0x01,0x00,"XGA"},
    {0x03,0x02,0x00,"3D"},
    {0x03,0x80,0x00,"VGAOther"},

    {0x04,0x00,0x00,"Video"},
    {0x04,0x01,0x00,"Audio"},
    {0x04,0x02,0x00,"Telephony"},
    {0x04,0x80,0x00,"Other"},

    {0x05,0x00,0x00,"RAM"},
    {0x05,0x01,0x00,"Flash"},
    {0x05,0x80,0x00,"Other"},

    {0x06,0x00,0x00,"PCItoHOST"},
    {0x06,0x01,0x00,"PCItoISA"},
    {0x06,0x02,0x00,"PCItoEISA"},
    {0x06,0x03,0x00,"PCItoMCA"},
    {0x06,0x04,0x00,"PCItoPCI"},
    {0x06,0x04,0x01,"PCItoPCI(SubtractiveDecode)"},
    {0x06,0x05,0x00,"PCItoPCMCIA"},
    {0x06,0x06,0x00,"PCItoNuBUS"},
    {0x06,0x07,0x00,"PCItoCardbus"},
    {0x06,0x08,0x00,"PCItoRACEway"},
    {0x06,0x09,0x00,"PCItoPCI"},
    {0x06,0x0A,0x00,"PCItoInfiBand"},
    {0x06,0x80,0x00,"PCItoOther"},

    {0x07,0x00,0x00,"Serial"},
    {0x07,0x00,0x01,"Serial-16450"},
    {0x07,0x00,0x02,"Serial-16550"},
    {0x07,0x00,0x03,"Serial-16650"},
    {0x07,0x00,0x04,"Serial-16750"},
    {0x07,0x00,0x05,"Serial-16850"},
    {0x07,0x00,0x06,"Serial-16950"},
    {0x07,0x01,0x00,"Parallel"},
    {0x07,0x01,0x01,"Parallel-BiDir"},
    {0x07,0x01,0x02,"Parallel-ECP"},
    {0x07,0x01,0x03,"Parallel-IEEE1284"},
    {0x07,0x01,0xFE,"Parallel-IEEE1284Target"},
    {0x07,0x02,0x00,"MultiportSerial"},
    {0x07,0x03,0x00,"HayesCompatibleModem"},
    {0x07,0x03,0x01,"HayesCompatibleModem,16450"},
    {0x07,0x03,0x02,"HayesCompatibleModem,16550"},
    {0x07,0x03,0x03,"HayesCompatibleModem,16650"},
    {0x07,0x03,0x04,"HayesCompatibleModem,16750"},
    {0x07,0x80,0x00,"Other"},

    {0x08,0x00,0x00,"PIC"},
    {0x08,0x00,0x01,"ISAPIC"},
    {0x08,0x00,0x02,"EISAPIC"},
    {0x08,0x00,0x10,"I/OAPIC"},
    {0x08,0x00,0x20,"I/O(x)APIC"},
    {0x08,0x01,0x00,"DMA"},
    {0x08,0x01,0x01,"ISADMA"},
    {0x08,0x01,0x02,"EISADMA"},
    {0x08,0x02,0x00,"Timer"},
    {0x08,0x02,0x01,"ISATimer"},
    {0x08,0x02,0x02,"EISATimer"},
    {0x08,0x03,0x00,"RTC"},
    {0x08,0x03,0x00,"ISARTC"},
    {0x08,0x03,0x00,"Hot-Plug"},
    {0x08,0x80,0x00,"Other"},

    {0x09,0x00,0x00,"Keyboard"},
    {0x09,0x01,0x00,"Pen"},
    {0x09,0x02,0x00,"Mouse"},
    {0x09,0x03,0x00,"Scanner"},
    {0x09,0x04,0x00,"GamePort"},
    {0x09,0x80,0x00,"Other"},

    {0x0a,0x00,0x00,"Generic"},
    {0x0a,0x80,0x00,"Other"},

    {0x0b,0x00,0x00,"386"},
    {0x0b,0x01,0x00,"486"},
    {0x0b,0x02,0x00,"Pentium"},
    {0x0b,0x03,0x00,"PentiumPro"},
    {0x0b,0x10,0x00,"DECAlpha"},
    {0x0b,0x20,0x00,"PowerPC"},
    {0x0b,0x30,0x00,"MIPS"},
    {0x0b,0x40,0x00,"Coprocessor"},
    {0x0b,0x80,0x00,"Other"},

    {0x0c,0x00,0x00,"FireWire"},
    {0x0c,0x00,0x10,"OHCIFireWire"},
    {0x0c,0x01,0x00,"Access.bus"},
    {0x0c,0x02,0x00,"SSA"},
    {0x0c,0x03,0x00,"USB(UHCI)"},
    {0x0c,0x03,0x10,"USB(OHCI)"},
    {0x0c,0x03,0x80,"USB"},
    {0x0c,0x03,0xFE,"USBDevice"},
    {0x0c,0x04,0x00,"Fiber"},
    {0x0c,0x05,0x00,"SMBusController"},
    {0x0c,0x06,0x00,"InfiniBand"},
    {0x0c,0x80,0x00,"Other"},

    {0x0d,0x00,0x00,"iRDA"},
    {0x0d,0x01,0x00,"ConsumerIR"},
    {0x0d,0x10,0x00,"RF"},
    {0x0d,0x80,0x00,"Other"},

    {0x0e,0x00,0x00,"I2O"},
    {0x0e,0x80,0x00,"Other"},

    {0x0f,0x01,0x00,"TV"},
    {0x0f,0x02,0x00,"Audio"},
    {0x0f,0x03,0x00,"Voice"},
    {0x0f,0x04,0x00,"Data"},
    {0x0f,0x80,0x00,"Other"},

    {0x10,0x00,0x00,"Network"},
    {0x10,0x10,0x00,"Entertainment"},
    {0x10,0x80,0x00,"Other"},

    {0x11,0x00,0x00,"DPIOModules"},
    {0x11,0x01,0x00,"PerformanceCounters"},
    {0x11,0x10,0x00,"CommSync,Time+FrequencyMeasurement"},
    {0x11,0x80,0x00,"Other"},

    };

    uInt32pciRead(intbus,intdev,intfunc,intreg,intbytes){
    uInt16base;

    union{
    structconfaddc;
    uInt32n;
    }u;

    u.n=0;
    u.c.enable=1;
    u.c.rsvd=0;
    u.c.bus=bus;
    u.c.dev=dev;
    u.c.func=func;
    u.c.reg=reg&0xFC;

    outportDWord(0xCF8,u.n);

    base=0xCFC+(reg&0x03);

    switch(bytes){
    case1:return(inportByte(base));
    case2:return(inportWord(base));
    case4:return(inportDWord(base));
    default:return0;
    }
    }

    voidpciWrite(intbus,intdev,intfunc,intreg,uInt32v,intbytes){
    uInt16base;

    union{
    structconfaddc;
    uInt32n;
    }u;

    u.n=0;
    u.c.enable=1;
    u.c.rsvd=0;
    u.c.bus=bus;
    u.c.dev=dev;
    u.c.func=func;
    u.c.reg=reg&0xFC;

    base=0xCFC+(reg&0x03);
    outportDWord(0xCF8,u.n);
    switch(bytes){
    case1:outportByte(base,(uInt8)v);break;
    case2:outportWord(base,(uInt16)v);break;
    case4:outportDWord(base,v);break;
    }
    }

    boolpciProbe(intbus,intdev,intfunc,structpciConfig*cfg){
    uInt32*word=(uInt32*)cfg;
    uInt32v;
    inti;
    for(i=0;i<4;i++){
    word[i]=pciRead(bus,dev,func,4*i,4);
    }
    if(cfg->vendorId==0xffff)returnFALSE;
    if(cfg->vendorId==0x0)returnFALSE;/*QuickHack*/

    cfg->bus=bus;
    cfg->dev=dev;
    cfg->func=func;
    cfg->subsysVendor=pciRead(bus,dev,func,0x2c,2);
    cfg->subsys=pciRead(bus,dev,func,0x2e,2);
    kprintf("DeviceInfo:/bus/pci/%d/%d/%d\n",bus,dev,func);
    kprintf("*Vendor:%XDevice:%XClass/SubClass/Interface%X/%X/%X\n",cfg->vendorId,cfg->deviceId,cfg->baseClass,cfg->subClass,cfg->interface);
    kprintf("*Status:%XCommand:%XBIST/Type/Lat/CLS:%X/%X/%X/%X\n",cfg->status,cfg->command,cfg->bist,cfg->headerType,cfg->latencyTimer,cfg->cacheLineSize);
    switch(cfg->headerType&0x7F){
    case0:/*normaldevice*/
    for(i=0;i<6;i++){
    v=pciRead(bus,dev,func,i*4+0x10,4);
    if(v){
    intv2;
    pciWrite(bus,dev,func,i*4+0x10,0xffffffff,4);
    v2=pciRead(bus,dev,func,i*4+0x10,4)&0xfffffff0;
    pciWrite(bus,dev,func,i*4+0x10,v,4);
    v2=1+~v2;
    if(v&1){
    cfg->base[i]=v&0xffff;
    cfg->size[i]=v2&0xffff;
    }
    else{
    cfg->base[i]=v;
    cfg->size[i]=v2;
    }
    }
    else{
    cfg->base[i]=0;
    cfg->size[i]=0;
    }
    }
    v=pciRead(bus,dev,func,0x3c,1);
    cfg->irq=(v==0xff?0:v);
    break;
    case1:
    kprintf("*PCI<->PCIBridge\n");
    break;
    default:
    kprintf("*UnknownHeaderType\n");
    break;
    }

    return(TRUE);
    }

    intpci_init(){
    uInt16bus,dev,func;
    inti=0x0;
    structpciConfigpcfg;
    for(bus=0x0;bus<0x2;bus++){/*255*/
    for(dev=0;dev<32;dev++){
    for(func=0;func<8;func++){
    if(pciProbe(bus,dev,func,&pcfg)==TRUE){
    /*kprintf("*Vendor:%XDevice:%XClass/SubClass/Interface%X/%X/%X\n",pcfg.vendorId,pcfg.deviceId,pcfg.baseClass,pcfg.subClass,pcfg.interface);*/
    for(i=0x0;i<countof(pciClasses);i++){
    if(pcfg.baseClass==pciClasses[i].baseClass&&pcfg.subClass==pciClasses[i].subClass&&pcfg.interface==pciClasses[i].interface){
    kprintf("PCIDevice:%s@IRQ:0x%X\n",pciClasses[i].name,pcfg.irq);
    break;
    }
    }
    }
    }
    }
    }
    return(0x0);
    }

    /***
    $Log: pci_8c.xml,v $
    Revision 1.6  2006/12/19 14:12:52  reddawg
    rtld-elf almost workign

    Revision1.1.1.12006/06/0112:46:16reddawg
    ubix2

    Revision1.22005/10/1200:13:37reddawg
    Removed

    Revision1.1.1.12005/09/2617:24:36reddawg
    nomessage

    Revision1.42004/08/2017:49:13reddawg
    Tinyfixens

    Revision1.32004/08/2016:49:11reddawg
    PCIUpdates-MoretofollowasPCIsystemgetsrevamped

    Revision1.22004/07/0911:58:19reddawg
    UpdatingDriverRoutines

    Revision1.1.1.12004/04/1512:07:16reddawg
    UbixOSv1.0

    Revision1.52004/04/1316:36:33reddawg
    Changedourcopyright,itisallnowunderaBSD-Stylelicense

    END
    ***/