3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1992-1997,2000-2003 Silicon Graphics, Inc. All rights reserved.
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <asm/sn/sgi.h>
14 #include <asm/sn/io.h>
15 #include <asm/sn/iograph.h>
16 #include <asm/sn/hwgfs.h>
17 #include <asm/sn/invent.h>
18 #include <asm/sn/hcl.h>
19 #include <asm/sn/labelcl.h>
20 #include <asm/sn/invent.h>
21 #include <asm/sn/hcl_util.h>
22 #include <asm/sn/nodepda.h>
24 static vertex_hdl_t hwgraph_all_cnodes = GRAPH_VERTEX_NONE;
25 extern vertex_hdl_t hwgraph_root;
29 ** Return the "master" for a given vertex. A master vertex is a
30 ** controller or adapter or other piece of hardware that the given
31 ** vertex passes through on the way to the rest of the system.
34 device_master_get(vertex_hdl_t vhdl)
39 rc = hwgraph_edge_get(vhdl, EDGE_LBL_MASTER, &master);
40 if (rc == GRAPH_SUCCESS)
43 return(GRAPH_VERTEX_NONE);
47 ** Set the master for a given vertex.
48 ** Returns 0 on success, non-0 indicates failure
51 device_master_set(vertex_hdl_t vhdl, vertex_hdl_t master)
55 rc = hwgraph_edge_add(vhdl, master, EDGE_LBL_MASTER);
56 return(rc != GRAPH_SUCCESS);
61 ** Return the compact node id of the node that ultimately "owns" the specified
62 ** vertex. In order to do this, we walk back through masters and connect points
63 ** until we reach a vertex that represents a node.
66 master_node_get(vertex_hdl_t vhdl)
72 cnodeid = nodevertex_to_cnodeid(vhdl);
73 if (cnodeid != CNODEID_NONE)
76 master = device_master_get(vhdl);
78 /* Check for exceptional cases */
80 /* Since we got a reference to the "master" thru
81 * device_master_get() we should decrement
82 * its reference count by 1
87 if (master == GRAPH_VERTEX_NONE) {
88 master = hwgraph_connectpt_get(vhdl);
89 if ((master == GRAPH_VERTEX_NONE) ||
99 static vertex_hdl_t hwgraph_all_cpuids = GRAPH_VERTEX_NONE;
103 mark_cpuvertex_as_cpu(vertex_hdl_t vhdl, cpuid_t cpuid)
105 if (cpuid == CPU_NONE)
108 (void)labelcl_info_add_LBL(vhdl, INFO_LBL_CPUID, INFO_DESC_EXPORT,
109 (arbitrary_info_t)cpuid);
111 char cpuid_buffer[10];
113 if (hwgraph_all_cpuids == GRAPH_VERTEX_NONE) {
114 (void)hwgraph_path_add( hwgraph_root,
116 &hwgraph_all_cpuids);
119 sprintf(cpuid_buffer, "%ld", cpuid);
120 (void)hwgraph_edge_add( hwgraph_all_cpuids,
127 ** If the specified device represents a node, return its
128 ** compact node ID; otherwise, return CNODEID_NONE.
131 nodevertex_to_cnodeid(vertex_hdl_t vhdl)
134 arbitrary_info_t cnodeid = CNODEID_NONE;
136 rv = labelcl_info_get_LBL(vhdl, INFO_LBL_CNODEID, NULL, &cnodeid);
138 return((cnodeid_t)cnodeid);
142 mark_nodevertex_as_node(vertex_hdl_t vhdl, cnodeid_t cnodeid)
144 if (cnodeid == CNODEID_NONE)
147 cnodeid_to_vertex(cnodeid) = vhdl;
148 labelcl_info_add_LBL(vhdl, INFO_LBL_CNODEID, INFO_DESC_EXPORT,
149 (arbitrary_info_t)cnodeid);
152 char cnodeid_buffer[10];
154 if (hwgraph_all_cnodes == GRAPH_VERTEX_NONE) {
155 (void)hwgraph_path_add( hwgraph_root,
157 &hwgraph_all_cnodes);
160 sprintf(cnodeid_buffer, "%d", cnodeid);
161 (void)hwgraph_edge_add( hwgraph_all_cnodes,
168 ** If the specified device represents a CPU, return its cpuid;
169 ** otherwise, return CPU_NONE.
172 cpuvertex_to_cpuid(vertex_hdl_t vhdl)
174 arbitrary_info_t cpuid = CPU_NONE;
176 (void)labelcl_info_get_LBL(vhdl, INFO_LBL_CPUID, NULL, &cpuid);
178 return((cpuid_t)cpuid);
183 ** dev_to_name converts a vertex_hdl_t into a canonical name. If the vertex_hdl_t
184 ** represents a vertex in the hardware graph, it is converted in the
185 ** normal way for vertices. If the vertex_hdl_t is an old vertex_hdl_t (one which
186 ** does not represent a hwgraph vertex), we synthesize a name based
187 ** on major/minor number.
189 ** Usually returns a pointer to the original buffer, filled in as
190 ** appropriate. If the buffer is too small to hold the entire name,
191 ** or if anything goes wrong while determining the name, dev_to_name
192 ** returns "UnknownDevice".
195 dev_to_name(vertex_hdl_t dev, char *buf, uint buflen)
197 return(vertex_to_name(dev, buf, buflen));