xref: /titanic_44/usr/src/uts/common/sys/port_kernel.h (revision 749f21d359d8fbd020c974a1a5227316221bfc9c)
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 2004 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 	int	portkev_source;		/* event: source */
54 	int	portkev_events; 	/* event: data */
55 	int	portkev_flags;		/* internal flags */
56 	pid_t	portkev_pid;		/* pid of process using this struct */
57 	long	portkev_object;		/* event: object */
58 	void	*portkev_user;		/* event: user-defined value */
59 	int	(*portkev_callback)(void *, int *, pid_t, int, void *);
60 	void	*portkev_arg;		/* event source callback arg */
61 	struct	port *portkev_port;	/* associated port */
62 	list_node_t portkev_node;	/* pointer to neighbor events */
63 } port_kevent_t;
64 
65 /* portkev_flags */
66 #define	PORT_KEV_PRIVATE	0x01	/* subsystem private, don't free */
67 #define	PORT_KEV_CACHED		0x02	/* port local cached, don't free */
68 #define	PORT_KEV_SCACHED	0x04	/* source local cached, don't free */
69 #define	PORT_KEV_VALID		0x08	/* event associated and enabled */
70 #define	PORT_KEV_DONEQ		0x10	/* event is in done queue */
71 #define	PORT_KEV_FREE		0x20	/* free event and don't copyout it */
72 #define	PORT_KEV_NOSHARE	0x40	/* non-shareable across processes */
73 
74 /* flags : port_alloc_event() */
75 #define	PORT_ALLOC_DEFAULT	0
76 #define	PORT_ALLOC_PRIVATE	PORT_KEV_PRIVATE
77 #define	PORT_ALLOC_CACHED	PORT_KEV_CACHED
78 #define	PORT_ALLOC_SCACHED	PORT_KEV_SCACHED
79 
80 /* flags : callback function */
81 #define	PORT_CALLBACK_DEFAULT	0	/* free resources, event delivery */
82 #define	PORT_CALLBACK_CLOSE	1	/* free resources, don't copyout */
83 #define	PORT_CALLBACK_DISSOCIATE 2	/* dissociate object */
84 
85 #define	PORT_DEFAULT_PORTS	0x02000
86 #define	PORT_MAX_PORTS		0x10000
87 #define	PORT_DEFAULT_EVENTS	0x10000	/* default # of events per port */
88 #define	PORT_MAX_EVENTS		UINT_MAX/2 /* max. # of events per port */
89 
90 /*
91  * port_source_t represents a source associated with a port.
92  * The portsrc_close() function is required to notify the source when
93  * a port is closed.
94  */
95 typedef struct port_source {
96 	int	portsrc_source;
97 	int	portsrc_cnt;		/* # of associations */
98 	void	(*portsrc_close)(void *, int, pid_t, int);
99 	void	*portsrc_closearg;	/* callback arg */
100 	struct port_source *portsrc_next;
101 	struct port_source *portsrc_prev;
102 } port_source_t;
103 
104 
105 /*
106  * One cache for each port that uses PORT_SOURCE_FD.
107  * pc_lock must be the first element of port_fdcache_t to keep it
108  * synchronized with the offset of pc_lock in pollcache_t (see pollrelock()).
109  */
110 typedef struct port_fdcache {
111 	kmutex_t	pc_lock;	/* lock to protect portcache */
112 	struct portfd	**pc_hash;	/* points to a hash table of ptrs */
113 	int		pc_hashsize;	/* the size of current hash table */
114 	int		pc_fdcount;	/* track how many fd's are hashed */
115 } port_fdcache_t;
116 
117 /*
118  * Structure of port_ksource_tab[] table.
119  * The port_ksource_tab[] is required to allow kernel sources to become
120  * associated with a port at the time of port creation. This feature is
121  * required to avoid performance degradation in sub-systems, specially when
122  * they should need to check the association on every event activity.
123  */
124 typedef	struct	port_ksource {
125 	int	pks_source;
126 	void	(*pks_close)(void *, int, pid_t, int);
127 	void	*pks_closearg;
128 	void	*pks_portsrc;
129 } port_ksource_t;
130 
131 /* event port and source management */
132 int	port_associate_ksource(int, int, struct port_source **,
133     void (*)(void *, int, pid_t, int), void *arg,
134     int (*)(port_kevent_t *, int, int, uintptr_t, void *));
135 int	port_dissociate_ksource(int, int, struct port_source *);
136 
137 /* event management */
138 int	port_alloc_event(int, int, int, port_kevent_t **);
139 int	port_send_event(port_kevent_t *);
140 void	port_free_event(port_kevent_t *);
141 void	port_init_event(port_kevent_t *, uintptr_t, void *,
142     int (*)(void *, int *, pid_t, int, void *), void *);
143 int	port_dup_event(port_kevent_t *, port_kevent_t **, int);
144 int	port_associate_fd(struct port *, int, uintptr_t, int, void *);
145 int	port_dissociate_fd(struct port *, uintptr_t);
146 
147 /* misc functions */
148 void	port_free_event_local(port_kevent_t *, int counter);
149 int	port_alloc_event_local(struct port *, int, int, port_kevent_t **);
150 void	port_close_pfd(struct portfd *);
151 
152 #endif	/* _KERNEL */
153 
154 #ifdef	__cplusplus
155 }
156 #endif
157 
158 #endif	/* _SYS_PORT_KERNEL_H */
159