2 * drivers/base/node.c - basic Node class support
5 #include <linux/sysdev.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
9 #include <linux/node.h>
10 #include <linux/cpumask.h>
11 #include <linux/topology.h>
13 static struct sysdev_class node_class = {
14 set_kset_name("node"),
18 static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
20 struct node *node_dev = to_node(dev);
21 cpumask_t mask = node_dev->cpumap;
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");
31 static SYSDEV_ATTR(cpumap,S_IRUGO,node_read_cpumap,NULL);
33 #define K(x) ((x) << (PAGE_SHIFT - 10))
34 static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
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",
49 nid, K(i.totalram-i.freeram),
52 nid, K(i.totalram-i.totalhigh),
53 nid, K(i.freeram-i.freehigh));
56 static SYSDEV_ATTR(meminfo,S_IRUGO,node_read_meminfo,NULL);
60 * register_node - Setup a driverfs device for a node.
61 * @num - Node number to use when creating the device.
63 * Initialize and register the node device.
65 int __init register_node(struct node *node, int num, struct node *parent)
69 node->cpumap = node_to_cpumask(num);
70 node->sysdev.id = num;
71 node->sysdev.cls = &node_class;
72 error = sysdev_register(&node->sysdev);
75 sysdev_create_file(&node->sysdev, &attr_cpumap);
76 sysdev_create_file(&node->sysdev, &attr_meminfo);
82 int __init register_node_type(void)
84 return sysdev_class_register(&node_class);
86 postcore_initcall(register_node_type);