xref: /titanic_52/usr/src/uts/common/io/xge/hal/include/xge-os-pal.h (revision 7eced415e5dd557aef2d78483b5a7785f0e13670)
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  * Copyright (c) 2002-2006 Neterion, Inc.
22  */
23 
24 #ifndef XGE_OS_PAL_H
25 #define XGE_OS_PAL_H
26 
27 #include "xge-defs.h"
28 
29 __EXTERN_BEGIN_DECLS
30 
31 /*--------------------------- platform switch ------------------------------*/
32 
33 /* platform specific header */
34 #include "xge_osdep.h"
35 
36 #if !defined(XGE_OS_PLATFORM_64BIT) && !defined(XGE_OS_PLATFORM_32BIT)
37 #error "either 32bit or 64bit switch must be defined!"
38 #endif
39 
40 #if !defined(XGE_OS_HOST_BIG_ENDIAN) && !defined(XGE_OS_HOST_LITTLE_ENDIAN)
41 #error "either little endian or big endian switch must be defined!"
42 #endif
43 
44 #if defined(XGE_OS_PLATFORM_64BIT)
45 #define XGE_OS_MEMORY_DEADCODE_PAT	0x5a5a5a5a5a5a5a5a
46 #else
47 #define XGE_OS_MEMORY_DEADCODE_PAT	0x5a5a5a5a
48 #endif
49 
50 #define XGE_OS_TRACE_MSGBUF_MAX		512
51 typedef struct xge_os_tracebuf_t {
52 	int		wrapped_once;     /* circular buffer been wrapped */
53 	int		timestamp;        /* whether timestamps are enabled */
54 	volatile int	offset;           /* offset within the tracebuf */
55 	int		size;             /* total size of trace buffer */
56 	char		msg[XGE_OS_TRACE_MSGBUF_MAX]; /* each individual buffer */
57 	int		msgbuf_max;	  /* actual size of msg buffer */
58 	char		*data;            /* pointer to data buffer */
59 } xge_os_tracebuf_t;
60 extern xge_os_tracebuf_t *g_xge_os_tracebuf;
61 
62 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
63 extern xge_os_tracebuf_t *g_xge_os_tracebuf;
64 extern char *dmesg_start;
65 
66 /* Calculate the size of the msg and copy it into the global buffer */
67 #define __xge_trace(tb) { \
68 	int msgsize = xge_os_strlen(tb->msg) + 2; \
69 	int offset = tb->offset; \
70 	if (msgsize != 2 && msgsize < tb->msgbuf_max) { \
71 		int leftsize =  tb->size - offset; \
72 		if ((msgsize + tb->msgbuf_max) > leftsize) { \
73 			xge_os_memzero(tb->data + offset, leftsize); \
74 			offset = 0; \
75 			tb->wrapped_once = 1; \
76 		} \
77 		xge_os_memcpy(tb->data + offset, tb->msg, msgsize-1); \
78 		*(tb->data + offset + msgsize-1) = '\n'; \
79 		*(tb->data + offset + msgsize) = 0; \
80 		offset += msgsize; \
81 		tb->offset = offset; \
82 		dmesg_start = tb->data + offset; \
83 		*tb->msg = 0; \
84 	} \
85 }
86 
87 #define xge_os_vatrace(tb, fmt) { \
88 	if (tb != NULL) { \
89 		char *_p = tb->msg; \
90 		if (tb->timestamp) { \
91 			xge_os_timestamp(tb->msg); \
92 			_p = tb->msg + xge_os_strlen(tb->msg); \
93 		} \
94 		xge_os_vasprintf(_p, fmt); \
95 		__xge_trace(tb); \
96 	} \
97 }
98 
99 #ifdef __GNUC__
100 #define xge_os_trace(tb, fmt...) { \
101 	int msgsize = xge_os_strlen(tb->msg); \
102 	if (tb != NULL) { \
103 		if (tb->timestamp) { \
104 			xge_os_timestamp(tb->msg); \
105 		} \
106 		xge_os_snprintf(tb->msg + msgsize, \
107 		    (sizeof(tb->msg) - msgsize)), \
108 		    fmt); \
109 		__xge_trace(tb); \
110 	} \
111 }
112 #endif /* __GNUC__ */
113 
114 #else
115 #define xge_os_vatrace(tb, fmt)
116 #ifdef __GNUC__
117 #define xge_os_trace(tb, fmt...)
118 #endif /* __GNUC__ */
119 #endif
120 
121 __EXTERN_END_DECLS
122 
123 #endif /* XGE_OS_PAL_H */
124