All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Fontenot <nfont@linux.vnet.ibm.com>
To: LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>,
	linuxppc-dev@lists.ozlabs.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 7/8]  Add memory hot add/remove notifier handlers for pwoerpc
Date: Wed, 24 Jul 2013 13:45:47 -0500	[thread overview]
Message-ID: <51F020DB.3090909@linux.vnet.ibm.com> (raw)
In-Reply-To: <51F01E06.6090800@linux.vnet.ibm.com>

Add memory hot add/remove notifier handlers for powerpc/pseries.

This patch allows the powerpc/pseries platforms to perform memory DLPAR
int the kernel. The handlers for add and remove do the work of
acquiring/releasing the memory to firmware and updating the device tree.

This is only used when memory is specified in the
ibm,dynamic-reconfiguration-memory device tree node so the memory notifiers
are registered contingent on its existence.

Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/pseries/dlpar.c |  103 +++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

Index: linux/arch/powerpc/platforms/pseries/dlpar.c
===================================================================
--- linux.orig/arch/powerpc/platforms/pseries/dlpar.c
+++ linux/arch/powerpc/platforms/pseries/dlpar.c
@@ -15,6 +15,7 @@
 #include <linux/notifier.h>
 #include <linux/spinlock.h>
 #include <linux/cpu.h>
+#include <linux/memory.h>
 #include <linux/slab.h>
 #include <linux/of.h>
 #include "offline_states.h"
@@ -531,11 +532,113 @@ out:
 	return rc ? rc : count;
 }
 
+static struct of_drconf_cell *dlpar_get_drconf_cell(struct device_node *dn,
+						    unsigned long phys_addr)
+{
+	struct of_drconf_cell *drmem;
+	u32 entries;
+	u32 *prop;
+	int i;
+
+	prop = (u32 *)of_get_property(dn, "ibm,dynamic-memory", NULL);
+	of_node_put(dn);
+	if (!prop)
+		return NULL;
+
+	entries = *prop++;
+	drmem = (struct of_drconf_cell *)prop;
+
+	for (i = 0; i < entries; i++) {
+		if (drmem[i].base_addr == phys_addr)
+			return &drmem[i];
+	}
+
+	return NULL;
+}
+
+static int dlpar_mem_probe(unsigned long phys_addr)
+{
+	struct device_node *dn;
+	struct of_drconf_cell *drmem;
+	int rc;
+
+	dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
+	if (!dn)
+		return -EINVAL;
+
+	drmem = dlpar_get_drconf_cell(dn, phys_addr);
+	of_node_put(dn);
+
+	if (!drmem)
+		return -EINVAL;
+
+	if (drmem->flags & DRCONF_MEM_ASSIGNED)
+		return 0;
+
+	drmem->flags |= DRCONF_MEM_ASSIGNED;
+
+	rc = dlpar_acquire_drc(drmem->drc_index);
+	return rc;
+}
+
+static int dlpar_mem_release(unsigned long phys_addr)
+{
+	struct device_node *dn;
+	struct of_drconf_cell *drmem;
+	int rc;
+
+	dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
+	if (!dn)
+		return -EINVAL;
+
+	drmem = dlpar_get_drconf_cell(dn, phys_addr);
+	of_node_put(dn);
+
+	if (!drmem)
+		return -EINVAL;
+
+	if (!drmem->flags & DRCONF_MEM_ASSIGNED)
+		return 0;
+
+	drmem->flags &= ~DRCONF_MEM_ASSIGNED;
+
+	rc = dlpar_release_drc(drmem->drc_index);
+	return rc;
+}
+
+static int pseries_dlpar_mem_callback(struct notifier_block *nb,
+				      unsigned long action, void *hp_arg)
+{
+	struct memory_notify *arg = hp_arg;
+	unsigned long phys_addr = arg->start_pfn << PAGE_SHIFT;
+	int rc = 0;
+
+
+	switch (action) {
+	case MEM_BEING_HOT_ADDED:
+		rc = dlpar_mem_probe(phys_addr);
+		break;
+	case MEM_HOT_REMOVED:
+		rc = dlpar_mem_release(phys_addr);
+		break;
+	}
+
+	return notifier_from_errno(rc);
+}
+
 static int __init pseries_dlpar_init(void)
 {
+	struct device_node *dn;
+
 	ppc_md.cpu_probe = dlpar_cpu_probe;
 	ppc_md.cpu_release = dlpar_cpu_release;
 
+	dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
+	if (dn) {
+		hotplug_memory_notifier(pseries_dlpar_mem_callback, 0);
+		of_node_put(dn);
+	}
+
 	return 0;
 }
 machine_device_initcall(pseries, pseries_dlpar_init);

