1994-05-25 09:21:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 John S. Dyson
|
|
|
|
* All rights reserved.
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
1994-05-25 09:21:21 +00:00
|
|
|
* notice immediately at the beginning of the file, without modification,
|
|
|
|
* this list of conditions, and the following disclaimer.
|
1994-05-24 10:09:53 +00:00
|
|
|
* 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.
|
1994-05-25 09:21:21 +00:00
|
|
|
* 3. Absolutely no warranty of function or purpose is made by the author
|
|
|
|
* John S. Dyson.
|
|
|
|
* 4. Modifications may be freely made to this file if the above conditions
|
|
|
|
* are met.
|
1994-08-02 07:55:43 +00:00
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/proc.h>
|
1998-03-28 10:33:27 +00:00
|
|
|
#include <sys/uio.h>
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-12-02 18:58:56 +00:00
|
|
|
static void physwakeup __P((struct buf *bp));
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-05-07 07:03:47 +00:00
|
|
|
int
|
|
|
|
physread(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
1999-08-14 11:40:51 +00:00
|
|
|
return(physio(NULL, dev, 1, minphys, uio));
|
1999-05-07 07:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
physwrite(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
1999-08-14 11:40:51 +00:00
|
|
|
return(physio(NULL, dev, 0, minphys, uio));
|
1999-05-07 07:03:47 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
1999-08-14 11:40:51 +00:00
|
|
|
physio(bp, dev, rw, minp, uio)
|
1994-05-25 09:21:21 +00:00
|
|
|
struct buf *bp;
|
|
|
|
dev_t dev;
|
|
|
|
int rw;
|
1995-12-02 18:58:56 +00:00
|
|
|
u_int (*minp) __P((struct buf *bp));
|
1994-05-25 09:21:21 +00:00
|
|
|
struct uio *uio;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1994-05-25 09:21:21 +00:00
|
|
|
int i;
|
|
|
|
int bufflags = rw?B_READ:0;
|
|
|
|
int error;
|
|
|
|
int spl;
|
1994-08-06 09:15:42 +00:00
|
|
|
caddr_t sa;
|
1999-08-21 06:48:16 +00:00
|
|
|
off_t blockno;
|
1994-08-06 09:15:42 +00:00
|
|
|
int bp_alloc = (bp == 0);
|
|
|
|
struct buf *bpa;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1999-04-06 03:04:47 +00:00
|
|
|
/*
|
|
|
|
* Keep the process UPAGES from being swapped. (XXX for performance?)
|
|
|
|
*/
|
|
|
|
PHOLD(curproc);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
/* create and build a buffer header for a transfer */
|
1999-09-12 08:27:41 +00:00
|
|
|
bpa = getpbuf(NULL);
|
1999-06-26 02:47:16 +00:00
|
|
|
if (!bp_alloc)
|
|
|
|
BUF_LOCK(bp, LK_EXCLUSIVE);
|
|
|
|
else
|
1994-08-06 09:15:42 +00:00
|
|
|
bp = bpa;
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1994-08-06 09:15:42 +00:00
|
|
|
/*
|
|
|
|
* get a copy of the kva from the physical buffer
|
|
|
|
*/
|
|
|
|
sa = bpa->b_data;
|
1994-05-25 09:21:21 +00:00
|
|
|
error = bp->b_error = 0;
|
|
|
|
|
1999-06-26 02:47:16 +00:00
|
|
|
for (i = 0; i < uio->uio_iovcnt; i++) {
|
|
|
|
while (uio->uio_iov[i].iov_len) {
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1998-01-24 02:01:46 +00:00
|
|
|
bp->b_dev = dev;
|
1994-05-25 09:21:21 +00:00
|
|
|
bp->b_bcount = uio->uio_iov[i].iov_len;
|
1999-06-26 02:47:16 +00:00
|
|
|
bp->b_flags = B_PHYS | B_CALL | bufflags;
|
1996-06-26 05:52:15 +00:00
|
|
|
bp->b_iodone = physwakeup;
|
|
|
|
bp->b_data = uio->uio_iov[i].iov_base;
|
1994-08-07 13:10:43 +00:00
|
|
|
bp->b_bcount = minp( bp);
|
|
|
|
if( minp != minphys)
|
|
|
|
bp->b_bcount = minphys( bp);
|
1994-05-25 09:21:21 +00:00
|
|
|
bp->b_bufsize = bp->b_bcount;
|
1994-08-06 09:15:42 +00:00
|
|
|
/*
|
|
|
|
* pass in the kva from the physical buffer
|
|
|
|
* for the temporary kernel mapping.
|
|
|
|
*/
|
|
|
|
bp->b_saveaddr = sa;
|
1999-08-21 06:48:16 +00:00
|
|
|
blockno = uio->uio_offset >> DEV_BSHIFT;
|
1999-08-21 18:22:44 +00:00
|
|
|
if ((daddr_t)blockno != blockno) {
|
1999-08-21 06:48:16 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto doerror;
|
|
|
|
}
|
1999-08-21 18:22:44 +00:00
|
|
|
bp->b_blkno = blockno;
|
1998-08-19 10:50:32 +00:00
|
|
|
bp->b_offset = uio->uio_offset;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-11-28 02:40:38 +00:00
|
|
|
if (uio->uio_segflg == UIO_USERSPACE) {
|
|
|
|
if (rw && !useracc(bp->b_data, bp->b_bufsize, B_WRITE)) {
|
|
|
|
error = EFAULT;
|
|
|
|
goto doerror;
|
|
|
|
}
|
|
|
|
if (!rw && !useracc(bp->b_data, bp->b_bufsize, B_READ)) {
|
|
|
|
error = EFAULT;
|
|
|
|
goto doerror;
|
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1995-11-28 02:40:38 +00:00
|
|
|
/* bring buffer into kernel space */
|
|
|
|
vmapbuf(bp);
|
|
|
|
}
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
/* perform transfer */
|
1999-08-14 11:40:51 +00:00
|
|
|
BUF_STRATEGY(bp, 0);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
spl = splbio();
|
|
|
|
while ((bp->b_flags & B_DONE) == 0)
|
|
|
|
tsleep((caddr_t)bp, PRIBIO, "physstr", 0);
|
|
|
|
splx(spl);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-11-28 02:40:38 +00:00
|
|
|
/* release mapping into kernel space */
|
|
|
|
if (uio->uio_segflg == UIO_USERSPACE)
|
|
|
|
vunmapbuf(bp);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* update the uio data
|
|
|
|
*/
|
1995-05-30 08:16:23 +00:00
|
|
|
{
|
1994-05-25 09:21:21 +00:00
|
|
|
int iolen = bp->b_bcount - bp->b_resid;
|
1994-08-08 13:53:55 +00:00
|
|
|
|
|
|
|
if (iolen == 0 && !(bp->b_flags & B_ERROR))
|
|
|
|
goto doerror; /* EOF */
|
1994-05-25 09:21:21 +00:00
|
|
|
uio->uio_iov[i].iov_len -= iolen;
|
|
|
|
uio->uio_iov[i].iov_base += iolen;
|
|
|
|
uio->uio_resid -= iolen;
|
|
|
|
uio->uio_offset += iolen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check for an error
|
|
|
|
*/
|
|
|
|
if( bp->b_flags & B_ERROR) {
|
|
|
|
error = bp->b_error;
|
|
|
|
goto doerror;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doerror:
|
1999-01-21 08:29:12 +00:00
|
|
|
relpbuf(bpa, NULL);
|
1994-08-06 09:15:42 +00:00
|
|
|
if (!bp_alloc) {
|
1999-06-26 02:47:16 +00:00
|
|
|
bp->b_flags &= ~B_PHYS;
|
|
|
|
BUF_UNLOCK(bp);
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1999-04-06 03:04:47 +00:00
|
|
|
/*
|
|
|
|
* Allow the process UPAGES to be swapped again.
|
|
|
|
*/
|
|
|
|
PRELE(curproc);
|
1994-05-25 09:21:21 +00:00
|
|
|
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
1997-08-26 00:15:04 +00:00
|
|
|
minphys(bp)
|
|
|
|
struct buf *bp;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1999-09-22 19:56:14 +00:00
|
|
|
u_int maxphys;
|
1996-06-26 05:52:15 +00:00
|
|
|
|
1999-09-22 19:56:14 +00:00
|
|
|
maxphys = bp->b_dev->si_iosize_max;
|
1999-10-02 11:17:54 +00:00
|
|
|
if(!maxphys) {
|
1999-10-09 05:17:05 +00:00
|
|
|
printf("WARNING: %s maxphys = 0 ??\n", devtoname(bp->b_dev));
|
1999-10-02 11:17:54 +00:00
|
|
|
maxphys = DFLTPHYS;
|
1999-10-02 20:21:49 +00:00
|
|
|
bp->b_dev->si_iosize_max = DFLTPHYS;
|
1999-10-02 11:17:54 +00:00
|
|
|
}
|
1998-04-04 05:55:05 +00:00
|
|
|
if (bp->b_kvasize && (bp->b_kvasize < maxphys))
|
1998-01-24 02:01:46 +00:00
|
|
|
maxphys = bp->b_kvasize;
|
|
|
|
|
|
|
|
if(((vm_offset_t) bp->b_data) & PAGE_MASK) {
|
|
|
|
maxphys -= PAGE_SIZE;
|
1996-06-26 05:52:15 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1996-06-26 05:52:15 +00:00
|
|
|
if( bp->b_bcount > maxphys) {
|
|
|
|
bp->b_bcount = maxphys;
|
1994-05-25 09:21:21 +00:00
|
|
|
}
|
1998-01-24 02:01:46 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
return bp->b_bcount;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
static void
|
|
|
|
physwakeup(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
wakeup((caddr_t) bp);
|
|
|
|
bp->b_flags &= ~B_CALL;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|