[Skiboot] [PATCH 15/18] direct-controls: p8 implementation of generic direct controls

Nicholas Piggin npiggin at gmail.com
Sun Nov 19 20:15:05 AEDT 2017


This reworks the sreset functionality that was brought over from
fast-reboot, and fits it with the generic direct controls APIs. The
fast reboot APIs are implementing using generic direct controls.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 core/direct-controls.c | 199 +++++++++++++++++++++++++++----------------------
 1 file changed, 109 insertions(+), 90 deletions(-)

diff --git a/core/direct-controls.c b/core/direct-controls.c
index 046c5190..2377d4f7 100644
--- a/core/direct-controls.c
+++ b/core/direct-controls.c
@@ -44,7 +44,7 @@ static void mambo_sreset_cpu(struct cpu_thread *cpu)
 #define P8_DIRECT_CTL_PRENAP		PPC_BIT(47)
 #define P8_DIRECT_CTL_SRESET		PPC_BIT(60)
 
-static int p8_set_special_wakeup(struct cpu_thread *cpu)
+static int p8_core_set_special_wakeup(struct cpu_thread *cpu)
 {
 	uint64_t val, poll_target, stamp;
 	uint32_t core_id;
@@ -155,7 +155,7 @@ static int p8_set_special_wakeup(struct cpu_thread *cpu)
 	return OPAL_HARDWARE;
 }
 
-static int p8_clr_special_wakeup(struct cpu_thread *cpu)
+static int p8_core_clear_special_wakeup(struct cpu_thread *cpu)
 {
 	uint64_t val;
 	uint32_t core_id;
@@ -215,91 +215,19 @@ static void p8_set_direct_ctl(struct cpu_thread *cpu, uint64_t bits)
 	xscom_write(chip_id, xscom_addr, bits);
 }
 
-static int p8_sreset_all_prepare(void)
+static int p8_stop_thread(struct cpu_thread *cpu)
 {
-	struct cpu_thread *cpu;
-
-	prlog(PR_DEBUG, "RESET: Resetting from cpu: 0x%x (core 0x%x)\n",
-	      this_cpu()->pir, pir_to_core_id(this_cpu()->pir));
-
-	/* Assert special wakup on all cores. Only on operational cores. */
-	for_each_ungarded_primary(cpu) {
-		if (p8_set_special_wakeup(cpu) != OPAL_SUCCESS)
-			return OPAL_HARDWARE;
-	}
-
-	prlog(PR_DEBUG, "RESET: Stopping the world...\n");
-
-	/* Put everybody in stop except myself */
-	for_each_ungarded_cpu(cpu) {
-		if (cpu != this_cpu())
-			p8_set_direct_ctl(cpu, P8_DIRECT_CTL_STOP);
-	}
+	p8_set_direct_ctl(cpu, P8_DIRECT_CTL_STOP);
 
 	return OPAL_SUCCESS;
 }
 
