1 /* $NetBSD: dev_disk.c,v 1.3 2005/12/11 12:19:29 christos 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>
55 struct saioreq disk_ioreq
;
58 disk_open(struct open_file
*f
, ...)
65 char *devname
; /* Device part of file name (or NULL). */
69 devname
= va_arg(ap
, char *);
71 printf("disk_open: %s\n", devname
);
76 if (disk_opencount
== 0) {
78 * Setup our part of the saioreq.
79 * (determines what gets opened)
81 bp
= *romVectorPtr
->bootParam
;
82 si
->si_boottab
= bp
->bootDevice
;
83 si
->si_ctlr
= bp
->ctlrNum
;
84 si
->si_unit
= bp
->unitNum
;
85 si
->si_boff
= bp
->partNum
;
86 if ((error
= prom_iopen(si
)) != 0)
96 disk_close(struct open_file
*f
)
102 printf("disk_close: ocnt=%d\n", disk_opencount
);
107 if (disk_opencount
<= 0)
109 if (--disk_opencount
== 0)
115 disk_strategy(void *devdata
, int flag
, daddr_t dblk
, size_t size
, void *buf
,
121 int retry
, si_flag
, xcnt
;
124 ops
= si
->si_boottab
;
128 printf("disk_strategy: size=%d dblk=%d\n", size
, dblk
);
131 dmabuf
= dvma_mapin(buf
, size
);
132 si_flag
= (flag
== F_READ
) ? SAIO_F_READ
: SAIO_F_WRITE
;
135 * The PROM strategy will occasionally return -1 and expect
136 * us to try again. From mouse@Collatz.McRCIM.McGill.EDU
143 xcnt
= (*ops
->b_strategy
)(si
, si_flag
);
144 } while ((xcnt
<= 0) && (--retry
> 0));
146 dvma_mapout(dmabuf
, size
);
150 printf("disk_strategy: xcnt = %x retries=%d\n",
151 xcnt
, RETRY_COUNT
- retry
);
162 disk_ioctl(struct open_file
*f
, u_long cmd
, void *data
)