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: 103171 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp1536646qgd; Tue, 6 Jun 2017 10:27:45 -0700 (PDT) X-Received: by 10.107.139.214 with SMTP id n205mr16656622iod.178.1496770065621; Tue, 06 Jun 2017 10:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496770065; cv=none; d=google.com; s=arc-20160816; b=yiBn/L27jQIgNrkRK4ccICLRbgs8aurig30OonoY92jn6f48IhTAFULcu9utNzuq3x pBjcOCGhKhOhehPn7/3pNB1s/Trw6k4OXNfqe8yNPJfQXu0qWgSf+spWplfmez3Bwqcj E8Q/LG5ePUU3QTL8H8yt1t10/tASISIe8wRlZIOVzp8VEhhX9e4UQHlbzsrxO8z6JzcQ TmQnKDcdBlOrCn9mrqo+MYtJf000QistkKhATX3SPv7dDD08v6qTFgJt5PbLKaMZG4aP o6WoLqqsDy84XiX8ODXJ+hDKI3jBWVapnWDRfgdDq6Eopu6mZN+IjBSm5yBYKmuQl8Jd 3pig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=yU61mAy/rfPJFSv77P2QI8AOgL1JuT62MC2c+q0J2sc=; b=q45+datdq0pEgXPnIzUJ30JK2zuKZRJod/MqJ6qMOK8RSuiTq3njh7EpLXMERFxdab TRRZYNKPtFetc61koLLDoKpCuuR5aRuQ96j7fW19WmBv/bBsS0ZJ+oaj4UPwdffGxn1V ZTv3nkh+nA3IqhZCCi6Fd+qqLVbLeKPKlc/QOBOiBlqLKvnZKmaVJH7nRxIOtnjd3Lax naGdnVzpGN/uTEWzf58whoDGw2G203K+LievtRPBAEraHrHS7a0bq+89dUAIql4wfG/3 rmhJUpX73I3LAStPB6R67SLss0UZb/J0EpFBZSvN6te+16TURKK3IveOfZ928OJLoQ7G lkPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id m36si15053380iti.31.2017.06.06.10.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 10:27:45 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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 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" 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__ */