move.c revision 2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#include <sys/sysmacros.h>
#define UIO_DCOPY_CHANNEL 0
#define UIO_DCOPY_CMD 1
/*
* Move "n" bytes at byte address "p"; "rw" indicates the direction
* of the move, and the I/O parameters are provided in "uio", which is
* update to reflect the data which was moved. Returns 0 on success or
* a non-zero errno on failure.
*/
int
{
int error;
if (cnt == 0l) {
uio->uio_iovcnt--;
continue;
}
switch (uio->uio_segflg) {
case UIO_USERSPACE:
case UIO_USERISPACE:
} else {
}
if (error)
return (error);
break;
case UIO_SYSSPACE:
else
if (error)
return (error);
break;
}
n -= cnt;
}
return (0);
}
/*
* Fault in the pages of the first n bytes specified by the uio structure.
* 1 byte in each page is touched and the uio struct is unmodified. Any
* error will terminate the process as this is only a best attempt to get
* the pages resident.
*/
void
{
caddr_t p;
int iovcnt;
while ((n > 0) && (iovcnt > 0)) {
if (cnt == 0) {
/* empty iov entry */
iov++;
iovcnt--;
continue;
}
n -= cnt;
/*
* touch each page in this segment.
*/
while (cnt) {
switch (uio->uio_segflg) {
case UIO_USERSPACE:
case UIO_USERISPACE:
return;
break;
case UIO_SYSSPACE:
return;
break;
}
p += incr;
}
/*
* touch the last byte in case it straddles a page.
*/
p--;
switch (uio->uio_segflg) {
case UIO_USERSPACE:
case UIO_USERISPACE:
return;
break;
case UIO_SYSSPACE:
return;
break;
}
iov++;
iovcnt--;
}
}
/*
* same as uiomove() but doesn't modify uio structure.
* return in cbytes how many bytes were copied.
*/
int
{
int error;
int iovcnt;
*cbytes = 0;
if (cnt == 0)
continue;
switch (uio->uio_segflg) {
case UIO_USERSPACE:
case UIO_USERISPACE:
} else {
}
if (error)
return (error);
break;
case UIO_SYSSPACE:
else
if (error)
return (error);
break;
}
n -= cnt;
}
return (0);
}
/*
* transfer a character value into the address space
* delineated by a uio and update fields within the
* uio for next character. Return 0 for success, EFAULT
* for error.
*/
int
{
unsigned char c;
/*
* first determine if uio is valid. uiop should be
* non-NULL and the resid count > 0.
*/
return (EFAULT);
/*
* scan through iovecs until one is found that is non-empty.
* Return EFAULT if none found.
*/
while (uiop->uio_iovcnt > 0) {
uiop->uio_iovcnt--;
} else
break;
}
if (uiop->uio_iovcnt <= 0)
return (EFAULT);
/*
* Transfer character to uio space.
*/
c = (unsigned char) (val & 0xFF);
switch (uiop->uio_segflg) {
case UIO_USERISPACE:
case UIO_USERSPACE:
return (EFAULT);
break;
case UIO_SYSSPACE: /* can do direct copy since kernel-kernel */
break;
default:
return (EFAULT); /* invalid segflg value */
}
/*
*/
uiop->uio_loffset++;
return (0); /* success */
}
/*
* return a character value from the address space
* delineated by a uio and update fields within the
* uio for next character. Return the character for success,
* -1 for error.
*/
int
{
unsigned char c;
/*
* verify we were passed a valid uio structure.
* (1) non-NULL uiop, (2) positive resid count
* (3) there is an iovec with positive length
*/
return (-1);
while (uiop->uio_iovcnt > 0) {
uiop->uio_iovcnt--;
} else
break;
}
if (uiop->uio_iovcnt <= 0)
return (-1);
/*
* Get the character from the uio address space.
*/
switch (uiop->uio_segflg) {
case UIO_USERISPACE:
case UIO_USERSPACE:
return (-1);
break;
case UIO_SYSSPACE:
break;
default:
return (-1); /* invalid segflg */
}
/*
* Adjust fields of iovec and uio appropriately.
*/
uiop->uio_loffset++;
return ((int)c & 0xFF); /* success */
}
/*
* Drop the next n chars out of *uiop.
*/
void
{
return;
while (n != 0) {
if (niovb == 0) {
uiop->uio_iovcnt--;
continue;
}
n -= niovb;
}
}
/*
* Dup the suio into the duio and diovec of size diov_cnt. If diov
* is too small to dup suio then an error will be returned, else 0.
*/
int
{
int ix;
return (1);
}
return (0);
}
/*
* Shadow state for checking if a platform has hardware asynchronous
*
* Dcopy does a call-back to uioa_dcopy_enable() when a dma device calls
* into dcopy to register and uioa_dcopy_disable() when the device calls
* into dcopy to unregister.
*/
void
{
}
void
{
}
/*
* Schedule an asynchronous move of "n" bytes at byte address "p",
* "rw" indicates the direction of the move, I/O parameters and
* async state are provided in "uioa" which is update to reflect
* the data which is to be moved.
*
* Returns 0 on success or a non-zero errno on failure.
*
* Note, while the uioasync APIs are general purpose in design
*/
int
{
int cnt;
int ret = 0;
int dcopy_flags;
/* The uioa_t isn't enabled */
return (ENXIO);
}
/* Only support to user-land from kernel */
return (ENOTSUP);
}
/*
* While source bytes and destination bytes.
*/
uioa->uio_iovcnt--;
continue;
}
/*
* While source bytes schedule an async
* dma for destination page by page.
*/
while (n > 0) {
/* Min copy count src and dst and page sized */
/* XXX if next page(s) contiguous could use multipage */
/*
* if we have an old command, we want to link all
* other commands to the next command we alloced so
* we only need to track the last command but can
* still free them all.
*/
}
if (ret != DCOPY_SUCCESS) {
/* Error of some sort */
return (EIO);
}
if (uioa_maxpoll >= 0) {
/* Blocking (>0 may be) used in uioafini() */
} else {
/* Non blocking uioafini() so no intr */
}
/* Have a (page_t **) */
} else {
/* Have a (pfn_t *) */
}
if (ret != DCOPY_SUCCESS) {
/* Error of some sort */
return (EIO);
}
ret = 0;
/* If UIOA_POLL not set, set it */
n -= cnt;
/* End of iovec? */
/* Yup, next iovec */
break;
}
/* Next dst addr page? */
/* Yup, next page_t */
}
}
}
return (ret);
}
/*
* Initialize a uioa_t for a given uio_t for the current user context,
* copy the common uio_t to the uioa_t, walk the shared iovec_t and
* lock down the user-land page(s) containing iovec_t data, then mapin
* user-land pages using segkpm.
*/
int
{
int off;
int len;
int error;
/* Can only init() a freshly allocated uioa_t */
return (EINVAL);
}
if (error == DCOPY_NORESOURCES) {
/* Turn off uioa */
return (ENODEV);
}
if (error != DCOPY_SUCCESS) {
/* Alloc failed */
return (EIO);
}
/* Indicate uioa_t (will be) initialized */
uioap->uioa_mbytes = 0;
/* initialize *uiop->uio_iov */
if (iovcnt > UIOA_IOV_MAX) {
/* Too big? */
return (E2BIG);
}
/* Mark the uioap as such */
/*
* For each iovec_t, lock-down the page(s) backing the iovec_t
* and save the page_t list for phys addr use in uioamove().
*/
while (iovcnt > 0) {
/* Lock down page(s) for the iov span */
/* Error */
goto cleanup;
}
/*
* Need page_t list, really only need
* a pfn list so build one.
*/
if (off)
pcnt++;
KM_NOSLEEP)) == NULL) {
goto cleanup;
}
while (pcnt-- > 0) {
}
} else {
/* Have a page_t list, save it */
locked->uioa_pfncnt = 0;
}
/* Save for as_pageunlock() in uioafini() */
locked++;
/* Next iovec_t */
iov++;
iovcnt--;
}
/* Initialize curret pointer into uioa_locked[] and it's uioa_ppp */
return (0);
/* Unlock any previously locked page_t(s) */
locked--;
}
/* Last indicate uioa_t still in alloc state */
uioap->uioa_mbytes = 0;
return (error);
}
/*
* Finish processing of a uioa_t by cleanup any pending "uioap" actions.
*/
int
{
int ret = 0;
/* Must be an active uioa_t */
return (EINVAL);
}
/* XXX - why do we get cmd == NULL sometimes? */
/* Wait for last dcopy() to finish */
int poll_flag = DCOPY_POLL_NOFLAGS;
do {
if (uioa_maxpoll == 0 ||
(uioa_maxpoll > 0 &&
poll >= uioa_maxpoll)) {
/* Always block or after maxpoll */
} else {
/* No block, poll */
poll++;
}
} while (ret == DCOPY_PENDING);
if (ret == DCOPY_COMPLETED) {
ret = 0;
} else {
}
}
}
/* Unlock all page(s) iovec_t by iovec_t */
while (iovcnt-- > 0) {
if (locked->uioa_pfncnt == 0) {
/* A as_pagelock() returned (page_t **) */
} else {
/* Our pfn_t array */
sizeof (pfn_t *));
}
S_WRITE);
locked++;
}
/* uioa_t->uio_t common struct copy */
/*
* Last, reset uioa state to alloc.
*
* Note, we only initialize the state here, all other members
* will be initialized in a subsequent uioainit().
*/
uioap->uioa_mbytes = 0;
return (ret);
}