Merge branch 'misc.namei' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-2.6-microblaze.git] / arch / arm64 / kvm / sys_regs.h
index 9d06214..cc0cc95 100644 (file)
 #ifndef __ARM64_KVM_SYS_REGS_LOCAL_H__
 #define __ARM64_KVM_SYS_REGS_LOCAL_H__
 
+#include <linux/bsearch.h>
+
+#define reg_to_encoding(x)                                             \
+       sys_reg((u32)(x)->Op0, (u32)(x)->Op1,                           \
+               (u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2)
+
 struct sys_reg_params {
        u8      Op0;
        u8      Op1;
@@ -21,6 +27,14 @@ struct sys_reg_params {
        bool    is_write;
 };
 
+#define esr_sys64_to_params(esr)                                               \
+       ((struct sys_reg_params){ .Op0 = ((esr) >> 20) & 3,                    \
+                                 .Op1 = ((esr) >> 14) & 0x7,                  \
+                                 .CRn = ((esr) >> 10) & 0xf,                  \
+                                 .CRm = ((esr) >> 1) & 0xf,                   \
+                                 .Op2 = ((esr) >> 17) & 0x7,                  \
+                                 .is_write = !((esr) & 1) })
+
 struct sys_reg_desc {
        /* Sysreg string for debug */
        const char *name;
@@ -152,6 +166,23 @@ static inline int cmp_sys_reg(const struct sys_reg_desc *i1,
        return i1->Op2 - i2->Op2;
 }
 
+static inline int match_sys_reg(const void *key, const void *elt)
+{
+       const unsigned long pval = (unsigned long)key;
+       const struct sys_reg_desc *r = elt;
+
+       return pval - reg_to_encoding(r);
+}
+
+static inline const struct sys_reg_desc *
+find_reg(const struct sys_reg_params *params, const struct sys_reg_desc table[],
+        unsigned int num)
+{
+       unsigned long pval = reg_to_encoding(params);
+
+       return __inline_bsearch((void *)pval, table, num, sizeof(table[0]), match_sys_reg);
+}
+
 const struct sys_reg_desc *find_reg_by_id(u64 id,
                                          struct sys_reg_params *params,
                                          const struct sys_reg_desc table[],