xref: /titanic_52/usr/src/uts/common/sys/door_data.h (revision 96a62ada8aa6cb19b04270da282e7e21ba74b808)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DOOR_DATA_H
27 #define	_SYS_DOOR_DATA_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/door.h>
33 
34 #if defined(_KERNEL)
35 #include <sys/thread.h>
36 #include <sys/file.h>
37 #endif
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #if defined(_KERNEL)
44 /* door_return() stack layout */
45 typedef struct door_layout {
46 	caddr_t		dl_descp;	/* start of descriptors (or 0) */
47 	caddr_t		dl_datap;	/* start of data (or 0) */
48 	caddr_t		dl_infop;	/* start of door_info_t (or 0) */
49 	caddr_t		dl_resultsp;	/* start of door_results{32}_t */
50 	caddr_t		dl_sp;		/* final stack pointer (non-biased) */
51 } door_layout_t;
52 
53 /* upcall invocation information */
54 typedef struct door_upcall_data {
55 	cred_t		*du_cred;	/* Credential associated w/ upcall */
56 	size_t		du_max_data;	/* Maximum amount of reply data */
57 	uint_t		du_max_descs;	/* Maximum number of reply descs */
58 } door_upcall_t;
59 
60 /*
61  * Per-thread data associated with door invocations.  Each door invocation
62  * effects the client structure of one thread and the server structure of
63  * another.  This way, the server thread for one door_call() can make door
64  * calls of its own without interference.
65  */
66 typedef struct door_client {
67 	door_arg_t	d_args;		/* Door arg/results */
68 	door_upcall_t	*d_upcall;	/* upcall information */
69 	caddr_t		d_buf;		/* Temp buffer for data transfer */
70 	int		d_bufsize;	/* Size of temp buffer */
71 	int		d_fpp_size;	/* Number of File ptrs */
72 	struct file	**d_fpp;	/* File ptrs  */
73 	int		d_error;	/* Error (if any) */
74 	kcondvar_t	d_cv;
75 	uchar_t		d_args_done;	/* server has processed client's args */
76 	uchar_t		d_hold;		/* Thread needs to stick around */
77 	uchar_t		d_noresults;	/* No results allowed */
78 	uchar_t		d_overflow;	/* Result overflow occurred */
79 	uchar_t		d_kernel;	/* Kernel door server */
80 } door_client_t;
81 
82 typedef struct door_server {
83 	struct _kthread	*d_caller;	/* Door caller */
84 	struct _kthread *d_servers;	/* List of door servers */
85 	struct door_node *d_active;	/* Active door */
86 	struct door_node *d_pool;	/* our server thread pool */
87 	door_layout_t	d_layout;
88 	caddr_t		d_sp;		/* Saved thread stack base */
89 	size_t		d_ssize;	/* Saved thread stack size */
90 	kcondvar_t	d_cv;
91 	uchar_t		d_hold;		/* Thread needs to stick around */
92 	uchar_t		d_invbound;	/* Thread is bound to invalid door */
93 	uchar_t		d_layout_done;	/* d_layout has been filled */
94 } door_server_t;
95 
96 typedef struct door_data {
97 	door_client_t d_client;
98 	door_server_t d_server;
99 } door_data_t;
100 
101 #define	DOOR_CLIENT(dp) (&(dp)->d_client)
102 #define	DOOR_SERVER(dp) (&(dp)->d_server)
103 
104 /*
105  * Macros for holding a thread in place.  Takes a door_server_t or
106  * door_client_t pointer as an argument.
107  */
108 #define	DOOR_T_HELD(cst)	((cst)->d_hold)
109 
110 #define	DOOR_T_HOLD(cst) \
111 	(ASSERT(!DOOR_T_HELD(cst)), ((cst)->d_hold = 1))
112 #define	DOOR_T_RELEASE(cst) \
113 	(ASSERT(DOOR_T_HELD(cst)), ((cst)->d_hold = 0), \
114 	    cv_broadcast(&(cst)->d_cv))
115 
116 /*
117  * Roundup buffer size when passing/returning data via kernel buffer.
118  * This cuts down on the number of overflows that occur on return
119  */
120 #define	DOOR_ROUND	128
121 
122 #endif	/* defined(_KERNEL) */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _SYS_DOOR_DATA_H */
129