2009-03-18 20:06:41 +03:00
|
|
|
/* $NetBSD: md_root.c,v 1.31 2009/03/18 17:06:43 cegger Exp $ */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
1996-03-15 00:41:04 +03:00
|
|
|
* Copyright (c) 1996 Leo Weppelman.
|
1995-03-26 11:12:03 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Leo Weppelman.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 05:19:42 +04:00
|
|
|
#include <sys/cdefs.h>
|
2009-03-18 20:06:41 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: md_root.c,v 1.31 2009/03/18 17:06:43 cegger Exp $");
|
2003-07-15 05:19:42 +04:00
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/dkbad.h>
|
|
|
|
|
1996-04-26 10:59:15 +04:00
|
|
|
#include <dev/cons.h>
|
1996-12-29 02:50:44 +03:00
|
|
|
#include <dev/md.h>
|
1996-03-15 00:41:04 +03:00
|
|
|
|
1996-09-16 10:27:11 +04:00
|
|
|
#include <atari/atari/device.h>
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Misc. defines:
|
|
|
|
*/
|
|
|
|
#define RAMD_CHUNK (9 * 512) /* Chunk-size for auto-load */
|
2002-05-23 10:39:32 +04:00
|
|
|
#define RAMD_NDEV 3 /* Number of devices configured */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
struct ramd_info {
|
|
|
|
u_long ramd_size; /* Size of disk in bytes */
|
|
|
|
u_long ramd_flag; /* see defs below */
|
|
|
|
dev_t ramd_dev; /* device to load from */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ramd_flag:
|
|
|
|
*/
|
|
|
|
#define RAMD_LOAD 0x01 /* Auto load when first opened */
|
|
|
|
#define RAMD_LCOMP 0x02 /* Input is compressed */
|
|
|
|
|
|
|
|
struct ramd_info rd_info[RAMD_NDEV] = {
|
|
|
|
{
|
|
|
|
1105920, /* 1Mb in 2160 sectors */
|
|
|
|
RAMD_LOAD, /* auto-load this device */
|
1996-11-08 17:17:08 +03:00
|
|
|
MAKEDISKDEV(2, 0, 2), /* XXX: This is crap! (720Kb flop) */
|
1995-03-26 11:12:03 +04:00
|
|
|
},
|
|
|
|
{
|
2002-05-23 10:39:32 +04:00
|
|
|
1474560, /* 1.44Mb in 2880 sectors */
|
|
|
|
RAMD_LOAD, /* auto-load this device */
|
|
|
|
MAKEDISKDEV(2, 0, 2), /* XXX: This is crap! (720Kb flop) */
|
2002-05-23 18:59:28 +04:00
|
|
|
},
|
2002-05-23 10:39:32 +04:00
|
|
|
{
|
|
|
|
1474560, /* 1.44Mb in 2880 sectors */
|
1995-03-26 11:12:03 +04:00
|
|
|
RAMD_LOAD, /* auto-load this device */
|
1997-07-30 19:45:33 +04:00
|
|
|
MAKEDISKDEV(2, 0, 3), /* XXX: This is crap! (1.44Mb flop) */
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct read_info {
|
|
|
|
struct buf *bp; /* buffer for strategy function */
|
|
|
|
long nbytes; /* total number of bytes to read */
|
|
|
|
long offset; /* offset in input medium */
|
2007-03-06 17:15:13 +03:00
|
|
|
char *bufp; /* current output buffer */
|
|
|
|
char *ebufp; /* absolute maximum for bufp */
|
1995-03-26 11:12:03 +04:00
|
|
|
int chunk; /* chunk size on input medium */
|
|
|
|
int media_sz; /* size of input medium */
|
1996-03-15 00:41:04 +03:00
|
|
|
void (*strat)(struct buf *); /* strategy function for read */
|
1995-03-26 11:12:03 +04:00
|
|
|
};
|
|
|
|
|
1996-03-15 00:41:04 +03:00
|
|
|
|
2009-03-14 17:45:51 +03:00
|
|
|
static int loaddisk(struct md_conf *, dev_t ld_dev, struct lwp *);
|
|
|
|
static int ramd_norm_read(struct read_info *);
|
1996-04-18 12:51:11 +04:00
|
|
|
|
|
|
|
#ifdef support_compression
|
2009-03-14 17:45:51 +03:00
|
|
|
static int cpy_uncompressed(void *, int, struct read_info *);
|
|
|
|
static int md_compressed(void *, int, struct read_info *);
|
1996-04-18 12:51:11 +04:00
|
|
|
#endif
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
1996-03-15 00:41:04 +03:00
|
|
|
* This is called during autoconfig.
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1996-03-15 00:41:04 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
md_attach_hook(int unit, struct md_conf *md)
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
1996-03-15 00:41:04 +03:00
|
|
|
if (atari_realconfig && (unit < RAMD_NDEV) && rd_info[unit].ramd_flag) {
|
1997-03-31 01:04:13 +04:00
|
|
|
printf ("md%d: %sauto-load on open. Size %ld bytes.\n", unit,
|
|
|
|
rd_info[unit].ramd_flag & RAMD_LCOMP ? "decompress/" : "",
|
1996-03-15 00:41:04 +03:00
|
|
|
rd_info[unit].ramd_size);
|
1996-12-29 02:37:26 +03:00
|
|
|
md->md_type = MD_UNCONFIGURED; /* Paranoia... */
|
1996-01-08 01:01:38 +03:00
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1996-03-15 00:41:04 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
md_open_hook(int unit, struct md_conf *md)
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
struct ramd_info *ri;
|
|
|
|
|
1996-03-15 00:41:04 +03:00
|
|
|
if(unit >= RAMD_NDEV)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ri = &rd_info[unit];
|
1996-12-29 02:37:26 +03:00
|
|
|
if (md->md_type != MD_UNCONFIGURED)
|
1996-03-15 00:41:04 +03:00
|
|
|
return; /* Only configure once */
|
1996-12-29 02:37:26 +03:00
|
|
|
md->md_addr = malloc(ri->ramd_size, M_DEVBUF, M_WAITOK);
|
|
|
|
md->md_size = ri->ramd_size;
|
|
|
|
if(md->md_addr == NULL)
|
1996-03-15 00:41:04 +03:00
|
|
|
return;
|
|
|
|
if(ri->ramd_flag & RAMD_LOAD) {
|
2005-12-11 15:16:03 +03:00
|
|
|
if (loaddisk(md, ri->ramd_dev, curlwp)) {
|
1996-12-29 02:37:26 +03:00
|
|
|
free(md->md_addr, M_DEVBUF);
|
|
|
|
md->md_addr = NULL;
|
1996-03-15 00:41:04 +03:00
|
|
|
return;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
}
|
1996-12-29 02:37:26 +03:00
|
|
|
md->md_type = MD_KMEM_ALLOCATED;
|
1995-07-13 01:41:03 +04:00
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
loaddisk(struct md_conf *md, dev_t ld_dev, struct lwp *lwp)
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
2008-01-02 14:48:20 +03:00
|
|
|
struct buf *buf;
|
1995-03-26 11:12:03 +04:00
|
|
|
int error;
|
2002-09-06 17:18:43 +04:00
|
|
|
const struct bdevsw *bdp;
|
1995-03-26 11:12:03 +04:00
|
|
|
struct disklabel dl;
|
|
|
|
struct read_info rs;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
bdp = bdevsw_lookup(ld_dev);
|
|
|
|
if (bdp == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
1996-03-15 00:41:04 +03:00
|
|
|
* Initialize our buffer header:
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
2008-01-02 14:48:20 +03:00
|
|
|
buf = getiobuf(NULL, false);
|
|
|
|
buf->b_cflags = BC_BUSY;
|
|
|
|
buf->b_dev = ld_dev;
|
|
|
|
buf->b_error = 0;
|
|
|
|
buf->b_proc = lwp->l_proc;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup read_info:
|
|
|
|
*/
|
2008-01-02 14:48:20 +03:00
|
|
|
rs.bp = buf;
|
1996-12-29 02:37:26 +03:00
|
|
|
rs.nbytes = md->md_size;
|
1995-03-26 11:12:03 +04:00
|
|
|
rs.offset = 0;
|
1996-12-29 02:37:26 +03:00
|
|
|
rs.bufp = md->md_addr;
|
2007-03-06 17:15:13 +03:00
|
|
|
rs.ebufp = (char *)md->md_addr + md->md_size;
|
1995-03-26 11:12:03 +04:00
|
|
|
rs.chunk = RAMD_CHUNK;
|
1996-12-29 02:37:26 +03:00
|
|
|
rs.media_sz = md->md_size;
|
1995-03-26 11:12:03 +04:00
|
|
|
rs.strat = bdp->d_strategy;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open device and try to get some statistics.
|
|
|
|
*/
|
2008-01-02 14:48:20 +03:00
|
|
|
if((error = bdp->d_open(ld_dev, FREAD | FNONBLOCK, 0, lwp)) != 0) {
|
|
|
|
putiobuf(buf);
|
1995-03-26 11:12:03 +04:00
|
|
|
return(error);
|
2008-01-02 14:48:20 +03:00
|
|
|
}
|
2007-03-04 08:59:00 +03:00
|
|
|
if(bdp->d_ioctl(ld_dev, DIOCGDINFO, (void *)&dl, FREAD, lwp) == 0) {
|
1995-03-26 11:12:03 +04:00
|
|
|
/* Read on a cylinder basis */
|
|
|
|
rs.chunk = dl.d_secsize * dl.d_secpercyl;
|
|
|
|
rs.media_sz = dl.d_secperunit * dl.d_secsize;
|
|
|
|
}
|
|
|
|
|
1996-03-15 00:41:04 +03:00
|
|
|
#ifdef support_compression
|
1995-03-26 11:12:03 +04:00
|
|
|
if(ri->ramd_flag & RAMD_LCOMP)
|
1996-12-29 02:37:26 +03:00
|
|
|
error = decompress(cpy_uncompressed, md_compressed, &rs);
|
1995-03-26 11:12:03 +04:00
|
|
|
else
|
1996-03-15 00:41:04 +03:00
|
|
|
#endif /* support_compression */
|
1995-03-26 11:12:03 +04:00
|
|
|
error = ramd_norm_read(&rs);
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
bdp->d_close(ld_dev,FREAD | FNONBLOCK, 0, lwp);
|
2008-01-02 14:48:20 +03:00
|
|
|
putiobuf(buf);
|
1995-03-26 11:12:03 +04:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
ramd_norm_read(struct read_info *rsp)
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
long bytes_left;
|
|
|
|
int done, error;
|
|
|
|
struct buf *bp;
|
|
|
|
int dotc = 0;
|
|
|
|
|
|
|
|
bytes_left = rsp->nbytes;
|
|
|
|
bp = rsp->bp;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
while(bytes_left > 0) {
|
2008-01-02 14:48:20 +03:00
|
|
|
bp->b_cflags = BC_BUSY;
|
|
|
|
bp->b_flags = B_PHYS | B_READ;
|
2008-12-28 06:13:59 +03:00
|
|
|
bp->b_oflags &= ~BO_DONE;
|
1995-03-26 11:12:03 +04:00
|
|
|
bp->b_blkno = btodb(rsp->offset);
|
2008-12-28 06:13:59 +03:00
|
|
|
bp->b_bcount = min(rsp->chunk, bytes_left);
|
1995-03-26 11:12:03 +04:00
|
|
|
bp->b_data = rsp->bufp;
|
2007-07-29 16:15:35 +04:00
|
|
|
bp->b_error = 0;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/* Initiate read */
|
|
|
|
(*rsp->strat)(bp);
|
|
|
|
|
|
|
|
/* Wait for results */
|
2008-01-02 14:48:20 +03:00
|
|
|
biowait(bp);
|
2007-07-29 16:15:35 +04:00
|
|
|
error = bp->b_error;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/* Dot counter */
|
1996-10-13 08:10:34 +04:00
|
|
|
printf(".");
|
1995-08-13 00:30:45 +04:00
|
|
|
if(!(++dotc % 40))
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
done = bp->b_bcount - bp->b_resid;
|
2008-11-04 20:08:45 +03:00
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
bytes_left -= done;
|
|
|
|
rsp->offset += done;
|
|
|
|
rsp->bufp += done;
|
|
|
|
|
|
|
|
if(error || !done)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if((rsp->offset == rsp->media_sz) && (bytes_left != 0)) {
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("\nInsert next media and hit any key...");
|
1995-03-26 11:12:03 +04:00
|
|
|
cngetc();
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
rsp->offset = 0;
|
|
|
|
}
|
|
|
|
}
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1996-03-15 00:41:04 +03:00
|
|
|
#ifdef support_compression
|
1995-03-26 11:12:03 +04:00
|
|
|
/*
|
|
|
|
* Functions supporting uncompression:
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copy from the uncompression buffer to the ramdisk
|
|
|
|
*/
|
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
cpy_uncompressed(void * buf, int nbyte, struct read_info *rsp)
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
if((rsp->bufp + nbyte) >= rsp->ebufp)
|
|
|
|
return(0);
|
2009-03-18 20:06:41 +03:00
|
|
|
memcpy( rsp->bufp, buf, nbyte);
|
1995-03-26 11:12:03 +04:00
|
|
|
rsp->bufp += nbyte;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a maximum of 'nbyte' bytes into 'buf'.
|
|
|
|
*/
|
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
md_compressed(void * buf, int nbyte, struct read_info *rsp)
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
static int dotc = 0;
|
|
|
|
struct buf *bp;
|
|
|
|
int nread = 0;
|
|
|
|
int done, error;
|
|
|
|
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
bp = rsp->bp;
|
|
|
|
nbyte &= ~(DEV_BSIZE - 1);
|
|
|
|
|
|
|
|
while(nbyte > 0) {
|
2008-01-02 14:48:20 +03:00
|
|
|
bp->b_cflags = BC_BUSY;
|
|
|
|
bp->b_flags = B_PHYS | B_READ;
|
2008-12-28 06:13:59 +03:00
|
|
|
bp->b_oflags &= ~BO_DONE;
|
1995-03-26 11:12:03 +04:00
|
|
|
bp->b_blkno = btodb(rsp->offset);
|
|
|
|
bp->b_bcount = min(rsp->chunk, nbyte);
|
|
|
|
bp->b_data = buf;
|
2007-07-29 16:15:35 +04:00
|
|
|
bp->b_error = 0;
|
1995-08-13 00:30:45 +04:00
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
/* Initiate read */
|
|
|
|
(*rsp->strat)(bp);
|
|
|
|
|
|
|
|
/* Wait for results */
|
2008-01-02 14:48:20 +03:00
|
|
|
biowait(bp);
|
2008-11-04 20:08:45 +03:00
|
|
|
error = bp->b_error;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/* Dot counter */
|
1996-10-13 08:10:34 +04:00
|
|
|
printf(".");
|
1995-08-13 00:30:45 +04:00
|
|
|
if(!(++dotc % 40))
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
done = bp->b_bcount - bp->b_resid;
|
2008-11-04 20:08:45 +03:00
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
nbyte -= done;
|
|
|
|
nread += done;
|
|
|
|
rsp->offset += done;
|
|
|
|
|
|
|
|
if(error || !done)
|
|
|
|
break;
|
|
|
|
|
1996-03-15 00:41:04 +03:00
|
|
|
if((rsp->offset == rsp->media_sz) && (nbyte != 0)) {
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("\nInsert next media and hit any key...");
|
1995-03-26 11:12:03 +04:00
|
|
|
if(cngetc() != '\n')
|
1996-10-13 08:10:34 +04:00
|
|
|
printf("\n");
|
1995-03-26 11:12:03 +04:00
|
|
|
rsp->offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(nread);
|
|
|
|
}
|
1996-03-15 00:41:04 +03:00
|
|
|
#endif /* support_compression */
|