No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / mvme68k / stand / bootst / dev_tape.c
blobcb981a58a0c56807d9dee5156edbc19d51fb02d1
1 /* $NetBSD: dev_tape.c,v 1.10 2008/04/28 20:23:29 martin Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
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.
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>
45 #include "libsa.h"
46 #include "dev_tape.h"
48 extern int debug;
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.
60 int
61 devopen(struct open_file *f, const char *fname, char **file)
63 struct devsw *dp;
65 *file = (char *)fname;
66 dp = &devsw[0];
67 f->f_dev = dp;
69 /* The following will call tape_open() */
70 return dp->dv_open(f, fname);
73 int
74 tape_open(struct open_file *f, ...)
76 char *fname; /* partition number, i.e. "1" */
77 int part;
78 struct mvmeprom_dskio *ti;
79 va_list ap;
81 va_start(ap, f);
82 fname = va_arg(ap, char *);
83 va_end(ap);
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')) {
90 return ENOENT;
92 part = fname[0] - '0';
95 * Setup our part of the saioreq.
96 * (determines what gets opened)
98 ti = &tape_ioreq;
99 memset((void *)ti, 0, sizeof(*ti));
101 ti->ctrl_lun = bugargs.ctrl_lun;
102 ti->dev_lun = bugargs.dev_lun;
103 ti->status = 0;
104 ti->pbuffer = NULL;
105 ti->blk_num = part;
106 ti->blk_cnt = 0;
107 ti->flag = 0;
108 ti->addr_mod = 0;
110 f->f_devdata = ti;
112 return 0;
116 tape_close(struct open_file *f)
118 struct mvmeprom_dskio *ti;
120 ti = f->f_devdata;
121 f->f_devdata = NULL;
122 return 0;
125 #define MVMEPROM_SCALE (512/MVMEPROM_BLOCK_SIZE)
128 tape_strategy(void *devdata, int flag, daddr_t dblk, u_int size, void *buf,
129 u_int *rsize)
131 struct mvmeprom_dskio *ti;
132 int ret;
134 ti = devdata;
136 if (flag != F_READ)
137 return EROFS;
139 ti->status = 0;
140 ti->pbuffer = buf;
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);
147 else
148 ret = mvmeprom_diskrd(ti);
150 if (ret != 0)
151 return EIO;
153 *rsize = (ti->blk_cnt / MVMEPROM_SCALE) * 512;
154 ti->flag |= IGNORE_FILENUM; /* ignore next time */
156 return 0;
160 tape_ioctl(struct open_file *f, u_long cmd, void *data)
163 return EIO;
166 static int
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;
179 int ret;
181 nti = *ti;
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)
194 return ret;
196 blkoffset = 0;
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);
207 return 0;