void mdesc_devfini(md_t *mdp) { if (mdp) (void) md_fini(mdp); if (md_bufp) free(md_bufp); md_bufp = NULL; }
/* * Extract from the PRI the processor, strand and their fru identity */ int cpu_mdesc_init(topo_mod_t *mod, md_info_t *chip) { int rc = -1; md_t *mdp; ssize_t bufsiz = 0; uint64_t *bufp; ldom_hdl_t *lhp; uint32_t type = 0; /* get the PRI/MD */ if ((lhp = ldom_init(cpu_alloc, cpu_free)) == NULL) { topo_mod_dprintf(mod, "ldom_init() failed\n"); return (topo_mod_seterrno(mod, EMOD_NOMEM)); } (void) ldom_get_type(lhp, &type); if ((type & LDOM_TYPE_CONTROL) != 0) { bufsiz = ldom_get_core_md(lhp, &bufp); } else { bufsiz = ldom_get_local_md(lhp, &bufp); } if (bufsiz <= 0) { topo_mod_dprintf(mod, "failed to get the PRI/MD\n"); ldom_fini(lhp); return (-1); } if ((mdp = md_init_intern(bufp, cpu_alloc, cpu_free)) == NULL || md_node_count(mdp) <= 0) { cpu_free(bufp, (size_t)bufsiz); ldom_fini(lhp); return (-1); } /* * N1 MD contains cpu nodes while N2 MD contains component nodes. */ if (md_find_name(mdp, MD_STR_COMPONENT) != MDE_INVAL_STR_COOKIE) { rc = cpu_n2_mdesc_init(mod, mdp, chip); } else if (md_find_name(mdp, MD_STR_CPU) != MDE_INVAL_STR_COOKIE) { rc = cpu_n1_mdesc_init(mod, mdp, chip); } else { topo_mod_dprintf(mod, "Unsupported PRI/MD\n"); rc = -1; } cpu_free(bufp, (size_t)bufsiz); (void) md_fini(mdp); ldom_fini(lhp); return (rc); }
/* * Client interface to clean up the refernce to the MD returned * by md_get_handle(). */ int md_fini_handle(md_t *ptr) { machine_descrip_t *mdescp; md_impl_t *mdp; mdp = (md_impl_t *)ptr; if (mdp == NULL) return (-1); /* * Check if mdp is current MD gen */ mutex_enter(&curr_mach_descrip_lock); if (curr_mach_descrip->gen == mdp->gen) { curr_mach_descrip->refcnt--; mutex_exit(&curr_mach_descrip_lock); goto fini; } mutex_exit(&curr_mach_descrip_lock); /* * MD is in the obsolete list */ mdescp = md_obs_list_look_up_by_gen(mdp->gen); if (mdescp == NULL) return (-1); mutex_enter(&mdescp->lock); mdescp->refcnt--; if (mdescp->refcnt == 0) { md_obs_list_remove(mdescp); mutex_exit(&mdescp->lock); destroy_machine_descrip(mdescp); goto fini; } mutex_exit(&mdescp->lock); fini: return (md_fini(ptr)); }
static int mb_get_pri_info(topo_mod_t *mod, char **serialp, char **partp, char **csnp, char **psnp) { char isa[MAXNAMELEN]; md_t *mdp; mde_cookie_t *listp; uint64_t *bufp; ssize_t bufsize = 0; int nfrus, num_nodes, i; char *pstr = NULL; char *sn, *pn, *dn, *csn, *psn; uint32_t type = 0; ldom_hdl_t *lhp; lhp = ldom_init(mb_topo_alloc, mb_topo_free); if (lhp == NULL) { topo_mod_dprintf(mod, "ldom_init failed\n"); return (-1); } (void) sysinfo(SI_MACHINE, isa, MAXNAMELEN); if (strcmp(isa, "sun4v") != 0) { topo_mod_dprintf(mod, "not sun4v architecture%s\n", isa); ldom_fini(lhp); return (-1); } (void) ldom_get_type(lhp, &type); if ((type & LDOM_TYPE_CONTROL) != 0) { bufsize = ldom_get_core_md(lhp, &bufp); } else { bufsize = ldom_get_local_md(lhp, &bufp); } if (bufsize < 1) { topo_mod_dprintf(mod, "Failed to get the pri/md (bufsize=%d)\n", bufsize); ldom_fini(lhp); return (-1); } topo_mod_dprintf(mod, "pri/md bufsize=%d\n", bufsize); if ((mdp = md_init_intern(bufp, mb_topo_alloc, mb_topo_free)) == NULL || (num_nodes = md_node_count(mdp)) < 1) { topo_mod_dprintf(mod, "md_init_intern error\n"); mb_topo_free(bufp, (size_t)bufsize); ldom_fini(lhp); return (-1); } topo_mod_dprintf(mod, "num_nodes=%d\n", num_nodes); if ((listp = (mde_cookie_t *)mb_topo_alloc( sizeof (mde_cookie_t) * num_nodes)) == NULL) { topo_mod_dprintf(mod, "alloc listp error\n"); mb_topo_free(bufp, (size_t)bufsize); (void) md_fini(mdp); ldom_fini(lhp); return (-1); } nfrus = md_scan_dag(mdp, MDE_INVAL_ELEM_COOKIE, md_find_name(mdp, "component"), md_find_name(mdp, "fwd"), listp); if (nfrus <= 0) { topo_mod_dprintf(mod, "error: nfrus=%d\n", nfrus); mb_topo_free(listp, sizeof (mde_cookie_t) * num_nodes); mb_topo_free(bufp, (size_t)bufsize); (void) md_fini(mdp); ldom_fini(lhp); return (-1); } topo_mod_dprintf(mod, "nfrus=%d\n", nfrus); sn = pn = dn = psn = csn = NULL; for (i = 0; i < nfrus; i++) { if (md_get_prop_str(mdp, listp[i], "type", &pstr) == 0) { /* systemboard/motherboard component */ if (strcmp("systemboard", pstr) == 0) { if (md_get_prop_str(mdp, listp[i], "serial_number", &sn) < 0) sn = NULL; if (md_get_prop_str(mdp, listp[i], "part_number", &pn) < 0) pn = NULL; if (md_get_prop_str(mdp, listp[i], "dash_number", &dn) < 0) dn = NULL; } else if (strcmp("product", pstr) == 0) { if (md_get_prop_str(mdp, listp[i], "serial_number", &psn) < 0) psn = NULL; } } /* redefined access method for chassis serial number */ if (md_get_prop_str(mdp, listp[i], "nac", &pstr) == 0) { if (strcmp("SYS", pstr) == 0) { if (md_get_prop_str(mdp, listp[i], "serial_number", &csn) < 0) csn = NULL; } } } *serialp = topo_mod_strdup(mod, sn); i = (pn ? strlen(pn) : 0) + (dn ? strlen(dn) : 0) + 1; pstr = mb_topo_alloc(i); (void) snprintf(pstr, i, "%s%s", pn ? pn : "", dn ? dn : ""); *partp = topo_mod_strdup(mod, pstr); mb_topo_free(pstr, i); *csnp = topo_mod_strdup(mod, csn); *psnp = topo_mod_strdup(mod, psn); mb_topo_free(listp, sizeof (mde_cookie_t) * num_nodes); mb_topo_free(bufp, (size_t)bufsize); (void) md_fini(mdp); ldom_fini(lhp); return (0); }
static int xaui_get_pri_label(topo_mod_t *mod, topo_instance_t n, void *priv, char **labelp) { ldom_hdl_t *hdlp; uint32_t type = 0; ssize_t bufsize = 0; uint64_t *bufp; md_t *mdp; int num_nodes, ncomp; mde_cookie_t *listp; char *pstr = NULL; int i; char *path; /* Get device path minus the device names */ path = xaui_get_path(mod, priv, n); if (path == NULL) { topo_mod_dprintf(mod, "can't get path\n"); return (-1); } hdlp = ldom_init(xaui_topo_alloc, xaui_topo_free); if (hdlp == NULL) { topo_mod_dprintf(mod, "ldom_init failed\n"); return (-1); } (void) ldom_get_type(hdlp, &type); if ((type & LDOM_TYPE_CONTROL) != 0) { bufsize = ldom_get_core_md(hdlp, &bufp); } else { bufsize = ldom_get_local_md(hdlp, &bufp); } if (bufsize < 1) { topo_mod_dprintf(mod, "failed to get pri/md (%d)\n", bufsize); ldom_fini(hdlp); return (-1); } if ((mdp = md_init_intern(bufp, xaui_topo_alloc, xaui_topo_free)) == NULL || (num_nodes = md_node_count(mdp)) < 1) { topo_mod_dprintf(mod, "md_init_intern failed\n"); xaui_topo_free(bufp, (size_t)bufsize); ldom_fini(hdlp); return (-1); } if ((listp = (mde_cookie_t *)xaui_topo_alloc( sizeof (mde_cookie_t) * num_nodes)) == NULL) { topo_mod_dprintf(mod, "can't alloc listp\n"); xaui_topo_free(bufp, (size_t)bufsize); (void) md_fini(mdp); ldom_fini(hdlp); return (-1); } ncomp = md_scan_dag(mdp, MDE_INVAL_ELEM_COOKIE, md_find_name(mdp, "component"), md_find_name(mdp, "fwd"), listp); if (ncomp <= 0) { topo_mod_dprintf(mod, "no component nodes found\n"); xaui_topo_free(listp, sizeof (mde_cookie_t) * num_nodes); xaui_topo_free(bufp, (size_t)bufsize); (void) md_fini(mdp); ldom_fini(hdlp); return (-1); } topo_mod_dprintf(mod, "number of comps (%d)\n", ncomp); for (i = 0; i < ncomp; i++) { /* * Look for type == "io", topo-hc-name == "xaui"; * match "path" md property. */ if ((md_get_prop_str(mdp, listp[i], "type", &pstr) == 0) && (pstr != NULL) && (strncmp(pstr, "io", strlen(pstr)) == 0) && (md_get_prop_str(mdp, listp[i], "topo-hc-name", &pstr) == 0) && (pstr != NULL) && (strncmp(pstr, "xaui", strlen(pstr)) == 0) && (md_get_prop_str(mdp, listp[i], "path", &pstr) == 0) && (pstr != NULL)) { /* check node path */ if (strncmp(pstr, path, sizeof (path)) == 0) { /* this is the node, grab the label */ if (md_get_prop_str(mdp, listp[i], "nac", &pstr) == 0) { *labelp = topo_mod_strdup(mod, pstr); /* need to free this later */ freeprilabel = 1; break; } } } } xaui_topo_free(listp, sizeof (mde_cookie_t) * num_nodes); xaui_topo_free(bufp, (size_t)bufsize); (void) md_fini(mdp); ldom_fini(hdlp); if (path != NULL) { xaui_topo_free(path, strlen(path) + 1); } return (0); }