[Pdbg] [PATCH 2/8] libpdbg: Move hardware units to a separate header

Amitay Isaacs amitay at ozlabs.org
Thu Jun 13 13:24:10 AEST 2019


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 Makefile.am      |   1 +
 libpdbg/adu.c    |   1 +
 libpdbg/bmcfsi.c |   2 +-
 libpdbg/cfam.c   |   2 +-
 libpdbg/chip.c   |   2 +-
 libpdbg/device.c |   1 +
 libpdbg/fake.c   |   1 +
 libpdbg/host.c   |   2 +-
 libpdbg/htm.c    |   2 +-
 libpdbg/hwunit.h | 138 +++++++++++++++++++++++++++++++++++++++++++++++
 libpdbg/i2c.c    |   1 +
 libpdbg/kernel.c |   2 +-
 libpdbg/p8chip.c |   2 +-
 libpdbg/p9chip.c |   2 +-
 libpdbg/target.c |   2 +-
 libpdbg/target.h | 113 --------------------------------------
 libpdbg/xbus.c   |   2 +-
 src/pdbgproxy.c  |   2 +-
 18 files changed, 154 insertions(+), 124 deletions(-)
 create mode 100644 libpdbg/hwunit.h

diff --git a/Makefile.am b/Makefile.am
index f1e06f6..707df6b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -159,6 +159,7 @@ libpdbg_la_SOURCES = \
 	libpdbg/fake.c \
 	libpdbg/host.c \
 	libpdbg/htm.c \
+	libpdbg/hwunit.h \
 	libpdbg/i2c.c \
 	libpdbg/kernel.c \
 	libpdbg/libpdbg.c \
diff --git a/libpdbg/adu.c b/libpdbg/adu.c
index 650ec6b..5eeb249 100644
--- a/libpdbg/adu.c
+++ b/libpdbg/adu.c
@@ -21,6 +21,7 @@
 #include "operations.h"
 #include "bitutils.h"
 #include "debug.h"
+#include "hwunit.h"
 
 /* P8 ADU SCOM Register Definitions */
 #define P8_ALTD_CONTROL_REG	0x0
diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c
index f9cee3d..a4fb04c 100644
--- a/libpdbg/bmcfsi.c
+++ b/libpdbg/bmcfsi.c
@@ -27,7 +27,7 @@
 
 #include "bitutils.h"
 #include "operations.h"
-#include "target.h"
+#include "hwunit.h"
 #include "debug.h"
 
 #define GPIO_BASE	0x1e780000
diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c
index c9bdf3b..3f30549 100644
--- a/libpdbg/cfam.c
+++ b/libpdbg/cfam.c
@@ -19,7 +19,7 @@
 #include <stdio.h>
 #include <inttypes.h>
 
-#include "target.h"
+#include "hwunit.h"
 #include "bitutils.h"
 #include "operations.h"
 #include "debug.h"
diff --git a/libpdbg/chip.c b/libpdbg/chip.c
index 5b67c7b..10630fb 100644
--- a/libpdbg/chip.c
+++ b/libpdbg/chip.c
@@ -21,7 +21,7 @@
 #include <ccan/array_size/array_size.h>
 #include <unistd.h>
 
-#include "target.h"
+#include "hwunit.h"
 #include "operations.h"
 #include "bitutils.h"
 #include "debug.h"
diff --git a/libpdbg/device.c b/libpdbg/device.c
index 3dc301f..6a60676 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -27,6 +27,7 @@
 
 #include "debug.h"
 #include "compiler.h"
+#include "hwunit.h"
 
 #define prerror printf
 #define is_rodata(p) false
diff --git a/libpdbg/fake.c b/libpdbg/fake.c
index a816ff5..fb7ab97 100644
--- a/libpdbg/fake.c
+++ b/libpdbg/fake.c
@@ -18,6 +18,7 @@
 
 #include "libpdbg.h"
 #include "operations.h"
