ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / base / node.c
1 /*
2  * drivers/base/node.c - basic Node class support
3  */
4
5 #include <linux/sysdev.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/mm.h>
9 #include <linux/node.h>
10 #include <linux/cpumask.h>
11 #include <linux/topology.h>
12
13 static struct sysdev_class node_class = {
14         set_kset_name("node"),
15 };
16
17
18 static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
19 {
20         struct node *node_dev = to_node(dev);
21         cpumask_t mask = node_dev->cpumap;
22         int len;
23
24         /* FIXME - someone should pass us a buffer size (count) or
25          * use seq_file or something to avoid buffer overrun risk. */
26         len = cpumask_scnprintf(buf, 99 /* XXX FIXME */, mask);
27         len += sprintf(buf + len, "\n");
28         return len;
29 }
30
31 static SYSDEV_ATTR(cpumap,S_IRUGO,node_read_cpumap,NULL);
32
33 #define K(x) ((x) << (PAGE_SHIFT - 10))
34 static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
35 {
36         int nid = dev->id;
37         struct sysinfo i;
38         si_meminfo_node(&i, nid);
39         return sprintf(buf, "\n"
40                        "Node %d MemTotal:     %8lu kB\n"
41                        "Node %d MemFree:      %8lu kB\n"
42                        "Node %d MemUsed:      %8lu kB\n"
43                        "Node %d HighTotal:    %8lu kB\n"
44                        "Node %d HighFree:     %8lu kB\n"
45                        "Node %d LowTotal:     %8lu kB\n"
46                        "Node %d LowFree:      %8lu kB\n",
47                        nid, K(i.totalram),
48                        nid, K(i.freeram),
49                        nid, K(i.totalram-i.freeram),
50                        nid, K(i.totalhigh),
51                        nid, K(i.freehigh),
52                        nid, K(i.totalram-i.totalhigh),
53                        nid, K(i.freeram-i.freehigh));
54 }
55 #undef K 
56 static SYSDEV_ATTR(meminfo,S_IRUGO,node_read_meminfo,NULL);
57
58
59 /*
60  * register_node - Setup a driverfs device for a node.
61  * @num - Node number to use when creating the device.
62  *
63  * Initialize and register the node device.
64  */
65 int __init register_node(struct node *node, int num, struct node *parent)
66 {
67         int error;
68
69         node->cpumap = node_to_cpumask(num);
70         node->sysdev.id = num;
71         node->sysdev.cls = &node_class;
72         error = sysdev_register(&node->sysdev);
73
74         if (!error){
75                 sysdev_create_file(&node->sysdev, &attr_cpumap);
76                 sysdev_create_file(&node->sysdev, &attr_meminfo);
77         }
78         return error;
79 }
80
81
82 int __init register_node_type(void)
83 {
84         return sysdev_class_register(&node_class);
85 }
86 postcore_initcall(register_node_type);