xref: /dragonfly/sys/sys/xio.h (revision 13dd34d8)
181ee925dSMatthew Dillon /*
28c10bfcfSMatthew Dillon  * Copyright (c) 2003,2004 The DragonFly Project.  All rights reserved.
38c10bfcfSMatthew Dillon  *
48c10bfcfSMatthew Dillon  * This code is derived from software contributed to The DragonFly Project
58c10bfcfSMatthew Dillon  * by Matthew Dillon <dillon@backplane.com>
681ee925dSMatthew Dillon  *
781ee925dSMatthew Dillon  * Redistribution and use in source and binary forms, with or without
881ee925dSMatthew Dillon  * modification, are permitted provided that the following conditions
981ee925dSMatthew Dillon  * are met:
108c10bfcfSMatthew Dillon  *
1181ee925dSMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
1281ee925dSMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
1381ee925dSMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
148c10bfcfSMatthew Dillon  *    notice, this list of conditions and the following disclaimer in
158c10bfcfSMatthew Dillon  *    the documentation and/or other materials provided with the
168c10bfcfSMatthew Dillon  *    distribution.
178c10bfcfSMatthew Dillon  * 3. Neither the name of The DragonFly Project nor the names of its
188c10bfcfSMatthew Dillon  *    contributors may be used to endorse or promote products derived
198c10bfcfSMatthew Dillon  *    from this software without specific, prior written permission.
2081ee925dSMatthew Dillon  *
218c10bfcfSMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
228c10bfcfSMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
238c10bfcfSMatthew Dillon  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
248c10bfcfSMatthew Dillon  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
258c10bfcfSMatthew Dillon  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
268c10bfcfSMatthew Dillon  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
278c10bfcfSMatthew Dillon  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
288c10bfcfSMatthew Dillon  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
298c10bfcfSMatthew Dillon  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
308c10bfcfSMatthew Dillon  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
318c10bfcfSMatthew Dillon  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3281ee925dSMatthew Dillon  * SUCH DAMAGE.
3381ee925dSMatthew Dillon  */
3481ee925dSMatthew Dillon 
3581ee925dSMatthew Dillon /*
3603aa69bdSMatthew Dillon  * An XIO holds a platform-agnostic page list representing a data set for
3703aa69bdSMatthew Dillon  * the purposes of I/O, mapping (SFBUF/MSFBUF), or other operations.  The
3803aa69bdSMatthew Dillon  * representation of the data set is byte aligned.  xio_offset and xio_bytes
3903aa69bdSMatthew Dillon  * specifies the precise byte-ranged block within the page list being
4003aa69bdSMatthew Dillon  * represented.
4103aa69bdSMatthew Dillon  *
4203aa69bdSMatthew Dillon  * XIOs do not track an ongoing I/O, they simply represent a block of data.
4303aa69bdSMatthew Dillon  * For this reason most XIO API functions have a 'uoffset' argument which
4403aa69bdSMatthew Dillon  * the caller may use to index within the represented dataset.  This index
4503aa69bdSMatthew Dillon  * is relative to the represented dataset, NOT to the beginning of the
4603aa69bdSMatthew Dillon  * first page.
4781ee925dSMatthew Dillon  */
4881ee925dSMatthew Dillon #ifndef _SYS_XIO_H_
4981ee925dSMatthew Dillon #define	_SYS_XIO_H_
5081ee925dSMatthew Dillon 
5181ee925dSMatthew Dillon #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
5281ee925dSMatthew Dillon 
531bd40720SMatthew Dillon #ifndef _SYS_TYPES_H_
541bd40720SMatthew Dillon #include <sys/types.h>
551bd40720SMatthew Dillon #endif
56*13dd34d8Szrj #ifndef _SYS__UIO_H_
57*13dd34d8Szrj #include <sys/_uio.h>
581bd40720SMatthew Dillon #endif
5981ee925dSMatthew Dillon #ifndef _SYS_MSGPORT_H_
6081ee925dSMatthew Dillon #include <sys/msgport.h>
6181ee925dSMatthew Dillon #endif
621bd40720SMatthew Dillon #ifndef _MACHINE_PARAM_H_
631bd40720SMatthew Dillon #include <machine/param.h>
641bd40720SMatthew Dillon #endif
6581ee925dSMatthew Dillon 
6681ee925dSMatthew Dillon #define XIO_INTERNAL_PAGES	btoc(MAXPHYS)
6781ee925dSMatthew Dillon #define XIO_INTERNAL_SIZE	(XIO_INTERNAL_PAGES * PAGE_SIZE)
6881ee925dSMatthew Dillon 
6981ee925dSMatthew Dillon struct vm_page;
7081ee925dSMatthew Dillon 
7181ee925dSMatthew Dillon struct xio {
7281ee925dSMatthew Dillon 	struct vm_page **xio_pages;
7381ee925dSMatthew Dillon 	int	xio_npages;	/* number of pages in xio_pages[] array */
7481ee925dSMatthew Dillon 	int	xio_offset;	/* byte offset (may exceed a page) */
7581ee925dSMatthew Dillon 	int	xio_bytes;	/* number of bytes to transfer */
7681ee925dSMatthew Dillon 	int	xio_flags;
7781ee925dSMatthew Dillon 	int	xio_error;
7881ee925dSMatthew Dillon 	struct vm_page *xio_internal_pages[XIO_INTERNAL_PAGES];
7981ee925dSMatthew Dillon };
8081ee925dSMatthew Dillon 
8181ee925dSMatthew Dillon typedef struct xio *xio_t;
8281ee925dSMatthew Dillon 
8381ee925dSMatthew Dillon #define XIOF_READ	0x0001
8481ee925dSMatthew Dillon #define XIOF_WRITE	0x0002
85c4734fe7SMatthew Dillon #define XIOF_VMLINEAR	0x0004	/* must be VM object linear */
8681ee925dSMatthew Dillon 
8781ee925dSMatthew Dillon #endif
8881ee925dSMatthew Dillon 
8981ee925dSMatthew Dillon #if defined(_KERNEL)
9081ee925dSMatthew Dillon 
9152c90fbcSMatthew Dillon void xio_init(xio_t xio);
9281ee925dSMatthew Dillon int xio_init_kbuf(xio_t xio, void *kbase, size_t kbytes);
9383269e7dSMatthew Dillon int xio_init_pages(xio_t xio, struct vm_page **mbase, int npages, int xflags);
9481ee925dSMatthew Dillon void xio_release(xio_t xio);
95e54488bbSMatthew Dillon int xio_uio_copy(xio_t xio, int uoffset, struct uio *uio, size_t *sizep);
9603aa69bdSMatthew Dillon int xio_copy_xtou(xio_t xio, int uoffset, void *uptr, int bytes);
9703aa69bdSMatthew Dillon int xio_copy_xtok(xio_t xio, int uoffset, void *kptr, int bytes);
980a7648b9SMatthew Dillon int xio_copy_utox(xio_t xio, int uoffset, const void *uptr, int bytes);
990a7648b9SMatthew Dillon int xio_copy_ktox(xio_t xio, int uoffset, const void *kptr, int bytes);
10003aa69bdSMatthew Dillon 
10103aa69bdSMatthew Dillon /*
10203aa69bdSMatthew Dillon  * XIOs are not modified by copy operations, the caller must track the
10303aa69bdSMatthew Dillon  * offset itself.  This routine will return the number of bytes remaining
10403aa69bdSMatthew Dillon  * in an XIO's buffer given an offset relative to the buffer used to
10503aa69bdSMatthew Dillon  * originally construct the XIO.
10603aa69bdSMatthew Dillon  */
10703aa69bdSMatthew Dillon static __inline
10803aa69bdSMatthew Dillon int
xio_remaining(xio_t xio,int uoffset)10903aa69bdSMatthew Dillon xio_remaining(xio_t xio, int uoffset)
11003aa69bdSMatthew Dillon {
11103aa69bdSMatthew Dillon 	return(xio->xio_bytes - uoffset);
11203aa69bdSMatthew Dillon }
11303aa69bdSMatthew Dillon 
11403aa69bdSMatthew Dillon /*
11503aa69bdSMatthew Dillon  * XIOs do not map data but if the page list WERE mapped, this routine will
11603aa69bdSMatthew Dillon  * return the actual KVA offset given a user offset relative to the original
11703aa69bdSMatthew Dillon  * buffer used to construct the XIO.
11803aa69bdSMatthew Dillon  */
11903aa69bdSMatthew Dillon static __inline
12003aa69bdSMatthew Dillon int
xio_kvaoffset(xio_t xio,int uoffset)12103aa69bdSMatthew Dillon xio_kvaoffset(xio_t xio, int uoffset)
12203aa69bdSMatthew Dillon {
12303aa69bdSMatthew Dillon 	return(xio->xio_offset + uoffset);
12403aa69bdSMatthew Dillon }
12581ee925dSMatthew Dillon 
12681ee925dSMatthew Dillon #endif /* _KERNEL */
12781ee925dSMatthew Dillon 
128693cbfd3SJoerg Sonnenberger #endif /* !_SYS_XIO_H_ */
129