xref: /titanic_50/usr/src/uts/common/sys/door_data.h (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_DOOR_DATA_H
28 #define	_SYS_DOOR_DATA_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/door.h>
34 
35 #if defined(_KERNEL)
36 #include <sys/thread.h>
37 #include <sys/file.h>
38 #endif
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 #if defined(_KERNEL)
45 /* door_return() stack layout */
46 typedef struct door_layout {
47 	caddr_t		dl_descp;	/* start of descriptors (or 0) */
48 	caddr_t		dl_datap;	/* start of data (or 0) */
49 	caddr_t		dl_infop;	/* start of door_info_t (or 0) */
50 	caddr_t		dl_resultsp;	/* start of door_results{32}_t */
51 	caddr_t		dl_sp;		/* final stack pointer (non-biased) */
52 } door_layout_t;
53 
54 /*
55  * Per-thread data associated with door invocations.  Each door invocation
56  * effects the client structure of one thread and the server structure of
57  * another.  This way, the server thread for one door_call() can make door
58  * calls of its own without interference.
59  */
60 typedef struct door_client {
61 	door_arg_t	d_args;		/* Door arg/results */
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