Home | History | Annotate | Line # | Download | only in boot
xd.c revision 1.1
      1 /*
      2  * $NetBSD: xd.c,v 1.1 1996/11/29 23:36:29 is 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 <stand.h>
     37 #include <ufs.h>
     38 
     39 
     40 #include "samachdep.h"
     41 #include "amigaio.h"
     42 #include "libstubs.h"
     43 
     44 static int xdstrategy __P((void *, int, daddr_t, size_t, void *, size_t *));
     45 static int xdopen __P((struct open_file *, ...));
     46 static int xdclose __P((struct open_file *));
     47 static int xdioctl __P((struct open_file *, u_long, void *));
     48 
     49 static u_int32_t aio_base;
     50 static struct AmigaIO *aio_save;
     51 
     52 static struct devsw devsw[] = {
     53         { "xd", xdstrategy, xdopen, xdclose, xdioctl }
     54 };
     55 
     56 struct fs_ops file_system[] = {
     57 	{ ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat },
     58 };
     59 
     60 int nfsys = sizeof(file_system)/sizeof(struct fs_ops);
     61 
     62 
     63 
     64 /* called from configure */
     65 
     66 void
     67 xdinit(aio)
     68 	void *aio;
     69 {
     70 	aio_save = aio;
     71 	aio_base = aio_save->offset;
     72 }
     73 
     74 /*
     75  * Kernel ist loaded from device and partition the kickstart
     76  * menu or boot priority has chosen:
     77  */
     78 
     79 int
     80 devopen(f, fname, file)
     81 	struct open_file *f;
     82 	const char *fname;
     83 	char **file;
     84 {
     85 	f->f_devdata = aio_save;
     86 	f->f_dev = &devsw[0];
     87 	*file = (char *)fname;
     88 	return 0;
     89 }
     90 
     91 /* tell kickstart to do the real work */
     92 
     93 static int
     94 xdstrategy (devd, flag, dblk, size, buf, rsize)
     95 	void	*devd;
     96 	int     flag;
     97 	daddr_t dblk;
     98 	size_t  size;
     99 	void    *buf;
    100 	size_t  *rsize;
    101 {
    102 	struct AmigaIO *aio = (struct AmigaIO *)devd;
    103 
    104 	if (flag != F_READ)
    105 		return EIO;
    106 
    107 	aio->cmd = Cmd_Rd;
    108 	aio->length = size;
    109 	aio->offset = aio_base + (dblk << 9);
    110 	aio->buf = buf;
    111 
    112 #ifdef XDDEBUG
    113 	printf("strategy called: %ld(%ld), %ld, 0x%lx\n",
    114 	    (long)dblk, (long)aio->offset, (long)size, (unsigned long)buf);
    115 #endif
    116 
    117 	DoIO(aio);
    118 
    119 #ifdef XDDEBUG
    120 	printf("strategy got err %ld, rsize %ld\n", aio->err, aio->actual);
    121 #endif
    122 
    123 	if (aio->err) {
    124 		*rsize = 0;
    125 		return EIO;
    126 	}
    127 
    128 	*rsize = aio->actual;
    129 	return 0;
    130 }
    131 
    132 
    133 /* nothing do do for these: */
    134 
    135 static int
    136 xdopen(f)
    137 	struct open_file *f;
    138 {
    139 	return 0;
    140 }
    141 
    142 static int
    143 xdclose(f)
    144 	struct open_file *f;
    145 {
    146 	return 0;
    147 }
    148 
    149 static int
    150 xdioctl (f, cmd, data)
    151 	struct open_file *f;
    152 	u_long  cmd;
    153 	void    *data;
    154 {
    155 	return EIO;
    156 }
    157