2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1992-1997,2000-2003 Silicon Graphics, Inc. All rights reserved.
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <asm/sn/sgi.h>
13 #include <asm/sn/io.h>
14 #include <asm/sn/iograph.h>
15 #include <asm/sn/hwgfs.h>
16 #include <asm/sn/hcl.h>
17 #include <asm/sn/labelcl.h>
18 #include <asm/sn/hcl_util.h>
19 #include <asm/sn/nodepda.h>
21 static vertex_hdl_t hwgraph_all_cnodes = GRAPH_VERTEX_NONE;
22 extern vertex_hdl_t hwgraph_root;
23 static vertex_hdl_t hwgraph_all_cpuids = GRAPH_VERTEX_NONE;
27 mark_cpuvertex_as_cpu(vertex_hdl_t vhdl, cpuid_t cpuid)
29 char cpuid_buffer[10];
31 if (cpuid == CPU_NONE)
34 if (hwgraph_all_cpuids == GRAPH_VERTEX_NONE) {
35 (void)hwgraph_path_add( hwgraph_root,
40 sprintf(cpuid_buffer, "%ld", cpuid);
41 (void)hwgraph_edge_add( hwgraph_all_cpuids, vhdl, cpuid_buffer);
45 ** Return the "master" for a given vertex. A master vertex is a
46 ** controller or adapter or other piece of hardware that the given
47 ** vertex passes through on the way to the rest of the system.
50 device_master_get(vertex_hdl_t vhdl)
55 rc = hwgraph_edge_get(vhdl, EDGE_LBL_MASTER, &master);
56 if (rc == GRAPH_SUCCESS)
59 return(GRAPH_VERTEX_NONE);
63 ** Set the master for a given vertex.
64 ** Returns 0 on success, non-0 indicates failure
67 device_master_set(vertex_hdl_t vhdl, vertex_hdl_t master)
71 rc = hwgraph_edge_add(vhdl, master, EDGE_LBL_MASTER);
72 return(rc != GRAPH_SUCCESS);
77 ** Return the compact node id of the node that ultimately "owns" the specified
78 ** vertex. In order to do this, we walk back through masters and connect points
79 ** until we reach a vertex that represents a node.
82 master_node_get(vertex_hdl_t vhdl)
88 cnodeid = nodevertex_to_cnodeid(vhdl);
89 if (cnodeid != CNODEID_NONE)
92 master = device_master_get(vhdl);
94 /* Check for exceptional cases */
96 /* Since we got a reference to the "master" thru
97 * device_master_get() we should decrement
98 * its reference count by 1
100 return(CNODEID_NONE);
103 if (master == GRAPH_VERTEX_NONE) {
104 master = hwgraph_connectpt_get(vhdl);
105 if ((master == GRAPH_VERTEX_NONE) ||
107 return(CNODEID_NONE);
117 ** If the specified device represents a node, return its
118 ** compact node ID; otherwise, return CNODEID_NONE.
121 nodevertex_to_cnodeid(vertex_hdl_t vhdl)
124 arbitrary_info_t cnodeid = CNODEID_NONE;
126 rv = labelcl_info_get_LBL(vhdl, INFO_LBL_CNODEID, NULL, &cnodeid);
128 return((cnodeid_t)cnodeid);
132 mark_nodevertex_as_node(vertex_hdl_t vhdl, cnodeid_t cnodeid)
134 if (cnodeid == CNODEID_NONE)
137 cnodeid_to_vertex(cnodeid) = vhdl;
138 labelcl_info_add_LBL(vhdl, INFO_LBL_CNODEID, INFO_DESC_EXPORT,
139 (arbitrary_info_t)cnodeid);
142 char cnodeid_buffer[10];
144 if (hwgraph_all_cnodes == GRAPH_VERTEX_NONE) {
145 (void)hwgraph_path_add( hwgraph_root,
147 &hwgraph_all_cnodes);
150 sprintf(cnodeid_buffer, "%d", cnodeid);
151 (void)hwgraph_edge_add( hwgraph_all_cnodes,
154 HWGRAPH_DEBUG(__FILE__, __FUNCTION__, __LINE__, hwgraph_all_cnodes, NULL, "Creating path vhdl1\n");
159 ** dev_to_name converts a vertex_hdl_t into a canonical name. If the vertex_hdl_t
160 ** represents a vertex in the hardware graph, it is converted in the
161 ** normal way for vertices. If the vertex_hdl_t is an old vertex_hdl_t (one which
162 ** does not represent a hwgraph vertex), we synthesize a name based
163 ** on major/minor number.
165 ** Usually returns a pointer to the original buffer, filled in as
166 ** appropriate. If the buffer is too small to hold the entire name,
167 ** or if anything goes wrong while determining the name, dev_to_name
168 ** returns "UnknownDevice".
171 dev_to_name(vertex_hdl_t dev, char *buf, uint buflen)
173 return(vertex_to_name(dev, buf, buflen));