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