Skip to content

Commit 10fbcf4

Browse files
kaysieversgregkh
authored andcommitted
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>
1 parent 8a25a2f commit 10fbcf4

8 files changed

Lines changed: 177 additions & 200 deletions

File tree

‎arch/powerpc/kernel/sysfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,15 @@ static void register_nodes(void)
592592
int sysfs_add_device_to_node(struct device *dev, int nid)
593593
{
594594
struct node *node = &node_devices[nid];
595-
return sysfs_create_link(&node->sysdev.kobj, &dev->kobj,
595+
return sysfs_create_link(&node->dev.kobj, &dev->kobj,
596596
kobject_name(&dev->kobj));
597597
}
598598
EXPORT_SYMBOL_GPL(sysfs_add_device_to_node);
599599

600600
void sysfs_remove_device_from_node(struct device *dev, int nid)
601601
{
602602
struct node *node = &node_devices[nid];
603-
sysfs_remove_link(&node->sysdev.kobj, kobject_name(&dev->kobj));
603+
sysfs_remove_link(&node->dev.kobj, kobject_name(&dev->kobj));
604604
}
605605
EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node);
606606

‎drivers/base/memory.c‎

Lines changed: 66 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* drivers/base/memory.c - basic Memory class support
2+
* Memory subsystem support
33
*
44
* Written by Matt Tolentino <matthew.e.tolentino@intel.com>
55
* Dave Hansen <haveblue@us.ibm.com>
@@ -10,7 +10,6 @@
1010
* SPARSEMEM should be contained here, or in mm/memory_hotplug.c.
1111
*/
1212

13-
#include <linux/sysdev.h>
1413
#include <linux/module.h>
1514
#include <linux/init.h>
1615
#include <linux/topology.h>
@@ -38,26 +37,9 @@ static inline int base_memory_block_id(int section_nr)
3837
return section_nr / sections_per_block;
3938
}
4039

41-
static struct sysdev_class memory_sysdev_class = {
40+
static struct bus_type memory_subsys = {
4241
.name = MEMORY_CLASS_NAME,
43-
};
44-
45-
static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj)
46-
{
47-
return MEMORY_CLASS_NAME;
48-
}
49-
50-
static 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-
58-
static const struct kset_uevent_ops memory_uevent_ops = {
59-
.name = memory_uevent_name,
60-
.uevent = memory_uevent,
42+
.dev_name = MEMORY_CLASS_NAME,
6143
};
6244

6345
static BLOCKING_NOTIFIER_HEAD(memory_chain);
@@ -96,21 +78,21 @@ int register_memory(struct memory_block *memory)
9678
{
9779
int error;
9880

99-
memory->sysdev.cls = &memory_sysdev_class;
100-
memory->sysdev.id = memory->start_section_nr / sections_per_block;
81+
memory->dev.bus = &memory_subsys;
82+
memory->dev.id = memory->start_section_nr / sections_per_block;
10183

102-
error = sysdev_register(&memory->sysdev);
84+
error = device_register(&memory->dev);
10385
return error;
10486
}
10587

10688
static void
10789
unregister_memory(struct memory_block *memory)
10890
{
109-
BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
91+
BUG_ON(memory->dev.bus != &memory_subsys);
11092

11193
/* drop the ref. we got in remove_memory_block() */
112-
kobject_put(&memory->sysdev.kobj);
113-
sysdev_unregister(&memory->sysdev);
94+
kobject_put(&memory->dev.kobj);
95+
device_unregister(&memory->dev);
11496
}
11597

11698
unsigned long __weak memory_block_size_bytes(void)
@@ -138,22 +120,22 @@ static unsigned long get_memory_block_size(void)
138120
* uses.
139121
*/
140122

141-
static ssize_t show_mem_start_phys_index(struct sys_device *dev,
142-
struct sysdev_attribute *attr, char *buf)
123+
static ssize_t show_mem_start_phys_index(struct device *dev,
124+
struct device_attribute *attr, char *buf)
143125
{
144126
struct memory_block *mem =
145-
container_of(dev, struct memory_block, sysdev);
127+
container_of(dev, struct memory_block, dev);
146128
unsigned long phys_index;
147129

148130
phys_index = mem->start_section_nr / sections_per_block;
149131
return sprintf(buf, "%08lx\n", phys_index);
150132
}
151133

