ses: SUN plugin doesn't actually need libnvfru
[unleashed/lotheac.git] / usr / src / lib / libfru / libfruraw / fru_access_impl.h
blob4260a59734496f627d512d9d66f0a5f1d9fe01e2
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _FRU_ACCESS_IMPL_H
28 #define _FRU_ACCESS_IMPL_H
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
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 <strings.h>
41 #include <libdevinfo.h>
42 #include <sys/systeminfo.h>
43 #include <sys/byteorder.h>
44 #include <syslog.h>
45 #include <errno.h>
46 #include <libfru.h>
47 #include <limits.h>
48 #include <fru_tag.h>
49 #include <fru_access.h>
52 /* object types */
53 typedef enum {CONTAINER_TYPE, SECTION_TYPE, SEGMENT_TYPE, PACKET_TYPE} object_t;
55 #define TABLE_SIZE 64 /* hash table size */
58 /* section header */
59 #define SECTION_HDR_TAG 0x08
60 #define SECTION_HDR_VER 0x0001
61 #define SECTION_HDR_LENGTH 0x06
62 #define SECTION_HDR_CRC8 0x00
63 #define SECTION_HDR_VER_BIT0 0x00
64 #define SECTION_HDR_VER_BIT1 0x01
66 #define READ_ONLY_SECTION 1 /* section is read-only */
68 #define GET_SEGMENT_DESCRIPTOR \
69 (BE_16(seg_layout->descriptor[1])| \
70 BE_16(seg_layout->descriptor[0] << 16))
72 #define GET_SECTION_HDR_VERSION \
73 (sec_hdr.headerversion[1]|sec_hdr.headerversion[0] << 8)
75 /* Segment Trailer Tag */
76 #define SEG_TRAILER_TAG 0x0C
78 /* defines fixed segment */
79 #define SEGMENT_FIXED 1
81 typedef union {
82 uint32_t all_bits;
83 struct {
84 unsigned read_only : 1;
85 unsigned unused : 8;
86 unsigned : 8;
87 unsigned : 8;
88 unsigned : 7;
89 } field;
90 } sectdescbit_t;
92 typedef enum {
93 ENC_STANDARD = 0, /* proper fruid data */
94 ENC_SPD /* serial presence detect data */
95 } sectencoding_t;
97 typedef struct {
98 sectdescbit_t description;
99 uint32_t address; /* for SEEPROMS this is the offset */
100 uint32_t size;
101 sectencoding_t encoding;
102 } sectioninfo_t;
104 typedef uint16_t headerrev_t;
106 #define MAX_NUMOF_SECTION 2
108 typedef struct {
109 headerrev_t header_ver;
110 int num_sections;
111 sectioninfo_t section_info[MAX_NUMOF_SECTION];
112 } container_info_t;
115 /* section header layout */
116 typedef struct {
117 uint8_t headertag; /* section header tag */
118 uint8_t headerversion[2]; /* header version (msb) */
119 uint8_t headerlength; /* header length */
120 uint8_t headercrc8; /* crc8 */
121 uint8_t segmentcount; /* total number of segment */
122 } section_layout_t;
124 /* segment header layout */
125 typedef struct {
126 uint16_t name; /* segment name */
127 uint16_t descriptor[2]; /* descriptor (msb) */
128 uint16_t offset; /* segment data offset */
129 uint16_t length; /* segment length */
130 } segment_layout_t;
132 /* segment information used in finding new offset for a new segment */
133 typedef struct {
134 int segnum; /* segment number */
135 int offset; /* segment offset */
136 int length; /* segment length */
137 int fixed; /* fixed or non-fixed segment */
138 } seg_info_t;
140 typedef uint64_t handle_t;
142 struct hash_obj;
144 /* packet hash object */
145 typedef struct {
146 handle_t segment_hdl; /* segment handle */
147 fru_tag_t tag;
148 int tag_size;
149 uint8_t *payload;
150 uint32_t paylen;
151 uint32_t payload_offset;
152 struct hash_obj *next;
153 } packet_obj_t;
155 /* segment hash object */
156 typedef struct {
157 handle_t section_hdl; /* section handle */
158 int num_of_packets; /* in a segment */
159 int trailer_offset;
160 segment_t segment;
161 struct hash_obj *pkt_obj_list; /* packet object list */
162 struct hash_obj *next;
163 } segment_obj_t;
165 /* section hash object */
166 typedef struct {
167 handle_t cont_hdl; /* container handle */
168 section_t section;
169 sectencoding_t encoding; /* standard or needing interpretation */
170 int num_of_segment; /* in a section */
171 struct hash_obj *seg_obj_list; /* points to segment objects list */
172 struct hash_obj *next;
173 } section_obj_t;
175 /* container hash object */
176 typedef struct {
177 char device_pathname[PATH_MAX]; /* device name */
178 int num_of_section; /* num of section in container */
179 struct hash_obj *sec_obj_list; /* points to section objects list */
180 } container_obj_t;
182 /* hash object */
183 typedef struct hash_obj {
184 int object_type;
185 handle_t obj_hdl;
186 union {
187 container_obj_t *cont_obj;
188 section_obj_t *sec_obj;
189 segment_obj_t *seg_obj;
190 packet_obj_t *pkt_obj;
191 } u;
192 struct hash_obj *next;
193 struct hash_obj *prev;
194 } hash_obj_t;
196 unsigned char compute_crc8(unsigned char *bytes, int length);
197 long compute_crc32(unsigned char *bytes, int length);
198 long compute_checksum32(unsigned char *bytes, int length);
200 #ifdef __cplusplus
202 #endif
204 #endif /* _FRU_ACCESS_IMPL_H */