platform: andes: Factor out is_andes() helper
authorYu Chien Peter Lin <peterlin@andestech.com>
Thu, 30 Nov 2023 12:42:09 +0000 (20:42 +0800)
committerAnup Patel <anup@brainfault.org>
Wed, 6 Dec 2023 12:33:12 +0000 (18:03 +0530)
We will need is_andes(45) in the following patch,
so factor out the code that parses marchid to make
it reusable for checking any Andes CPU variants.

Also improves the comment in ae350_hart_start().

Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
platform/generic/andes/ae350.c
platform/generic/include/andes/andes45.h

index dc769b7266665279ca2ebc0c609b0704f9a6cf22..088ec077b58ed023a4ff109e4ca5958defbe2f7b 100644 (file)
@@ -24,16 +24,14 @@ static struct smu_data smu = { 0 };
 extern void __ae350_enable_coherency_warmboot(void);
 extern void __ae350_disable_coherency(void);
 
-static __always_inline bool is_andes25(void)
-{
-       ulong marchid = csr_read(CSR_MARCHID);
-       return !!(EXTRACT_FIELD(marchid, CSR_MARCHID_MICROID) == 0xa25);
-}
-
 static int ae350_hart_start(u32 hartid, ulong saddr)
 {
-       /* Don't send wakeup command at boot-time */
-       if (!sbi_init_count(hartid) || (is_andes25() && hartid == 0))
+       /*
+        * Don't send wakeup command when:
+        * 1) boot-time
+        * 2) the target hart is non-sleepable 25-series hart0
+        */
+       if (!sbi_init_count(hartid) || (is_andes(25) && hartid == 0))
                return sbi_ipi_raw_send(sbi_hartid_to_hartindex(hartid));
 
        /* Write wakeup command to the sleep hart */
@@ -52,7 +50,7 @@ static int ae350_hart_stop(void)
         * L2-cache, instead of turning it off, it should fall
         * through and jump to warmboot_addr.
         */
-       if (is_andes25() && hartid == 0)
+       if (is_andes(25) && hartid == 0)
                return SBI_ENOTSUPP;
 
        if (!smu_support_sleep_mode(&smu, DEEPSLEEP_MODE, hartid))
index ce31617c5ec35b015626879832f29ac4061a5bdc..01f63d444ea3ba9e48dfbd1be8146472a139d94c 100644 (file)
 
 #ifndef __ASSEMBLER__
 
+#define is_andes(series)                               \
+({                                                     \
+       char value = csr_read(CSR_MARCHID) & 0xff;      \
+       (series) == (value >> 4) * 10 + (value & 0x0f); \
+})
+
 #define has_andes_pmu()                                        \
 ({                                                     \
        (((csr_read(CSR_MMSC_CFG) &                     \