xref: /titanic_52/usr/src/uts/common/sys/door_data.h (revision 31925ed2254d4e4e9ce3632df5ee99a1d9b3294c)
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_hold;		/* Thread needs to stick around */
69 	uchar_t		d_upcall;	/* Kernel level upcall */
70 	uchar_t		d_noresults;	/* No results allowed */
71 	uchar_t		d_overflow;	/* Result overflow occurred */
72 	uchar_t		d_kernel;	/* Kernel door server */
73 } door_client_t;
74 
75 typedef struct door_server {
76 	struct _kthread	*d_caller;	/* Door caller */
77 	struct _kthread *d_servers;	/* List of door servers */
78 	struct door_node *d_active;	/* Active door */
79 	struct door_node *d_pool;	/* our server thread pool */
80 	door_layout_t	d_layout;
81 	caddr_t		d_sp;		/* Saved thread stack base */
82 	size_t		d_ssize;	/* Saved thread stack size */
83 	kcondvar_t	d_cv;
84 	uchar_t		d_hold;		/* Thread needs to stick around */
85 	uchar_t		d_invbound;	/* Thread is bound to invalid door */
86 	uchar_t		d_layout_done;	/* d_layout has been filled */
87 } door_server_t;
88 
89 typedef struct door_data {
90 	door_client_t d_client;
91 	door_server_t d_server;
92 } door_data_t;
93 
94 #define	DOOR_CLIENT(dp) (&(dp)->d_client)
95 #define	DOOR_SERVER(dp) (&(dp)->d_server)
96 
97 /*
98  * Macros for holding a thread in place.  Takes a door_server_t or
99  * door_client_t pointer as an argument.
100  */
101 #define	DOOR_T_HELD(cst)	((cst)->d_hold)
102 
103 #define	DOOR_T_HOLD(cst) \
104 	(ASSERT(!DOOR_T_HELD(cst)), ((cst)->d_hold = 1))
105 #define	DOOR_T_RELEASE(cst) \
106 	(ASSERT(DOOR_T_HELD(cst)), ((cst)->d_hold = 0), \
107 	    cv_broadcast(&(cst)->d_cv))
108 
109 /*
110  * Roundup buffer size when passing/returning data via kernel buffer.
111  * This cuts down on the number of overflows that occur on return
112  */
113 #define	DOOR_ROUND	128
114 
115 #endif	/* defined(_KERNEL) */
116 
117 #ifdef	__cplusplus
118 }
119 #endif
120 
121 #endif	/* _SYS_DOOR_DATA_H */
122