xref: /illumos-gate/usr/src/uts/sun4u/serengeti/sys/sgsbbc_mailbox_priv.h (revision cf9a187ca73bc899270af62ab1cd99f2e205cf41)
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 /*
23  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SGSBBC_MAILBOX_PRIV_H
28 #define	_SYS_SGSBBC_MAILBOX_PRIV_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/sgsbbc_mailbox.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Internal flags for message processing
40  */
41 #define	WAIT_FOR_REPLY		0x1
42 #define	NOWAIT_FOR_REPLY	0x2
43 #define	WAIT_FOR_SPACE		0x4
44 #define	NOWAIT_FOR_SPACE	0x8
45 
46 #define	MBOX_INTRS		4
47 #define	MBOX_MSGIN_INTR		0
48 #define	MBOX_MSGOUT_INTR	1
49 #define	MBOX_SPACEIN_INTR	2
50 #define	MBOX_SPACEOUT_INTR	3
51 
52 
53 #define	SBBC_MAILBOXES		2	/* InBox & OutBox */
54 #define	SBBC_INBOX		0
55 #define	SBBC_OUTBOX		1
56 #define	SBBC_MBOX_MSG_TYPES	32	/* this will do for now */
57 #define	SBBC_MBOX_INTR_TYPES	4	/* see below */
58 
59 
60 #define	SBBC_MSG_TYPE_MASK	0xffff
61 
62 /* Number of bytes the mailbox messages align at */
63 #define	MBOX_ALIGN_BYTES	8	/* align at 8-byte boundary */
64 
65 #define	PANIC_ENV_EVENT_MSG		"SC triggered Domain shutdown due to " \
66 					"temperature exceeding limits.\n"
67 
68 /*
69  * This struct is used internally by both the SC & OS mailbox
70  * handlers. Every message in the mailbox is made up
71  * of a fragment struct followed immediately by some optional
72  * user data. (We will allow zero-length messages.)
73  *
74  * Note: ID == 0 => unsolicited
75  *
76  * make them all 32-bit ints and add a bit of
77  * user-data padding to make life easy for the SC
78  */
79 struct sbbc_fragment {
80 	uint32_t	f_id;		/* msg_id */
81 	sbbc_msg_type_t	f_type;		/* msg_type */
82 	uint32_t	f_status;	/* not used yet */
83 	uint32_t	f_total_len;
84 	uint32_t	f_frag_len;
85 	uint32_t	f_frag_offset;	/* offset into msg_buf */
86 	uint32_t	f_data[2];	/* for junk mail */
87 };
88 
89 
90 typedef enum { INBOX, OUTBOX } mb_type_t;
91 
92 /*
93  * this describes the In/Out mailboxes
94  */
95 typedef struct sbbc_mbox {
96 	kmutex_t	mb_lock;	/* global lock for this mailbox */
97 	mb_type_t	mb_type;	/* read-only/read-write */
98 	/*
99 	 * If the mailbox is full, we can either block waiting
100 	 * for space or just return an error. We will make this
101 	 * dependent on the message flag
102 	 */
103 	kcondvar_t	mb_full;	/* protected by mb_lock */
104 } sbbc_mbox_t;
105 
106 
107 /*
108  * When a message requires a reply, it is put on a waitlist
109  * until a message of that type with a matching ID comes in.
110  */
111 struct sbbc_msg_waiter {
112 	uint32_t		w_id;	/* ID */
113 	sbbc_msg_t		*w_msg;	/* message we are waiting for */
114 	kcondvar_t		w_cv;	/* protected by wait_list lock */
115 	time_t			w_timeout;
116 	struct sbbc_msg_waiter	*w_next;
117 };
118 
119 
120 /*
121  * this struct describes the mailbox as seen by the OS
122  */
123 typedef struct sbbc_mailbox {
124 	/*
125 	 * Two mailboxes, SC -> OS mbox_in
126 	 *		  OS -> SC mbox_out
127 	 */
128 	sbbc_mbox_t		*mbox_in;
129 	sbbc_mbox_t		*mbox_out;
130 	/*
131 	 * Interrupt handlers. Mailbox registers itself with
132 	 * the SBBC for the following interrupt types
133 	 *
134 	 * SBBC_MAILBOX_IN
135 	 * SBBC_MAILBOX_OUT
136 	 * SBBC_MAILBOX_SPACE_IN
137 	 * SBBC_MAILBOX_SPACE_OUT
138 	 *
139 	 * Of course, we should only ever see the *-IN interrupts
140 	 * but we will register the *-OUT ones as ours anyway to ensure
141 	 * no-one else tries to overload these interrupt types.
142 	 *
143 	 */
144 	struct {
145 		kmutex_t	mbox_intr_lock;
146 		uint_t		mbox_intr_state;
147 	} intr_state[SBBC_MBOX_INTR_TYPES];
148 
149 	/*
150 	 * Message handlers - one per message type
151 	 * These are used for incoming unsolicited messages
152 	 */
153 	sbbc_intrs_t		*intrs[SBBC_MBOX_MSG_TYPES];
154 
155 	/*
156 	 * Next message ID
157 	 */
158 	uint32_t		mbox_msg_id;
159 
160 	/*
161 	 * List of 'waiters' for each incoming message type
162 	 */
163 	kmutex_t		mbox_wait_lock[SBBC_MBOX_MSG_TYPES];
164 	struct sbbc_msg_waiter	*mbox_wait_list[SBBC_MBOX_MSG_TYPES];
165 
166 } sbbc_mailbox_t;
167 
168 
169 /*
170  * This data will be written by the SC at the
171  * start of the mailbox in IOSRAM.
172  * This is read from offset 0 with key SBBC_MAILBOX_KEY
173  *
174  * make them all 32-bit ints and add a bit of
175  * user-data padding to make life easy for the SC
176  */
177 struct sbbc_mbox_header {
178 	uint32_t	mbox_magic;
179 	uint32_t	mbox_version;
180 	struct mbox {
181 		uint32_t	mbox_type;	/* SBBC_{IN|OUT}BOX */
182 		uint32_t	mbox_offset;	/* from start of mailbox */
183 						/* SRAM area */
184 		uint32_t	mbox_len;	/* size in bytes */
185 		uint32_t	mbox_producer;	/* producer offset from */
186 						/* start of this mailbox */
187 		uint32_t	mbox_consumer;  /* consumer offset from */
188 						/* start of this mailbox */
189 	} mailboxes[SBBC_MAILBOXES];
190 	uint32_t	mbox_data[4];		/* pad */
191 };
192 
193 
194 extern void	sbbc_mbox_init();
195 extern void	sbbc_mbox_fini();
196 extern int	sbbc_mbox_create(sbbc_softstate_t *);
197 extern int	sbbc_mbox_switch(sbbc_softstate_t *);
198 
199 extern sbbc_mailbox_t	*master_mbox;
200 
201 #ifdef	__cplusplus
202 }
203 #endif
204 
205 #endif	/* _SYS_SGSBBC_MAILBOX_PRIV_H */
206