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