Annotation of cci/sys/stand/xpformat.c, revision 1.1

1.1     ! root        1: /*
        !             2: /* format disk on Xylogics controller - fsd/smd/fujitsu type */
        !             3: /**/
        !             4: 
        !             5: #include "../machine/mtpr.h"
        !             6: #include "../h/param.h"
        !             7: #include "../h/inode.h"
        !             8: #include "../h/xpreg.h"
        !             9: #include "saio.h"
        !            10: 
        !            11: char disk[10] ;                        /* disk type (smd/fsd/fuj) */
        !            12: char drive[10] ;               /* drive number */
        !            13: char start[10];        
        !            14: char buf[512];                 /* format data buffer */
        !            15: 
        !            16: int vdebug = 1;
        !            17: 
        !            18: long   xpstand[] = {
        !            19:                0x0fee40 };
        !            20: 
        !            21: struct xp_iopb *iopb = &iopbx;
        !            22: int dsktype;
        !            23: int nsect,ncyl,ntrack;
        !            24: 
        !            25: #define XY_SHORT(x)    (short)((((x) >> 8) & 0xff) + (((x) << 8) & 0xff00))
        !            26: #define        b_cylin b_resid
        !            27: int xytimeout;
        !            28: #define POLLTILLDONE(x) { xytimeout = 1000*(x); \
        !            29:                        while (xpaddr->xpcsr & XP_GBSY) { \
        !            30:                                DELAY(1000); \
        !            31:                                xytimeout--; \
        !            32:                                if (xytimeout <= 0) { \
        !            33:                                        printf("XY timeout\n"); \
        !            34:                                        return(0); \
        !            35:                                } \
        !            36:                        } \
        !            37:                }
        !            38: 
        !            39: main()
        !            40: {
        !            41:        int j, c, i, n;
        !            42: 
        !            43:        printf("Drive type [fsd/smd/fuj]: ");
        !            44:        gets(disk);
        !            45:        printf("Drive number [0-3]: ");
        !            46:        gets(drive);
        !            47:        j = number(drive);
        !            48:        if ((strcmp(disk,"fsd") || strcmp(disk,"smd") ||
        !            49:             strcmp(disk,"fuj")) && ( j <= 3))
        !            50:        {
        !            51:                if (xpstart(disk,j) == 0) {
        !            52:                        printf("Initialization failed (drive not ready?), giving up!\n");
        !            53:                        return;
        !            54:                }
        !            55:                printf("Type  <return> to start formatting ");
        !            56:                gets(start);
        !            57:                if (xpformat(disk,j)); 
        !            58:                        printf("Formatting completed. \n");
        !            59:        }
        !            60:        else if (j>3) printf("Illegal drive number\n");
        !            61:             else printf("Illegal drive type\n"); 
        !            62: }
        !            63: 
        !            64: int number (response)
        !            65: char *response;
        !            66: {
        !            67:        int     i, j;
        !            68:        
        !            69:        j = 0;  /* Total */
        !            70:        while (*response == ' ' || *response == '\t') response++;
        !            71:        while (*response >= '0' && *response <= '9') {
        !            72:                j = j*10 + *response - '0';
        !            73:                response++;
        !            74:        }
        !            75:        return (j);
        !            76: }
        !            77: 
        !            78: xpstart(disk,unit)
        !            79: char *disk;
        !            80: int unit;
        !            81: {
        !            82:        struct xpdevice *xpaddr;
        !            83:        int ret;
        !            84: 
        !            85:        /*
        !            86:         * Check if a drive is really there. (NOP selects the drive and
        !            87:         * returns DRDY status
        !            88:         */
        !            89:        xpmkiopb(XP_NOP,unit,0,0,0,0,0,0);
        !            90:        iopb->io_comm &= ~XP_IEN;               /* disable interrupts */
        !            91: 
        !            92:        xpaddr = (struct xpdevice *)(xpstand[0] + IOBASE); /* formatting on cntl 0  */
        !            93:        ret = xpaddr->xpreset;                  /* reset controller */
        !            94:        DELAY(400);                             /* wait 400 ns */
        !            95:        xpdgo(xpaddr,iopb);     /* start the controller */
        !            96:        DELAY(200);     /* wait 200 ns before checking CSR for completion */
        !            97: 
        !            98:        POLLTILLDONE(1)
        !            99:        DELAY(200);
        !           100:        uncache((char *)&iopb->io_status);
        !           101:        if ((XY_SHORT(iopb->io_status) != 5) ||  /* 5 = no errors, xy450, DONE */
        !           102:                !(xpaddr->xpcsr & XP_DRDY) ||   /* drive is not ready */
        !           103:                (xpaddr->xpcsr & (XP_ERR | XP_DERR))) { /* errors? */
        !           104:                        printf("XY start error. Status = %x, xpcsr= %x\n",
        !           105:                                XY_SHORT(iopb->io_status),xpaddr->xpcsr);
        !           106:                return(0);
        !           107:        }
        !           108:        /*
        !           109:         * now set the drive size parameters in the controller 
        !           110:        */
        !           111:        if (strcmp(disk,"fsd")) {
        !           112:                xpmkiopb(XP_DSIZE,unit,9,822,31,0,0,0); /* 160M fsd */
        !           113:                dsktype = 0;
        !           114:                nsect = 32;
        !           115:                ncyl = 823;
        !           116:                ntrack = 10;
        !           117:        }
        !           118:        else
        !           119:          if (strcmp(disk,"smd")) {
        !           120:                xpmkiopb(XP_DSIZE,unit,18,822,31,0,0,0x40); /* 300M smd */
        !           121:                dsktype = 0x40;
        !           122:                nsect = 32;
        !           123:                ncyl = 823;
        !           124:                ntrack = 19;
        !           125:          }
        !           126:          else {
        !           127:                xpmkiopb(XP_DSIZE,unit,19,841,45,0,0,0x80);  /* 474M Fujitsu */
        !           128:                dsktype = 0x80;
        !           129:                nsect = 46;
        !           130:                ncyl = 842;
        !           131:                ntrack = 20;
        !           132:               }
        !           133:        iopb->io_comm &= ~XP_IEN;       /* disable interrupts */
        !           134:        xpdgo(xpaddr,iopb);
        !           135:        DELAY(200);
        !           136: 
        !           137:        POLLTILLDONE(1)
        !           138:        DELAY(200);
        !           139:        uncache((char *)&iopb->io_status);
        !           140:        if ((XY_SHORT(iopb->io_status) != 5) ||                 /* errors */
        !           141:                !(xpaddr->xpcsr & XP_DRDY) ||
        !           142:                (xpaddr->xpcsr & (XP_ERR | XP_DERR))) 
        !           143:        {
        !           144:                printf("XY set size error. status= %x, drive $d, type %s\n",
        !           145:                        XY_SHORT(iopb->io_status),unit,disk);
        !           146:                return(0);
        !           147:        }
        !           148:        else return(1);
        !           149: }
        !           150: 
        !           151: xpformat(disk,unit)
        !           152: char disk[10];
        !           153: int unit;
        !           154: {
        !           155:        struct xpdevice *xpaddr;
        !           156:        int i,j,flag;
        !           157: 
        !           158:        xpaddr = (struct xpdevice *)(xpstand[0] + IOBASE); /* formatting on cntl 0  */
        !           159:        xpmkiopb(XP_FORMAT,unit,0,0,0,nsect,0,dsktype); 
        !           160:        for (i=0; i<ncyl; i++) {
        !           161:                iopb->io_comm &= ~XP_IEN;       /* disable interrupts */
        !           162:                iopb->io_status = 0;
        !           163:                iopb->io_sect = 0;
        !           164:                iopb->io_scnt = XY_SHORT(nsect*ntrack);
        !           165:                iopb->io_cyl = XY_SHORT(i);
        !           166:                iopb->io_head = 0;
        !           167:                xpdgo(xpaddr,iopb);
        !           168:                DELAY(200);
        !           169: 
        !           170:                POLLTILLDONE(1*60)
        !           171:                DELAY(200);
        !           172:                uncache((char *)&iopb->io_status);
        !           173:                if ((XY_SHORT(iopb->io_status) != 5) ||
        !           174:                        (xpaddr->xpcsr & (XP_ERR | XP_DERR)) )
        !           175:                {
        !           176:                        printf("XY format error %x, drive $d, type %s\n",
        !           177:                                XY_SHORT(iopb->io_status),unit,disk);
        !           178:                        return(0);
        !           179:                }
        !           180:                printf(".");
        !           181:        }
        !           182:        return(1);
        !           183: }
        !           184: 
        !           185: strcmp(str1,str2)
        !           186: char *str1;
        !           187: char *str2;
        !           188: {
        !           189: 
        !           190:        while (*str1++ && *str2++ ) 
        !           191:                if (*str1 != *str2) return(0) ;
        !           192:        return(1);
        !           193: } 
        !           194:                        
        !           195: /*
        !           196:  * Now all ready to go, stuff the registers.
        !           197:  */
        !           198: xpdgo(xpaddr, iopb)
        !           199:        register struct xpdevice *xpaddr;
        !           200:        register struct xp_iopb *iopb;
        !           201: {
        !           202:        xpmovob( (u_char)((int)iopb >> 24),&xpaddr->xpmrel );
        !           203:        DELAY(5);
        !           204:        xpmovob( (u_char)((int)iopb >> 16),&xpaddr->xplrel );
        !           205:        DELAY(5);
        !           206:        xpmovob( (u_char)((int)iopb >> 8),&xpaddr->xpmba );
        !           207:        DELAY(5);
        !           208:        xpmovob( (u_char)((int)iopb),&xpaddr->xplba );
        !           209:        DELAY(5);
        !           210:        xpmovob( XP_GBSY,&xpaddr->xpcsr) ;
        !           211: }
        !           212: 
        !           213: /*
        !           214:  * Fill the iopb with the appropriate data.
        !           215:  */
        !           216: xpmkiopb(cmd,unit,head,cylinder,sector,scount,baddr,xptype)
        !           217:   unsigned int cmd, unit, head, cylinder, sector, scount, xptype;
        !           218:   caddr_t baddr;
        !           219: {
        !           220:        iopb->io_comm = cmd | XP_RELO ;
        !           221:        iopb->io_imode = XPM_ASR | XPM_EEF | XPM_ECC;
        !           222:        iopb->io_throt = XPT_T128;
        !           223:        iopb->io_drive = xptype | unit;
        !           224:        iopb->io_head = head;
        !           225:        iopb->io_sect = sector;
        !           226:        iopb->io_cyl = XY_SHORT(cylinder);
        !           227:        iopb->io_scnt = XY_SHORT(scount);
        !           228:        iopb->io_mladdr = XY_SHORT((int)baddr & 0xffff);
        !           229:        iopb->io_mhaddr = XY_SHORT(((int)baddr >> 16) & 0xffff);
        !           230:        iopb->io_status = 0;
        !           231: }
        !           232: 
        !           233: xpmovob(byte, destination)
        !           234: long byte, destination;
        !           235: {
        !           236:        asm("movob      7(fp),*8(fp);");
        !           237: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.