xref: /illumos-gate/usr/src/uts/sun4v/sys/qcn.h (revision 1b83305c)
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 2008 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 #include <sys/consdev.h>
45 
46 #define	RINGBITS	8		/* # of bits in ring ptrs */
47 #define	RINGSIZE	(1<<RINGBITS)	/* size of ring */
48 #define	RINGMASK	(RINGSIZE-1)
49 
50 #define	RING_INIT(qsp)	((qsp)->qcn_rput = (qsp)->qcn_rget = 0)
51 #define	RING_CNT(qsp)	(((qsp)->qcn_rput - (qsp)->qcn_rget) & RINGMASK)
52 #define	RING_POK(qsp, n) ((int)RING_CNT(qsp) < (int)(RINGSIZE-(n)))
53 #define	RING_PUT(qsp, c) \
54 	((qsp)->qcn_ring[(qsp)->qcn_rput++ & RINGMASK] =  (uchar_t)(c))
55 #define	RING_GET(qsp)	((qsp)->qcn_ring[(qsp)->qcn_rget++ & RINGMASK])
56 #define	RING_ADDR(qsp)	(&((qsp)->qcn_ring[(qsp)->qcn_rget & RINGMASK]))
57 #define	RING_POFF(qsp)	((qsp)->qcn_rput & RINGMASK)
58 #define	RING_GOFF(qsp)	((qsp)->qcn_rget & RINGMASK)
59 #define	RING_LEFT(qsp)	(RING_POFF(qsp) >= RING_GOFF(qsp) ? (RINGSIZE) - \
60 			RING_POFF(qsp) : RING_GOFF(qsp) - RING_POFF(qsp))
61 
62 #define	RING_UPD(qsp, n)	((qsp)->qcn_rput += (n))
63 
64 /*
65  * qcn driver's soft state structure
66  */
67 typedef struct qcn {
68 	/* mutexes */
69 	kmutex_t qcn_hi_lock;		/* protects qcn_t (soft state)	*/
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 
89 	/* the following is protected by atomic operations */
90 	volatile unsigned int	qcn_soft_pend;
91 
92 	ddi_softint_handle_t qcn_softint_hdl;
93 	uchar_t	*qcn_ring;
94 	ushort_t	qcn_hangup;
95 	ddi_intr_handle_t *qcn_htable;	/* For array of interrupts */
96 	int	qcn_intr_type;	/* What type of interrupt */
97 	int	qcn_intr_cnt;	/* # of intrs count returned */
98 	size_t	qcn_intr_size;	/* Size of intr array */
99 	uint_t	qcn_intr_pri;	/* Interrupt priority   */
100 	uint_t	qcn_rbuf_overflow;
101 	/*
102 	 * support for console read/write support
103 	 */
104 	int		(*cons_transmit)(queue_t *, mblk_t *);
105 	void		(*cons_receive)(void);
106 	char		*cons_write_buffer;
107 	uint64_t	cons_write_buf_ra;
108 	uint64_t	cons_read_buf_ra;
109 
110 	/*
111 	 * support for polled io
112 	 */
113 	cons_polledio_t	qcn_polledio;
114 	boolean_t	qcn_char_available;
115 	uint8_t		qcn_hold_char;
116 } qcn_t;
117 
118 /* Constants for qcn_soft_pend */
119 #define	QCN_SP_IDL	0	/* qcn_soft_pend is idle - do trigger */
120 #define	QCN_SP_DO	1	/* soft interrupt needs to be processed */
121 #define	QCN_SP_IP	2	/* in process, if interrupt, set DO, no trig */
122 
123 /* Constants used by promif routines */
124 #define	QCN_CLNT_STR	"CON_CLNT"
125 #define	QCN_OBP_STR	"CON_OBP"
126 
127 /* alternate break sequence */
128 extern void (*abort_seq_handler)();
129 
130 extern struct mod_ops mod_driverops;
131 
132 #define	QCN_TXINT_ENABLE	0x1
133 #define	QCN_RXINT_ENABLE	0x2
134 
135 /*
136  * API major/minor definitions for console
137  * read/write support.
138  */
139 
140 #define	QCN_API_MAJOR	1
141 #define	QCN_API_MINOR	1
142 
143 /*
144  * The buffer size must be a power of 2 or contig_mem_alloc will fail
145  */
146 #define	CONS_WR_BUF_SIZE	64
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #endif	/* _QCN_H */
153