pi_generic.c revision 908f1e1388f616898b4e515d343c0414f2a6472e
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29/*
30 * Create a generic topology node for a given PRI node.
31 */
32#include <sys/types.h>
33#include <strings.h>
34#include <sys/fm/protocol.h>
35#include <fm/topo_mod.h>
36#include <fm/topo_hc.h>
37#include "pi_impl.h"
38
39#define	_ENUM_NAME	"enum_generic"
40
41int
42pi_enum_generic(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node,
43    topo_instance_t inst, tnode_t *t_parent, const char *hc_name,
44    tnode_t **t_node)
45{
46	int		result;
47
48	/*
49	 * For a generic node that is not a top-level node, we use the
50	 * same parent topology node to generate the FMRI as well as
51	 * to bind the new node.
52	 */
53	result = pi_enum_generic_impl(mod, mdp, mde_node, inst, t_parent,
54	    t_parent, hc_name, _ENUM_NAME, t_node);
55
56	return (result);
57}
58
59
60/*
61 * Create a generic topo node based on the PRI information in the machine
62 * description information.
63 */
64int
65pi_enum_generic_impl(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node,
66    topo_instance_t inst, tnode_t *t_bindparent, tnode_t *t_fmriparent,
67    const char *hc_name, const char *enum_name, tnode_t **t_node)
68{
69	nvlist_t	*fmri;
70	nvlist_t	*auth;
71
72	topo_mod_dprintf(mod, "%s adding entry for node_0x%llx type %s\n",
73	    enum_name, (uint64_t)mde_node, hc_name);
74
75	if (t_bindparent == NULL) {
76		topo_mod_dprintf(mod,
77		    "%s called with NULL parent for node_0x%llx type %s\n",
78		    enum_name, (uint64_t)mde_node, hc_name);
79		return (-1);
80	}
81
82	/* Create the FMRI for this node */
83	auth = topo_mod_auth(mod, t_bindparent);
84	fmri = topo_mod_hcfmri(mod, t_fmriparent, FM_HC_SCHEME_VERSION, hc_name,
85	    inst, NULL, auth, NULL, NULL, NULL);
86	if (fmri == NULL) {
87		topo_mod_dprintf(mod,
88		    "%s failed to create fmri node_0x%llx: %s\n", enum_name,
89		    (uint64_t)mde_node, topo_strerror(topo_mod_errno(mod)));
90		nvlist_free(auth);
91		return (-1);
92	}
93
94	/* Bind this node to the parent */
95	*t_node = pi_node_bind(mod, mdp, mde_node, t_bindparent, hc_name, inst,
96	    fmri);
97	nvlist_free(fmri);
98	nvlist_free(auth);
99	if (*t_node == NULL) {
100		topo_mod_dprintf(mod,
101		    "%s failed to bind node_0x%llx instance %d: %s\n",
102		    enum_name, (uint64_t)mde_node, (uint32_t)inst,
103		    topo_strerror(topo_mod_errno(mod)));
104		return (-1);
105	}
106
107	topo_mod_dprintf(mod, "%s added node_0x%llx type %s\n",
108	    enum_name, (uint64_t)mde_node, hc_name);
109
110	return (0);
111}
112