WARNING: multiple messages have this Message-ID (diff)
From: Nathan Fontenot <nfont@linux.vnet.ibm.com>
To: LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>,
	linuxppc-dev@lists.ozlabs.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 7/8]  Add memory hot add/remove notifier handlers for pwoerpc
Date: Wed, 24 Jul 2013 13:45:47 -0500	[thread overview]
Message-ID: <51F020DB.3090909@linux.vnet.ibm.com> (raw)
In-Reply-To: <51F01E06.6090800@linux.vnet.ibm.com>

Add memory hot add/remove notifier handlers for powerpc/pseries.

This patch allows the powerpc/pseries platforms to perform memory DLPAR
int the kernel. The handlers for add and remove do the work of
acquiring/releasing the memory to firmware and updating the device tree.

This is only used when memory is specified in the
ibm,dynamic-reconfiguration-memory device tree node so the memory notifiers
are registered contingent on its existence.

Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/pseries/dlpar.c |  103 +++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

Index: linux/arch/powerpc/platforms/pseries/dlpar.c
===================================================================
--- linux.orig/arch/powerpc/platforms/pseries/dlpar.c
+++ linux/arch/powerpc/platforms/pseries/dlpar.c
@@ -15,6 +15,7 @@
 #include <linux/notifier.h>
 #include <linux/spinlock.h>
 #include <linux/cpu.h>
+#include <linux/memory.h>
 #include <linux/slab.h>
 #include <linux/of.h>
 #include "offline_states.h"
@@ -531,11 +532,113 @@ out:
 	return rc ? rc : count;
 }
 
