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 534709573Sraf * Common Development and Distribution License (the "License"). 634709573Sraf * 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 */ 2134709573Sraf 227c478bd9Sstevel@tonic-gate /* 23*df2381bfSpraks * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_PORT_KERNEL_H 287c478bd9Sstevel@tonic-gate #define _SYS_PORT_KERNEL_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 337c478bd9Sstevel@tonic-gate #include <sys/list.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * Note: 417c478bd9Sstevel@tonic-gate * The contents of this file are private to the implementation of the 427c478bd9Sstevel@tonic-gate * Solaris system and event ports subsystem and are subject to change 437c478bd9Sstevel@tonic-gate * at any time without notice. 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #ifdef _KERNEL 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * The port_kevent_t struct represents the kernel internal port event. 507c478bd9Sstevel@tonic-gate * Every event is associated to a port (portkev_port). 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate typedef struct port_kevent { 5361b4b1efSpraks kmutex_t portkev_lock; /* used by PORT_SOURCE_FD source */ 547c478bd9Sstevel@tonic-gate int portkev_source; /* event: source */ 557c478bd9Sstevel@tonic-gate int portkev_events; /* event: data */ 567c478bd9Sstevel@tonic-gate int portkev_flags; /* internal flags */ 577c478bd9Sstevel@tonic-gate pid_t portkev_pid; /* pid of process using this struct */ 587c478bd9Sstevel@tonic-gate long portkev_object; /* event: object */ 597c478bd9Sstevel@tonic-gate void *portkev_user; /* event: user-defined value */ 607c478bd9Sstevel@tonic-gate int (*portkev_callback)(void *, int *, pid_t, int, void *); 617c478bd9Sstevel@tonic-gate void *portkev_arg; /* event source callback arg */ 627c478bd9Sstevel@tonic-gate struct port *portkev_port; /* associated port */ 637c478bd9Sstevel@tonic-gate list_node_t portkev_node; /* pointer to neighbor events */ 647c478bd9Sstevel@tonic-gate } port_kevent_t; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* portkev_flags */ 677c478bd9Sstevel@tonic-gate #define PORT_KEV_PRIVATE 0x01 /* subsystem private, don't free */ 687c478bd9Sstevel@tonic-gate #define PORT_KEV_CACHED 0x02 /* port local cached, don't free */ 697c478bd9Sstevel@tonic-gate #define PORT_KEV_SCACHED 0x04 /* source local cached, don't free */ 707c478bd9Sstevel@tonic-gate #define PORT_KEV_VALID 0x08 /* event associated and enabled */ 717c478bd9Sstevel@tonic-gate #define PORT_KEV_DONEQ 0x10 /* event is in done queue */ 727c478bd9Sstevel@tonic-gate #define PORT_KEV_FREE 0x20 /* free event and don't copyout it */ 737c478bd9Sstevel@tonic-gate #define PORT_KEV_NOSHARE 0x40 /* non-shareable across processes */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* flags : port_alloc_event() */ 767c478bd9Sstevel@tonic-gate #define PORT_ALLOC_DEFAULT 0 777c478bd9Sstevel@tonic-gate #define PORT_ALLOC_PRIVATE PORT_KEV_PRIVATE 787c478bd9Sstevel@tonic-gate #define PORT_ALLOC_CACHED PORT_KEV_CACHED 797c478bd9Sstevel@tonic-gate #define PORT_ALLOC_SCACHED PORT_KEV_SCACHED 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* flags : callback function */ 827c478bd9Sstevel@tonic-gate #define PORT_CALLBACK_DEFAULT 0 /* free resources, event delivery */ 837c478bd9Sstevel@tonic-gate #define PORT_CALLBACK_CLOSE 1 /* free resources, don't copyout */ 847c478bd9Sstevel@tonic-gate #define PORT_CALLBACK_DISSOCIATE 2 /* dissociate object */ 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #define PORT_DEFAULT_PORTS 0x02000 877c478bd9Sstevel@tonic-gate #define PORT_MAX_PORTS 0x10000 887c478bd9Sstevel@tonic-gate #define PORT_DEFAULT_EVENTS 0x10000 /* default # of events per port */ 897c478bd9Sstevel@tonic-gate #define PORT_MAX_EVENTS UINT_MAX/2 /* max. # of events per port */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * port_source_t represents a source associated with a port. 937c478bd9Sstevel@tonic-gate * The portsrc_close() function is required to notify the source when 947c478bd9Sstevel@tonic-gate * a port is closed. 957c478bd9Sstevel@tonic-gate */ 967c478bd9Sstevel@tonic-gate typedef struct port_source { 977c478bd9Sstevel@tonic-gate int portsrc_source; 987c478bd9Sstevel@tonic-gate int portsrc_cnt; /* # of associations */ 997c478bd9Sstevel@tonic-gate void (*portsrc_close)(void *, int, pid_t, int); 1007c478bd9Sstevel@tonic-gate void *portsrc_closearg; /* callback arg */ 101*df2381bfSpraks void *portsrc_data; /* Private data of source */ 1027c478bd9Sstevel@tonic-gate struct port_source *portsrc_next; 1037c478bd9Sstevel@tonic-gate struct port_source *portsrc_prev; 1047c478bd9Sstevel@tonic-gate } port_source_t; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 108*df2381bfSpraks * PORT_SOURCE_FILE cache structure. 109*df2381bfSpraks */ 110*df2381bfSpraks #define PORTFOP_HASHSIZE 256 /* cache space for fop events */ 111*df2381bfSpraks 112*df2381bfSpraks /* 113*df2381bfSpraks * One cache for each port that uses PORT_SOURCE_FILE. 114*df2381bfSpraks */ 115*df2381bfSpraks typedef struct portfop_cache { 116*df2381bfSpraks kmutex_t pfc_lock; /* lock to protect cache */ 117*df2381bfSpraks kcondvar_t pfc_lclosecv; /* last close cv */ 118*df2381bfSpraks int pfc_objcount; /* track how many file obj are hashed */ 119*df2381bfSpraks struct portfop *pfc_hash[PORTFOP_HASHSIZE]; /* hash table */ 120*df2381bfSpraks } portfop_cache_t; 121*df2381bfSpraks 122*df2381bfSpraks /* 123*df2381bfSpraks * PORT_SOURCE_FD cache per port. 1247c478bd9Sstevel@tonic-gate * One cache for each port that uses PORT_SOURCE_FD. 1257c478bd9Sstevel@tonic-gate * pc_lock must be the first element of port_fdcache_t to keep it 1267c478bd9Sstevel@tonic-gate * synchronized with the offset of pc_lock in pollcache_t (see pollrelock()). 1277c478bd9Sstevel@tonic-gate */ 1287c478bd9Sstevel@tonic-gate typedef struct port_fdcache { 1297c478bd9Sstevel@tonic-gate kmutex_t pc_lock; /* lock to protect portcache */ 13061b4b1efSpraks kcondvar_t pc_lclosecv; 1317c478bd9Sstevel@tonic-gate struct portfd **pc_hash; /* points to a hash table of ptrs */ 1327c478bd9Sstevel@tonic-gate int pc_hashsize; /* the size of current hash table */ 1337c478bd9Sstevel@tonic-gate int pc_fdcount; /* track how many fd's are hashed */ 1347c478bd9Sstevel@tonic-gate } port_fdcache_t; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * Structure of port_ksource_tab[] table. 1387c478bd9Sstevel@tonic-gate * The port_ksource_tab[] is required to allow kernel sources to become 1397c478bd9Sstevel@tonic-gate * associated with a port at the time of port creation. This feature is 1407c478bd9Sstevel@tonic-gate * required to avoid performance degradation in sub-systems, specially when 1417c478bd9Sstevel@tonic-gate * they should need to check the association on every event activity. 1427c478bd9Sstevel@tonic-gate */ 1437c478bd9Sstevel@tonic-gate typedef struct port_ksource { 1447c478bd9Sstevel@tonic-gate int pks_source; 1457c478bd9Sstevel@tonic-gate void (*pks_close)(void *, int, pid_t, int); 1467c478bd9Sstevel@tonic-gate void *pks_closearg; 1477c478bd9Sstevel@tonic-gate void *pks_portsrc; 1487c478bd9Sstevel@tonic-gate } port_ksource_t; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* event port and source management */ 1517c478bd9Sstevel@tonic-gate int port_associate_ksource(int, int, struct port_source **, 1527c478bd9Sstevel@tonic-gate void (*)(void *, int, pid_t, int), void *arg, 1537c478bd9Sstevel@tonic-gate int (*)(port_kevent_t *, int, int, uintptr_t, void *)); 1547c478bd9Sstevel@tonic-gate int port_dissociate_ksource(int, int, struct port_source *); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* event management */ 1577c478bd9Sstevel@tonic-gate int port_alloc_event(int, int, int, port_kevent_t **); 15811dc39ddSpraks int port_pollwkup(struct port *); 15911dc39ddSpraks void port_pollwkdone(struct port *); 16034709573Sraf void port_send_event(port_kevent_t *); 1617c478bd9Sstevel@tonic-gate void port_free_event(port_kevent_t *); 1627c478bd9Sstevel@tonic-gate void port_init_event(port_kevent_t *, uintptr_t, void *, 1637c478bd9Sstevel@tonic-gate int (*)(void *, int *, pid_t, int, void *), void *); 1647c478bd9Sstevel@tonic-gate int port_dup_event(port_kevent_t *, port_kevent_t **, int); 1657c478bd9Sstevel@tonic-gate int port_associate_fd(struct port *, int, uintptr_t, int, void *); 1667c478bd9Sstevel@tonic-gate int port_dissociate_fd(struct port *, uintptr_t); 167*df2381bfSpraks int port_associate_fop(struct port *, int, uintptr_t, int, void *); 168*df2381bfSpraks int port_dissociate_fop(struct port *, uintptr_t); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* misc functions */ 1717c478bd9Sstevel@tonic-gate void port_free_event_local(port_kevent_t *, int counter); 1727c478bd9Sstevel@tonic-gate int port_alloc_event_local(struct port *, int, int, port_kevent_t **); 1737c478bd9Sstevel@tonic-gate void port_close_pfd(struct portfd *); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate #endif 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #endif /* _SYS_PORT_KERNEL_H */ 182