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 51991Sheppo * Common Development and Distribution License (the "License"). 61991Sheppo * 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 */ 211991Sheppo 220Sstevel@tonic-gate /* 23*11596SJason.Beloro@Sun.COM * Copyright 2010 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 #ifdef __cplusplus 310Sstevel@tonic-gate extern "C" { 320Sstevel@tonic-gate #endif 330Sstevel@tonic-gate 34911Siskreen #define LIBMD_MAGIC 0x4d61636844657363ULL /* MachDesc */ 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifndef _ASM 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* 390Sstevel@tonic-gate * Internal definitions 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * Each MD has the following header to 450Sstevel@tonic-gate * provide information about each section of the MD. 460Sstevel@tonic-gate * 470Sstevel@tonic-gate * There are 3 sections: 480Sstevel@tonic-gate * The description list, the name table and the data block. 490Sstevel@tonic-gate * 500Sstevel@tonic-gate * All values are stored in network byte order. 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * Elements in the first (description list) section are defined by their 530Sstevel@tonic-gate * index location within the node block. An index is simply the byte offset 540Sstevel@tonic-gate * within the block / element size (16bytes). All elements are refered to 550Sstevel@tonic-gate * by their index, to avoid bugs related to alignment etc. 560Sstevel@tonic-gate * 570Sstevel@tonic-gate * The name_len field holds the storage length of an ASCII name, NOT the strlen. 580Sstevel@tonic-gate * The header fields are written in network 590Sstevel@tonic-gate * byte order. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate 620Sstevel@tonic-gate struct md_header_s { 630Sstevel@tonic-gate uint32_t transport_version; 640Sstevel@tonic-gate uint32_t node_blk_sz; /* size in bytes of the node block */ 650Sstevel@tonic-gate uint32_t name_blk_sz; /* size in bytes of the name block */ 660Sstevel@tonic-gate uint32_t data_blk_sz; /* size in bytes of the data block */ 670Sstevel@tonic-gate }; 680Sstevel@tonic-gate 690Sstevel@tonic-gate typedef struct md_header_s md_header_t; 700Sstevel@tonic-gate 710Sstevel@tonic-gate 720Sstevel@tonic-gate 73*11596SJason.Beloro@Sun.COM #if defined(_BIG_ENDIAN) 740Sstevel@tonic-gate #define mdtoh8(x) ((uint8_t)(x)) 750Sstevel@tonic-gate #define mdtoh16(x) ((uint16_t)(x)) 760Sstevel@tonic-gate #define mdtoh32(x) ((uint32_t)(x)) 770Sstevel@tonic-gate #define mdtoh64(x) ((uint64_t)(x)) 780Sstevel@tonic-gate #define htomd8(x) (x) 790Sstevel@tonic-gate #define htomd16(x) (x) 800Sstevel@tonic-gate #define htomd32(x) (x) 810Sstevel@tonic-gate #define htomd64(x) (x) 820Sstevel@tonic-gate #else 830Sstevel@tonic-gate #define mdtoh8(x) ((uint8_t)(x)) 84*11596SJason.Beloro@Sun.COM #define mdtoh16(x) BSWAP_16((uint16_t)(x)) 85*11596SJason.Beloro@Sun.COM #define mdtoh32(x) BSWAP_32((uint32_t)(x)) 86*11596SJason.Beloro@Sun.COM #define mdtoh64(x) BSWAP_64((uint64_t)(x)) 870Sstevel@tonic-gate #define htomd8(x) ((uint8_t)(x)) 88*11596SJason.Beloro@Sun.COM #define htomd16(x) BSWAP_16((uint16_t)(x)) 89*11596SJason.Beloro@Sun.COM #define htomd32(x) BSWAP_32((uint32_t)(x)) 90*11596SJason.Beloro@Sun.COM #define htomd64(x) BSWAP_64((uint64_t)(x)) 910Sstevel@tonic-gate #endif 920Sstevel@tonic-gate 930Sstevel@tonic-gate 940Sstevel@tonic-gate 950Sstevel@tonic-gate struct MD_ELEMENT { 960Sstevel@tonic-gate uint8_t tag; 970Sstevel@tonic-gate uint8_t name_len; 980Sstevel@tonic-gate uint16_t _reserved; 990Sstevel@tonic-gate uint32_t name_offset; /* mde_str_cookie_t */ 1000Sstevel@tonic-gate union { 1010Sstevel@tonic-gate struct { 1020Sstevel@tonic-gate uint32_t len; 1030Sstevel@tonic-gate uint32_t offset; 1040Sstevel@tonic-gate } prop_data; /* for PROP_DATA and PROP_STR */ 1050Sstevel@tonic-gate uint64_t prop_val; /* for PROP_VAL */ 1060Sstevel@tonic-gate uint64_t prop_idx; /* for PROP_ARC and NODE */ 1070Sstevel@tonic-gate } d; 1080Sstevel@tonic-gate }; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate typedef struct MD_ELEMENT md_element_t; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate struct MACHINE_DESCRIPTION { 1130Sstevel@tonic-gate caddr_t caddr; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate void *(*allocp)(size_t); 1161991Sheppo void (*freep)(void *, size_t); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate md_header_t *headerp; 1190Sstevel@tonic-gate md_element_t *mdep; 1200Sstevel@tonic-gate char *namep; 1210Sstevel@tonic-gate uint8_t *datap; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate int node_blk_size; 1240Sstevel@tonic-gate int name_blk_size; 1250Sstevel@tonic-gate int data_blk_size; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate int element_count; 1280Sstevel@tonic-gate int node_count; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate mde_cookie_t root_node; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate int size; 1331991Sheppo uint64_t gen; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate uint64_t md_magic; 1360Sstevel@tonic-gate }; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate typedef struct MACHINE_DESCRIPTION md_impl_t; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate #define MDE_TAG(_p) mdtoh8((_p)->tag) 1410Sstevel@tonic-gate #define MDE_NAME(_p) mdtoh32((_p)->name_offset) 1420Sstevel@tonic-gate #define MDE_NAME_LEN(_p) mdtoh32((_p)->name_len) 1430Sstevel@tonic-gate #define MDE_PROP_DATA_OFFSET(_p) mdtoh32((_p)->d.prop_data.offset) 1440Sstevel@tonic-gate #define MDE_PROP_DATA_LEN(_p) mdtoh32((_p)->d.prop_data.len) 1450Sstevel@tonic-gate #define MDE_PROP_VALUE(_p) mdtoh64((_p)->d.prop_val) 1460Sstevel@tonic-gate #define MDE_PROP_INDEX(_p) mdtoh64((_p)->d.prop_idx) 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate extern mde_str_cookie_t md_ident_name_str(char *); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate extern mde_cookie_t md_find_node_prop(md_impl_t *, 1510Sstevel@tonic-gate mde_cookie_t, 1520Sstevel@tonic-gate mde_str_cookie_t, 1530Sstevel@tonic-gate int); 1540Sstevel@tonic-gate #endif /* _ASM */ 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate #ifdef __cplusplus 1570Sstevel@tonic-gate } 1580Sstevel@tonic-gate #endif 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #endif /* _MDESC_IMPL_H_ */ 161