uint16_t fnvlist_lookup_uint16(nvlist_t *nvl, const char *name) { uint16_t rv; VERIFY0(nvlist_lookup_uint16(nvl, name, &rv)); return (rv); }
static int create_chip(topo_mod_t *mod, tnode_t *pnode, topo_instance_t min, topo_instance_t max, nvlist_t *cpu, nvlist_t *auth, int mc_offchip) { tnode_t *chip; nvlist_t *fmri = NULL; int err, perr, nerr = 0; int32_t chipid, procnodeid, procnodes_per_pkg; const char *vendor; int32_t family, model; boolean_t create_mc = B_FALSE; uint16_t smbios_id; /* * /dev/fm will export the chipid based on SMBIOS' ordering * of Type-4 structures, if SMBIOS meets FMA needs */ err = nvlist_lookup_pairs(cpu, 0, FM_PHYSCPU_INFO_CHIP_ID, DATA_TYPE_INT32, &chipid, FM_PHYSCPU_INFO_NPROCNODES, DATA_TYPE_INT32, &procnodes_per_pkg, FM_PHYSCPU_INFO_PROCNODE_ID, DATA_TYPE_INT32, &procnodeid, FM_PHYSCPU_INFO_VENDOR_ID, DATA_TYPE_STRING, &vendor, FM_PHYSCPU_INFO_FAMILY, DATA_TYPE_INT32, &family, FM_PHYSCPU_INFO_MODEL, DATA_TYPE_INT32, &model, NULL); if (err) { whinge(mod, NULL, "create_chip: lookup failed: %s\n", strerror(err)); return (-1); } if (chipid < min || chipid > max) return (-1); if (FM_AWARE_SMBIOS(mod)) { if ((err = nvlist_lookup_uint16(cpu, FM_PHYSCPU_INFO_SMBIOS_ID, &smbios_id)) != 0) { whinge(mod, NULL, "create_chip: lookup smbios_id failed" ": enumerating x86pi & chip topology, but" " no Chip properties from SMBIOS" " - err msg : %s\n", strerror(err)); /* * Lets reset the module specific * data to NULL, overriding any * SMBIOS capability encoded earlier. * This will fail all subsequent * FM_AWARE_SMBIOS checks. */ topo_mod_setspecific(mod, NULL); } } if ((chip = topo_node_lookup(pnode, CHIP_NODE_NAME, chipid)) == NULL) { if ((chip = create_node(mod, pnode, auth, CHIP_NODE_NAME, chipid, smbios_id)) == NULL) return (-1); /* * Do not register XML map methods if SMBIOS can provide * serial, part, revision & label */ if (!FM_AWARE_SMBIOS(mod)) { if (topo_method_register(mod, chip, chip_methods) < 0) whinge(mod, &nerr, "create_chip: " "topo_method_register failed\n"); } (void) topo_pgroup_create(chip, &chip_pgroup, &err); nerr -= add_nvlist_strprop(mod, chip, cpu, PGNAME(CHIP), CHIP_VENDOR_ID, NULL); nerr -= add_nvlist_longprops(mod, chip, cpu, PGNAME(CHIP), NULL, CHIP_FAMILY, CHIP_MODEL, CHIP_STEPPING, NULL); if (FM_AWARE_SMBIOS(mod)) { int fru = 0; char *serial = NULL; char *part = NULL; char *rev = NULL; char *label; fru = chip_fru_smbios_get(mod, smbios_id); /* * Chip is not a FRU, set the FRU fmri of parent node */ if (topo_node_resource(chip, &fmri, &perr) != 0) whinge(mod, &nerr, "create_chip: " "topo_node_resource failed\n"); if (!fru) { (void) topo_node_fru_set(chip, NULL, 0, &perr); label = NULL; } else { label = (char *)chip_label_smbios_get(mod, pnode, smbios_id, NULL); if (topo_node_fru_set(chip, fmri, 0, &perr) != 0) { whinge(mod, NULL, "create_chip: " "topo_node_fru_set failed\n"); perr = 0; } } perr += nvlist_lookup_string(fmri, FM_FMRI_HC_SERIAL_ID, &serial); perr += nvlist_lookup_string(fmri, FM_FMRI_HC_PART, &part); perr += nvlist_lookup_string(fmri, FM_FMRI_HC_REVISION, &rev); if (perr != 0) { whinge(mod, NULL, "create_chip: nvlist_lookup_string" "failed\n"); perr = 0; } perr += topo_prop_set_string(chip, PGNAME(CHIP), FM_FMRI_HC_SERIAL_ID, TOPO_PROP_IMMUTABLE, serial, &perr); perr += topo_prop_set_string(chip, PGNAME(CHIP), FM_FMRI_HC_PART, TOPO_PROP_IMMUTABLE, part, &perr); perr += topo_prop_set_string(chip, PGNAME(CHIP), FM_FMRI_HC_REVISION, TOPO_PROP_IMMUTABLE, rev, &perr); if (perr != 0) whinge(mod, NULL, "create_chip: topo_prop_set_string" "failed\n"); nvlist_free(fmri); if (topo_node_label_set(chip, label, &perr) == -1) { whinge(mod, NULL, "create_chip: " "topo_node_label_set failed\n"); } topo_mod_strfree(mod, label); } else { if (topo_node_resource(chip, &fmri, &err) == -1) { whinge(mod, &nerr, "create_chip: " "topo_node_resource failed\n"); } else { (void) topo_node_fru_set(chip, fmri, 0, &perr); nvlist_free(fmri); } } if (topo_method_register(mod, chip, strands_retire_methods) < 0) whinge(mod, &nerr, "create_chip: " "topo_method_register failed\n"); if (topo_node_range_create(mod, chip, CORE_NODE_NAME, 0, 255)) return (-1); if (strcmp(vendor, "AuthenticAMD") == 0) { if (topo_node_range_create(mod, chip, MCT_NODE_NAME, 0, 255)) return (-1); } create_mc = B_TRUE; } if (FM_AWARE_SMBIOS(mod)) { int status = 0; /* * STATUS * CPU Socket Populated * CPU Socket Unpopulated * Populated : Enabled * Populated : Disabled by BIOS (Setup) * Populated : Disabled by BIOS (Error) * Populated : Idle * * Enumerate core & strand only for Populated : Enabled * Enumerate Off-Chip Memory Controller only for * Populated : Enabled */ status = chip_status_smbios_get(mod, (id_t)smbios_id); if (!status) { whinge(mod, NULL, "create_chip: " "CPU Socket is not populated or is disabled\n"); return (0); } } err = create_core(mod, chip, cpu, auth, smbios_id); /* * Create memory-controller node under a chip for architectures * that may have on-chip memory-controller(s). * If SMBIOS meets FMA needs, when Multi-Chip-Module is * addressed, mc instances should be derived from SMBIOS */ if (strcmp(vendor, "AuthenticAMD") == 0) { amd_mc_create(mod, smbios_id, chip, MCT_NODE_NAME, auth, procnodeid, procnodes_per_pkg, family, model, &nerr); } else if (create_mc && !mc_offchip) onchip_mc_create(mod, smbios_id, chip, MCT_NODE_NAME, auth); return (err == 0 && nerr == 0 ? 0 : -1); }
/* * Decodes (unpack) provided buffer which contains a list of name-value * pairs into given dfs_info_t structure */ static uint32_t dfs_root_decode(dfs_info_t *info, char *buf, size_t bufsz, uint32_t infolvl) { nvlist_t *nvl; char *cmnt, *guid; char *t_server, *t_share; uint32_t t_state; uint32_t t_priority_class; uint16_t t_priority_rank; boolean_t decode_priority = B_FALSE; int rc; if (nvlist_unpack(buf, bufsz, &nvl, 0) != 0) return (ERROR_INTERNAL_ERROR); rc = nvlist_lookup_string(nvl, "comment", &cmnt); rc |= nvlist_lookup_string(nvl, "guid", &guid); rc |= nvlist_lookup_uint32(nvl, "state", &info->i_state); rc |= nvlist_lookup_uint32(nvl, "timeout", &info->i_timeout); rc |= nvlist_lookup_uint32(nvl, "propflags", &info->i_propflags); if (rc != 0) { nvlist_free(nvl); return (ERROR_INTERNAL_ERROR); } (void) strlcpy(info->i_comment, (cmnt) ? cmnt : "", sizeof (info->i_comment)); (void) strlcpy(info->i_guid, (guid) ? guid : "", sizeof (info->i_guid)); info->i_targets = NULL; info->i_ntargets = 1; switch (infolvl) { case DFS_INFO_ALL: case 3: case 4: /* need target information */ break; case 6: case 9: /* need target and priority information */ decode_priority = B_TRUE; break; default: nvlist_free(nvl); return (ERROR_SUCCESS); } info->i_targets = malloc(sizeof (dfs_target_t)); if (info->i_targets == NULL) { nvlist_free(nvl); return (ERROR_NOT_ENOUGH_MEMORY); } rc = nvlist_lookup_string(nvl, "t_server", &t_server); rc |= nvlist_lookup_string(nvl, "t_share", &t_share); rc |= nvlist_lookup_uint32(nvl, "t_state", &t_state); if (rc != 0) { nvlist_free(nvl); free(info->i_targets); return (ERROR_INTERNAL_ERROR); } dfs_target_init(info->i_targets, t_server, t_share, t_state); if (decode_priority) { rc = nvlist_lookup_uint32(nvl, "t_priority_class", &t_priority_class); if (rc == 0) rc = nvlist_lookup_uint16(nvl, "t_priority_rank", &t_priority_rank); if (rc != 0 && rc != ENOENT) { nvlist_free(nvl); free(info->i_targets); return (ERROR_INTERNAL_ERROR); } else if (rc == 0) { info->i_targets->t_priority.p_class = t_priority_class; info->i_targets->t_priority.p_rank = t_priority_rank; } } nvlist_free(nvl); return (ERROR_SUCCESS); }