+#include "hwunit.h"
 
 static int fake_fsi_read(struct fsi *fsi, uint32_t addr, uint32_t *value)
 {
diff --git a/libpdbg/host.c b/libpdbg/host.c
index 163b991..60ccc55 100644
--- a/libpdbg/host.c
+++ b/libpdbg/host.c
@@ -32,7 +32,7 @@
 
 #include "bitutils.h"
 #include "operations.h"
-#include "target.h"
+#include "hwunit.h"
 
 #define XSCOM_BASE_PATH "/sys/kernel/debug/powerpc/scom"
 
diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index 4a326d2..39ab883 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -27,7 +27,7 @@
 
 #include "operations.h"
 #include "bitutils.h"
-#include "target.h"
+#include "hwunit.h"
 #include "debug.h"
 
 #define HTM_ERR(x) ({int rc = (x); if (rc) {PR_ERROR("HTM Error %d %s:%d\n", \
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
new file mode 100644
index 0000000..7a0df6a
--- /dev/null
+++ b/libpdbg/hwunit.h
@@ -0,0 +1,138 @@
+/* Copyright 2019 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __HWUNIT_H
+#define __HWUNIT_H
+
+#include <stdint.h>
+
+#include "target.h"
+
+/* This works and should be safe because struct pdbg_target is guaranteed to be
+ * the first member of the specialised type (see the DECLARE_HW_UNIT definition
+ * below). I'm not sure how sane it is though. Probably not very but it does
+ * remove a bunch of tedious container_of() typing */
+#define translate_cast(x) (uint64_t (*)(struct pdbg_target *, uint64_t)) (x)
+
+struct hw_unit_info {
+	void *hw_unit;
+	size_t size;
+};
+struct hw_unit_info *find_compatible_target(const char *compat);
+
+/* We can't pack the structs themselves directly into a special
+ * section because there doesn't seem to be any standard way of doing
+ * that due to alignment rules. So instead we pack pointers into a
+ * special section.
+ *
+ * If this macro fails to compile for you, you've probably not
+ * declared the struct pdbg_target as the first member of the
+ * container struct. Not doing so will break other assumptions.
+ * */
+#define DECLARE_HW_UNIT(name)						\
+	static inline void name ##_hw_unit_check(void) {		\
+		((void)sizeof(char[1 - 2 * (container_off(typeof(name), target) != 0)])); \
+	}								\
+	const struct hw_unit_info __used name ##_hw_unit =              \
+	{ .hw_unit = &name, .size = sizeof(name) }; 	                \
+	const struct hw_unit_info __used __section("hw_units") *name ##_hw_unit_p = &name ##_hw_unit
+
+struct htm {
+	struct pdbg_target target;
+	int (*start)(struct htm *);
+	int (*stop)(struct htm *);
+	int (*status)(struct htm *);
+	int (*dump)(struct htm *, char *);
+	int (*record)(struct htm *, char *);
+};
+#define target_to_htm(x) container_of(x, struct htm, target)
+
+struct adu {
+	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);
+};
+#define target_to_adu(x) container_of(x, struct adu, target)
+
+struct pib {
+	struct pdbg_target target;
+	int (*read)(struct pib *, uint64_t, uint64_t *);
+	int (*write)(struct pib *, uint64_t, uint64_t);
+	void *priv;
+};
+#define target_to_pib(x) container_of(x, struct pib, target)
+
+struct opb {
+	struct pdbg_target target;
+	int (*read)(struct opb *, uint32_t, uint32_t *);
+	int (*write)(struct opb *, uint32_t, uint32_t);
+};
+#define target_to_opb(x) container_of(x, struct opb, target)
+
+struct fsi {
+	struct pdbg_target target;
+	int (*read)(struct fsi *, uint32_t, uint32_t *);
+	int (*write)(struct fsi *, uint32_t, uint32_t);
+	enum chip_type chip_type;
+};
+#define target_to_fsi(x) container_of(x, struct fsi, target)
+
+struct core {
+	struct pdbg_target target;
+	bool release_spwkup;
+};
+#define target_to_core(x) container_of(x, struct core, target)
+
+struct thread {
+	struct pdbg_target target;
+	struct thread_state status;
+	int id;
+	int (*step)(struct thread *, int);
+	int (*start)(struct thread *);
+	int (*stop)(struct thread *);
+	int (*sreset)(struct thread *);
+
+	bool ram_did_quiesce; /* was the thread quiesced by ram mode */
+
+	/* ram_setup() should be called prior to using ram_instruction() to
+	 * actually ram the instruction and return the result. ram_destroy()
+	 * should be called at completion to clean-up. */
+	bool ram_is_setup;
+	int (*ram_setup)(struct thread *);
+	int (*ram_instruction)(struct thread *, uint64_t opcode, uint64_t *scratch);
+	int (*ram_destroy)(struct thread *);
+	int (*ram_getxer)(struct pdbg_target *, uint64_t *value);
+	int (*ram_putxer)(struct pdbg_target *, uint64_t value);
+	int (*enable_attn)(struct pdbg_target *);
+};
+#define target_to_thread(x) container_of(x, struct thread, target)
+
+/* Place holder for chiplets which we just want translation for */
+struct chiplet {
+        struct pdbg_target target;
+	int (*getring)(struct chiplet *, uint64_t, int64_t, uint32_t[]);
+};
+#define target_to_chiplet(x) container_of(x, struct chiplet, target)
+
+struct xbus {
+	struct pdbg_target target;
+	uint32_t ring_id;
+};
+#define target_to_xbus(x) container_of(x, struct xbus, target)
+
+#endif /* __HWUNIT_H */
+
diff --git a/libpdbg/i2c.c b/libpdbg/i2c.c
index f1c6ea9..48b4c95 100644
--- a/libpdbg/i2c.c
+++ b/libpdbg/i2c.c
@@ -26,6 +26,7 @@
 #include "bitutils.h"
 #include "operations.h"
 #include "debug.h"