+static struct of_drconf_cell *dlpar_get_drconf_cell(struct device_node *dn,
+						    unsigned long phys_addr)
+{
+	struct of_drconf_cell *drmem;
+	u32 entries;
+	u32 *prop;
+	int i;
+
+	prop = (u32 *)of_get_property(dn, "ibm,dynamic-memory", NULL);
+	of_node_put(dn);
+	if (!prop)
+		return NULL;
+
+	entries = *prop++;
+	drmem = (struct of_drconf_cell *)prop;
+
+	for (i = 0; i < entries; i++) {
+		if (drmem[i].base_addr == phys_addr)
+			return &drmem[i];
+	}
+
+	return NULL;
+}
+
+static int dlpar_mem_probe(unsigned long phys_addr)
+{
+	struct device_node *dn;
+	struct of_drconf_cell *drmem;
+	int rc;
+
+	dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
+	if (!dn)
+		return -EINVAL;
+
+	drmem = dlpar_get_drconf_cell(dn, phys_addr);
+	of_node_put(dn);
+
+	if (!drmem)
+		return -EINVAL;
+
+	if (drmem->flags & DRCONF_MEM_ASSIGNED)
+		return 0;
+
+	drmem->flags |= DRCONF_MEM_ASSIGNED;
+
+	rc = dlpar_acquire_drc(drmem->drc_index);
+	return rc;
+}
+
+static int dlpar_mem_release(unsigned long phys_addr)
+{
+	struct device_node *dn;
+	struct of_drconf_cell *drmem;
+	int rc;
+
+	dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
+	if (!dn)
+		return -EINVAL;
+
+	drmem = dlpar_get_drconf_cell(dn, phys_addr);
+	of_node_put(dn);
+
+	if (!drmem)
+		return -EINVAL;
+
+	if (!drmem->flags & DRCONF_MEM_ASSIGNED)
+		return 0;
+
+	drmem->flags &= ~DRCONF_MEM_ASSIGNED;
+
+	rc = dlpar_release_drc(drmem->drc_index);
+	return rc;
+}
+
+static int pseries_dlpar_mem_callback(struct notifier_block *nb,
+				      unsigned long action, void *hp_arg)
+{
+	struct memory_notify *arg = hp_arg;
+	unsigned long phys_addr = arg->start_pfn << PAGE_SHIFT;
+	int rc = 0;
+
+
+	switch (action) {
+	case MEM_BEING_HOT_ADDED:
+		rc = dlpar_mem_probe(phys_addr);
+		break;
+	case MEM_HOT_REMOVED:
+		rc = dlpar_mem_release(phys_addr);
+		break;
+	}
+
+	return notifier_from_errno(rc);
+}
+
 static int __init pseries_dlpar_init(void)
 {
+	struct device_node *dn;
+
 	ppc_md.cpu_probe = dlpar_cpu_probe;
 	ppc_md.cpu_release = dlpar_cpu_release;
 
+	dn = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
+	if (dn) {
+		hotplug_memory_notifier(pseries_dlpar_mem_callback, 0);
+		of_node_put(dn);
+	}
+
 	return 0;
 }
 machine_device_initcall(pseries, pseries_dlpar_init);


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2013-07-24 18:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-24 18:33 [PATCH 0/8] Correct memory hot add/remove for powerpc Nathan Fontenot
2013-07-24 18:33 ` Nathan Fontenot
2013-07-24 18:35 ` [PATCH 1/8] register bootmem pages for powerpc when sparse vmemmap is not defined Nathan Fontenot
2013-07-24 18:35   ` Nathan Fontenot
2013-08-02  2:27   ` Michael Ellerman
2013-08-02  2:27     ` Michael Ellerman
2013-08-02  2:27     ` Michael Ellerman
2013-08-02 19:04     ` Nathan Fontenot
2013-08-02 19:04       ` Nathan Fontenot
2013-07-24 18:36 ` [PATCH 2/8] Mark powerpc memory resources as busy Nathan Fontenot
2013-07-24 18:36   ` Nathan Fontenot
2013-08-02  2:28   ` Michael Ellerman
2013-08-02  2:28     ` Michael Ellerman
2013-08-02  2:28     ` Michael Ellerman
2013-08-02 19:05     ` Nathan Fontenot
2013-08-02 19:05       ` Nathan Fontenot
2013-08-05  3:11       ` Michael Ellerman
2013-08-05  3:11         ` Michael Ellerman
2013-07-24 18:37 ` [PATCH 3/8] Add all memory via sysfs probe interface at once Nathan Fontenot
2013-07-24 18:37   ` Nathan Fontenot
2013-08-02  2:32   ` Michael Ellerman
2013-08-02  2:32     ` Michael Ellerman
2013-08-02  2:32     ` Michael Ellerman
2013-08-02 19:13     ` Nathan Fontenot
2013-08-02 19:13       ` Nathan Fontenot
2013-08-05  3:13       ` Michael Ellerman
2013-08-05  3:13         ` Michael Ellerman
2013-08-06 20:44         ` Nathan Fontenot
2013-08-06 20:44           ` Nathan Fontenot
2013-08-09  7:16           ` Benjamin Herrenschmidt
2013-08-09  7:16             ` Benjamin Herrenschmidt
2013-08-09  7:16             ` Benjamin Herrenschmidt
2013-07-24 18:39 ` [PATCH 4/8] Create a sysfs release file for hot removing memory Nathan Fontenot
2013-07-24 18:39   ` Nathan Fontenot
2013-07-24 18:41 ` [PATCH 5/8] Add notifiers for memory hot add/remove Nathan Fontenot
2013-07-24 18:41   ` Nathan Fontenot
2013-07-24 18:44 ` [PATCH 6/8] Update the powerpc arch specific memory add/remove handlers Nathan Fontenot
2013-07-24 18:44   ` Nathan Fontenot
2013-07-24 18:45 ` Nathan Fontenot [this message]
2013-07-24 18:45   ` [PATCH 7/8] Add memory hot add/remove notifier handlers for pwoerpc Nathan Fontenot
2013-07-24 18:47 ` [PATCH 8/8] Remove no longer needed powerpc memory node update handler Nathan Fontenot
2013-07-24 18:47   ` Nathan Fontenot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51F020DB.3090909@linux.vnet.ibm.com \
    --to=nfont@linux.vnet.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.