From de67080fbe01164b3deaa26ea23c3ec1c5de2e0e Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 27 Jan 2021 18:03:40 -0800 Subject: [PATCH] qti: spmi_arb: Fix NUM_APID and REG_APID_MAP() argument The NUM_APID value was derived from kernel device tree sources, but I made a conversion mistake: the amount of bytes in the APID map is the total size of the "core" register range (0x1100) minus the offset of the APID map in that range (0x900). This is of course 0x1100 - 0x900 = 0x800 and not 0x200, so the amount of 4-byte integers it can fit is not 0x80 but 0x200. Fix this and make the math more explicit so it can be more easily factored out and adjusted if that becomes necessary for a future SoC. Also fix a dangerous typo in REG_APID_MAP() where the macro would reference a random variable `i` rather than its argument (`apid`), and we just got lucky that the only caller in the current code happened to pass in a variable called `i` as that argument. Signed-off-by: Julius Werner Change-Id: I049dd044fa5aeb65be0e7b12150afd6eb4bac0fa --- plat/qti/common/src/spmi_arb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plat/qti/common/src/spmi_arb.c b/plat/qti/common/src/spmi_arb.c index 16e85a6fc..4213ed1b3 100644 --- a/plat/qti/common/src/spmi_arb.c +++ b/plat/qti/common/src/spmi_arb.c @@ -10,8 +10,8 @@ #include -#define REG_APID_MAP(apid) (0x0C440900U + 4U * i) -#define NUM_APID 0x80 +#define REG_APID_MAP(apid) (0x0C440900U + sizeof(uint32_t) * apid) +#define NUM_APID ((0x1100U - 0x900U) / sizeof(uint32_t)) #define PPID_MASK (0xfffU << 8)