xref: /onnv-gate/usr/src/uts/sun4v/sys/qcn.h (revision 5974:05fbdff2571b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52282Sjb145095  * Common Development and Distribution License (the "License").
62282Sjb145095  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*5974Sjm22469  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_QCN_H
270Sstevel@tonic-gate #define	_QCN_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef __cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * sun4v Console driver
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <sys/stream.h>
410Sstevel@tonic-gate #include <sys/tty.h>
420Sstevel@tonic-gate #include <sys/ddi.h>
430Sstevel@tonic-gate #include <sys/sunddi.h>
44*5974Sjm22469 #include <sys/consdev.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #define	RINGBITS	8		/* # of bits in ring ptrs */
470Sstevel@tonic-gate #define	RINGSIZE	(1<<RINGBITS)	/* size of ring */
480Sstevel@tonic-gate #define	RINGMASK	(RINGSIZE-1)
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #define	RING_INIT(qsp)	((qsp)->qcn_rput = (qsp)->qcn_rget = 0)
510Sstevel@tonic-gate #define	RING_CNT(qsp)	(((qsp)->qcn_rput - (qsp)->qcn_rget) & RINGMASK)
520Sstevel@tonic-gate #define	RING_POK(qsp, n) ((int)RING_CNT(qsp) < (int)(RINGSIZE-(n)))
530Sstevel@tonic-gate #define	RING_PUT(qsp, c) \
540Sstevel@tonic-gate 	((qsp)->qcn_ring[(qsp)->qcn_rput++ & RINGMASK] =  (uchar_t)(c))
550Sstevel@tonic-gate #define	RING_GET(qsp)	((qsp)->qcn_ring[(qsp)->qcn_rget++ & RINGMASK])
562282Sjb145095 #define	RING_ADDR(qsp)	(&((qsp)->qcn_ring[(qsp)->qcn_rget & RINGMASK]))
572282Sjb145095 #define	RING_POFF(qsp)	((qsp)->qcn_rput & RINGMASK)
582282Sjb145095 #define	RING_GOFF(qsp)	((qsp)->qcn_rget & RINGMASK)
592282Sjb145095 #define	RING_LEFT(qsp)	(RING_POFF(qsp) >= RING_GOFF(qsp) ? (RINGSIZE) - \
602282Sjb145095 			RING_POFF(qsp) : RING_GOFF(qsp) - RING_POFF(qsp))
612282Sjb145095 
622282Sjb145095 #define	RING_UPD(qsp, n)	((qsp)->qcn_rput += (n))
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  * qcn driver's soft state structure
660Sstevel@tonic-gate  */
670Sstevel@tonic-gate typedef struct qcn {
680Sstevel@tonic-gate 	/* mutexes */
690Sstevel@tonic-gate 	kmutex_t qcn_hi_lock;		/* protects qcn_t (soft state)	*/
700Sstevel@tonic-gate 	kmutex_t qcn_lock;	/* protects output queue	*/
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	/* stream queues */
730Sstevel@tonic-gate 	queue_t *qcn_writeq;		/* stream write queue		*/
740Sstevel@tonic-gate 	queue_t	*qcn_readq;		/* stream read queue		*/
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	/* dev info */
770Sstevel@tonic-gate 	dev_info_t	*qcn_dip;	/* dev_info			*/
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	/* for handling IOCTL messages */
800Sstevel@tonic-gate 	bufcall_id_t	qcn_wbufcid;	/* for console ioctl	*/
810Sstevel@tonic-gate 	tty_common_t	qcn_tty;	/* for console ioctl	*/
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	/* for console output timeout */
840Sstevel@tonic-gate 	time_t qcn_sc_active;		/* last time (sec) SC was active */
850Sstevel@tonic-gate 	uint_t	qcn_polling;
860Sstevel@tonic-gate 	uchar_t	qcn_rget;
870Sstevel@tonic-gate 	uchar_t	qcn_rput;
882432Sjb145095 
892432Sjb145095 	/* the following is protected by atomic operations */
902432Sjb145095 	volatile unsigned int	qcn_soft_pend;
912432Sjb145095 
920Sstevel@tonic-gate 	ddi_softint_handle_t qcn_softint_hdl;
932282Sjb145095 	uchar_t	*qcn_ring;
940Sstevel@tonic-gate 	ushort_t	qcn_hangup;
950Sstevel@tonic-gate 	ddi_intr_handle_t *qcn_htable;	/* For array of interrupts */
960Sstevel@tonic-gate 	int	qcn_intr_type;	/* What type of interrupt */
970Sstevel@tonic-gate 	int	qcn_intr_cnt;	/* # of intrs count returned */
980Sstevel@tonic-gate 	size_t	qcn_intr_size;	/* Size of intr array */
990Sstevel@tonic-gate 	uint_t	qcn_intr_pri;	/* Interrupt priority   */
1000Sstevel@tonic-gate 	uint_t	qcn_rbuf_overflow;
1012282Sjb145095 	/*
1022282Sjb145095 	 * support for console read/write support
1032282Sjb145095 	 */
1042282Sjb145095 	int		(*cons_transmit)(queue_t *, mblk_t *);
1052282Sjb145095 	void		(*cons_receive)(void);
1062282Sjb145095 	char		*cons_write_buffer;
1072282Sjb145095 	uint64_t	cons_write_buf_ra;
1082282Sjb145095 	uint64_t	cons_read_buf_ra;
109*5974Sjm22469 
110*5974Sjm22469 	/*
111*5974Sjm22469 	 * support for polled io
112*5974Sjm22469 	 */
113*5974Sjm22469 	cons_polledio_t	qcn_polledio;
114*5974Sjm22469 	boolean_t	qcn_char_available;
115*5974Sjm22469 	uint8_t		qcn_hold_char;
1160Sstevel@tonic-gate } qcn_t;
1170Sstevel@tonic-gate 
1182432Sjb145095 /* Constants for qcn_soft_pend */
1192432Sjb145095 #define	QCN_SP_IDL	0	/* qcn_soft_pend is idle - do trigger */
1202432Sjb145095 #define	QCN_SP_DO	1	/* soft interrupt needs to be processed */
1212432Sjb145095 #define	QCN_SP_IP	2	/* in process, if interrupt, set DO, no trig */
1222432Sjb145095 
1230Sstevel@tonic-gate /* Constants used by promif routines */
1240Sstevel@tonic-gate #define	QCN_CLNT_STR	"CON_CLNT"
1250Sstevel@tonic-gate #define	QCN_OBP_STR	"CON_OBP"
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate /* alternate break sequence */
1280Sstevel@tonic-gate extern void (*abort_seq_handler)();
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate #define	QCN_TXINT_ENABLE	0x1
1330Sstevel@tonic-gate #define	QCN_RXINT_ENABLE	0x2
1340Sstevel@tonic-gate 
1352282Sjb145095 /*
1362282Sjb145095  * API major/minor definitions for console
1372282Sjb145095  * read/write support.
1382282Sjb145095  */
1392282Sjb145095 
1402282Sjb145095 #define	QCN_API_MAJOR	1
1412282Sjb145095 #define	QCN_API_MINOR	1
1422282Sjb145095 
1432282Sjb145095 /*
1442282Sjb145095  * The buffer size must be a power of 2 or contig_mem_alloc will fail
1452282Sjb145095  */
1462282Sjb145095 #define	CONS_WR_BUF_SIZE	64
1472282Sjb145095 
1480Sstevel@tonic-gate #ifdef __cplusplus
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate #endif
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #endif	/* _QCN_H */
153