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