[Pdbg] [RFC 01/12] libpdbg: Rename adu class to mem

Alistair Popple alistair at popple.id.au
Tue Aug 6 11:37:12 AEST 2019


The ADU is really an implementation of a method to access system
memory. Therefore it should export an interface to access system
memory rather than an implementation specific interface. Rename the
class from "adu" to "mem" to reflect this.

Signed-off-by: Alistair Popple <alistair at popple.id.au>
---
 libpdbg/adu.c    | 74 ++++++++++++++++++++++++------------------------
 libpdbg/htm.c    |  2 +-
 libpdbg/hwunit.h | 13 ++++-----
 libpdbg/target.c | 20 ++++++-------
 src/mem.c        |  4 +--
 src/pdbgproxy.c  |  2 +-
 src/thread.c     |  2 +-
 7 files changed, 58 insertions(+), 59 deletions(-)

diff --git a/libpdbg/adu.c b/libpdbg/adu.c
index 3904265..25f08cd 100644
--- a/libpdbg/adu.c
+++ b/libpdbg/adu.c
@@ -111,7 +111,7 @@ uint8_t blog2(uint8_t x)
 	}
 }
 
-static int adu_read(struct adu *adu, uint64_t start_addr, uint8_t *output,
+static int adu_read(struct mem *adu, uint64_t start_addr, uint8_t *output,
 		    uint64_t size, uint8_t block_size, bool ci)
 {
 	uint8_t *output0;
@@ -164,10 +164,10 @@ static int adu_read(struct adu *adu, uint64_t start_addr, uint8_t *output,
 int adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr,
 	       uint8_t *output, uint64_t size)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	return adu_read(adu, start_addr, output, size, 8, false);
 }
@@ -175,10 +175,10 @@ int adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr,
 int adu_getmem_ci(struct pdbg_target *adu_target, uint64_t start_addr,
 		  uint8_t *output, uint64_t size)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	return adu_read(adu, start_addr, output, size, 8, true);
 }
@@ -186,10 +186,10 @@ int adu_getmem_ci(struct pdbg_target *adu_target, uint64_t start_addr,
 int adu_getmem_io(struct pdbg_target *adu_target, uint64_t start_addr,
 		  uint8_t *output, uint64_t size, uint8_t blocksize)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	/* There is no equivalent for cachable memory as blocksize
 	 * does not apply to cachable reads */
@@ -199,15 +199,15 @@ int adu_getmem_io(struct pdbg_target *adu_target, uint64_t start_addr,
 int __adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr,
 		 uint8_t *output, uint64_t size, bool ci)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	return adu_read(adu, start_addr, output, size, 8, ci);
 }
 
