xref: /netbsd-src/sys/arch/news68k/stand/boot/devopen.c (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1 /*	$NetBSD: devopen.c,v 1.1 1999/12/09 14:53:22 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (C) 1999 Tsubai Masanari.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <lib/libkern/libkern.h>
30 #include <lib/libsa/stand.h>
31 #include <lib/libsa/ufs.h>
32 
33 #include <machine/romcall.h>
34 
35 #ifdef BOOT_DEBUG
36 # define DPRINTF printf
37 #else
38 # define DPRINTF while (0) printf
39 #endif
40 
41 int dkopen __P((struct open_file *, ...));
42 int dkclose __P((struct open_file *));
43 int dkstrategy __P((void *, int, daddr_t, size_t, void *, size_t *));
44 
45 struct devsw devsw[] = {
46 	{ "dk", dkstrategy, dkopen, dkclose, noioctl }
47 };
48 int ndevs = sizeof(devsw) / sizeof(devsw[0]);
49 
50 struct fs_ops file_system[] = {
51 	{ ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat }
52 };
53 int nfsys = sizeof(file_system) / sizeof(file_system[0]);
54 
55 struct romdev {
56 	int fd;
57 } romdev;
58 
59 int
60 devopen(f, fname, file)
61 	struct open_file *f;
62 	const char *fname;
63 	char **file;	/* out */
64 {
65 	int fd;
66 	char devname[32];
67 	char *cp;
68 
69 	DPRINTF("devopen: %s\n", fname);
70 
71 	strcpy(devname, fname);
72 	cp = strchr(devname, ')') + 1;
73 	*cp = 0;
74 	fd = rom_open(devname, 0);
75 
76 	DPRINTF("devname = %s, fd = %d\n", devname, fd);
77 	if (fd == -1)
78 		return -1;
79 
80 	romdev.fd = fd;
81 
82 	f->f_dev = devsw;
83 	f->f_devdata = &romdev;
84 	*file = strchr(fname, ')') + 1;
85 
86 	return 0;
87 }
88 
89 int
90 dkopen(struct open_file *f, ...)
91 {
92 	DPRINTF("dkopen\n");
93 	return 0;
94 }
95 
96 int
97 dkclose(f)
98 	struct open_file *f;
99 {
100 	struct romdev *dev = f->f_devdata;
101 
102 	DPRINTF("dkclose\n");
103 	rom_close(dev->fd);
104 	return 0;
105 }
106 
107 int
108 dkstrategy(devdata, rw, blk, size, buf, rsize)
109 	void *devdata;
110 	int rw;
111 	daddr_t blk;
112 	size_t size;
113 	void *buf;
114 	size_t *rsize;	/* out: number of bytes transfered */
115 {
116 	struct romdev *dev = devdata;
117 
118 	/* XXX should use partition offset */
119 
120 	rom_lseek(dev->fd, blk * 512, 0);
121 	rom_read(dev->fd, buf, size);
122 	*rsize = size;
123 	return 0;
124 }
125