Fix memory barrier in a debug function
[netbsd-mini2440.git] / sys / arch / sun68k / stand / tapeboot / dev_tape.c
blobf60f9b062f2cf87be881147d3cd4bed473f98e53
1 /* $NetBSD: dev_tape.c,v 1.4 2008/04/28 20:23:39 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).
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>
45 #include <stand.h>
47 #include "libsa.h"
48 #include "dvma.h"
49 #include "saio.h"
50 #include "dev_tape.h"
52 extern int debug;
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.
62 int
63 devopen(struct open_file *f, const char *fname, char **file)
65 struct devsw *dp;
67 *file = (char *)fname;
68 dp = &devsw[0];
69 f->f_dev = dp;
71 /* The following will call tape_open() */
72 return (dp->dv_open(f, fname));
75 int
76 tape_open(struct open_file *f, ...)
78 struct bootparam *bp;
79 struct saioreq *si;
80 int error, part;
81 char *fname; /* partition number, i.e. "1" */
82 va_list ap;
84 va_start(ap, f);
85 fname = va_arg(ap, char *);
86 #ifdef DEBUG
87 printf("tape_open: part=%s\n", fname);
88 #endif
89 va_end(ap);
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')) {
96 return ENOENT;
98 part = fname[0] - '0';
101 * Setup our part of the saioreq.
102 * (determines what gets opened)
104 si = &tape_ioreq;
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);
115 #ifdef DEBUG
116 printf("tape_open: prom_iopen returned 0x%x\n", error);
117 #endif
119 if (!error)
120 f->f_devdata = si;
122 return (error);
125 int
126 tape_close(struct open_file *f)
128 struct saioreq *si;
130 #ifdef DEBUG
131 printf("tape_close: calling prom_iclose\n");
132 #endif
134 si = f->f_devdata;
135 prom_iclose(si);
136 f->f_devdata = NULL;
137 return 0;
140 int
141 tape_strategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf,
142 size_t *rsize)
144 struct saioreq *si;
145 struct boottab *ops;
146 char *dmabuf;
147 int si_flag, xcnt;
149 si = devdata;
150 ops = si->si_boottab;
152 #ifdef DEBUG
153 if (debug > 1)
154 printf("tape_strategy: size=%d dblk=%d\n", size, dblk);
155 #endif
157 dmabuf = dvma_mapin(buf, size);
159 si->si_bn = dblk;
160 si->si_ma = dmabuf;
161 si->si_cc = 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);
167 #ifdef DEBUG
168 if (debug > 1)
169 printf("tape_strategy: xcnt = %x\n", xcnt);
170 #endif
172 /* At end of tape, xcnt == 0 (not an error) */
173 if (xcnt < 0)
174 return (EIO);
176 *rsize = xcnt;
177 return (0);
180 int
181 tape_ioctl(struct open_file *f, u_long cmd, void *data)
183 return EIO;