xen/arm: cpufeature: Add helper to check constant caps
authorJulien Grall <julien.grall@arm.com>
Mon, 1 Oct 2018 12:46:37 +0000 (13:46 +0100)
committerStefano Stabellini <sstabellini@kernel.org>
Mon, 1 Oct 2018 20:45:15 +0000 (13:45 -0700)
Some capababilities are set right during boot and will never change
afterwards. At the moment, the function cpu_have_caps will check whether
the cap is enabled from the memory.

It is possible to avoid the load from the memory by using an
ALTERNATIVE. With that the check is just reduced to 1 instruction.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/include/asm-arm/cpufeature.h

index 3de6b543015633b1bd3a6c7f1f181663b27d12b4..c6cbc2ec845026859f62d6b0aebdd501a7abf5bd 100644 (file)
@@ -63,6 +63,18 @@ static inline bool cpus_have_cap(unsigned int num)
     return test_bit(num, cpu_hwcaps);
 }
 
+/* System capability check for constant cap */
+#define cpus_have_const_cap(num) ({                 \
+        bool __ret;                                 \
+                                                    \
+        asm volatile (ALTERNATIVE("mov %0, #0",     \
+                                  "mov %0, #1",     \
+                                  num)              \
+                      : "=r" (__ret));              \
+                                                    \
+        unlikely(__ret);                            \
+        })
+
 static inline void cpus_set_cap(unsigned int num)
 {
     if (num >= ARM_NCAPS)