Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sun68k / stand / libsa / dev_disk.c
blob8d25c92201e22faddcaac75243d20d09b08d8b8e
1 /* $NetBSD: dev_disk.c,v 1.3 2005/12/11 12:19:29 christos 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_disk.h"
52 #define RETRY_COUNT 5
54 int disk_opencount;
55 struct saioreq disk_ioreq;
57 int
58 disk_open(struct open_file *f, ...)
60 struct bootparam *bp;
61 struct saioreq *si;
62 int error;
64 #ifdef DEBUG_PROM
65 char *devname; /* Device part of file name (or NULL). */
66 va_list ap;
68 va_start(ap, f);
69 devname = va_arg(ap, char *);
70 if (debug)
71 printf("disk_open: %s\n", devname);
72 va_end(ap);
73 #endif
75 si = &disk_ioreq;
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)
87 return (error);
89 disk_opencount++;
91 f->f_devdata = si;
92 return 0;
95 int
96 disk_close(struct open_file *f)
98 struct saioreq *si;
100 #ifdef DEBUG_PROM
101 if (debug)
102 printf("disk_close: ocnt=%d\n", disk_opencount);
103 #endif
105 si = f->f_devdata;
106 f->f_devdata = NULL;
107 if (disk_opencount <= 0)
108 return 0;
109 if (--disk_opencount == 0)
110 prom_iclose(si);
111 return 0;
114 int
115 disk_strategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf,
116 size_t *rsize)
118 struct saioreq *si;
119 struct boottab *ops;
120 char *dmabuf;
121 int retry, si_flag, xcnt;
123 si = devdata;
124 ops = si->si_boottab;
126 #ifdef DEBUG_PROM
127 if (debug > 1)
128 printf("disk_strategy: size=%d dblk=%d\n", size, dblk);
129 #endif
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
138 retry = RETRY_COUNT;
139 do {
140 si->si_bn = dblk;
141 si->si_ma = dmabuf;
142 si->si_cc = size;
143 xcnt = (*ops->b_strategy)(si, si_flag);
144 } while ((xcnt <= 0) && (--retry > 0));
146 dvma_mapout(dmabuf, size);
148 #ifdef DEBUG_PROM
149 if (debug > 1)
150 printf("disk_strategy: xcnt = %x retries=%d\n",
151 xcnt, RETRY_COUNT - retry);
152 #endif
154 if (xcnt <= 0)
155 return (EIO);
157 *rsize = xcnt;
158 return (0);
161 int
162 disk_ioctl(struct open_file *f, u_long cmd, void *data)
164 return EIO;