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
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]
23 * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
34 /* ========================================================================= */
35 /* Ancestor object definitions. */
37 Ancestor::Ancestor(Str field
, fru_tag_t t
, const fru_regdef_t
*d
)
45 offsets
= (uint32_t *)malloc(sizeof (uint32_t)
46 * ANCESTOR_INST_BUF_SIZE
);
47 paths
= (char **)malloc(sizeof (char *)
48 * ANCESTOR_INST_BUF_SIZE
);
55 for (int i
= 0; i
< numInstances
; i
++) {
67 fprintf(stderr, "Ancestor Information\n");
68 fprintf(stderr, "Tag Name: %s\n", def->name);
69 fprintf(stderr, "Tag Type: %s\n",
70 get_tagtype_str(get_tag_type(&tag)));
71 fprintf(stderr, "Num instances: %d\n", numInstances);
72 fprintf(stderr, " offsets:\n");
73 for (int i = 0; i < numInstances; i++) {
74 fprintf(stderr, " %d\n", offsets[i]);
84 Ancestor::addInstance(const char *path
, uint32_t offset
)
86 if (numInstances
>= ANCESTOR_INST_BUF_SIZE
) {
88 offsets
= (uint32_t *)realloc(offsets
,
90 (ANCESTOR_INST_BUF_SIZE
* numBufs
)));
91 paths
= (char **)realloc(offsets
,
93 (ANCESTOR_INST_BUF_SIZE
* numBufs
)));
95 offsets
[numInstances
] = offset
;
96 paths
[numInstances
++] = strdup(path
);
100 Ancestor::getFieldName(void)
106 Ancestor::getTag(void)
112 Ancestor::getDef(void)
118 Ancestor::getNumInstances(void)
120 return (numInstances
);
124 Ancestor::getInstOffset(int num
)
126 if (num
< numInstances
)
127 return (offsets
[num
]);
129 return (offsets
[numInstances
]);
133 Ancestor::getPath(int num
)
135 if (num
< numInstances
)
138 return (paths
[numInstances
]);
143 Ancestor::listTaggedAncestors(char *element
)
146 fru_regdef_t
*def
= NULL
;
149 unsigned int number
= 0;
150 char **data_elems
= fru_reg_list_entries(&number
);
152 if (data_elems
== NULL
) {
156 // look through all the elements.
157 for (i
= 0; i
< number
; i
++) {
158 def
= (fru_regdef_t
*)
159 fru_reg_lookup_def_by_name(data_elems
[i
]);
160 Ancestor
*ant
= createTaggedAncestor(def
, element
);
166 while (tmp
->next
!= NULL
) {
174 for (i
= 0; i
< number
; i
++) {
183 Ancestor::createTaggedAncestor(const fru_regdef_t
*def
, Str element
)
185 // ancestors have to be tagged.
186 if (def
->tagType
== FRU_X
)
190 mk_tag(def
->tagType
, def
->tagDense
, def
->payloadLen
, &tag
);
191 Ancestor
*rc
= new Ancestor(element
, tag
, def
);
193 if (element
.compare(def
->name
) == 0) {
194 rc
->addInstance("", 0);
199 if (def
->dataType
== FDTYPE_Record
) {
201 for (int i
= 0; i
< def
->enumCount
; i
++) {
202 const fru_regdef_t
*tmp
203 = fru_reg_lookup_def_by_name
204 ((char *)def
->enumTable
[i
].text
);
207 int f
= definitionContains(tmp
, def
, element
,
209 if (f
== 1) found
= 1; // found needs to latch at one.
210 offset
+= tmp
->payloadLen
;
223 Ancestor::definitionContains(const fru_regdef_t
*def
,
224 const fru_regdef_t
*parent_def
,
230 if (element
.compare(def
->name
) == 0) {
231 if (parent_def
->iterationType
!= FRU_NOT_ITERATED
) {
233 for (int i
= 0; i
< parent_def
->iterationCount
; i
++) {
235 tmp
<< "[" << i
<< "]/";
236 ant
->addInstance(tmp
.peak(), offset
);
237 offset
+= (parent_def
->payloadLen
- 4) /
238 parent_def
->iterationCount
;
242 ant
->addInstance(path
.peak(), offset
);
248 if (def
->dataType
== FDTYPE_Record
) {
249 for (int i
= 0; i
< def
->enumCount
; i
++) {
250 const fru_regdef_t
*tmp
251 = fru_reg_lookup_def_by_name
252 ((char *)def
->enumTable
[i
].text
);
254 newPath
<< "/" << def
->name
;
255 int f
= definitionContains(tmp
, def
, element
,
256 offset
, ant
, newPath
);
257 if (f
== 1) found
= 1; // found needs to latch at one.
258 offset
+= tmp
->payloadLen
;