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