From patchwork Wed May 10 14:24:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 9719951 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 47C4860236 for ; Wed, 10 May 2017 14:29:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 389B328236 for ; Wed, 10 May 2017 14:29:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D79828600; Wed, 10 May 2017 14:29:29 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 1360528236 for ; Wed, 10 May 2017 14:29:27 +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 1d8Sa4-0002Ys-Ku; Wed, 10 May 2017 14:27:08 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8Sa3-0002Yj-S3 for xen-devel@lists.xenproject.org; Wed, 10 May 2017 14:27:08 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 4F/77-03058-B3323195; Wed, 10 May 2017 14:27:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42Lxqg021bVSFo4 0mLxCyeL7lslMDowehz9cYQlgjGLNzEvKr0hgzVj19jdLwZLwirt717E2MK7R6GLk4hASmM4o cejDe1YQh0WgnVni6OpVYI6EwDsWiU1bTzJ1MXICOXES79bPYoWwKySW3ZrDBmILCWhJHD01m xViVBOTxLpzz4ESHBxsAiYSszokQGpEBJQk7q2aDDaHWSBU4t+zNnYQW1ggQuLT1yPMIDaLgK rEtvv9jCA2r4C3xOqXb9kgdslJ3DzXyTyBkW8BI8MqRo3i1KKy1CJdI0u9pKLM9IyS3MTMHF1 DAzO93NTi4sT01JzEpGK95PzcTYzAUGEAgh2MBxYFHmKU5GBSEuXV3SUUKcSXlJ9SmZFYnBFf VJqTWnyIUYaDQ0mC97+icKSQYFFqempFWmYOMGhh0hIcPEoivK9B0rzFBYm5xZnpEKlTjLocj 1b+eM8kxJKXn5cqJc7rqARUJABSlFGaBzcCFkGXGGWlhHkZgY4S4ilILcrNLEGVf8UozsGoJM z7G2QVT2ZeCdymV0BHMAEdEcggAHJESSJCSqqBsWRbj/7772y6oc7l1Ytk0mI2trzXrto99/0 Z4V33v05is9/9yfPT0mkyzS1yom/mO3ZtWDyv+ohX/vyE1hc+YYards/7/7NgQ9+ic3vNrzxN q5qSO+sp35PdjrY6/1eJ2uXEl2jauu4LWqr4VyH80blN/9a3HwpSDD93qbfh7i0ty/tzNHJVf iuxFGckGmoxFxUnAgC5BAAimwIAAA== X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-15.tower-27.messagelabs.com!1494426425!48498322!1 X-Originating-IP: [74.125.83.53] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5546 invoked from network); 10 May 2017 14:27:06 -0000 Received: from mail-pg0-f53.google.com (HELO mail-pg0-f53.google.com) (74.125.83.53) by server-15.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 10 May 2017 14:27:06 -0000 Received: by mail-pg0-f53.google.com with SMTP id o3so17552759pgn.2 for ; Wed, 10 May 2017 07:27:06 -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; bh=IGrbkDdkRhycryHarwtaF3ehGjbsa+VPScMKE2Zv3Es=; b=ZprNn+1KtCdKA2HhYXWqLQkv6IjVieWkRdsIS540uaGwyZNjow0h7UzPrvIUt2rA4o CVqVn0kbUDItlZMxf0stEXtRiiSpRkO9d7pgMjXOjLLjKvGZ4Fo0uu5zqEmGli0/uWxA h6Cibox4hqIWJzy1vPiHBnTGkj3g9VFClqxKA= 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; bh=IGrbkDdkRhycryHarwtaF3ehGjbsa+VPScMKE2Zv3Es=; b=c+nyq/BQDOYQa5m4JMRxoWRNc3jPucKm8V2P473J3X4UmPD3MCmViVgIaxCgaF0Let yMPST0JpUsyZ7U8m8ttl5pAYN8DDZBVkK1SITKfgdBKHRx+2wEP0C+mmOG/e8zyLFdNT wgwWqDiLlVrjg6VzPzF3/suHdK/59kArKkUVvk4SoUXw0W/eewh/SAtjaJzyozKJ1e0G cC6jm4OYDisovki7smfXwVdJu2TsDsP8GeV6gq827YIvGz5B0ua5094MTKARRle4xLd2 1mjeuFDVYvYK4D1CQ0UaopDUm7kpnkk1d8F8KTQ56wFHC4QHJYMUrJLnPT667EqNtCPM QggQ== X-Gm-Message-State: AODbwcD5W9kL09VSrWIs5w6ev6yeO7lds7muL77G/DVmzyqLW7XFyWeg XsXTtM9lQA+rjGGJ X-Received: by 10.98.0.146 with SMTP id 140mr6480171pfa.172.1494426424877; Wed, 10 May 2017 07:27:04 -0700 (PDT) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([61.0.91.57]) by smtp.gmail.com with ESMTPSA id k79sm6432320pfj.6.2017.05.10.07.27.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 May 2017 07:27:04 -0700 (PDT) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Wed, 10 May 2017 19:54:51 +0530 Message-Id: <1494426293-32481-1-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH 01/12 v3] 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 funictions to read/write the registers. This patch moves the register access function definitions from vgic.h to vreg.h. Signed-off-by: Bhupinder Thakur --- xen/include/asm-arm/vgic.h | 99 +--------------------------------------------- xen/include/asm-arm/vreg.h | 98 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 98 deletions(-) diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index 544867a..c838298 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,104 +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 diff --git a/xen/include/asm-arm/vreg.h b/xen/include/asm-arm/vreg.h index ed2bd6f..1442c58 100644 --- a/xen/include/asm-arm/vreg.h +++ b/xen/include/asm-arm/vreg.h @@ -107,4 +107,102 @@ 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; \ +} + #endif /* __ASM_ARM_VREG__ */