From patchwork Wed Dec 7 12:33:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 87086 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp291010qgi; Wed, 7 Dec 2016 04:36:01 -0800 (PST) X-Received: by 10.36.67.199 with SMTP id s190mr1887970itb.41.1481114161665; Wed, 07 Dec 2016 04:36:01 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x63si5810691itg.104.2016.12.07.04.36.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 04:36:01 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cEbQI-00069W-QC; Wed, 07 Dec 2016 12:34:10 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cEbQI-00068e-2o for xen-devel@lists.xen.org; Wed, 07 Dec 2016 12:34:10 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id D8/67-08512-1C108485; Wed, 07 Dec 2016 12:34:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsVysyfVTfcAo0e Ewbw/5hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8atNpOCdaoV++/cZGlgXCbTxcjFISSwiVFi 3ZlpTBDOaUaJzsb3bF2MnBxsApoSdz5/YgKxRQSkJa59vswIYjMLOEi8+XiPpYuRg0NYIEri5 PZIkDCLgKrEm77zzCA2r4CrxIHFO8FaJQTkJE4em8wKYnMCxW99/csCYgsJuEh8bVrGMoGRew EjwypGjeLUorLUIl0jY72kosz0jJLcxMwcXUMDU73c1OLixPTUnMSkYr3k/NxNjEDv1jMwMO5 g3NHud4hRkoNJSZR31wT3CCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvIsYPCKEBItS01Mr0jJz gGEGk5bg4FES4d33H6iVt7ggMbc4Mx0idYpRUUqcdy5InwBIIqM0D64NFtqXGGWlhHkZGRgYh HgKUotyM0tQ5V8xinMwKgnz/gaZwpOZVwI3/RXQYiagxfNugC0uSURISTUwBsWcCpwzXYCvwO bLm/06h159d61ZtJJ575rH+4NWxOTpeahGOU80XuD2c1rRra2TXlTtVj/cZfF+pfHnhiUx3h9 N2l8eOqAgGHKqKc7DRm+KZfTGAq1DZn6KDMrlEeErEvma6rbIPbeX3fVCPCArbZK1sq0RR0/i k5u8NcqbY/NEjpUuOfpIiaU4I9FQi7moOBEAKFK3I2gCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1481114046!74322811!2 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33072 invoked from network); 7 Dec 2016 12:34:07 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-4.tower-206.messagelabs.com with SMTP; 7 Dec 2016 12:34:07 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7B562707; Wed, 7 Dec 2016 04:34:08 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DBA3E3F477; Wed, 7 Dec 2016 04:34:07 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 7 Dec 2016 12:33:49 +0000 Message-Id: <1481114033-11024-10-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481114033-11024-1-git-send-email-julien.grall@arm.com> References: <1481114033-11024-1-git-send-email-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH 09/13] xen/arm: vtimer: Move emulate_sysreg* callback in a separate header X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" The core emulation of sysreg (reading/writing registers) is not specific to the virtual timer. Move the helpers in a new header vreg.h. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- The helpers will be necessary in a follow-up patch to emulate sysreg for another components. --- xen/arch/arm/vtimer.c | 53 ++++--------------------------------------- xen/include/asm-arm/vreg.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 xen/include/asm-arm/vreg.h diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index 3fc97b3..091b5e7 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -27,6 +27,7 @@ #include #include #include +#include #include /* @@ -321,52 +322,6 @@ static bool vtimer_emulate_cp64(struct cpu_user_regs *regs, union hsr hsr) } #ifdef CONFIG_ARM_64 -typedef bool (*vtimer_sysreg32_fn_t)(struct cpu_user_regs *regs, uint32_t *r, - bool read); -typedef bool (*vtimer_sysreg64_fn_t)(struct cpu_user_regs *regs, uint64_t *r, - bool read); - -static bool vtimer_emulate_sysreg32(struct cpu_user_regs *regs, union hsr hsr, - vtimer_sysreg32_fn_t fn) -{ - struct hsr_sysreg sysreg = hsr.sysreg; - uint32_t r = 0; - bool ret; - - if ( !sysreg.read ) - r = get_user_reg(regs, sysreg.reg); - - ret = fn(regs, &r, sysreg.read); - - if ( ret && sysreg.read ) - set_user_reg(regs, sysreg.reg, r); - - return ret; -} - -static bool vtimer_emulate_sysreg64(struct cpu_user_regs *regs, union hsr hsr, - vtimer_sysreg64_fn_t fn) -{ - struct hsr_sysreg sysreg = hsr.sysreg; - /* - * Initialize to zero to avoid leaking data if there is an - * implementation error in the emulation (such as not correctly - * setting x). - */ - uint64_t x = 0; - bool ret; - - if ( !sysreg.read ) - x = get_user_reg(regs, sysreg.reg); - - ret = fn(regs, &x, sysreg.read); - - if ( ret && sysreg.read ) - set_user_reg(regs, sysreg.reg, x); - - return ret; -} - static bool vtimer_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr) { struct hsr_sysreg sysreg = hsr.sysreg; @@ -379,11 +334,11 @@ static bool vtimer_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr) switch ( hsr.bits & HSR_SYSREG_REGS_MASK ) { case HSR_SYSREG_CNTP_CTL_EL0: - return vtimer_emulate_sysreg32(regs, hsr, vtimer_cntp_ctl); + return vreg_emulate_sysreg32(regs, hsr, vtimer_cntp_ctl); case HSR_SYSREG_CNTP_TVAL_EL0: - return vtimer_emulate_sysreg32(regs, hsr, vtimer_cntp_tval); + return vreg_emulate_sysreg32(regs, hsr, vtimer_cntp_tval); case HSR_SYSREG_CNTP_CVAL_EL0: - return vtimer_emulate_sysreg64(regs, hsr, vtimer_cntp_cval); + return vreg_emulate_sysreg64(regs, hsr, vtimer_cntp_cval); default: return false; diff --git a/xen/include/asm-arm/vreg.h b/xen/include/asm-arm/vreg.h new file mode 100644 index 0000000..2671f6e --- /dev/null +++ b/xen/include/asm-arm/vreg.h @@ -0,0 +1,56 @@ +/* + * Helpers to emulate co-processor and system registers + */ +#ifndef __ASM_ARM_VREG__ +#define __ASM_ARM_VREG__ + +#ifdef CONFIG_ARM_64 +typedef bool (*vreg_sysreg32_fn_t)(struct cpu_user_regs *regs, uint32_t *r, + bool read); +typedef bool (*vreg_sysreg64_fn_t)(struct cpu_user_regs *regs, uint64_t *r, + bool read); + +static inline bool vreg_emulate_sysreg32(struct cpu_user_regs *regs, union hsr hsr, + vreg_sysreg32_fn_t fn) +{ + struct hsr_sysreg sysreg = hsr.sysreg; + uint32_t r = 0; + bool ret; + + if ( !sysreg.read ) + r = get_user_reg(regs, sysreg.reg); + + ret = fn(regs, &r, sysreg.read); + + if ( ret && sysreg.read ) + set_user_reg(regs, sysreg.reg, r); + + return ret; +} + +static inline bool vreg_emulate_sysreg64(struct cpu_user_regs *regs, union hsr hsr, + vreg_sysreg64_fn_t fn) +{ + struct hsr_sysreg sysreg = hsr.sysreg; + /* + * Initialize to zero to avoid leaking data if there is an + * implementation error in the emulation (such as not correctly + * setting x). + */ + uint64_t x = 0; + bool ret; + + if ( !sysreg.read ) + x = get_user_reg(regs, sysreg.reg); + + ret = fn(regs, &x, sysreg.read); + + if ( ret && sysreg.read ) + set_user_reg(regs, sysreg.reg, x); + + return ret; +} + +#endif + +#endif /* __ASM_ARM_VREG__ */