Skip to content

Commit 74ce0f3

Browse files
Krystian Pradzynskisgruszka
authored andcommitted
accel/ivpu: Fix verbose version of REG_POLL macros
Remove two out of four _POLL macros. For two remaining _POLL macros add message about polling register start and finish. Additionally avoid inconsequence when using REGV_WR/RD macros in MMU code - passing raw register offset instead of register name. Signed-off-by: Krystian Pradzynski <[email protected]> Reviewed-by: Stanislaw Gruszka <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Signed-off-by: Stanislaw Gruszka <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 276e483 commit 74ce0f3

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

drivers/accel/ivpu/ivpu_hw_reg_io.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,30 @@
4747
#define REG_TEST_FLD_NUM(REG, FLD, num, val) \
4848
((num) == FIELD_GET(REG##_##FLD##_MASK, val))
4949

50-
#define REGB_POLL(reg, var, cond, timeout_us) \
51-
read_poll_timeout(REGB_RD32_SILENT, var, cond, REG_POLL_SLEEP_US, timeout_us, false, reg)
52-
53-
#define REGV_POLL(reg, var, cond, timeout_us) \
54-
read_poll_timeout(REGV_RD32_SILENT, var, cond, REG_POLL_SLEEP_US, timeout_us, false, reg)
55-
5650
#define REGB_POLL_FLD(reg, fld, val, timeout_us) \
5751
({ \
5852
u32 var; \
59-
REGB_POLL(reg, var, (FIELD_GET(reg##_##fld##_MASK, var) == (val)), timeout_us); \
53+
int r; \
54+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) Polling field %s started (expected 0x%x)\n", \
55+
__func__, #reg, reg, #fld, val); \
56+
r = read_poll_timeout(REGB_RD32_SILENT, var, (FIELD_GET(reg##_##fld##_MASK, var) == (val)),\
57+
REG_POLL_SLEEP_US, timeout_us, false, (reg)); \
58+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) Polling field %s %s (reg val 0x%08x)\n", \
59+
__func__, #reg, reg, #fld, r ? "ETIMEDOUT" : "OK", var); \
60+
r; \
6061
})
6162

6263
#define REGV_POLL_FLD(reg, fld, val, timeout_us) \
6364
({ \
6465
u32 var; \
65-
REGV_POLL(reg, var, (FIELD_GET(reg##_##fld##_MASK, var) == (val)), timeout_us); \
66+
int r; \
67+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) Polling field %s started (expected 0x%x)\n", \
68+
__func__, #reg, reg, #fld, val); \
69+
r = read_poll_timeout(REGV_RD32_SILENT, var, (FIELD_GET(reg##_##fld##_MASK, var) == (val)),\
70+
REG_POLL_SLEEP_US, timeout_us, false, (reg)); \
71+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) Polling field %s %s (reg val 0x%08x)\n", \
72+
__func__, #reg, reg, #fld, r ? "ETIMEDOUT" : "OK", var); \
73+
r; \
6674
})
6775

6876
static inline u32
@@ -71,7 +79,7 @@ ivpu_hw_reg_rd32(struct ivpu_device *vdev, void __iomem *base, u32 reg,
7179
{
7280
u32 val = readl(base + reg);
7381

74-
ivpu_dbg(vdev, REG, "%s RD: %s (0x%08x) => 0x%08x\n", func, name, reg, val);
82+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) RD: 0x%08x\n", func, name, reg, val);
7583
return val;
7684
}
7785

@@ -81,23 +89,23 @@ ivpu_hw_reg_rd64(struct ivpu_device *vdev, void __iomem *base, u32 reg,
8189
{
8290
u64 val = readq(base + reg);
8391

84-
ivpu_dbg(vdev, REG, "%s RD: %s (0x%08x) => 0x%016llx\n", func, name, reg, val);
92+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) RD: 0x%016llx\n", func, name, reg, val);
8593
return val;
8694
}
8795

8896
static inline void
8997
ivpu_hw_reg_wr32(struct ivpu_device *vdev, void __iomem *base, u32 reg, u32 val,
9098
const char *name, const char *func)
9199
{
92-
ivpu_dbg(vdev, REG, "%s WR: %s (0x%08x) <= 0x%08x\n", func, name, reg, val);
100+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) WR: 0x%08x\n", func, name, reg, val);
93101
writel(val, base + reg);
94102
}
95103

96104
static inline void
97105
ivpu_hw_reg_wr64(struct ivpu_device *vdev, void __iomem *base, u32 reg, u64 val,
98106
const char *name, const char *func)
99107
{
100-
ivpu_dbg(vdev, REG, "%s WR: %s (0x%08x) <= 0x%016llx\n", func, name, reg, val);
108+
ivpu_dbg(vdev, REG, "%s : %s (0x%08x) WR: 0x%016llx\n", func, name, reg, val);
101109
writeq(val, base + reg);
102110
}
103111

drivers/accel/ivpu/ivpu_mmu.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#define IVPU_MMU_REG_IDR5 0x00200014u
1919
#define IVPU_MMU_REG_CR0 0x00200020u
2020
#define IVPU_MMU_REG_CR0ACK 0x00200024u
21+
#define IVPU_MMU_REG_CR0ACK_VAL_MASK GENMASK(31, 0)
2122
#define IVPU_MMU_REG_CR1 0x00200028u
2223
#define IVPU_MMU_REG_CR2 0x0020002cu
2324
#define IVPU_MMU_REG_IRQ_CTRL 0x00200050u
2425
#define IVPU_MMU_REG_IRQ_CTRLACK 0x00200054u
26+
#define IVPU_MMU_REG_IRQ_CTRLACK_VAL_MASK GENMASK(31, 0)
2527

2628
#define IVPU_MMU_REG_GERROR 0x00200060u
2729
#define IVPU_MMU_REG_GERROR_CMDQ_MASK BIT_MASK(0)
@@ -39,12 +41,13 @@
3941
#define IVPU_MMU_REG_CMDQ_BASE 0x00200090u
4042
#define IVPU_MMU_REG_CMDQ_PROD 0x00200098u
4143
#define IVPU_MMU_REG_CMDQ_CONS 0x0020009cu
44+
#define IVPU_MMU_REG_CMDQ_CONS_VAL_MASK GENMASK(23, 0)
45+
#define IVPU_MMU_REG_CMDQ_CONS_ERR_MASK GENMASK(30, 24)
4246
#define IVPU_MMU_REG_EVTQ_BASE 0x002000a0u
4347
#define IVPU_MMU_REG_EVTQ_PROD 0x002000a8u
4448
#define IVPU_MMU_REG_EVTQ_CONS 0x002000acu
4549
#define IVPU_MMU_REG_EVTQ_PROD_SEC (0x002000a8u + SZ_64K)
4650
#define IVPU_MMU_REG_EVTQ_CONS_SEC (0x002000acu + SZ_64K)
47-
#define IVPU_MMU_REG_CMDQ_CONS_ERR_MASK GENMASK(30, 24)
4851

4952
#define IVPU_MMU_IDR0_REF 0x080f3e0f
5053
#define IVPU_MMU_IDR0_REF_SIMICS 0x080f3e1f
@@ -409,39 +412,45 @@ static int ivpu_mmu_structs_alloc(struct ivpu_device *vdev)
409412
return ret;
410413
}
411414

412-
static int ivpu_mmu_reg_write(struct ivpu_device *vdev, u32 reg, u32 val)
415+
static int ivpu_mmu_reg_write_cr0(struct ivpu_device *vdev, u32 val)
413416
{
414-
u32 reg_ack = reg + 4; /* ACK register is 4B after base register */
415-
u32 val_ack;
416-
int ret;
417+
REGV_WR32(IVPU_MMU_REG_CR0, val);
417418

418-
REGV_WR32(reg, val);
419+
return REGV_POLL_FLD(IVPU_MMU_REG_CR0ACK, VAL, val, IVPU_MMU_REG_TIMEOUT_US);
420+
}
419421

420-
ret = REGV_POLL(reg_ack, val_ack, (val == val_ack), IVPU_MMU_REG_TIMEOUT_US);
421-
if (ret)
422-
ivpu_err(vdev, "Failed to write register 0x%x\n", reg);
422+
static int ivpu_mmu_reg_write_irq_ctrl(struct ivpu_device *vdev, u32 val)
423+
{
424+
REGV_WR32(IVPU_MMU_REG_IRQ_CTRL, val);
423425

424-
return ret;
426+
return REGV_POLL_FLD(IVPU_MMU_REG_IRQ_CTRLACK, VAL, val, IVPU_MMU_REG_TIMEOUT_US);
425427
}
426428

427429
static int ivpu_mmu_irqs_setup(struct ivpu_device *vdev)
428430
{
429431
u32 irq_ctrl = IVPU_MMU_IRQ_EVTQ_EN | IVPU_MMU_IRQ_GERROR_EN;
430432
int ret;
431433

432-
ret = ivpu_mmu_reg_write(vdev, IVPU_MMU_REG_IRQ_CTRL, 0);
434+
ret = ivpu_mmu_reg_write_irq_ctrl(vdev, 0);
433435
if (ret)
434436
return ret;
435437

436-
return ivpu_mmu_reg_write(vdev, IVPU_MMU_REG_IRQ_CTRL, irq_ctrl);
438+
return ivpu_mmu_reg_write_irq_ctrl(vdev, irq_ctrl);
437439
}
438440

439441
static int ivpu_mmu_cmdq_wait_for_cons(struct ivpu_device *vdev)
440442
{
441443
struct ivpu_mmu_queue *cmdq = &vdev->mmu->cmdq;
444+
int ret;
445+
446+
ret = REGV_POLL_FLD(IVPU_MMU_REG_CMDQ_CONS, VAL, cmdq->prod,
447+
IVPU_MMU_QUEUE_TIMEOUT_US);
448+
if (ret)
449+
return ret;
450+
451+
cmdq->cons = cmdq->prod;
442452

443-
return REGV_POLL(IVPU_MMU_REG_CMDQ_CONS, cmdq->cons, (cmdq->prod == cmdq->cons),
444-
IVPU_MMU_QUEUE_TIMEOUT_US);
453+
return 0;
445454
}
446455

447456
static int ivpu_mmu_cmdq_cmd_write(struct ivpu_device *vdev, const char *name, u64 data0, u64 data1)
@@ -528,7 +537,7 @@ static int ivpu_mmu_reset(struct ivpu_device *vdev)
528537
mmu->evtq.prod = 0;
529538
mmu->evtq.cons = 0;
530539

531-
ret = ivpu_mmu_reg_write(vdev, IVPU_MMU_REG_CR0, 0);
540+
ret = ivpu_mmu_reg_write_cr0(vdev, 0);
532541
if (ret)
533542
return ret;
534543

@@ -548,7 +557,7 @@ static int ivpu_mmu_reset(struct ivpu_device *vdev)
548557
REGV_WR32(IVPU_MMU_REG_CMDQ_CONS, 0);
549558

550559
val = IVPU_MMU_CR0_CMDQEN;
551-
ret = ivpu_mmu_reg_write(vdev, IVPU_MMU_REG_CR0, val);
560+
ret = ivpu_mmu_reg_write_cr0(vdev, val);
552561
if (ret)
553562
return ret;
554563

@@ -569,12 +578,12 @@ static int ivpu_mmu_reset(struct ivpu_device *vdev)
569578
REGV_WR32(IVPU_MMU_REG_EVTQ_CONS_SEC, 0);
570579

571580
val |= IVPU_MMU_CR0_EVTQEN;
572-
ret = ivpu_mmu_reg_write(vdev, IVPU_MMU_REG_CR0, val);
581+
ret = ivpu_mmu_reg_write_cr0(vdev, val);
573582
if (ret)
574583
return ret;
575584

576585
val |= IVPU_MMU_CR0_ATSCHK;
577-
ret = ivpu_mmu_reg_write(vdev, IVPU_MMU_REG_CR0, val);
586+
ret = ivpu_mmu_reg_write_cr0(vdev, val);
578587
if (ret)
579588
return ret;
580589

@@ -583,7 +592,7 @@ static int ivpu_mmu_reset(struct ivpu_device *vdev)
583592
return ret;
584593

585594
val |= IVPU_MMU_CR0_SMMUEN;
586-
return ivpu_mmu_reg_write(vdev, IVPU_MMU_REG_CR0, val);
595+
return ivpu_mmu_reg_write_cr0(vdev, val);
587596
}
588597

589598
static void ivpu_mmu_strtab_link_cd(struct ivpu_device *vdev, u32 sid)

0 commit comments

Comments
 (0)