[BACK]Return to bugdev.c CVS log [TXT][DIR] Up to [local] / sys / arch / mvme88k / stand / libsa

Annotation of sys/arch/mvme88k/stand/libsa/bugdev.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: bugdev.c,v 1.4 2007/06/17 00:28:56 deraadt Exp $ */
                      2:
                      3: /*
                      4:  * Copyright (c) 1993 Paul Kranenburg
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *      This product includes software developed by Paul Kranenburg.
                     18:  * 4. The name of the author may not be used to endorse or promote products
                     19:  *    derived from this software without specific prior written permission
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     22:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     23:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     24:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     25:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     26:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     27:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     28:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     29:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     30:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     31:  */
                     32:
                     33: #include <sys/param.h>
                     34: #include <sys/disklabel.h>
                     35: #include <machine/prom.h>
                     36:
                     37: #include "stand.h"
                     38: #include "libsa.h"
                     39:
                     40: void cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp);
                     41:
                     42: int errno;
                     43:
                     44: struct bugsc_softc {
                     45:        int     fd;     /* Prom file descriptor */
                     46:        int     poff;   /* Partition offset */
                     47:        int     psize;  /* Partition size */
                     48:        short   ctrl;
                     49:        short   dev;
                     50: } bugsc_softc[1];
                     51:
                     52: int
                     53: devopen(f, fname, file)
                     54:        struct open_file *f;
                     55:        const char *fname;
                     56:        char **file;
                     57: {
                     58:        register struct bugsc_softc *pp = &bugsc_softc[0];
                     59:        size_t i;
                     60:        int error, pn = 0;
                     61:        char    *dev, *cp;
                     62:        static  char iobuf[MAXBSIZE];
                     63:        struct disklabel sdlabel;
                     64:
                     65:        dev = bugargs.arg_start;
                     66:
                     67:        /*
                     68:         * Extract partition # from boot device string.
                     69:         */
                     70:        for (cp = dev; *cp; cp++) /* void */;
                     71:        while (*cp != '/' && cp > dev) {
                     72:                if (*cp == ':')
                     73:                        pn = *(cp+1) - 'a';
                     74:                --cp;
                     75:        }
                     76:
                     77:        pp->fd = bugscopen(f);
                     78:
                     79:        if (pp->fd < 0) {
                     80:                printf("Can't open device `%s'\n", dev);
                     81:                return (ENXIO);
                     82:        }
                     83:        error = bugscstrategy(pp, F_READ, LABELSECTOR, DEV_BSIZE, iobuf, &i);
                     84:        if (error)
                     85:                return (error);
                     86:        if (i != DEV_BSIZE)
                     87:                return (EINVAL);
                     88:
                     89:        cputobsdlabel(&sdlabel, (struct mvmedisklabel *)iobuf);
                     90:        pp->poff = sdlabel.d_partitions[pn].p_offset;
                     91:        pp->psize = sdlabel.d_partitions[pn].p_size;
                     92:
                     93:        f->f_dev = devsw;
                     94:        f->f_devdata = (void *)pp;
                     95:        *file = (char *)fname;
                     96:        return (0);
                     97: }
                     98:
                     99: /* silly block scale factor */
                    100: #define BUG_BLOCK_SIZE 256
                    101: #define BUG_SCALE (512/BUG_BLOCK_SIZE)
                    102: int
                    103: bugscstrategy(devdata, func, dblk, size, buf, rsize)
                    104:        void *devdata;
                    105:        int func;
                    106:        daddr_t dblk;
                    107:        size_t size;
                    108:        void *buf;
                    109:        size_t *rsize;
                    110: {
                    111:        struct mvmeprom_dskio dio;
                    112:        register struct bugsc_softc *pp = (struct bugsc_softc *)devdata;
                    113:        daddr_t blk = dblk + pp->poff;
                    114:
                    115:        twiddle();
                    116:
                    117:        dio.ctrl_lun = pp->ctrl;
                    118:        dio.dev_lun = pp->dev;
                    119:        dio.status = 0;
                    120:        dio.pbuffer = buf;
                    121:        dio.blk_num = blk * BUG_SCALE;
                    122:        dio.blk_cnt = size / BUG_BLOCK_SIZE; /* assumed size in bytes */
                    123:        dio.flag = 0;
                    124:        dio.addr_mod = 0;
                    125: #ifdef DEBUG
                    126:        printf("bugscstrategy: size=%d blk=%d buf=%x\n", size, blk, buf);
                    127:        printf("ctrl %d dev %d\n", dio.ctrl_lun, dio.dev_lun);
                    128: #endif
                    129:        mvmeprom_diskrd(&dio);
                    130:
                    131:        *rsize = dio.blk_cnt * BUG_BLOCK_SIZE;
                    132: #ifdef DEBUG
                    133: printf("rsize %d status %x\n", *rsize, dio.status);
                    134: #endif
                    135:
                    136:        if (dio.status)
                    137:                return (EIO);
                    138:        return (0);
                    139: }
                    140:
                    141: int
                    142: bugscopen(f)
                    143:        struct open_file *f;
                    144: {
                    145: #ifdef DEBUG
                    146:        printf("bugscopen:\n");
                    147: #endif
                    148:
                    149:        f->f_devdata = (void *)bugsc_softc;
                    150:        bugsc_softc[0].ctrl = (short)bugargs.ctrl_lun;
                    151:        bugsc_softc[0].dev =  (short)bugargs.dev_lun;
                    152: #ifdef DEBUG
                    153:        printf("using mvmebug ctrl %d dev %d\n",
                    154:            bugsc_softc[0].ctrl, bugsc_softc[0].dev);
                    155: #endif
                    156:        return (0);
                    157: }
                    158:
                    159: int
                    160: bugscclose(f)
                    161:        struct open_file *f;
                    162: {
                    163:        return (EIO);
                    164: }
                    165:
                    166: int
                    167: bugscioctl(f, cmd, data)
                    168:        struct open_file *f;
                    169:        u_long cmd;
                    170:        void *data;
                    171: {
                    172:        return (EIO);
                    173: }
                    174:
                    175: void
                    176: cputobsdlabel(lp, clp)
                    177:        struct disklabel *lp;
                    178:        struct mvmedisklabel *clp;
                    179: {
                    180:        int i;
                    181:
                    182:        lp->d_magic = clp->magic1;
                    183:        lp->d_type = clp->type;
                    184:        lp->d_subtype = clp->subtype;
                    185:        bcopy(clp->vid_vd, lp->d_typename, 16);
                    186:        bcopy(clp->packname, lp->d_packname, 16);
                    187:        lp->d_secsize = clp->cfg_psm;
                    188:        lp->d_nsectors = clp->cfg_spt;
                    189:        lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */
                    190:        lp->d_ntracks = clp->cfg_hds;
                    191:
                    192:        lp->d_secpercyl = clp->secpercyl;
                    193:        lp->d_secperunit = clp->secperunit;
                    194:        lp->d_secpercyl = clp->secpercyl;
                    195:        lp->d_secperunit = clp->secperunit;
                    196:        lp->d_sparespertrack = clp->sparespertrack;
                    197:        lp->d_sparespercyl = clp->sparespercyl;
                    198:        lp->d_acylinders = clp->acylinders;
                    199:        lp->d_rpm = clp->rpm;
                    200:        lp->d_interleave = clp->cfg_ilv;
                    201:        lp->d_trackskew = clp->cfg_sof;
                    202:        lp->d_cylskew = clp->cylskew;
                    203:        lp->d_headswitch = clp->headswitch;
                    204:
                    205:        /* this silly table is for winchester drives */
                    206:        switch (clp->cfg_ssr) {
                    207:        case 0:
                    208:                lp->d_trkseek = 0;
                    209:                break;
                    210:        case 1:
                    211:                lp->d_trkseek = 6;
                    212:                break;
                    213:        case 2:
                    214:                lp->d_trkseek = 10;
                    215:                break;
                    216:        case 3:
                    217:                lp->d_trkseek = 15;
                    218:                break;
                    219:        case 4:
                    220:                lp->d_trkseek = 20;
                    221:                break;
                    222:        default:
                    223:                lp->d_trkseek = 0;
                    224:                break;
                    225:        }
                    226:        lp->d_flags = clp->flags;
                    227:        for (i = 0; i < NDDATA; i++)
                    228:                lp->d_drivedata[i] = clp->drivedata[i];
                    229:        for (i = 0; i < NSPARE; i++)
                    230:                lp->d_spare[i] = clp->spare[i];
                    231:        lp->d_magic2 = clp->magic2;
                    232:        lp->d_checksum = clp->checksum;
                    233:        lp->d_npartitions = clp->partitions;
                    234:        lp->d_bbsize = clp->bbsize;
                    235:        lp->d_sbsize = clp->sbsize;
                    236:        bcopy(clp->vid_4, &(lp->d_partitions[0]),sizeof (struct partition) * 4);
                    237:        bcopy(clp->cfg_4, &(lp->d_partitions[4]), sizeof (struct partition)
                    238:                * ((MAXPARTITIONS < 16) ? (MAXPARTITIONS - 4) : 12));
                    239: }

CVSweb