xref: /onnv-gate/usr/src/uts/common/sys/port_kernel.h (revision 4863:7b14ad153d91)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51885Sraf  * Common Development and Distribution License (the "License").
61885Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211885Sraf 
220Sstevel@tonic-gate /*
23*4863Spraks  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_PORT_KERNEL_H
280Sstevel@tonic-gate #define	_SYS_PORT_KERNEL_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/vnode.h>
330Sstevel@tonic-gate #include <sys/list.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef	__cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * Note:
410Sstevel@tonic-gate  * The contents of this file are private to the implementation of the
420Sstevel@tonic-gate  * Solaris system and event ports subsystem and are subject to change
430Sstevel@tonic-gate  * at any time without notice.
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #ifdef _KERNEL
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * The port_kevent_t struct represents the kernel internal port event.
500Sstevel@tonic-gate  * Every event is associated to a port (portkev_port).
510Sstevel@tonic-gate  */
520Sstevel@tonic-gate typedef	struct	port_kevent {
531425Spraks 	kmutex_t	portkev_lock;	/* used by PORT_SOURCE_FD source */
540Sstevel@tonic-gate 	int	portkev_source;		/* event: source */
550Sstevel@tonic-gate 	int	portkev_events; 	/* event: data */
560Sstevel@tonic-gate 	int	portkev_flags;		/* internal flags */
570Sstevel@tonic-gate 	pid_t	portkev_pid;		/* pid of process using this struct */
580Sstevel@tonic-gate 	long	portkev_object;		/* event: object */
590Sstevel@tonic-gate 	void	*portkev_user;		/* event: user-defined value */
600Sstevel@tonic-gate 	int	(*portkev_callback)(void *, int *, pid_t, int, void *);
610Sstevel@tonic-gate 	void	*portkev_arg;		/* event source callback arg */
620Sstevel@tonic-gate 	struct	port *portkev_port;	/* associated port */
630Sstevel@tonic-gate 	list_node_t portkev_node;	/* pointer to neighbor events */
640Sstevel@tonic-gate } port_kevent_t;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /* portkev_flags */
670Sstevel@tonic-gate #define	PORT_KEV_PRIVATE	0x01	/* subsystem private, don't free */
680Sstevel@tonic-gate #define	PORT_KEV_CACHED		0x02	/* port local cached, don't free */
690Sstevel@tonic-gate #define	PORT_KEV_SCACHED	0x04	/* source local cached, don't free */
700Sstevel@tonic-gate #define	PORT_KEV_VALID		0x08	/* event associated and enabled */
710Sstevel@tonic-gate #define	PORT_KEV_DONEQ		0x10	/* event is in done queue */
720Sstevel@tonic-gate #define	PORT_KEV_FREE		0x20	/* free event and don't copyout it */
730Sstevel@tonic-gate #define	PORT_KEV_NOSHARE	0x40	/* non-shareable across processes */
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /* flags : port_alloc_event() */
760Sstevel@tonic-gate #define	PORT_ALLOC_DEFAULT	0
770Sstevel@tonic-gate #define	PORT_ALLOC_PRIVATE	PORT_KEV_PRIVATE
780Sstevel@tonic-gate #define	PORT_ALLOC_CACHED	PORT_KEV_CACHED
790Sstevel@tonic-gate #define	PORT_ALLOC_SCACHED	PORT_KEV_SCACHED
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /* flags : callback function */
820Sstevel@tonic-gate #define	PORT_CALLBACK_DEFAULT	0	/* free resources, event delivery */
830Sstevel@tonic-gate #define	PORT_CALLBACK_CLOSE	1	/* free resources, don't copyout */
840Sstevel@tonic-gate #define	PORT_CALLBACK_DISSOCIATE 2	/* dissociate object */
850Sstevel@tonic-gate 
860Sstevel@tonic-gate #define	PORT_DEFAULT_PORTS	0x02000
870Sstevel@tonic-gate #define	PORT_MAX_PORTS		0x10000
880Sstevel@tonic-gate #define	PORT_DEFAULT_EVENTS	0x10000	/* default # of events per port */
890Sstevel@tonic-gate #define	PORT_MAX_EVENTS		UINT_MAX/2 /* max. # of events per port */
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate  * port_source_t represents a source associated with a port.
930Sstevel@tonic-gate  * The portsrc_close() function is required to notify the source when
940Sstevel@tonic-gate  * a port is closed.
950Sstevel@tonic-gate  */
960Sstevel@tonic-gate typedef struct port_source {
970Sstevel@tonic-gate 	int	portsrc_source;
980Sstevel@tonic-gate 	int	portsrc_cnt;		/* # of associations */
990Sstevel@tonic-gate 	void	(*portsrc_close)(void *, int, pid_t, int);
1000Sstevel@tonic-gate 	void	*portsrc_closearg;	/* callback arg */
101*4863Spraks 	void	*portsrc_data;		/* Private data of source */
1020Sstevel@tonic-gate 	struct port_source *portsrc_next;
1030Sstevel@tonic-gate 	struct port_source *portsrc_prev;
1040Sstevel@tonic-gate } port_source_t;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate /*
108*4863Spraks  * PORT_SOURCE_FILE cache structure.
109*4863Spraks  */
110*4863Spraks #define	PORTFOP_HASHSIZE	256	/* cache space for fop events */
111*4863Spraks 
112*4863Spraks /*
113*4863Spraks  * One cache for each port that uses PORT_SOURCE_FILE.
114*4863Spraks  */
115*4863Spraks typedef struct portfop_cache {
116*4863Spraks 	kmutex_t	pfc_lock;	/* lock to protect cache */
117*4863Spraks 	kcondvar_t	pfc_lclosecv;	/* last close cv */
118*4863Spraks 	int		pfc_objcount;	/* track how many file obj are hashed */
119*4863Spraks 	struct portfop	*pfc_hash[PORTFOP_HASHSIZE]; /* hash table */
120*4863Spraks } portfop_cache_t;
121*4863Spraks 
122*4863Spraks /*
123*4863Spraks  * PORT_SOURCE_FD cache per port.
1240Sstevel@tonic-gate  * One cache for each port that uses PORT_SOURCE_FD.
1250Sstevel@tonic-gate  * pc_lock must be the first element of port_fdcache_t to keep it
1260Sstevel@tonic-gate  * synchronized with the offset of pc_lock in pollcache_t (see pollrelock()).
1270Sstevel@tonic-gate  */
1280Sstevel@tonic-gate typedef struct port_fdcache {
1290Sstevel@tonic-gate 	kmutex_t	pc_lock;	/* lock to protect portcache */
1301425Spraks 	kcondvar_t	pc_lclosecv;
1310Sstevel@tonic-gate 	struct portfd	**pc_hash;	/* points to a hash table of ptrs */
1320Sstevel@tonic-gate 	int		pc_hashsize;	/* the size of current hash table */
1330Sstevel@tonic-gate 	int		pc_fdcount;	/* track how many fd's are hashed */
1340Sstevel@tonic-gate } port_fdcache_t;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate  * Structure of port_ksource_tab[] table.
1380Sstevel@tonic-gate  * The port_ksource_tab[] is required to allow kernel sources to become
1390Sstevel@tonic-gate  * associated with a port at the time of port creation. This feature is
1400Sstevel@tonic-gate  * required to avoid performance degradation in sub-systems, specially when
1410Sstevel@tonic-gate  * they should need to check the association on every event activity.
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate typedef	struct	port_ksource {
1440Sstevel@tonic-gate 	int	pks_source;
1450Sstevel@tonic-gate 	void	(*pks_close)(void *, int, pid_t, int);
1460Sstevel@tonic-gate 	void	*pks_closearg;
1470Sstevel@tonic-gate 	void	*pks_portsrc;
1480Sstevel@tonic-gate } port_ksource_t;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /* event port and source management */
1510Sstevel@tonic-gate int	port_associate_ksource(int, int, struct port_source **,
1520Sstevel@tonic-gate     void (*)(void *, int, pid_t, int), void *arg,
1530Sstevel@tonic-gate     int (*)(port_kevent_t *, int, int, uintptr_t, void *));
1540Sstevel@tonic-gate int	port_dissociate_ksource(int, int, struct port_source *);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate /* event management */
1570Sstevel@tonic-gate int	port_alloc_event(int, int, int, port_kevent_t **);
1582948Spraks int	port_pollwkup(struct port *);
1592948Spraks void	port_pollwkdone(struct port *);
1601885Sraf void	port_send_event(port_kevent_t *);
1610Sstevel@tonic-gate void	port_free_event(port_kevent_t *);
1620Sstevel@tonic-gate void	port_init_event(port_kevent_t *, uintptr_t, void *,
1630Sstevel@tonic-gate     int (*)(void *, int *, pid_t, int, void *), void *);
1640Sstevel@tonic-gate int	port_dup_event(port_kevent_t *, port_kevent_t **, int);
1650Sstevel@tonic-gate int	port_associate_fd(struct port *, int, uintptr_t, int, void *);
1660Sstevel@tonic-gate int	port_dissociate_fd(struct port *, uintptr_t);
167*4863Spraks int	port_associate_fop(struct port *, int, uintptr_t, int, void *);
168*4863Spraks int	port_dissociate_fop(struct port *, uintptr_t);
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /* misc functions */
1710Sstevel@tonic-gate void	port_free_event_local(port_kevent_t *, int counter);
1720Sstevel@tonic-gate int	port_alloc_event_local(struct port *, int, int, port_kevent_t **);
1730Sstevel@tonic-gate void	port_close_pfd(struct portfd *);
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate #endif	/* _KERNEL */
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate #ifdef	__cplusplus
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate #endif
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate #endif	/* _SYS_PORT_KERNEL_H */
182