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

Annotation of sys/arch/mvme68k/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(struct open_file *f, const char *fname, char **file)
                     54: {
                     55:        register struct bugsc_softc *pp = &bugsc_softc[0];
                     56:        int     error, i, dn = 0, pn = 0;
                     57:        char    *dev, *cp;
                     58:        static  char iobuf[MAXBSIZE];
                     59:        struct disklabel sdlabel;
                     60:
                     61:        dev = bugargs.arg_start;
                     62:
                     63:        /*
                     64:         * Extract partition # from boot device string.
                     65:         */
                     66:        for (cp = dev; *cp; cp++) /* void */;
                     67:        while (*cp != '/' && cp > dev) {
                     68:                if (*cp == ':')
                     69:                        pn = *(cp+1) - 'a';
                     70:                --cp;
                     71:        }
                     72:
                     73:        pp->fd = bugscopen(f);
                     74:
                     75:        if (pp->fd < 0) {
                     76:                printf("Can't open device `%s'\n", dev);
                     77:                return (ENXIO);
                     78:        }
                     79:        error = bugscstrategy(pp, F_READ, LABELSECTOR, DEV_BSIZE, iobuf, &i);
                     80:        if (error)
                     81:                return (error);
                     82:        if (i != DEV_BSIZE)
                     83:                return (EINVAL);
                     84:
                     85:        cputobsdlabel(&sdlabel, (struct mvmedisklabel *)iobuf);
                     86:        pp->poff = sdlabel.d_partitions[pn].p_offset;
                     87:        pp->psize = sdlabel.d_partitions[pn].p_size;
                     88:
                     89:        f->f_dev = devsw;
                     90:        f->f_devdata = (void *)pp;
                     91:        *file = (char *)fname;
                     92:        return (0);
                     93: }
                     94:
                     95: /* silly block scale factor */
                     96: #define BUG_BLOCK_SIZE 256
                     97: #define BUG_SCALE (512/BUG_BLOCK_SIZE)
                     98:
                     99: int
                    100: bugscstrategy(void *devdata, int func, daddr_t dblk, size_t size, void *buf,
                    101:     size_t *rsize)
                    102: {
                    103:        struct mvmeprom_dskio dio;
                    104:        register struct bugsc_softc *pp = (struct bugsc_softc *)devdata;
                    105:        daddr_t blk = dblk + pp->poff;
                    106:
                    107:        twiddle();
                    108:
                    109:        dio.ctrl_lun = pp->ctrl;
                    110:        dio.dev_lun = pp->dev;
                    111:        dio.status = 0;
                    112:        dio.pbuffer = buf;
                    113:        dio.blk_num = blk * BUG_SCALE;
                    114:        dio.blk_cnt = size / BUG_BLOCK_SIZE; /* assumed size in bytes */
                    115:        dio.flag = 0;
                    116:        dio.addr_mod = 0;
                    117: #ifdef DEBUG
                    118:        printf("bugscstrategy: size=%d blk=%d buf=%x\n", size, blk, buf);
                    119:        printf("ctrl %d dev %d\n", dio.ctrl_lun, dio.dev_lun);
                    120: #endif
                    121:        mvmeprom_diskrd(&dio);
                    122:
                    123:        *rsize = dio.blk_cnt * BUG_BLOCK_SIZE;
                    124: #ifdef DEBUG
                    125: printf("rsize %d status %x\n", *rsize, dio.status);
                    126: #endif
                    127:
                    128:        if (dio.status)
                    129:                return (EIO);
                    130:        return (0);
                    131: }
                    132:
                    133: int
                    134: bugscopen(struct open_file *f)
                    135: {
                    136: #ifdef DEBUG
                    137:        printf("bugscopen:\n");
                    138: #endif
                    139:
                    140:        f->f_devdata = (void *)bugsc_softc;
                    141:        bugsc_softc[0].ctrl = (short)bugargs.ctrl_lun;
                    142:        bugsc_softc[0].dev =  (short)bugargs.dev_lun;
                    143: #ifdef DEBUG
                    144:        printf("using mvmebug ctrl %d dev %d\n",
                    145:            bugsc_softc[0].ctrl, bugsc_softc[0].dev);
                    146: #endif
                    147:        return (0);
                    148: }
                    149:
                    150: int
                    151: bugscclose(struct open_file *f)
                    152: {
                    153:        return (EIO);
                    154: }
                    155:
                    156: int
                    157: bugscioctl(struct open_file *f, u_long cmd, void *data)
                    158: {
                    159:        return (EIO);
                    160: }
                    161:
                    162: void
                    163: cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
                    164: {
                    165:        int i;
                    166:
                    167:        lp->d_magic = clp->magic1;
                    168:        lp->d_type = clp->type;
                    169:        lp->d_subtype = clp->subtype;
                    170:        bcopy(clp->vid_vd, lp->d_typename, 16);
                    171:        bcopy(clp->packname, lp->d_packname, 16);
                    172:        lp->d_secsize = clp->cfg_psm;
                    173:        lp->d_nsectors = clp->cfg_spt;
                    174:        lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */
                    175:        lp->d_ntracks = clp->cfg_hds;
                    176:
                    177:        lp->d_secpercyl = clp->secpercyl;
                    178:        lp->d_secperunit = clp->secperunit;
                    179:        lp->d_secpercyl = clp->secpercyl;
                    180:        lp->d_secperunit = clp->secperunit;
                    181:        lp->d_sparespertrack = clp->sparespertrack;
                    182:        lp->d_sparespercyl = clp->sparespercyl;
                    183:        lp->d_acylinders = clp->acylinders;
                    184:        lp->d_rpm = clp->rpm;
                    185:        lp->d_interleave = clp->cfg_ilv;
                    186:        lp->d_trackskew = clp->cfg_sof;
                    187:        lp->d_cylskew = clp->cylskew;
                    188:        lp->d_headswitch = clp->headswitch;
                    189:
                    190:        /* this silly table is for winchester drives */
                    191:        switch (clp->cfg_ssr) {
                    192:        case 0:
                    193:                lp->d_trkseek = 0;
                    194:                break;
                    195:        case 1:
                    196:                lp->d_trkseek = 6;
                    197:                break;
                    198:        case 2:
                    199:                lp->d_trkseek = 10;
                    200:                break;
                    201:        case 3:
                    202:                lp->d_trkseek = 15;
                    203:                break;
                    204:        case 4:
                    205:                lp->d_trkseek = 20;
                    206:                break;
                    207:        default:
                    208:                lp->d_trkseek = 0;
                    209:                break;
                    210:        }
                    211:        lp->d_flags = clp->flags;
                    212:        for (i = 0; i < NDDATA; i++)
                    213:                lp->d_drivedata[i] = clp->drivedata[i];
                    214:        for (i = 0; i < NSPARE; i++)
                    215:                lp->d_spare[i] = clp->spare[i];
                    216:        lp->d_magic2 = clp->magic2;
                    217:        lp->d_checksum = clp->checksum;
                    218:        lp->d_npartitions = clp->partitions;
                    219:        lp->d_bbsize = clp->bbsize;
                    220:        lp->d_sbsize = clp->sbsize;
                    221:        bcopy(clp->vid_4, &(lp->d_partitions[0]),sizeof (struct partition) * 4);
                    222:        bcopy(clp->cfg_4, &(lp->d_partitions[4]), sizeof (struct partition) *
                    223:            ((MAXPARTITIONS < 16) ? (MAXPARTITIONS - 4) : 12));
                    224: }

CVSweb