49#include <sys/kernel.h>
50#include <sys/limits.h>
54#include <sys/resourcevar.h>
55#include <sys/rwlock.h>
57#include <sys/sysctl.h>
61#include <vm/vm_param.h>
62#include <vm/vm_extern.h>
63#include <vm/vm_page.h>
64#include <vm/vm_pageout.h>
67#include <machine/bus.h>
69SYSCTL_INT(_kern, KERN_IOV_MAX, iov_max, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, UIO_MAXIOV,
70 "Maximum number of elements in an I/O vector; sysconf(_SC_IOV_MAX)");
79 save = vm_fault_disable_pagefaults();
80 error = copyin(udaddr, kaddr, len);
81 vm_fault_enable_pagefaults(save);
90 save = vm_fault_disable_pagefaults();
91 error = copyout(kaddr, udaddr, len);
92 vm_fault_enable_pagefaults(save);
96#define PHYS_PAGE_COUNT(len) (howmany(len, PAGE_SIZE) + 1)
106 iov[0].iov_base =
src;
107 iov[0].iov_len = len;
112 uio.uio_segflg = UIO_SYSSPACE;
113 uio.uio_rw = UIO_WRITE;
115 m[i] = PHYS_TO_VM_PAGE(dst);
116 return (uiomove_fromphys(m, dst & PAGE_MASK, len, &uio));
127 iov[0].iov_base = dst;
128 iov[0].iov_len = len;
133 uio.uio_segflg = UIO_SYSSPACE;
134 uio.uio_rw = UIO_READ;
136 m[i] = PHYS_TO_VM_PAGE(
src);
137 return (uiomove_fromphys(m,
src & PAGE_MASK, len, &uio));
140#undef PHYS_PAGE_COUNT
150 while (offset >=
src->ds_len) {
151 offset -=
src->ds_len;
155 while (len > 0 && error == 0) {
156 seg_len = MIN(
src->ds_len - offset, len);
157 error =
physcopyin((
void *)(uintptr_t)(
src->ds_addr + offset),
176 while (offset >= dst->ds_len) {
177 offset -= dst->ds_len;
181 while (len > 0 && error == 0) {
182 seg_len = MIN(dst->ds_len - offset, len);
213 int error, newflags, save;
217 KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
219 KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread,
222 if (uio->uio_segflg == UIO_USERSPACE) {
223 newflags = TDP_DEADLKTREAT;
228 newflags |= TDP_NOFAULTING | TDP_RESETSPUR;
230 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
231 "Calling uiomove()");
233 save = curthread_pflags_set(newflags);
235 KASSERT(nofault == 0, (
"uiomove: nofault"));
238 while (n > 0 && uio->uio_resid) {
249 switch (uio->uio_segflg) {
252 if (uio->uio_rw == UIO_READ)
253 error = copyout(cp, iov->iov_base, cnt);
255 error = copyin(iov->iov_base, cp, cnt);
261 if (uio->uio_rw == UIO_READ)
262 bcopy(cp, iov->iov_base, cnt);
264 bcopy(iov->iov_base, cp, cnt);
269 iov->iov_base = (
char *)iov->iov_base + cnt;
271 uio->uio_resid -= cnt;
272 uio->uio_offset += cnt;
273 cp = (
char *)cp + cnt;
278 curthread_pflags_restore(save);
294 if (uio->uio_offset < 0 || uio->uio_resid < 0 ||
295 (offset = uio->uio_offset) != uio->uio_offset)
297 if (buflen <= 0 || offset >= buflen)
299 if ((n = buflen - offset) > IOSIZE_MAX)
301 return (
uiomove((
char *)
buf + offset, n, uio));
313 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
317 if (uio->uio_iovcnt == 0 || uio->uio_resid == 0)
320 if (iov->iov_len == 0) {
325 switch (uio->uio_segflg) {
327 if (subyte(iov->iov_base, c) < 0)
332 iov_base = iov->iov_base;
339 iov->iov_base = (
char *)iov->iov_base + 1;
347copyiniov(
const struct iovec *iovp, u_int iovcnt,
struct iovec **iov,
int error)
352 if (iovcnt > UIO_MAXIOV)
354 iovlen = iovcnt *
sizeof (
struct iovec);
355 *iov =
malloc(iovlen, M_IOV, M_WAITOK);
356 error = copyin(iovp, *iov, iovlen);
365copyinuio(
const struct iovec *iovp, u_int iovcnt,
struct uio **uiop)
373 if (iovcnt > UIO_MAXIOV)
375 iovlen = iovcnt *
sizeof (
struct iovec);
376 uio =
malloc(iovlen +
sizeof *uio, M_IOV, M_WAITOK);
377 iov = (
struct iovec *)(uio + 1);
378 error = copyin(iovp, iov, iovlen);
384 uio->uio_iovcnt = iovcnt;
385 uio->uio_segflg = UIO_USERSPACE;
386 uio->uio_offset = -1;
388 for (i = 0; i < iovcnt; i++) {
389 if (iov->iov_len > IOSIZE_MAX - uio->uio_resid) {
393 uio->uio_resid += iov->iov_len;
406 iovlen = uiop->uio_iovcnt *
sizeof (
struct iovec);
407 uio =
malloc(iovlen +
sizeof *uio, M_IOV, M_WAITOK);
409 uio->uio_iov = (
struct iovec *)(uio + 1);
410 bcopy(uiop->uio_iov, uio->uio_iov, iovlen);
425 vms = td->td_proc->p_vmspace;
430 *
addr = round_page((vm_offset_t)vms->vm_daddr +
434 size = (vm_size_t)round_page(sz);
437 error = vm_mmap_object(&vms->vm_map,
addr, size, VM_PROT_READ |
438 VM_PROT_WRITE, VM_PROT_ALL, MAP_PRIVATE | MAP_ANON, NULL, 0,
455 map = &td->td_proc->p_vmspace->vm_map;
456 size = (vm_size_t)round_page(sz);
458 if (vm_map_remove(map,
addr,
addr + size) != KERN_SUCCESS)
470 rv = fueword32(
addr, &val);
471 return (rv == -1 ? -1 : val);
476fuword64(
volatile const void *
addr)
481 rv = fueword64(
addr, &val);
482 return (rv == -1 ? -1 : val);
492 rv = fueword(
addr, &val);
493 return (rv == -1 ? -1 : val);
502 rv = casueword32(
addr, old, &val,
new);
503 return (rv == -1 ? -1 : val);
512 rv = casueword(
addr, old, &val,
new);
513 return (rv == -1 ? -1 : val);
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
rlim_t lim_max(struct thread *td, int which)
void panic(const char *fmt,...)
struct intr_irqsrc ** src
#define PHYS_PAGE_COUNT(len)
int copyiniov(const struct iovec *iovp, u_int iovcnt, struct iovec **iov, int error)
int copyout_unmap(struct thread *td, vm_offset_t addr, size_t sz)
int uiomove_nofault(void *cp, int n, struct uio *uio)
SYSCTL_INT(_kern, KERN_IOV_MAX, iov_max, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, UIO_MAXIOV, "Maximum number of elements in an I/O vector; sysconf(_SC_IOV_MAX)")
int32_t fuword32(volatile const void *addr)
int copyin_nofault(const void *udaddr, void *kaddr, size_t len)
static int uiomove_faultflag(void *cp, int n, struct uio *uio, int nofault)
int copyout_nofault(const void *kaddr, void *udaddr, size_t len)
int copyinuio(const struct iovec *iovp, u_int iovcnt, struct uio **uiop)
uint32_t casuword32(volatile uint32_t *addr, uint32_t old, uint32_t new)
struct uio * cloneuio(struct uio *uiop)
int uiomove(void *cp, int n, struct uio *uio)
int physcopyin_vlist(bus_dma_segment_t *src, off_t offset, vm_paddr_t dst, size_t len)
int ureadc(int c, struct uio *uio)
long fuword(volatile const void *addr)
u_long casuword(volatile u_long *addr, u_long old, u_long new)
int uiomove_frombuf(void *buf, int buflen, struct uio *uio)
int physcopyin(void *src, vm_paddr_t dst, size_t len)
int physcopyout_vlist(vm_paddr_t src, bus_dma_segment_t *dst, off_t offset, size_t len)
int physcopyout(vm_paddr_t src, void *dst, size_t len)
int copyout_map(struct thread *td, vm_offset_t *addr, size_t sz)