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) 2004-2006 Silicon Graphics, Inc. All rights reserved.
8 * SGI Altix topology and hardware performance monitoring API.
9 * Mark Goodwin <markgw@sgi.com>.
11 * Creates /proc/sgi_sn/sn_topology (read-only) to export
12 * info about Altix nodes, routers, CPUs and NumaLink
13 * interconnection/topology.
15 * Also creates a dynamic misc device named "sn_hwperf"
16 * that supports an ioctl interface to call down into SAL
17 * to discover hw objects, topology and to read/write
18 * memory mapped registers, e.g. for performance monitoring.
19 * The "sn_hwperf" device is registered only after the procfs
20 * file is first opened, i.e. only if/when it's needed.
22 * This API is used by SGI Performance Co-Pilot and other
23 * tools, see http://oss.sgi.com/projects/pcp
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/seq_file.h>
30 #include <linux/miscdevice.h>
31 #include <linux/utsname.h>
32 #include <linux/cpumask.h>
33 #include <linux/smp_lock.h>
34 #include <linux/nodemask.h>
35 #include <linux/smp.h>
36 #include <linux/mutex.h>
38 #include <asm/processor.h>
39 #include <asm/topology.h>
40 #include <asm/semaphore.h>
41 #include <asm/uaccess.h>
43 #include <asm/sn/io.h>
44 #include <asm/sn/sn_sal.h>
45 #include <asm/sn/module.h>
46 #include <asm/sn/geo.h>
47 #include <asm/sn/sn2/sn_hwperf.h>
48 #include <asm/sn/addrs.h>
50 static void *sn_hwperf_salheap
= NULL
;
51 static int sn_hwperf_obj_cnt
= 0;
52 static nasid_t sn_hwperf_master_nasid
= INVALID_NASID
;
53 static int sn_hwperf_init(void);
54 static DEFINE_MUTEX(sn_hwperf_init_mutex
);
56 #define cnode_possible(n) ((n) < num_cnodes)
58 static int sn_hwperf_enum_objects(int *nobj
, struct sn_hwperf_object_info
**ret
)
62 struct sn_hwperf_object_info
*objbuf
= NULL
;
64 if ((e
= sn_hwperf_init()) < 0) {
65 printk(KERN_ERR
"sn_hwperf_init failed: err %d\n", e
);
69 sz
= sn_hwperf_obj_cnt
* sizeof(struct sn_hwperf_object_info
);
72 printk("sn_hwperf_enum_objects: vmalloc(%d) failed\n", (int)sz
);
77 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, SN_HWPERF_ENUM_OBJECTS
,
78 0, sz
, (u64
) objbuf
, 0, 0, NULL
);
79 if (e
!= SN_HWPERF_OP_OK
) {
85 *nobj
= sn_hwperf_obj_cnt
;
90 static int sn_hwperf_location_to_bpos(char *location
,
91 int *rack
, int *bay
, int *slot
, int *slab
)
95 /* first scan for an old style geoid string */
96 if (sscanf(location
, "%03d%c%02d#%d",
97 rack
, &type
, bay
, slab
) == 4)
99 else /* scan for a new bladed geoid string */
100 if (sscanf(location
, "%03d%c%02d^%02d#%d",
101 rack
, &type
, bay
, slot
, slab
) != 5)
107 static int sn_hwperf_geoid_to_cnode(char *location
)
111 moduleid_t module_id
;
112 int rack
, bay
, slot
, slab
;
113 int this_rack
, this_bay
, this_slot
, this_slab
;
115 if (sn_hwperf_location_to_bpos(location
, &rack
, &bay
, &slot
, &slab
))
119 * FIXME: replace with cleaner for_each_XXX macro which addresses
120 * both compute and IO nodes once ACPI3.0 is available.
122 for (cnode
= 0; cnode
< num_cnodes
; cnode
++) {
123 geoid
= cnodeid_get_geoid(cnode
);
124 module_id
= geo_module(geoid
);
125 this_rack
= MODULE_GET_RACK(module_id
);
126 this_bay
= MODULE_GET_BPOS(module_id
);
127 this_slot
= geo_slot(geoid
);
128 this_slab
= geo_slab(geoid
);
129 if (rack
== this_rack
&& bay
== this_bay
&&
130 slot
== this_slot
&& slab
== this_slab
) {
135 return cnode_possible(cnode
) ? cnode
: -1;
138 static int sn_hwperf_obj_to_cnode(struct sn_hwperf_object_info
* obj
)
140 if (!SN_HWPERF_IS_NODE(obj
) && !SN_HWPERF_IS_IONODE(obj
))
142 if (SN_HWPERF_FOREIGN(obj
))
144 return sn_hwperf_geoid_to_cnode(obj
->location
);
147 static int sn_hwperf_generic_ordinal(struct sn_hwperf_object_info
*obj
,
148 struct sn_hwperf_object_info
*objs
)
151 struct sn_hwperf_object_info
*p
;
153 for (ordinal
=0, p
=objs
; p
!= obj
; p
++) {
154 if (SN_HWPERF_FOREIGN(p
))
156 if (SN_HWPERF_SAME_OBJTYPE(p
, obj
))
163 static const char *slabname_node
= "node"; /* SHub asic */
164 static const char *slabname_ionode
= "ionode"; /* TIO asic */
165 static const char *slabname_router
= "router"; /* NL3R or NL4R */
166 static const char *slabname_other
= "other"; /* unknown asic */
168 static const char *sn_hwperf_get_slabname(struct sn_hwperf_object_info
*obj
,
169 struct sn_hwperf_object_info
*objs
, int *ordinal
)
172 const char *slabname
= slabname_other
;
174 if ((isnode
= SN_HWPERF_IS_NODE(obj
)) || SN_HWPERF_IS_IONODE(obj
)) {
175 slabname
= isnode
? slabname_node
: slabname_ionode
;
176 *ordinal
= sn_hwperf_obj_to_cnode(obj
);
179 *ordinal
= sn_hwperf_generic_ordinal(obj
, objs
);
180 if (SN_HWPERF_IS_ROUTER(obj
))
181 slabname
= slabname_router
;
187 static void print_pci_topology(struct seq_file
*s
)
193 for (sz
= PAGE_SIZE
; sz
< 16 * PAGE_SIZE
; sz
+= PAGE_SIZE
) {
194 if (!(p
= kmalloc(sz
, GFP_KERNEL
)))
196 e
= ia64_sn_ioif_get_pci_topology(__pa(p
), sz
);
200 if (e
== SALRET_OK
|| e
== SALRET_NOT_IMPLEMENTED
)
205 static inline int sn_hwperf_has_cpus(cnodeid_t node
)
207 return node
< MAX_NUMNODES
&& node_online(node
) && nr_cpus_node(node
);
210 static inline int sn_hwperf_has_mem(cnodeid_t node
)
212 return node
< MAX_NUMNODES
&& node_online(node
) && NODE_DATA(node
)->node_present_pages
;
215 static struct sn_hwperf_object_info
*
216 sn_hwperf_findobj_id(struct sn_hwperf_object_info
*objbuf
,
220 struct sn_hwperf_object_info
*p
= objbuf
;
222 for (i
=0; i
< nobj
; i
++, p
++) {
231 static int sn_hwperf_get_nearest_node_objdata(struct sn_hwperf_object_info
*objbuf
,
232 int nobj
, cnodeid_t node
, cnodeid_t
*near_mem_node
, cnodeid_t
*near_cpu_node
)
235 struct sn_hwperf_object_info
*nodeobj
= NULL
;
236 struct sn_hwperf_object_info
*op
;
237 struct sn_hwperf_object_info
*dest
;
238 struct sn_hwperf_object_info
*router
;
239 struct sn_hwperf_port_info ptdata
[16];
245 if (!cnode_possible(node
))
248 if (sn_hwperf_has_cpus(node
)) {
250 *near_cpu_node
= node
;
254 if (sn_hwperf_has_mem(node
)) {
256 *near_mem_node
= node
;
260 if (found_cpu
&& found_mem
)
261 return 0; /* trivially successful */
263 /* find the argument node object */
264 for (i
=0, op
=objbuf
; i
< nobj
; i
++, op
++) {
265 if (!SN_HWPERF_IS_NODE(op
) && !SN_HWPERF_IS_IONODE(op
))
267 if (node
== sn_hwperf_obj_to_cnode(op
)) {
277 /* get it's interconnect topology */
278 sz
= op
->ports
* sizeof(struct sn_hwperf_port_info
);
279 if (sz
> sizeof(ptdata
))
281 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
282 SN_HWPERF_ENUM_PORTS
, nodeobj
->id
, sz
,
283 (u64
)&ptdata
, 0, 0, NULL
);
284 if (e
!= SN_HWPERF_OP_OK
) {
289 /* find nearest node with cpus and nearest memory */
290 for (router
=NULL
, j
=0; j
< op
->ports
; j
++) {
291 dest
= sn_hwperf_findobj_id(objbuf
, nobj
, ptdata
[j
].conn_id
);
292 if (dest
&& SN_HWPERF_IS_ROUTER(dest
))
294 if (!dest
|| SN_HWPERF_FOREIGN(dest
) ||
295 !SN_HWPERF_IS_NODE(dest
) || SN_HWPERF_IS_IONODE(dest
)) {
298 c
= sn_hwperf_obj_to_cnode(dest
);
299 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
304 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
311 if (router
&& (!found_cpu
|| !found_mem
)) {
312 /* search for a node connected to the same router */
313 sz
= router
->ports
* sizeof(struct sn_hwperf_port_info
);
314 if (sz
> sizeof(ptdata
))
316 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
317 SN_HWPERF_ENUM_PORTS
, router
->id
, sz
,
318 (u64
)&ptdata
, 0, 0, NULL
);
319 if (e
!= SN_HWPERF_OP_OK
) {
323 for (j
=0; j
< router
->ports
; j
++) {
324 dest
= sn_hwperf_findobj_id(objbuf
, nobj
,
326 if (!dest
|| dest
->id
== node
||
327 SN_HWPERF_FOREIGN(dest
) ||
328 !SN_HWPERF_IS_NODE(dest
) ||
329 SN_HWPERF_IS_IONODE(dest
)) {
332 c
= sn_hwperf_obj_to_cnode(dest
);
333 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
338 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
343 if (found_cpu
&& found_mem
)
348 if (!found_cpu
|| !found_mem
) {
349 /* resort to _any_ node with CPUs and memory */
350 for (i
=0, op
=objbuf
; i
< nobj
; i
++, op
++) {
351 if (SN_HWPERF_FOREIGN(op
) ||
352 SN_HWPERF_IS_IONODE(op
) ||
353 !SN_HWPERF_IS_NODE(op
)) {
356 c
= sn_hwperf_obj_to_cnode(op
);
357 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
362 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
367 if (found_cpu
&& found_mem
)
372 if (!found_cpu
|| !found_mem
)
380 static int sn_topology_show(struct seq_file
*s
, void *d
)
387 const char *slabname
;
391 struct cpuinfo_ia64
*c
;
392 struct sn_hwperf_port_info
*ptdata
;
393 struct sn_hwperf_object_info
*p
;
394 struct sn_hwperf_object_info
*obj
= d
; /* this object */
395 struct sn_hwperf_object_info
*objs
= s
->private; /* all objects */
407 seq_printf(s
, "# sn_topology version 2\n");
408 seq_printf(s
, "# objtype ordinal location partition"
409 " [attribute value [, ...]]\n");
411 if (ia64_sn_get_sn_info(0,
412 &shubtype
, &nasid_mask
, &nasid_shift
, &system_size
,
413 &sharing_size
, &partid
, &coher
, ®ion_size
))
415 for (nasid_msb
=63; nasid_msb
> 0; nasid_msb
--) {
416 if (((u64
)nasid_mask
<< nasid_shift
) & (1ULL << nasid_msb
))
419 seq_printf(s
, "partition %u %s local "
421 "nasid_mask 0x%016lx, "
425 "coherency_domain %d, "
428 partid
, utsname()->nodename
,
429 shubtype
? "shub2" : "shub1",
430 (u64
)nasid_mask
<< nasid_shift
, nasid_msb
, nasid_shift
,
431 system_size
, sharing_size
, coher
, region_size
);
433 print_pci_topology(s
);
436 if (SN_HWPERF_FOREIGN(obj
)) {
437 /* private in another partition: not interesting */
441 for (i
= 0; i
< SN_HWPERF_MAXSTRING
&& obj
->name
[i
]; i
++) {
442 if (obj
->name
[i
] == ' ')
446 slabname
= sn_hwperf_get_slabname(obj
, objs
, &ordinal
);
447 seq_printf(s
, "%s %d %s %s asic %s", slabname
, ordinal
, obj
->location
,
448 obj
->sn_hwp_this_part
? "local" : "shared", obj
->name
);
450 if (ordinal
< 0 || (!SN_HWPERF_IS_NODE(obj
) && !SN_HWPERF_IS_IONODE(obj
)))
453 cnodeid_t near_mem
= -1;
454 cnodeid_t near_cpu
= -1;
456 seq_printf(s
, ", nasid 0x%x", cnodeid_to_nasid(ordinal
));
458 if (sn_hwperf_get_nearest_node_objdata(objs
, sn_hwperf_obj_cnt
,
459 ordinal
, &near_mem
, &near_cpu
) == 0) {
460 seq_printf(s
, ", near_mem_nodeid %d, near_cpu_nodeid %d",
464 if (!SN_HWPERF_IS_IONODE(obj
)) {
465 for_each_online_node(i
) {
466 seq_printf(s
, i
? ":%d" : ", dist %d",
467 node_distance(ordinal
, i
));
474 * CPUs on this node, if any
476 if (!SN_HWPERF_IS_IONODE(obj
)) {
477 cpumask
= node_to_cpumask(ordinal
);
478 for_each_online_cpu(i
) {
479 if (cpu_isset(i
, cpumask
)) {
480 slice
= 'a' + cpuid_to_slice(i
);
482 seq_printf(s
, "cpu %d %s%c local"
483 " freq %luMHz, arch ia64",
484 i
, obj
->location
, slice
,
485 c
->proc_freq
/ 1000000);
486 for_each_online_cpu(j
) {
487 seq_printf(s
, j
? ":%d" : ", dist %d",
502 sz
= obj
->ports
* sizeof(struct sn_hwperf_port_info
);
503 if ((ptdata
= kmalloc(sz
, GFP_KERNEL
)) == NULL
)
505 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
506 SN_HWPERF_ENUM_PORTS
, obj
->id
, sz
,
507 (u64
) ptdata
, 0, 0, NULL
);
508 if (e
!= SN_HWPERF_OP_OK
)
510 for (ordinal
=0, p
=objs
; p
!= obj
; p
++) {
511 if (!SN_HWPERF_FOREIGN(p
))
514 for (pt
= 0; pt
< obj
->ports
; pt
++) {
515 for (p
= objs
, i
= 0; i
< sn_hwperf_obj_cnt
; i
++, p
++) {
516 if (ptdata
[pt
].conn_id
== p
->id
) {
520 seq_printf(s
, "numalink %d %s-%d",
521 ordinal
+pt
, obj
->location
, ptdata
[pt
].port
);
523 if (i
>= sn_hwperf_obj_cnt
) {
525 seq_puts(s
, " local endpoint disconnected"
526 ", protocol unknown\n");
530 if (obj
->sn_hwp_this_part
&& p
->sn_hwp_this_part
)
531 /* both ends local to this partition */
532 seq_puts(s
, " local");
533 else if (SN_HWPERF_FOREIGN(p
))
534 /* both ends of the link in foreign partiton */
535 seq_puts(s
, " foreign");
537 /* link straddles a partition */
538 seq_puts(s
, " shared");
541 * Unlikely, but strictly should query the LLP config
542 * registers because an NL4R can be configured to run
543 * NL3 protocol, even when not talking to an NL3 router.
544 * Ditto for node-node.
546 seq_printf(s
, " endpoint %s-%d, protocol %s\n",
547 p
->location
, ptdata
[pt
].conn_port
,
548 (SN_HWPERF_IS_NL3ROUTER(obj
) ||
549 SN_HWPERF_IS_NL3ROUTER(p
)) ? "LLP3" : "LLP4");
557 static void *sn_topology_start(struct seq_file
*s
, loff_t
* pos
)
559 struct sn_hwperf_object_info
*objs
= s
->private;
561 if (*pos
< sn_hwperf_obj_cnt
)
562 return (void *)(objs
+ *pos
);
567 static void *sn_topology_next(struct seq_file
*s
, void *v
, loff_t
* pos
)
570 return sn_topology_start(s
, pos
);
573 static void sn_topology_stop(struct seq_file
*m
, void *v
)
579 * /proc/sgi_sn/sn_topology, read-only using seq_file
581 static const struct seq_operations sn_topology_seq_ops
= {
582 .start
= sn_topology_start
,
583 .next
= sn_topology_next
,
584 .stop
= sn_topology_stop
,
585 .show
= sn_topology_show
588 struct sn_hwperf_op_info
{
590 struct sn_hwperf_ioctl_args
*a
;
596 static void sn_hwperf_call_sal(void *info
)
598 struct sn_hwperf_op_info
*op_info
= info
;
601 r
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, op_info
->op
,
602 op_info
->a
->arg
, op_info
->a
->sz
,
603 (u64
) op_info
->p
, 0, 0, op_info
->v0
);
607 static int sn_hwperf_op_cpu(struct sn_hwperf_op_info
*op_info
)
612 cpumask_t save_allowed
;
614 cpu
= (op_info
->a
->arg
& SN_HWPERF_ARG_CPU_MASK
) >> 32;
615 use_ipi
= op_info
->a
->arg
& SN_HWPERF_ARG_USE_IPI_MASK
;
616 op_info
->a
->arg
&= SN_HWPERF_ARG_OBJID_MASK
;
618 if (cpu
!= SN_HWPERF_ARG_ANY_CPU
) {
619 if (cpu
>= NR_CPUS
|| !cpu_online(cpu
)) {
625 if (cpu
== SN_HWPERF_ARG_ANY_CPU
|| cpu
== get_cpu()) {
626 /* don't care, or already on correct cpu */
627 sn_hwperf_call_sal(op_info
);
631 /* use an interprocessor interrupt to call SAL */
632 smp_call_function_single(cpu
, sn_hwperf_call_sal
,
636 /* migrate the task before calling SAL */
637 save_allowed
= current
->cpus_allowed
;
638 set_cpus_allowed(current
, cpumask_of_cpu(cpu
));
639 sn_hwperf_call_sal(op_info
);
640 set_cpus_allowed(current
, save_allowed
);
649 /* map SAL hwperf error code to system error code */
650 static int sn_hwperf_map_err(int hwperf_err
)
655 case SN_HWPERF_OP_OK
:
659 case SN_HWPERF_OP_NOMEM
:
663 case SN_HWPERF_OP_NO_PERM
:
667 case SN_HWPERF_OP_IO_ERROR
:
671 case SN_HWPERF_OP_BUSY
:
675 case SN_HWPERF_OP_RECONFIGURE
:
679 case SN_HWPERF_OP_INVAL
:
689 * ioctl for "sn_hwperf" misc device
692 sn_hwperf_ioctl(struct inode
*in
, struct file
*fp
, u32 op
, u64 arg
)
694 struct sn_hwperf_ioctl_args a
;
695 struct cpuinfo_ia64
*cdata
;
696 struct sn_hwperf_object_info
*objs
;
697 struct sn_hwperf_object_info
*cpuobj
;
698 struct sn_hwperf_op_info op_info
;
710 /* only user requests are allowed here */
711 if ((op
& SN_HWPERF_OP_MASK
) < 10) {
715 r
= copy_from_user(&a
, (const void __user
*)arg
,
716 sizeof(struct sn_hwperf_ioctl_args
));
723 * Allocate memory to hold a kernel copy of the user buffer. The
724 * buffer contents are either copied in or out (or both) of user
725 * space depending on the flags encoded in the requested operation.
735 if (op
& SN_HWPERF_OP_MEM_COPYIN
) {
736 r
= copy_from_user(p
, (const void __user
*)a
.ptr
, a
.sz
);
744 case SN_HWPERF_GET_CPU_INFO
:
745 if (a
.sz
== sizeof(u64
)) {
746 /* special case to get size needed */
747 *(u64
*) p
= (u64
) num_online_cpus() *
748 sizeof(struct sn_hwperf_object_info
);
750 if (a
.sz
< num_online_cpus() * sizeof(struct sn_hwperf_object_info
)) {
754 if ((r
= sn_hwperf_enum_objects(&nobj
, &objs
)) == 0) {
755 int cpuobj_index
= 0;
758 for (i
= 0; i
< nobj
; i
++) {
759 if (!SN_HWPERF_IS_NODE(objs
+ i
))
761 node
= sn_hwperf_obj_to_cnode(objs
+ i
);
762 for_each_online_cpu(j
) {
763 if (node
!= cpu_to_node(j
))
765 cpuobj
= (struct sn_hwperf_object_info
*) p
+ cpuobj_index
++;
766 slice
= 'a' + cpuid_to_slice(j
);
769 snprintf(cpuobj
->name
,
770 sizeof(cpuobj
->name
),
772 cdata
->proc_freq
/ 1000000,
774 snprintf(cpuobj
->location
,
775 sizeof(cpuobj
->location
),
776 "%s%c", objs
[i
].location
,
785 case SN_HWPERF_GET_NODE_NASID
:
786 if (a
.sz
!= sizeof(u64
) ||
787 (node
= a
.arg
) < 0 || !cnode_possible(node
)) {
791 *(u64
*)p
= (u64
)cnodeid_to_nasid(node
);
794 case SN_HWPERF_GET_OBJ_NODE
:
795 if (a
.sz
!= sizeof(u64
) || a
.arg
< 0) {
799 if ((r
= sn_hwperf_enum_objects(&nobj
, &objs
)) == 0) {
805 if (objs
[(i
= a
.arg
)].id
!= a
.arg
) {
806 for (i
= 0; i
< nobj
; i
++) {
807 if (objs
[i
].id
== a
.arg
)
817 if (!SN_HWPERF_IS_NODE(objs
+ i
) &&
818 !SN_HWPERF_IS_IONODE(objs
+ i
)) {
824 *(u64
*)p
= (u64
)sn_hwperf_obj_to_cnode(objs
+ i
);
829 case SN_HWPERF_GET_MMRS
:
830 case SN_HWPERF_SET_MMRS
:
831 case SN_HWPERF_OBJECT_DISTANCE
:
836 r
= sn_hwperf_op_cpu(&op_info
);
838 r
= sn_hwperf_map_err(r
);
845 /* all other ops are a direct SAL call */
846 r
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, op
,
847 a
.arg
, a
.sz
, (u64
) p
, 0, 0, &v0
);
849 r
= sn_hwperf_map_err(r
);
856 if (op
& SN_HWPERF_OP_MEM_COPYOUT
) {
857 r
= copy_to_user((void __user
*)a
.ptr
, p
, a
.sz
);
871 static const struct file_operations sn_hwperf_fops
= {
872 .ioctl
= sn_hwperf_ioctl
,
875 static struct miscdevice sn_hwperf_dev
= {
881 static int sn_hwperf_init(void)
887 /* single threaded, once-only initialization */
888 mutex_lock(&sn_hwperf_init_mutex
);
890 if (sn_hwperf_salheap
) {
891 mutex_unlock(&sn_hwperf_init_mutex
);
896 * The PROM code needs a fixed reference node. For convenience the
897 * same node as the console I/O is used.
899 sn_hwperf_master_nasid
= (nasid_t
) ia64_sn_get_console_nasid();
902 * Request the needed size and install the PROM scratch area.
903 * The PROM keeps various tracking bits in this memory area.
905 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
906 (u64
) SN_HWPERF_GET_HEAPSIZE
, 0,
907 (u64
) sizeof(u64
), (u64
) &v
, 0, 0, NULL
);
908 if (salr
!= SN_HWPERF_OP_OK
) {
913 if ((sn_hwperf_salheap
= vmalloc(v
)) == NULL
) {
917 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
918 SN_HWPERF_INSTALL_HEAP
, 0, v
,
919 (u64
) sn_hwperf_salheap
, 0, 0, NULL
);
920 if (salr
!= SN_HWPERF_OP_OK
) {
925 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
926 SN_HWPERF_OBJECT_COUNT
, 0,
927 sizeof(u64
), (u64
) &v
, 0, 0, NULL
);
928 if (salr
!= SN_HWPERF_OP_OK
) {
932 sn_hwperf_obj_cnt
= (int)v
;
935 if (e
< 0 && sn_hwperf_salheap
) {
936 vfree(sn_hwperf_salheap
);
937 sn_hwperf_salheap
= NULL
;
938 sn_hwperf_obj_cnt
= 0;
940 mutex_unlock(&sn_hwperf_init_mutex
);
944 int sn_topology_open(struct inode
*inode
, struct file
*file
)
947 struct seq_file
*seq
;
948 struct sn_hwperf_object_info
*objbuf
;
951 if ((e
= sn_hwperf_enum_objects(&nobj
, &objbuf
)) == 0) {
952 e
= seq_open(file
, &sn_topology_seq_ops
);
953 seq
= file
->private_data
;
954 seq
->private = objbuf
;
960 int sn_topology_release(struct inode
*inode
, struct file
*file
)
962 struct seq_file
*seq
= file
->private_data
;
965 return seq_release(inode
, file
);
968 int sn_hwperf_get_nearest_node(cnodeid_t node
,
969 cnodeid_t
*near_mem_node
, cnodeid_t
*near_cpu_node
)
973 struct sn_hwperf_object_info
*objbuf
;
975 if ((e
= sn_hwperf_enum_objects(&nobj
, &objbuf
)) == 0) {
976 e
= sn_hwperf_get_nearest_node_objdata(objbuf
, nobj
,
977 node
, near_mem_node
, near_cpu_node
);
984 static int __devinit
sn_hwperf_misc_register_init(void)
988 if (!ia64_platform_is("sn2"))
994 * Register a dynamic misc device for hwperf ioctls. Platforms
995 * supporting hotplug will create /dev/sn_hwperf, else user
996 * can to look up the minor number in /proc/misc.
998 if ((e
= misc_register(&sn_hwperf_dev
)) != 0) {
999 printk(KERN_ERR
"sn_hwperf_misc_register_init: failed to "
1000 "register misc device for \"%s\"\n", sn_hwperf_dev
.name
);
1006 device_initcall(sn_hwperf_misc_register_init
); /* after misc_init() */
1007 EXPORT_SYMBOL(sn_hwperf_get_nearest_node
);