Switch to the mi ramdisk driver.

This commit is contained in:
leo 1996-03-14 21:41:04 +00:00
parent 25b31cbc91
commit 55b65fb49a
11 changed files with 453 additions and 244 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.4 1996/02/22 10:10:44 leo Exp $ */
/* $NetBSD: autoconf.c,v 1.5 1996/03/14 21:41:04 leo Exp $ */
/*
* Copyright (c) 1995 Leo Weppelman
@ -254,13 +254,14 @@ mbattach(pdp, dp, auxp)
void *auxp;
{
printf ("\n");
config_found(dp, "nvr" , simple_devprint);
config_found(dp, "clock" , simple_devprint);
config_found(dp, "grfbus" , simple_devprint);
config_found(dp, "kbd" , simple_devprint);
config_found(dp, "fdc" , simple_devprint);
config_found(dp, "zs" , simple_devprint);
config_found(dp, "ncrscsi", simple_devprint);
config_found(dp, "nvr" , simple_devprint);
config_found(dp, "*" , simple_devprint);
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: conf.c,v 1.12 1996/03/14 21:24:40 christos Exp $ */
/* $NetBSD: conf.c,v 1.13 1996/03/14 21:41:06 leo Exp $ */
/*
* Copyright (c) 1991 The Regents of the University of California.
@ -62,7 +62,7 @@ int lkmenodev();
#include "vnd.h"
bdev_decl(vnd);
#include "ramd.h"
#include "rd.h"
bdev_decl(rd);
#include "fd.h"
#define fdopen Fdopen /* conflicts with fdopen() in kern_descrip.c */
@ -81,7 +81,7 @@ bdev_decl(ccd);
struct bdevsw bdevsw[] =
{
bdev_disk_init(NVND,vnd), /* 0: vnode disk driver */
bdev_rd_init(NRAMD,rd), /* 1: ram disk - for install disk */
bdev_rd_init(NRD,rd), /* 1: ram disk - for install disk */
#define fdopen Fdopen /* conflicts with fdopen() in kern_descrip.c */
bdev_disk_init(NFD,fd), /* 2: floppy disk */
#undef fdopen
@ -232,6 +232,7 @@ dev_t swapdev = makedev(3, 0);
/*
* Returns true if dev is /dev/mem or /dev/kmem.
*/
int
iskmemdev(dev)
dev_t dev;
{
@ -242,6 +243,7 @@ iskmemdev(dev)
/*
* Returns true if dev is /dev/zero.
*/
int
iszerodev(dev)
dev_t dev;
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: swapgeneric.c,v 1.3 1996/01/07 22:02:02 thorpej Exp $ */
/* $NetBSD: swapgeneric.c,v 1.4 1996/03/14 21:41:07 leo Exp $ */
/*
* Copyright (c) 1995 Leo Weppelman
@ -46,7 +46,7 @@
#include <sys/proc.h> /* XXXX and all that uses it */
#include <sys/disk.h>
#include "ramd.h"
#include "rd.h"
#include "fd.h"
#include "sd.h"
#include "cd.h"
@ -71,8 +71,8 @@ struct swdevt swdevt[] = {
#if NFD > 0
extern struct cfdriver fdcd;
#endif
#if NRAMD > 0
extern struct cfdriver ramdcd;
#if NRD > 0
extern struct cfdriver rdcd;
#endif
#if NSD > 0
extern struct cfdriver sdcd;
@ -92,8 +92,8 @@ struct genericconf {
* in preference of boot.
*/
static struct genericconf genericconf[] = {
#if NRAMD > 0
{&ramdcd,makedev(1, 0)},
#if NRD > 0
{&rdcd, makedev(1, 0)},
#endif
#if NFD > 0
{&fdcd, makedev(2, 0)},
@ -142,6 +142,7 @@ char *bp;
return (gc);
}
void
setconf()
{
struct genericconf *gc;

View File

@ -1,5 +1,5 @@
#
# $NetBSD: ATARITT,v 1.9 1996/02/19 09:05:46 leo Exp $
# $NetBSD: ATARITT,v 1.10 1996/03/14 21:41:19 leo Exp $
#
# ATARI-TT
#
@ -82,6 +82,7 @@ options GENERIC # Mini-root boot support
#
options TT_SCSI # SCSI-support for TT only
options TT_VIDEO # Graphics support for TT only
options RAMDISK_HOOKS # Boot RAM-disk
options DISKLABEL_NBDA # NetBSD disklabels (required)
options DISKLABEL_AHDI # NetBSD/AHDI disklabels

View File

@ -1,5 +1,5 @@
#
# $NetBSD: BOOT,v 1.6 1996/02/19 09:05:47 leo Exp $
# $NetBSD: BOOT,v 1.7 1996/03/14 21:41:21 leo Exp $
#
# BOOT
#
@ -77,6 +77,7 @@ options TT_SCSI # SCSI-support for TT
options FALCON_SCSI # SCSI-support for Falcon
options TT_VIDEO # Graphics support for TT
options FALCON_VIDEO # Graphics support for FALCON
options RAMDISK_HOOKS # Boot RAM-disk
options DISKLABEL_NBDA # NetBSD disklabels (required)
options DISKLABEL_AHDI # NetBSD/AHDI disklabels

View File

@ -1,5 +1,5 @@
#
# $NetBSD: FALCON,v 1.6 1996/02/19 09:05:48 leo Exp $
# $NetBSD: FALCON,v 1.7 1996/03/14 21:41:23 leo Exp $
#
# ATARI-FALCON
#
@ -68,6 +68,7 @@ options GENERIC # Mini-root boot support
#
options FALCON_SCSI # SCSI-support for FACLON only
options FALCON_VIDEO # Graphics support for FALCON
options RAMDISK_HOOKS # Boot RAM-disk
options DISKLABEL_NBDA # NetBSD disklabels (required)
options DISKLABEL_AHDI # NetBSD/AHDI disklabels

View File

@ -1,5 +1,5 @@
#
# $NetBSD: GENERIC,v 1.11 1996/02/19 09:05:49 leo Exp $
# $NetBSD: GENERIC,v 1.12 1996/03/14 21:41:25 leo Exp $
#
# Generic atari
#
@ -92,6 +92,7 @@ options FALCON_SCSI # SCSI-support for Falcon
options TT_VIDEO # Graphics support for TT
options FALCON_VIDEO # Graphics support for FALCON
options STATCLOCK # Separate {stat,prof}clock
options RAMDISK_HOOKS # Boot RAM-disk
options DISKLABEL_NBDA # NetBSD disklabels (required)
options DISKLABEL_AHDI # NetBSD/AHDI disklabels

View File

@ -1,5 +1,5 @@
#
# $NetBSD: files.atari,v 1.15 1996/03/06 14:47:44 leo Exp $
# $NetBSD: files.atari,v 1.16 1996/03/14 21:41:29 leo Exp $
#
maxpartitions 16
@ -25,8 +25,9 @@ device zs at mainbus: tty
file arch/atari/dev/zs.c zs needs-count
#ramdisk
device ramd at mainbus
file arch/atari/dev/ramd.c ramd needs-flag
device rd at mainbus
file dev/ramdisk.c rd needs-count
file arch/atari/dev/rd_root.c ramdisk_hooks
# nvram
device nvr at mainbus

View File

@ -1,4 +1,4 @@
# $NetBSD: std.atari,v 1.3 1995/06/09 19:43:23 leo Exp $
# $NetBSD: std.atari,v 1.4 1996/03/14 21:41:31 leo Exp $
#
# standard atari information
#
@ -10,7 +10,7 @@ options MACHINE_NONCONTIG # Non-contiguous memory support
mainbus0 at root
clock0 at mainbus0 # system clock
ramd0 at mainbus0 # ramdisk for install-fs
rd0 at mainbus0 # ramdisk for install-fs
kbd0 at mainbus0 # standard keyboard
fdc0 at mainbus0 # floppy controller
fd0 at fdc0 unit 0 # buildin floppy drive

View File

@ -1,7 +1,7 @@
/* $NetBSD: ramd.c,v 1.6 1996/01/07 22:02:06 thorpej Exp $ */
/* $NetBSD: md_root.c,v 1.1 1996/03/14 21:41:51 leo Exp $ */
/*
* Copyright (c) 1995 Leo Weppelman.
* Copyright (c) 1996 Leo Weppelman.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -44,6 +44,8 @@
#include <sys/disk.h>
#include <sys/dkbad.h>
#include <dev/ramdisk.h>
/*
* Misc. defines:
*/
@ -54,8 +56,6 @@ 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 */
u_long ramd_state; /* runtime state see defs below */
caddr_t ramd_addr; /* Kernel virtual addr */
};
/*
@ -64,29 +64,16 @@ struct ramd_info {
#define RAMD_LOAD 0x01 /* Auto load when first opened */
#define RAMD_LCOMP 0x02 /* Input is compressed */
/*
* ramd_state:
*/
#define RAMD_ALLOC 0x01 /* Memory is allocated */
#define RAMD_OPEN 0x02 /* Ramdisk is open */
#define RAMD_INOPEN 0x04 /* Ramdisk is being opened */
#define RAMD_WANTED 0x08 /* Someone is waiting on struct */
#define RAMD_LOADED 0x10 /* Ramdisk is properly loaded */
struct ramd_info rd_info[RAMD_NDEV] = {
{
1105920, /* 1Mb in 2160 sectors */
RAMD_LOAD, /* auto-load this device */
MAKEDISKDEV(2, 0, 1), /* XXX: This is crap! (720Kb flop) */
0, /* Will be set at runtime */
NULL /* Will be set at runtime */
},
{
1474560, /* 1.44Mb in 2880 sectors */
RAMD_LOAD, /* auto-load this device */
MAKEDISKDEV(2, 0, 1), /* XXX: This is crap! (720Kb flop) */
0, /* Will be set at runtime */
NULL /* Will be set at runtime */
}
};
@ -98,234 +85,93 @@ struct read_info {
caddr_t ebufp; /* absolute maximum for bufp */
int chunk; /* chunk size on input medium */
int media_sz; /* size of input medium */
void (*strat)(); /* strategy function for read */
void (*strat)(struct buf *); /* strategy function for read */
};
static struct disk ramd_disks[RAMD_NDEV]; /* XXX Ick. */
/*
* Autoconfig stuff....
*/
static int ramdmatch __P((struct device *, struct cfdata *, void *));
static int ramdprint __P((void *, char *));
static void ramdattach __P((struct device *, struct device *, void *));
struct cfdriver ramdcd = {
NULL, "rd", (cfmatch_t)ramdmatch, ramdattach, DV_DULL,
sizeof(struct device), NULL, 0 };
void rdstrategy __P((struct buf *));
struct dkdriver ramddkdriver = { rdstrategy };
static int
ramdmatch(pdp, cfp, auxp)
struct device *pdp;
struct cfdata *cfp;
void *auxp;
{
if(strcmp("rd", auxp) || (cfp->cf_unit >= RAMD_NDEV))
return(0);
return(1);
}
static void
ramdattach(pdp, dp, auxp)
struct device *pdp, *dp;
void *auxp;
{
int i;
struct disk *diskp;
/*
* XXX It's not really clear to me _exactly_ what's going
* on here, so this might need to be adjusted. --thorpej
*/
for(i = 0; i < RAMD_NDEV; i++) {
/*
* Initialize and attach the disk structure.
*/
diskp = &ramd_disks[i];
bzero(diskp, sizeof(struct disk));
if ((diskp->dk_name = malloc(8, M_DEVBUF, M_NOWAIT)) == NULL)
panic("ramdattach: can't allocate space for name");
bzero(diskp->dk_name, 8);
sprintf(diskp->dk_name, "rd%d", i);
diskp->dk_driver = &ramddkdriver;
disk_attach(diskp);
config_found(dp, (void*)i, ramdprint);
}
}
static int
ramdprint(auxp, pnp)
void *auxp;
char *pnp;
{
return(UNCONF);
}
static int loaddisk __P((struct ramd_info *, struct proc *));
static int loaddisk __P((struct rd_conf *, dev_t ld_dev, struct proc *));
static int ramd_norm_read __P((struct read_info *));
static int cpy_uncompressed __P((caddr_t, int, struct read_info *));
static int rd_compressed __P((caddr_t, int, struct read_info *));
/*
* This is called during autoconfig.
*/
int
rdopen(dev, flags, devtype, p)
dev_t dev;
int flags, devtype;
struct proc *p;
rd_match_hook(parent, self, aux)
struct device *parent;
void *self;
void *aux;
{
if(strcmp("rd", aux) && strcmp("*", aux))
return(0);
return(1);
}
void
rd_attach_hook(unit, rd)
int unit;
struct rd_conf *rd;
{
extern int atari_realconfig;
if (atari_realconfig && (unit < RAMD_NDEV) && rd_info[unit].ramd_flag) {
printf (":%sauto-load on open. Size %d bytes.",
rd_info[unit].ramd_flag & RAMD_LCOMP ? " decompress/" : "",
rd_info[unit].ramd_size);
rd->rd_type = RD_UNCONFIGURED; /* Paranoia... */
}
}
void
rd_open_hook(unit, rd)
int unit;
struct rd_conf *rd;
{
struct ramd_info *ri;
int s;
int error = 0;
if(DISKUNIT(dev) >= RAMD_NDEV)
return(ENXIO);
if(unit >= RAMD_NDEV)
return;
ri = &rd_info[DISKUNIT(dev)];
if(ri->ramd_state & RAMD_OPEN)
return(0);
/*
* If someone is busy opening, wait for it to complete.
*/
s = splbio();
while(ri->ramd_state & RAMD_INOPEN) {
ri->ramd_state |= RAMD_WANTED;
tsleep((caddr_t)ri, PRIBIO, "rdopen", 0);
}
ri->ramd_state |= RAMD_INOPEN;
splx(s);
if(!(ri->ramd_state & RAMD_ALLOC)) {
ri->ramd_addr = malloc(ri->ramd_size, M_DEVBUF, M_WAITOK);
if(ri->ramd_addr == NULL) {
error = ENXIO;
goto done;
ri = &rd_info[unit];
if (rd->rd_type != RD_UNCONFIGURED)
return; /* Only configure once */
rd->rd_addr = malloc(ri->ramd_size, M_DEVBUF, M_WAITOK);
rd->rd_size = ri->ramd_size;
if(rd->rd_addr == NULL)
return;
if(ri->ramd_flag & RAMD_LOAD) {
if (loaddisk(rd, ri->ramd_dev, curproc)) {
free(rd->rd_addr, M_DEVBUF);
rd->rd_addr = NULL;
return;
}
ri->ramd_state |= RAMD_ALLOC;
}
if((ri->ramd_flag & RAMD_LOAD) && !(ri->ramd_state & RAMD_LOADED)) {
error = loaddisk(ri, p);
if(!error)
ri->ramd_state |= RAMD_LOADED;
}
done:
ri->ramd_state &= ~RAMD_INOPEN;
if(ri->ramd_state & RAMD_WANTED) {
ri->ramd_state &= ~RAMD_WANTED;
wakeup((caddr_t)ri);
}
return(error);
}
int
rdclose(dev, flags, devtype, p)
dev_t dev;
int flags, devtype;
struct proc *p;
{
return(0);
}
int
rdioctl(dev, cmd, addr, flag, p)
dev_t dev;
u_long cmd;
int flag;
caddr_t addr;
struct proc *p;
{
return(ENOTTY);
}
/*
* no dumps to ram disks thank you.
*/
int
rdsize(dev)
dev_t dev;
{
return(-1);
}
void
rdstrategy(bp)
struct buf *bp;
{
struct ramd_info *ri;
long maxsz, sz;
char *datap;
ri = &rd_info[DISKUNIT(bp->b_dev)];
maxsz = ri->ramd_size / DEV_BSIZE;
sz = (bp->b_bcount + DEV_BSIZE - 1) / DEV_BSIZE;
if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
if((bp->b_blkno == maxsz) && (bp->b_flags & B_READ)) {
/* Hitting EOF */
bp->b_resid = bp->b_bcount;
goto done;
}
sz = maxsz - bp->b_blkno;
if((sz <= 0) || (bp->b_blkno < 0)) {
bp->b_error = EINVAL;
bp->b_flags |= B_ERROR;
goto done;
}
bp->b_bcount = sz * DEV_BSIZE;
}
datap = (char*)((u_long)ri->ramd_addr + bp->b_blkno * DEV_BSIZE);
if(bp->b_flags & B_READ)
bcopy(datap, bp->b_data, bp->b_bcount);
else bcopy(bp->b_data, datap, bp->b_bcount);
bp->b_resid = 0;
biodone(bp);
return;
done:
bp->b_resid = bp->b_bcount;
biodone(bp);
}
int
rdread(dev, uio)
dev_t dev;
struct uio *uio;
{
return (physio(rdstrategy, NULL, dev, B_READ, minphys, uio));
}
int
rdwrite(dev, uio)
dev_t dev;
struct uio *uio;
{
return (physio(rdstrategy, NULL, dev, B_WRITE, minphys, uio));
rd->rd_type = RD_KMEM_ALLOCATED;
}
static int
loaddisk(ri, proc)
struct ramd_info *ri;
loaddisk(rd, ld_dev, proc)
struct rd_conf *rd;
dev_t ld_dev;
struct proc *proc;
{
struct buf buf;
int error;
struct bdevsw *bdp = &bdevsw[major(ri->ramd_dev)];
struct bdevsw *bdp = &bdevsw[major(ld_dev)];
struct disklabel dl;
struct read_info rs;
/*
* Initialize out buffer header:
* Initialize our buffer header:
*/
buf.b_actf = NULL;
buf.b_rcred = buf.b_wcred = proc->p_ucred;
buf.b_vnbufs.le_next = NOLIST;
buf.b_flags = B_BUSY;
buf.b_dev = ri->ramd_dev;
buf.b_dev = ld_dev;
buf.b_error = 0;
buf.b_proc = proc;
@ -333,33 +179,33 @@ struct proc *proc;
* Setup read_info:
*/
rs.bp = &buf;
rs.nbytes = ri->ramd_size;
rs.nbytes = rd->rd_size;
rs.offset = 0;
rs.bufp = ri->ramd_addr;
rs.ebufp = ri->ramd_addr + ri->ramd_size;
rs.bufp = rd->rd_addr;
rs.ebufp = rd->rd_addr + rd->rd_size;
rs.chunk = RAMD_CHUNK;
rs.media_sz = ri->ramd_size;
rs.media_sz = rd->rd_size;
rs.strat = bdp->d_strategy;
/*
* Open device and try to get some statistics.
*/
if(error = bdp->d_open(ri->ramd_dev,FREAD | FNONBLOCK, 0, proc))
if(error = bdp->d_open(ld_dev, FREAD | FNONBLOCK, 0, proc))
return(error);
if(bdp->d_ioctl(ri->ramd_dev,DIOCGDINFO,(caddr_t)&dl,FREAD,proc) == 0) {
if(bdp->d_ioctl(ld_dev, DIOCGDINFO, (caddr_t)&dl, FREAD, proc) == 0) {
/* Read on a cylinder basis */
rs.chunk = dl.d_secsize * dl.d_secpercyl;
rs.media_sz = dl.d_secperunit * dl.d_secsize;
}
#ifdef notyet
#ifdef support_compression
if(ri->ramd_flag & RAMD_LCOMP)
error = decompress(cpy_uncompressed, rd_compressed, &rs);
else
#endif /* notyet */
#endif /* support_compression */
error = ramd_norm_read(&rs);
bdp->d_close(ri->ramd_dev,FREAD | FNONBLOCK, 0, proc);
bdp->d_close(ld_dev,FREAD | FNONBLOCK, 0, proc);
return(error);
}
@ -417,11 +263,10 @@ struct read_info *rsp;
}
}
printf("\n");
s = splbio();
splx(s);
return(error);
}
#ifdef support_compression
/*
* Functions supporting uncompression:
*/
@ -493,6 +338,7 @@ int nbyte;
if(error || !done)
break;
if((rsp->offset == rsp->media_sz) && (nbyte != 0)) {
if(rsp->offset == rsp->media_sz) {
printf("\nInsert next media and hit any key...");
if(cngetc() != '\n')
@ -504,3 +350,4 @@ int nbyte;
splx(s);
return(nread);
}
#endif /* support_compression */

View File

@ -0,0 +1,353 @@
/* $NetBSD: rd_root.c,v 1.1 1996/03/14 21:41:51 leo Exp $ */
/*
* Copyright (c) 1996 Leo Weppelman.
* 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.
*/
#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>
#include <dev/ramdisk.h>
/*
* Misc. defines:
*/
#define RAMD_CHUNK (9 * 512) /* Chunk-size for auto-load */
#define RAMD_NDEV 2 /* Number of devices configured */
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 */
MAKEDISKDEV(2, 0, 1), /* XXX: This is crap! (720Kb flop) */
},
{
1474560, /* 1.44Mb in 2880 sectors */
RAMD_LOAD, /* auto-load this device */
MAKEDISKDEV(2, 0, 1), /* XXX: This is crap! (720Kb flop) */
}
};
struct read_info {
struct buf *bp; /* buffer for strategy function */
long nbytes; /* total number of bytes to read */
long offset; /* offset in input medium */
caddr_t bufp; /* current output buffer */
caddr_t ebufp; /* absolute maximum for bufp */
int chunk; /* chunk size on input medium */
int media_sz; /* size of input medium */
void (*strat)(struct buf *); /* strategy function for read */
};
static int loaddisk __P((struct rd_conf *, dev_t ld_dev, struct proc *));
static int ramd_norm_read __P((struct read_info *));
static int cpy_uncompressed __P((caddr_t, int, struct read_info *));
static int rd_compressed __P((caddr_t, int, struct read_info *));
/*
* This is called during autoconfig.
*/
int
rd_match_hook(parent, self, aux)
struct device *parent;
void *self;
void *aux;
{
if(strcmp("rd", aux) && strcmp("*", aux))
return(0);
return(1);
}
void
rd_attach_hook(unit, rd)
int unit;
struct rd_conf *rd;
{
extern int atari_realconfig;
if (atari_realconfig && (unit < RAMD_NDEV) && rd_info[unit].ramd_flag) {
printf (":%sauto-load on open. Size %d bytes.",
rd_info[unit].ramd_flag & RAMD_LCOMP ? " decompress/" : "",
rd_info[unit].ramd_size);
rd->rd_type = RD_UNCONFIGURED; /* Paranoia... */
}
}
void
rd_open_hook(unit, rd)
int unit;
struct rd_conf *rd;
{
struct ramd_info *ri;
int s;
int error = 0;
if(unit >= RAMD_NDEV)
return;
ri = &rd_info[unit];
if (rd->rd_type != RD_UNCONFIGURED)
return; /* Only configure once */
rd->rd_addr = malloc(ri->ramd_size, M_DEVBUF, M_WAITOK);
rd->rd_size = ri->ramd_size;
if(rd->rd_addr == NULL)
return;
if(ri->ramd_flag & RAMD_LOAD) {
if (loaddisk(rd, ri->ramd_dev, curproc)) {
free(rd->rd_addr, M_DEVBUF);
rd->rd_addr = NULL;
return;
}
}
rd->rd_type = RD_KMEM_ALLOCATED;
}
static int
loaddisk(rd, ld_dev, proc)
struct rd_conf *rd;
dev_t ld_dev;
struct proc *proc;
{
struct buf buf;
int error;
struct bdevsw *bdp = &bdevsw[major(ld_dev)];
struct disklabel dl;
struct read_info rs;
/*
* Initialize our buffer header:
*/
buf.b_actf = NULL;
buf.b_rcred = buf.b_wcred = proc->p_ucred;
buf.b_vnbufs.le_next = NOLIST;
buf.b_flags = B_BUSY;
buf.b_dev = ld_dev;
buf.b_error = 0;
buf.b_proc = proc;
/*
* Setup read_info:
*/
rs.bp = &buf;
rs.nbytes = rd->rd_size;
rs.offset = 0;
rs.bufp = rd->rd_addr;
rs.ebufp = rd->rd_addr + rd->rd_size;
rs.chunk = RAMD_CHUNK;
rs.media_sz = rd->rd_size;
rs.strat = bdp->d_strategy;
/*
* Open device and try to get some statistics.
*/
if(error = bdp->d_open(ld_dev, FREAD | FNONBLOCK, 0, proc))
return(error);
if(bdp->d_ioctl(ld_dev, DIOCGDINFO, (caddr_t)&dl, FREAD, proc) == 0) {
/* Read on a cylinder basis */
rs.chunk = dl.d_secsize * dl.d_secpercyl;
rs.media_sz = dl.d_secperunit * dl.d_secsize;
}
#ifdef support_compression
if(ri->ramd_flag & RAMD_LCOMP)
error = decompress(cpy_uncompressed, rd_compressed, &rs);
else
#endif /* support_compression */
error = ramd_norm_read(&rs);
bdp->d_close(ld_dev,FREAD | FNONBLOCK, 0, proc);
return(error);
}
static int
ramd_norm_read(rsp)
struct read_info *rsp;
{
long bytes_left;
int done, error;
struct buf *bp;
int s;
int dotc = 0;
bytes_left = rsp->nbytes;
bp = rsp->bp;
error = 0;
while(bytes_left > 0) {
s = splbio();
bp->b_flags = B_BUSY | B_PHYS | B_READ;
splx(s);
bp->b_blkno = btodb(rsp->offset);
bp->b_bcount = rsp->chunk;
bp->b_data = rsp->bufp;
/* Initiate read */
(*rsp->strat)(bp);
/* Wait for results */
s = splbio();
while ((bp->b_flags & B_DONE) == 0)
tsleep((caddr_t) bp, PRIBIO + 1, "ramd_norm_read", 0);
if (bp->b_flags & B_ERROR)
error = (bp->b_error ? bp->b_error : EIO);
splx(s);
/* Dot counter */
printf(".");
if(!(++dotc % 40))
printf("\n");
done = bp->b_bcount - bp->b_resid;
bytes_left -= done;
rsp->offset += done;
rsp->bufp += done;
if(error || !done)
break;
if((rsp->offset == rsp->media_sz) && (bytes_left != 0)) {
printf("\nInsert next media and hit any key...");
cngetc();
printf("\n");
rsp->offset = 0;
}
}
printf("\n");
return(error);
}
#ifdef support_compression
/*
* Functions supporting uncompression:
*/
/*
* Copy from the uncompression buffer to the ramdisk
*/
static int
cpy_uncompressed(buf, nbyte, rsp)
caddr_t buf;
struct read_info *rsp;
int nbyte;
{
if((rsp->bufp + nbyte) >= rsp->ebufp)
return(0);
bcopy(buf, rsp->bufp, nbyte);
rsp->bufp += nbyte;
return(0);
}
/*
* Read a maximum of 'nbyte' bytes into 'buf'.
*/
static int
rd_compressed(buf, nbyte, rsp)
caddr_t buf;
struct read_info *rsp;
int nbyte;
{
static int dotc = 0;
struct buf *bp;
int nread = 0;
int s;
int done, error;
error = 0;
bp = rsp->bp;
nbyte &= ~(DEV_BSIZE - 1);
while(nbyte > 0) {
s = splbio();
bp->b_flags = B_BUSY | B_PHYS | B_READ;
splx(s);
bp->b_blkno = btodb(rsp->offset);
bp->b_bcount = min(rsp->chunk, nbyte);
bp->b_data = buf;
/* Initiate read */
(*rsp->strat)(bp);
/* Wait for results */
s = splbio();
while ((bp->b_flags & B_DONE) == 0)
tsleep((caddr_t) bp, PRIBIO + 1, "ramd_norm_read", 0);
if (bp->b_flags & B_ERROR)
error = (bp->b_error ? bp->b_error : EIO);
splx(s);
/* Dot counter */
printf(".");
if(!(++dotc % 40))
printf("\n");
done = bp->b_bcount - bp->b_resid;
nbyte -= done;
nread += done;
rsp->offset += done;
if(error || !done)
break;
if((rsp->offset == rsp->media_sz) && (nbyte != 0)) {
if(rsp->offset == rsp->media_sz) {
printf("\nInsert next media and hit any key...");
if(cngetc() != '\n')
printf("\n");
rsp->offset = 0;
}
}
s = splbio();
splx(s);
return(nread);
}
#endif /* support_compression */