10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1991Sheppo * Common Development and Distribution License (the "License"). 6*1991Sheppo * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*1991Sheppo 220Sstevel@tonic-gate /* 23*1991Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _MDESC_IMPL_H_ 280Sstevel@tonic-gate #define _MDESC_IMPL_H_ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 36911Siskreen #define LIBMD_MAGIC 0x4d61636844657363ULL /* MachDesc */ 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifndef _ASM 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * Internal definitions 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * Each MD has the following header to 470Sstevel@tonic-gate * provide information about each section of the MD. 480Sstevel@tonic-gate * 490Sstevel@tonic-gate * There are 3 sections: 500Sstevel@tonic-gate * The description list, the name table and the data block. 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * All values are stored in network byte order. 530Sstevel@tonic-gate * 540Sstevel@tonic-gate * Elements in the first (description list) section are defined by their 550Sstevel@tonic-gate * index location within the node block. An index is simply the byte offset 560Sstevel@tonic-gate * within the block / element size (16bytes). All elements are refered to 570Sstevel@tonic-gate * by their index, to avoid bugs related to alignment etc. 580Sstevel@tonic-gate * 590Sstevel@tonic-gate * The name_len field holds the storage length of an ASCII name, NOT the strlen. 600Sstevel@tonic-gate * The header fields are written in network 610Sstevel@tonic-gate * byte order. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate 640Sstevel@tonic-gate struct md_header_s { 650Sstevel@tonic-gate uint32_t transport_version; 660Sstevel@tonic-gate uint32_t node_blk_sz; /* size in bytes of the node block */ 670Sstevel@tonic-gate uint32_t name_blk_sz; /* size in bytes of the name block */ 680Sstevel@tonic-gate uint32_t data_blk_sz; /* size in bytes of the data block */ 690Sstevel@tonic-gate }; 700Sstevel@tonic-gate 710Sstevel@tonic-gate typedef struct md_header_s md_header_t; 720Sstevel@tonic-gate 730Sstevel@tonic-gate 740Sstevel@tonic-gate 750Sstevel@tonic-gate #if defined(_BIG_ENDIAN) && !defined(lint) 760Sstevel@tonic-gate #define mdtoh8(x) ((uint8_t)(x)) 770Sstevel@tonic-gate #define mdtoh16(x) ((uint16_t)(x)) 780Sstevel@tonic-gate #define mdtoh32(x) ((uint32_t)(x)) 790Sstevel@tonic-gate #define mdtoh64(x) ((uint64_t)(x)) 800Sstevel@tonic-gate #define htomd8(x) (x) 810Sstevel@tonic-gate #define htomd16(x) (x) 820Sstevel@tonic-gate #define htomd32(x) (x) 830Sstevel@tonic-gate #define htomd64(x) (x) 840Sstevel@tonic-gate #else 850Sstevel@tonic-gate #define mdtoh8(x) ((uint8_t)(x)) 860Sstevel@tonic-gate extern uint16_t mdtoh16(uint16_t); 870Sstevel@tonic-gate extern uint32_t mdtoh32(uint32_t); 880Sstevel@tonic-gate extern uint64_t mdtoh64(uint64_t); 890Sstevel@tonic-gate #define htomd8(x) ((uint8_t)(x)) 900Sstevel@tonic-gate extern uint16_t htomd16(uint16_t); 910Sstevel@tonic-gate extern uint32_t htomd32(uint32_t); 920Sstevel@tonic-gate extern uint64_t htomd64(uint64_t); 930Sstevel@tonic-gate #endif 940Sstevel@tonic-gate 950Sstevel@tonic-gate 960Sstevel@tonic-gate 970Sstevel@tonic-gate struct MD_ELEMENT { 980Sstevel@tonic-gate uint8_t tag; 990Sstevel@tonic-gate uint8_t name_len; 1000Sstevel@tonic-gate uint16_t _reserved; 1010Sstevel@tonic-gate uint32_t name_offset; /* mde_str_cookie_t */ 1020Sstevel@tonic-gate union { 1030Sstevel@tonic-gate struct { 1040Sstevel@tonic-gate uint32_t len; 1050Sstevel@tonic-gate uint32_t offset; 1060Sstevel@tonic-gate } prop_data; /* for PROP_DATA and PROP_STR */ 1070Sstevel@tonic-gate uint64_t prop_val; /* for PROP_VAL */ 1080Sstevel@tonic-gate uint64_t prop_idx; /* for PROP_ARC and NODE */ 1090Sstevel@tonic-gate } d; 1100Sstevel@tonic-gate }; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate typedef struct MD_ELEMENT md_element_t; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate struct MACHINE_DESCRIPTION { 1150Sstevel@tonic-gate caddr_t caddr; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate void *(*allocp)(size_t); 118*1991Sheppo void (*freep)(void *, size_t); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate md_header_t *headerp; 1210Sstevel@tonic-gate md_element_t *mdep; 1220Sstevel@tonic-gate char *namep; 1230Sstevel@tonic-gate uint8_t *datap; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate int node_blk_size; 1260Sstevel@tonic-gate int name_blk_size; 1270Sstevel@tonic-gate int data_blk_size; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate int element_count; 1300Sstevel@tonic-gate int node_count; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate mde_cookie_t root_node; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate int size; 135*1991Sheppo uint64_t gen; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate uint64_t md_magic; 1380Sstevel@tonic-gate }; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate typedef struct MACHINE_DESCRIPTION md_impl_t; 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate #define MDE_TAG(_p) mdtoh8((_p)->tag) 1430Sstevel@tonic-gate #define MDE_NAME(_p) mdtoh32((_p)->name_offset) 1440Sstevel@tonic-gate #define MDE_NAME_LEN(_p) mdtoh32((_p)->name_len) 1450Sstevel@tonic-gate #define MDE_PROP_DATA_OFFSET(_p) mdtoh32((_p)->d.prop_data.offset) 1460Sstevel@tonic-gate #define MDE_PROP_DATA_LEN(_p) mdtoh32((_p)->d.prop_data.len) 1470Sstevel@tonic-gate #define MDE_PROP_VALUE(_p) mdtoh64((_p)->d.prop_val) 1480Sstevel@tonic-gate #define MDE_PROP_INDEX(_p) mdtoh64((_p)->d.prop_idx) 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate extern mde_str_cookie_t md_ident_name_str(char *); 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate extern mde_cookie_t md_find_node_prop(md_impl_t *, 1530Sstevel@tonic-gate mde_cookie_t, 1540Sstevel@tonic-gate mde_str_cookie_t, 1550Sstevel@tonic-gate int); 1560Sstevel@tonic-gate #endif /* _ASM */ 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate #ifdef __cplusplus 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate #endif 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate #endif /* _MDESC_IMPL_H_ */ 163