xref: /netbsd/sys/arch/amiga/stand/bootblock/boot/xd.c (revision ca833ec3)
1 /*
2  * $NetBSD: xd.c,v 1.11 2021/02/25 03:42:14 rin Exp $
3  *
4  * Copyright (c) 1996 Ignatios Souvatzis.
5  * Copyright (c) 1995 Waldi Ravens.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *        This product includes software developed by Waldi Ravens.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/types.h>
35 
36 #include <lib/libsa/stand.h>
37 #include <ufs.h>
38 #include <ustarfs.h>
39 
40 #include "samachdep.h"
41 #include "amigaio.h"
42 #include "libstubs.h"
43 
44 static int xdstrategy(void *, int, daddr_t, size_t, void *, size_t *);
45 static int xdopenclose(struct open_file *);
46 static int xdioctl(struct open_file *, u_long, void *);
47 
48 u_int32_t aio_base;
49 static struct AmigaIO *aio_save;
50 
51 struct devsw devsw[] = {
52         { "xd", xdstrategy, (void *)xdopenclose, (void *)xdopenclose, xdioctl }
53 };
54 
55 struct fs_ops file_system[] = {
56 #if !defined(_PRIMARY_BOOT) || BOOTXX_FFS_VERSION == 1
57 	FS_OPS(ufs),
58 	FS_OPS(ustarfs),
59 #endif
60 #if !defined(_PRIMARY_BOOT) || BOOTXX_FFS_VERSION == 2
61 	FS_OPS(ffsv2),
62 #endif
63 };
64 
65 int nfsys = sizeof(file_system)/sizeof(struct fs_ops);
66 
67 
68 
69 /* called from configure */
70 
71 void
xdinit(void * aio)72 xdinit(void *aio)
73 {
74 	aio_save = aio;
75 	aio_base = aio_save->offset;
76 }
77 
78 /*
79  * Kernel ist loaded from device and partition the kickstart
80  * menu or boot priority has chosen:
81  */
82 
83 int
devopen(struct open_file * f,const char * fname,char ** file)84 devopen(struct open_file *f, const char *fname, char **file)
85 {
86 	f->f_devdata = aio_save;
87 	f->f_dev = &devsw[0];
88 	*file = (char *)fname;
89 	return 0;
90 }
91 
92 /* tell kickstart to do the real work */
93 
94 static int
xdstrategy(void * devd,int flag,daddr_t dblk,size_t size,void * buf,size_t * rsize)95 xdstrategy(void *devd, int flag, daddr_t dblk, size_t size, void *buf,
96 	   size_t *rsize)
97 {
98 	struct AmigaIO *aio = (struct AmigaIO *)devd;
99 
100 	if (flag != F_READ)
101 		return EIO;
102 
103 	aio->cmd = Cmd_Rd;
104 	aio->length = size;
105 	aio->offset = aio_base + (dblk << 9);
106 	aio->buf = buf;
107 
108 #ifdef XDDEBUG
109 	printf("strategy called: %ld(%ld), %ld, 0x%lx\n",
110 	    (long)dblk, (long)aio->offset, (long)size, (unsigned long)buf);
111 #endif
112 
113 	DoIO(aio);
114 
115 #ifdef XDDEBUG
116 	printf("strategy got err %ld, rsize %ld\n", (long)aio->err, (long)aio->actual);
117 #endif
118 
119 	if (aio->err) {
120 		*rsize = 0;
121 		return EIO;
122 	}
123 
124 	*rsize = aio->actual;
125 	return 0;
126 }
127 
128 
129 /* nothing do do for these: */
130 
131 static int
xdopenclose(struct open_file * f)132 xdopenclose(struct open_file *f)
133 {
134 	aio_save->offset = aio_base;	/* Restore original offset */
135 	return 0;
136 }
137 
138 static int
xdioctl(struct open_file * f,u_long cmd,void * data)139 xdioctl(struct open_file *f, u_long cmd, void *data)
140 {
141 	return EIO;
142 }
143 
144 #ifdef _PRIMARY_BOOT
145 void
xdreset(void)146 xdreset(void)
147 {
148 	aio_save->offset = aio_base;	/* Restore original offset */
149 }
150 #endif
151