sw: Properly mask syscon register fields
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Thu, 4 Jun 2020 01:56:47 +0000 (11:56 +1000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 10 Jun 2020 03:10:57 +0000 (13:10 +1000)
Some fields might get extended with extra bits, use the appropriate
masks when reading the values.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
include/microwatt_soc.h
lib/console.c
litedram/gen-src/sdram_init/main.c

index 866ccb4cd30f902991fd8186a09feecdf48b250b..51c32664068b16ee6bf71c1c58ec06fb81e8eb86 100644 (file)
 #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)
index a75d9a09d11dd497577568bb29c74781b4d43a79..bce220e9f9eb1bceaf5667fecf9af3b3a6541ec7 100644 (file)
@@ -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));
 }
index 68eda1569cd4e1d97092d17b57ea7ad88e80a441..605906247f75baf9cc9e56ea761eaeb50db9ced4 100644 (file)
@@ -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");