dev_tape.c revision 1.1.8.2 1 /* $NetBSD: dev_tape.c,v 1.1.8.2 2001/06/14 12:57:18 fredette 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 * The implementation is deceptively simple because it uses the
45 * drivers provided by the Sun PROM monitor. Note that only the
46 * PROM driver used to load the boot program is available here.
47 */
48
49 #include <sys/types.h>
50 #include <machine/mon.h>
51 #include <machine/stdarg.h>
52 #include <stand.h>
53
54 #include "libsa.h"
55 #include "dvma.h"
56 #include "saio.h"
57 #include "dev_tape.h"
58
59 extern int debug;
60
61 struct saioreq tape_ioreq;
62
63 /*
64 * This is a special version of devopen() for tape boot.
65 * In this version, the file name is a numeric string of
66 * one digit, which is passed to the device open so it
67 * can open the appropriate tape segment.
68 */
69 int
70 devopen(f, fname, file)
71 struct open_file *f;
72 const char *fname; /* normally "1" */
73 char **file;
74 {
75 struct devsw *dp;
76 int error;
77
78 *file = (char*)fname;
79 dp = &devsw[0];
80 f->f_dev = dp;
81
82 /* The following will call tape_open() */
83 return (dp->dv_open(f, fname));
84 }
85
86 int
87 tape_open(struct open_file *f, ...)
88 {
89 struct bootparam *bp;
90 struct saioreq *si;
91 int error, part;
92 char *fname; /* partition number, i.e. "1" */
93 va_list ap;
94
95 va_start(ap, f);
96 fname = va_arg(ap, char *);
97 #ifdef DEBUG
98 printf("tape_open: part=%s\n", fname);
99 #endif
100 va_end(ap);
101
102 /*
103 * Set the tape segment number to the one indicated
104 * by the single digit fname passed in above.
105 */
106 if ((fname[0] < '0') && (fname[0] > '9')) {
107 return ENOENT;
108 }
109 part = fname[0] - '0';
110
111 /*
112 * Setup our part of the saioreq.
113 * (determines what gets opened)
114 */
115 si = &tape_ioreq;
116 bzero((caddr_t)si, sizeof(*si));
117
118 bp = *romVectorPtr->bootParam;
119 si->si_boottab = bp->bootDevice;
120 si->si_ctlr = bp->ctlrNum;
121 si->si_unit = bp->unitNum;
122 si->si_boff = part; /* default = bp->partNum + 1; */
123
124 error = prom_iopen(si);
125
126 #ifdef DEBUG
127 printf("tape_open: prom_iopen returned 0x%x\n", error);
128 #endif
129
130 if (!error)
131 f->f_devdata = si;
132
133 return (error);
134 }
135
136 int
137 tape_close(f)
138 struct open_file *f;
139 {
140 struct saioreq *si;
141
142 #ifdef DEBUG
143 printf("tape_close: calling prom_iclose\n");
144 #endif
145
146 si = f->f_devdata;
147 prom_iclose(si);
148 f->f_devdata = NULL;
149 return 0;
150 }
151
152 int
153 tape_strategy(devdata, flag, dblk, size, buf, rsize)
154 void *devdata;
155 int flag;
156 daddr_t dblk;
157 size_t size;
158 void *buf;
159 size_t *rsize;
160 {
161 struct saioreq *si;
162 struct boottab *ops;
163 char *dmabuf;
164 int si_flag, xcnt;
165
166 si = devdata;
167 ops = si->si_boottab;
168
169 #ifdef DEBUG
170 if (debug > 1)
171 printf("tape_strategy: size=%d dblk=%d\n", size, dblk);
172 #endif
173
174 dmabuf = dvma_mapin(buf, size);
175
176 si->si_bn = dblk;
177 si->si_ma = dmabuf;
178 si->si_cc = size;
179
180 si_flag = (flag == F_READ) ? SAIO_F_READ : SAIO_F_WRITE;
181 xcnt = (*ops->b_strategy)(si, si_flag);
182 dvma_mapout(dmabuf, size);
183
184 #ifdef DEBUG
185 if (debug > 1)
186 printf("tape_strategy: xcnt = %x\n", xcnt);
187 #endif
188
189 /* At end of tape, xcnt == 0 (not an error) */
190 if (xcnt < 0)
191 return (EIO);
192
193 *rsize = xcnt;
194 return (0);
195 }
196
197 int
198 tape_ioctl(f, cmd, data)
199 struct open_file *f;
200 u_long cmd;
201 void *data;
202 {
203 return EIO;
204 }
205
206