2 * Copyright (c) 1994 John S. Dyson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice immediately at the beginning of the file, without modification,
10 * this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Absolutely no warranty of function or purpose is made by the author
16 * 4. Modifications may be freely made to this file if the above conditions
19 * $FreeBSD: src/sys/kern/kern_physio.c,v 1.46.2.3 2003/05/29 06:15:35 alc Exp $
20 * $DragonFly: src/sys/kern/kern_physio.c,v 1.2 2003/06/17 04:28:41 dillon Exp $
23 #include <sys/param.h>
24 #include <sys/systm.h>
31 #include <vm/vm_extern.h>
34 physwakeup(struct buf *bp)
40 physio(dev_t dev, struct uio *uio, int ioflag)
50 /* Keep the process UPAGES from being swapped. XXX: why ? */
57 /* XXX: sanity check */
58 if(dev->si_iosize_max < PAGE_SIZE) {
59 printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
60 devtoname(dev), dev->si_iosize_max);
61 dev->si_iosize_max = DFLTPHYS;
64 for (i = 0; i < uio->uio_iovcnt; i++) {
65 while (uio->uio_iov[i].iov_len) {
66 if (uio->uio_rw == UIO_READ)
67 bp->b_flags = B_PHYS | B_CALL | B_READ;
69 bp->b_flags = B_PHYS | B_CALL | B_WRITE;
71 bp->b_iodone = physwakeup;
72 bp->b_data = uio->uio_iov[i].iov_base;
73 bp->b_bcount = uio->uio_iov[i].iov_len;
74 bp->b_offset = uio->uio_offset;
77 /* Don't exceed drivers iosize limit */
78 if (bp->b_bcount > dev->si_iosize_max)
79 bp->b_bcount = dev->si_iosize_max;
82 * Make sure the pbuf can map the request
83 * XXX: The pbuf has kvasize = MAXPHYS so a request
84 * XXX: larger than MAXPHYS - PAGE_SIZE must be
85 * XXX: page aligned or it will be fragmented.
87 iolen = ((vm_offset_t) bp->b_data) & PAGE_MASK;
88 if ((bp->b_bcount + iolen) > bp->b_kvasize) {
89 bp->b_bcount = bp->b_kvasize;
91 bp->b_bcount -= PAGE_SIZE;
93 bp->b_bufsize = bp->b_bcount;
95 blockno = bp->b_offset >> DEV_BSHIFT;
96 if ((daddr_t)blockno != blockno) {
97 error = EINVAL; /* blockno overflow */
100 bp->b_blkno = blockno;
102 if (uio->uio_segflg == UIO_USERSPACE)
103 if (vmapbuf(bp) < 0) {
110 while ((bp->b_flags & B_DONE) == 0)
111 tsleep((caddr_t)bp, PRIBIO, "physstr", 0);
114 if (uio->uio_segflg == UIO_USERSPACE)
116 iolen = bp->b_bcount - bp->b_resid;
117 if (iolen == 0 && !(bp->b_flags & B_ERROR))
118 goto doerror; /* EOF */
119 uio->uio_iov[i].iov_len -= iolen;
120 uio->uio_iov[i].iov_base += iolen;
121 uio->uio_resid -= iolen;
122 uio->uio_offset += iolen;
123 if( bp->b_flags & B_ERROR) {