summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdevinfo
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libdevinfo')
-rw-r--r--usr/src/lib/libdevinfo/devinfo.c125
-rw-r--r--usr/src/lib/libdevinfo/devinfo_prop_decode.c108
-rw-r--r--usr/src/lib/libdevinfo/libdevinfo.h37
-rw-r--r--usr/src/lib/libdevinfo/mapfile-vers9
4 files changed, 268 insertions, 11 deletions
diff --git a/usr/src/lib/libdevinfo/devinfo.c b/usr/src/lib/libdevinfo/devinfo.c
index ee33c2d518..e37e207474 100644
--- a/usr/src/lib/libdevinfo/devinfo.c
+++ b/usr/src/lib/libdevinfo/devinfo.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
@@ -19,9 +18,8 @@
*
* CDDL HEADER END
*/
-
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -1488,6 +1486,31 @@ di_prop_search(dev_t match_dev, di_node_t node, const char *name,
return (DI_PROP_NIL);
}
+di_prop_t
+di_prop_find(dev_t match_dev, di_node_t node, const char *name)
+{
+ di_prop_t prop = DI_PROP_NIL;
+
+ if ((node == DI_NODE_NIL) || (name == NULL) || (strlen(name) == 0) ||
+ (match_dev == DDI_DEV_T_NONE)) {
+ errno = EINVAL;
+ return (DI_PROP_NIL);
+ }
+
+ while ((prop = di_prop_next(node, prop)) != DI_PROP_NIL) {
+ DPRINTF((DI_TRACE1, "found prop name %s, devt 0x%lx, type %d\n",
+ di_prop_name(prop), di_prop_devt(prop),
+ di_prop_type(prop)));
+
+ if (strcmp(name, di_prop_name(prop)) == 0 &&
+ (match_dev == DDI_DEV_T_ANY ||
+ di_prop_devt(prop) == match_dev))
+ return (prop);
+ }
+
+ return (DI_PROP_NIL);
+}
+
int
di_prop_lookup_ints(dev_t dev, di_node_t node, const char *prop_name,
int **prop_data)
@@ -2688,6 +2711,98 @@ di_prom_prop_lookup_bytes(di_prom_handle_t ph, di_node_t node,
return (len);
}
+/*
+ * returns an allocated array through <prop_data> only when its count > 0
+ * and the number of entries (count) as the function return value;
+ * use di_slot_names_free() to free the array
+ */
+int
+di_prop_slot_names(di_prop_t prop, di_slot_name_t **prop_data)
+{
+ int rawlen, count;
+ uchar_t *rawdata;
+ char *nm = di_prop_name(prop);
+
+ if (nm == NULL || strcmp(DI_PROP_SLOT_NAMES, nm) != 0)
+ goto ERROUT;
+
+ rawlen = di_prop_rawdata(prop, &rawdata);
+ if (rawlen <= 0 || rawdata == NULL)
+ goto ERROUT;
+
+ count = di_slot_names_decode(rawdata, rawlen, prop_data);
+ if (count < 0 || *prop_data == NULL)
+ goto ERROUT;
+
+ return (count);
+ /*NOTREACHED*/
+ERROUT:
+ errno = EFAULT;
+ *prop_data = NULL;
+ return (-1);
+}
+
+int
+di_prop_lookup_slot_names(dev_t dev, di_node_t node,
+ di_slot_name_t **prop_data)
+{
+ di_prop_t prop;
+
+ /*
+ * change this if and when DI_PROP_TYPE_COMPOSITE is implemented
+ * and slot-names is properly flagged as such
+ */
+ if ((prop = di_prop_find(dev, node, DI_PROP_SLOT_NAMES)) ==
+ DI_PROP_NIL) {
+ *prop_data = NULL;
+ return (-1);
+ }
+
+ return (di_prop_slot_names(prop, (void *)prop_data));
+}
+
+/*
+ * returns an allocated array through <prop_data> only when its count > 0
+ * and the number of entries (count) as the function return value;
+ * use di_slot_names_free() to free the array
+ */
+int
+di_prom_prop_slot_names(di_prom_prop_t prom_prop, di_slot_name_t **prop_data)
+{
+ int rawlen, count;
+ uchar_t *rawdata;
+
+ rawlen = di_prom_prop_data(prom_prop, &rawdata);
+ if (rawlen <= 0 || rawdata == NULL)
+ goto ERROUT;
+
+ count = di_slot_names_decode(rawdata, rawlen, prop_data);
+ if (count < 0 || *prop_data == NULL)
+ goto ERROUT;
+
+ return (count);
+ /*NOTREACHED*/
+ERROUT:
+ errno = EFAULT;
+ *prop_data = NULL;
+ return (-1);
+}
+
+int
+di_prom_prop_lookup_slot_names(di_prom_handle_t ph, di_node_t node,
+ di_slot_name_t **prop_data)
+{
+ struct di_prom_prop *prom_prop;
+
+ prom_prop = di_prom_prop_lookup_common(ph, node, DI_PROP_SLOT_NAMES);
+ if (prom_prop == NULL) {
+ *prop_data = NULL;
+ return (-1);
+ }
+
+ return (di_prom_prop_slot_names(prom_prop, prop_data));
+}
+
di_lnode_t
di_link_to_lnode(di_link_t link, uint_t endpoint)
{
diff --git a/usr/src/lib/libdevinfo/devinfo_prop_decode.c b/usr/src/lib/libdevinfo/devinfo_prop_decode.c
index 542cb54d52..cc8b0d00ce 100644
--- a/usr/src/lib/libdevinfo/devinfo_prop_decode.c
+++ b/usr/src/lib/libdevinfo/devinfo_prop_decode.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -932,4 +931,103 @@ di_prop_decode_common(void *data, int size, int prop_type, int prom)
return (nelements);
}
-/* end of devinfo_prop_decode.c */
+void
+di_slot_names_free(int count, di_slot_name_t *slot_names)
+{
+ if (slot_names == NULL)
+ return;
+
+ while (--count >= 0) {
+ if (slot_names[count].name != NULL)
+ free(slot_names[count].name);
+ }
+ free(slot_names);
+}
+
+/*
+ * 1275 "slot-names" format: [int][string1][string2]...[stringN]
+ * - [int] is a 1275 encoded integer
+ * - [string1]...[stringN] are concatenated null-terminated strings
+ * - each bit position in [int] represents a pci device number
+ * - each bit which is set in [int] represents a slot with a device
+ * number of that bit position
+ * - each string in [string1]...[stringN] identifies a slot name only
+ * for the bits which are set in [int]
+ * - the ordering of strings follow the ordering of bits set in [int]
+ *
+ * an allocated array of di_slot_name_t is returned through prop_data if
+ * [int] is non-zero and the number of entries as the return value;
+ * use di_slot_names_free() to free the array
+ */
+int
+di_slot_names_decode(uchar_t *rawdata, int rawlen,
+ di_slot_name_t **prop_data)
+{
+ char *sp, *maxsp;
+ int count, i;
+ size_t len;
+ int slots;
+ int maxcount = 0;
+ int maxslots = 0;
+ di_slot_name_t *slot_names = NULL;
+
+ if (rawlen < sizeof (slots))
+ goto ERROUT;
+
+ slots = impl_di_prop_int_from_prom(rawdata, sizeof (slots));
+ if (slots == 0) {
+ *prop_data = NULL;
+ return (0);
+ }
+
+ maxslots = sizeof (slots) * 8;
+ count = 0;
+ for (i = 0; i < maxslots; i++) {
+ if (slots & (1 << i))
+ count++;
+ }
+ maxslots = i;
+ maxcount = count;
+ slot_names = malloc(sizeof (*slot_names) * maxcount);
+ bzero(slot_names, sizeof (*slot_names) * maxcount);
+
+ /* also handle unterminated strings */
+ sp = (char *)(rawdata + sizeof (slots));
+ maxsp = sp + (rawlen - sizeof (slots));
+ count = 0;
+ for (i = 0; i < maxslots; i++) {
+ if (slots & (1 << i)) {
+ if (sp > maxsp)
+ break;
+ len = strnlen(sp, (maxsp - sp) + 1);
+ if (len == 0)
+ break;
+
+ slot_names[count].name =
+ malloc(sizeof (char) * (len + 1));
+ (void) strlcpy(slot_names[count].name, sp, len + 1);
+
+ slot_names[count].num = i;
+
+ sp += len + 1;
+ count++;
+ }
+ }
+
+ /*
+ * check if the number of strings match with the number of slots;
+ * we can also get a lesser string count even when there appears to be
+ * the correct number of strings if one or more pair of strings are
+ * seperated by more than one NULL byte
+ */
+ if (count != maxcount)
+ goto ERROUT;
+
+ *prop_data = slot_names;
+ return (maxcount);
+ /*NOTREACHED*/
+ERROUT:
+ di_slot_names_free(maxcount, slot_names);
+ *prop_data = NULL;
+ return (-1);
+}
diff --git a/usr/src/lib/libdevinfo/libdevinfo.h b/usr/src/lib/libdevinfo/libdevinfo.h
index d570e8e714..ad08502628 100644
--- a/usr/src/lib/libdevinfo/libdevinfo.h
+++ b/usr/src/lib/libdevinfo/libdevinfo.h
@@ -126,6 +126,19 @@ typedef struct di_lnode *di_lnode_t; /* opaque handle to endpoint */
#define DI_PROM_HANDLE_NIL NULL
#define DI_PATH_NIL NULL
+/*
+ * IEEE 1275 properties and other standardized property names
+ */
+#define DI_PROP_FIRST_CHAS "first-in-chassis"
+#define DI_PROP_SLOT_NAMES "slot-names"
+#define DI_PROP_PHYS_SLOT "physical-slot#"
+#define DI_PROP_DEV_TYPE "device_type"
+#define DI_PROP_BUS_RANGE "bus-range"
+#define DI_PROP_SERID "serialid#"
+#define DI_PROP_REG "reg"
+#define DI_PROP_AP_NAMES "ap-names"
+
+
/* Interface Prototypes */
/*
@@ -267,6 +280,30 @@ extern int di_prom_prop_lookup_bytes(di_prom_handle_t prom, di_node_t node,
* to run on future releases.
*/
+extern di_prop_t di_prop_find(dev_t match_dev, di_node_t node,
+ const char *name);
+
+/*
+ * Interfaces for handling IEEE 1275 and other standardized properties
+ */
+
+/* structure for a single slot */
+typedef struct di_slot_name {
+ int num; /* corresponding pci device number */
+ char *name;
+} di_slot_name_t;
+
+extern void di_slot_names_free(int count, di_slot_name_t *slot_names);
+extern int di_slot_names_decode(uchar_t *rawdata, int rawlen,
+ di_slot_name_t **prop_data);
+extern int di_prop_slot_names(di_prop_t prop, di_slot_name_t **prop_data);
+extern int di_prom_prop_slot_names(di_prom_prop_t prom_prop,
+ di_slot_name_t **prop_data);
+extern int di_prop_lookup_slot_names(dev_t dev, di_node_t node,
+ di_slot_name_t **prop_data);
+extern int di_prom_prop_lookup_slot_names(di_prom_handle_t ph, di_node_t node,
+ di_slot_name_t **prop_data);
+
/*
* Interfaces for accessing I/O multipathing data
*/
diff --git a/usr/src/lib/libdevinfo/mapfile-vers b/usr/src/lib/libdevinfo/mapfile-vers
index 34251800bd..f94882dcae 100644
--- a/usr/src/lib/libdevinfo/mapfile-vers
+++ b/usr/src/lib/libdevinfo/mapfile-vers
@@ -19,7 +19,7 @@
# CDDL HEADER END
#
#
-# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -199,6 +199,13 @@ SUNWprivate_1.1 {
di_dli_openr;
di_dli_openw;
di_dli_close;
+ di_slot_names_free;
+ di_slot_names_decode;
+ di_prop_slot_names;
+ di_prom_prop_slot_names;
+ di_prop_lookup_slot_names;
+ di_prom_prop_lookup_slot_names;
+ di_prop_find;
device_exists;
finddev_readdir;
finddev_close;