diff mbox series

[04/12] libpdbg: Prepare to add chtm for p10

Message ID 20210802054112.461728-5-jniethe5@gmail.com
State Superseded
Headers show
Series P10 HTM Support | expand

Commit Message

Jordan Niethe Aug. 2, 2021, 5:41 a.m. UTC
Break some p8 specific functionality into helper functions to make
things cleaner when adding support for chtm on p10.

Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
---
 libpdbg/htm.c | 74 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index ac0668631001..6a6ffeca12a5 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -595,11 +595,33 @@  static int configure_debugfs_memtrace(struct htm *htm)
 	return 0;
 }
 
-static int configure_chtm(struct htm *htm, bool wrap)
+static int configure_chtm_p8(struct htm *htm)
 {
-	uint64_t hid0, ncu, val;
+	uint64_t hid0, ncu;
 	struct pdbg_target *core;
 
+	core = pdbg_target_require_parent("core", &htm->target);
+
+	if (pdbg_target_compatible(&htm->target, "ibm,power8-chtm")) {
+		if (HTM_ERR(pib_read(core, HID0_REGISTER, &hid0)))
+			return -1;
+		hid0 |= HID0_TRACE_BITS;
+		if (HTM_ERR(pib_write(core, HID0_REGISTER, hid0)))
+			return -1;
+
+		if (HTM_ERR(pib_read(core, NCU_MODE_REGISTER, &ncu)))
+			return -1;
+		ncu |= NCU_MODE_HTM_ENABLE;
+		if (HTM_ERR(pib_write(core, NCU_MODE_REGISTER, ncu)))
+			return -1;
+	}
+
+	return 0;
+}
+static int configure_chtm(struct htm *htm, bool wrap)
+{
+	uint64_t val;
+
 	if (!pdbg_target_is_class(&htm->target, "chtm"))
 		return 0;
 
@@ -611,11 +633,7 @@  static int configure_chtm(struct htm *htm, bool wrap)
 		HTM_MODE_ENABLE | val)))
 		return -1;
 
-	core = pdbg_target_require_parent("core", &htm->target);
-	if (HTM_ERR(pib_read(core, HID0_REGISTER, &hid0)))
-		return -1;
-	hid0 |= HID0_TRACE_BITS;
-	if (HTM_ERR(pib_write(core, HID0_REGISTER, hid0)))
+	if (configure_chtm_p8(htm) < 0)
 		return -1;
 
 	if (HTM_ERR(pib_read(core, NCU_MODE_REGISTER, &ncu)))
@@ -627,25 +645,38 @@  static int configure_chtm(struct htm *htm, bool wrap)
 	return 0;
 }
 
-static int deconfigure_chtm(struct htm *htm)
+static int deconfigure_chtm_p8(struct htm *htm)
 {
-	uint64_t hid0, ncu;
 	struct pdbg_target *core;
+	uint64_t ncu, hid0;
+
+	if (pdbg_target_compatible(&htm->target, "ibm,power8-chtm")) {
+		core = pdbg_target_require_parent("core", &htm->target);
+		if (HTM_ERR(pib_read(core, NCU_MODE_REGISTER, &ncu)))
+			return -1;
+		ncu &= ~NCU_MODE_HTM_ENABLE;
+		if (HTM_ERR(pib_write(core, NCU_MODE_REGISTER, ncu)))
+			return -1;
+
+		if (HTM_ERR(pib_read(core, HID0_REGISTER, &hid0)))
+			return -1;
+		hid0 &= ~(HID0_TRACE_BITS);
+		if (HTM_ERR(pib_write(core, HID0_REGISTER, hid0)))
+			return -1;
+	}
+
+	return 0;
+}
+
+static int deconfigure_chtm(struct htm *htm)
+{
 
 	if (!pdbg_target_is_class(&htm->target, "chtm"))
 		return 0;
 
-	core = pdbg_target_require_parent("core", &htm->target);
-	if (HTM_ERR(pib_read(core, NCU_MODE_REGISTER, &ncu)))
-		return -1;
-	ncu &= ~NCU_MODE_HTM_ENABLE;
-	if (HTM_ERR(pib_write(core, NCU_MODE_REGISTER, ncu)))
+	if (deconfigure_chtm_p8(htm) < 0)
 		return -1;
 
-	if (HTM_ERR(pib_read(core, HID0_REGISTER, &hid0)))
-		return -1;
-	hid0 &= ~(HID0_TRACE_BITS);
-	if (HTM_ERR(pib_write(core, HID0_REGISTER, hid0)))
 		return -1;
 
 	if (HTM_ERR(pib_write(&htm->target, HTM_COLLECTION_MODE,0)))
@@ -945,7 +976,7 @@  static int do_htm_reset(struct htm *htm, bool wrap)
 /* Stolen from p8chip.c */
 #define RAS_MODE_REG			0x1
 #define  MR_THREAD_IN_DEBUG		PPC_BIT(43)
-static int htm_toggle_debug_bit(struct htm *htm)
+static int post_configure_chtm_p8(struct htm *htm)
 {
 	struct pdbg_target *target;
 	struct pdbg_target *core;
@@ -959,8 +990,7 @@  static int htm_toggle_debug_bit(struct htm *htm)
 
 	/* FIXME: this is a hack for P8 */
 	if (!pdbg_target_compatible(core, "ibm,power8-core")) {
-		PR_ERROR("HTM is POWER8 only currently\n");
-		return -1;
+		return 0;
 	}
 
 	pdbg_for_each_target("thread", core, target) {
@@ -996,7 +1026,7 @@  static int __do_htm_start(struct htm *htm, bool wrap)
 	if (HTM_ERR(pib_write(&htm->target, reg_off(htm, HTM_SCOM_TRIGGER), HTM_TRIG_START)))
 		return -1;
 
-	if (htm_toggle_debug_bit(htm))
+	if (post_configure_chtm_p8(htm))
 		return -1;
 
 	/*