-static void p8_sreset_all_finish(void)
-{
-	struct cpu_thread *cpu;
-
-	for_each_ungarded_primary(cpu)
-		p8_clr_special_wakeup(cpu);
-}
-
-static void p8_sreset_all_others(void)
-{
-	struct cpu_thread *cpu;
-
-	prlog(PR_DEBUG, "RESET: Resetting all threads but one...\n");
-
-	/* Reset everybody except my own core threads */
-	for_each_ungarded_cpu(cpu) {
-		if (cpu == this_cpu())
-			continue;
-
-		p8_set_direct_ctl(cpu, P8_DIRECT_CTL_PRENAP);
-		p8_set_direct_ctl(cpu, P8_DIRECT_CTL_SRESET);
-	}
-}
-
-int sreset_all_prepare(void)
-{
-	if (chip_quirk(QUIRK_MAMBO_CALLOUTS))
-		return OPAL_SUCCESS;
-
-	if (proc_gen == proc_gen_p8)
-		return p8_sreset_all_prepare();
-
-	return OPAL_UNSUPPORTED;
-}
-
-void sreset_all_finish(void)
+static int p8_sreset_thread(struct cpu_thread *cpu)
 {
-	if (chip_quirk(QUIRK_MAMBO_CALLOUTS))
-		return;
-
-	if (proc_gen == proc_gen_p8)
-		return p8_sreset_all_finish();
-}
-
-int sreset_all_others(void)
-{
-	if (chip_quirk(QUIRK_MAMBO_CALLOUTS)) {
-		struct cpu_thread *cpu;
+	p8_set_direct_ctl(cpu, P8_DIRECT_CTL_PRENAP);
+	p8_set_direct_ctl(cpu, P8_DIRECT_CTL_SRESET);
 
-		for_each_ungarded_cpu(cpu)
-			mambo_sreset_cpu(cpu);
-
-		return OPAL_SUCCESS;
-	}
-
-	if (proc_gen == proc_gen_p8) {
-		p8_sreset_all_others();
-		return OPAL_SUCCESS;
-	}
-
-	return OPAL_UNSUPPORTED;
+	return OPAL_SUCCESS;
 }
 
 
@@ -504,17 +432,24 @@ static int p9_sreset_thread(struct cpu_thread *cpu)
 	return 0;
 }
 
+
+/**************** generic direct controls ****************/
+
 static int dctl_set_special_wakeup(struct cpu_thread *t)
 {
 	struct cpu_thread *c = t->primary;
 	int rc = OPAL_SUCCESS;
 
-	if (proc_gen != proc_gen_p9)
+	if (proc_gen != proc_gen_p9 && proc_gen != proc_gen_p8)
 		return OPAL_UNSUPPORTED;
 
 	lock(&c->dctl_lock);
-	if (c->special_wakeup_count == 0)
-		rc = p9_core_set_special_wakeup(c);
+	if (c->special_wakeup_count == 0) {
+		if (proc_gen == proc_gen_p9)
+			rc = p9_core_set_special_wakeup(c);
+		else /* (proc_gen == proc_gen_p8) */
+			rc = p8_core_set_special_wakeup(c);
+	}
 	if (!rc)
 		c->special_wakeup_count++;
 	unlock(&c->dctl_lock);
@@ -527,14 +462,18 @@ static int dctl_clear_special_wakeup(struct cpu_thread *t)
 	struct cpu_thread *c = t->primary;
 	int rc = OPAL_SUCCESS;
 
-	if (proc_gen != proc_gen_p9)
+	if (proc_gen != proc_gen_p9 && proc_gen != proc_gen_p8)
 		return OPAL_UNSUPPORTED;
 
 	lock(&c->dctl_lock);
 	if (!c->special_wakeup_count)
 		goto out;
-	if (c->special_wakeup_count == 1)
-		rc = p9_core_clear_special_wakeup(c);
+	if (c->special_wakeup_count == 1) {
+		if (proc_gen == proc_gen_p9)
+			rc = p9_core_clear_special_wakeup(c);
+		else /* (proc_gen == proc_gen_p8) */
+			rc = p8_core_clear_special_wakeup(c);
+	}
 	if (!rc)
 		c->special_wakeup_count--;
 out:
@@ -548,7 +487,7 @@ static int dctl_stop(struct cpu_thread *t)
 	struct cpu_thread *c = t->primary;
 	int rc;
 
-	if (proc_gen != proc_gen_p9)
+	if (proc_gen != proc_gen_p9 && proc_gen != proc_gen_p8)
 		return OPAL_UNSUPPORTED;
 
 	lock(&c->dctl_lock);
@@ -556,7 +495,10 @@ static int dctl_stop(struct cpu_thread *t)
 		unlock(&c->dctl_lock);
 		return OPAL_BUSY;
 	}
