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