xref: /illumos-gate/usr/src/uts/common/sys/copyops.h (revision fafb665d337b69015870e0bcdb516fd2f869693f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_COPYOPS_H
28 #define	_SYS_COPYOPS_H
29 
30 #include <sys/types.h>
31 #include <sys/thread.h>
32 #include <sys/buf.h>
33 #include <sys/aio_req.h>
34 #include <sys/uio.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 /*
43  * Copy in/out vector operations.  This structure is used to interpose
44  * on the kernel copyin/copyout/etc. operations for various purposes
45  * such as handling watchpoints in the affected user memory.  When one of the
46  * copy operations causes a fault, the corresponding function in this vector is
47  * called to handle it.
48  *
49  * The 64-bit operations in the structure fetch and store extended
50  * words and are only used on platforms with 64 bit general
51  * registers e.g. sun4u.
52  *
53  * Since the only users of these interfaces (watchpoints and pxfs) perform the
54  * default action unless there is a page fault, we can save the overhead of
55  * having to go through this indirection unless there is a page fault.  This
56  * improves performance both in general and when watchpoints are enabled.  If,
57  * in the future, a consumer relies on being able to interpose on all actions,
58  * then this assumption will have to be undone.
59  *
60  * No consumers should call these functions directly.  They are automatically
61  * handled by the generic versions.
62  */
63 typedef struct copyops {
64 	/*
65 	 * unstructured byte copyin/out functions
66 	 */
67 	int	(*cp_copyin)(const void *, void *, size_t);
68 	int	(*cp_xcopyin)(const void *, void *, size_t);
69 	int	(*cp_copyout)(const void *, void *, size_t);
70 	int	(*cp_xcopyout)(const void *, void *, size_t);
71 	int	(*cp_copyinstr)(const char *, char *, size_t, size_t *);
72 	int	(*cp_copyoutstr)(const char *, char *, size_t, size_t *);
73 
74 	/*
75 	 * fetch/store byte/halfword/word/extended word
76 	 */
77 	int	(*cp_fuword8)(const void *, uint8_t *);
78 	int	(*cp_fuword16)(const void *, uint16_t *);
79 	int	(*cp_fuword32)(const void *, uint32_t *);
80 	int	(*cp_fuword64)(const void *, uint64_t *);
81 
82 	int	(*cp_suword8)(void *, uint8_t);
83 	int	(*cp_suword16)(void *, uint16_t);
84 	int	(*cp_suword32)(void *, uint32_t);
85 	int	(*cp_suword64)(void *, uint64_t);
86 
87 	int	(*cp_physio)(int (*)(struct buf *), struct buf *, dev_t,
88 	    int, void (*)(struct buf *), struct uio *);
89 } copyops_t;
90 
91 extern int	default_physio(int (*)(struct buf *), struct buf *,
92     dev_t, int, void (*)(struct buf *), struct uio *);
93 
94 /*
95  * Interfaces for installing and removing copyops.
96  */
97 extern void install_copyops(kthread_id_t tp, copyops_t *cp);
98 extern void remove_copyops(kthread_id_t tp);
99 extern int copyops_installed(kthread_id_t tp);
100 
101 #endif	/* _KERNEL */
102 
103 #ifdef	__cplusplus
104 }
105 #endif
106 
107 #endif /* _SYS_COPYOPS_H */
108