-	rc = p9_stop_thread(t);
+	if (proc_gen == proc_gen_p9)
+		rc = p9_stop_thread(t);
+	else /* (proc_gen == proc_gen_p8) */
+		rc = p8_stop_thread(t);
 	if (!rc)
 		t->dctl_stopped = true;
 	unlock(&c->dctl_lock);
@@ -590,7 +532,7 @@ static int dctl_sreset(struct cpu_thread *t)
 	struct cpu_thread *c = t->primary;
 	int rc;
 
-	if (proc_gen != proc_gen_p9)
+	if (proc_gen != proc_gen_p9 && proc_gen != proc_gen_p8)
 		return OPAL_UNSUPPORTED;
 
 	lock(&c->dctl_lock);
@@ -598,7 +540,10 @@ static int dctl_sreset(struct cpu_thread *t)
 		unlock(&c->dctl_lock);
 		return OPAL_BUSY;
 	}
-	rc = p9_sreset_thread(t);
+	if (proc_gen == proc_gen_p9)
+		rc = p9_sreset_thread(t);
+	else /* (proc_gen == proc_gen_p8) */
+		rc = p8_sreset_thread(t);
 	if (!rc)
 		t->dctl_stopped = false;
 	unlock(&c->dctl_lock);
@@ -606,6 +551,80 @@ static int dctl_sreset(struct cpu_thread *t)
 	return rc;
 }
 
+
+/**************** fast reboot API ****************/
+
+int sreset_all_prepare(void)
+{
+	struct cpu_thread *cpu;
+
+	prlog(PR_DEBUG, "RESET: Resetting from cpu: 0x%x (core 0x%x)\n",
+	      this_cpu()->pir, pir_to_core_id(this_cpu()->pir));
+
+	if (chip_quirk(QUIRK_MAMBO_CALLOUTS))
+		return OPAL_SUCCESS;
+
+	/* Assert special wakup on all cores. Only on operational cores. */
+	for_each_ungarded_primary(cpu) {
+		if (dctl_set_special_wakeup(cpu) != OPAL_SUCCESS)
+			return OPAL_HARDWARE;
+	}
+
+	prlog(PR_DEBUG, "RESET: Stopping the world...\n");
+
+	/* Put everybody in stop except myself */
+	for_each_ungarded_cpu(cpu) {
+		if (cpu == this_cpu())
+			continue;
+		if (dctl_stop(cpu) != OPAL_SUCCESS)
+			return OPAL_HARDWARE;
+
+	}
+
+	return OPAL_SUCCESS;
+}
+
+void sreset_all_finish(void)
+{
+	struct cpu_thread *cpu;
+
+	if (chip_quirk(QUIRK_MAMBO_CALLOUTS))
+		return;
+
+	for_each_ungarded_primary(cpu)
+		dctl_clear_special_wakeup(cpu);
+}
+
+int sreset_all_others(void)
+{
+	struct cpu_thread *cpu;
+
+	prlog(PR_DEBUG, "RESET: Resetting all threads but self...\n");
+
+	/*
+	 * mambo should actually implement stop as well, and implement
+	 * the dctl_ helpers properly. Currently it's racy just sresetting.
+	 */
+	if (chip_quirk(QUIRK_MAMBO_CALLOUTS)) {
+		for_each_ungarded_cpu(cpu)
+			mambo_sreset_cpu(cpu);
+
+		return OPAL_SUCCESS;
+	}
+
+	for_each_ungarded_cpu(cpu) {
+		if (cpu == this_cpu())
+			continue;
+		if (dctl_sreset(cpu) != OPAL_SUCCESS)
+			return OPAL_HARDWARE;
+	}
+
+	return OPAL_SUCCESS;
+}
+
+
+/**************** OPAL_SIGNAL_SYSTEM_RESET API ****************/
+
 /*
  * This provides a way for the host to raise system reset exceptions
  * on other threads using direct control scoms on POWER9.
-- 
2.15.0



More information about the Skiboot mailing list