1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
7 /* CPU specific code */
11 #include <asm/cache.h>
14 #define CSR_MCACHE_CTL 0x7ca
15 #define CSR_MMISC_CTL 0x7d0
16 #define CSR_MARCHID 0xf12
18 #define V5_MCACHE_CTL_IC_EN_OFFSET 0
19 #define V5_MCACHE_CTL_DC_EN_OFFSET 1
20 #define V5_MCACHE_CTL_CCTL_SUEN_OFFSET 8
21 #define V5_MCACHE_CTL_DC_COHEN_OFFSET 19
22 #define V5_MCACHE_CTL_DC_COHSTA_OFFSET 20
24 #define V5_MCACHE_CTL_IC_EN BIT(V5_MCACHE_CTL_IC_EN_OFFSET)
25 #define V5_MCACHE_CTL_DC_EN BIT(V5_MCACHE_CTL_DC_EN_OFFSET)
26 #define V5_MCACHE_CTL_CCTL_SUEN BIT(V5_MCACHE_CTL_CCTL_SUEN_OFFSET)
27 #define V5_MCACHE_CTL_DC_COHEN_EN BIT(V5_MCACHE_CTL_DC_COHEN_OFFSET)
28 #define V5_MCACHE_CTL_DC_COHSTA_EN BIT(V5_MCACHE_CTL_DC_COHSTA_OFFSET)
32 * cleanup_before_linux() is called just before we call linux
33 * it prepares the processor for linux
35 * we disable interrupt and caches.
37 int cleanup_before_linux(void)
41 /* turn off I/D-cache */
49 void harts_early_init(void)
51 if (CONFIG_IS_ENABLED(RISCV_MMODE)) {
52 unsigned long long mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
54 if (!(mcache_ctl_val & V5_MCACHE_CTL_DC_COHEN_EN))
55 mcache_ctl_val |= V5_MCACHE_CTL_DC_COHEN_EN;
56 if (!(mcache_ctl_val & V5_MCACHE_CTL_IC_EN))
57 mcache_ctl_val |= V5_MCACHE_CTL_IC_EN;
58 if (!(mcache_ctl_val & V5_MCACHE_CTL_DC_EN))
59 mcache_ctl_val |= V5_MCACHE_CTL_DC_EN;
60 if (!(mcache_ctl_val & V5_MCACHE_CTL_CCTL_SUEN))
61 mcache_ctl_val |= V5_MCACHE_CTL_CCTL_SUEN;
62 csr_write(CSR_MCACHE_CTL, mcache_ctl_val);
65 * Check DC_COHEN_EN, if cannot write to mcache_ctl,
66 * we assume this bitmap not support L2 CM
68 mcache_ctl_val = csr_read(CSR_MCACHE_CTL);
69 if ((mcache_ctl_val & V5_MCACHE_CTL_DC_COHEN_EN)) {
70 /* Wait for DC_COHSTA bit be set */
71 while (!(mcache_ctl_val & V5_MCACHE_CTL_DC_COHSTA_EN))
72 mcache_ctl_val = csr_read(CSR_MCACHE_CTL);