From: Julien Grall Subject: [PATCH 3/4] xen/arm: vtimer: Introduce vtimer_emulate_sysreg{32, 64} Date: Fri, 11 Dec 2015 15:28:22 +0000 Message-ID: <1449847703-21252-4-git-send-email-julien.grall@citrix.com> References: <1449847703-21252-1-git-send-email-julien.grall@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a7Pdr-0003wi-Ql for xen-devel@lists.xenproject.org; Fri, 11 Dec 2015 15:29:55 +0000 In-Reply-To: <1449847703-21252-1-git-send-email-julien.grall@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Julien Grall , ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org Factorize the code to emulate a a 32-bit/64-bit sysreg in specific helpers. While this is currently not necessary, it will be helpful in a following patch to handle properly some registers. Signed-off-by: Julien Grall --- xen/arch/arm/vtimer.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index 629feb4..b9c0b41 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -302,11 +302,39 @@ static int vtimer_emulate_cp64(struct cpu_user_regs *regs, union hsr hsr) } #ifdef CONFIG_ARM_64 -static int vtimer_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr) +typedef int (*vtimer_sysreg32_fn_t)(struct cpu_user_regs *regs, uint32_t *r, + int read); +typedef int (*vtimer_sysreg64_fn_t)(struct cpu_user_regs *regs, uint64_t *r, + int read); + +static int vtimer_emulate_sysreg32(struct cpu_user_regs *regs, union hsr hsr, + vtimer_sysreg32_fn_t fn) { struct hsr_sysreg sysreg = hsr.sysreg; register_t *x = select_user_reg(regs, sysreg.reg); - uint32_t r = (uint32_t)*x; + uint32_t r = *x; + int ret; + + ret = fn(regs, &r, sysreg.read); + + if ( ret && sysreg.read ) + *x = r; + + return ret; +} + +static int vtimer_emulate_sysreg64(struct cpu_user_regs *regs, union hsr hsr, + vtimer_sysreg64_fn_t fn) +{ + struct hsr_sysreg sysreg = hsr.sysreg; + uint64_t *x = select_user_reg(regs, sysreg.reg); + + return fn(regs, x, sysreg.read); +} + +static int vtimer_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr) +{ + struct hsr_sysreg sysreg = hsr.sysreg; if ( sysreg.read ) perfc_incr(vtimer_sysreg_reads); @@ -316,20 +344,11 @@ static int vtimer_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr) switch ( hsr.bits & HSR_SYSREG_REGS_MASK ) { case HSR_SYSREG_CNTP_CTL_EL0: - if ( !vtimer_cntp_ctl(regs, &r, sysreg.read) ) - return 0; - if ( sysreg.read ) - *x = r; - return 1; + return vtimer_emulate_sysreg32(regs, hsr, vtimer_cntp_ctl); case HSR_SYSREG_CNTP_TVAL_EL0: - if ( !vtimer_cntp_tval(regs, &r, sysreg.read) ) - return 0; - if ( sysreg.read ) - *x = r; - return 1; - + return vtimer_emulate_sysreg32(regs, hsr, vtimer_cntp_tval); case HSR_SYSREG_CNTP_CVAL_EL0: - return vtimer_cntp_cval(regs, x, sysreg.read); + return vtimer_emulate_sysreg64(regs, hsr, vtimer_cntp_cval); default: return 0; -- 2.1.4