File powerpc-utils-papr.drmgs_mem_rm.patch of Package powerpc-utils
---
cmds/drmgr/drslot_chrp_mem.c | 120 ++++++++++++++++++++++---------------------
1 file changed, 64 insertions(+), 56 deletions(-)
--- a/cmds/drmgr/drslot_chrp_mem.c
+++ b/cmds/drmgr/drslot_chrp_mem.c
@@ -579,7 +579,7 @@ acquire_lmb(struct lmb *lmb, struct lmb_
rc = add_node(add_path, lmb->of_node);
} else {
/* Supply the correct add_path for lmb fixup below */
- sprintf(add_path, "ibm,dynamic-reconfiguration-memory");
+ sprintf(add_path, "/ibm,dynamic-reconfiguration-memory");
}
} else {
/* Add the new nodes to the device tree */
@@ -591,7 +591,7 @@ acquire_lmb(struct lmb *lmb, struct lmb_
return rc;
/* fix up the lmb now that we own it. */
- sprintf(lmb->ofdt_path, "%s/%s", OFDT_BASE, add_path);
+ sprintf(lmb->ofdt_path, "%s%s", OFDT_BASE, add_path);
if (! lmb_list->drconf_buf) {
/* Find the physical address for this lmb. This is only
@@ -733,6 +733,44 @@ set_mem_scn_state(struct mem_scn *mem_sc
}
/**
+ * probe_lmb
+ * @brief Probe all of the memory sections of the lmb
+ *
+ * @param lmb pointer to lmb to probe
+ * @returns 0 on success,!0 otherwise
+ */
+static int
+probe_lmb(struct lmb *lmb)
+{
+ struct mem_scn *scn;
+ int probe_file;
+ int rc = 0;
+
+ probe_file = open(MEM_PROBE_FILE, O_WRONLY);
+ if (probe_file <= 0) {
+ dbg("Could not open %s to probe memory\n", MEM_PROBE_FILE);
+ return errno;
+ }
+
+ for (scn = lmb->mem_scns; scn; scn = scn->next) {
+ char addr[DR_STR_MAX];
+
+ memset(addr, 0, DR_STR_MAX);
+ sprintf(addr, "0x%llx", scn->phys_addr);
+
+ dbg("Probing memory address 0x%llx\n", scn->phys_addr);
+ rc = write(probe_file, addr, strlen(addr));
+ if (rc == -1) {
+ dbg("Probe failed:\n%s\n", strerror(errno));
+ return rc;
+ }
+ }
+
+ close(probe_file);
+ return 0;
+}
+
+/**
* set_lmb_state
*
* @param lmb lmb to set the state for
@@ -743,16 +781,12 @@ static int
set_lmb_state(struct lmb *lmb, int state)
{
struct mem_scn *scn;
- int probe_file;
int rc = 0;
if (state == ONLINE) {
- probe_file = open(MEM_PROBE_FILE, O_WRONLY);
- if (probe_file <= 0) {
- dbg("Could not open %s to probe memory\n",
- MEM_PROBE_FILE);
- return errno;
- }
+ rc = probe_lmb(lmb);
+ if (rc)
+ return rc;
} else {
/* Ensure that we own this lmb */
if (! (lmb->flags & LMB_OWNED)) {
@@ -763,29 +797,9 @@ set_lmb_state(struct lmb *lmb, int state
}
for (scn = lmb->mem_scns; scn; scn = scn->next) {
- if (state == ONLINE) {
- char addr[DR_STR_MAX];
-
- memset(addr, 0, DR_STR_MAX);
- sprintf(addr, "0x%llx", scn->phys_addr);
-
- dbg("Probing memory address 0x%llx\n", scn->phys_addr);
- rc = write(probe_file, addr, strlen(addr));
- dbg("Probe write rc = %d\n", rc);
- if (rc == -1) {
- dbg("Could not write to %s:\n%s\n",
- MEM_PROBE_FILE, strerror(errno));
- break;
- }
-
- /* reset rc so we don't exit with false rc values */
- rc = 0;
- }
-
rc = set_mem_scn_state(scn, state);
if (rc)
break;
-
}
if (rc) {
@@ -800,9 +814,6 @@ set_lmb_state(struct lmb *lmb, int state
}
}
- if (state == ONLINE)
- close(probe_file);
-
lmb->flags |= LMB_STATE_SET;
return rc;
}
@@ -825,35 +836,31 @@ add_lmbs(int nr_lmbs, struct options *op
int rc = 0;
struct lmb *lmb;
- lmb = get_available_lmb(opts, lmb_list);
- if (lmb == NULL)
- return -1;
-
- rc = acquire_lmb(lmb, lmb_list);
- if (rc)
- return -1;
+ lmb_list->lmbs_modified = 0;
+ while (lmb_list->lmbs_modified < nr_lmbs) {
+ lmb = get_available_lmb(opts, lmb_list);
+ if (lmb == NULL)
+ return -1;
- if (nr_lmbs > 1)
- rc = add_lmbs(nr_lmbs - 1, opts, lmb_list);
+ rc = acquire_lmb(lmb, lmb_list);
+ if (rc) {
+ release_lmb(lmb, lmb_list);
+ lmb->flags |= LMB_UNUSABLE;
+ break;
+ }
- if (rc) {
- /* Roll back the operation. Is this the correct behavior? */
- release_lmb(lmb, lmb_list);
- return 1;
- }
+ rc = set_lmb_state(lmb, ONLINE);
+ dbg("setlmb rc = %d\n");
+ if (rc) {
+ release_lmb(lmb, lmb_list);
+ lmb->flags |= LMB_UNUSABLE;
+ break;
+ }
- rc = set_lmb_state(lmb, ONLINE);
- if (rc) {
- /* Roll back the operation. Is this the correct behavior? */
-#if 0
- set_lmb_state(lmb, OFFLINE);
- release_lmb(lmb, lmb_list);
-#endif
- return 1;
+ lmb_list->lmbs_modified++;
}
- lmb_list->lmbs_modified++;
- return 0;
+ return rc;
}
/**
@@ -875,6 +882,7 @@ mem_add(struct options *opts)
dbg("Adding %d lmbs\n", opts->quantity);
rc = add_lmbs(opts->quantity, opts, lmb_list);
+ dbg("DR_TOTAL_RESOURCES=%d\n", lmb_list->lmbs_modified);
printf("DR_TOTAL_RESOURCES=%d\n", lmb_list->lmbs_modified);
free_lmbs(lmb_list);