aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2011-12-21 17:48:43 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-12-21 17:48:43 -0500
commit10fbcf4c6cb122005cdf36fc24d7683da92c7a27 (patch)
tree1a2ad572b421d576e14dbf006ecb321a53063f0c /drivers/base
parent8a25a2fd126c621f44f3aeaef80d51f00fc11639 (diff)
convert 'memory' sysdev_class to a regular subsystem
This moves the 'memory sysdev_class' over to a regular 'memory' subsystem and converts the devices to regular devices. The sysdev drivers are implemented as subsystem interfaces now. After all sysdev classes are ported to regular driver core entities, the sysdev implementation will be entirely removed from the kernel. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/memory.c160
-rw-r--r--drivers/base/node.c146
2 files changed, 142 insertions, 164 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 8272d92d22c0..f17e3ea041c0 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * drivers/base/memory.c - basic Memory class support 2 * Memory subsystem support
3 * 3 *
4 * Written by Matt Tolentino <matthew.e.tolentino@intel.com> 4 * Written by Matt Tolentino <matthew.e.tolentino@intel.com>
5 * Dave Hansen <haveblue@us.ibm.com> 5 * Dave Hansen <haveblue@us.ibm.com>
@@ -10,7 +10,6 @@
10 * SPARSEMEM should be contained here, or in mm/memory_hotplug.c. 10 * SPARSEMEM should be contained here, or in mm/memory_hotplug.c.
11 */ 11 */
12 12
13#include <linux/sysdev.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/init.h> 14#include <linux/init.h>
16#include <linux/topology.h> 15#include <linux/topology.h>
@@ -38,26 +37,9 @@ static inline int base_memory_block_id(int section_nr)
38 return section_nr / sections_per_block; 37 return section_nr / sections_per_block;
39} 38}
40 39
41static struct sysdev_class memory_sysdev_class = { 40static struct bus_type memory_subsys = {
42 .name = MEMORY_CLASS_NAME, 41 .name = MEMORY_CLASS_NAME,
43}; 42 .dev_name = MEMORY_CLASS_NAME,
44
45static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj)
46{
47 return MEMORY_CLASS_NAME;
48}
49
50static int memory_uevent(struct kset *kset, struct kobject *obj,
51 struct kobj_uevent_env *env)
52{
53 int retval = 0;
54
55 return retval;
56}
57
58static const struct kset_uevent_ops memory_uevent_ops = {
59 .name = memory_uevent_name,
60 .uevent = memory_uevent,
61}; 43};
62 44
63static BLOCKING_NOTIFIER_HEAD(memory_chain); 45static BLOCKING_NOTIFIER_HEAD(memory_chain);
@@ -96,21 +78,21 @@ int register_memory(struct memory_block *memory)
96{ 78{
97 int error; 79 int error;
98 80
99 memory->sysdev.cls = &memory_sysdev_class; 81 memory->dev.bus = &memory_subsys;
100 memory->sysdev.id = memory->start_section_nr / sections_per_block; 82 memory->dev.id = memory->start_section_nr / sections_per_block;
101 83
102 error = sysdev_register(&memory->sysdev); 84 error = device_register(&memory->dev);
103 return error; 85 return error;
104} 86}
105 87
106static void 88static void
107unregister_memory(struct memory_block *memory) 89unregister_memory(struct memory_block *memory)
108{ 90{
109 BUG_ON(memory->sysdev.cls != &memory_sysdev_class); 91 BUG_ON(memory->dev.bus != &memory_subsys);
110 92
111 /* drop the ref. we got in remove_memory_block() */ 93 /* drop the ref. we got in remove_memory_block() */
112 kobject_put(&memory->sysdev.kobj); 94 kobject_put(&memory->dev.kobj);
113 sysdev_unregister(&memory->sysdev); 95 device_unregister(&memory->dev);
114} 96}
115 97
116unsigned long __weak memory_block_size_bytes(void) 98unsigned long __weak memory_block_size_bytes(void)
@@ -138,22 +120,22 @@ static unsigned long get_memory_block_size(void)
138 * uses. 120 * uses.
139 */ 121 */
140 122
141static ssize_t show_mem_start_phys_index(struct sys_device *dev, 123static ssize_t show_mem_start_phys_index(struct device *dev,
142 struct sysdev_attribute *attr, char *buf) 124 struct device_attribute *attr, char *buf)
143{ 125{
144 struct memory_block *mem = 126 struct memory_block *mem =
145 container_of(dev, struct memory_block, sysdev); 127 container_of(dev, struct memory_block, dev);
146 unsigned long phys_index; 128 unsigned long phys_index;
147 129
148 phys_index = mem->start_section_nr / sections_per_block; 130 phys_index = mem->start_section_nr / sections_per_block;
149 return sprintf(buf, "%08lx\n", phys_index); 131 return sprintf(buf, "%08lx\n", phys_index);
150} 132}
151 133
152static ssize_t show_mem_end_phys_index(struct sys_device *dev, 134static ssize_t show_mem_end_phys_index(struct device *dev,
153 struct sysdev_attribute *attr, char *buf) 135 struct device_attribute *attr, char *buf)
154{ 136{
155 struct memory_block *mem = 137 struct memory_block *mem =
156 container_of(dev, struct memory_block, sysdev); 138 container_of(dev, struct memory_block, dev);
157 unsigned long phys_index; 139 unsigned long phys_index;
158 140
159 phys_index = mem->end_section_nr / sections_per_block; 141 phys_index = mem->end_section_nr / sections_per_block;
@@ -163,13 +145,13 @@ static ssize_t show_mem_end_phys_index(struct sys_device *dev,
163/* 145/*
164 * Show whether the section of memory is likely to be hot-removable 146 * Show whether the section of memory is likely to be hot-removable
165 */ 147 */
166static ssize_t show_mem_removable(struct sys_device *dev, 148static ssize_t show_mem_removable(struct device *dev,
167 struct sysdev_attribute *attr, char *buf) 149 struct device_attribute *attr, char *buf)
168{ 150{
169 unsigned long i, pfn; 151 unsigned long i, pfn;
170 int ret = 1; 152 int ret = 1;
171 struct memory_block *mem = 153 struct memory_block *mem =
172 container_of(dev, struct memory_block, sysdev); 154 container_of(dev, struct memory_block, dev);
173 155
174 for (i = 0; i < sections_per_block; i++) { 156 for (i = 0; i < sections_per_block; i++) {
175 pfn = section_nr_to_pfn(mem->start_section_nr + i); 157 pfn = section_nr_to_pfn(mem->start_section_nr + i);
@@ -182,11 +164,11 @@ static ssize_t show_mem_removable(struct sys_device *dev,
182/* 164/*
183 * online, offline, going offline, etc. 165 * online, offline, going offline, etc.
184 */ 166 */
185static ssize_t show_mem_state(struct sys_device *dev, 167static ssize_t show_mem_state(struct device *dev,
186 struct sysdev_attribute *attr, char *buf) 168 struct device_attribute *attr, char *buf)
187{ 169{
188 struct memory_block *mem = 170 struct memory_block *mem =
189 container_of(dev, struct memory_block, sysdev); 171 container_of(dev, struct memory_block, dev);
190 ssize_t len = 0; 172 ssize_t len = 0;
191 173
192 /* 174 /*
@@ -324,13 +306,13 @@ out:
324} 306}
325 307
326static ssize_t 308static ssize_t
327store_mem_state(struct sys_device *dev, 309store_mem_state(struct device *dev,
328 struct sysdev_attribute *attr, const char *buf, size_t count) 310 struct device_attribute *attr, const char *buf, size_t count)
329{ 311{
330 struct memory_block *mem; 312 struct memory_block *mem;
331 int ret = -EINVAL; 313 int ret = -EINVAL;
332 314
333 mem = container_of(dev, struct memory_block, sysdev); 315 mem = container_of(dev, struct memory_block, dev);
334 316
335 if (!strncmp(buf, "online", min((int)count, 6))) 317 if (!strncmp(buf, "online", min((int)count, 6)))
336 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); 318 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
@@ -351,41 +333,41 @@ store_mem_state(struct sys_device *dev,
351 * s.t. if I offline all of these sections I can then 333 * s.t. if I offline all of these sections I can then
352 * remove the physical device? 334 * remove the physical device?
353 */ 335 */
354static ssize_t show_phys_device(struct sys_device *dev, 336static ssize_t show_phys_device(struct device *dev,
355 struct sysdev_attribute *attr, char *buf) 337 struct device_attribute *attr, char *buf)
356{ 338{
357 struct memory_block *mem = 339 struct memory_block *mem =
358 container_of(dev, struct memory_block, sysdev); 340 container_of(dev, struct memory_block, dev);
359 return sprintf(buf, "%d\n", mem->phys_device); 341 return sprintf(buf, "%d\n", mem->phys_device);
360} 342}
361 343
362static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); 344static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
363static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL); 345static DEVICE_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
364static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); 346static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
365static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); 347static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
366static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL); 348static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
367 349
368#define mem_create_simple_file(mem, attr_name) \ 350#define mem_create_simple_file(mem, attr_name) \
369 sysdev_create_file(&mem->sysdev, &attr_##attr_name) 351 device_create_file(&mem->dev, &dev_attr_##attr_name)
370#define mem_remove_simple_file(mem, attr_name) \ 352#define mem_remove_simple_file(mem, attr_name) \
371 sysdev_remove_file(&mem->sysdev, &attr_##attr_name) 353 device_remove_file(&mem->dev, &dev_attr_##attr_name)
372 354
373/* 355/*
374 * Block size attribute stuff 356 * Block size attribute stuff
375 */ 357 */
376static ssize_t 358static ssize_t
377print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr, 359print_block_size(struct device *dev, struct device_attribute *attr,
378 char *buf) 360 char *buf)
379{ 361{
380 return sprintf(buf, "%lx\n", get_memory_block_size()); 362 return sprintf(buf, "%lx\n", get_memory_block_size());
381} 363}
382 364
383static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); 365static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL);
384 366
385static int block_size_init(void) 367static int block_size_init(void)
386{ 368{
387 return sysfs_create_file(&memory_sysdev_class.kset.kobj, 369 return device_create_file(memory_subsys.dev_root,
388 &attr_block_size_bytes.attr); 370 &dev_attr_block_size_bytes);
389} 371}
390 372
391/* 373/*
@@ -396,7 +378,7 @@ static int block_size_init(void)
396 */ 378 */
397#ifdef CONFIG_ARCH_MEMORY_PROBE 379#ifdef CONFIG_ARCH_MEMORY_PROBE
398static ssize_t 380static ssize_t
399memory_probe_store(struct class *class, struct class_attribute *attr, 381memory_probe_store(struct device *dev, struct device_attribute *attr,
400 const char *buf, size_t count) 382 const char *buf, size_t count)
401{ 383{
402 u64 phys_addr; 384 u64 phys_addr;
@@ -423,12 +405,11 @@ memory_probe_store(struct class *class, struct class_attribute *attr,
423out: 405out:
424 return ret; 406 return ret;
425} 407}
426static CLASS_ATTR(probe, S_IWUSR, NULL, memory_probe_store); 408static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store);
427 409
428static int memory_probe_init(void) 410static int memory_probe_init(void)
429{ 411{
430 return sysfs_create_file(&memory_sysdev_class.kset.kobj, 412 return device_create_file(memory_subsys.dev_root, &dev_attr_probe);
431 &class_attr_probe.attr);
432} 413}
433#else 414#else
434static inline int memory_probe_init(void) 415static inline int memory_probe_init(void)
@@ -444,8 +425,8 @@ static inline int memory_probe_init(void)
444 425
445/* Soft offline a page */ 426/* Soft offline a page */
446static ssize_t 427static ssize_t
447store_soft_offline_page(struct class *class, 428store_soft_offline_page(struct device *dev,
448 struct class_attribute *attr, 429 struct device_attribute *attr,
449 const char *buf, size_t count) 430 const char *buf, size_t count)
450{ 431{
451 int ret; 432 int ret;
@@ -463,8 +444,8 @@ store_soft_offline_page(struct class *class,
463 444
464/* Forcibly offline a page, including killing processes. */ 445/* Forcibly offline a page, including killing processes. */
465static ssize_t 446static ssize_t
466store_hard_offline_page(struct class *class, 447store_hard_offline_page(struct device *dev,
467 struct class_attribute *attr, 448 struct device_attribute *attr,
468 const char *buf, size_t count) 449 const char *buf, size_t count)
469{ 450{
470 int ret; 451 int ret;
@@ -478,18 +459,18 @@ store_hard_offline_page(struct class *class,
478 return ret ? ret : count; 459 return ret ? ret : count;
479} 460}
480 461
481static CLASS_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page); 462static DEVICE_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page);
482static CLASS_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page); 463static DEVICE_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page);
483 464
484static __init int memory_fail_init(void) 465static __init int memory_fail_init(void)
485{ 466{
486 int err; 467 int err;
487 468
488 err = sysfs_create_file(&memory_sysdev_class.kset.kobj, 469 err = device_create_file(memory_subsys.dev_root,
489 &class_attr_soft_offline_page.attr); 470 &dev_attr_soft_offline_page);
490 if (!err) 471 if (!err)
491 err = sysfs_create_file(&memory_sysdev_class.kset.kobj, 472 err = device_create_file(memory_subsys.dev_root,
492 &class_attr_hard_offline_page.attr); 473 &dev_attr_hard_offline_page);
493 return err; 474 return err;
494} 475}
495#else 476#else
@@ -509,31 +490,23 @@ int __weak arch_get_memory_phys_device(unsigned long start_pfn)
509 return 0; 490 return 0;
510} 491}
511 492
493/*
494 * A reference for the returned object is held and the reference for the
495 * hinted object is released.
496 */
512struct memory_block *find_memory_block_hinted(struct mem_section *section, 497struct memory_block *find_memory_block_hinted(struct mem_section *section,
513 struct memory_block *hint) 498 struct memory_block *hint)
514{ 499{
515 struct kobject *kobj;
516 struct sys_device *sysdev;
517 struct memory_block *mem;
518 char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1];
519 int block_id = base_memory_block_id(__section_nr(section)); 500 int block_id = base_memory_block_id(__section_nr(section));
501 struct device *hintdev = hint ? &hint->dev : NULL;
502 struct device *dev;
520 503
521 kobj = hint ? &hint->sysdev.kobj : NULL; 504 dev = subsys_find_device_by_id(&memory_subsys, block_id, hintdev);
522 505 if (hint)
523 /* 506 put_device(&hint->dev);
524 * This only works because we know that section == sysdev->id 507 if (!dev)
525 * slightly redundant with sysdev_register()
526 */
527 sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, block_id);
528
529 kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj);
530 if (!kobj)
531 return NULL; 508 return NULL;
532 509 return container_of(dev, struct memory_block, dev);
533 sysdev = container_of(kobj, struct sys_device, kobj);
534 mem = container_of(sysdev, struct memory_block, sysdev);
535
536 return mem;
537} 510}
538 511
539/* 512/*
@@ -542,7 +515,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
542 * this gets to be a real problem, we can always use a radix 515 * this gets to be a real problem, we can always use a radix
543 * tree or something here. 516 * tree or something here.
544 * 517 *
545 * This could be made generic for all sysdev classes. 518 * This could be made generic for all device subsystems.
546 */ 519 */
547struct memory_block *find_memory_block(struct mem_section *section) 520struct memory_block *find_memory_block(struct mem_section *section)
548{ 521{
@@ -598,7 +571,7 @@ static int add_memory_section(int nid, struct mem_section *section,
598 mem = find_memory_block(section); 571 mem = find_memory_block(section);
599 if (mem) { 572 if (mem) {
600 mem->section_count++; 573 mem->section_count++;
601 kobject_put(&mem->sysdev.kobj); 574 kobject_put(&mem->dev.kobj);
602 } else 575 } else
603 ret = init_memory_block(&mem, section, state); 576 ret = init_memory_block(&mem, section, state);
604 577
@@ -631,7 +604,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
631 unregister_memory(mem); 604 unregister_memory(mem);
632 kfree(mem); 605 kfree(mem);
633 } else 606 } else
634 kobject_put(&mem->sysdev.kobj); 607 kobject_put(&mem->dev.kobj);
635 608
636 mutex_unlock(&mem_sysfs_mutex); 609 mutex_unlock(&mem_sysfs_mutex);
637 return 0; 610 return 0;
@@ -664,8 +637,7 @@ int __init memory_dev_init(void)
664 int err; 637 int err;
665 unsigned long block_sz; 638 unsigned long block_sz;
666 639
667 memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops; 640 ret = subsys_system_register(&memory_subsys, NULL);
668 ret = sysdev_class_register(&memory_sysdev_class);
669 if (ret) 641 if (ret)
670 goto out; 642 goto out;
671 643
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 6ce1501c7de5..996d2189689b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -1,8 +1,7 @@
1/* 1/*
2 * drivers/base/node.c - basic Node class support 2 * Basic Node interface support
3 */ 3 */
4 4
5#include <linux/sysdev.h>
6#include <linux/module.h> 5#include <linux/module.h>
7#include <linux/init.h> 6#include <linux/init.h>
8#include <linux/mm.h> 7#include <linux/mm.h>
@@ -19,18 +18,16 @@
19#include <linux/swap.h> 18#include <linux/swap.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21 20
22static struct sysdev_class_attribute *node_state_attrs[]; 21static struct bus_type node_subsys = {
23
24static struct sysdev_class node_class = {
25 .name = "node", 22 .name = "node",
26 .attrs = node_state_attrs, 23 .dev_name = "node",
27}; 24};
28 25
29 26
30static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) 27static ssize_t node_read_cpumap(struct device *dev, int type, char *buf)
31{ 28{
32 struct node *node_dev = to_node(dev); 29 struct node *node_dev = to_node(dev);
33 const struct cpumask *mask = cpumask_of_node(node_dev->sysdev.id); 30 const struct cpumask *mask = cpumask_of_node(node_dev->dev.id);
34 int len; 31 int len;
35 32
36 /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */ 33 /* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
@@ -44,23 +41,23 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf)
44 return len; 41 return len;
45} 42}
46 43
47static inline ssize_t node_read_cpumask(struct sys_device *dev, 44static inline ssize_t node_read_cpumask(struct device *dev,
48 struct sysdev_attribute *attr, char *buf) 45 struct device_attribute *attr, char *buf)
49{ 46{
50 return node_read_cpumap(dev, 0, buf); 47 return node_read_cpumap(dev, 0, buf);
51} 48}
52static inline ssize_t node_read_cpulist(struct sys_device *dev, 49static inline ssize_t node_read_cpulist(struct device *dev,
53 struct sysdev_attribute *attr, char *buf) 50 struct device_attribute *attr, char *buf)
54{ 51{
55 return node_read_cpumap(dev, 1, buf); 52 return node_read_cpumap(dev, 1, buf);
56} 53}
57 54
58static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); 55static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL);
59static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); 56static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
60 57
61#define K(x) ((x) << (PAGE_SHIFT - 10)) 58#define K(x) ((x) << (PAGE_SHIFT - 10))
62static ssize_t node_read_meminfo(struct sys_device * dev, 59static ssize_t node_read_meminfo(struct device *dev,
63 struct sysdev_attribute *attr, char * buf) 60 struct device_attribute *attr, char *buf)
64{ 61{
65 int n; 62 int n;
66 int nid = dev->id; 63 int nid = dev->id;
@@ -155,10 +152,10 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
155} 152}
156 153
157#undef K 154#undef K
158static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); 155static DEVICE_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
159 156
160static ssize_t node_read_numastat(struct sys_device * dev, 157static ssize_t node_read_numastat(struct device *dev,
161 struct sysdev_attribute *attr, char * buf) 158 struct device_attribute *attr, char *buf)
162{ 159{
163 return sprintf(buf, 160 return sprintf(buf,
164 "numa_hit %lu\n" 161 "numa_hit %lu\n"
@@ -174,10 +171,10 @@ static ssize_t node_read_numastat(struct sys_device * dev,
174 node_page_state(dev->id, NUMA_LOCAL), 171 node_page_state(dev->id, NUMA_LOCAL),
175 node_page_state(dev->id, NUMA_OTHER)); 172 node_page_state(dev->id, NUMA_OTHER));
176} 173}
177static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); 174static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
178 175
179static ssize_t node_read_vmstat(struct sys_device *dev, 176static ssize_t node_read_vmstat(struct device *dev,
180 struct sysdev_attribute *attr, char *buf) 177 struct device_attribute *attr, char *buf)
181{ 178{
182 int nid = dev->id; 179 int nid = dev->id;
183 int i; 180 int i;
@@ -189,10 +186,10 @@ static ssize_t node_read_vmstat(struct sys_device *dev,
189 186
190 return n; 187 return n;
191} 188}
192static SYSDEV_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL); 189static DEVICE_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL);
193 190
194static ssize_t node_read_distance(struct sys_device * dev, 191static ssize_t node_read_distance(struct device *dev,
195 struct sysdev_attribute *attr, char * buf) 192 struct device_attribute *attr, char * buf)
196{ 193{
197 int nid = dev->id; 194 int nid = dev->id;
198 int len = 0; 195 int len = 0;
@@ -210,7 +207,7 @@ static ssize_t node_read_distance(struct sys_device * dev,
210 len += sprintf(buf + len, "\n"); 207 len += sprintf(buf + len, "\n");
211 return len; 208 return len;
212} 209}
213static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL); 210static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL);
214 211
215#ifdef CONFIG_HUGETLBFS 212#ifdef CONFIG_HUGETLBFS
216/* 213/*
@@ -228,7 +225,7 @@ static node_registration_func_t __hugetlb_unregister_node;
228static inline bool hugetlb_register_node(struct node *node) 225static inline bool hugetlb_register_node(struct node *node)
229{ 226{
230 if (__hugetlb_register_node && 227 if (__hugetlb_register_node &&
231 node_state(node->sysdev.id, N_HIGH_MEMORY)) { 228 node_state(node->dev.id, N_HIGH_MEMORY)) {
232 __hugetlb_register_node(node); 229 __hugetlb_register_node(node);
233 return true; 230 return true;
234 } 231 }
@@ -264,17 +261,17 @@ int register_node(struct node *node, int num, struct node *parent)
264{ 261{
265 int error; 262 int error;
266 263
267 node->sysdev.id = num; 264 node->dev.id = num;
268 node->sysdev.cls = &node_class; 265 node->dev.bus = &node_subsys;
269 error = sysdev_register(&node->sysdev); 266 error = device_register(&node->dev);
270 267
271 if (!error){ 268 if (!error){
272 sysdev_create_file(&node->sysdev, &attr_cpumap); 269 device_create_file(&node->dev, &dev_attr_cpumap);
273 sysdev_create_file(&node->sysdev, &attr_cpulist); 270 device_create_file(&node->dev, &dev_attr_cpulist);
274 sysdev_create_file(&node->sysdev, &attr_meminfo); 271 device_create_file(&node->dev, &dev_attr_meminfo);
275 sysdev_create_file(&node->sysdev, &attr_numastat); 272 device_create_file(&node->dev, &dev_attr_numastat);
276 sysdev_create_file(&node->sysdev, &attr_distance); 273 device_create_file(&node->dev, &dev_attr_distance);
277 sysdev_create_file(&node->sysdev, &attr_vmstat); 274 device_create_file(&node->dev, &dev_attr_vmstat);
278 275
279 scan_unevictable_register_node(node); 276 scan_unevictable_register_node(node);
280 277
@@ -294,17 +291,17 @@ int register_node(struct node *node, int num, struct node *parent)
294 */ 291 */
295void unregister_node(struct node *node) 292void unregister_node(struct node *node)
296{ 293{
297 sysdev_remove_file(&node->sysdev, &attr_cpumap); 294 device_remove_file(&node->dev, &dev_attr_cpumap);
298 sysdev_remove_file(&node->sysdev, &attr_cpulist); 295 device_remove_file(&node->dev, &dev_attr_cpulist);
299 sysdev_remove_file(&node->sysdev, &attr_meminfo); 296 device_remove_file(&node->dev, &dev_attr_meminfo);
300 sysdev_remove_file(&node->sysdev, &attr_numastat); 297 device_remove_file(&node->dev, &dev_attr_numastat);
301 sysdev_remove_file(&node->sysdev, &attr_distance); 298 device_remove_file(&node->dev, &dev_attr_distance);
302 sysdev_remove_file(&node->sysdev, &attr_vmstat); 299 device_remove_file(&node->dev, &dev_attr_vmstat);
303 300
304 scan_unevictable_unregister_node(node); 301 scan_unevictable_unregister_node(node);
305 hugetlb_unregister_node(node); /* no-op, if memoryless node */ 302 hugetlb_unregister_node(node); /* no-op, if memoryless node */
306 303
307 sysdev_unregister(&node->sysdev); 304 device_unregister(&node->dev);
308} 305}
309 306
310struct node node_devices[MAX_NUMNODES]; 307struct node node_devices[MAX_NUMNODES];
@@ -324,15 +321,15 @@ int register_cpu_under_node(unsigned int cpu, unsigned int nid)
324 if (!obj) 321 if (!obj)
325 return 0; 322 return 0;
326 323
327 ret = sysfs_create_link(&node_devices[nid].sysdev.kobj, 324 ret = sysfs_create_link(&node_devices[nid].dev.kobj,
328 &obj->kobj, 325 &obj->kobj,
329 kobject_name(&obj->kobj)); 326 kobject_name(&obj->kobj));
330 if (ret) 327 if (ret)
331 return ret; 328 return ret;
332 329
333 return sysfs_create_link(&obj->kobj, 330 return sysfs_create_link(&obj->kobj,
334 &node_devices[nid].sysdev.kobj, 331 &node_devices[nid].dev.kobj,
335 kobject_name(&node_devices[nid].sysdev.kobj)); 332 kobject_name(&node_devices[nid].dev.kobj));
336} 333}
337 334
338int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) 335int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
@@ -346,10 +343,10 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
346 if (!obj) 343 if (!obj)
347 return 0; 344 return 0;
348 345
349 sysfs_remove_link(&node_devices[nid].sysdev.kobj, 346 sysfs_remove_link(&node_devices[nid].dev.kobj,
350 kobject_name(&obj->kobj)); 347 kobject_name(&obj->kobj));
351 sysfs_remove_link(&obj->kobj, 348 sysfs_remove_link(&obj->kobj,
352 kobject_name(&node_devices[nid].sysdev.kobj)); 349 kobject_name(&node_devices[nid].dev.kobj));
353 350
354 return 0; 351 return 0;
355} 352}
@@ -391,15 +388,15 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
391 continue; 388 continue;
392 if (page_nid != nid) 389 if (page_nid != nid)
393 continue; 390 continue;
394 ret = sysfs_create_link_nowarn(&node_devices[nid].sysdev.kobj, 391 ret = sysfs_create_link_nowarn(&node_devices[nid].dev.kobj,
395 &mem_blk->sysdev.kobj, 392 &mem_blk->dev.kobj,
396 kobject_name(&mem_blk->sysdev.kobj)); 393 kobject_name(&mem_blk->dev.kobj));
397 if (ret) 394 if (ret)
398 return ret; 395 return ret;
399 396
400 return sysfs_create_link_nowarn(&mem_blk->sysdev.kobj, 397 return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
401 &node_devices[nid].sysdev.kobj, 398 &node_devices[nid].dev.kobj,
402 kobject_name(&node_devices[nid].sysdev.kobj)); 399 kobject_name(&node_devices[nid].dev.kobj));
403 } 400 }
404 /* mem section does not span the specified node */ 401 /* mem section does not span the specified node */
405 return 0; 402 return 0;
@@ -432,10 +429,10 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
432 continue; 429 continue;
433 if (node_test_and_set(nid, *unlinked_nodes)) 430 if (node_test_and_set(nid, *unlinked_nodes))
434 continue; 431 continue;
435 sysfs_remove_link(&node_devices[nid].sysdev.kobj, 432 sysfs_remove_link(&node_devices[nid].dev.kobj,
436 kobject_name(&mem_blk->sysdev.kobj)); 433 kobject_name(&mem_blk->dev.kobj));
437 sysfs_remove_link(&mem_blk->sysdev.kobj, 434 sysfs_remove_link(&mem_blk->dev.kobj,
438 kobject_name(&node_devices[nid].sysdev.kobj)); 435 kobject_name(&node_devices[nid].dev.kobj));
439 } 436 }
440 NODEMASK_FREE(unlinked_nodes); 437 NODEMASK_FREE(unlinked_nodes);
441 return 0; 438 return 0;
@@ -466,7 +463,7 @@ static int link_mem_sections(int nid)
466 } 463 }
467 464
468 if (mem_blk) 465 if (mem_blk)
469 kobject_put(&mem_blk->sysdev.kobj); 466 kobject_put(&mem_blk->dev.kobj);
470 return err; 467 return err;
471} 468}
472 469
@@ -594,19 +591,19 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
594} 591}
595 592
596struct node_attr { 593struct node_attr {
597 struct sysdev_class_attribute attr; 594 struct device_attribute attr;
598 enum node_states state; 595 enum node_states state;
599}; 596};
600 597
601static ssize_t show_node_state(struct sysdev_class *class, 598static ssize_t show_node_state(struct device *dev,
602 struct sysdev_class_attribute *attr, char *buf) 599 struct device_attribute *attr, char *buf)
603{ 600{
604 struct node_attr *na = container_of(attr, struct node_attr, attr); 601 struct node_attr *na = container_of(attr, struct node_attr, attr);
605 return print_nodes_state(na->state, buf); 602 return print_nodes_state(na->state, buf);
606} 603}
607 604
608#define _NODE_ATTR(name, state) \ 605#define _NODE_ATTR(name, state) \
609 { _SYSDEV_CLASS_ATTR(name, 0444, show_node_state, NULL), state } 606 { __ATTR(name, 0444, show_node_state, NULL), state }
610 607
611static struct node_attr node_state_attr[] = { 608static struct node_attr node_state_attr[] = {
612 _NODE_ATTR(possible, N_POSSIBLE), 609 _NODE_ATTR(possible, N_POSSIBLE),
@@ -618,17 +615,26 @@ static struct node_attr node_state_attr[] = {
618#endif 615#endif
619}; 616};
620 617
621static struct sysdev_class_attribute *node_state_attrs[] = { 618static struct attribute *node_state_attrs[] = {
622 &node_state_attr[0].attr, 619 &node_state_attr[0].attr.attr,
623 &node_state_attr[1].attr, 620 &node_state_attr[1].attr.attr,
624 &node_state_attr[2].attr, 621 &node_state_attr[2].attr.attr,
625 &node_state_attr[3].attr, 622 &node_state_attr[3].attr.attr,
626#ifdef CONFIG_HIGHMEM 623#ifdef CONFIG_HIGHMEM
627 &node_state_attr[4].attr, 624 &node_state_attr[4].attr.attr,
628#endif 625#endif
629 NULL 626 NULL
630}; 627};
631 628
629static struct attribute_group memory_root_attr_group = {
630 .attrs = node_state_attrs,
631};
632
633static const struct attribute_group *cpu_root_attr_groups[] = {
634 &memory_root_attr_group,
635 NULL,
636};
637
632#define NODE_CALLBACK_PRI 2 /* lower than SLAB */ 638#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
633static int __init register_node_type(void) 639static int __init register_node_type(void)
634{ 640{
@@ -637,7 +643,7 @@ static int __init register_node_type(void)
637 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES); 643 BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
638 BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES); 644 BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
639 645
640 ret = sysdev_class_register(&node_class); 646 ret = subsys_system_register(&node_subsys, cpu_root_attr_groups);
641 if (!ret) { 647 if (!ret) {
642 hotplug_memory_notifier(node_memory_callback, 648 hotplug_memory_notifier(node_memory_callback,
643 NODE_CALLBACK_PRI); 649 NODE_CALLBACK_PRI);