Home | History | Annotate | Line # | Download | only in bootst
dev_tape.c revision 1.2
      1  1.2    scw /*	$NetBSD: dev_tape.c,v 1.2 1997/12/17 21:28:02 scw 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 /*
     34  1.1  chuck  * This module implements a "raw device" interface suitable for
     35  1.1  chuck  * use by the stand-alone I/O library UFS file-system code, and
     36  1.1  chuck  * possibly for direct access (i.e. boot from tape).
     37  1.1  chuck  */
     38  1.1  chuck 
     39  1.1  chuck #include <sys/types.h>
     40  1.1  chuck #include <machine/prom.h>
     41  1.1  chuck 
     42  1.1  chuck #include "stand.h"
     43  1.1  chuck #include "libsa.h"
     44  1.1  chuck 
     45  1.1  chuck 
     46  1.1  chuck extern int debug;
     47  1.1  chuck 
     48  1.1  chuck struct mvmeprom_dskio tape_ioreq;
     49  1.1  chuck 
     50  1.2    scw static int hackprom_diskrd(struct mvmeprom_dskio *);
     51  1.2    scw 
     52  1.1  chuck /*
     53  1.1  chuck  * This is a special version of devopen() for tape boot.
     54  1.1  chuck  * In this version, the file name is a numeric string of
     55  1.1  chuck  * one digit, which is passed to the device open so it
     56  1.1  chuck  * can open the appropriate tape segment.
     57  1.1  chuck  */
     58  1.1  chuck int
     59  1.1  chuck devopen(f, fname, file)
     60  1.1  chuck 	struct open_file *f;
     61  1.1  chuck 	const char *fname;		/* normally "1" */
     62  1.1  chuck 	char **file;
     63  1.1  chuck {
     64  1.1  chuck 	struct devsw *dp;
     65  1.1  chuck 	int error;
     66  1.1  chuck 
     67  1.1  chuck 	*file = (char*)fname;
     68  1.1  chuck 	dp = &devsw[0];
     69  1.1  chuck 	f->f_dev = dp;
     70  1.1  chuck 
     71  1.1  chuck 	/* The following will call tape_open() */
     72  1.1  chuck 	return (dp->dv_open(f, fname));
     73  1.1  chuck }
     74  1.1  chuck 
     75  1.1  chuck int
     76  1.1  chuck tape_open(f, fname)
     77  1.1  chuck 	struct open_file *f;
     78  1.1  chuck 	char *fname;		/* partition number, i.e. "1" */
     79  1.1  chuck {
     80  1.2    scw 	int	part;
     81  1.1  chuck 	struct mvmeprom_dskio *ti;
     82  1.1  chuck 
     83  1.1  chuck 	/*
     84  1.1  chuck 	 * Set the tape segment number to the one indicated
     85  1.1  chuck 	 * by the single digit fname passed in above.
     86  1.1  chuck 	 */
     87  1.1  chuck 	if ((fname[0] < '0') && (fname[0] > '9')) {
     88  1.1  chuck 		return ENOENT;
     89  1.1  chuck 	}
     90  1.1  chuck 	part = fname[0] - '0';
     91  1.1  chuck 
     92  1.1  chuck 	/*
     93  1.1  chuck 	 * Setup our part of the saioreq.
     94  1.1  chuck 	 * (determines what gets opened)
     95  1.1  chuck 	 */
     96  1.1  chuck 	ti = &tape_ioreq;
     97  1.1  chuck 	bzero((caddr_t)ti, sizeof(*ti));
     98  1.1  chuck 
     99  1.1  chuck 	ti->ctrl_lun = bugargs.ctrl_lun;
    100  1.1  chuck 	ti->dev_lun = bugargs.dev_lun;
    101  1.1  chuck 	ti->status = 0;
    102  1.1  chuck 	ti->pbuffer = NULL;
    103  1.1  chuck 	ti->blk_num = part;
    104  1.1  chuck 	ti->blk_cnt = 0;
    105  1.1  chuck 	ti->flag = 0;
    106  1.1  chuck 	ti->addr_mod = 0;
    107  1.1  chuck 
    108  1.1  chuck 	f->f_devdata = ti;
    109  1.1  chuck 
    110  1.2    scw 	return (0);
    111  1.1  chuck }
    112  1.1  chuck 
    113  1.1  chuck int
    114  1.1  chuck tape_close(f)
    115  1.1  chuck 	struct open_file *f;
    116  1.1  chuck {
    117  1.1  chuck 	struct mvmeprom_dskio *ti;
    118  1.1  chuck 
    119  1.1  chuck 
    120  1.1  chuck 	ti = f->f_devdata;
    121  1.1  chuck 	f->f_devdata = NULL;
    122  1.1  chuck 	return 0;
    123  1.1  chuck }
    124  1.1  chuck 
    125  1.1  chuck #define MVMEPROM_SCALE (512/MVMEPROM_BLOCK_SIZE)
    126  1.1  chuck 
    127  1.1  chuck int
    128  1.1  chuck tape_strategy(devdata, flag, dblk, size, buf, rsize)
    129  1.1  chuck 	void	*devdata;
    130  1.1  chuck 	int	flag;
    131  1.1  chuck 	daddr_t	dblk;
    132  1.1  chuck 	u_int	size;
    133  1.1  chuck 	char	*buf;
    134  1.1  chuck 	u_int	*rsize;
    135  1.1  chuck {
    136  1.1  chuck 	struct mvmeprom_dskio *ti;
    137  1.1  chuck 	int ret;
    138  1.1  chuck 
    139  1.1  chuck 	ti = devdata;
    140  1.1  chuck 
    141  1.1  chuck 	if (flag != F_READ)
    142  1.1  chuck 		return(EROFS);
    143  1.1  chuck 
    144  1.1  chuck 	ti->status = 0;
    145  1.1  chuck 	ti->pbuffer = buf;
    146  1.1  chuck 	/* don't change block #, set in open */
    147  1.1  chuck 	ti->blk_cnt = size / (512 / MVMEPROM_SCALE);
    148  1.1  chuck 
    149  1.2    scw 	/* work around for stupid '147 prom bug */
    150  1.2    scw 	if ( bugargs.cputyp == 0x147 )
    151  1.2    scw 		ret = hackprom_diskrd(ti);
    152  1.2    scw 	else
    153  1.2    scw 		ret = mvmeprom_diskrd(ti);
    154  1.1  chuck 
    155  1.1  chuck 	if (ret != 0)
    156  1.1  chuck 		return (EIO);
    157  1.1  chuck 
    158  1.1  chuck 	*rsize = (ti->blk_cnt / MVMEPROM_SCALE) * 512;
    159  1.1  chuck 	ti->flag |= IGNORE_FILENUM; /* ignore next time */
    160  1.1  chuck 
    161  1.1  chuck 	return (0);
    162  1.1  chuck }
    163  1.1  chuck 
    164  1.1  chuck int
    165  1.1  chuck tape_ioctl()
    166  1.1  chuck {
    167  1.1  chuck 	return EIO;
    168  1.1  chuck }
    169  1.1  chuck 
    170  1.2    scw static int
    171  1.2    scw hackprom_diskrd(struct mvmeprom_dskio *ti)
    172  1.2    scw {
    173  1.2    scw 	static int blkoffset = 0;
    174  1.2    scw 
    175  1.2    scw #define	hackload_addr	((char *) 0x080000)	/* Load tape segment here */
    176  1.2    scw #define hackload_blocks 0x2000			/* 2Mb worth */
    177  1.2    scw 
    178  1.2    scw 	if ( (ti->flag & IGNORE_FILENUM) == 0 ) {
    179  1.2    scw 		/*
    180  1.2    scw 		 * First time through. Load the whole tape segment...
    181  1.2    scw 		 */
    182  1.2    scw 		struct mvmeprom_dskio nti;
    183  1.2    scw 		int ret;
    184  1.2    scw 
    185  1.2    scw 		nti = *ti;
    186  1.2    scw 
    187  1.2    scw 		nti.pbuffer = hackload_addr;
    188  1.2    scw 		nti.blk_cnt = hackload_blocks;
    189  1.2    scw 		nti.flag |= END_OF_FILE;
    190  1.2    scw 
    191  1.2    scw 		ret = mvmeprom_diskrd(&nti);
    192  1.2    scw 
    193  1.2    scw 		/*
    194  1.2    scw 		 * PROM returns 1 on end-of-file. This isn't an
    195  1.2    scw 		 * error in this instance, just in case you're wondering! ;-)
    196  1.2    scw 		 */
    197  1.2    scw 		if ( ret < 0 || ret > 1 )
    198  1.2    scw 			return ret;
    199  1.2    scw 
    200  1.2    scw 		blkoffset = 0;
    201  1.2    scw 	}
    202  1.2    scw 
    203  1.2    scw 	/*
    204  1.2    scw 	 * Grab the required number of block(s)
    205  1.2    scw 	 */
    206  1.2    scw 	bcopy(&(hackload_addr[blkoffset]), ti->pbuffer,
    207  1.2    scw 	      ti->blk_cnt * MVMEPROM_BLOCK_SIZE);
    208  1.2    scw 
    209  1.2    scw 	blkoffset += (ti->blk_cnt * MVMEPROM_BLOCK_SIZE);
    210  1.2    scw 
    211  1.2    scw 	return 0;
    212  1.2    scw }
    213