1 /* $NetBSD: dev_tape.c,v 1.4 2008/04/28 20:23:39 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).
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.
42 #include <sys/types.h>
43 #include <machine/mon.h>
44 #include <machine/stdarg.h>
54 struct saioreq tape_ioreq
;
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.
63 devopen(struct open_file
*f
, const char *fname
, char **file
)
67 *file
= (char *)fname
;
71 /* The following will call tape_open() */
72 return (dp
->dv_open(f
, fname
));
76 tape_open(struct open_file
*f
, ...)
81 char *fname
; /* partition number, i.e. "1" */
85 fname
= va_arg(ap
, char *);
87 printf("tape_open: part=%s\n", fname
);
92 * Set the tape segment number to the one indicated
93 * by the single digit fname passed in above.
95 if ((fname
[0] < '0') && (fname
[0] > '9')) {
98 part
= fname
[0] - '0';
101 * Setup our part of the saioreq.
102 * (determines what gets opened)
105 memset(si
, 0, sizeof(*si
));
107 bp
= *romVectorPtr
->bootParam
;
108 si
->si_boottab
= bp
->bootDevice
;
109 si
->si_ctlr
= bp
->ctlrNum
;
110 si
->si_unit
= bp
->unitNum
;
111 si
->si_boff
= part
; /* default = bp->partNum + 1; */
113 error
= prom_iopen(si
);
116 printf("tape_open: prom_iopen returned 0x%x\n", error
);
126 tape_close(struct open_file
*f
)
131 printf("tape_close: calling prom_iclose\n");
141 tape_strategy(void *devdata
, int flag
, daddr_t dblk
, size_t size
, void *buf
,
150 ops
= si
->si_boottab
;
154 printf("tape_strategy: size=%d dblk=%d\n", size
, dblk
);
157 dmabuf
= dvma_mapin(buf
, size
);
163 si_flag
= (flag
== F_READ
) ? SAIO_F_READ
: SAIO_F_WRITE
;
164 xcnt
= (*ops
->b_strategy
)(si
, si_flag
);
165 dvma_mapout(dmabuf
, size
);
169 printf("tape_strategy: xcnt = %x\n", xcnt
);
172 /* At end of tape, xcnt == 0 (not an error) */
181 tape_ioctl(struct open_file
*f
, u_long cmd
, void *data
)