diff mbox series

[v2,5/9] libpdbg: Prepare to add chtm for p10

Message ID 20211125004138.120917-6-jniethe5@gmail.com
State Accepted
Headers show
Series Add P10 HTM support | expand

Commit Message

Jordan Niethe Nov. 25, 2021, 12: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>
---
v2: add .configure, .deconfigure, function pointers
---
 libpdbg/htm.c    | 52 +++++++++++++++++++++++++++++++-----------------
 libpdbg/hwunit.h |  3 +++
 2 files changed, 37 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index 419ac287e760..f4a0c28a20a7 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -586,8 +586,7 @@  static int configure_debugfs_memtrace(struct htm *htm)
 
 static int configure_chtm(struct htm *htm, bool wrap)
 {
-	uint64_t hid0, ncu, val;
-	struct pdbg_target *core;
+	uint64_t val;
 
 	if (!pdbg_target_is_class(&htm->target, "chtm"))
 		return 0;
@@ -600,6 +599,17 @@  static int configure_chtm(struct htm *htm, bool wrap)
 		HTM_MODE_ENABLE | val)))
 		return -1;
 
+	if (htm->configure && htm->configure(htm) < 0)
+		return -1;
+
+	return 0;
+}
+
+static int do_configure_chtm_p8(struct htm *htm)
+{
+	uint64_t hid0, ncu;
+	struct pdbg_target *core;
+
 	core = pdbg_target_require_parent("core", &htm->target);
 	if (HTM_ERR(pib_read(core, HID0_REGISTER, &hid0)))
 		return -1;
@@ -618,12 +628,27 @@  static int configure_chtm(struct htm *htm, bool wrap)
 
 static int deconfigure_chtm(struct htm *htm)
 {
-	uint64_t hid0, ncu;
-	struct pdbg_target *core;
 
 	if (!pdbg_target_is_class(&htm->target, "chtm"))
 		return 0;
 
+	if (htm->deconfigure && htm->deconfigure(htm) < 0)
+		return -1;
+
+	if (HTM_ERR(pib_write(&htm->target, HTM_COLLECTION_MODE,0)))
+		return -1;
+
+//	FIXME this needs kernel work to happen
+//	if (HTM_ERR(deconfigure_debugfs_memtrace(htm)))
+//		return -1;
+	return 0;
+}
+
+static int do_deconfigure_chtm_p8(struct htm *htm)
+{
+	struct pdbg_target *core;
+	uint64_t ncu, hid0;
+
 	core = pdbg_target_require_parent("core", &htm->target);
 	if (HTM_ERR(pib_read(core, NCU_MODE_REGISTER, &ncu)))
 		return -1;
@@ -637,12 +662,6 @@  static int deconfigure_chtm(struct htm *htm)
 	if (HTM_ERR(pib_write(core, HID0_REGISTER, hid0)))
 		return -1;
 
-	if (HTM_ERR(pib_write(&htm->target, HTM_COLLECTION_MODE,0)))
-		return -1;
-
-//	FIXME this needs kernel work to happen
-//	if (HTM_ERR(deconfigure_debugfs_memtrace(htm)))
-//		return -1;
 	return 0;
 }
 
@@ -929,7 +948,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 do_post_configure_chtm_p8(struct htm *htm)
 {
 	struct pdbg_target *target;
 	struct pdbg_target *core;
@@ -941,12 +960,6 @@  static int htm_toggle_debug_bit(struct htm *htm)
 	if (!core)
 		return 0; /* nhtm case */
 
-	/* 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;
-	}
-
 	pdbg_for_each_target("thread", core, target) {
 		if (pdbg_target_index(target) == 0) {
 			/* Need to set this bit to ensure HTM starts */
@@ -980,7 +993,7 @@  static int __do_htm_start(struct htm *htm, bool wrap)
 	if (HTM_ERR(pib_write(&htm->target, HTM_SCOM_TRIGGER, HTM_TRIG_START)))
 		return -1;
 
-	if (htm_toggle_debug_bit(htm))
+	if (htm->post_configure && htm->post_configure(htm))
 		return -1;
 
 	/*
@@ -1378,6 +1391,9 @@  static struct htm p8_chtm = {
 	.record = do_htm_record,
 	.status = do_htm_status,
 	.dump = do_htm_dump,
+	.configure = do_configure_chtm_p8,
+	.deconfigure = do_deconfigure_chtm_p8,
+	.post_configure = do_post_configure_chtm_p8,
 };
 DECLARE_HW_UNIT(p8_chtm);
 
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index de15a870c20f..b8504b187d15 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -58,6 +58,9 @@  struct htm {
 	int (*status)(struct htm *);
 	int (*dump)(struct htm *, char *);
 	int (*record)(struct htm *, char *);
+	int (*configure)(struct htm *);
+	int (*deconfigure)(struct htm *);
+	int (*post_configure)(struct htm *);
 };
 #define target_to_htm(x) container_of(x, struct htm, target)