152-
static ssize_t show_mem_end_phys_index(struct sys_device *dev,
153-
struct sysdev_attribute *attr, char *buf)
134+
static ssize_t show_mem_end_phys_index(struct device *dev,
135+
struct device_attribute *attr, char *buf)
154136
{
155137
struct memory_block *mem =
156-
container_of(dev, struct memory_block, sysdev);
138+
container_of(dev, struct memory_block, dev);
157139
unsigned long phys_index;
158140

159141
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,
163145
/*
164146
* Show whether the section of memory is likely to be hot-removable
165147
*/
166-
static ssize_t show_mem_removable(struct sys_device *dev,
167-
struct sysdev_attribute *attr, char *buf)
148+
static ssize_t show_mem_removable(struct device *dev,
149+
struct device_attribute *attr, char *buf)
168150
{
169151
unsigned long i, pfn;
170152
int ret = 1;
171153
struct memory_block *mem =
172-
container_of(dev, struct memory_block, sysdev);
154+
container_of(dev, struct memory_block, dev);
173155

174156
for (i = 0; i < sections_per_block; i++) {
175157
pfn = section_nr_to_pfn(mem->start_section_nr + i);
@@ -182,11 +164,11 @@ static ssize_t show_mem_removable(struct sys_device *dev,
182164
/*
183165
* online, offline, going offline, etc.
184166
*/
185-
static ssize_t show_mem_state(struct sys_device *dev,
186-
struct sysdev_attribute *attr, char *buf)
167+
static ssize_t show_mem_state(struct device *dev,
168+
struct device_attribute *attr, char *buf)
187169
{
188170
struct memory_block *mem =
189-
container_of(dev, struct memory_block, sysdev);
171+
container_of(dev, struct memory_block, dev);
190172
ssize_t len = 0;
191173

192174
/*
@@ -324,13 +306,13 @@ static int memory_block_change_state(struct memory_block *mem,
324306
}
325307

326308
static ssize_t
327-
store_mem_state(struct sys_device *dev,
328-
struct sysdev_attribute *attr, const char *buf, size_t count)
309+
store_mem_state(struct device *dev,
310+
struct device_attribute *attr, const char *buf, size_t count)
329311
{
330312
struct memory_block *mem;
331313
int ret = -EINVAL;
332314

333-
mem = container_of(dev, struct memory_block, sysdev);
315+
mem = container_of(dev, struct memory_block, dev);
334316

335317
if (!strncmp(buf, "online", min((int)count, 6)))
336318
ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
@@ -351,41 +333,41 @@ store_mem_state(struct sys_device *dev,
351333
* s.t. if I offline all of these sections I can then
352334
* remove the physical device?
353335
*/
354-
static ssize_t show_phys_device(struct sys_device *dev,
355-
struct sysdev_attribute *attr, char *buf)
336+
static ssize_t show_phys_device(struct device *dev,
337+
struct device_attribute *attr, char *buf)
356338
{
357339
struct memory_block *mem =
358-
container_of(dev, struct memory_block, sysdev);
340+
container_of(dev, struct memory_block, dev);
359341
return sprintf(buf, "%d\n", mem->phys_device);
360342
}
361343

362-
static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
363-
static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
364-
static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
365-
static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
366-
static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
344+
static DEVICE_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
345+
static DEVICE_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
346+
static DEVICE_ATTR(state, 0644, show_mem_state, store_mem_state);
347+
static DEVICE_ATTR(phys_device, 0444, show_phys_device, NULL);
348+
static DEVICE_ATTR(removable, 0444, show_mem_removable, NULL);
367349

368350
#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)
370352
#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)
372354

373355
/*
374356
* Block size attribute stuff
375357
*/
376358
static ssize_t
377-
print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr,
359+
print_block_size(struct device *dev, struct device_attribute *attr,
378360
char *buf)
379361
{
380362
return sprintf(buf, "%lx\n", get_memory_block_size());
381363
}
382364

383-
static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL);
365+
static DEVICE_ATTR(block_size_bytes, 0444, print_block_size, NULL);
384366

385367
static int block_size_init(void)
386368
{
387-
return sysfs_create_file(&memory_sysdev_class.kset.kobj,
388-
&attr_block_size_bytes.attr);
369+
return device_create_file(memory_subsys.dev_root,
370+
&dev_attr_block_size_bytes);
389371
}
390372

391373
/*
@@ -396,7 +378,7 @@ static int block_size_init(void)
396378
*/
397379
#ifdef CONFIG_ARCH_MEMORY_PROBE
398380
static ssize_t
399-
memory_probe_store(struct class *class, struct class_attribute *attr,
381+
memory_probe_store(struct device *dev, struct device_attribute *attr,
400382
const char *buf, size_t count)
401383
{
402384
u64 phys_addr;
@@ -423,12 +405,11 @@ memory_probe_store(struct class *class, struct class_attribute *attr,
423405
out:
424406
return ret;
425407
}
426-
static CLASS_ATTR(probe, S_IWUSR, NULL, memory_probe_store);
408+
static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store);
427409

428410
static int memory_probe_init(void)
429411
{
430-
return sysfs_create_file(&memory_sysdev_class.kset.kobj,
431-
&class_attr_probe.attr);
412+
return device_create_file(memory_subsys.dev_root, &dev_attr_probe);
432413
}
433414
#else
434415
static inline int memory_probe_init(void)
@@ -444,8 +425,8 @@ static inline int memory_probe_init(void)
444425

445426
/* Soft offline a page */
446427
static ssize_t
447-
store_soft_offline_page(struct class *class,
448-
struct class_attribute *attr,
428+
store_soft_offline_page(struct device *dev,
429+
struct device_attribute *attr,
449430
const char *buf, size_t count)
450431
{
451432
int ret;
@@ -463,8 +444,8 @@ store_soft_offline_page(struct class *class,
463444

464445
/* Forcibly offline a page, including killing processes. */
465446
static ssize_t
466-
store_hard_offline_page(struct class *class,
467-
struct class_attribute *attr,
447+
store_hard_offline_page(struct device *dev,
448+
struct device_attribute *attr,
468449
const char *buf, size_t count)
469450
{
470451
int ret;
@@ -478,18 +459,18 @@ store_hard_offline_page(struct class *class,
478459
return ret ? ret : count;
479460
}
480461

481-
static CLASS_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page);
482-
static CLASS_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page);
462+
static DEVICE_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page);
463+
static DEVICE_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page);
483464

484465
static __init int memory_fail_init(void)
485466
{
486467
int err;
487468

488-
err = sysfs_create_file(&memory_sysdev_class.kset.kobj,
489-
&class_attr_soft_offline_page.attr);
469+
err = device_create_file(memory_subsys.dev_root,
470+
&dev_attr_soft_offline_page);
490471
if (!err)
491-
err = sysfs_create_file(&memory_sysdev_class.kset.kobj,
492-
&class_attr_hard_offline_page.attr);
472+
err = device_create_file(memory_subsys.dev_root,
473+
&dev_attr_hard_offline_page);
493474
return err;
494475
}
495476
#else
@@ -509,31 +490,23 @@ int __weak arch_get_memory_phys_device(unsigned long start_pfn)
509490
return 0;
510491
}
511492

493+
/*
494+
* A reference for the returned object is held and the reference for the
495+
* hinted object is released.
496+
*/
512497
struct memory_block *find_memory_block_hinted(struct mem_section *section,
513498
struct memory_block *hint)
514499
{
515-
struct kobject *kobj;
516-
struct sys_device *sysdev;
517-
struct memory_block *mem;
518-
char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1];
519500
int block_id = base_memory_block_id(__section_nr(section));
501+
struct device *hintdev = hint ? &hint->dev : NULL;
502+
struct device *dev;
520503

521-
kobj = hint ? &hint->sysdev.kobj : NULL;
522-
523-
/*
524-
* This only works because we know that section == sysdev->id
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)
504+
dev = subsys_find_device_by_id(&memory_subsys, block_id, hintdev);
505+
if (hint)
506+
put_device(&hint->dev);
507+
if (!dev)
531508
return NULL;
532-
533-
sysdev = container_of(kobj, struct sys_device, kobj);
534-
mem = container_of(sysdev, struct memory_block, sysdev);
535-
536-
return mem;
509+
return container_of(dev, struct memory_block, dev);
537510
}
538511

539512
/*
@@ -542,7 +515,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
542515
* this gets to be a real problem, we can always use a radix
543516
* tree or something here.
544517
*
545-
* This could be made generic for all sysdev classes.
518+
* This could be made generic for all device subsystems.
546519
*/
547520
struct memory_block *find_memory_block(struct mem_section *section)
548521
{
@@ -598,7 +571,7 @@ static int add_memory_section(int nid, struct mem_section *section,
598571
mem = find_memory_block(section);
599572
if (mem) {
600573
mem->section_count++;
601-
kobject_put(&mem->sysdev.kobj);
574+
kobject_put(&mem->dev.kobj);
602575
} else
603576
ret = init_memory_block(&mem, section, state);
604577

@@ -631,7 +604,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
631604
unregister_memory(mem);
632605
kfree(mem);
633606
} else
634-
kobject_put(&mem->sysdev.kobj);
607+
kobject_put(&mem->dev.kobj);
635608

636609
mutex_unlock(&mem_sysfs_mutex);
637610
return 0;
@@ -664,8 +637,7 @@ int __init memory_dev_init(void)
664637
int err;
665638
unsigned long block_sz;
666639

667-
memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops;
668-
ret = sysdev_class_register(&memory_sysdev_class);
640+
ret = subsys_system_register(&memory_subsys, NULL);
669641
if (ret)
670642
goto out;
671643

0 commit comments

Comments
 (0)