-static int adu_write(struct adu *adu, uint64_t start_addr, uint8_t *input,
+static int adu_write(struct mem *adu, uint64_t start_addr, uint8_t *input,
 		     uint64_t size, uint8_t block_size, bool ci)
 {
 	int rc = 0, tsize;
@@ -248,10 +248,10 @@ static int adu_write(struct adu *adu, uint64_t start_addr, uint8_t *input,
 int adu_putmem(struct pdbg_target *adu_target, uint64_t start_addr,
 	       uint8_t *input, uint64_t size)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	return adu_write(adu, start_addr, input, size, 8, false);
 }
@@ -259,10 +259,10 @@ int adu_putmem(struct pdbg_target *adu_target, uint64_t start_addr,
 int adu_putmem_ci(struct pdbg_target *adu_target, uint64_t start_addr,
 		  uint8_t *input, uint64_t size)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	return adu_write(adu, start_addr, input, size, 8, true);
 }
@@ -270,10 +270,10 @@ int adu_putmem_ci(struct pdbg_target *adu_target, uint64_t start_addr,
 int adu_putmem_io(struct pdbg_target *adu_target, uint64_t start_addr,
 		  uint8_t *input, uint64_t size, uint8_t block_size)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	return adu_write(adu, start_addr, input, size, block_size, true);
 }
@@ -281,15 +281,15 @@ int adu_putmem_io(struct pdbg_target *adu_target, uint64_t start_addr,
 int __adu_putmem(struct pdbg_target *adu_target, uint64_t start_addr,
 		 uint8_t *input, uint64_t size, bool ci)
 {
-	struct adu *adu;
+	struct mem *adu;
 
-	assert(!strcmp(adu_target->class, "adu"));
-	adu = target_to_adu(adu_target);
+	assert(!strcmp(adu_target->class, "mem"));
+	adu = target_to_mem(adu_target);
 
 	return adu_write(adu, start_addr, input, size, 8, ci);
 }
 
-static int adu_lock(struct adu *adu)
+static int adu_lock(struct mem *adu)
 {
 	uint64_t val;
 
@@ -304,7 +304,7 @@ static int adu_lock(struct adu *adu)
 	return 0;
 }
 
-static int adu_unlock(struct adu *adu)
+static int adu_unlock(struct mem *adu)
 {
 	uint64_t val;
 
@@ -321,7 +321,7 @@ static int adu_unlock(struct adu *adu)
 	return 0;
 }
 
-static int adu_reset(struct adu *adu)
+static int adu_reset(struct mem *adu)
 {
 	uint64_t val;
 
@@ -332,7 +332,7 @@ static int adu_reset(struct adu *adu)
 	return 0;
 }
 
-static int p8_adu_getmem(struct adu *adu, uint64_t addr, uint64_t *data,
+static int p8_adu_getmem(struct mem *adu, uint64_t addr, uint64_t *data,
 			 int ci, uint8_t block_size)
 {
 	uint64_t ctrl_reg, cmd_reg, val;
@@ -394,7 +394,7 @@ out:
 
 }
 
-int p8_adu_putmem(struct adu *adu, uint64_t addr, uint64_t data, int size,
+int p8_adu_putmem(struct mem *adu, uint64_t addr, uint64_t data, int size,
 		  int ci, uint8_t block_size)
 {
 	int rc = 0;
@@ -455,7 +455,7 @@ out:
 	return rc;
 }
 
-static int p9_adu_getmem(struct adu *adu, uint64_t addr, uint64_t *data,
+static int p9_adu_getmem(struct mem *adu, uint64_t addr, uint64_t *data,
 			 int ci, uint8_t block_size)
 {
 	uint64_t ctrl_reg, cmd_reg, val;
@@ -512,7 +512,7 @@ retry:
 	return 0;
 }
 
-static int p9_adu_putmem(struct adu *adu, uint64_t addr, uint64_t data, int size,
+static int p9_adu_putmem(struct mem *adu, uint64_t addr, uint64_t data, int size,
 			 int ci, uint8_t block_size)
 {
 	uint64_t ctrl_reg, cmd_reg, val;
@@ -569,11 +569,11 @@ retry:
 	return 0;
 }
 
-static struct adu p8_adu = {
+static struct mem p8_adu = {
 	.target = {
 		.name =	"POWER8 ADU",
 		.compatible = "ibm,power8-adu",
-		.class = "adu",
+		.class = "mem",
 	},
 	.getmem = p8_adu_getmem,
 	.putmem = p8_adu_putmem,
@@ -582,11 +582,11 @@ static struct adu p8_adu = {
 };
 DECLARE_HW_UNIT(p8_adu);
 
-static struct adu p9_adu = {
+static struct mem p9_adu = {
 	.target = {
 		.name =	"POWER9 ADU",
 		.compatible = "ibm,power9-adu",
-		.class = "adu",
+		.class = "mem",
 	},
 	.getmem = p9_adu_getmem,
 	.putmem = p9_adu_putmem,
diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index 72fe570..4d23e82 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -782,7 +782,7 @@ static int __do_htm_start(struct htm *htm, bool wrap)
 	/*
 	 * Instead of the HTM_TRIG_START, this is where you might want
 	 * to call do_adu_magic()
-	 * for_each_child_target("adu", core, do_adu_magic, NULL, NULL);
+	 * for_each_child_target("mem", core, do_adu_magic, NULL, NULL);
 	 * see what I mean?
 	 */
 
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index 1bfb872..2618941 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -56,14 +56,14 @@ struct htm {
 };
 #define target_to_htm(x) container_of(x, struct htm, target)
 
-struct adu {
+struct mem {
 	struct pdbg_target target;
-	int (*getmem)(struct adu *, uint64_t, uint64_t *, int, uint8_t);
-	int (*putmem)(struct adu *, uint64_t, uint64_t, int, int, uint8_t);
-	int (*read)(struct adu *, uint64_t, uint8_t *, uint64_t, uint8_t, bool);
-	int (*write)(struct adu *, uint64_t, uint8_t *, uint64_t, uint8_t, bool);
+	int (*getmem)(struct mem *, uint64_t, uint64_t *, int, uint8_t);
+	int (*putmem)(struct mem *, uint64_t, uint64_t, int, int, uint8_t);
+	int (*read)(struct mem *, uint64_t, uint8_t *, uint64_t, uint8_t, bool);
+	int (*write)(struct mem *, uint64_t, uint8_t *, uint64_t, uint8_t, bool);
 };
-#define target_to_adu(x) container_of(x, struct adu, target)
+#define target_to_mem(x) container_of(x, struct mem, target)
 
 struct sbefifo {
 	struct pdbg_target target;
@@ -151,4 +151,3 @@ struct xbus {
 #define target_to_xbus(x) container_of(x, struct xbus, target)
 
 #endif /* __HWUNIT_H */
-
diff --git a/libpdbg/target.c b/libpdbg/target.c
index 9edc0bc..8880bf3 100644
--- a/libpdbg/target.c
+++ b/libpdbg/target.c
@@ -222,7 +222,7 @@ int mem_read(struct pdbg_target *target, uint64_t addr, uint8_t *output, uint64_
 	int rc = -1;
 
 	assert(pdbg_target_is_class(target, "sbefifo") ||
-	       pdbg_target_is_class(target, "adu"));
+	       pdbg_target_is_class(target, "mem"));
 
 	if (pdbg_target_is_class(target, "sbefifo")) {
 		struct sbefifo *sbefifo;
@@ -231,11 +231,11 @@ int mem_read(struct pdbg_target *target, uint64_t addr, uint8_t *output, uint64_
 		rc = sbefifo->mem_read(sbefifo, addr, output, size, ci);
 	}
 
-	if (pdbg_target_is_class(target, "adu")) {
-		struct adu *adu;
+	if (pdbg_target_is_class(target, "mem")) {
+		struct mem *mem;
 
-		adu = target_to_adu(target);
-		rc = adu->read(adu, addr, output, size, block_size, ci);
+		mem = target_to_mem(target);
+		rc = mem->read(mem, addr, output, size, block_size, ci);
 	}
 
 	return rc;
@@ -246,7 +246,7 @@ int mem_write(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_
 	int rc = -1;
 
 	assert(pdbg_target_is_class(target, "sbefifo") ||
-	       pdbg_target_is_class(target, "adu"));
+	       pdbg_target_is_class(target, "mem"));
 
 	if (pdbg_target_is_class(target, "sbefifo")) {
 		struct sbefifo *sbefifo;
@@ -255,11 +255,11 @@ int mem_write(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_
 		rc = sbefifo->mem_write(sbefifo, addr, input, size, ci);
 	}
 
-	if (pdbg_target_is_class(target, "adu")) {
-		struct adu *adu;
+	if (pdbg_target_is_class(target, "mem")) {
+		struct mem *mem;
 
-		adu = target_to_adu(target);
-		rc = adu->write(adu, addr, input, size, block_size, ci);
+		mem = target_to_mem(target);
+		rc = mem->write(mem, addr, input, size, block_size, ci);
 	}
 
 	return rc;
diff --git a/src/mem.c b/src/mem.c
index 0b8ad7e..cacd394 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -112,7 +112,7 @@ static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size, bool ci, bo
 		goto done;
 	}
 
-	pdbg_for_each_class_target("adu", target) {
+	pdbg_for_each_class_target("mem", target) {
 		if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
 			continue;
 
@@ -205,7 +205,7 @@ static int _putmem(uint64_t addr, uint8_t block_size, bool ci)
 		goto done;
 	}
 
-	pdbg_for_each_class_target("adu", target) {
+	pdbg_for_each_class_target("mem", target) {
 		if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
 			continue;
 
diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c
index 5bba03f..4177f01 100644
--- a/src/pdbgproxy.c
+++ b/src/pdbgproxy.c
@@ -532,7 +532,7 @@ static int gdbserver(uint16_t port)
 	littleendian = 0x01 & msr;
 
 	/* Select ADU target */
-	pdbg_for_each_class_target("adu", adu) {
+	pdbg_for_each_class_target("mem", adu) {
 		if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED)
 			break;
 	}
diff --git a/src/thread.c b/src/thread.c
index 7fd53a8..e44ad42 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -340,7 +340,7 @@ static int thread_regs_print(struct reg_flags flags)
 		if (flags.do_backtrace) {
 			struct pdbg_target *adu;
 
-			pdbg_for_each_class_target("adu", adu) {
+			pdbg_for_each_class_target("mem", adu) {
 				if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) {
 					dump_stack(&regs, adu);
 					break;
-- 
2.20.1



More information about the Pdbg mailing list