From 3167515069e6ca2e236781974af08c05a06a0f84 Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Thu, 4 Jun 2020 11:56:47 +1000 Subject: [PATCH] sw: Properly mask syscon register fields Some fields might get extended with extra bits, use the appropriate masks when reading the values. Signed-off-by: Benjamin Herrenschmidt --- include/microwatt_soc.h | 3 +++ lib/console.c | 2 +- litedram/gen-src/sdram_init/main.c | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/microwatt_soc.h b/include/microwatt_soc.h index 866ccb4..51c3266 100644 --- a/include/microwatt_soc.h +++ b/include/microwatt_soc.h @@ -25,8 +25,11 @@ #define SYS_REG_INFO_HAS_DRAM (1ull << 1) #define SYS_REG_INFO_HAS_BRAM (1ull << 2) #define SYS_REG_BRAMINFO 0x10 +#define SYS_REG_BRAMINFO_SIZE_MASK 0xfffffffffffffull #define SYS_REG_DRAMINFO 0x18 +#define SYS_REG_DRAMINFO_SIZE_MASK 0xfffffffffffffull #define SYS_REG_CLKINFO 0x20 +#define SYS_REG_CLKINFO_FREQ_MASK 0xffffffffffull #define SYS_REG_CTRL 0x28 #define SYS_REG_CTRL_DRAM_AT_0 (1ull << 0) #define SYS_REG_CTRL_CORE_RESET (1ull << 1) diff --git a/lib/console.c b/lib/console.c index a75d9a0..bce220e 100644 --- a/lib/console.c +++ b/lib/console.c @@ -75,7 +75,7 @@ void potato_uart_init(void) uint64_t proc_freq; potato_uart_base = UART_BASE; - proc_freq = readq(SYSCON_BASE + SYS_REG_CLKINFO); + proc_freq = readq(SYSCON_BASE + SYS_REG_CLKINFO) & SYS_REG_CLKINFO_FREQ_MASK; potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(proc_freq, UART_FREQ)); } diff --git a/litedram/gen-src/sdram_init/main.c b/litedram/gen-src/sdram_init/main.c index 68eda15..6059062 100644 --- a/litedram/gen-src/sdram_init/main.c +++ b/litedram/gen-src/sdram_init/main.c @@ -58,16 +58,16 @@ void main(void) printf("BRAM "); printf("\n"); if (ftr & SYS_REG_INFO_HAS_BRAM) { - val = readq(SYSCON_BASE + SYS_REG_BRAMINFO); + val = readq(SYSCON_BASE + SYS_REG_BRAMINFO) & SYS_REG_BRAMINFO_SIZE_MASK; printf(" BRAM: %lld KB\n", val / 1024); } if (ftr & SYS_REG_INFO_HAS_DRAM) { - val = readq(SYSCON_BASE + SYS_REG_DRAMINFO); + val = readq(SYSCON_BASE + SYS_REG_DRAMINFO) & SYS_REG_DRAMINFO_SIZE_MASK; printf(" DRAM: %lld MB\n", val / (1024 * 1024)); val = readq(SYSCON_BASE + SYS_REG_DRAMINITINFO); printf(" DRAM INIT: %lld KB\n", val / 1024); } - val = readq(SYSCON_BASE + SYS_REG_CLKINFO); + val = readq(SYSCON_BASE + SYS_REG_CLKINFO) & SYS_REG_CLKINFO_FREQ_MASK; printf(" CLK: %lld MHz\n", val / 1000000); printf("\n"); -- 2.30.2