20 #include <sys/cdefs.h>
23 #include <sys/param.h>
24 #include <sys/systm.h>
32 #include <vm/vm_extern.h>
35 physio(
struct cdev *dev,
struct uio *uio,
int ioflag)
51 if(dev->si_iosize_max < PAGE_SIZE) {
52 printf(
"WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
54 dev->si_iosize_max = DFLTPHYS;
57 for (i = 0; i < uio->uio_iovcnt; i++) {
58 while (uio->uio_iov[i].iov_len) {
60 if (uio->uio_rw == UIO_READ) {
61 bp->b_iocmd = BIO_READ;
62 curthread->td_ru.ru_inblock++;
64 bp->b_iocmd = BIO_WRITE;
65 curthread->td_ru.ru_oublock++;
68 bp->b_data = uio->uio_iov[i].iov_base;
69 bp->b_bcount = uio->uio_iov[i].iov_len;
70 bp->b_offset = uio->uio_offset;
71 bp->b_iooffset = uio->uio_offset;
75 if (bp->b_bcount > dev->si_iosize_max)
76 bp->b_bcount = dev->si_iosize_max;
84 iolen = ((vm_offset_t) bp->b_data) & PAGE_MASK;
85 if ((bp->b_bcount + iolen) > bp->b_kvasize) {
86 bp->b_bcount = bp->b_kvasize;
88 bp->b_bcount -= PAGE_SIZE;
90 bp->b_bufsize = bp->b_bcount;
92 bp->b_blkno = btodb(bp->b_offset);
95 if (uio->uio_segflg == UIO_USERSPACE) {
96 if (dev->si_flags & SI_UNMAPPED)
107 if (uio->uio_rw == UIO_READ)
108 bwait(bp, PRIBIO,
"physrd");
110 bwait(bp, PRIBIO,
"physwr");
112 if (uio->uio_segflg == UIO_USERSPACE)
114 iolen = bp->b_bcount - bp->b_resid;
115 if (iolen == 0 && !(bp->b_ioflags & BIO_ERROR))
117 uio->uio_iov[i].iov_len -= iolen;
118 uio->uio_iov[i].iov_base =
119 (
char *)uio->uio_iov[i].iov_base + iolen;
120 uio->uio_resid -= iolen;
121 uio->uio_offset += iolen;
122 if( bp->b_ioflags & BIO_ERROR) {
void dev_strategy_csw(struct cdev *dev, struct cdevsw *csw, struct buf *bp)
void bwait(struct buf *bp, u_char pri, const char *wchan)
void bdone(struct buf *bp)
void vunmapbuf(struct buf *bp)
int printf(const char *fmt,...)
int physio(struct cdev *dev, struct uio *uio, int ioflag)
const char * devtoname(struct cdev *dev)
int vmapbuf(struct buf *bp, int mapbuf)