xref: /titanic_52/usr/src/uts/common/sys/door_data.h (revision 020c47705d28102a8df83a43ddf08e34dde21f22)
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 /*
54  * Per-thread data associated with door invocations.  Each door invocation
55  * effects the client structure of one thread and the server structure of
56  * another.  This way, the server thread for one door_call() can make door
57  * calls of its own without interference.
58  */
59 typedef struct door_client {
60 	door_arg_t	d_args;		/* Door arg/results */
61 	struct cred	*d_cred;	/* Cred overridden by the client */
62 	caddr_t		d_buf;		/* Temp buffer for data transfer */
63 	int		d_bufsize;	/* Size of temp buffer */
64 	int		d_fpp_size;	/* Number of File ptrs */
65 	struct file	**d_fpp;	/* File ptrs  */
66 	int		d_error;	/* Error (if any) */
67 	kcondvar_t	d_cv;
68 	uchar_t		d_args_done;	/* server has processed client's args */
69 	uchar_t		d_hold;		/* Thread needs to stick around */
70 	uchar_t		d_upcall;	/* Kernel level upcall */
71 	uchar_t		d_noresults;	/* No results allowed */
72 	uchar_t		d_overflow;	/* Result overflow occurred */
73 	uchar_t		d_kernel;	/* Kernel door server */
74 } door_client_t;
75 
76 typedef struct door_server {
77 	struct _kthread	*d_caller;	/* Door caller */
78 	struct _kthread *d_servers;	/* List of door servers */
79 	struct door_node *d_active;	/* Active door */
80 	struct door_node *d_pool;	/* our server thread pool */
81 	door_layout_t	d_layout;
82 	caddr_t		d_sp;		/* Saved thread stack base */
83 	size_t		d_ssize;	/* Saved thread stack size */
84 	kcondvar_t	d_cv;
85 	uchar_t		d_hold;		/* Thread needs to stick around */
86 	uchar_t		d_invbound;	/* Thread is bound to invalid door */
87 	uchar_t		d_layout_done;	/* d_layout has been filled */
88 } door_server_t;
89 
90 typedef struct door_data {
91 	door_client_t d_client;
92 	door_server_t d_server;
93 } door_data_t;
94 
95 #define	DOOR_CLIENT(dp) (&(dp)->d_client)
96 #define	DOOR_SERVER(dp) (&(dp)->d_server)
97 
98 /*
99  * Macros for holding a thread in place.  Takes a door_server_t or
100  * door_client_t pointer as an argument.
101  */
102 #define	DOOR_T_HELD(cst)	((cst)->d_hold)
103 
104 #define	DOOR_T_HOLD(cst) \
105 	(ASSERT(!DOOR_T_HELD(cst)), ((cst)->d_hold = 1))
106 #define	DOOR_T_RELEASE(cst) \
107 	(ASSERT(DOOR_T_HELD(cst)), ((cst)->d_hold = 0), \
108 	    cv_broadcast(&(cst)->d_cv))
109 
110 /*
111  * Roundup buffer size when passing/returning data via kernel buffer.
112  * This cuts down on the number of overflows that occur on return
113  */
114 #define	DOOR_ROUND	128
115 
116 #endif	/* defined(_KERNEL) */
117 
118 #ifdef	__cplusplus
119 }
120 #endif
121 
122 #endif	/* _SYS_DOOR_DATA_H */
123