Changeset View
Changeset View
Standalone View
Standalone View
sys/arm64/arm64/mem.c
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
#include <vm/vm_page.h> | #include <vm/vm_page.h> | ||||
struct mem_range_softc mem_range_softc; | struct mem_range_softc mem_range_softc; | ||||
int | int | ||||
memrw(struct cdev *dev, struct uio *uio, int flags) | memrw(struct cdev *dev, struct uio *uio, int flags) | ||||
{ | { | ||||
struct iovec *iov; | struct iovec *iov; | ||||
struct vm_page m; | vm_offset_t off, v, p; | ||||
vm_page_t marr; | |||||
vm_offset_t off, v; | |||||
u_int cnt; | u_int cnt; | ||||
int error; | int error; | ||||
void *ptr; | |||||
error = 0; | error = 0; | ||||
while (uio->uio_resid > 0 && error == 0) { | while (uio->uio_resid > 0 && error == 0) { | ||||
iov = uio->uio_iov; | iov = uio->uio_iov; | ||||
if (iov->iov_len == 0) { | if (iov->iov_len == 0) { | ||||
uio->uio_iov++; | uio->uio_iov++; | ||||
uio->uio_iovcnt--; | uio->uio_iovcnt--; | ||||
if (uio->uio_iovcnt < 0) | if (uio->uio_iovcnt < 0) | ||||
panic("memrw"); | panic("memrw"); | ||||
continue; | continue; | ||||
} | } | ||||
v = uio->uio_offset; | p = v = uio->uio_offset; | ||||
off = v & PAGE_MASK; | off = v & PAGE_MASK; | ||||
cnt = ulmin(iov->iov_len, PAGE_SIZE - (u_int)off); | cnt = ulmin(iov->iov_len, PAGE_SIZE - (u_int)off); | ||||
if (cnt == 0) | if (cnt == 0) | ||||
continue; | continue; | ||||
switch(dev2unit(dev)) { | switch(dev2unit(dev)) { | ||||
case CDEV_MINOR_KMEM: | case CDEV_MINOR_KMEM: | ||||
/* If the address is in the DMAP just copy it */ | /* If the address is in the DMAP just copy it */ | ||||
if (VIRT_IN_DMAP(v)) { | if (VIRT_IN_DMAP(v)) { | ||||
error = uiomove((void *)v, cnt, uio); | error = uiomove((void *)v, cnt, uio); | ||||
break; | break; | ||||
} | } | ||||
if (!kernacc((void *)v, cnt, uio->uio_rw == UIO_READ ? | if (!kernacc((void *)v, cnt, uio->uio_rw == UIO_READ ? | ||||
VM_PROT_READ : VM_PROT_WRITE)) { | VM_PROT_READ : VM_PROT_WRITE)) { | ||||
error = EFAULT; | error = EFAULT; | ||||
break; | break; | ||||
} | } | ||||
/* Get the physical address to read */ | /* Get the physical address to read */ | ||||
v = pmap_extract(kernel_pmap, v); | p = pmap_extract(kernel_pmap, v); | ||||
if (v == 0) { | if (p == 0) { | ||||
error = EFAULT; | error = EFAULT; | ||||
break; | break; | ||||
} | } | ||||
/* FALLTHROUGH */ | /* FALLTHROUGH */ | ||||
case CDEV_MINOR_MEM: | case CDEV_MINOR_MEM: | ||||
/* If within the DMAP use this to copy from */ | /* If within the DMAP use this to copy from */ | ||||
if (PHYS_IN_DMAP(v)) { | if (PHYS_IN_DMAP_STRICT(p)) { | ||||
v = PHYS_TO_DMAP(v); | v = PHYS_TO_DMAP(p); | ||||
error = uiomove((void *)v, cnt, uio); | error = uiomove((void *)v, cnt, uio); | ||||
break; | break; | ||||
} | } | ||||
/* Have uiomove_fromphys handle the data */ | ptr = pmap_mapdev(p, PAGE_SIZE); | ||||
m.phys_addr = trunc_page(v); | error = uiomove((void*)ptr, cnt, uio); | ||||
marr = &m; | pmap_unmapdev((vm_offset_t)ptr, PAGE_SIZE); | ||||
uiomove_fromphys(&marr, off, cnt, uio); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
Show All 21 Lines |