Skip to content

Commit

Permalink
powerpc/pseries: Refactor dlpar_add_lmb() code
Browse files Browse the repository at this point in the history
Re-factor dlpar_lmb_add() routine by moving the validation of the lmb
flags and the acquireing of the DRC to a wrapper around the work to add
the memory to the system. This is done to make handling of errors
during the addition of the memory easier and to facilitate the upcoming
addition of updating the lmb's affinity prior to adding the memory.

Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Nathan Fontenot authored and Michael Ellerman committed Apr 11, 2016
1 parent bf16200 commit 4a4bdfe
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions arch/powerpc/platforms/pseries/hotplug-memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,58 +384,64 @@ static int dlpar_memory_remove_by_index(u32 drc_index, struct property *prop)

#endif /* CONFIG_MEMORY_HOTREMOVE */

static int dlpar_add_lmb(struct of_drconf_cell *lmb)
static int dlpar_add_lmb_memory(struct of_drconf_cell *lmb)
{
struct memory_block *mem_block;
unsigned long block_sz;
int nid, rc;

if (lmb->flags & DRCONF_MEM_ASSIGNED)
return -EINVAL;

block_sz = memory_block_size_bytes();

rc = dlpar_acquire_drc(lmb->drc_index);
if (rc)
return rc;

/* Find the node id for this address */
nid = memory_add_physaddr_to_nid(lmb->base_addr);

/* Add the memory */
rc = add_memory(nid, lmb->base_addr, block_sz);
if (rc) {
dlpar_release_drc(lmb->drc_index);
if (rc)
return rc;
}

/* Register this block of memory */
rc = memblock_add(lmb->base_addr, block_sz);
if (rc) {
remove_memory(nid, lmb->base_addr, block_sz);
dlpar_release_drc(lmb->drc_index);
return rc;
}

mem_block = lmb_to_memblock(lmb);
if (!mem_block) {
remove_memory(nid, lmb->base_addr, block_sz);
dlpar_release_drc(lmb->drc_index);
return -EINVAL;
}

rc = device_online(&mem_block->dev);
put_device(&mem_block->dev);
if (rc) {
remove_memory(nid, lmb->base_addr, block_sz);
dlpar_release_drc(lmb->drc_index);
return rc;
}

lmb->flags |= DRCONF_MEM_ASSIGNED;
return 0;
}

static int dlpar_add_lmb(struct of_drconf_cell *lmb)
{
int rc;

if (lmb->flags & DRCONF_MEM_ASSIGNED)
return -EINVAL;

rc = dlpar_acquire_drc(lmb->drc_index);
if (rc)
return rc;

rc = dlpar_add_lmb_memory(lmb);
if (rc)
dlpar_release_drc(lmb->drc_index);

return rc;
}

static int dlpar_memory_add_by_count(u32 lmbs_to_add, struct property *prop)
{
struct of_drconf_cell *lmbs;
Expand Down

0 comments on commit 4a4bdfe

Please sign in to comment.