From patchwork Tue Jun 6 17:25:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 9769325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3782160393 for ; Tue, 6 Jun 2017 17:28:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B3BC20373 for ; Tue, 6 Jun 2017 17:28:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FECD28469; Tue, 6 Jun 2017 17:28:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87F8926CFC for ; Tue, 6 Jun 2017 17:28:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dIIEh-0001UA-92; Tue, 06 Jun 2017 17:25:43 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dIIEf-0001Tf-PD for xen-devel@lists.xenproject.org; Tue, 06 Jun 2017 17:25:41 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id BE/A6-02199-495E6395; Tue, 06 Jun 2017 17:25:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsVyMfTASt0pT80 iDQ7sYLP4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOu3XjCVPAuumL+tZlsDYzTdLoYuTiEBGYw SixYsIwJxGERmMcssebjETBHQqCfVeLG1IksXYycQE6axPl7+9kg7CqJRd8b2UFsIQEtiaOnZ rNCjGpmkjh6/TZQAwcHm4CJxKwOCZAaEQEliXurJjOB2MwCoRJT/z4AmyksECHx/9hssJksAq oSr37uYQWxeQW8Jd5vfMcIsUtO4ua5TmYQm1PAR2Lm+SWMEHu9JfY0tDFOYBRYwMiwilG9OLW oLLVI11gvqSgzPaMkNzEzR9fQwFgvN7W4ODE9NScxqVgvOT93EyMwsBiAYAdj8xenQ4ySHExK oryRl8wihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnwfnkMlBMsSk1PrUjLzAGGOExagoNHSYR38 gOgNG9xQWJucWY6ROoUozHHlSvrvjBxTDmw/QuTEEtefl6qlDivwhOgUgGQ0ozSPLhBsNi7xC grJczLCHSaEE9BalFuZgmq/CtGcQ5GJWHeFJApPJl5JXD7XgGdwgR0Ct8lE5BTShIRUlINjFW Lb+1k39N3yGWTVXRZVrC9f5Bhl9SaUpO8oGKlTyfVd/i3t0ayqyV5X9v9hWtTdfIsO+5pTUJ+ 5tetn6fNcXqwbfamiz8P/Ik65Lkpwr36p/ueo3L154MuJh3QUF0dsN1g/rZDrJ5L1aYlav3cl y1bXLI5ue1b7DOzLLac5iaxpqL1q+0TlFiKMxINtZiLihMBNksuvbgCAAA= X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-9.tower-31.messagelabs.com!1496769938!48878377!1 X-Originating-IP: [209.85.192.169] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56909 invoked from network); 6 Jun 2017 17:25:39 -0000 Received: from mail-pf0-f169.google.com (HELO mail-pf0-f169.google.com) (209.85.192.169) by server-9.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 6 Jun 2017 17:25:39 -0000 Received: by mail-pf0-f169.google.com with SMTP id 83so42505002pfr.0 for ; Tue, 06 Jun 2017 10:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mKQyHCr4fhk7FRvcwewPz3anN3P4JyxOPFBfdU5g9mw=; b=eLbgtt0Uj6fqjEQa+vU2g1DmcehjqeqWsr+x2iIXOJY9atm48B8/BR8L8bYfsSqcEw fA3hyvwQuQXiRYEzIHY1F7wqOOl1XQ/0H/V7KXvUVIOfzS3GBLo0NgF95Epy+n4QfzR2 5M8PgdZ3EexZl450vU3Abb66qlOm6LHdKtsmA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mKQyHCr4fhk7FRvcwewPz3anN3P4JyxOPFBfdU5g9mw=; b=ndCKXGmSOA/npAjcRQOwP2ZHJTNzvoApXMfef2yL/x0N7/uTWFE/ToPGP4SYE1/AFG 2Idkmgn2X8HBOodpiUuofYC22lArKJJQFj0Vz8rytoyZ0rlyJtKJ3j5V4Itdrp+lZLLf iOD78LHNKmFtfaQw7iwwN9CKxjmGjJJnz6vN51lPT7vwRGyoLyyE9F8t3K+mnAvt549U syAw4u+VFQscEnlPDfRtmD8tSZkB09cPhQOqKfVQumPfG0jDfH270vgmnhrDROA4AI2O FsAaOXEX+pDzwiGeXBNo2NaAt60hxmJpfNeIkSgwxdAMMBJH0gV1SVubTcz9HoXNleTM qKBw== X-Gm-Message-State: AODbwcB+P5anqGNUFqy3tyDTdFO6atdhu2v+/NaC5zhOD3wIYxUIaW6c N0+uwUnG697+ulS+hOtD3A== X-Received: by 10.99.175.76 with SMTP id s12mr27907651pgo.152.1496769937918; Tue, 06 Jun 2017 10:25:37 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([103.5.19.18]) by smtp.gmail.com with ESMTPSA id 62sm6031632pfr.90.2017.06.06.10.25.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Jun 2017 10:25:37 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Tue, 6 Jun 2017 22:55:16 +0530 Message-Id: <1496769929-23355-2-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496769929-23355-1-git-send-email-bhupinder.thakur@linaro.org> References: <1496769929-23355-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH 01/14 v4] xen/arm: vpl011: Move vgic register access functions to vreg.h 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" X-Virus-Scanned: ClamAV using ClamSMTP These functions are generic in nature and can be reused by other emulation code in Xen. One recent example is pl011 emulation, which needs similar functions to read/write the registers. This patch moves the register access function definitions from vgic.h to vreg.h. Signed-off-by: Bhupinder Thakur Acked-by: Julien Grall --- CC: ss CC: jg Changes since v3: - Moved the macro call VGIC_REG_HELPERS to vreg.h from vgic.h. xen/include/asm-arm/vgic.h | 111 +-------------------------------------------- xen/include/asm-arm/vreg.h | 110 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 110 deletions(-) diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index 544867a..75c716e 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -20,6 +20,7 @@ #include #include +#include struct pending_irq { @@ -171,116 +172,6 @@ static inline int REG_RANK_NR(int b, uint32_t n) } } -#define VGIC_REG_MASK(size) ((~0UL) >> (BITS_PER_LONG - ((1 << (size)) * 8))) - -/* - * The check on the size supported by the register has to be done by - * the caller of vgic_regN_*. - * - * vgic_reg_* should never be called directly. Instead use the vgic_regN_* - * according to size of the emulated register - * - * Note that the alignment fault will always be taken in the guest - * (see B3.12.7 DDI0406.b). - */ -static inline register_t vgic_reg_extract(unsigned long reg, - unsigned int offset, - enum dabt_size size) -{ - reg >>= 8 * offset; - reg &= VGIC_REG_MASK(size); - - return reg; -} - -static inline void vgic_reg_update(unsigned long *reg, register_t val, - unsigned int offset, - enum dabt_size size) -{ - unsigned long mask = VGIC_REG_MASK(size); - int shift = offset * 8; - - *reg &= ~(mask << shift); - *reg |= ((unsigned long)val & mask) << shift; -} - -static inline void vgic_reg_setbits(unsigned long *reg, register_t bits, - unsigned int offset, - enum dabt_size size) -{ - unsigned long mask = VGIC_REG_MASK(size); - int shift = offset * 8; - - *reg |= ((unsigned long)bits & mask) << shift; -} - -static inline void vgic_reg_clearbits(unsigned long *reg, register_t bits, - unsigned int offset, - enum dabt_size size) -{ - unsigned long mask = VGIC_REG_MASK(size); - int shift = offset * 8; - - *reg &= ~(((unsigned long)bits & mask) << shift); -} - -/* N-bit register helpers */ -#define VGIC_REG_HELPERS(sz, offmask) \ -static inline register_t vgic_reg##sz##_extract(uint##sz##_t reg, \ - const mmio_info_t *info)\ -{ \ - return vgic_reg_extract(reg, info->gpa & offmask, \ - info->dabt.size); \ -} \ - \ -static inline void vgic_reg##sz##_update(uint##sz##_t *reg, \ - register_t val, \ - const mmio_info_t *info) \ -{ \ - unsigned long tmp = *reg; \ - \ - vgic_reg_update(&tmp, val, info->gpa & offmask, \ - info->dabt.size); \ - \ - *reg = tmp; \ -} \ - \ -static inline void vgic_reg##sz##_setbits(uint##sz##_t *reg, \ - register_t bits, \ - const mmio_info_t *info) \ -{ \ - unsigned long tmp = *reg; \ - \ - vgic_reg_setbits(&tmp, bits, info->gpa & offmask, \ - info->dabt.size); \ - \ - *reg = tmp; \ -} \ - \ -static inline void vgic_reg##sz##_clearbits(uint##sz##_t *reg, \ - register_t bits, \ - const mmio_info_t *info) \ -{ \ - unsigned long tmp = *reg; \ - \ - vgic_reg_clearbits(&tmp, bits, info->gpa & offmask, \ - info->dabt.size); \ - \ - *reg = tmp; \ -} - -/* - * 64 bits registers are only supported on platform with 64-bit long. - * This is also allow us to optimize the 32 bit case by using - * unsigned long rather than uint64_t - */ -#if BITS_PER_LONG == 64 -VGIC_REG_HELPERS(64, 0x7); -#endif -VGIC_REG_HELPERS(32, 0x3); - -#undef VGIC_REG_HELPERS - enum gic_sgi_mode; /* diff --git a/xen/include/asm-arm/vreg.h b/xen/include/asm-arm/vreg.h index ed2bd6f..348584f 100644 --- a/xen/include/asm-arm/vreg.h +++ b/xen/include/asm-arm/vreg.h @@ -107,4 +107,114 @@ static inline bool vreg_emulate_sysreg64(struct cpu_user_regs *regs, union hsr h #endif +#define VGIC_REG_MASK(size) ((~0UL) >> (BITS_PER_LONG - ((1 << (size)) * 8))) + +/* + * The check on the size supported by the register has to be done by + * the caller of vgic_regN_*. + * + * vgic_reg_* should never be called directly. Instead use the vgic_regN_* + * according to size of the emulated register + * + * Note that the alignment fault will always be taken in the guest + * (see B3.12.7 DDI0406.b). + */ +static inline register_t vgic_reg_extract(unsigned long reg, + unsigned int offset, + enum dabt_size size) +{ + reg >>= 8 * offset; + reg &= VGIC_REG_MASK(size); + + return reg; +} + +static inline void vgic_reg_update(unsigned long *reg, register_t val, + unsigned int offset, + enum dabt_size size) +{ + unsigned long mask = VGIC_REG_MASK(size); + int shift = offset * 8; + + *reg &= ~(mask << shift); + *reg |= ((unsigned long)val & mask) << shift; +} + +static inline void vgic_reg_setbits(unsigned long *reg, register_t bits, + unsigned int offset, + enum dabt_size size) +{ + unsigned long mask = VGIC_REG_MASK(size); + int shift = offset * 8; + + *reg |= ((unsigned long)bits & mask) << shift; +} + +static inline void vgic_reg_clearbits(unsigned long *reg, register_t bits, + unsigned int offset, + enum dabt_size size) +{ + unsigned long mask = VGIC_REG_MASK(size); + int shift = offset * 8; + + *reg &= ~(((unsigned long)bits & mask) << shift); +} + +/* N-bit register helpers */ +#define VGIC_REG_HELPERS(sz, offmask) \ +static inline register_t vgic_reg##sz##_extract(uint##sz##_t reg, \ + const mmio_info_t *info)\ +{ \ + return vgic_reg_extract(reg, info->gpa & offmask, \ + info->dabt.size); \ +} \ + \ +static inline void vgic_reg##sz##_update(uint##sz##_t *reg, \ + register_t val, \ + const mmio_info_t *info) \ +{ \ + unsigned long tmp = *reg; \ + \ + vgic_reg_update(&tmp, val, info->gpa & offmask, \ + info->dabt.size); \ + \ + *reg = tmp; \ +} \ + \ +static inline void vgic_reg##sz##_setbits(uint##sz##_t *reg, \ + register_t bits, \ + const mmio_info_t *info) \ +{ \ + unsigned long tmp = *reg; \ + \ + vgic_reg_setbits(&tmp, bits, info->gpa & offmask, \ + info->dabt.size); \ + \ + *reg = tmp; \ +} \ + \ +static inline void vgic_reg##sz##_clearbits(uint##sz##_t *reg, \ + register_t bits, \ + const mmio_info_t *info) \ +{ \ + unsigned long tmp = *reg; \ + \ + vgic_reg_clearbits(&tmp, bits, info->gpa & offmask, \ + info->dabt.size); \ + \ + *reg = tmp; \ +} + +/* + * 64 bits registers are only supported on platform with 64-bit long. + * This is also allow us to optimize the 32 bit case by using + * unsigned long rather than uint64_t + */ +#if BITS_PER_LONG == 64 +VGIC_REG_HELPERS(64, 0x7); +#endif +VGIC_REG_HELPERS(32, 0x3); + +#undef VGIC_REG_HELPERS + #endif /* __ASM_ARM_VREG__ */