xref: /titanic_44/usr/src/uts/sun4v/sys/qcn.h (revision b37f08b54f759faa31d36ca235699a81554ec720)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_QCN_H
27 #define	_QCN_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * sun4v Console driver
37  */
38 
39 #include <sys/types.h>
40 #include <sys/stream.h>
41 #include <sys/tty.h>
42 #include <sys/ddi.h>
43 #include <sys/sunddi.h>
44 
45 #define	RINGBITS	8		/* # of bits in ring ptrs */
46 #define	RINGSIZE	(1<<RINGBITS)	/* size of ring */
47 #define	RINGMASK	(RINGSIZE-1)
48 
49 #define	RING_INIT(qsp)	((qsp)->qcn_rput = (qsp)->qcn_rget = 0)
50 #define	RING_CNT(qsp)	(((qsp)->qcn_rput - (qsp)->qcn_rget) & RINGMASK)
51 #define	RING_POK(qsp, n) ((int)RING_CNT(qsp) < (int)(RINGSIZE-(n)))
52 #define	RING_PUT(qsp, c) \
53 	((qsp)->qcn_ring[(qsp)->qcn_rput++ & RINGMASK] =  (uchar_t)(c))
54 #define	RING_GET(qsp)	((qsp)->qcn_ring[(qsp)->qcn_rget++ & RINGMASK])
55 #define	RING_ADDR(qsp)	(&((qsp)->qcn_ring[(qsp)->qcn_rget & RINGMASK]))
56 #define	RING_POFF(qsp)	((qsp)->qcn_rput & RINGMASK)
57 #define	RING_GOFF(qsp)	((qsp)->qcn_rget & RINGMASK)
58 #define	RING_LEFT(qsp)	(RING_POFF(qsp) >= RING_GOFF(qsp) ? (RINGSIZE) - \
59 			RING_POFF(qsp) : RING_GOFF(qsp) - RING_POFF(qsp))
60 
61 #define	RING_UPD(qsp, n)	((qsp)->qcn_rput += (n))
62 
63 /*
64  * qcn driver's soft state structure
65  */
66 typedef struct qcn {
67 	/* mutexes */
68 	kmutex_t qcn_hi_lock;		/* protects qcn_t (soft state)	*/
69 	kmutex_t qcn_softlock;	/* protects input handler	*/
70 	kmutex_t qcn_lock;	/* protects output queue	*/
71 
72 	/* stream queues */
73 	queue_t *qcn_writeq;		/* stream write queue		*/
74 	queue_t	*qcn_readq;		/* stream read queue		*/
75 
76 	/* dev info */
77 	dev_info_t	*qcn_dip;	/* dev_info			*/
78 
79 	/* for handling IOCTL messages */
80 	bufcall_id_t	qcn_wbufcid;	/* for console ioctl	*/
81 	tty_common_t	qcn_tty;	/* for console ioctl	*/
82 
83 	/* for console output timeout */
84 	time_t qcn_sc_active;		/* last time (sec) SC was active */
85 	uint_t	qcn_polling;
86 	uchar_t	qcn_rget;
87 	uchar_t	qcn_rput;
88 	int	qcn_soft_pend;
89 	ddi_softint_handle_t qcn_softint_hdl;
90 	uchar_t	*qcn_ring;
91 	ushort_t	qcn_hangup;
92 	ddi_intr_handle_t *qcn_htable;	/* For array of interrupts */
93 	int	qcn_intr_type;	/* What type of interrupt */
94 	int	qcn_intr_cnt;	/* # of intrs count returned */
95 	size_t	qcn_intr_size;	/* Size of intr array */
96 	uint_t	qcn_intr_pri;	/* Interrupt priority   */
97 	ddi_iblock_cookie_t qcn_soft_pri;
98 	uint_t	qcn_rbuf_overflow;
99 	/*
100 	 * support for console read/write support
101 	 */
102 	int		(*cons_transmit)(queue_t *, mblk_t *);
103 	void		(*cons_receive)(void);
104 	char		*cons_write_buffer;
105 	uint64_t	cons_write_buf_ra;
106 	uint64_t	cons_read_buf_ra;
107 } qcn_t;
108 
109 /* Constants used by promif routines */
110 #define	QCN_CLNT_STR	"CON_CLNT"
111 #define	QCN_OBP_STR	"CON_OBP"
112 
113 /* alternate break sequence */
114 extern void (*abort_seq_handler)();
115 
116 extern struct mod_ops mod_driverops;
117 
118 #define	QCN_TXINT_ENABLE	0x1
119 #define	QCN_RXINT_ENABLE	0x2
120 
121 /*
122  * API major/minor definitions for console
123  * read/write support.
124  */
125 
126 #define	QCN_API_MAJOR	1
127 #define	QCN_API_MINOR	1
128 
129 /*
130  * The buffer size must be a power of 2 or contig_mem_alloc will fail
131  */
132 #define	CONS_WR_BUF_SIZE	64
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #endif	/* _QCN_H */
139