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