xref: /titanic_54/usr/src/uts/common/sys/ptms.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #ifndef _SYS_PTMS_H
31*7c478bd9Sstevel@tonic-gate #define	_SYS_PTMS_H
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
36*7c478bd9Sstevel@tonic-gate extern "C" {
37*7c478bd9Sstevel@tonic-gate #endif
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /*
40*7c478bd9Sstevel@tonic-gate  * Structures and definitions supporting the pseudo terminal
41*7c478bd9Sstevel@tonic-gate  * drivers. This structure is private and should not be used by any
42*7c478bd9Sstevel@tonic-gate  * applications.
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate struct pt_ttys {
45*7c478bd9Sstevel@tonic-gate 	queue_t *ptm_rdq; 	/* master's read queue pointer */
46*7c478bd9Sstevel@tonic-gate 	queue_t *pts_rdq; 	/* slave's read queue pointer */
47*7c478bd9Sstevel@tonic-gate 	mblk_t	*pt_nullmsg;	/* 0-bytes message block for pts close */
48*7c478bd9Sstevel@tonic-gate 	pid_t	 pt_pid;	/* process id (for debugging) */
49*7c478bd9Sstevel@tonic-gate 	minor_t	 pt_minor;	/* Minor number of this pty */
50*7c478bd9Sstevel@tonic-gate 	int	 pt_refcnt;	/* reference count for ptm_rdq/pts_rdq uses */
51*7c478bd9Sstevel@tonic-gate 	ushort_t pt_state;	/* state of master/slave pair */
52*7c478bd9Sstevel@tonic-gate 	kcondvar_t pt_cv;	/* condition variable for exclusive access */
53*7c478bd9Sstevel@tonic-gate 	kmutex_t pt_lock;	/* Per-element lock */
54*7c478bd9Sstevel@tonic-gate 	zoneid_t pt_zoneid;	/* Zone membership for this pty */
55*7c478bd9Sstevel@tonic-gate };
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * pt_state values
59*7c478bd9Sstevel@tonic-gate  */
60*7c478bd9Sstevel@tonic-gate #define	PTLOCK		0x01	/* master/slave pair is locked */
61*7c478bd9Sstevel@tonic-gate #define	PTMOPEN 	0x02  	/* master side is open */
62*7c478bd9Sstevel@tonic-gate #define	PTSOPEN 	0x04	/* slave side is open */
63*7c478bd9Sstevel@tonic-gate #define	PTSTTY		0x08	/* slave side is tty */
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /*
68*7c478bd9Sstevel@tonic-gate  * Multi-threading primitives.
69*7c478bd9Sstevel@tonic-gate  * Values of pt_refcnt: -1 if a writer is accessing the struct
70*7c478bd9Sstevel@tonic-gate  *			0  if no one is reading or writing
71*7c478bd9Sstevel@tonic-gate  *			> 0 equals to the number of readers accessing the struct
72*7c478bd9Sstevel@tonic-gate  */
73*7c478bd9Sstevel@tonic-gate #define	PT_ENTER_READ(p) {			\
74*7c478bd9Sstevel@tonic-gate 	mutex_enter(&(p)->pt_lock);		\
75*7c478bd9Sstevel@tonic-gate 	while ((p)->pt_refcnt < 0)		\
76*7c478bd9Sstevel@tonic-gate 		cv_wait(&((p)->pt_cv), &(p)->pt_lock);	\
77*7c478bd9Sstevel@tonic-gate 	(p)->pt_refcnt++;			\
78*7c478bd9Sstevel@tonic-gate 	mutex_exit(&(p)->pt_lock);		\
79*7c478bd9Sstevel@tonic-gate }
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate #define	PT_ENTER_WRITE(p) {			\
82*7c478bd9Sstevel@tonic-gate 	mutex_enter(&(p)->pt_lock);		\
83*7c478bd9Sstevel@tonic-gate 	while ((p)->pt_refcnt != 0)		\
84*7c478bd9Sstevel@tonic-gate 		cv_wait(&((p)->pt_cv), &(p)->pt_lock);	\
85*7c478bd9Sstevel@tonic-gate 	(p)->pt_refcnt = -1;			\
86*7c478bd9Sstevel@tonic-gate 	mutex_exit(&(p)->pt_lock);		\
87*7c478bd9Sstevel@tonic-gate }
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate #define	PT_EXIT_READ(p) {			\
90*7c478bd9Sstevel@tonic-gate 	mutex_enter(&(p)->pt_lock);		\
91*7c478bd9Sstevel@tonic-gate 	ASSERT((p)->pt_refcnt > 0);		\
92*7c478bd9Sstevel@tonic-gate 	if ((--((p)->pt_refcnt)) == 0)		\
93*7c478bd9Sstevel@tonic-gate 		cv_broadcast(&(p)->pt_cv);	\
94*7c478bd9Sstevel@tonic-gate 	mutex_exit(&(p)->pt_lock);		\
95*7c478bd9Sstevel@tonic-gate }
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate #define	PT_EXIT_WRITE(p) {			\
98*7c478bd9Sstevel@tonic-gate 	mutex_enter(&(p)->pt_lock);		\
99*7c478bd9Sstevel@tonic-gate 	ASSERT((p)->pt_refcnt == -1);		\
100*7c478bd9Sstevel@tonic-gate 	(p)->pt_refcnt = 0;			\
101*7c478bd9Sstevel@tonic-gate 	cv_broadcast(&(p)->pt_cv);		\
102*7c478bd9Sstevel@tonic-gate 	mutex_exit(&(p)->pt_lock);		\
103*7c478bd9Sstevel@tonic-gate }
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate /*
106*7c478bd9Sstevel@tonic-gate  * ptms_lock and pt_cnt are defined in ptms_conf.c
107*7c478bd9Sstevel@tonic-gate  */
108*7c478bd9Sstevel@tonic-gate extern kmutex_t		ptms_lock;
109*7c478bd9Sstevel@tonic-gate extern dev_info_t 	*pts_dip;	/* private copy of devinfo ptr */
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate extern void ptms_init(void);
112*7c478bd9Sstevel@tonic-gate extern struct pt_ttys *pt_ttys_alloc(void);
113*7c478bd9Sstevel@tonic-gate extern void ptms_close(struct pt_ttys *, uint_t);
114*7c478bd9Sstevel@tonic-gate extern struct pt_ttys *ptms_minor2ptty(minor_t);
115*7c478bd9Sstevel@tonic-gate extern int ptms_create_pts_nodes(dev_info_t *);
116*7c478bd9Sstevel@tonic-gate extern int ptms_destroy_pts_nodes(dev_info_t *);
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
119*7c478bd9Sstevel@tonic-gate extern void ptms_log(char *, uint_t);
120*7c478bd9Sstevel@tonic-gate extern void ptms_logp(char *, uintptr_t);
121*7c478bd9Sstevel@tonic-gate #define	DDBG(a, b) ptms_log(a, b)
122*7c478bd9Sstevel@tonic-gate #define	DDBGP(a, b) ptms_logp(a, b)
123*7c478bd9Sstevel@tonic-gate #else
124*7c478bd9Sstevel@tonic-gate #define	DDBG(a, b)
125*7c478bd9Sstevel@tonic-gate #define	DDBGP(a, b)
126*7c478bd9Sstevel@tonic-gate #endif
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate /*
131*7c478bd9Sstevel@tonic-gate  * ioctl commands
132*7c478bd9Sstevel@tonic-gate  *
133*7c478bd9Sstevel@tonic-gate  *   ISPTM: Determines whether the file descriptor is that of an open master
134*7c478bd9Sstevel@tonic-gate  *	    device. Return code of zero indicates that the file descriptor
135*7c478bd9Sstevel@tonic-gate  *	    represents master device.
136*7c478bd9Sstevel@tonic-gate  *
137*7c478bd9Sstevel@tonic-gate  *  UNLKPT: Unlocks the master and slave devices.  It returns 0 on success. On
138*7c478bd9Sstevel@tonic-gate  *	    failure, the errno is set to EINVAL indicating that the master
139*7c478bd9Sstevel@tonic-gate  *	    device is not open.
140*7c478bd9Sstevel@tonic-gate  *
141*7c478bd9Sstevel@tonic-gate  *  ZONEPT: Sets the zoneid of the pair of master and slave devices.  It
142*7c478bd9Sstevel@tonic-gate  *	    returns 0 upon success.  Used to force a pty 'into' a zone upon
143*7c478bd9Sstevel@tonic-gate  *	    zone entry.
144*7c478bd9Sstevel@tonic-gate  */
145*7c478bd9Sstevel@tonic-gate #define	ISPTM	(('P'<<8)|1)	/* query for master */
146*7c478bd9Sstevel@tonic-gate #define	UNLKPT	(('P'<<8)|2)	/* unlock master/slave pair */
147*7c478bd9Sstevel@tonic-gate #define	PTSSTTY	(('P'<<8)|3)	/* set tty flag */
148*7c478bd9Sstevel@tonic-gate #define	ZONEPT	(('P'<<8)|4)	/* set zone of master/slave pair */
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
151*7c478bd9Sstevel@tonic-gate }
152*7c478bd9Sstevel@tonic-gate #endif
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_PTMS_H */
155