xref: /titanic_53/usr/src/uts/sun4v/sys/qcn.h (revision 136097cead98e48ee9260b7cc3b7edd749c5c808)
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
5*136097ceSjb145095  * Common Development and Distribution License (the "License").
6*136097ceSjb145095  * 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  */
217c478bd9Sstevel@tonic-gate /*
22*136097ceSjb145095  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_QCN_H
277c478bd9Sstevel@tonic-gate #define	_QCN_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef __cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * sun4v Console driver
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <sys/stream.h>
417c478bd9Sstevel@tonic-gate #include <sys/tty.h>
427c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
437c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	RINGBITS	8		/* # of bits in ring ptrs */
467c478bd9Sstevel@tonic-gate #define	RINGSIZE	(1<<RINGBITS)	/* size of ring */
477c478bd9Sstevel@tonic-gate #define	RINGMASK	(RINGSIZE-1)
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	RING_INIT(qsp)	((qsp)->qcn_rput = (qsp)->qcn_rget = 0)
507c478bd9Sstevel@tonic-gate #define	RING_CNT(qsp)	(((qsp)->qcn_rput - (qsp)->qcn_rget) & RINGMASK)
517c478bd9Sstevel@tonic-gate #define	RING_POK(qsp, n) ((int)RING_CNT(qsp) < (int)(RINGSIZE-(n)))
527c478bd9Sstevel@tonic-gate #define	RING_PUT(qsp, c) \
537c478bd9Sstevel@tonic-gate 	((qsp)->qcn_ring[(qsp)->qcn_rput++ & RINGMASK] =  (uchar_t)(c))
547c478bd9Sstevel@tonic-gate #define	RING_GET(qsp)	((qsp)->qcn_ring[(qsp)->qcn_rget++ & RINGMASK])
55*136097ceSjb145095 #define	RING_ADDR(qsp)	(&((qsp)->qcn_ring[(qsp)->qcn_rget & RINGMASK]))
56*136097ceSjb145095 #define	RING_POFF(qsp)	((qsp)->qcn_rput & RINGMASK)
57*136097ceSjb145095 #define	RING_GOFF(qsp)	((qsp)->qcn_rget & RINGMASK)
58*136097ceSjb145095 #define	RING_LEFT(qsp)	(RING_POFF(qsp) >= RING_GOFF(qsp) ? (RINGSIZE) - \
59*136097ceSjb145095 			RING_POFF(qsp) : RING_GOFF(qsp) - RING_POFF(qsp))
60*136097ceSjb145095 
61*136097ceSjb145095 #define	RING_UPD(qsp, n)	((qsp)->qcn_rput += (n))
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * qcn driver's soft state structure
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate typedef struct qcn {
677c478bd9Sstevel@tonic-gate 	/* mutexes */
687c478bd9Sstevel@tonic-gate 	kmutex_t qcn_hi_lock;		/* protects qcn_t (soft state)	*/
697c478bd9Sstevel@tonic-gate 	kmutex_t qcn_softlock;	/* protects input handler	*/
707c478bd9Sstevel@tonic-gate 	kmutex_t qcn_lock;	/* protects output queue	*/
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	/* stream queues */
737c478bd9Sstevel@tonic-gate 	queue_t *qcn_writeq;		/* stream write queue		*/
747c478bd9Sstevel@tonic-gate 	queue_t	*qcn_readq;		/* stream read queue		*/
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	/* dev info */
777c478bd9Sstevel@tonic-gate 	dev_info_t	*qcn_dip;	/* dev_info			*/
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	/* for handling IOCTL messages */
807c478bd9Sstevel@tonic-gate 	bufcall_id_t	qcn_wbufcid;	/* for console ioctl	*/
817c478bd9Sstevel@tonic-gate 	tty_common_t	qcn_tty;	/* for console ioctl	*/
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	/* for console output timeout */
847c478bd9Sstevel@tonic-gate 	time_t qcn_sc_active;		/* last time (sec) SC was active */
857c478bd9Sstevel@tonic-gate 	uint_t	qcn_polling;
867c478bd9Sstevel@tonic-gate 	uchar_t	qcn_rget;
877c478bd9Sstevel@tonic-gate 	uchar_t	qcn_rput;
887c478bd9Sstevel@tonic-gate 	int	qcn_soft_pend;
897c478bd9Sstevel@tonic-gate 	ddi_softint_handle_t qcn_softint_hdl;
90*136097ceSjb145095 	uchar_t	*qcn_ring;
917c478bd9Sstevel@tonic-gate 	ushort_t	qcn_hangup;
927c478bd9Sstevel@tonic-gate 	ddi_intr_handle_t *qcn_htable;	/* For array of interrupts */
937c478bd9Sstevel@tonic-gate 	int	qcn_intr_type;	/* What type of interrupt */
947c478bd9Sstevel@tonic-gate 	int	qcn_intr_cnt;	/* # of intrs count returned */
957c478bd9Sstevel@tonic-gate 	size_t	qcn_intr_size;	/* Size of intr array */
967c478bd9Sstevel@tonic-gate 	uint_t	qcn_intr_pri;	/* Interrupt priority   */
977c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t qcn_soft_pri;
987c478bd9Sstevel@tonic-gate 	uint_t	qcn_rbuf_overflow;
99*136097ceSjb145095 	/*
100*136097ceSjb145095 	 * support for console read/write support
101*136097ceSjb145095 	 */
102*136097ceSjb145095 	int		(*cons_transmit)(queue_t *, mblk_t *);
103*136097ceSjb145095 	void		(*cons_receive)(void);
104*136097ceSjb145095 	char		*cons_write_buffer;
105*136097ceSjb145095 	uint64_t	cons_write_buf_ra;
106*136097ceSjb145095 	uint64_t	cons_read_buf_ra;
1077c478bd9Sstevel@tonic-gate } qcn_t;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /* Constants used by promif routines */
1107c478bd9Sstevel@tonic-gate #define	QCN_CLNT_STR	"CON_CLNT"
1117c478bd9Sstevel@tonic-gate #define	QCN_OBP_STR	"CON_OBP"
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /* alternate break sequence */
1147c478bd9Sstevel@tonic-gate extern void (*abort_seq_handler)();
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	QCN_TXINT_ENABLE	0x1
1197c478bd9Sstevel@tonic-gate #define	QCN_RXINT_ENABLE	0x2
1207c478bd9Sstevel@tonic-gate 
121*136097ceSjb145095 /*
122*136097ceSjb145095  * API major/minor definitions for console
123*136097ceSjb145095  * read/write support.
124*136097ceSjb145095  */
125*136097ceSjb145095 
126*136097ceSjb145095 #define	QCN_API_MAJOR	1
127*136097ceSjb145095 #define	QCN_API_MINOR	1
128*136097ceSjb145095 
129*136097ceSjb145095 /*
130*136097ceSjb145095  * The buffer size must be a power of 2 or contig_mem_alloc will fail
131*136097ceSjb145095  */
132*136097ceSjb145095 #define	CONS_WR_BUF_SIZE	64
133*136097ceSjb145095 
1347c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate #endif
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate #endif	/* _QCN_H */
139