hd.c
pci/hd.h
sys/video.h
sys/device.h
sys/io.h
lib/kmalloc.h
lib/kprintf.h
devfs/devfs.h
string.h
sys/thread.h
ubixos/sched.h
src/sys/pci/hd.c
devfs/devfs.h
ubixos/types.h
sys/_types.h
sys/video.h
string.h
vfs/file.h
sys/tss.h
lib/kmalloc.h
mpi/mpi.h
vfs/vfs.h
vfs/mount.h
lib/kprintf.h
ubixfs/ubixfs.h
ubixfs/dirCache.h
pci/hd.h
sys/sysproto.h
sys/signal.h
ubixos/tty.h
sys/io.h
sys/device.h
int int hdInit (struct device_node *dev) hdInit struct device_node * dev device_node::devInfo hdCmd hdData driveInfo::hdDev driveInfo::hdEnable hdHead driveInfo::hdMask driveInfo::hdMulti driveInfo::hdPort hdSecCount driveInfo::hdSector driveInfo::hdShift driveInfo::hdSize hdStat device_interface::info device_interface::initialized inportByte inportWord kprintf outportByte device_interface::size initHardDisk
int int hdIoctl () hdIoctl initHardDisk
void void hdRead (struct driveInfo *hdd, void *baseAddr, uInt32 startSector, uInt32 sectorCount) hdRead struct driveInfo * hdd void * baseAddr uInt32 startSector uInt32 sectorCount driveInfo::hdCalc hdCmd hdCylHi hdCylLow hdData driveInfo::hdDev driveInfo::hdEnable hdHead driveInfo::hdMulti driveInfo::hdPort hdSecCount hdSecNum driveInfo::hdShift hdStat inportByte inportWord kprintf outportByte driveInfo::parOffset x20 initHardDisk
int int hdReset () hdReset initHardDisk
int int hdStandby () hdStandby initHardDisk
int int hdStart () hdStart initHardDisk
int int hdStop () hdStop initHardDisk
void void hdWrite (struct driveInfo *hdd, void *baseAddr, uInt32 startSector, uInt32 sectorCount) hdWrite struct driveInfo * hdd void * baseAddr uInt32 startSector uInt32 sectorCount driveInfo::hdCalc hdCmd hdCylHi hdCylLow hdData driveInfo::hdDev driveInfo::hdEnable hdHead driveInfo::hdMulti driveInfo::hdPort hdSecCount hdSecNum driveInfo::hdShift hdStat inportByte kprintf outportByte outportWord driveInfo::parOffset x30 initHardDisk
int int initHardDisk () initHardDisk bsd_disklabel::d_npartitions bsd_disklabel::d_partitions devfs_makeNode device_add dos_partition::dp_start fstypenames driveInfo::hdDev hdInit hdIoctl driveInfo::hdPort hdRead hdReset driveInfo::hdSize hdStandby hdStart hdStop hdWrite device_interface::info device_interface::init device_interface::ioctl kmalloc kprintf device_interface::major memcpy name bsd_disklabel::partition::p_fstype bsd_disklabel::partition::p_offset bsd_disklabel::partition::p_size driveInfo::parOffset device_interface::read device_interface::reset sprintf device_interface::standby device_interface::start device_interface::stop device_interface::write x1

    /*****************************************************************************************
    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: hd_8c.xml 88 2016-01-12 00:11:29Z reddawg $

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

    #include<pci/hd.h>
    #include<sys/video.h>
    #include<sys/device.h>
    #include<sys/io.h>
    #include<lib/kmalloc.h>
    #include<lib/kprintf.h>
    #include<devfs/devfs.h>
    #include<string.h>

    intinitHardDisk(){
    inti=0x0;
    intx=0x0;
    intminor=0x0;
    structdevice_interface*devInfo=0x0;
    structdevice_interface*devInfo2=0x0;
    structdos_partition*d=0x0;
    structdriveInfo*hdd=0x0;
    structdriveInfo*hdd2=0x0;
    char*data=0x0;
    char*data2=0x0;
    charname[16];
    structbsd_disklabel*bsdd=0x0;

    hdd=(structdriveInfo*)kmalloc(sizeof(structdriveInfo));
    hdd->hdPort=0x1F0;
    hdd->hdDev=0x40;
    hdd->parOffset=0x0;

    /*Allocmemoryfordevicestructureandsetitupcorrectly*/
    devInfo=(structdevice_interface*)kmalloc(sizeof(structdevice_interface));
    devInfo->read=(void*)&hdRead;
    devInfo->write=(void*)&hdWrite;
    devInfo->reset=(void*)&hdReset;
    devInfo->init=(void*)&hdInit;
    devInfo->ioctl=(void*)&hdIoctl;
    devInfo->stop=(void*)&hdStop;
    devInfo->start=(void*)&hdStart;
    devInfo->standby=(void*)&hdStandby;
    devInfo->info=hdd;

    devInfo->major=0x1;

    data=(char*)kmalloc(512);
    d=(structdos_partition*)(data+0x1BE);

    data2=(char*)kmalloc(512);
    bsdd=(structbsd_disklabel*)data2;

    if(device_add(0,'c',devInfo)==0x0){
    kprintf("ad0-Start:[0x0],Size:[0x%x/0x%X]\n",hdd->hdSize,hdd->hdSize*512);
    devfs_makeNode("ad0",'b',0x1,0x0);
    hdRead(devInfo->info,data,0x0,0x1);
    for(i=0x0;i<0x4;i++){
    if(d[i].dp_type!=0x0){
    devInfo2=(structdevice_interface*)kmalloc(sizeof(structdevice_interface));
    hdd2=(structdriveInfo*)kmalloc(sizeof(structdriveInfo));
    memcpy(devInfo2,devInfo,sizeof(structdevice_interface));
    memcpy(hdd2,hdd,sizeof(structdriveInfo));
    hdd2->parOffset=d[i].dp_start;
    devInfo2->info=hdd2;
    minor++;
    if(device_add(minor,'c',devInfo2)==0x0){
    sprintf(name,"ad0s%i",i+1);
    kprintf("%s-Type:[0x%X],Start:[0x%X],Size:[0x%X]\n",name,d[i].dp_type,d[i].dp_start,d[i].dp_size);
    devfs_makeNode(name,'c',0x1,minor);
    if(d[i].dp_type==0xA5){
    //Whydoineedtoadd1?
    hdRead(devInfo->info,data2,d[i].dp_start+1,0x1);
    for(x=0;x<bsdd->d_npartitions;x++){
    if(bsdd->d_partitions[x].p_size>0){
    sprintf(name,"ad0s%i%c",i+1,'a'+x);
    //NewNodes
    devInfo2=(structdevice_interface*)kmalloc(sizeof(structdevice_interface));
    hdd2=(structdriveInfo*)kmalloc(sizeof(structdriveInfo));
    memcpy(devInfo2,devInfo,sizeof(structdevice_interface));
    memcpy(hdd2,hdd,sizeof(structdriveInfo));
    //hdd2->parOffset=d[i].dp_start+bsdd->d_partitions[x].p_offset;
    hdd2->parOffset=bsdd->d_partitions[x].p_offset;
    devInfo2->info=hdd2;
    minor++;
    device_add(minor,'c',devInfo2);
    devfs_makeNode(name,'c',0x1,minor);
    kprintf("%s-Type:[%s],Start:[0x%X],Size:[0x%X],MM:[%i:%i]\n",name,fstypenames[bsdd->d_partitions[x].p_fstype],bsdd->d_partitions[x].p_offset,bsdd->d_partitions[x].p_size,devInfo->major,minor);
    }
    }
    }
    }
    }
    }
    }
    kfree(data);
    return(0x0);
    }

    inthdStandby(){
    return(0x0);
    }

    inthdStart(){
    return(0x0);
    }

    inthdStop(){
    return(0x0);
    }

    inthdIoctl(){
    return(0x0);
    }

    inthdReset(){
    return(0x0);
    }

    inthdInit(structdevice_node*dev){
    charretVal=0x0;
    longcounter=0x0;
    short*tmp=0x0;
    structdriveInfo*hdd=dev->devInfo->info;
    for(counter=1000000;counter>=0;counter--){
    retVal=inportByte(hdd->hdPort+hdStat)&0x80;
    if(!retVal)gotoready;
    }
    kprintf("ErrorInitializingDrive\n");
    return(1);
    ready:
    outportByte(hdd->hdPort+hdHead,hdd->hdDev);
    outportByte(hdd->hdPort+hdCmd,0xEC);
    for(counter=1000000;counter>=0;counter--){
    retVal=inportByte(hdd->hdPort+hdStat);
    if((retVal&1)!=0x0){
    kprintf("ErrorDriveNotAvailable\n");
    return(1);
    }
    if((retVal&8)!=0x0){
    gotogo;
    }
    }
    kprintf("TimeOutWaitingOnDrive\n");
    return(1);
    go:
    tmp=(short*)hdd->hdSector;
    for(counter=0;counter<(512/2);counter++){
    tmp[counter]=inportWord(hdd->hdPort+hdData);
    }
    retVal=tmp[0x2F]&0xFF;
    switch(retVal){
    case0:
    hdd->hdShift=0;
    hdd->hdMulti=1;
    break;
    case2:
    hdd->hdShift=1;
    hdd->hdMulti=retVal;
    break;
    case4:
    hdd->hdShift=2;
    hdd->hdMulti=retVal;
    break;
    case8:
    hdd->hdShift=3;
    hdd->hdMulti=retVal;
    break;
    case16:
    hdd->hdShift=4;
    hdd->hdMulti=retVal;
    break;
    case32:
    hdd->hdShift=5;
    hdd->hdMulti=retVal;
    break;
    case64:
    hdd->hdShift=6;
    hdd->hdMulti=retVal;
    break;
    default:
    kprintf("ErrorBLOCKModeUnavailable:[%i]\n",retVal);
    return(1);
    }
    outportByte(hdd->hdPort+hdSecCount,retVal);
    outportByte(hdd->hdPort+hdHead,hdd->hdDev);
    outportByte(hdd->hdPort+hdCmd,0xC6);
    hdd->hdMask=retVal;
    hdd->hdSize=(hdd->hdSector[0x7B]*256*256*256)+(hdd->hdSector[0x7A]*256*256)+(hdd->hdSector[0x79]*256)+hdd->hdSector[0x78];
    hdd->hdEnable=1;
    kprintf("Drive:[0x%X/0x%X],Size:[%iSectors/%iKBytes]\n",hdd->hdPort,hdd->hdDev,hdd->hdSize,((hdd->hdSize*512)/1024));
    dev->devInfo->size=hdd->hdSize*512;
    dev->devInfo->initialized=0x1;
    return(0x0);
    }

    voidhdWrite(structdriveInfo*hdd,void*baseAddr,uInt32startSector,uInt32sectorCount){
    longcounter=0x0;
    longretVal=0x0;
    shorttransactionCount=0x0;
    short*tmp=(short*)baseAddr;
    startSector+=hdd->parOffset;
    if(hdd->hdEnable==0x0){
    kprintf("InvalidDrive\n");
    return;
    }
    if((sectorCount>>hdd->hdShift)==0x0){
    hdd->hdCalc=sectorCount;/*hdd->hdMask;*/
    transactionCount=1;
    }
    else{
    hdd->hdCalc=hdd->hdMulti;
    transactionCount=sectorCount>>hdd->hdShift;
    }
    for(;transactionCount>0;transactionCount--){
    for(counter=1000000;counter>=0;counter--){
    retVal=inportByte(hdd->hdPort+hdStat)&0x80;
    if(!retVal)gotoready;
    }
    kprintf("TimeOutWaitingOnDrive\n");
    return;
    ready:
    outportByte(hdd->hdPort+hdSecCount,hdd->hdCalc);
    outportByte(hdd->hdPort+hdSecNum,(startSector&0xFF));
    retVal=startSector>>8;
    outportByte(hdd->hdPort+hdCylLow,(retVal&0xFF));
    retVal>>=8;
    outportByte(hdd->hdPort+hdCylHi,(retVal&0xFF));
    retVal>>=8;
    retVal&=0x0F;
    retVal|=(hdd->hdDev|0xA0);//TestAsPerTJ
    outportByte(hdd->hdPort+hdHead,(retVal&0xFF));
    if(hdd->hdShift>0)
    outportByte(hdd->hdPort+hdCmd,0xC5);
    else
    outportByte(hdd->hdPort+hdCmd,0x30);
    for(counter=1000000;counter>=0;counter--){
    retVal=inportByte(hdd->hdPort+hdStat);
    if((retVal&1)!=0x0){
    kprintf("HDWriteError\n");
    return;
    }
    if((retVal&8)!=0x0){
    gotogo;
    }
    }
    kprintf("TimeOutWaitingOnDrive\n");
    return;
    go:
    for(counter=0;counter<(hdd->hdCalc<<8);counter++){
    outportWord(hdd->hdPort+hdData,(short)tmp[counter]);
    }
    tmp+=(counter+0);
    startSector+=hdd->hdCalc;
    }
    return;
    }

    voidhdRead(structdriveInfo*hdd,void*baseAddr,uInt32startSector,uInt32sectorCount){
    longcounter=0x0;
    longretVal=0x0;
    shorttransactionCount=0x0;
    short*tmp=(short*)baseAddr;
    startSector+=hdd->parOffset;

    if(hdd->hdEnable==0x0){
    kprintf("InvalidDrive\n");
    return;
    }
    if((sectorCount>>hdd->hdShift)==0x0){
    hdd->hdCalc=sectorCount;/*hdd->hdMask);*/
    transactionCount=1;
    }
    else{
    hdd->hdCalc=hdd->hdMulti;
    transactionCount=sectorCount>>hdd->hdShift;
    }
    for(;transactionCount>0;transactionCount--){
    for(counter=1000000;counter>=0;counter--){
    retVal=inportByte(hdd->hdPort+hdStat)&0x80;
    if(!retVal)gotoready;
    }
    kprintf("TimeOutWaitingOnDrive\n");
    return;
    ready:
    outportByte(hdd->hdPort+hdSecCount,hdd->hdCalc);
    outportByte(hdd->hdPort+hdSecNum,(startSector&0xFF));
    retVal=startSector>>8;
    outportByte(hdd->hdPort+hdCylLow,(retVal&0xFF));
    retVal>>=8;
    outportByte(hdd->hdPort+hdCylHi,(retVal&0xFF));
    retVal>>=8;
    retVal&=0x0F;
    retVal|=(hdd->hdDev|0xA0);//TestasperTJ
    //retVal|=hdd->hdDev;//retVal|=(hdd->hdDev|0xA0);//TestasperTJ
    outportByte(hdd->hdPort+hdHead,(retVal&0xFF));
    if(hdd->hdShift>0)
    outportByte(hdd->hdPort+hdCmd,0xC4);
    else
    outportByte(hdd->hdPort+hdCmd,0x20);
    for(counter=1000000;counter>=0;counter--){
    retVal=inportByte(hdd->hdPort+hdStat);
    if((retVal&1)!=0x0){
    kprintf("HDReadError:[%i:0x%X:%i]\n",counter,(uInt32)baseAddr,startSector);
    return;
    }
    if((retVal&8)!=0x0){
    gotogo;
    }
    }
    kprintf("Error:TimeOutWaitingOnDrive\n");
    return;
    go:
    for(counter=0;counter<(hdd->hdCalc<<8);counter++){
    tmp[counter]=inportWord(hdd->hdPort+hdData);
    }
    tmp+=(counter+0);
    startSector+=hdd->hdCalc;
    }
    return;
    }

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

    Revision1.52006/10/1215:00:26reddawg
    Morechanges

    Revision1.42006/10/1014:14:01reddawg
    UFSReading

    Revision1.32006/10/0902:58:05reddawg
    FixingUFS

    Revision1.22006/10/0615:48:01reddawg
    StartingtomakeubixosworkwithUFS2

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

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

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

    Revision1.162004/08/2622:51:19reddawg
    TCAtouchedme:(ithinkhelikesmen....

    sched.h:kTask_taddedparentPid
    endtask.c:fixedtermbacktoparentPid
    exec.c:cleanedwarnings
    fork.c:fixedtermtochildPid
    sched.c:cleanupfordeadtasks
    systemtask.c:cleanupdeadtasks
    kmalloc.c:cleanedupwarnings
    udp.c:cleanedupwarnings
    bot.c:cleanedupwarnings
    shell.c:cleanedupwarnings
    tcpdump.c:tookadump
    hd.c:cleanedupwarnings
    ubixfs.c:stoppedprningdebuginfo

    Revision1.152004/08/1500:33:02reddawg
    Wowtheidedriverworksagain

    Revision1.142004/08/1421:56:44reddawg
    Addedinitializedbytetothedevicesystemtomakeiteasytoaddchilddeviceswhichuseparenthardware.

    Revision1.132004/08/0211:43:17reddawg
    Fixens

    Revision1.122004/07/2110:02:09reddawg
    devfs:renamedfunctions
    devicesystem:renamedfunctions
    fdc:fixedafewpotentialbugsandcleanedupsomeunusedvariables
    strol:fixeddefinition
    endtask:madeitprintoutfreepagedebuginfo
    kmalloc:fixedahugememoryleakwehadsomeunhandleddescriptorinsertionsosomedescriptorswerelost
    ld:fixedapointerconversion
    file:cleanedupafewunusedvariables
    sched:broketaskdeletion
    kprintf:fixedogPrintfdefinition

    Revision1.112004/05/1923:36:52reddawg
    BugFixes

    Revision1.102004/05/1915:20:06reddawg
    Fixedreferenceproblemsduetochangesindrivesubsystem

    Revision1.92004/05/1915:07:59reddawg
    TypodefInfoshouldofbeendevInfo

    Revision1.72004/05/1904:07:43reddawg
    kmalloc(size,pid)nomoreitisnokmalloc(size);thewayitshouldofbeen

    Revision1.62004/04/2821:10:40reddawg
    LotsOfchangestomakeitworkwithexistingos

    Revision1.52004/04/2802:37:34reddawg
    Moreupdatesforusingthenewdriversubsystem

    Revision1.42004/04/2802:22:54reddawg
    Thisisafiarlylargecommitbutwearestartingtousenewdrivermodel
    allaround

    Revision1.32004/04/2721:05:19reddawg
    Updatingdriverstousenewmodel

    Revision1.22004/04/2622:22:33reddawg
    DevFSnowusescorrectsizeofdevice

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

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

    END
    ***/