1 /* $NetBSD: dev_tape.c,v 1.10 2008/04/28 20:23:29 martin Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * This module implements a "raw device" interface suitable for
34 * use by the stand-alone I/O library UFS file-system code, and
35 * possibly for direct access (i.e. boot from tape).
38 #include <sys/types.h>
39 #include <machine/prom.h>
40 #include <machine/stdarg.h>
42 #include <lib/libkern/libkern.h>
44 #include <lib/libsa/stand.h>
50 struct mvmeprom_dskio tape_ioreq
;
52 static int hackprom_diskrd(struct mvmeprom_dskio
*);
55 * This is a special version of devopen() for tape boot.
56 * In this version, the file name is a numeric string of
57 * one digit, which is passed to the device open so it
58 * can open the appropriate tape segment.
61 devopen(struct open_file
*f
, const char *fname
, char **file
)
65 *file
= (char *)fname
;
69 /* The following will call tape_open() */
70 return dp
->dv_open(f
, fname
);
74 tape_open(struct open_file
*f
, ...)
76 char *fname
; /* partition number, i.e. "1" */
78 struct mvmeprom_dskio
*ti
;
82 fname
= va_arg(ap
, char *);
86 * Set the tape segment number to the one indicated
87 * by the single digit fname passed in above.
89 if ((fname
[0] < '0') && (fname
[0] > '9')) {
92 part
= fname
[0] - '0';
95 * Setup our part of the saioreq.
96 * (determines what gets opened)
99 memset((void *)ti
, 0, sizeof(*ti
));
101 ti
->ctrl_lun
= bugargs
.ctrl_lun
;
102 ti
->dev_lun
= bugargs
.dev_lun
;
116 tape_close(struct open_file
*f
)
118 struct mvmeprom_dskio
*ti
;
125 #define MVMEPROM_SCALE (512/MVMEPROM_BLOCK_SIZE)
128 tape_strategy(void *devdata
, int flag
, daddr_t dblk
, u_int size
, void *buf
,
131 struct mvmeprom_dskio
*ti
;
141 /* don't change block #, set in open */
142 ti
->blk_cnt
= size
/ (512 / MVMEPROM_SCALE
);
144 /* work around for stupid '147 prom bug */
145 if (bugargs
.cputyp
== 0x147)
146 ret
= hackprom_diskrd(ti
);
148 ret
= mvmeprom_diskrd(ti
);
153 *rsize
= (ti
->blk_cnt
/ MVMEPROM_SCALE
) * 512;
154 ti
->flag
|= IGNORE_FILENUM
; /* ignore next time */
160 tape_ioctl(struct open_file
*f
, u_long cmd
, void *data
)
167 hackprom_diskrd(struct mvmeprom_dskio
*ti
)
169 static int blkoffset
= 0;
171 #define hackload_addr ((char *)0x080000) /* Load tape segment here */
172 #define hackload_blocks 0x3000 /* 3Mb worth */
174 if ((ti
->flag
& IGNORE_FILENUM
) == 0) {
176 * First time through. Load the whole tape segment...
178 struct mvmeprom_dskio nti
;
183 nti
.pbuffer
= hackload_addr
;
184 nti
.blk_cnt
= hackload_blocks
;
185 nti
.flag
|= END_OF_FILE
;
187 ret
= mvmeprom_diskrd(&nti
);
190 * PROM returns 1 on end-of-file. This isn't an
191 * error in this instance, just in case you're wondering! ;-)
193 if (ret
< 0 || ret
> 1)
200 * Grab the required number of block(s)
202 memcpy(ti
->pbuffer
, &(hackload_addr
[blkoffset
]),
203 ti
->blk_cnt
* MVMEPROM_BLOCK_SIZE
);
205 blkoffset
+= (ti
->blk_cnt
* MVMEPROM_BLOCK_SIZE
);