KVM
Classes | Macros | Functions | Variables
sys_regs.h File Reference
#include <linux/bsearch.h>
Include dependency graph for sys_regs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  sys_reg_params
 
struct  sys_reg_desc
 

Macros

#define reg_to_encoding(x)
 
#define encoding_to_params(reg)
 
#define esr_sys64_to_params(esr)
 
#define esr_cp1x_32_to_params(esr)
 
#define REG_HIDDEN   (1 << 0) /* hidden from userspace and guest */
 
#define REG_HIDDEN_USER   (1 << 1) /* hidden from userspace only */
 
#define REG_RAZ   (1 << 2) /* RAZ from userspace and guest */
 
#define REG_USER_WI   (1 << 3) /* WI from userspace only */
 
#define AA32(_x)   .aarch32_map = AA32_##_x
 
#define Op0(_x)   .Op0 = _x
 
#define Op1(_x)   .Op1 = _x
 
#define CRn(_x)   .CRn = _x
 
#define CRm(_x)   .CRm = _x
 
#define Op2(_x)   .Op2 = _x
 
#define SYS_DESC(reg)
 

Functions

static __printf (2, 3) inline void print_sys_reg_msg(const struct sys_reg_params *p
 
static char va_start (va, fmt)
 
 kvm_pr_unimpl ("%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n", &(struct va_format){ fmt, &va }, p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" :"read")
 
 va_end (va)
 
static void print_sys_reg_instr (const struct sys_reg_params *p)
 
static bool ignore_write (struct kvm_vcpu *vcpu, const struct sys_reg_params *p)
 
static bool read_zero (struct kvm_vcpu *vcpu, struct sys_reg_params *p)
 
static u64 reset_unknown (struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 
static u64 reset_val (struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 
static unsigned int sysreg_visibility (const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 
static bool sysreg_hidden (const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 
static bool sysreg_hidden_user (const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 
static bool sysreg_visible_as_raz (const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 
static bool sysreg_user_write_ignore (const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 
static int cmp_sys_reg (const struct sys_reg_desc *i1, const struct sys_reg_desc *i2)
 
static int match_sys_reg (const void *key, const void *elt)
 
static const struct sys_reg_descfind_reg (const struct sys_reg_params *params, const struct sys_reg_desc table[], unsigned int num)
 
const struct sys_reg_descget_reg_by_id (u64 id, const struct sys_reg_desc table[], unsigned int num)
 
int kvm_arm_sys_reg_get_reg (struct kvm_vcpu *vcpu, const struct kvm_one_reg *)
 
int kvm_arm_sys_reg_set_reg (struct kvm_vcpu *vcpu, const struct kvm_one_reg *)
 
int kvm_sys_reg_get_user (struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg, const struct sys_reg_desc table[], unsigned int num)
 
int kvm_sys_reg_set_user (struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg, const struct sys_reg_desc table[], unsigned int num)
 

Variables

static char * fmt
 

Macro Definition Documentation

◆ AA32

#define AA32 (   _x)    .aarch32_map = AA32_##_x

Definition at line 236 of file sys_regs.h.

◆ CRm

#define CRm (   _x)    .CRm = _x

Definition at line 240 of file sys_regs.h.

◆ CRn

#define CRn (   _x)    .CRn = _x

Definition at line 239 of file sys_regs.h.

◆ encoding_to_params

#define encoding_to_params (   reg)
Value:
((struct sys_reg_params){ .Op0 = sys_reg_Op0(reg), \
.Op1 = sys_reg_Op1(reg), \
.CRn = sys_reg_CRn(reg), \
.CRm = sys_reg_CRm(reg), \
.Op2 = sys_reg_Op2(reg) })

Definition at line 30 of file sys_regs.h.

◆ esr_cp1x_32_to_params

#define esr_cp1x_32_to_params (   esr)
Value:
((struct sys_reg_params){ .Op1 = ((esr) >> 14) & 0x7, \
.CRn = ((esr) >> 10) & 0xf, \
.CRm = ((esr) >> 1) & 0xf, \
.Op2 = ((esr) >> 17) & 0x7, \
.is_write = !((esr) & 1) })

Definition at line 45 of file sys_regs.h.

◆ esr_sys64_to_params

#define esr_sys64_to_params (   esr)
Value:
((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) })

Definition at line 37 of file sys_regs.h.

◆ Op0

#define Op0 (   _x)    .Op0 = _x

Definition at line 237 of file sys_regs.h.

◆ Op1

#define Op1 (   _x)    .Op1 = _x

Definition at line 238 of file sys_regs.h.

◆ Op2

#define Op2 (   _x)    .Op2 = _x

Definition at line 241 of file sys_regs.h.

◆ REG_HIDDEN

#define REG_HIDDEN   (1 << 0) /* hidden from userspace and guest */

Definition at line 97 of file sys_regs.h.

◆ REG_HIDDEN_USER

#define REG_HIDDEN_USER   (1 << 1) /* hidden from userspace only */

Definition at line 98 of file sys_regs.h.

◆ REG_RAZ

#define REG_RAZ   (1 << 2) /* RAZ from userspace and guest */

Definition at line 99 of file sys_regs.h.

◆ reg_to_encoding

#define reg_to_encoding (   x)
Value:
sys_reg((u32)(x)->Op0, (u32)(x)->Op1, \
(u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2)
#define CRm(_x)
Definition: sys_regs.h:240
#define Op1(_x)
Definition: sys_regs.h:238
#define Op2(_x)
Definition: sys_regs.h:241
#define CRn(_x)
Definition: sys_regs.h:239
#define Op0(_x)
Definition: sys_regs.h:237

Definition at line 16 of file sys_regs.h.

◆ REG_USER_WI

#define REG_USER_WI   (1 << 3) /* WI from userspace only */

Definition at line 100 of file sys_regs.h.

◆ SYS_DESC

#define SYS_DESC (   reg)
Value:
.name = #reg, \
Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)), \
Op2(sys_reg_Op2(reg))

Definition at line 243 of file sys_regs.h.

Function Documentation

◆ __printf()

static __printf ( ,
 
) const
static

◆ cmp_sys_reg()

static int cmp_sys_reg ( const struct sys_reg_desc i1,
const struct sys_reg_desc i2 
)
inlinestatic

Definition at line 189 of file sys_regs.h.

191 {
192  BUG_ON(i1 == i2);
193  if (!i1)
194  return 1;
195  else if (!i2)
196  return -1;
197  if (i1->Op0 != i2->Op0)
198  return i1->Op0 - i2->Op0;
199  if (i1->Op1 != i2->Op1)
200  return i1->Op1 - i2->Op1;
201  if (i1->CRn != i2->CRn)
202  return i1->CRn - i2->CRn;
203  if (i1->CRm != i2->CRm)
204  return i1->CRm - i2->CRm;
205  return i1->Op2 - i2->Op2;
206 }
Here is the caller graph for this function:

◆ find_reg()

static const struct sys_reg_desc* find_reg ( const struct sys_reg_params params,
const struct sys_reg_desc  table[],
unsigned int  num 
)
inlinestatic

Definition at line 217 of file sys_regs.h.

219 {
220  unsigned long pval = reg_to_encoding(params);
221 
222  return __inline_bsearch((void *)pval, table, num, sizeof(table[0]), match_sys_reg);
223 }
#define reg_to_encoding(x)
Definition: sys_regs.h:16
static int match_sys_reg(const void *key, const void *elt)
Definition: sys_regs.h:208
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_reg_by_id()

const struct sys_reg_desc* get_reg_by_id ( u64  id,
const struct sys_reg_desc  table[],
unsigned int  num 
)

Definition at line 3528 of file sys_regs.c.

3531 {
3532  struct sys_reg_params params;
3533 
3534  if (!index_to_params(id, &params))
3535  return NULL;
3536 
3537  return find_reg(&params, table, num);
3538 }
static bool index_to_params(u64 id, struct sys_reg_params *params)
Definition: sys_regs.c:3499
static const struct sys_reg_desc * find_reg(const struct sys_reg_params *params, const struct sys_reg_desc table[], unsigned int num)
Definition: sys_regs.h:217
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ignore_write()

static bool ignore_write ( struct kvm_vcpu *  vcpu,
const struct sys_reg_params p 
)
inlinestatic

Definition at line 122 of file sys_regs.h.

124 {
125  return true;
126 }
Here is the caller graph for this function:

◆ kvm_arm_sys_reg_get_reg()

int kvm_arm_sys_reg_get_reg ( struct kvm_vcpu *  vcpu,
const struct kvm_one_reg *  reg 
)

Definition at line 3705 of file sys_regs.c.

3706 {
3707  void __user *uaddr = (void __user *)(unsigned long)reg->addr;
3708  int err;
3709 
3710  if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_DEMUX)
3711  return demux_c15_get(vcpu, reg->id, uaddr);
3712 
3713  err = get_invariant_sys_reg(reg->id, uaddr);
3714  if (err != -ENOENT)
3715  return err;
3716 
3717  return kvm_sys_reg_get_user(vcpu, reg,
3718  sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
3719 }
int kvm_sys_reg_get_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg, const struct sys_reg_desc table[], unsigned int num)
Definition: sys_regs.c:3680
static int get_invariant_sys_reg(u64 id, u64 __user *uaddr)
Definition: sys_regs.c:3595
static const struct sys_reg_desc sys_reg_descs[]
Definition: sys_regs.c:2188
static int demux_c15_get(struct kvm_vcpu *vcpu, u64 id, void __user *uaddr)
Definition: sys_regs.c:3627
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_arm_sys_reg_set_reg()

int kvm_arm_sys_reg_set_reg ( struct kvm_vcpu *  vcpu,
const struct kvm_one_reg *  reg 
)

Definition at line 3749 of file sys_regs.c.

3750 {
3751  void __user *uaddr = (void __user *)(unsigned long)reg->addr;
3752  int err;
3753 
3754  if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_DEMUX)
3755  return demux_c15_set(vcpu, reg->id, uaddr);
3756 
3757  err = set_invariant_sys_reg(reg->id, uaddr);
3758  if (err != -ENOENT)
3759  return err;
3760 
3761  return kvm_sys_reg_set_user(vcpu, reg,
3762  sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
3763 }
static int set_invariant_sys_reg(u64 id, u64 __user *uaddr)
Definition: sys_regs.c:3607
static int demux_c15_set(struct kvm_vcpu *vcpu, u64 id, void __user *uaddr)
Definition: sys_regs.c:3652
int kvm_sys_reg_set_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg, const struct sys_reg_desc table[], unsigned int num)
Definition: sys_regs.c:3721
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_pr_unimpl()

kvm_pr_unimpl ( "%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s }  ,
\n"  ,
&(struct va_format){ fmt, &va }  ,
p->  Op0,
p->  Op1,
p->  CRn,
p->  CRm,
p->  Op2,
p->is_write ? "write" :"read"   
)
Here is the caller graph for this function:

◆ kvm_sys_reg_get_user()

int kvm_sys_reg_get_user ( struct kvm_vcpu *  vcpu,
const struct kvm_one_reg *  reg,
const struct sys_reg_desc  table[],
unsigned int  num 
)

Definition at line 3680 of file sys_regs.c.

3682 {
3683  u64 __user *uaddr = (u64 __user *)(unsigned long)reg->addr;
3684  const struct sys_reg_desc *r;
3685  u64 val;
3686  int ret;
3687 
3688  r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
3689  if (!r || sysreg_hidden_user(vcpu, r))
3690  return -ENOENT;
3691 
3692  if (r->get_user) {
3693  ret = (r->get_user)(vcpu, r, &val);
3694  } else {
3695  val = __vcpu_sys_reg(vcpu, r->reg);
3696  ret = 0;
3697  }
3698 
3699  if (!ret)
3700  ret = put_user(val, uaddr);
3701 
3702  return ret;
3703 }
int(* get_user)(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, u64 *val)
Definition: sys_regs.h:87
static const struct sys_reg_desc * id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, const struct sys_reg_desc table[], unsigned int num)
Definition: sys_regs.c:3542
static bool sysreg_hidden_user(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
Definition: sys_regs.h:168
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_sys_reg_set_user()

int kvm_sys_reg_set_user ( struct kvm_vcpu *  vcpu,
const struct kvm_one_reg *  reg,
const struct sys_reg_desc  table[],
unsigned int  num 
)

Definition at line 3721 of file sys_regs.c.

3723 {
3724  u64 __user *uaddr = (u64 __user *)(unsigned long)reg->addr;
3725  const struct sys_reg_desc *r;
3726  u64 val;
3727  int ret;
3728 
3729  if (get_user(val, uaddr))
3730  return -EFAULT;
3731 
3732  r = id_to_sys_reg_desc(vcpu, reg->id, table, num);
3733  if (!r || sysreg_hidden_user(vcpu, r))
3734  return -ENOENT;
3735 
3736  if (sysreg_user_write_ignore(vcpu, r))
3737  return 0;
3738 
3739  if (r->set_user) {
3740  ret = (r->set_user)(vcpu, r, val);
3741  } else {
3742  __vcpu_sys_reg(vcpu, r->reg) = val;
3743  ret = 0;
3744  }
3745 
3746  return ret;
3747 }
int(* set_user)(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, u64 val)
Definition: sys_regs.h:89
static bool sysreg_user_write_ignore(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
Definition: sys_regs.h:183
Here is the call graph for this function:
Here is the caller graph for this function:

◆ match_sys_reg()

static int match_sys_reg ( const void *  key,
const void *  elt 
)
inlinestatic

Definition at line 208 of file sys_regs.h.

209 {
210  const unsigned long pval = (unsigned long)key;
211  const struct sys_reg_desc *r = elt;
212 
213  return pval - reg_to_encoding(r);
214 }
Here is the caller graph for this function:

◆ print_sys_reg_instr()

static void print_sys_reg_instr ( const struct sys_reg_params p)
inlinestatic

Definition at line 116 of file sys_regs.h.

117 {
118  /* GCC warns on an empty format string */
119  print_sys_reg_msg(p, "%s", "");
120 }
Here is the caller graph for this function:

◆ read_zero()

static bool read_zero ( struct kvm_vcpu *  vcpu,
struct sys_reg_params p 
)
inlinestatic

Definition at line 128 of file sys_regs.h.

130 {
131  p->regval = 0;
132  return true;
133 }
Here is the caller graph for this function:

◆ reset_unknown()

static u64 reset_unknown ( struct kvm_vcpu *  vcpu,
const struct sys_reg_desc r 
)
inlinestatic

Definition at line 136 of file sys_regs.h.

138 {
139  BUG_ON(!r->reg);
140  BUG_ON(r->reg >= NR_SYS_REGS);
141  __vcpu_sys_reg(vcpu, r->reg) = 0x1de7ec7edbadc0deULL;
142  return __vcpu_sys_reg(vcpu, r->reg);
143 }
Here is the caller graph for this function:

◆ reset_val()

static u64 reset_val ( struct kvm_vcpu *  vcpu,
const struct sys_reg_desc r 
)
inlinestatic

Definition at line 145 of file sys_regs.h.

146 {
147  BUG_ON(!r->reg);
148  BUG_ON(r->reg >= NR_SYS_REGS);
149  __vcpu_sys_reg(vcpu, r->reg) = r->val;
150  return __vcpu_sys_reg(vcpu, r->reg);
151 }

◆ sysreg_hidden()

static bool sysreg_hidden ( const struct kvm_vcpu *  vcpu,
const struct sys_reg_desc r 
)
inlinestatic

Definition at line 162 of file sys_regs.h.

164 {
165  return sysreg_visibility(vcpu, r) & REG_HIDDEN;
166 }
static unsigned int sysreg_visibility(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
Definition: sys_regs.h:153
#define REG_HIDDEN
Definition: sys_regs.h:97
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sysreg_hidden_user()

static bool sysreg_hidden_user ( const struct kvm_vcpu *  vcpu,
const struct sys_reg_desc r 
)
inlinestatic

Definition at line 168 of file sys_regs.h.

170 {
171  if (likely(!r->visibility))
172  return false;
173 
174  return r->visibility(vcpu, r) & (REG_HIDDEN | REG_HIDDEN_USER);
175 }
unsigned int(* visibility)(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd)
Definition: sys_regs.h:93
#define REG_HIDDEN_USER
Definition: sys_regs.h:98
Here is the caller graph for this function:

◆ sysreg_user_write_ignore()

static bool sysreg_user_write_ignore ( const struct kvm_vcpu *  vcpu,
const struct sys_reg_desc r 
)
inlinestatic

Definition at line 183 of file sys_regs.h.

185 {
186  return sysreg_visibility(vcpu, r) & REG_USER_WI;
187 }
#define REG_USER_WI
Definition: sys_regs.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sysreg_visibility()

static unsigned int sysreg_visibility ( const struct kvm_vcpu *  vcpu,
const struct sys_reg_desc r 
)
inlinestatic

Definition at line 153 of file sys_regs.h.

155 {
156  if (likely(!r->visibility))
157  return 0;
158 
159  return r->visibility(vcpu, r);
160 }
Here is the caller graph for this function:

◆ sysreg_visible_as_raz()

static bool sysreg_visible_as_raz ( const struct kvm_vcpu *  vcpu,
const struct sys_reg_desc r 
)
inlinestatic

Definition at line 177 of file sys_regs.h.

179 {
180  return sysreg_visibility(vcpu, r) & REG_RAZ;
181 }
#define REG_RAZ
Definition: sys_regs.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ va_end()

va_end ( va  )

◆ va_start()

static char va_start ( va  ,
fmt   
)

Variable Documentation

◆ fmt

char* fmt

Definition at line 104 of file sys_regs.h.