ofw_disk.c revision 113583
1/*
2 * Copyright (C) 2000 Benno Rice.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD: head/sys/boot/ofw/libofw/ofw_disk.c 113583 2003-04-16 21:09:41Z phk $
26 */
27
28/*
29 * Disk I/O routines using Open Firmware
30 */
31
32#include <sys/param.h>
33
34#include <netinet/in.h>
35
36#include <machine/stdarg.h>
37
38#include <stand.h>
39
40#include "bootstrap.h"
41#include "libofw.h"
42
43static int	ofwd_init(void);
44static int	ofwd_strategy(void *devdata, int flag, daddr_t dblk,
45				size_t size, char *buf, size_t *rsize);
46static int	ofwd_open(struct open_file *f, ...);
47static int	ofwd_close(struct open_file *f);
48static int	ofwd_ioctl(struct open_file *f, u_long cmd, void *data);
49static void	ofwd_print(int verbose);
50
51struct devsw ofwdisk = {
52	"block",
53	DEVT_DISK,
54	ofwd_init,
55	ofwd_strategy,
56	ofwd_open,
57	ofwd_close,
58	ofwd_ioctl,
59	ofwd_print
60};
61
62static int
63ofwd_init(void)
64{
65	return 0;
66}
67
68static int
69ofwd_strategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf,
70    size_t *rsize)
71{
72	struct ofw_devdesc *dp = (struct ofw_devdesc *)devdata;
73	unsigned long pos;
74	int n;
75	int i, j;
76
77	pos = dblk * 512;
78	do {
79		if (OF_seek(dp->d_handle, pos) < 0)
80			return EIO;
81		n = OF_read(dp->d_handle, buf, size);
82		if (n < 0 && n != -2)
83			return EIO;
84	} while (n == -2);
85	*rsize = size;
86	return 0;
87}
88
89static int
90ofwd_open(struct open_file *f, ...)
91{
92	struct ofw_devdesc *dp;
93	phandle_t handle;
94	va_list vl;
95
96	va_start(vl, f);
97	dp = va_arg(vl, struct ofw_devdesc *);
98	va_end(vl);
99	if ((handle = OF_open(dp->d_path)) == -1) {
100		printf("ofwd_open: Could not open %s\n", dp->d_path);
101		return 1;
102	}
103	dp->d_handle = handle;
104	return 0;
105}
106
107static int
108ofwd_close(struct open_file *f)
109{
110	struct ofw_devdesc *dev = f->f_devdata;
111
112	OF_close(dev->d_handle);
113	return 0;
114}
115
116static int
117ofwd_ioctl(struct open_file *f, u_long cmd, void *data)
118{
119
120	return (EINVAL);
121}
122
123static void
124ofwd_print(int verbose)
125{
126}
127