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