+#include "hwunit.h"
 
 struct i2c_data {
 	int addr;
diff --git a/libpdbg/kernel.c b/libpdbg/kernel.c
index 8b597ef..956cbdc 100644
--- a/libpdbg/kernel.c
+++ b/libpdbg/kernel.c
@@ -28,7 +28,7 @@
 
 #include "bitutils.h"
 #include "operations.h"
-#include "target.h"
+#include "hwunit.h"
 
 #define FSI_SCAN_PATH "/sys/bus/platform/devices/gpio-fsi/fsi0/rescan"
 #define FSI_CFAM_PATH "/sys/devices/platform/gpio-fsi/fsi0/slave at 00:00/raw"
diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c
index 1202caa..024a0bf 100644
--- a/libpdbg/p8chip.c
+++ b/libpdbg/p8chip.c
@@ -21,7 +21,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 
-#include "target.h"
+#include "hwunit.h"
 #include "operations.h"
 #include "bitutils.h"
 #include "debug.h"
diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c
index 9d43725..f8d0ebf 100644
--- a/libpdbg/p9chip.c
+++ b/libpdbg/p9chip.c
@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 
-#include "target.h"
+#include "hwunit.h"
 #include "operations.h"
 #include "bitutils.h"
 #include "debug.h"
diff --git a/libpdbg/target.c b/libpdbg/target.c
index e678470..2ae50cb 100644
--- a/libpdbg/target.c
+++ b/libpdbg/target.c
@@ -6,7 +6,7 @@
 #include <libfdt/libfdt.h>
 
 #include "bitutils.h"
-#include "target.h"
+#include "hwunit.h"
 #include "operations.h"
 #include "debug.h"
 
diff --git a/libpdbg/target.h b/libpdbg/target.h
index 8360f26..233f085 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -58,120 +58,7 @@ struct pdbg_target_class *require_target_class(const char *name);
 struct pdbg_target_class *get_target_class(const char *name);
 bool pdbg_target_is_class(struct pdbg_target *target, const char *class);
 
-/* This works and should be safe because struct pdbg_target is guaranteed to be
- * the first member of the specialised type (see the DECLARE_HW_UNIT definition
- * below). I'm not sure how sane it is though. Probably not very but it does
- * remove a bunch of tedious container_of() typing */
-#define translate_cast(x) (uint64_t (*)(struct pdbg_target *, uint64_t)) (x)
-
 extern struct list_head empty_list;
 extern struct list_head target_classes;
 
-struct hw_unit_info {
-	void *hw_unit;
-	size_t size;
-};
-struct hw_unit_info *find_compatible_target(const char *compat);
-
-/* We can't pack the structs themselves directly into a special
- * section because there doesn't seem to be any standard way of doing
- * that due to alignment rules. So instead we pack pointers into a
- * special section.
- *
- * If this macro fails to compile for you, you've probably not
- * declared the struct pdbg_target as the first member of the
- * container struct. Not doing so will break other assumptions.
- * */
-#define DECLARE_HW_UNIT(name)						\
-	static inline void name ##_hw_unit_check(void) {		\
-		((void)sizeof(char[1 - 2 * (container_off(typeof(name), target) != 0)])); \
-	}								\
-	const struct hw_unit_info __used name ##_hw_unit =              \
-	{ .hw_unit = &name, .size = sizeof(name) }; 	                \
-	const struct hw_unit_info __used __section("hw_units") *name ##_hw_unit_p = &name ##_hw_unit
-
-struct htm {
-	struct pdbg_target target;
-	int (*start)(struct htm *);
-	int (*stop)(struct htm *);
-	int (*status)(struct htm *);
-	int (*dump)(struct htm *, char *);
-	int (*record)(struct htm *, char *);
-};
-#define target_to_htm(x) container_of(x, struct htm, target)
-
-struct adu {
-	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);
-};
-#define target_to_adu(x) container_of(x, struct adu, target)
-
-struct pib {
-	struct pdbg_target target;
-	int (*read)(struct pib *, uint64_t, uint64_t *);
-	int (*write)(struct pib *, uint64_t, uint64_t);
-	void *priv;
-};
-#define target_to_pib(x) container_of(x, struct pib, target)
-
-struct opb {
-	struct pdbg_target target;
-	int (*read)(struct opb *, uint32_t, uint32_t *);
-	int (*write)(struct opb *, uint32_t, uint32_t);
-};
-#define target_to_opb(x) container_of(x, struct opb, target)
-
-struct fsi {
-	struct pdbg_target target;
-	int (*read)(struct fsi *, uint32_t, uint32_t *);
-	int (*write)(struct fsi *, uint32_t, uint32_t);
-	enum chip_type chip_type;
-};
-#define target_to_fsi(x) container_of(x, struct fsi, target)
-
-struct core {
-	struct pdbg_target target;
-	bool release_spwkup;
-};
-#define target_to_core(x) container_of(x, struct core, target)
-
-struct thread {
-	struct pdbg_target target;
-	struct thread_state status;
-	int id;
-	int (*step)(struct thread *, int);
-	int (*start)(struct thread *);
-	int (*stop)(struct thread *);
-	int (*sreset)(struct thread *);
-
-	bool ram_did_quiesce; /* was the thread quiesced by ram mode */
-
-	/* ram_setup() should be called prior to using ram_instruction() to
-	 * actually ram the instruction and return the result. ram_destroy()
-	 * should be called at completion to clean-up. */
-	bool ram_is_setup;
-	int (*ram_setup)(struct thread *);
-	int (*ram_instruction)(struct thread *, uint64_t opcode, uint64_t *scratch);
-	int (*ram_destroy)(struct thread *);
-	int (*ram_getxer)(struct pdbg_target *, uint64_t *value);
-	int (*ram_putxer)(struct pdbg_target *, uint64_t value);
-	int (*enable_attn)(struct pdbg_target *);
-};
-#define target_to_thread(x) container_of(x, struct thread, target)
-
-/* Place holder for chiplets which we just want translation for */
-struct chiplet {
-        struct pdbg_target target;
-	int (*getring)(struct chiplet *, uint64_t, int64_t, uint32_t[]);
-};
-#define target_to_chiplet(x) container_of(x, struct chiplet, target)
-
-struct xbus {
-	struct pdbg_target target;
-	uint32_t ring_id;
-};
-#define target_to_xbus(x) container_of(x, struct xbus, target)
 #endif
diff --git a/libpdbg/xbus.c b/libpdbg/xbus.c
index 661b9a3..d36dab0 100644
--- a/libpdbg/xbus.c
+++ b/libpdbg/xbus.c
@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 
-#include "target.h"
+#include "hwunit.h"
 #include "bitutils.h"
 
 /* XBus addressing is more complicated. This comes from p9_scominfo.C
diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c
index 572af01..c340c56 100644
--- a/src/pdbgproxy.c
+++ b/src/pdbgproxy.c
@@ -16,8 +16,8 @@
 #include <errno.h>
 #include <ccan/array_size/array_size.h>
 
-#include <backend.h>
 #include <operations.h>
+#include <hwunit.h>
 
 #include "pdbgproxy.h"
 #include "main.h"
-- 
2.21.0



More information about the Pdbg mailing list