xref: /titanic_52/usr/src/lib/libtnfprobe/tnf_buf.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #ifndef _TNF_BUF_H
27 #define	_TNF_BUF_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef _KERNEL
32 #include <sys/tnf_com.h>
33 #else  /* _KERNEL */
34 #include <tnf/com.h>
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Size of the file header and forwarding pointer (directory) area combined.
43  * Tag and data blocks start this many bytes into the file.
44  *
45  * The kernel uses a smaller directory area, and uses the saved space
46  * as block pool reserved for tag allocations.
47  */
48 
49 #ifdef _KERNEL
50 #define	TNFW_B_FW_ZONE			0x4000
51 #define	TNFW_B_TAG_RESERVE		0xc000
52 #else
53 #define	TNFW_B_FW_ZONE			0x10000
54 #define	TNFW_B_TAG_RESERVE		0x8000
55 #endif
56 #define	TNFW_B_DATA_BLOCK_BEGIN		(TNFW_B_FW_ZONE + TNFW_B_TAG_RESERVE)
57 
58 /*
59  * CAUTION: do not change integer values of TNF_ALLOC_REUSABLE or
60  *		TNF_ALLOC_FIXED
61  */
62 enum tnf_alloc_mode {
63 	TNF_ALLOC_REUSABLE = 0,
64 	TNF_ALLOC_FIXED
65 };
66 
67 typedef struct {
68 	tnf_uint32_t		magic;
69 	tnf_file_header_t	com;
70 	struct {
71 		uint_t		hi;
72 		uint_t		lo[2];
73 	} next_alloc;
74 	uint_t			next_tag_alloc;
75 	uint_t			next_fw_alloc;
76 } tnf_buf_file_header_t;
77 
78 typedef struct tnfw_b_pos TNFW_B_POS;
79 
80 struct tnfw_b_pos {
81 	tnf_block_header_t 	*tnfw_w_block;
82 	tnf_block_header_t 	*tnfw_w_uncommitted;
83 	short 			tnfw_w_write_off;
84 };
85 
86 typedef struct {
87 	boolean_t 		tnfw_w_initialized;
88 	struct tnfw_b_pos 	tnfw_w_pos;
89 	struct tnfw_b_pos 	tnfw_w_tag_pos;
90 	int 			tnfw_w_gen_shift;
91 	int 			tnfw_w_block_shift;
92 	pid_t 			tnfw_w_pid;
93 	u_long 			tnfw_w_block_size;
94 #ifdef TNFWB_MAY_RELEASE_A_LOCK
95 	u_long 			tnfw_w_generation;
96 	boolean_t 		tnfw_w_a_lock_released;
97 #endif
98 } TNFW_B_WCB;
99 
100 typedef enum {
101 	TNFW_B_OK,
102 	TNFW_B_NOTCONN,
103 	TNFW_B_ACKPHT,
104 	TNFW_B_NO_ALLOC,
105 	TNFW_B_NO_SPACE,
106 	TNFW_B_BAD_BLOCK_SIZE,
107 	TNFW_B_BAD_BLOCK_COUNT,
108 	TNFW_B_RECORD_TOO_BIG
109 } TNFW_B_STATUS;
110 
111 typedef enum {
112     TNFW_B_RUNNING = 0,
113     TNFW_B_NOBUFFER,
114     TNFW_B_FORKED,
115     TNFW_B_BROKEN
116 } TNFW_B_STATE;
117 
118 /*
119  * The STOPPED bit may be or-ed into the state field.
120  */
121 #define	TNFW_B_STOPPED  16
122 #define	TNFW_B_SET_STOPPED(state)	((state) |= TNFW_B_STOPPED)
123 #define	TNFW_B_UNSET_STOPPED(state)	((state) &= ~TNFW_B_STOPPED)
124 #define	TNFW_B_IS_STOPPED(state)	((state) & TNFW_B_STOPPED)
125 
126 
127 typedef struct {
128 	TNFW_B_STATE tnf_state;
129 	volatile char *tnf_buffer;
130 	int (*tnf_init_callback)(void);
131 	void (*tnf_fork_callback)(void);
132 	pid_t tnf_pid;
133 } TNFW_B_CONTROL;
134 
135 extern TNFW_B_CONTROL *_tnfw_b_control;
136 
137 /*
138  * structure exported by buffering layer - guaranteed to be filled
139  * after tnfw_b_init_buffer is called.
140  */
141 typedef struct {
142 	char *	fw_file_header;
143 	char *	fw_block_header;
144 	char *	fw_root;
145 } tnf_buf_header_t;
146 
147 extern tnf_buf_header_t *_tnf_buf_headers_p;
148 
149 /*
150  * External interface
151  */
152 
153 #define	TNFW_B_GIVEBACK(wcb, new_pos)	\
154 	((wcb)->tnfw_w_pos.tnfw_w_write_off = \
155 	(((char *)(new_pos) - (char *)((wcb)->tnfw_w_pos.tnfw_w_block) + 7) \
156 	& ~7), *(int *)(new_pos) = 0)
157 
158 TNFW_B_STATUS tnfw_b_init_buffer(char *, int, int, boolean_t);
159 TNFW_B_STATUS tnfw_b_connect(TNFW_B_WCB *, volatile char *);
160 void * tnfw_b_alloc(TNFW_B_WCB *, size_t, enum tnf_alloc_mode);
161 TNFW_B_STATUS tnfw_b_xcommit(TNFW_B_WCB *);
162 TNFW_B_STATUS tnfw_b_xabort(TNFW_B_WCB *);
163 tnf_uint32_t *tnfw_b_fw_alloc(TNFW_B_WCB *);
164 void tnfw_b_release_block(TNFW_B_WCB *);
165 
166 /* Declare lock routines written in assembly language. */
167 extern int tnfw_b_get_lock(tnf_byte_lock_t *);
168 extern void tnfw_b_clear_lock(tnf_byte_lock_t *);
169 extern u_long tnfw_b_atomic_swap(uint_t *, u_long);
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif /* _TNF_BUF_H */
176