xref: /titanic_51/usr/src/uts/common/sys/mdesc_impl.h (revision 814a60b13c0ad90e5d2edfd29a7a84bbf416cc1a)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_MDESC_IMPL_H_
28 #define	_MDESC_IMPL_H_
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define	LIBMD_MAGIC	0x4d61636844657363	/* MachDesc */
37 
38 #ifndef _ASM
39 
40 	/*
41 	 * Internal definitions
42 	 */
43 
44 
45 /*
46  * Each MD has the following header to
47  * provide information about each section of the MD.
48  *
49  * There are 3 sections:
50  * The description list, the name table and the data block.
51  *
52  * All values are stored in network byte order.
53  *
54  * Elements in the first (description list) section are defined by their
55  * index location within the node block. An index is simply the byte offset
56  * within the block / element size (16bytes). All elements are refered to
57  * by their index, to avoid bugs related to alignment etc.
58  *
59  * The name_len field holds the storage length of an ASCII name, NOT the strlen.
60  * The header fields are written in network
61  * byte order.
62  */
63 
64 struct md_header_s {
65 	uint32_t	transport_version;
66 	uint32_t	node_blk_sz;	/* size in bytes of the node block */
67 	uint32_t	name_blk_sz;	/* size in bytes of the name block */
68 	uint32_t	data_blk_sz;	/* size in bytes of the data block */
69 };
70 
71 typedef struct md_header_s md_header_t;
72 
73 
74 
75 #if defined(_BIG_ENDIAN) && !defined(lint)
76 #define	mdtoh8(x)	((uint8_t)(x))
77 #define	mdtoh16(x)	((uint16_t)(x))
78 #define	mdtoh32(x)	((uint32_t)(x))
79 #define	mdtoh64(x)	((uint64_t)(x))
80 #define	htomd8(x)	(x)
81 #define	htomd16(x)	(x)
82 #define	htomd32(x)	(x)
83 #define	htomd64(x)	(x)
84 #else
85 #define	mdtoh8(x)	((uint8_t)(x))
86 extern	uint16_t	mdtoh16(uint16_t);
87 extern	uint32_t	mdtoh32(uint32_t);
88 extern	uint64_t	mdtoh64(uint64_t);
89 #define	htomd8(x)	((uint8_t)(x))
90 extern	uint16_t	htomd16(uint16_t);
91 extern	uint32_t	htomd32(uint32_t);
92 extern	uint64_t	htomd64(uint64_t);
93 #endif
94 
95 
96 
97 struct MD_ELEMENT {
98 	uint8_t		tag;
99 	uint8_t		name_len;
100 	uint16_t	_reserved;
101 	uint32_t	name_offset;	/* mde_str_cookie_t */
102 	union {
103 		struct {
104 			uint32_t	len;
105 			uint32_t	offset;
106 		} prop_data;			/* for PROP_DATA and PROP_STR */
107 		uint64_t	prop_val;	/* for PROP_VAL */
108 		uint64_t	prop_idx;	/* for PROP_ARC and NODE */
109 	} d;
110 };
111 
112 typedef struct MD_ELEMENT md_element_t;
113 
114 struct MACHINE_DESCRIPTION {
115 	caddr_t		caddr;
116 
117 	void		*(*allocp)(size_t);
118 	void		(*freep)(void*, size_t);
119 
120 	md_header_t	*headerp;
121 	md_element_t	*mdep;
122 	char		*namep;
123 	uint8_t		*datap;
124 
125 	int		node_blk_size;
126 	int		name_blk_size;
127 	int		data_blk_size;
128 
129 	int		element_count;
130 	int		node_count;
131 
132 	mde_cookie_t	root_node;
133 
134 	int		size;
135 
136 	uint64_t	md_magic;
137 };
138 
139 typedef struct MACHINE_DESCRIPTION md_impl_t;
140 
141 #define	MDE_TAG(_p)			mdtoh8((_p)->tag)
142 #define	MDE_NAME(_p)			mdtoh32((_p)->name_offset)
143 #define	MDE_NAME_LEN(_p)		mdtoh32((_p)->name_len)
144 #define	MDE_PROP_DATA_OFFSET(_p)	mdtoh32((_p)->d.prop_data.offset)
145 #define	MDE_PROP_DATA_LEN(_p)		mdtoh32((_p)->d.prop_data.len)
146 #define	MDE_PROP_VALUE(_p)		mdtoh64((_p)->d.prop_val)
147 #define	MDE_PROP_INDEX(_p)		mdtoh64((_p)->d.prop_idx)
148 
149 extern mde_str_cookie_t md_ident_name_str(char *);
150 
151 extern mde_cookie_t	md_find_node_prop(md_impl_t *,
152 				mde_cookie_t,
153 				mde_str_cookie_t,
154 				int);
155 
156 #endif	/* _ASM */
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif	/* _MDESC_IMPL_H_ */
163