int di_bytes_get(topo_mod_t *mod, di_node_t n, const char *pnm, int *sz, uchar_t **db) { di_prom_handle_t ptp = DI_PROM_HANDLE_NIL; di_prom_prop_t pp = DI_PROM_PROP_NIL; di_prop_t hp = DI_PROP_NIL; if ((ptp = topo_mod_prominfo(mod)) == DI_PROM_HANDLE_NIL) return (-1); *sz = -1; while ((hp = di_prop_next(n, hp)) != DI_PROP_NIL) { if (strcmp(di_prop_name(hp), pnm) == 0) { if ((*sz = di_prop_bytes(hp, db)) < 0) continue; break; } } if (*sz < 0) { while ((pp = di_prom_prop_next(ptp, n, pp)) != DI_PROM_PROP_NIL) { if (strcmp(di_prom_prop_name(pp), pnm) == 0) { *sz = di_prom_prop_data(pp, db); if (*sz < 0) continue; break; } } } if (*sz < 0) return (-1); return (0); }
/* * Get the value of the named property on the named node in root. */ static char * get_prop(const char *nodename, const char *propname, size_t *lenp) { di_node_t node; di_prom_prop_t pp; char *val = NULL; int len; /* * Locate nodename within '/'. */ for (node = di_child_node(root_node); node != DI_NODE_NIL; node = di_sibling_node(node)) { if (strcmp(di_node_name(node), nodename) == 0) { break; } } if (node == DI_NODE_NIL) { return (NULL); } /* * Scan all properties of /nodename for the 'propname' property. */ for (pp = di_prom_prop_next(phdl, node, DI_PROM_PROP_NIL); pp != DI_PROM_PROP_NIL; pp = di_prom_prop_next(phdl, node, pp)) { if (strcmp(propname, di_prom_prop_name(pp)) == 0) { break; } } if (pp == DI_PROM_PROP_NIL) { return (NULL); } /* * Found the property; copy out its length and return its value. */ len = di_prom_prop_data(pp, (uchar_t **)&val); if (lenp != NULL) { *lenp = len; } return (val); }
/* * Check the root complex device node for a slot-names property. */ const char * opl_get_slot_name(topo_mod_t *mod, di_node_t n) { di_prom_handle_t ptp = DI_PROM_HANDLE_NIL; di_prom_prop_t pp = DI_PROM_PROP_NIL; uchar_t *buf; if ((ptp = topo_mod_prominfo(mod)) == DI_PROM_PROP_NIL) return (NULL); for (pp = di_prom_prop_next(ptp, n, pp); pp != DI_PROM_PROP_NIL; pp = di_prom_prop_next(ptp, n, pp)) { if (strcmp(di_prom_prop_name(pp), OPL_SLOT_NAMES) == 0) { if (di_prom_prop_data(pp, &buf) <= sizeof (uint32_t)) continue; return ((const char *)&buf[4]); } } return (NULL); }
/* * Retrieve the version from the card. * uses PROM properties */ static int emulex_fcodeversion(di_node_t node, uchar_t *ver) { di_prom_prop_t promprop; di_prom_handle_t ph; char *promname; uchar_t *ver_data = NULL; int size, found = 0; /* check to make sure ver is not NULL */ if (ver == NULL) { return (1); } if ((ph = di_prom_init()) == DI_PROM_HANDLE_NIL) { return (1); } for (promprop = di_prom_prop_next(ph, node, DI_PROM_PROP_NIL); promprop != DI_PROM_PROP_NIL; promprop = di_prom_prop_next(ph, node, promprop)) { if (((promname = di_prom_prop_name( promprop)) != NULL) && (strcmp(promname, "fcode-version") == 0)) { size = di_prom_prop_data(promprop, &ver_data); (void) memset(ver, NULL, size); (void) memcpy(ver, ver_data, size); found = 1; } } if (found) { return (0); } else { return (1); } }
/* * If this devinfo node came originally from OBP data, we'll have prom * properties associated with the node where we can find properties of * interest. We ignore anything after the the first four bytes of the * property, and interpet those first four bytes as our unsigned * integer. If we don't find the property or it's not large enough, * 'val' will remained unchanged and we'll return -1. Otherwise 'val' * gets updated with the property value and we return 0. */ static int promprop2uint(topo_mod_t *mod, di_node_t n, const char *propnm, uint_t *val) { di_prom_handle_t ptp = DI_PROM_HANDLE_NIL; di_prom_prop_t pp = DI_PROM_PROP_NIL; uchar_t *buf; if ((ptp = topo_mod_prominfo(mod)) == DI_PROM_HANDLE_NIL) return (-1); while ((pp = di_prom_prop_next(ptp, n, pp)) != DI_PROM_PROP_NIL) { if (strcmp(di_prom_prop_name(pp), propnm) == 0) { if (di_prom_prop_data(pp, &buf) < sizeof (uint_t)) continue; bcopy(buf, val, sizeof (uint_t)); return (0); } } return (-1); }