xref: /illumos-gate/usr/src/psm/promif/ieee1275/sun4/prom_vername.c (revision f9721e075222d67dfc8cab85ccca4a17f1eb8325)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
31 
32 /*
33  * Return a character string in buf,buflen representing the running
34  * version of the firmware. Systems that have no concept of such a
35  * string may return the string "unknown".
36  *
37  * Return the actual length of the string, including the NULL terminator.
38  * Copy at most buflen bytes into the caller's buffer, always providing
39  * NULL termination.
40  *
41  * Returns the actual length of the string, plus copies data in the callers
42  * buf copying at most buflen bytes.  Returns -1 if an internal error occurs.
43  */
44 
45 int
46 prom_version_name(char *buf, int buflen)
47 {
48 	pnode_t nodeid;
49 	int proplen;
50 	char *unknown = "unknown";
51 
52 	*buf = *(buf + buflen - 1) = (char)0;	/* Force NULL termination */
53 
54 	/*
55 	 * On sun4u systems, the /openprom "version" property
56 	 * contains the running version of the prom. Some older
57 	 * pre-FCS proms may not have the "version" property, so
58 	 * in that case we just return "unknown".
59 	 */
60 
61 	nodeid = prom_finddevice("/openprom");
62 	if (nodeid == (pnode_t)-1)
63 		return (-1);
64 
65 	proplen = prom_bounded_getprop(nodeid, "version", buf, buflen - 1);
66 	if (proplen <= 0) {
67 		(void) prom_strncpy(buf, unknown, buflen - 1);
68 		return (prom_strlen(unknown) + 1);
69 	}
70 
71 	return (proplen);
72 }
73