1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Sun4v Platform specific functions.
*
* called when :
* machine_type == ontario
*
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <kstat.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <libintl.h>
#include <note.h>
#include <sys/systeminfo.h>
#include <sys/openpromio.h>
#include <sys/sysmacros.h>
#include <picl.h>
#include "picldefs.h"
#include <pdevinfo.h>
#include <display.h>
#include <display_sun4v.h>
#include <libprtdiag.h>
#include "ontario.h"
#include "erie.h"
#include "pelton.h"
#include "stpaul.h"
#include "huron.h"
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
/*
* these functions will overlay the symbol table of libprtdiag
* at runtime
*/
void sun4v_display_pci(picl_nodehdl_t plafh);
void sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh);
/* local functions */
static void sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh);
static int ontario_pci_callback(picl_nodehdl_t pcih, void *args);
static int ontario_get_first_compatible_value(picl_nodehdl_t nodeh,
char **outbuf);
static int64_t ontario_get_int_propval(picl_nodehdl_t modh, char *prop_name,
int *ret);
static void
get_bus_type(char *path, struct io_card *card)
{
if (strncmp(path, PCIX_SLOT0, PCIX_COMP_NUM) == 0) {
(void) strcpy(card->bus_type, "PCIX");
} else {
(void) strcpy(card->bus_type, "PCIE");
}
}
static void
get_slot_number(picl_nodehdl_t nodeh, char *path, struct io_card *card)
{
if (strncmp(path, PCIE_SLOT0, PCIE_COMP_NUM) == 0) {
(void) strcpy(card->slot_str, "0");
card->slot = 0;
} else if (strncmp(path, PCIE_SLOT1, PCIE_COMP_NUM) == 0) {
(void) strcpy(card->slot_str, "1");
card->slot = 1;
} else if (strncmp(path, PCIE_SLOT2, PCIE_COMP_NUM) == 0) {
(void) strcpy(card->slot_str, "2");
card->slot = 2;
} else if ((strncmp(path, PCIX_SLOT1, strlen(PCIX_SLOT1)) == 0) ||
(strncmp(path, PCIX_SLOT0, strlen(PCIX_SLOT0)) == 0)) {
char ua[MAXSTRLEN];
int err;
(void) strcpy(card->slot_str, "PCIX");
card->slot = -1;
/*
* PCIX_SLOT0 and PCIX_SLOT1 are actually the same path so
* use the unit address to distinguish the slot number.
*/
err = picl_get_propval_by_name(nodeh, PICL_PROP_UNIT_ADDRESS,
ua, sizeof (ua));
if (err == PICL_SUCCESS) {
if (ua[0] == '2') {
card->slot = 0;
(void) strcpy(card->slot_str, "0");
} else if (ua[0] == '1') {
card->slot = 1;
(void) strcpy(card->slot_str, "1");
}
}
} else {
(void) strcpy(card->slot_str, IOBOARD);
card->slot = -1;
}
}
static int
ontario_get_network_instance(char *path)
{
if (strncmp(path, NETWORK_1_PATH, strlen(NETWORK_1_PATH)) == 0) {
return (1);
} else if (strncmp(path, NETWORK_3_PATH, strlen(NETWORK_3_PATH)) == 0) {
return (3);
} else if (strncmp(path, NETWORK_0_PATH, strlen(NETWORK_0_PATH)) == 0) {
return (0);
} else if (strncmp(path, NETWORK_2_PATH, strlen(NETWORK_2_PATH)) == 0) {
return (2);
} else {
return (-1);
}
}
/*
* add all io devices under pci in io list
*/
/* ARGSUSED */
static int
ontario_pci_callback(picl_nodehdl_t pcih, void *args)
{
int err = PICL_SUCCESS;
picl_nodehdl_t nodeh;
char path[MAXSTRLEN];
char parent_path[MAXSTRLEN];
char piclclass[PICL_CLASSNAMELEN_MAX];
char name[MAXSTRLEN];
char model[MAXSTRLEN];
char *compatible;
char binding_name[MAXSTRLEN];
struct io_card pci_card;
int32_t instance;
err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, parent_path,
sizeof (parent_path));
if (err != PICL_SUCCESS) {
return (err);
}
/* Walk through the children */
err = picl_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh,
sizeof (picl_nodehdl_t));
while (err == PICL_SUCCESS) {
err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME,
piclclass, sizeof (piclclass));
if (err != PICL_SUCCESS)
return (err);
/*
* Skip PCI and PCIEX devices because they will be processed
* later in the picl tree walk.
*/
if ((strcmp(piclclass, "pci") == 0) ||
(strcmp(piclclass, "pciex") == 0)) {
err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER,
&nodeh, sizeof (picl_nodehdl_t));
continue;
}
err = picl_get_propval_by_name(nodeh, PICL_PROP_DEVFS_PATH,
path, sizeof (path));
if (err != PICL_SUCCESS) {
return (err);
}
(void) strlcpy(pci_card.notes, path, sizeof (pci_card.notes));
get_bus_type(parent_path, &pci_card);
get_slot_number(nodeh, parent_path, &pci_card);
err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, &name,
sizeof (name));
if (err == PICL_PROPNOTFOUND)
(void) strcpy(name, "");
else if (err != PICL_SUCCESS)
return (err);
/* Figure NAC name */
if ((strcmp(name, NETWORK) == 0) &&
(strcmp(pci_card.slot_str, IOBOARD) == 0)) {
instance = ontario_get_network_instance(path);
(void) snprintf(pci_card.status,
sizeof (pci_card.status), "%s/%s%d", IOBOARD,
"NET", instance);
} else {
if (pci_card.slot != -1) {
(void) snprintf(pci_card.status,
sizeof (pci_card.status), "%s/%s%d",
IOBOARD, pci_card.bus_type, pci_card.slot);
} else {
(void) snprintf(pci_card.status,
sizeof (pci_card.status), "%s/%s", IOBOARD,
pci_card.bus_type);
}
}
/*
* Get the name of this card. If binding_name is found,
* name will be <nodename>-<binding_name>
*/
err = picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME,
&binding_name, sizeof (binding_name));
if (err == PICL_PROPNOTFOUND) {
/*
* if compatible prop is found, name will be
* <nodename>-<compatible>
*/
err = ontario_get_first_compatible_value(nodeh,
&compatible);
if (err == PICL_SUCCESS) {
(void) strlcat(name, "-", MAXSTRLEN);
(void) strlcat(name, compatible, MAXSTRLEN);
free(compatible);
} else if (err != PICL_PROPNOTFOUND) {
return (err);
}
} else if (err != PICL_SUCCESS) {
return (err);
} else if (strcmp(name, binding_name) != 0) {
(void) strlcat(name, "-", MAXSTRLEN);
(void) strlcat(name, binding_name, MAXSTRLEN);
}
(void) strlcpy(pci_card.name, name, sizeof (pci_card.name));
/* Get the model of this card */
err = picl_get_propval_by_name(nodeh, OBP_PROP_MODEL,
&model, sizeof (model));
if (err == PICL_PROPNOTFOUND)
(void) strcpy(model, "");
else if (err != PICL_SUCCESS)
return (err);
(void) strlcpy(pci_card.model, model, sizeof (pci_card.model));
/* Print NAC name */
log_printf("%-11s", pci_card.status);
/* Print IO Type */
log_printf("%6s", pci_card.bus_type);
/* Print Slot # */
log_printf("%5s", pci_card.slot_str);
/* Print Parent Path */
log_printf("%46.45s", pci_card.notes);
/* Printf Card Name */
if (strlen(pci_card.name) > 25)
log_printf("%25.24s+", pci_card.name);
else
log_printf("%26s", pci_card.name);
/* Print Card Model */
if (strlen(pci_card.model) > 10)
log_printf("%10.9s+", pci_card.model);
else
log_printf("%11s", pci_card.model);
log_printf("\n");
err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh,
sizeof (picl_nodehdl_t));
}
return (PICL_WALK_CONTINUE);
}
/*
* display_pci
* Display all the PCI IO cards on this board.
*/
void
sun4v_display_pci(picl_nodehdl_t plafh)
{
char platbuf[MAXSTRLEN];
char *fmt = "%-11s %-5s %-4s %-45s %-25s %-10s";
static int banner = FALSE; /* Have we printed the column headings? */
if (banner == FALSE) {
log_printf("\n", 0);
log_printf("=========================", 0);
log_printf(dgettext(TEXT_DOMAIN, " IO Configuration "), 0);
log_printf("=========================", 0);
log_printf("\n", 0);
log_printf("\n", 0);
log_printf(fmt, "", "IO", "", "", "", "", 0);
log_printf("\n", 0);
log_printf(fmt, "Location", "Type", "Slot", "Path",
"Name", "Model", 0);
log_printf("\n");
log_printf(fmt, "-----------", "-----", "----",
"---------------------------------------------",
"-------------------------", "----------", 0);
log_printf("\n");
banner = TRUE;
}
/* Get platform name, if that fails, use ontario name by default */
if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
(void) strcpy(platbuf, ONTARIO_PLATFORM);
}
/*
* Call functions based on appropriate platform
*/
if ((strncmp(platbuf, ONTARIO_PLATFORM,
strlen(ONTARIO_PLATFORM)) == 0) ||
(strncmp(platbuf, ONTARIO_PLATFORM2,
strlen(ONTARIO_PLATFORM2)) == 0)) {
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", ontario_pci_callback);
(void) picl_walk_tree_by_class(plafh, "pci",
"pci", ontario_pci_callback);
} else if ((strncmp(platbuf, PELTON_PLATFORM,
strlen(PELTON_PLATFORM))) == 0) {
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", pelton_pci_callback);
(void) picl_walk_tree_by_class(plafh, "pci",
"pci", pelton_pci_callback);
} else if ((strncmp(platbuf, STPAUL_PLATFORM,
strlen(STPAUL_PLATFORM))) == 0) {
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", stpaul_pci_callback);
} else if ((strncmp(platbuf, HURON_1U_PLATFORM,
strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
(void) picl_walk_tree_by_class(plafh, "sun4v",
"niu", huron_pci_callback);
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", huron_pci_callback);
} else {
(void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
erie_pci_callback);
(void) picl_walk_tree_by_class(plafh, "pci", "pci",
erie_pci_callback);
}
}
/*
* ----------------------------------------------------------------------------
*/
/* ARGSUSED */
void
sun4v_display_diaginfo(int flag, Prom_node *root, picl_nodehdl_t plafh)
{
/* NOTE(ARGUNUSED(kstats)) */
/*
* Now display the last powerfail time and the fatal hardware
* reset information. We do this under a couple of conditions.
* First if the user asks for it. The second is if the user
* told us to do logging, and we found a system failure.
*/
if (flag) {
/*
* display time of latest powerfail. Not all systems
* have this capability. For those that do not, this
* is just a no-op.
*/
disp_powerfail(root);
/* platform_disp_prom_version(tree); */
sun4v_display_hw_revisions(root, plafh);
}
}
/*
* local functions
*/
/*
* add all io devices under pci in io list
*/
/* ARGSUSED */
static int
ontario_hw_rev_callback(picl_nodehdl_t pcih, void *args)
{
int err = PICL_SUCCESS;
char path[MAXSTRLEN] = "";
char device_path[MAXSTRLEN];
char NAC[MAXSTRLEN];
char *compatible;
int32_t revision;
int device_found;
device_found = 0;
err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, path,
sizeof (path));
if (err != PICL_SUCCESS) {
return (err);
}
if ((strcmp(path, NETWORK_0_PATH) == 0) ||
(strcmp(path, NETWORK_1_PATH) == 0)) {
device_found = 1;
(void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
0);
revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
&err);
}
if ((strcmp(path, NETWORK_2_PATH) == 0) ||
(strcmp(path, NETWORK_3_PATH) == 0)) {
device_found = 1;
(void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
1);
revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
&err);
}
if ((strcmp(path, FIRE_PATH0) == 0) ||
(strcmp(path, FIRE_PATH1) == 0)) {
device_found = 1;
(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
"IO-BRIDGE");
revision = ontario_get_int_propval(pcih, OBP_PROP_VERSION_NUM,
&err);
}
if ((strcmp(path, PCIX_SLOT0) == 0) ||
(strcmp(path, PCIX_SLOT1) == 0)) {
device_found = 1;
(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
PCI_BRIDGE);
revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
&err);
}
if (strcmp(path, SWITCH_A_PATH) == 0) {
device_found = 1;
(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_A);
revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
&err);
}
if (strcmp(path, SWITCH_B_PATH) == 0) {
device_found = 1;
(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_B);
revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
&err);
}
if (strcmp(path, ONT_LSI_PATH) == 0) {
device_found = 1;
(void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
SAS_SATA_HBA);
revision = ontario_get_int_propval(pcih, OBP_PROP_REVISION_ID,
&err);
}
if (device_found == 1) {
(void) strcpy(device_path, path);
err = ontario_get_first_compatible_value(pcih, &compatible);
/* Print NAC name */
log_printf("%-20s", NAC);
/* Print Device Path */
if (strlen(device_path) > 38)
log_printf("%38.37s+", device_path);
else
log_printf("%39s", device_path);
/* Print Compatible # */
if (err == PICL_SUCCESS) {
log_printf("%31s", compatible);
free(compatible);
} else
log_printf("%31s", " ");
/* Print Revision */
log_printf("%6d", revision);
log_printf("\n");
}
return (PICL_WALK_CONTINUE);
}
/*ARGSUSED*/
static void
sun4v_display_hw_revisions(Prom_node *root, picl_nodehdl_t plafh)
{
Prom_node *pnode;
char *value;
char platbuf[MAXSTRLEN];
char *fmt = "%-20s %-45s %-30s %-9s";
log_printf(dgettext(TEXT_DOMAIN, "\n"
"========================= HW Revisions "
"=======================================\n\n"));
log_printf(dgettext(TEXT_DOMAIN,
"System PROM revisions:\n"
"----------------------\n"));
pnode = dev_find_node(root, "openprom");
if (pnode != NULL) {
value = (char *)get_prop_val(find_prop(pnode, "version"));
log_printf(value);
}
log_printf(dgettext(TEXT_DOMAIN, "\n\n"
"IO ASIC revisions:\n"
"------------------\n"));
log_printf(fmt, "Location", "Path", "Device", "Revision\n", 0);
log_printf(fmt, "--------------------",
"---------------------------------------------",
"------------------------------",
"---------\n", 0);
/* Get platform name, if that fails, use ontario name by default */
if (sysinfo(SI_PLATFORM, platbuf, sizeof (platbuf)) == -1) {
(void) strcpy(platbuf, ONTARIO_PLATFORM);
}
/*
* Walk tree based on platform
*/
if ((strncmp(platbuf, ONTARIO_PLATFORM,
strlen(ONTARIO_PLATFORM))) == 0) {
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", ontario_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "pci",
"pci", ontario_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "network",
"network", ontario_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
ontario_hw_rev_callback);
} else if ((strncmp(platbuf, PELTON_PLATFORM,
strlen(PELTON_PLATFORM))) == 0) {
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", pelton_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "pci",
"pci", pelton_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "network",
"network", pelton_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
pelton_hw_rev_callback);
} else if ((strncmp(platbuf, STPAUL_PLATFORM,
strlen(STPAUL_PLATFORM))) == 0) {
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", stpaul_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "pci",
"pci", stpaul_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "network",
"network", stpaul_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
stpaul_hw_rev_callback);
} else if ((strncmp(platbuf, HURON_1U_PLATFORM,
strlen(HURON_1U_PLATFORM)) == 0) || (strncmp(platbuf,
HURON_2U_PLATFORM, strlen(HURON_2U_PLATFORM)) == 0)) {
(void) picl_walk_tree_by_class(plafh, "pciex",
"pciex", huron_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "sun4v",
"niu", huron_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "network",
"network", huron_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
huron_hw_rev_callback);
} else {
(void) picl_walk_tree_by_class(plafh, "pciex", "pciex",
erie_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "pci", "pci",
erie_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "network", "network",
erie_hw_rev_callback);
(void) picl_walk_tree_by_class(plafh, "scsi-2", "scsi-2",
erie_hw_rev_callback);
}
}
/*
* return the first compatible value
*/
static int
ontario_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
{
int err;
picl_prophdl_t proph;
picl_propinfo_t pinfo;
picl_prophdl_t tblh;
picl_prophdl_t rowproph;
char *pval;
err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
&pinfo, &proph);
if (err != PICL_SUCCESS)
return (err);
if (pinfo.type == PICL_PTYPE_CHARSTRING) {
pval = malloc(pinfo.size);
if (pval == NULL)
return (PICL_FAILURE);
err = picl_get_propval(proph, pval, pinfo.size);
if (err != PICL_SUCCESS) {
free(pval);
return (err);
}
*outbuf = pval;
return (PICL_SUCCESS);
}
if (pinfo.type != PICL_PTYPE_TABLE)
return (PICL_FAILURE);
/* get first string from table */
err = picl_get_propval(proph, &tblh, pinfo.size);
if (err != PICL_SUCCESS)
return (err);
err = picl_get_next_by_row(tblh, &rowproph);
if (err != PICL_SUCCESS)
return (err);
err = picl_get_propinfo(rowproph, &pinfo);
if (err != PICL_SUCCESS)
return (err);
pval = malloc(pinfo.size);
if (pval == NULL)
return (PICL_FAILURE);
err = picl_get_propval(rowproph, pval, pinfo.size);
if (err != PICL_SUCCESS) {
free(pval);
return (err);
}
*outbuf = pval;
return (PICL_SUCCESS);
}
static int64_t
ontario_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret)
{
int err;
picl_prophdl_t proph;
picl_propinfo_t pinfo;
int8_t int8v;
int16_t int16v;
int32_t int32v;
int64_t int64v;
err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph);
if (err != PICL_SUCCESS) {
*ret = err;
return (0);
}
/*
* If it is not an int, uint or byte array prop, return failure
*/
if ((pinfo.type != PICL_PTYPE_INT) &&
(pinfo.type != PICL_PTYPE_UNSIGNED_INT) &&
(pinfo.type != PICL_PTYPE_BYTEARRAY)) {
*ret = PICL_FAILURE;
return (0);
}
switch (pinfo.size) {
case sizeof (int8_t):
err = picl_get_propval(proph, &int8v, sizeof (int8v));
*ret = err;
return (int8v);
case sizeof (int16_t):
err = picl_get_propval(proph, &int16v, sizeof (int16v));
*ret = err;
return (int16v);
case sizeof (int32_t):
err = picl_get_propval(proph, &int32v, sizeof (int32v));
*ret = err;
return (int32v);
case sizeof (int64_t):
err = picl_get_propval(proph, &int64v, sizeof (int64v));
*ret = err;
return (int64v);
default: /* not supported size */
*ret = PICL_FAILURE;
return (0);
}
}
|