aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorNathan Fontenot <nfont@austin.ibm.com>2011-01-20 11:44:29 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-02-03 19:08:57 -0500
commitd33601644cd3b09afb2edd9474517edc441c8fad (patch)
tree1fc119bb30895d39d2dc9d1f738fb8d82c095ab1 /drivers/base
parent0c2c99b1b8ab5d294f176d631e945ebdefcce4cd (diff)
memory hotplug: Update phys_index to [start|end]_section_nr
Update the 'phys_index' property of a the memory_block struct to be called start_section_nr, and add a end_section_nr property. The data tracked here is the same but the updated naming is more in line with what is stored here, namely the first and last section number that the memory block spans. The names presented to userspace remain the same, phys_index for start_section_nr and end_phys_index for end_section_nr, to avoid breaking anything in userspace. This also updates the node sysfs code to be aware of the new capability for a memory block to contain multiple memory sections and be aware of the memory block structure name changes (start_section_nr). This requires an additional parameter to unregister_mem_sect_under_nodes so that we know which memory section of the memory block to unregister. Signed-off-by: Nathan Fontenot <nfont@austin.ibm.com> Reviewed-by: Robin Holt <holt@sgi.com> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/memory.c41
-rw-r--r--drivers/base/node.c12
2 files changed, 39 insertions, 14 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 0b7040042587..71b4a32b1710 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -97,7 +97,7 @@ int register_memory(struct memory_block *memory)
97 int error; 97 int error;
98 98
99 memory->sysdev.cls = &memory_sysdev_class; 99 memory->sysdev.cls = &memory_sysdev_class;
100 memory->sysdev.id = memory->phys_index / sections_per_block; 100 memory->sysdev.id = memory->start_section_nr / sections_per_block;
101 101
102 error = sysdev_register(&memory->sysdev); 102 error = sysdev_register(&memory->sysdev);
103 return error; 103 return error;
@@ -138,12 +138,26 @@ static unsigned long get_memory_block_size(void)
138 * uses. 138 * uses.
139 */ 139 */
140 140
141static ssize_t show_mem_phys_index(struct sys_device *dev, 141static ssize_t show_mem_start_phys_index(struct sys_device *dev,
142 struct sysdev_attribute *attr, char *buf) 142 struct sysdev_attribute *attr, char *buf)
143{ 143{
144 struct memory_block *mem = 144 struct memory_block *mem =
145 container_of(dev, struct memory_block, sysdev); 145 container_of(dev, struct memory_block, sysdev);
146 return sprintf(buf, "%08lx\n", mem->phys_index / sections_per_block); 146 unsigned long phys_index;
147
148 phys_index = mem->start_section_nr / sections_per_block;
149 return sprintf(buf, "%08lx\n", phys_index);
150}
151
152static ssize_t show_mem_end_phys_index(struct sys_device *dev,
153 struct sysdev_attribute *attr, char *buf)
154{
155 struct memory_block *mem =
156 container_of(dev, struct memory_block, sysdev);
157 unsigned long phys_index;
158
159 phys_index = mem->end_section_nr / sections_per_block;
160 return sprintf(buf, "%08lx\n", phys_index);
147} 161}
148 162
149/* 163/*
@@ -158,7 +172,7 @@ static ssize_t show_mem_removable(struct sys_device *dev,
158 container_of(dev, struct memory_block, sysdev); 172 container_of(dev, struct memory_block, sysdev);
159 173
160 for (i = 0; i < sections_per_block; i++) { 174 for (i = 0; i < sections_per_block; i++) {
161 pfn = section_nr_to_pfn(mem->phys_index + i); 175 pfn = section_nr_to_pfn(mem->start_section_nr + i);
162 ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION); 176 ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
163 } 177 }
164 178
@@ -275,14 +289,15 @@ static int memory_block_change_state(struct memory_block *mem,
275 mem->state = MEM_GOING_OFFLINE; 289 mem->state = MEM_GOING_OFFLINE;
276 290
277 for (i = 0; i < sections_per_block; i++) { 291 for (i = 0; i < sections_per_block; i++) {
278 ret = memory_section_action(mem->phys_index + i, to_state); 292 ret = memory_section_action(mem->start_section_nr + i,
293 to_state);
279 if (ret) 294 if (ret)
280 break; 295 break;
281 } 296 }
282 297
283 if (ret) { 298 if (ret) {
284 for (i = 0; i < sections_per_block; i++) 299 for (i = 0; i < sections_per_block; i++)
285 memory_section_action(mem->phys_index + i, 300 memory_section_action(mem->start_section_nr + i,
286 from_state_req); 301 from_state_req);
287 302
288 mem->state = from_state_req; 303 mem->state = from_state_req;
@@ -330,7 +345,8 @@ static ssize_t show_phys_device(struct sys_device *dev,
330 return sprintf(buf, "%d\n", mem->phys_device); 345 return sprintf(buf, "%d\n", mem->phys_device);
331} 346}
332 347
333static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL); 348static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
349static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
334static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); 350static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
335static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); 351static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
336static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL); 352static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
@@ -522,17 +538,21 @@ static int init_memory_block(struct memory_block **memory,
522 return -ENOMEM; 538 return -ENOMEM;
523 539
524 scn_nr = __section_nr(section); 540 scn_nr = __section_nr(section);
525 mem->phys_index = base_memory_block_id(scn_nr) * sections_per_block; 541 mem->start_section_nr =
542 base_memory_block_id(scn_nr) * sections_per_block;
543 mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
526 mem->state = state; 544 mem->state = state;
527 mem->section_count++; 545 mem->section_count++;
528 mutex_init(&mem->state_mutex); 546 mutex_init(&mem->state_mutex);
529 start_pfn = section_nr_to_pfn(mem->phys_index); 547 start_pfn = section_nr_to_pfn(mem->start_section_nr);
530 mem->phys_device = arch_get_memory_phys_device(start_pfn); 548 mem->phys_device = arch_get_memory_phys_device(start_pfn);
531 549
532 ret = register_memory(mem); 550 ret = register_memory(mem);
533 if (!ret) 551 if (!ret)
534 ret = mem_create_simple_file(mem, phys_index); 552 ret = mem_create_simple_file(mem, phys_index);
535 if (!ret) 553 if (!ret)
554 ret = mem_create_simple_file(mem, end_phys_index);
555 if (!ret)
536 ret = mem_create_simple_file(mem, state); 556 ret = mem_create_simple_file(mem, state);
537 if (!ret) 557 if (!ret)
538 ret = mem_create_simple_file(mem, phys_device); 558 ret = mem_create_simple_file(mem, phys_device);
@@ -575,11 +595,12 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
575 595
576 mutex_lock(&mem_sysfs_mutex); 596 mutex_lock(&mem_sysfs_mutex);
577 mem = find_memory_block(section); 597 mem = find_memory_block(section);
598 unregister_mem_sect_under_nodes(mem, __section_nr(section));
578 599
579 mem->section_count--; 600 mem->section_count--;
580 if (mem->section_count == 0) { 601 if (mem->section_count == 0) {
581 unregister_mem_sect_under_nodes(mem);
582 mem_remove_simple_file(mem, phys_index); 602 mem_remove_simple_file(mem, phys_index);
603 mem_remove_simple_file(mem, end_phys_index);
583 mem_remove_simple_file(mem, state); 604 mem_remove_simple_file(mem, state);
584 mem_remove_simple_file(mem, phys_device); 605 mem_remove_simple_file(mem, phys_device);
585 mem_remove_simple_file(mem, removable); 606 mem_remove_simple_file(mem, removable);
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 36b43052001d..b3b72d64e805 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -375,8 +375,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
375 return -EFAULT; 375 return -EFAULT;
376 if (!node_online(nid)) 376 if (!node_online(nid))
377 return 0; 377 return 0;
378 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); 378
379 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; 379 sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
380 sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
381 sect_end_pfn += PAGES_PER_SECTION - 1;
380 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 382 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
381 int page_nid; 383 int page_nid;
382 384
@@ -400,7 +402,8 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
400} 402}
401 403
402/* unregister memory section under all nodes that it spans */ 404/* unregister memory section under all nodes that it spans */
403int unregister_mem_sect_under_nodes(struct memory_block *mem_blk) 405int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
406 unsigned long phys_index)
404{ 407{
405 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); 408 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
406 unsigned long pfn, sect_start_pfn, sect_end_pfn; 409 unsigned long pfn, sect_start_pfn, sect_end_pfn;
@@ -412,7 +415,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
412 if (!unlinked_nodes) 415 if (!unlinked_nodes)
413 return -ENOMEM; 416 return -ENOMEM;
414 nodes_clear(*unlinked_nodes); 417 nodes_clear(*unlinked_nodes);
415 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); 418
419 sect_start_pfn = section_nr_to_pfn(phys_index);
416 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; 420 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
417 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 421 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
418 int nid; 422 int nid;