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