[PATCH v18 14/18] RISC-V: KVM: Implement ONE REG interface for FP registers

Dan Carpenter dan.carpenter at oracle.com
Wed May 19 03:11:49 PDT 2021


On Wed, May 19, 2021 at 09:05:49AM +0530, Anup Patel wrote:
>  static int kvm_riscv_vcpu_set_reg(struct kvm_vcpu *vcpu,
>  				  const struct kvm_one_reg *reg)
>  {
> @@ -427,6 +519,12 @@ static int kvm_riscv_vcpu_set_reg(struct kvm_vcpu *vcpu,
>  		return kvm_riscv_vcpu_set_reg_csr(vcpu, reg);
>  	else if ((reg->id & KVM_REG_RISCV_TYPE_MASK) == KVM_REG_RISCV_TIMER)
>  		return kvm_riscv_vcpu_set_reg_timer(vcpu, reg);
> +	else if ((reg->id & KVM_REG_RISCV_TYPE_MASK) == KVM_REG_RISCV_FP_F)
> +		return kvm_riscv_vcpu_set_reg_fp(vcpu, reg,
> +						 KVM_REG_RISCV_FP_F);
> +	else if ((reg->id & KVM_REG_RISCV_TYPE_MASK) == KVM_REG_RISCV_FP_D)
> +		return kvm_riscv_vcpu_set_reg_fp(vcpu, reg,
> +						 KVM_REG_RISCV_FP_D);
>  
>  	return -EINVAL;
>  }
> @@ -442,6 +540,12 @@ static int kvm_riscv_vcpu_get_reg(struct kvm_vcpu *vcpu,
>  		return kvm_riscv_vcpu_get_reg_csr(vcpu, reg);
>  	else if ((reg->id & KVM_REG_RISCV_TYPE_MASK) == KVM_REG_RISCV_TIMER)
>  		return kvm_riscv_vcpu_get_reg_timer(vcpu, reg);
> +	else if ((reg->id & KVM_REG_RISCV_TYPE_MASK) == KVM_REG_RISCV_FP_F)
> +		return kvm_riscv_vcpu_get_reg_fp(vcpu, reg,
> +						 KVM_REG_RISCV_FP_F);
> +	else if ((reg->id & KVM_REG_RISCV_TYPE_MASK) == KVM_REG_RISCV_FP_D)
> +		return kvm_riscv_vcpu_get_reg_fp(vcpu, reg,
> +						 KVM_REG_RISCV_FP_D);

These have become unwieldy.  Use a switch statement:

	switch (reg->id & KVM_REG_RISCV_TYPE_MASK) {
	case KVM_REG_RISCV_TIMER:
		return kvm_riscv_vcpu_get_reg_timer(vcpu, reg);
regards,
dan carpenter




More information about the linux-riscv mailing list