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 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _FRU_ACCESS_IMPL_H 28 #define _FRU_ACCESS_IMPL_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #include <stdlib.h> 35 #include <stdio.h> 36 #include <sys/types.h> 37 #include <unistd.h> 38 #include <sys/stat.h> 39 #include <fcntl.h> 40 #include <dial.h> 41 #include <strings.h> 42 #include <libdevinfo.h> 43 #include <sys/systeminfo.h> 44 #include <picl.h> 45 #include <picltree.h> 46 #include <picldefs.h> 47 #include <syslog.h> 48 #include <errno.h> 49 #include <libfru.h> 50 #include <limits.h> 51 #include <fru_tag.h> 52 #include "fru_access.h" 53 #include "spd_data.h" 54 55 /* object types */ 56 typedef enum {CONTAINER_TYPE, SECTION_TYPE, SEGMENT_TYPE, PACKET_TYPE} object_t; 57 58 #define TABLE_SIZE 64 /* hash table size */ 59 60 /* container configuration file name */ 61 #define FRU_CONTAINER_CONF "fru_container.conf" 62 #define CONTAINER_DIR "/usr/platform/sun4u/lib" 63 64 /* section header */ 65 #define SECTION_HDR_TAG 0x08 66 #define SECTION_HDR_VER 0x0001 67 #define SECTION_HDR_LENGTH 0x06 68 #define SECTION_HDR_CRC8 0x00 69 #define SECTION_HDR_VER_BIT0 0x00 70 #define SECTION_HDR_VER_BIT1 0x01 71 72 #define READ_ONLY_SECTION 1 /* section is read-only */ 73 74 #define GET_SEGMENT_DESCRIPTOR \ 75 (seg_layout->descriptor[1]|seg_layout->descriptor[0] << 16) 76 77 #define GET_SECTION_HDR_VERSION \ 78 (sec_hdr.headerversion[1]|sec_hdr.headerversion[0] << 8) 79 80 /* Segment Trailer Tag */ 81 #define SEG_TRAILER_TAG 0x0C 82 83 /* defines fixed segment */ 84 #define SEGMENT_FIXED 1 85 86 typedef union { 87 uint32_t all_bits; 88 struct { 89 unsigned read_only : 1; 90 unsigned unused : 8; 91 unsigned : 8; 92 unsigned : 8; 93 unsigned : 7; 94 } field; 95 } sectdescbit_t; 96 97 typedef enum { 98 ENC_STANDARD = 0, /* proper fruid data */ 99 ENC_SPD /* serial presence detect data */ 100 } sectencoding_t; 101 102 typedef struct { 103 sectdescbit_t description; 104 uint32_t address; /* for SEEPROMS this is the offset */ 105 uint32_t size; 106 sectencoding_t encoding; 107 } sectioninfo_t; 108 109 typedef uint16_t headerrev_t; 110 111 #define MAX_NUMOF_SECTION 2 112 113 typedef struct { 114 headerrev_t header_ver; 115 int num_sections; 116 sectioninfo_t section_info[MAX_NUMOF_SECTION]; 117 } container_info_t; 118 119 120 /* section header layout */ 121 typedef struct { 122 uint8_t headertag; /* section header tag */ 123 uint8_t headerversion[2]; /* header version (msb) */ 124 uint8_t headerlength; /* header length */ 125 uint8_t headercrc8; /* crc8 */ 126 uint8_t segmentcount; /* total number of segment */ 127 } section_layout_t; 128 129 /* segment header layout */ 130 typedef struct { 131 uint16_t name; /* segment name */ 132 uint16_t descriptor[2]; /* descriptor (msb) */ 133 uint16_t offset; /* segment data offset */ 134 uint16_t length; /* segment length */ 135 } segment_layout_t; 136 137 /* segment information used in finding new offset for a new segment */ 138 typedef struct { 139 int segnum; /* segment number */ 140 int offset; /* segment offset */ 141 int length; /* segment length */ 142 int fixed; /* fixed or non-fixed segment */ 143 } seg_info_t; 144 145 typedef uint64_t handle_t; 146 147 struct hash_obj; 148 149 /* packet hash object */ 150 typedef struct { 151 handle_t segment_hdl; /* segment handle */ 152 fru_tag_t tag; 153 int tag_size; 154 uint8_t *payload; 155 uint32_t paylen; 156 uint32_t payload_offset; 157 struct hash_obj *next; 158 } packet_obj_t; 159 160 /* segment hash object */ 161 typedef struct { 162 handle_t section_hdl; /* section handle */ 163 int num_of_packets; /* in a segment */ 164 int trailer_offset; 165 segment_t segment; 166 struct hash_obj *pkt_obj_list; /* packet object list */ 167 struct hash_obj *next; 168 } segment_obj_t; 169 170 /* section hash object */ 171 typedef struct { 172 handle_t cont_hdl; /* container handle */ 173 section_t section; 174 sectencoding_t encoding; /* standard or needing interpretation */ 175 int num_of_segment; /* in a section */ 176 struct hash_obj *seg_obj_list; /* points to segment objects list */ 177 struct hash_obj *next; 178 } section_obj_t; 179 180 /* container hash object */ 181 typedef struct { 182 char device_pathname[PATH_MAX]; /* device name */ 183 int num_of_section; /* num of section in container */ 184 struct hash_obj *sec_obj_list; /* points to section objects list */ 185 } container_obj_t; 186 187 /* hash object */ 188 typedef struct hash_obj { 189 int object_type; 190 handle_t obj_hdl; 191 union { 192 container_obj_t *cont_obj; 193 section_obj_t *sec_obj; 194 segment_obj_t *seg_obj; 195 packet_obj_t *pkt_obj; 196 } u; 197 struct hash_obj *next; 198 struct hash_obj *prev; 199 } hash_obj_t; 200 201 unsigned char compute_crc8(unsigned char *bytes, int length); 202 long compute_crc32(unsigned char *bytes, int length); 203 long compute_checksum32(unsigned char *bytes, int length); 204 205 #ifdef __cplusplus 206 } 207 #endif 208 209 #endif /* _FRU_ACCESS_IMPL_H */ 210