103831d35Sstevel /*
203831d35Sstevel * CDDL HEADER START
303831d35Sstevel *
403831d35Sstevel * The contents of this file are subject to the terms of the
503831d35Sstevel * Common Development and Distribution License (the "License").
603831d35Sstevel * You may not use this file except in compliance with the License.
703831d35Sstevel *
803831d35Sstevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
903831d35Sstevel * or http://www.opensolaris.org/os/licensing.
1003831d35Sstevel * See the License for the specific language governing permissions
1103831d35Sstevel * and limitations under the License.
1203831d35Sstevel *
1303831d35Sstevel * When distributing Covered Code, include this CDDL HEADER in each
1403831d35Sstevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1503831d35Sstevel * If applicable, add the following below this CDDL HEADER, with the
1603831d35Sstevel * fields enclosed by brackets "[]" replaced with your own identifying
1703831d35Sstevel * information: Portions Copyright [yyyy] [name of copyright owner]
1803831d35Sstevel *
1903831d35Sstevel * CDDL HEADER END
2003831d35Sstevel */
2103831d35Sstevel /*
22*087113e1Smb * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2303831d35Sstevel * Use is subject to license terms.
2403831d35Sstevel */
2503831d35Sstevel
2603831d35Sstevel /*
2703831d35Sstevel * Sun4v Platform specific functions.
2803831d35Sstevel *
2903831d35Sstevel * called when :
3003831d35Sstevel * machine_type == pelton
3103831d35Sstevel *
3203831d35Sstevel */
3303831d35Sstevel
3403831d35Sstevel #include <stdio.h>
3503831d35Sstevel #include <stdlib.h>
3603831d35Sstevel #include <unistd.h>
3703831d35Sstevel #include <kstat.h>
3803831d35Sstevel #include <fcntl.h>
3903831d35Sstevel #include <string.h>
4003831d35Sstevel #include <assert.h>
4103831d35Sstevel #include <libintl.h>
4203831d35Sstevel #include <note.h>
4303831d35Sstevel #include <sys/systeminfo.h>
4403831d35Sstevel #include <sys/openpromio.h>
4503831d35Sstevel #include <sys/sysmacros.h>
4603831d35Sstevel #include <picl.h>
4703831d35Sstevel #include "picldefs.h"
4803831d35Sstevel #include <pdevinfo.h>
4903831d35Sstevel #include <display.h>
5003831d35Sstevel #include <display_sun4v.h>
5103831d35Sstevel #include <libprtdiag.h>
5203831d35Sstevel #include "pelton.h"
5303831d35Sstevel
5403831d35Sstevel #if !defined(TEXT_DOMAIN)
5503831d35Sstevel #define TEXT_DOMAIN "SYS_TEST"
5603831d35Sstevel #endif
5703831d35Sstevel
5803831d35Sstevel /* local functions */
5903831d35Sstevel static int pelton_get_first_compatible_value(picl_nodehdl_t nodeh,
6003831d35Sstevel char **outbuf);
6103831d35Sstevel static int64_t pelton_get_int_propval(picl_nodehdl_t modh, char *prop_name,
6203831d35Sstevel int *ret);
6303831d35Sstevel
6403831d35Sstevel static void
get_bus_type(char * path,struct io_card * card)6503831d35Sstevel get_bus_type(char *path, struct io_card *card)
6603831d35Sstevel {
6703831d35Sstevel if (strncmp(path, PEL_PCIX_SLOT0, PCIX_COMP_NUM) == 0) {
6803831d35Sstevel (void) strcpy(card->bus_type, "PCIX");
6903831d35Sstevel } else if (strncmp(path, PEL_PCIX_SLOT1, PCIX_COMP_NUM) == 0) {
7003831d35Sstevel (void) strcpy(card->bus_type, "PCIX");
7103831d35Sstevel } else if (strncmp(path, PEL_PCIX_SLOT2, PCIX_COMP_NUM) == 0) {
7203831d35Sstevel (void) strcpy(card->bus_type, "PCIX");
73483dd6e5Sarutz } else if (strncmp(path, PEL_PCIX_ONBOARD0, PCIX_COMP_NUM) == 0) {
7403831d35Sstevel (void) strcpy(card->bus_type, "PCIX");
7503831d35Sstevel } else {
7603831d35Sstevel (void) strcpy(card->bus_type, "PCIE");
7703831d35Sstevel }
7803831d35Sstevel }
7903831d35Sstevel
80483dd6e5Sarutz /*
81483dd6e5Sarutz * 'path' is the device-path of the *parent* of the IO card ('card').
82483dd6e5Sarutz *
83483dd6e5Sarutz * Compare the prefix of the string representing the device-path with
84483dd6e5Sarutz * the strings representing the platform's Slots.
85483dd6e5Sarutz *
86483dd6e5Sarutz * Note that string for PEL_PCIX_SLOT1 is a prefix of PEL_PCIX_SLOT2's
87483dd6e5Sarutz * string. Since we want to match the longest possible substring of
88483dd6e5Sarutz * 'path', compare SLOT2 before comparing SLOT1.
89483dd6e5Sarutz */
9003831d35Sstevel static void
get_slot_number(char * path,struct io_card * card)9103831d35Sstevel get_slot_number(char *path, struct io_card *card)
9203831d35Sstevel {
9303831d35Sstevel if (strncmp(path, PEL_PCIE_SLOT0, PCIE_COMP_NUM) == 0) {
9403831d35Sstevel (void) strcpy(card->slot_str, "0");
9503831d35Sstevel card->slot = 0;
9603831d35Sstevel } else if (strncmp(path, PEL_PCIX_SLOT2, strlen(PEL_PCIX_SLOT2)) == 0) {
97483dd6e5Sarutz (void) strcpy(card->slot_str, "2");
98483dd6e5Sarutz card->slot = 2;
9903831d35Sstevel } else if (strncmp(path, PEL_PCIX_SLOT1, strlen(PEL_PCIX_SLOT1)) == 0) {
100483dd6e5Sarutz (void) strcpy(card->slot_str, "3");
101483dd6e5Sarutz card->slot = 3;
10203831d35Sstevel } else if (strncmp(path, PEL_PCIX_SLOT0, strlen(PEL_PCIX_SLOT0)) == 0) {
103483dd6e5Sarutz (void) strcpy(card->slot_str, "1");
104483dd6e5Sarutz card->slot = 1;
10503831d35Sstevel } else {
10603831d35Sstevel (void) strcpy(card->slot_str, IOBOARD);
10703831d35Sstevel card->slot = -1;
10803831d35Sstevel }
10903831d35Sstevel }
11003831d35Sstevel
11103831d35Sstevel static int
pelton_get_network_instance(char * path)11203831d35Sstevel pelton_get_network_instance(char *path)
11303831d35Sstevel {
11403831d35Sstevel if (strncmp(path, PEL_NETWORK_1_PATH,
115483dd6e5Sarutz strlen(PEL_NETWORK_1_PATH)) == 0) {
11603831d35Sstevel return (1);
11703831d35Sstevel } else if (strncmp(path, PEL_NETWORK_3_PATH,
118483dd6e5Sarutz strlen(PEL_NETWORK_3_PATH)) == 0) {
11903831d35Sstevel return (3);
12003831d35Sstevel } else if (strncmp(path, PEL_NETWORK_0_PATH,
121483dd6e5Sarutz strlen(PEL_NETWORK_0_PATH)) == 0) {
12203831d35Sstevel return (0);
12303831d35Sstevel } else if (strncmp(path, PEL_NETWORK_2_PATH,
124483dd6e5Sarutz strlen(PEL_NETWORK_2_PATH)) == 0) {
12503831d35Sstevel return (2);
12603831d35Sstevel } else {
12703831d35Sstevel return (-1);
12803831d35Sstevel }
12903831d35Sstevel }
13003831d35Sstevel /*
13103831d35Sstevel * add all io devices under pci in io list
13203831d35Sstevel */
13303831d35Sstevel /* ARGSUSED */
13403831d35Sstevel int
pelton_pci_callback(picl_nodehdl_t pcih,void * args)13503831d35Sstevel pelton_pci_callback(picl_nodehdl_t pcih, void *args)
13603831d35Sstevel {
13703831d35Sstevel int err = PICL_SUCCESS;
13803831d35Sstevel picl_nodehdl_t nodeh;
13903831d35Sstevel char path[MAXSTRLEN];
14003831d35Sstevel char parent_path[MAXSTRLEN];
14103831d35Sstevel char piclclass[PICL_CLASSNAMELEN_MAX];
14203831d35Sstevel char name[MAXSTRLEN];
14303831d35Sstevel char model[MAXSTRLEN];
14403831d35Sstevel char *compatible;
14503831d35Sstevel char binding_name[MAXSTRLEN];
14603831d35Sstevel struct io_card pci_card;
14703831d35Sstevel int32_t instance;
14803831d35Sstevel
14903831d35Sstevel err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, parent_path,
15003831d35Sstevel sizeof (parent_path));
15103831d35Sstevel if (err != PICL_SUCCESS) {
15203831d35Sstevel return (err);
15303831d35Sstevel }
15403831d35Sstevel
15503831d35Sstevel /* Walk through the children */
15603831d35Sstevel
15703831d35Sstevel err = picl_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh,
15803831d35Sstevel sizeof (picl_nodehdl_t));
15903831d35Sstevel
16003831d35Sstevel while (err == PICL_SUCCESS) {
16103831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME,
16203831d35Sstevel piclclass, sizeof (piclclass));
16303831d35Sstevel if (err != PICL_SUCCESS)
16403831d35Sstevel return (err);
16503831d35Sstevel
166483dd6e5Sarutz if ((strcmp(piclclass, PICL_CLASS_PCIEX) == 0) ||
167483dd6e5Sarutz (strcmp(piclclass, PICL_CLASS_PCI) == 0)) {
16803831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER,
16903831d35Sstevel &nodeh, sizeof (picl_nodehdl_t));
17003831d35Sstevel continue;
17103831d35Sstevel }
17203831d35Sstevel
17303831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_DEVFS_PATH,
17403831d35Sstevel path, sizeof (path));
17503831d35Sstevel if (err != PICL_SUCCESS) {
17603831d35Sstevel return (err);
17703831d35Sstevel }
17803831d35Sstevel
17903831d35Sstevel (void) strlcpy(pci_card.notes, path, sizeof (pci_card.notes));
18003831d35Sstevel
18103831d35Sstevel get_bus_type(parent_path, &pci_card);
18203831d35Sstevel
18303831d35Sstevel get_slot_number(parent_path, &pci_card);
18403831d35Sstevel
18503831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_NAME, &name,
18603831d35Sstevel sizeof (name));
18703831d35Sstevel if (err == PICL_PROPNOTFOUND)
18803831d35Sstevel (void) strcpy(name, "");
18903831d35Sstevel else if (err != PICL_SUCCESS)
19003831d35Sstevel return (err);
19103831d35Sstevel
19203831d35Sstevel
19303831d35Sstevel /* Figure NAC name */
19403831d35Sstevel if ((strcmp(name, NETWORK) == 0) &&
19503831d35Sstevel (strcmp(pci_card.slot_str, IOBOARD) == 0)) {
19603831d35Sstevel instance = pelton_get_network_instance(path);
19703831d35Sstevel
19803831d35Sstevel (void) snprintf(pci_card.status,
19903831d35Sstevel sizeof (pci_card.status), "%s/%s%d", IOBOARD,
20003831d35Sstevel "NET", instance);
20103831d35Sstevel } else {
20203831d35Sstevel if (pci_card.slot != -1) {
20303831d35Sstevel (void) snprintf(pci_card.status,
20403831d35Sstevel sizeof (pci_card.status), "%s/%s%d",
20503831d35Sstevel IOBOARD, pci_card.bus_type, pci_card.slot);
20603831d35Sstevel } else {
20703831d35Sstevel (void) snprintf(pci_card.status,
20803831d35Sstevel sizeof (pci_card.status), "%s/%s", IOBOARD,
20903831d35Sstevel pci_card.bus_type);
21003831d35Sstevel }
21103831d35Sstevel }
21203831d35Sstevel
21303831d35Sstevel /*
21403831d35Sstevel * Get the name of this card. Iif binding_name is found,
21503831d35Sstevel * name will be <nodename>-<binding_name>
21603831d35Sstevel */
21703831d35Sstevel
21803831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_BINDING_NAME,
21903831d35Sstevel &binding_name, sizeof (binding_name));
22003831d35Sstevel if (err == PICL_PROPNOTFOUND) {
22103831d35Sstevel /*
22203831d35Sstevel * if compatible prop is found, name will be
22303831d35Sstevel * <nodename>-<compatible>
22403831d35Sstevel */
22503831d35Sstevel err = pelton_get_first_compatible_value(nodeh,
22603831d35Sstevel &compatible);
22703831d35Sstevel if (err == PICL_SUCCESS) {
22803831d35Sstevel (void) strlcat(name, "-", MAXSTRLEN);
22903831d35Sstevel (void) strlcat(name, compatible, MAXSTRLEN);
23003831d35Sstevel free(compatible);
23103831d35Sstevel } else if (err != PICL_PROPNOTFOUND) {
23203831d35Sstevel return (err);
23303831d35Sstevel }
23403831d35Sstevel } else if (err != PICL_SUCCESS) {
23503831d35Sstevel return (err);
23603831d35Sstevel } else if (strcmp(name, binding_name) != 0) {
23703831d35Sstevel (void) strlcat(name, "-", MAXSTRLEN);
23803831d35Sstevel (void) strlcat(name, binding_name, MAXSTRLEN);
23903831d35Sstevel }
24003831d35Sstevel
24103831d35Sstevel (void) strlcpy(pci_card.name, name, sizeof (pci_card.name));
24203831d35Sstevel
24303831d35Sstevel /* Get the model of this card */
24403831d35Sstevel
24503831d35Sstevel err = picl_get_propval_by_name(nodeh, OBP_PROP_MODEL,
24603831d35Sstevel &model, sizeof (model));
24703831d35Sstevel if (err == PICL_PROPNOTFOUND)
24803831d35Sstevel (void) strcpy(model, "");
24903831d35Sstevel else if (err != PICL_SUCCESS)
25003831d35Sstevel return (err);
25103831d35Sstevel (void) strlcpy(pci_card.model, model, sizeof (pci_card.model));
25203831d35Sstevel
25303831d35Sstevel /* Print NAC name */
25403831d35Sstevel log_printf("%-11s", pci_card.status);
25503831d35Sstevel /* Print IO Type */
25603831d35Sstevel log_printf("%6s", pci_card.bus_type);
25703831d35Sstevel /* Print Slot # */
25803831d35Sstevel log_printf("%5s", pci_card.slot_str);
25903831d35Sstevel /* Print Parent Path */
26003831d35Sstevel log_printf("%46.45s", pci_card.notes);
26103831d35Sstevel /* Printf Card Name */
26203831d35Sstevel if (strlen(pci_card.name) > 24)
26303831d35Sstevel log_printf("%25.24s+", pci_card.name);
26403831d35Sstevel else
26503831d35Sstevel log_printf("%26s", pci_card.name);
26603831d35Sstevel /* Print Card Model */
26703831d35Sstevel if (strlen(pci_card.model) > 10)
26803831d35Sstevel log_printf("%10.9s+", pci_card.model);
26903831d35Sstevel else
27003831d35Sstevel log_printf("%10s", pci_card.model);
27103831d35Sstevel log_printf("\n");
27203831d35Sstevel
27303831d35Sstevel err = picl_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh,
27403831d35Sstevel sizeof (picl_nodehdl_t));
27503831d35Sstevel
27603831d35Sstevel }
27703831d35Sstevel
27803831d35Sstevel return (PICL_WALK_CONTINUE);
27903831d35Sstevel }
28003831d35Sstevel
28103831d35Sstevel /*
28203831d35Sstevel * local functions
28303831d35Sstevel */
28403831d35Sstevel /*
28503831d35Sstevel * add all io devices under pci in io list
28603831d35Sstevel */
28703831d35Sstevel /* ARGSUSED */
28803831d35Sstevel int
pelton_hw_rev_callback(picl_nodehdl_t pcih,void * args)28903831d35Sstevel pelton_hw_rev_callback(picl_nodehdl_t pcih, void *args)
29003831d35Sstevel {
29103831d35Sstevel int err = PICL_SUCCESS;
29203831d35Sstevel char path[MAXSTRLEN] = "";
29303831d35Sstevel char device_path[MAXSTRLEN];
29403831d35Sstevel char NAC[MAXSTRLEN];
29503831d35Sstevel char *compatible;
29603831d35Sstevel int32_t revision;
29703831d35Sstevel int device_found;
29803831d35Sstevel
29903831d35Sstevel device_found = 0;
30003831d35Sstevel
30103831d35Sstevel err = picl_get_propval_by_name(pcih, PICL_PROP_DEVFS_PATH, path,
30203831d35Sstevel sizeof (path));
30303831d35Sstevel if (err != PICL_SUCCESS) {
30403831d35Sstevel return (err);
30503831d35Sstevel }
30603831d35Sstevel
30703831d35Sstevel if ((strcmp(path, PEL_NETWORK_0_PATH) == 0) ||
30803831d35Sstevel (strcmp(path, PEL_NETWORK_1_PATH) == 0)) {
30903831d35Sstevel device_found = 1;
31003831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
31103831d35Sstevel 0);
31203831d35Sstevel revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID,
31303831d35Sstevel &err);
31403831d35Sstevel }
31503831d35Sstevel
31603831d35Sstevel if ((strcmp(path, PEL_NETWORK_2_PATH) == 0) ||
31703831d35Sstevel (strcmp(path, PEL_NETWORK_3_PATH) == 0)) {
31803831d35Sstevel device_found = 1;
31903831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s%d", IOBOARD, OPHIR,
32003831d35Sstevel 1);
32103831d35Sstevel revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID,
32203831d35Sstevel &err);
32303831d35Sstevel }
32403831d35Sstevel
32503831d35Sstevel if ((strcmp(path, FIRE_PATH0) == 0) ||
32603831d35Sstevel (strcmp(path, FIRE_PATH1) == 0)) {
32703831d35Sstevel device_found = 1;
32803831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
32903831d35Sstevel "IO-BRIDGE");
33003831d35Sstevel revision = pelton_get_int_propval(pcih, OBP_PROP_VERSION_NUM,
33103831d35Sstevel &err);
33203831d35Sstevel }
33303831d35Sstevel
33403831d35Sstevel if ((strcmp(path, PEL_PCIX_SLOT0) == 0) ||
33503831d35Sstevel (strcmp(path, PEL_PCIX_SLOT1) == 0) ||
33603831d35Sstevel (strcmp(path, PEL_PCIX_SLOT2) == 0) ||
337483dd6e5Sarutz (strcmp(path, PEL_PCIX_ONBOARD0) == 0)) {
33803831d35Sstevel device_found = 1;
33903831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
34003831d35Sstevel PCI_BRIDGE);
34103831d35Sstevel revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID,
34203831d35Sstevel &err);
34303831d35Sstevel }
34403831d35Sstevel
34503831d35Sstevel if (strcmp(path, SWITCH_A_PATH) == 0) {
34603831d35Sstevel device_found = 1;
34703831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_A);
34803831d35Sstevel revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID,
34903831d35Sstevel &err);
35003831d35Sstevel }
35103831d35Sstevel
35203831d35Sstevel if (strcmp(path, SWITCH_B_PATH) == 0) {
35303831d35Sstevel device_found = 1;
35403831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD, SWITCH_B);
35503831d35Sstevel revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID,
35603831d35Sstevel &err);
35703831d35Sstevel }
35803831d35Sstevel
35903831d35Sstevel if (strcmp(path, PEL_LSI_PATH) == 0) {
36003831d35Sstevel device_found = 1;
36103831d35Sstevel (void) snprintf(NAC, sizeof (NAC), "%s/%s", IOBOARD,
36203831d35Sstevel PEL_SAS_HBA);
36303831d35Sstevel revision = pelton_get_int_propval(pcih, OBP_PROP_REVISION_ID,
36403831d35Sstevel &err);
36503831d35Sstevel }
36603831d35Sstevel if (device_found == 1) {
36703831d35Sstevel (void) strcpy(device_path, path);
36803831d35Sstevel err = pelton_get_first_compatible_value(pcih, &compatible);
36903831d35Sstevel
37003831d35Sstevel /* Print NAC name */
37103831d35Sstevel log_printf("%-20s", NAC);
37203831d35Sstevel /* Print Device Path */
37303831d35Sstevel if (strlen(device_path) > 38)
37403831d35Sstevel log_printf("%38.37s+", device_path);
37503831d35Sstevel else
37603831d35Sstevel log_printf("%39s", device_path);
37703831d35Sstevel /* Print Compatible # */
378*087113e1Smb if (err == PICL_SUCCESS) {
379*087113e1Smb log_printf("%31s", compatible);
380*087113e1Smb free(compatible);
381*087113e1Smb } else
382*087113e1Smb log_printf("%31s", " ");
38303831d35Sstevel /* Print Revision */
38403831d35Sstevel log_printf("%6d", revision);
38503831d35Sstevel log_printf("\n");
38603831d35Sstevel }
38703831d35Sstevel
38803831d35Sstevel return (PICL_WALK_CONTINUE);
38903831d35Sstevel }
39003831d35Sstevel
39103831d35Sstevel /*
39203831d35Sstevel * return the first compatible value
39303831d35Sstevel */
39403831d35Sstevel static int
pelton_get_first_compatible_value(picl_nodehdl_t nodeh,char ** outbuf)39503831d35Sstevel pelton_get_first_compatible_value(picl_nodehdl_t nodeh, char **outbuf)
39603831d35Sstevel {
39703831d35Sstevel int err;
39803831d35Sstevel picl_prophdl_t proph;
39903831d35Sstevel picl_propinfo_t pinfo;
40003831d35Sstevel picl_prophdl_t tblh;
40103831d35Sstevel picl_prophdl_t rowproph;
40203831d35Sstevel char *pval;
40303831d35Sstevel
40403831d35Sstevel err = picl_get_propinfo_by_name(nodeh, OBP_PROP_COMPATIBLE,
40503831d35Sstevel &pinfo, &proph);
40603831d35Sstevel if (err != PICL_SUCCESS)
407483dd6e5Sarutz return (err);
40803831d35Sstevel
40903831d35Sstevel if (pinfo.type == PICL_PTYPE_CHARSTRING) {
41003831d35Sstevel pval = malloc(pinfo.size);
41103831d35Sstevel if (pval == NULL)
41203831d35Sstevel return (PICL_FAILURE);
41303831d35Sstevel err = picl_get_propval(proph, pval, pinfo.size);
41403831d35Sstevel if (err != PICL_SUCCESS) {
41503831d35Sstevel free(pval);
41603831d35Sstevel return (err);
41703831d35Sstevel }
41803831d35Sstevel *outbuf = pval;
41903831d35Sstevel return (PICL_SUCCESS);
42003831d35Sstevel }
42103831d35Sstevel
42203831d35Sstevel if (pinfo.type != PICL_PTYPE_TABLE)
42303831d35Sstevel return (PICL_FAILURE);
42403831d35Sstevel
42503831d35Sstevel /* get first string from table */
42603831d35Sstevel err = picl_get_propval(proph, &tblh, pinfo.size);
42703831d35Sstevel if (err != PICL_SUCCESS)
42803831d35Sstevel return (err);
42903831d35Sstevel
43003831d35Sstevel err = picl_get_next_by_row(tblh, &rowproph);
43103831d35Sstevel if (err != PICL_SUCCESS)
43203831d35Sstevel return (err);
43303831d35Sstevel
43403831d35Sstevel err = picl_get_propinfo(rowproph, &pinfo);
43503831d35Sstevel if (err != PICL_SUCCESS)
436483dd6e5Sarutz return (err);
43703831d35Sstevel
43803831d35Sstevel pval = malloc(pinfo.size);
43903831d35Sstevel if (pval == NULL)
44003831d35Sstevel return (PICL_FAILURE);
44103831d35Sstevel
44203831d35Sstevel err = picl_get_propval(rowproph, pval, pinfo.size);
44303831d35Sstevel if (err != PICL_SUCCESS) {
44403831d35Sstevel free(pval);
44503831d35Sstevel return (err);
44603831d35Sstevel }
44703831d35Sstevel
44803831d35Sstevel *outbuf = pval;
44903831d35Sstevel return (PICL_SUCCESS);
45003831d35Sstevel }
45103831d35Sstevel
45203831d35Sstevel static int64_t
pelton_get_int_propval(picl_nodehdl_t modh,char * prop_name,int * ret)45303831d35Sstevel pelton_get_int_propval(picl_nodehdl_t modh, char *prop_name, int *ret)
45403831d35Sstevel {
45503831d35Sstevel int err;
45603831d35Sstevel picl_prophdl_t proph;
45703831d35Sstevel picl_propinfo_t pinfo;
45803831d35Sstevel int8_t int8v;
45903831d35Sstevel int16_t int16v;
46003831d35Sstevel int32_t int32v;
46103831d35Sstevel int64_t int64v;
46203831d35Sstevel
46303831d35Sstevel err = picl_get_propinfo_by_name(modh, prop_name, &pinfo, &proph);
46403831d35Sstevel if (err != PICL_SUCCESS) {
46503831d35Sstevel *ret = err;
46603831d35Sstevel return (0);
46703831d35Sstevel }
46803831d35Sstevel
46903831d35Sstevel /*
47003831d35Sstevel * If it is not an int, uint or byte array prop, return failure
47103831d35Sstevel */
47203831d35Sstevel if ((pinfo.type != PICL_PTYPE_INT) &&
473483dd6e5Sarutz (pinfo.type != PICL_PTYPE_UNSIGNED_INT) &&
474483dd6e5Sarutz (pinfo.type != PICL_PTYPE_BYTEARRAY)) {
47503831d35Sstevel *ret = PICL_FAILURE;
47603831d35Sstevel return (0);
47703831d35Sstevel }
47803831d35Sstevel
47903831d35Sstevel switch (pinfo.size) {
48003831d35Sstevel case sizeof (int8_t):
48103831d35Sstevel err = picl_get_propval(proph, &int8v, sizeof (int8v));
48203831d35Sstevel *ret = err;
48303831d35Sstevel return (int8v);
48403831d35Sstevel case sizeof (int16_t):
48503831d35Sstevel err = picl_get_propval(proph, &int16v, sizeof (int16v));
48603831d35Sstevel *ret = err;
48703831d35Sstevel return (int16v);
48803831d35Sstevel case sizeof (int32_t):
48903831d35Sstevel err = picl_get_propval(proph, &int32v, sizeof (int32v));
49003831d35Sstevel *ret = err;
49103831d35Sstevel return (int32v);
49203831d35Sstevel case sizeof (int64_t):
49303831d35Sstevel err = picl_get_propval(proph, &int64v, sizeof (int64v));
49403831d35Sstevel *ret = err;
49503831d35Sstevel return (int64v);
49603831d35Sstevel default: /* not supported size */
49703831d35Sstevel *ret = PICL_FAILURE;
49803831d35Sstevel return (0);
49903831d35Sstevel }
50003831d35Sstevel }
501