xref: /titanic_52/usr/src/uts/common/sys/port_kernel.h (revision d04ccbb3f3163ae5962a8b7465d9796bff6ca434)
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 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_PORT_KERNEL_H
28 #define	_SYS_PORT_KERNEL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/vnode.h>
33 #include <sys/list.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Note:
41  * The contents of this file are private to the implementation of the
42  * Solaris system and event ports subsystem and are subject to change
43  * at any time without notice.
44  */
45 
46 #ifdef _KERNEL
47 
48 /*
49  * The port_kevent_t struct represents the kernel internal port event.
50  * Every event is associated to a port (portkev_port).
51  */
52 typedef	struct	port_kevent {
53 	kmutex_t	portkev_lock;	/* used by PORT_SOURCE_FD source */
54 	int	portkev_source;		/* event: source */
55 	int	portkev_events; 	/* event: data */
56 	int	portkev_flags;		/* internal flags */
57 	pid_t	portkev_pid;		/* pid of process using this struct */
58 	long	portkev_object;		/* event: object */
59 	void	*portkev_user;		/* event: user-defined value */
60 	int	(*portkev_callback)(void *, int *, pid_t, int, void *);
61 	void	*portkev_arg;		/* event source callback arg */
62 	struct	port *portkev_port;	/* associated port */
63 	list_node_t portkev_node;	/* pointer to neighbor events */
64 } port_kevent_t;
65 
66 /* portkev_flags */
67 #define	PORT_KEV_PRIVATE	0x01	/* subsystem private, don't free */
68 #define	PORT_KEV_CACHED		0x02	/* port local cached, don't free */
69 #define	PORT_KEV_SCACHED	0x04	/* source local cached, don't free */
70 #define	PORT_KEV_VALID		0x08	/* event associated and enabled */
71 #define	PORT_KEV_DONEQ		0x10	/* event is in done queue */
72 #define	PORT_KEV_FREE		0x20	/* free event and don't copyout it */
73 #define	PORT_KEV_NOSHARE	0x40	/* non-shareable across processes */
74 
75 /* flags : port_alloc_event() */
76 #define	PORT_ALLOC_DEFAULT	0
77 #define	PORT_ALLOC_PRIVATE	PORT_KEV_PRIVATE
78 #define	PORT_ALLOC_CACHED	PORT_KEV_CACHED
79 #define	PORT_ALLOC_SCACHED	PORT_KEV_SCACHED
80 
81 /* flags : callback function */
82 #define	PORT_CALLBACK_DEFAULT	0	/* free resources, event delivery */
83 #define	PORT_CALLBACK_CLOSE	1	/* free resources, don't copyout */
84 #define	PORT_CALLBACK_DISSOCIATE 2	/* dissociate object */
85 
86 #define	PORT_DEFAULT_PORTS	0x02000
87 #define	PORT_MAX_PORTS		0x10000
88 #define	PORT_DEFAULT_EVENTS	0x10000	/* default # of events per port */
89 #define	PORT_MAX_EVENTS		UINT_MAX/2 /* max. # of events per port */
90 
91 /*
92  * port_source_t represents a source associated with a port.
93  * The portsrc_close() function is required to notify the source when
94  * a port is closed.
95  */
96 typedef struct port_source {
97 	int	portsrc_source;
98 	int	portsrc_cnt;		/* # of associations */
99 	void	(*portsrc_close)(void *, int, pid_t, int);
100 	void	*portsrc_closearg;	/* callback arg */
101 	struct port_source *portsrc_next;
102 	struct port_source *portsrc_prev;
103 } port_source_t;
104 
105 
106 /*
107  * One cache for each port that uses PORT_SOURCE_FD.
108  * pc_lock must be the first element of port_fdcache_t to keep it
109  * synchronized with the offset of pc_lock in pollcache_t (see pollrelock()).
110  */
111 typedef struct port_fdcache {
112 	kmutex_t	pc_lock;	/* lock to protect portcache */
113 	kcondvar_t	pc_lclosecv;
114 	struct portfd	**pc_hash;	/* points to a hash table of ptrs */
115 	int		pc_hashsize;	/* the size of current hash table */
116 	int		pc_fdcount;	/* track how many fd's are hashed */
117 } port_fdcache_t;
118 
119 /*
120  * Structure of port_ksource_tab[] table.
121  * The port_ksource_tab[] is required to allow kernel sources to become
122  * associated with a port at the time of port creation. This feature is
123  * required to avoid performance degradation in sub-systems, specially when
124  * they should need to check the association on every event activity.
125  */
126 typedef	struct	port_ksource {
127 	int	pks_source;
128 	void	(*pks_close)(void *, int, pid_t, int);
129 	void	*pks_closearg;
130 	void	*pks_portsrc;
131 } port_ksource_t;
132 
133 /* event port and source management */
134 int	port_associate_ksource(int, int, struct port_source **,
135     void (*)(void *, int, pid_t, int), void *arg,
136     int (*)(port_kevent_t *, int, int, uintptr_t, void *));
137 int	port_dissociate_ksource(int, int, struct port_source *);
138 
139 /* event management */
140 int	port_alloc_event(int, int, int, port_kevent_t **);
141 int	port_pollwkup(struct port *);
142 void	port_pollwkdone(struct port *);
143 void	port_send_event(port_kevent_t *);
144 void	port_free_event(port_kevent_t *);
145 void	port_init_event(port_kevent_t *, uintptr_t, void *,
146     int (*)(void *, int *, pid_t, int, void *), void *);
147 int	port_dup_event(port_kevent_t *, port_kevent_t **, int);
148 int	port_associate_fd(struct port *, int, uintptr_t, int, void *);
149 int	port_dissociate_fd(struct port *, uintptr_t);
150 
151 /* misc functions */
152 void	port_free_event_local(port_kevent_t *, int counter);
153 int	port_alloc_event_local(struct port *, int, int, port_kevent_t **);
154 void	port_close_pfd(struct portfd *);
155 
156 #endif	/* _KERNEL */
157 
158 #ifdef	__cplusplus
159 }
160 #endif
161 
162 #endif	/* _SYS_PORT_KERNEL_H */
163