xref: /illumos-gate/usr/src/uts/common/sys/door_data.h (revision 2d6eb4a5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5024b0a25Sseb  * Common Development and Distribution License (the "License").
6024b0a25Sseb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22024b0a25Sseb  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_DOOR_DATA_H
277c478bd9Sstevel@tonic-gate #define	_SYS_DOOR_DATA_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/door.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
337c478bd9Sstevel@tonic-gate #include <sys/thread.h>
347c478bd9Sstevel@tonic-gate #include <sys/file.h>
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
427c478bd9Sstevel@tonic-gate /* door_return() stack layout */
437c478bd9Sstevel@tonic-gate typedef struct door_layout {
447c478bd9Sstevel@tonic-gate 	caddr_t		dl_descp;	/* start of descriptors (or 0) */
457c478bd9Sstevel@tonic-gate 	caddr_t		dl_datap;	/* start of data (or 0) */
467c478bd9Sstevel@tonic-gate 	caddr_t		dl_infop;	/* start of door_info_t (or 0) */
477c478bd9Sstevel@tonic-gate 	caddr_t		dl_resultsp;	/* start of door_results{32}_t */
487c478bd9Sstevel@tonic-gate 	caddr_t		dl_sp;		/* final stack pointer (non-biased) */
497c478bd9Sstevel@tonic-gate } door_layout_t;
507c478bd9Sstevel@tonic-gate 
51*323a81d9Sjwadams /* upcall invocation information */
52*323a81d9Sjwadams typedef struct door_upcall_data {
53*323a81d9Sjwadams 	cred_t		*du_cred;	/* Credential associated w/ upcall */
54*323a81d9Sjwadams 	size_t		du_max_data;	/* Maximum amount of reply data */
55*323a81d9Sjwadams 	uint_t		du_max_descs;	/* Maximum number of reply descs */
56*323a81d9Sjwadams } door_upcall_t;
57*323a81d9Sjwadams 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * Per-thread data associated with door invocations.  Each door invocation
607c478bd9Sstevel@tonic-gate  * effects the client structure of one thread and the server structure of
617c478bd9Sstevel@tonic-gate  * another.  This way, the server thread for one door_call() can make door
627c478bd9Sstevel@tonic-gate  * calls of its own without interference.
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate typedef struct door_client {
657c478bd9Sstevel@tonic-gate 	door_arg_t	d_args;		/* Door arg/results */
66*323a81d9Sjwadams 	door_upcall_t	*d_upcall;	/* upcall information */
677c478bd9Sstevel@tonic-gate 	caddr_t		d_buf;		/* Temp buffer for data transfer */
687c478bd9Sstevel@tonic-gate 	int		d_bufsize;	/* Size of temp buffer */
697c478bd9Sstevel@tonic-gate 	int		d_fpp_size;	/* Number of File ptrs */
707c478bd9Sstevel@tonic-gate 	struct file	**d_fpp;	/* File ptrs  */
717c478bd9Sstevel@tonic-gate 	int		d_error;	/* Error (if any) */
727c478bd9Sstevel@tonic-gate 	kcondvar_t	d_cv;
73289175a0Sjwadams 	uchar_t		d_args_done;	/* server has processed client's args */
747c478bd9Sstevel@tonic-gate 	uchar_t		d_hold;		/* Thread needs to stick around */
757c478bd9Sstevel@tonic-gate 	uchar_t		d_noresults;	/* No results allowed */
767c478bd9Sstevel@tonic-gate 	uchar_t		d_overflow;	/* Result overflow occurred */
777c478bd9Sstevel@tonic-gate 	uchar_t		d_kernel;	/* Kernel door server */
787c478bd9Sstevel@tonic-gate } door_client_t;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate typedef struct door_server {
817c478bd9Sstevel@tonic-gate 	struct _kthread	*d_caller;	/* Door caller */
827c478bd9Sstevel@tonic-gate 	struct _kthread *d_servers;	/* List of door servers */
837c478bd9Sstevel@tonic-gate 	struct door_node *d_active;	/* Active door */
847c478bd9Sstevel@tonic-gate 	struct door_node *d_pool;	/* our server thread pool */
857c478bd9Sstevel@tonic-gate 	door_layout_t	d_layout;
867c478bd9Sstevel@tonic-gate 	caddr_t		d_sp;		/* Saved thread stack base */
877c478bd9Sstevel@tonic-gate 	size_t		d_ssize;	/* Saved thread stack size */
887c478bd9Sstevel@tonic-gate 	kcondvar_t	d_cv;
897c478bd9Sstevel@tonic-gate 	uchar_t		d_hold;		/* Thread needs to stick around */
907c478bd9Sstevel@tonic-gate 	uchar_t		d_invbound;	/* Thread is bound to invalid door */
917c478bd9Sstevel@tonic-gate 	uchar_t		d_layout_done;	/* d_layout has been filled */
927c478bd9Sstevel@tonic-gate } door_server_t;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate typedef struct door_data {
957c478bd9Sstevel@tonic-gate 	door_client_t d_client;
967c478bd9Sstevel@tonic-gate 	door_server_t d_server;
977c478bd9Sstevel@tonic-gate } door_data_t;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	DOOR_CLIENT(dp) (&(dp)->d_client)
1007c478bd9Sstevel@tonic-gate #define	DOOR_SERVER(dp) (&(dp)->d_server)
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Macros for holding a thread in place.  Takes a door_server_t or
1047c478bd9Sstevel@tonic-gate  * door_client_t pointer as an argument.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate #define	DOOR_T_HELD(cst)	((cst)->d_hold)
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	DOOR_T_HOLD(cst) \
1097c478bd9Sstevel@tonic-gate 	(ASSERT(!DOOR_T_HELD(cst)), ((cst)->d_hold = 1))
1107c478bd9Sstevel@tonic-gate #define	DOOR_T_RELEASE(cst) \
1117c478bd9Sstevel@tonic-gate 	(ASSERT(DOOR_T_HELD(cst)), ((cst)->d_hold = 0), \
1127c478bd9Sstevel@tonic-gate 	    cv_broadcast(&(cst)->d_cv))
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * Roundup buffer size when passing/returning data via kernel buffer.
1167c478bd9Sstevel@tonic-gate  * This cuts down on the number of overflows that occur on return
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate #define	DOOR_ROUND	128
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate #endif
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #endif	/* _SYS_DOOR_DATA_H */
127