7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
80ab886d233f514d54c2a6bdeb9fdfd951bd6881wesolows * Common Development and Distribution License (the "License").
80ab886d233f514d54c2a6bdeb9fdfd951bd6881wesolows * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
a62774df315360f02521d6470eab7d5080137dadSinanallur Balasubramanian * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * platform specific cpu module
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int cpu_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_instance_t, void *, void *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int cpu_nvl2str(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int cpu_str2nvl(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int cpu_fmri_asru(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenportstatic int cpu_fmri_create_meth(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic nvlist_t *fmri_create(topo_mod_t *, uint32_t, uint8_t, char *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_NVL2STR, TOPO_METH_NVL2STR_DESC, TOPO_METH_NVL2STR_VERSION,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_STR2NVL, TOPO_METH_STR2NVL_DESC, TOPO_METH_STR2NVL_VERSION,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_ASRU_COMPUTE, TOPO_METH_ASRU_COMPUTE_DESC,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_ASRU_COMPUTE_VERSION, TOPO_STABILITY_INTERNAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi { TOPO_METH_FMRI, TOPO_METH_FMRI_DESC, TOPO_METH_FMRI_VERSION,
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport TOPO_STABILITY_INTERNAL, cpu_fmri_create_meth },
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((cpuip = topo_mod_zalloc(mod, sizeof (cpu_node_t))) == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi cpuip->cn_ncpustats + 1) * sizeof (kstat_t *))) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_mod_register(mod, &cpu_info, TOPO_VERSION) != 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((ksp = kstat_lookup(cpuip->cn_kc, "cpu_info", i, NULL)) ==
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindicpu_create(topo_mod_t *mod, tnode_t *rnode, const char *name,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t min, topo_instance_t max, cpu_node_t *cpuip)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) topo_node_bind(mod, rnode, name, cpu_id, fmri);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindicpu_enum(topo_mod_t *mod, tnode_t *pnode, const char *name,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_instance_t min, topo_instance_t max, void *arg, void *notused2)
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * There is no platform specific cpu module, so use
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * the default enumeration with kstats of this builtin
14ea4bb737263733ad80a36b4f73f681c30a6b45sd * cpu module.
7bebe46c240b554f47faeed19186123896281967jc "cpu enumeration failed to create "
7bebe46c240b554f47faeed19186123896281967jc "cpu range [0-%d]: %s\n",
14ea4bb737263733ad80a36b4f73f681c30a6b45sd /* Fail to load the module */
7bebe46c240b554f47faeed19186123896281967jc "Failed to load module %s: %s",
14ea4bb737263733ad80a36b4f73f681c30a6b45sd return (-1);
14ea4bb737263733ad80a36b4f73f681c30a6b45sd if (topo_mod_enumerate(nmp, pnode, PLATFORM_CPU_NAME, name,
7bebe46c240b554f47faeed19186123896281967jc "%s failed to enumerate: %s",
14ea4bb737263733ad80a36b4f73f681c30a6b45sd return (-1);
14ea4bb737263733ad80a36b4f73f681c30a6b45sd return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindifmri_nvl2str(nvlist_t *nvl, uint8_t version, char *buf, size_t buflen)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_uint32(nvl, FM_FMRI_CPU_ID, &cpuid) != 0 ||
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_lookup_uint64(nvl, FM_FMRI_CPU_SERIAL_ID, &serint)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_uint32(nvl, FM_FMRI_CPU_ID, &cpuid) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Serial number is an optional element
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rc = nvlist_lookup_string(nvl, FM_FMRI_CPU_SERIAL_ID,
7bebe46c240b554f47faeed19186123896281967jc return (0);
7bebe46c240b554f47faeed19186123896281967jc * Cache index, way and type are optional elements
7bebe46c240b554f47faeed19186123896281967jc * But if we have one of them, we must have them all.
7bebe46c240b554f47faeed19186123896281967jc rc |= nvlist_lookup_uint32(nvl, FM_FMRI_CPU_CACHE_WAY, &way);
a62774df315360f02521d6470eab7d5080137dadSinanallur Balasubramanian rc |= nvlist_lookup_uint16(nvl, FM_FMRI_CPU_CACHE_BIT, &bit);
7bebe46c240b554f47faeed19186123896281967jc rc |= nvlist_lookup_uint8(nvl, FM_FMRI_CPU_CACHE_TYPE, &type);
7bebe46c240b554f47faeed19186123896281967jc /* Insure there were no errors accessing the nvl */
7bebe46c240b554f47faeed19186123896281967jc return (0);
7bebe46c240b554f47faeed19186123896281967jc /* If we have a serial string and no cache info */
a62774df315360f02521d6470eab7d5080137dadSinanallur Balasubramanian "cpu:///%s=%u/%s=%u/%s=%u/%s=%d/%s=%d",
7bebe46c240b554f47faeed19186123896281967jc "cpu:///%s=%u/%s=%s",
a62774df315360f02521d6470eab7d5080137dadSinanallur Balasubramanian "cpu:///%s=%u/%s=%s/%s=%u/%s=%u/%s=%d/%s=%d",
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindicpu_nvl2str(topo_mod_t *mod, tnode_t *node, topo_version_t version,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_add_string(*out, "fmri-string", name) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindicpu_str2nvl(topo_mod_t *mod, tnode_t *node, topo_version_t version,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(in, "fmri-string", &str) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* We're expecting a string version of a cpu scheme FMRI */
7bebe46c240b554f47faeed19186123896281967jc /* If there is a serial #, then there might also be cache data */
7bebe46c240b554f47faeed19186123896281967jc /* If there is cache data, all must be present */
a62774df315360f02521d6470eab7d5080137dadSinanallur Balasubramanian /* Now terminate the serial string */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_mod_nvalloc(mod, &fmri, NV_UNIQUE_NAME) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_add_uint8(fmri, FM_VERSION, CPU_SCHEME_VERSION1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_CPU);
80ab886d233f514d54c2a6bdeb9fdfd951bd6881wesolows err |= nvlist_add_uint32(fmri, FM_FMRI_CPU_ID, (uint32_t)cpuid);
a62774df315360f02521d6470eab7d5080137dadSinanallur Balasubramanian err |= nvlist_add_uint16(fmri, FM_FMRI_CPU_CACHE_BIT,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindifmri_create(topo_mod_t *mod, uint32_t cpu_id, uint8_t cpumask, char *s)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_mod_nvalloc(mod, &fmri, NV_UNIQUE_NAME) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_add_uint8(fmri, FM_VERSION, FM_CPU_SCHEME_VERSION);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_CPU);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_add_uint32(fmri, FM_FMRI_CPU_ID, cpu_id);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_add_uint8(fmri, FM_FMRI_CPU_MASK, cpumask);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_add_string(fmri, FM_FMRI_CPU_SERIAL_ID, s);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindicpu_fmri_asru(topo_mod_t *mod, tnode_t *node, topo_version_t version,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rc = nvlist_lookup_uint32(in, FM_FMRI_CPU_ID, &cpu_id)) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(in, FM_FMRI_CPU_SERIAL_ID, &serial);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_uint8(in, FM_FMRI_CPU_MASK, &cpumask);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenportcpu_fmri_create_meth(topo_mod_t *mod, tnode_t *node, topo_version_t version,
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport return (topo_mod_seterrno(mod, EMOD_VER_NEW));
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport rc = nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NVL, &args);
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport * This routine requires arguments to be packed in the
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport * format used in topo_fmri_create()
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport return (topo_mod_seterrno(mod, EMOD_METHOD_INVAL));
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport if (nvlist_lookup_string(args, FM_FMRI_CPU_SERIAL_ID, &serial) != 0 ||
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport nvlist_lookup_uint32(args, FM_FMRI_CPU_ID, &cpu_id) != 0 ||
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport nvlist_lookup_uint8(args, FM_FMRI_CPU_MASK, &cpumask) != 0) {
d5ea2ced3a0abbaf6cd28ea669168246d35920e7Scott Davenport return (topo_mod_seterrno(mod, EMOD_METHOD_INVAL));