Home | History | Annotate | Line # | Download | only in bootst
dev_tape.c revision 1.3
      1 /*	$NetBSD: dev_tape.c,v 1.3 1998/09/05 15:20:47 pk Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Paul Kranenburg.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * This module implements a "raw device" interface suitable for
     41  * use by the stand-alone I/O library UFS file-system code, and
     42  * possibly for direct access (i.e. boot from tape).
     43  */
     44 
     45 #include <sys/types.h>
     46 #include <machine/prom.h>
     47 
     48 #include "stand.h"
     49 #include "libsa.h"
     50 
     51 
     52 extern int debug;
     53 
     54 struct mvmeprom_dskio tape_ioreq;
     55 
     56 static int hackprom_diskrd(struct mvmeprom_dskio *);
     57 
     58 /*
     59  * This is a special version of devopen() for tape boot.
     60  * In this version, the file name is a numeric string of
     61  * one digit, which is passed to the device open so it
     62  * can open the appropriate tape segment.
     63  */
     64 int
     65 devopen(f, fname, file)
     66 	struct open_file *f;
     67 	const char *fname;		/* normally "1" */
     68 	char **file;
     69 {
     70 	struct devsw *dp;
     71 	int error;
     72 
     73 	*file = (char*)fname;
     74 	dp = &devsw[0];
     75 	f->f_dev = dp;
     76 
     77 	/* The following will call tape_open() */
     78 	return (dp->dv_open(f, fname));
     79 }
     80 
     81 int
     82 tape_open(f, fname)
     83 	struct open_file *f;
     84 	char *fname;		/* partition number, i.e. "1" */
     85 {
     86 	int	part;
     87 	struct mvmeprom_dskio *ti;
     88 
     89 	/*
     90 	 * Set the tape segment number to the one indicated
     91 	 * by the single digit fname passed in above.
     92 	 */
     93 	if ((fname[0] < '0') && (fname[0] > '9')) {
     94 		return ENOENT;
     95 	}
     96 	part = fname[0] - '0';
     97 
     98 	/*
     99 	 * Setup our part of the saioreq.
    100 	 * (determines what gets opened)
    101 	 */
    102 	ti = &tape_ioreq;
    103 	bzero((caddr_t)ti, sizeof(*ti));
    104 
    105 	ti->ctrl_lun = bugargs.ctrl_lun;
    106 	ti->dev_lun = bugargs.dev_lun;
    107 	ti->status = 0;
    108 	ti->pbuffer = NULL;
    109 	ti->blk_num = part;
    110 	ti->blk_cnt = 0;
    111 	ti->flag = 0;
    112 	ti->addr_mod = 0;
    113 
    114 	f->f_devdata = ti;
    115 
    116 	return (0);
    117 }
    118 
    119 int
    120 tape_close(f)
    121 	struct open_file *f;
    122 {
    123 	struct mvmeprom_dskio *ti;
    124 
    125 
    126 	ti = f->f_devdata;
    127 	f->f_devdata = NULL;
    128 	return 0;
    129 }
    130 
    131 #define MVMEPROM_SCALE (512/MVMEPROM_BLOCK_SIZE)
    132 
    133 int
    134 tape_strategy(devdata, flag, dblk, size, buf, rsize)
    135 	void	*devdata;
    136 	int	flag;
    137 	daddr_t	dblk;
    138 	u_int	size;
    139 	char	*buf;
    140 	u_int	*rsize;
    141 {
    142 	struct mvmeprom_dskio *ti;
    143 	int ret;
    144 
    145 	ti = devdata;
    146 
    147 	if (flag != F_READ)
    148 		return(EROFS);
    149 
    150 	ti->status = 0;
    151 	ti->pbuffer = buf;
    152 	/* don't change block #, set in open */
    153 	ti->blk_cnt = size / (512 / MVMEPROM_SCALE);
    154 
    155 	/* work around for stupid '147 prom bug */
    156 	if ( bugargs.cputyp == 0x147 )
    157 		ret = hackprom_diskrd(ti);
    158 	else
    159 		ret = mvmeprom_diskrd(ti);
    160 
    161 	if (ret != 0)
    162 		return (EIO);
    163 
    164 	*rsize = (ti->blk_cnt / MVMEPROM_SCALE) * 512;
    165 	ti->flag |= IGNORE_FILENUM; /* ignore next time */
    166 
    167 	return (0);
    168 }
    169 
    170 int
    171 tape_ioctl()
    172 {
    173 	return EIO;
    174 }
    175 
    176 static int
    177 hackprom_diskrd(struct mvmeprom_dskio *ti)
    178 {
    179 	static int blkoffset = 0;
    180 
    181 #define	hackload_addr	((char *) 0x080000)	/* Load tape segment here */
    182 #define hackload_blocks 0x2000			/* 2Mb worth */
    183 
    184 	if ( (ti->flag & IGNORE_FILENUM) == 0 ) {
    185 		/*
    186 		 * First time through. Load the whole tape segment...
    187 		 */
    188 		struct mvmeprom_dskio nti;
    189 		int ret;
    190 
    191 		nti = *ti;
    192 
    193 		nti.pbuffer = hackload_addr;
    194 		nti.blk_cnt = hackload_blocks;
    195 		nti.flag |= END_OF_FILE;
    196 
    197 		ret = mvmeprom_diskrd(&nti);
    198 
    199 		/*
    200 		 * PROM returns 1 on end-of-file. This isn't an
    201 		 * error in this instance, just in case you're wondering! ;-)
    202 		 */
    203 		if ( ret < 0 || ret > 1 )
    204 			return ret;
    205 
    206 		blkoffset = 0;
    207 	}
    208 
    209 	/*
    210 	 * Grab the required number of block(s)
    211 	 */
    212 	bcopy(&(hackload_addr[blkoffset]), ti->pbuffer,
    213 	      ti->blk_cnt * MVMEPROM_BLOCK_SIZE);
    214 
    215 	blkoffset += (ti->blk_cnt * MVMEPROM_BLOCK_SIZE);
    216 
    217 	return 0;
    218 }
    219