xref: /titanic_52/usr/src/uts/common/sys/mdesc_impl.h (revision fc256490629fe68815f7e0f23cf9b3545720cfac)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
211ae08745Sheppo 
227c478bd9Sstevel@tonic-gate /*
23*fc256490SJason Beloro  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_MDESC_IMPL_H_
287c478bd9Sstevel@tonic-gate #define	_MDESC_IMPL_H_
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
340bd5614cSiskreen #define	LIBMD_MAGIC	0x4d61636844657363ULL	/* MachDesc */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifndef _ASM
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate 	/*
397c478bd9Sstevel@tonic-gate 	 * Internal definitions
407c478bd9Sstevel@tonic-gate 	 */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * Each MD has the following header to
457c478bd9Sstevel@tonic-gate  * provide information about each section of the MD.
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  * There are 3 sections:
487c478bd9Sstevel@tonic-gate  * The description list, the name table and the data block.
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  * All values are stored in network byte order.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * Elements in the first (description list) section are defined by their
537c478bd9Sstevel@tonic-gate  * index location within the node block. An index is simply the byte offset
547c478bd9Sstevel@tonic-gate  * within the block / element size (16bytes). All elements are refered to
557c478bd9Sstevel@tonic-gate  * by their index, to avoid bugs related to alignment etc.
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * The name_len field holds the storage length of an ASCII name, NOT the strlen.
587c478bd9Sstevel@tonic-gate  * The header fields are written in network
597c478bd9Sstevel@tonic-gate  * byte order.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate struct md_header_s {
637c478bd9Sstevel@tonic-gate 	uint32_t	transport_version;
647c478bd9Sstevel@tonic-gate 	uint32_t	node_blk_sz;	/* size in bytes of the node block */
657c478bd9Sstevel@tonic-gate 	uint32_t	name_blk_sz;	/* size in bytes of the name block */
667c478bd9Sstevel@tonic-gate 	uint32_t	data_blk_sz;	/* size in bytes of the data block */
677c478bd9Sstevel@tonic-gate };
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate typedef struct md_header_s md_header_t;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 
73*fc256490SJason Beloro #if defined(_BIG_ENDIAN)
747c478bd9Sstevel@tonic-gate #define	mdtoh8(x)	((uint8_t)(x))
757c478bd9Sstevel@tonic-gate #define	mdtoh16(x)	((uint16_t)(x))
767c478bd9Sstevel@tonic-gate #define	mdtoh32(x)	((uint32_t)(x))
777c478bd9Sstevel@tonic-gate #define	mdtoh64(x)	((uint64_t)(x))
787c478bd9Sstevel@tonic-gate #define	htomd8(x)	(x)
797c478bd9Sstevel@tonic-gate #define	htomd16(x)	(x)
807c478bd9Sstevel@tonic-gate #define	htomd32(x)	(x)
817c478bd9Sstevel@tonic-gate #define	htomd64(x)	(x)
827c478bd9Sstevel@tonic-gate #else
837c478bd9Sstevel@tonic-gate #define	mdtoh8(x)	((uint8_t)(x))
84*fc256490SJason Beloro #define	mdtoh16(x)	BSWAP_16((uint16_t)(x))
85*fc256490SJason Beloro #define	mdtoh32(x)	BSWAP_32((uint32_t)(x))
86*fc256490SJason Beloro #define	mdtoh64(x)	BSWAP_64((uint64_t)(x))
877c478bd9Sstevel@tonic-gate #define	htomd8(x)	((uint8_t)(x))
88*fc256490SJason Beloro #define	htomd16(x)	BSWAP_16((uint16_t)(x))
89*fc256490SJason Beloro #define	htomd32(x)	BSWAP_32((uint32_t)(x))
90*fc256490SJason Beloro #define	htomd64(x)	BSWAP_64((uint64_t)(x))
917c478bd9Sstevel@tonic-gate #endif
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate struct MD_ELEMENT {
967c478bd9Sstevel@tonic-gate 	uint8_t		tag;
977c478bd9Sstevel@tonic-gate 	uint8_t		name_len;
987c478bd9Sstevel@tonic-gate 	uint16_t	_reserved;
997c478bd9Sstevel@tonic-gate 	uint32_t	name_offset;	/* mde_str_cookie_t */
1007c478bd9Sstevel@tonic-gate 	union {
1017c478bd9Sstevel@tonic-gate 		struct {
1027c478bd9Sstevel@tonic-gate 			uint32_t	len;
1037c478bd9Sstevel@tonic-gate 			uint32_t	offset;
1047c478bd9Sstevel@tonic-gate 		} prop_data;			/* for PROP_DATA and PROP_STR */
1057c478bd9Sstevel@tonic-gate 		uint64_t	prop_val;	/* for PROP_VAL */
1067c478bd9Sstevel@tonic-gate 		uint64_t	prop_idx;	/* for PROP_ARC and NODE */
1077c478bd9Sstevel@tonic-gate 	} d;
1087c478bd9Sstevel@tonic-gate };
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate typedef struct MD_ELEMENT md_element_t;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate struct MACHINE_DESCRIPTION {
1137c478bd9Sstevel@tonic-gate 	caddr_t		caddr;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	void		*(*allocp)(size_t);
11626cf27f0Sla135387 	void		(*freep)(void *, size_t);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	md_header_t	*headerp;
1197c478bd9Sstevel@tonic-gate 	md_element_t	*mdep;
1207c478bd9Sstevel@tonic-gate 	char		*namep;
1217c478bd9Sstevel@tonic-gate 	uint8_t		*datap;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	int		node_blk_size;
1247c478bd9Sstevel@tonic-gate 	int		name_blk_size;
1257c478bd9Sstevel@tonic-gate 	int		data_blk_size;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	int		element_count;
1287c478bd9Sstevel@tonic-gate 	int		node_count;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	mde_cookie_t	root_node;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	int		size;
1331ae08745Sheppo 	uint64_t	gen;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	uint64_t	md_magic;
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate typedef struct MACHINE_DESCRIPTION md_impl_t;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	MDE_TAG(_p)			mdtoh8((_p)->tag)
1417c478bd9Sstevel@tonic-gate #define	MDE_NAME(_p)			mdtoh32((_p)->name_offset)
1427c478bd9Sstevel@tonic-gate #define	MDE_NAME_LEN(_p)		mdtoh32((_p)->name_len)
1437c478bd9Sstevel@tonic-gate #define	MDE_PROP_DATA_OFFSET(_p)	mdtoh32((_p)->d.prop_data.offset)
1447c478bd9Sstevel@tonic-gate #define	MDE_PROP_DATA_LEN(_p)		mdtoh32((_p)->d.prop_data.len)
1457c478bd9Sstevel@tonic-gate #define	MDE_PROP_VALUE(_p)		mdtoh64((_p)->d.prop_val)
1467c478bd9Sstevel@tonic-gate #define	MDE_PROP_INDEX(_p)		mdtoh64((_p)->d.prop_idx)
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate extern mde_str_cookie_t md_ident_name_str(char *);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate extern mde_cookie_t	md_find_node_prop(md_impl_t *,
1517c478bd9Sstevel@tonic-gate 				mde_cookie_t,
1527c478bd9Sstevel@tonic-gate 				mde_str_cookie_t,
1537c478bd9Sstevel@tonic-gate 				int);
1547c478bd9Sstevel@tonic-gate #endif	/* _ASM */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate #endif
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #endif	/* _MDESC_IMPL_H_ */
161