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.4 2003/11/14 09:51:47 simokawa Exp $
20 * $DragonFly: src/sys/kern/kern_physio.c,v 1.9 2004/12/31 22:30:19 dillon Exp $
23 #include <sys/param.h>
24 #include <sys/systm.h>
29 #include <sys/device.h>
32 #include <vm/vm_extern.h>
34 #include <machine/physio_proc.h>
36 /* I have no idea what this is used for */
37 struct physio_proc_head physio_proc_freet
, physio_proc_busyt
;
40 physwakeup(struct buf
*bp
)
46 physio(dev_t dev
, struct uio
*uio
, int ioflag
)
58 * NOTE: we no longer have to PHOLD() the process, because the
59 * kernel stack / uarea cannot be swapped, and when it can be in
60 * the future it will only happen if the process is sleeping on
61 * a particular address.
67 /* XXX: sanity check */
68 if(dev
->si_iosize_max
< PAGE_SIZE
) {
69 printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
70 devtoname(dev
), dev
->si_iosize_max
);
71 dev
->si_iosize_max
= DFLTPHYS
;
74 /* Don't check block number overflow for D_MEM */
75 if ((dev_dflags(dev
) & D_TYPEMASK
) == D_MEM
)
80 for (i
= 0; i
< uio
->uio_iovcnt
; i
++) {
81 while (uio
->uio_iov
[i
].iov_len
) {
82 if (uio
->uio_rw
== UIO_READ
)
83 bp
->b_flags
= B_PHYS
| B_CALL
| B_READ
;
85 bp
->b_flags
= B_PHYS
| B_CALL
| B_WRITE
;
87 bp
->b_iodone
= physwakeup
;
88 bp
->b_data
= uio
->uio_iov
[i
].iov_base
;
89 bp
->b_bcount
= uio
->uio_iov
[i
].iov_len
;
90 bp
->b_offset
= uio
->uio_offset
;
93 /* Don't exceed drivers iosize limit */
94 if (bp
->b_bcount
> dev
->si_iosize_max
)
95 bp
->b_bcount
= dev
->si_iosize_max
;
98 * Make sure the pbuf can map the request
99 * XXX: The pbuf has kvasize = MAXPHYS so a request
100 * XXX: larger than MAXPHYS - PAGE_SIZE must be
101 * XXX: page aligned or it will be fragmented.
103 iolen
= ((vm_offset_t
) bp
->b_data
) & PAGE_MASK
;
104 if ((bp
->b_bcount
+ iolen
) > bp
->b_kvasize
) {
105 bp
->b_bcount
= bp
->b_kvasize
;
107 bp
->b_bcount
-= PAGE_SIZE
;
109 bp
->b_bufsize
= bp
->b_bcount
;
111 blockno
= bp
->b_offset
>> DEV_BSHIFT
;
112 if (chk_blockno
&& (daddr_t
)blockno
!= blockno
) {
113 error
= EINVAL
; /* blockno overflow */
116 bp
->b_blkno
= blockno
;
118 if (uio
->uio_segflg
== UIO_USERSPACE
)
119 if (vmapbuf(bp
) < 0) {
126 while ((bp
->b_flags
& B_DONE
) == 0)
127 tsleep((caddr_t
)bp
, 0, "physstr", 0);
130 if (uio
->uio_segflg
== UIO_USERSPACE
)
132 iolen
= bp
->b_bcount
- bp
->b_resid
;
133 if (iolen
== 0 && !(bp
->b_flags
& B_ERROR
))
134 goto doerror
; /* EOF */
135 uio
->uio_iov
[i
].iov_len
-= iolen
;
136 uio
->uio_iov
[i
].iov_base
+= iolen
;
137 uio
->uio_resid
-= iolen
;
138 uio
->uio_offset
+= iolen
;
139 if( bp
->b_flags
& B_ERROR
) {