]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/node.c
Driver core: change sysdev classes to use dynamic kobject names
[linux-2.6-omap-h63xx.git] / drivers / base / node.c
index 001e6f6b9c1bf085130f3f286b2a45d1116abf62..e59861f18ce55616981e7ca9fbc5ad2a6698f04f 100644 (file)
 #include <linux/topology.h>
 #include <linux/nodemask.h>
 #include <linux/cpu.h>
+#include <linux/device.h>
 
 static struct sysdev_class node_class = {
-       set_kset_name("node"),
+       .name = "node",
 };
 
 
@@ -40,13 +41,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
        int n;
        int nid = dev->id;
        struct sysinfo i;
-       unsigned long inactive;
-       unsigned long active;
-       unsigned long free;
 
        si_meminfo_node(&i, nid);
-       __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid));
-
 
        n = sprintf(buf, "\n"
                       "Node %d MemTotal:     %8lu kB\n"
@@ -74,8 +70,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
                       nid, K(i.totalram),
                       nid, K(i.freeram),
                       nid, K(i.totalram - i.freeram),
-                      nid, K(active),
-                      nid, K(inactive),
+                      nid, node_page_state(nid, NR_ACTIVE),
+                      nid, node_page_state(nid, NR_INACTIVE),
 #ifdef CONFIG_HIGHMEM
                       nid, K(i.totalhigh),
                       nid, K(i.freehigh),
@@ -138,7 +134,7 @@ static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
 
 
 /*
- * register_node - Setup a driverfs device for a node.
+ * register_node - Setup a sysfs device for a node.
  * @num - Node number to use when creating the device.
  *
  * Initialize and register the node device.
@@ -237,8 +233,96 @@ void unregister_one_node(int nid)
        unregister_node(&node_devices[nid]);
 }
 
+/*
+ * node states attributes
+ */
+
+static ssize_t print_nodes_state(enum node_states state, char *buf)
+{
+       int n;
+
+       n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
+       if (n > 0 && PAGE_SIZE > n + 1) {
+               *(buf + n++) = '\n';
+               *(buf + n++) = '\0';
+       }
+       return n;
+}
+
+static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf)
+{
+       return print_nodes_state(N_POSSIBLE, buf);
+}
+
+static ssize_t print_nodes_online(struct sysdev_class *class, char *buf)
+{
+       return print_nodes_state(N_ONLINE, buf);
+}
+
+static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
+                                               char *buf)
+{
+       return print_nodes_state(N_NORMAL_MEMORY, buf);
+}
+
+static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf)
+{
+       return print_nodes_state(N_CPU, buf);
+}
+
+static SYSDEV_CLASS_ATTR(possible, 0444, print_nodes_possible, NULL);
+static SYSDEV_CLASS_ATTR(online, 0444, print_nodes_online, NULL);
+static SYSDEV_CLASS_ATTR(has_normal_memory, 0444, print_nodes_has_normal_memory,
+                                                                       NULL);
+static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
+
+#ifdef CONFIG_HIGHMEM
+static ssize_t print_nodes_has_high_memory(struct sysdev_class *class,
+                                                char *buf)
+{
+       return print_nodes_state(N_HIGH_MEMORY, buf);
+}
+
+static SYSDEV_CLASS_ATTR(has_high_memory, 0444, print_nodes_has_high_memory,
+                                                                        NULL);
+#endif
+
+struct sysdev_class_attribute *node_state_attr[] = {
+       &attr_possible,
+       &attr_online,
+       &attr_has_normal_memory,
+#ifdef CONFIG_HIGHMEM
+       &attr_has_high_memory,
+#endif
+       &attr_has_cpu,
+};
+
+static int node_states_init(void)
+{
+       int i;
+       int err = 0;
+
+       for (i = 0;  i < NR_NODE_STATES; i++) {
+               int ret;
+               ret = sysdev_class_create_file(&node_class, node_state_attr[i]);
+               if (!err)
+                       err = ret;
+       }
+       return err;
+}
+
 static int __init register_node_type(void)
 {
-       return sysdev_class_register(&node_class);
+       int ret;
+
+       ret = sysdev_class_register(&node_class);
+       if (!ret)
+               ret = node_states_init();
+
+       /*
+        * Note:  we're not going to unregister the node class if we fail
+        * to register the node state class attribute files.
+        */
+       return ret;
 }
 postcore_initcall(register_node_type);