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
20 #include <sys/cdefs.h>
21 __FBSDID("$FreeBSD$");
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)
43 /* Keep the process UPAGES from being swapped. XXX: why ? */
50 /* XXX: sanity check */
51 if(dev->si_iosize_max < PAGE_SIZE) {
52 printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
53 devtoname(dev), dev->si_iosize_max);
54 dev->si_iosize_max = DFLTPHYS;
58 * If the driver does not want I/O to be split, that means that we
59 * need to reject any requests that will not fit into one buffer.
61 if (dev->si_flags & SI_NOSPLIT &&
62 (uio->uio_resid > dev->si_iosize_max || uio->uio_resid > MAXPHYS ||
63 uio->uio_iovcnt > 1)) {
65 * Tell the user why his I/O was rejected.
67 if (uio->uio_resid > dev->si_iosize_max)
68 uprintf("%s: request size=%zd > si_iosize_max=%d; "
69 "cannot split request\n", devtoname(dev),
70 uio->uio_resid, dev->si_iosize_max);
71 if (uio->uio_resid > MAXPHYS)
72 uprintf("%s: request size=%zd > MAXPHYS=%d; "
73 "cannot split request\n", devtoname(dev),
74 uio->uio_resid, MAXPHYS);
75 if (uio->uio_iovcnt > 1)
76 uprintf("%s: request vectors=%d > 1; "
77 "cannot split request\n", devtoname(dev),
84 for (i = 0; i < uio->uio_iovcnt; i++) {
85 while (uio->uio_iov[i].iov_len) {
87 if (uio->uio_rw == UIO_READ) {
88 bp->b_iocmd = BIO_READ;
89 curthread->td_ru.ru_inblock++;
91 bp->b_iocmd = BIO_WRITE;
92 curthread->td_ru.ru_oublock++;
95 bp->b_data = uio->uio_iov[i].iov_base;
96 bp->b_bcount = uio->uio_iov[i].iov_len;
97 bp->b_offset = uio->uio_offset;
98 bp->b_iooffset = uio->uio_offset;
101 /* Don't exceed drivers iosize limit */
102 if (bp->b_bcount > dev->si_iosize_max)
103 bp->b_bcount = dev->si_iosize_max;
106 * Make sure the pbuf can map the request
107 * XXX: The pbuf has kvasize = MAXPHYS so a request
108 * XXX: larger than MAXPHYS - PAGE_SIZE must be
109 * XXX: page aligned or it will be fragmented.
111 iolen = ((vm_offset_t) bp->b_data) & PAGE_MASK;
112 if ((bp->b_bcount + iolen) > bp->b_kvasize) {
114 * This device does not want I/O to be split.
116 if (dev->si_flags & SI_NOSPLIT) {
117 uprintf("%s: request ptr %p is not "
118 "on a page boundary; cannot split "
119 "request\n", devtoname(dev),
124 bp->b_bcount = bp->b_kvasize;
126 bp->b_bcount -= PAGE_SIZE;
128 bp->b_bufsize = bp->b_bcount;
130 bp->b_blkno = btodb(bp->b_offset);
133 if (uio->uio_segflg == UIO_USERSPACE) {
134 if (dev->si_flags & SI_UNMAPPED)
138 if (vmapbuf(bp, mapped) < 0) {
144 dev_strategy_csw(dev, csw, bp);
145 if (uio->uio_rw == UIO_READ)
146 bwait(bp, PRIBIO, "physrd");
148 bwait(bp, PRIBIO, "physwr");
150 if (uio->uio_segflg == UIO_USERSPACE)
152 iolen = bp->b_bcount - bp->b_resid;
153 if (iolen == 0 && !(bp->b_ioflags & BIO_ERROR))
154 goto doerror; /* EOF */
155 uio->uio_iov[i].iov_len -= iolen;
156 uio->uio_iov[i].iov_base =
157 (char *)uio->uio_iov[i].iov_base + iolen;
158 uio->uio_resid -= iolen;
159 uio->uio_offset += iolen;
160 if( bp->b_ioflags & BIO_ERROR) {