xref: /illumos-gate/usr/src/uts/sun4v/sys/qcn.h (revision 0a44ef6d9afbfe052a7e975f55ea0d2954b62a82)
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_lock;	/* protects output queue	*/
70 
71 	/* stream queues */
72 	queue_t *qcn_writeq;		/* stream write queue		*/
73 	queue_t	*qcn_readq;		/* stream read queue		*/
74 
75 	/* dev info */
76 	dev_info_t	*qcn_dip;	/* dev_info			*/
77 
78 	/* for handling IOCTL messages */
79 	bufcall_id_t	qcn_wbufcid;	/* for console ioctl	*/
80 	tty_common_t	qcn_tty;	/* for console ioctl	*/
81 
82 	/* for console output timeout */
83 	time_t qcn_sc_active;		/* last time (sec) SC was active */
84 	uint_t	qcn_polling;
85 	uchar_t	qcn_rget;
86 	uchar_t	qcn_rput;
87 
88 	/* the following is protected by atomic operations */
89 	volatile unsigned int	qcn_soft_pend;
90 
91 	ddi_softint_handle_t qcn_softint_hdl;
92 	uchar_t	*qcn_ring;
93 	ushort_t	qcn_hangup;
94 	ddi_intr_handle_t *qcn_htable;	/* For array of interrupts */
95 	int	qcn_intr_type;	/* What type of interrupt */
96 	int	qcn_intr_cnt;	/* # of intrs count returned */
97 	size_t	qcn_intr_size;	/* Size of intr array */
98 	uint_t	qcn_intr_pri;	/* Interrupt priority   */
99 	uint_t	qcn_rbuf_overflow;
100 	/*
101 	 * support for console read/write support
102 	 */
103 	int		(*cons_transmit)(queue_t *, mblk_t *);
104 	void		(*cons_receive)(void);
105 	char		*cons_write_buffer;
106 	uint64_t	cons_write_buf_ra;
107 	uint64_t	cons_read_buf_ra;
108 } qcn_t;
109 
110 /* Constants for qcn_soft_pend */
111 #define	QCN_SP_IDL	0	/* qcn_soft_pend is idle - do trigger */
112 #define	QCN_SP_DO	1	/* soft interrupt needs to be processed */
113 #define	QCN_SP_IP	2	/* in process, if interrupt, set DO, no trig */
114 
115 /* Constants used by promif routines */
116 #define	QCN_CLNT_STR	"CON_CLNT"
117 #define	QCN_OBP_STR	"CON_OBP"
118 
119 /* alternate break sequence */
120 extern void (*abort_seq_handler)();
121 
122 extern struct mod_ops mod_driverops;
123 
124 #define	QCN_TXINT_ENABLE	0x1
125 #define	QCN_RXINT_ENABLE	0x2
126 
127 /*
128  * API major/minor definitions for console
129  * read/write support.
130  */
131 
132 #define	QCN_API_MAJOR	1
133 #define	QCN_API_MINOR	1
134 
135 /*
136  * The buffer size must be a power of 2 or contig_mem_alloc will fail
137  */
138 #define	CONS_WR_BUF_SIZE	64
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif	/* _QCN_H */
145