[v2,1/5] npu2: Create npu2_write_mcd()

Message ID 20171114112306.8191-1-mikey@neuling.org
State Accepted
Headers show
Series
  • [v2,1/5] npu2: Create npu2_write_mcd()
Related show

Commit Message

Michael Neuling Nov. 14, 2017, 11:23 a.m.
This code is replicated, so let's put it in a function. Also add some cleanups.

No functional change.

Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 hw/npu2.c           | 24 ++++++++++++++++--------
 include/npu2-regs.h |  3 +++
 2 files changed, 19 insertions(+), 8 deletions(-)

Comments

Stewart Smith Nov. 15, 2017, 8:35 a.m. | #1
Michael Neuling <mikey@neuling.org> writes:
> This code is replicated, so let's put it in a function. Also add some cleanups.
>
> No functional change.
>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> ---
>  hw/npu2.c           | 24 ++++++++++++++++--------
>  include/npu2-regs.h |  3 +++
>  2 files changed, 19 insertions(+), 8 deletions(-)

Series merged to master as of c76636f3d73fbbc3a1f56ca085eb80f9e56d0411
and to 5.9.x as of 9b068ad820a870c203571548c9025455f0f3e8b8

Patch

diff --git a/hw/npu2.c b/hw/npu2.c
index 8fd6246bfb..773ac07bdf 100644
--- a/hw/npu2.c
+++ b/hw/npu2.c
@@ -845,6 +845,20 @@  static int64_t npu2_ioda_reset(struct phb *phb, bool purge)
 	return OPAL_SUCCESS;
 }
 
+static void npu2_write_mcd(struct npu2 *p, uint64_t pcb_addr, uint64_t addr,
+			   uint64_t size)
+{
+	uint64_t val;
+
+	NPU2DBG(p, "Setting MCD addr:%llx\n", pcb_addr);
+	assert(is_pow2(size));
+
+	val = MCD_BANK_CN_VALID;
+	val = SETFIELD(MCD_BANK_CN_SIZE, val, (size >> 25) - 1);
+	val = SETFIELD(MCD_BANK_CN_ADDR, val, addr >> 25);
+	xscom_write(p->chip_id, pcb_addr, val);
+}
+
 static void npu2_hw_init(struct npu2 *p)
 {
 	int i;
@@ -884,10 +898,7 @@  static void npu2_hw_init(struct npu2 *p)
 	/* Allocate the biggest chunk first as we assume gpu_max_addr has the
 	 * highest alignment. */
 	addr = gpu_max_addr - size;
-	val = PPC_BIT(0);
-	val = SETFIELD(PPC_BITMASK(13, 29), val, (size >> 25) - 1);
-	val = SETFIELD(PPC_BITMASK(33, 63), val, addr >> 25);
-	xscom_write(p->chip_id, MCD0_BANK0_CN3, val);
+	npu2_write_mcd(p, MCD0_BANK0_CN3, addr, size);
 	total_size -= size;
 	if (total_size) {
 	/* total_size was not a power of two, but the remainder should
@@ -896,10 +907,7 @@  static void npu2_hw_init(struct npu2 *p)
 		size = 1ull << ilog2(total_size);
 		addr -= size;
 		assert(addr <= gpu_min_addr);
-		val = PPC_BIT(0);
-		val = SETFIELD(PPC_BITMASK(13, 29), val, (size >> 25) - 1);
-		val = SETFIELD(PPC_BITMASK(33, 63), val, addr >> 25);
-		xscom_write(p->chip_id, MCD1_BANK0_CN3, val);
+		npu2_write_mcd(p, MCD1_BANK0_CN3, addr, size);
 	}
 }
 
diff --git a/include/npu2-regs.h b/include/npu2-regs.h
index 88ba7090b7..ab046acaf3 100644
--- a/include/npu2-regs.h
+++ b/include/npu2-regs.h
@@ -28,6 +28,9 @@  void npu2_write_mask(struct npu2 *p, uint64_t reg, uint64_t val, uint64_t mask);
  * code */
 #define MCD0_BANK0_CN3 0x301100d
 #define MCD1_BANK0_CN3 0x301140d
+#define	MCD_BANK_CN_VALID	PPC_BIT(0)
+#define	MCD_BANK_CN_SIZE	PPC_BITMASK(13,29)
+#define	MCD_BANK_CN_ADDR	PPC_BITMASK(33,63)
 
 #define NPU2_REG_OFFSET(stack, block, offset) \
 	(((stack) << 20) | ((block) << 16) | (offset))