From patchwork Thu Dec 1 05:16:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 9455393 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 8F1CC60756 for ; Thu, 1 Dec 2016 05:16:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8426928497 for ; Thu, 1 Dec 2016 05:16:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C418284BF; Thu, 1 Dec 2016 05:16:57 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C51352849D for ; Thu, 1 Dec 2016 05:16:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757153AbcLAFQw (ORCPT ); Thu, 1 Dec 2016 00:16:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37742 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755224AbcLAFQv (ORCPT ); Thu, 1 Dec 2016 00:16:51 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB6B631B32E; Thu, 1 Dec 2016 05:16:50 +0000 (UTC) Received: from weilaptop.redhat.com (vpn-61-59.rdu2.redhat.com [10.10.61.59]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB15Ggrb016323; Thu, 1 Dec 2016 00:16:47 -0500 From: Wei Huang To: cov@codeaurora.org Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, shannon.zhao@linaro.org, alistair.francis@xilinx.com, croberts@codeaurora.org, alindsay@codeaurora.org, drjones@redhat.com, andre.przywara@arm.com Subject: [kvm-unit-tests PATCH v13 1/4] arm: Define macros for accessing system registers Date: Wed, 30 Nov 2016 23:16:39 -0600 Message-Id: <1480569402-8848-2-git-send-email-wei@redhat.com> In-Reply-To: <1480569402-8848-1-git-send-email-wei@redhat.com> References: <1480569402-8848-1-git-send-email-wei@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 01 Dec 2016 05:16:51 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch defines four macros to assist creating system register accessors under both ARMv7 and AArch64: * DEFINE_GET_SYSREG32(name, ...) * DEFINE_SET_SYSREG32(name, ...) * DEFINE_GET_SYSREG64(name, ...) * DEFINE_SET_SYSREG64(name, ...) These macros are translated to inline functions with consistent naming, get_##name() and set_##name(), which can be used by C code directly. Signed-off-by: Andre Przywara Signed-off-by: Wei Huang --- lib/arm/asm/processor.h | 37 ++++++++++++++++++++++++++++++++----- lib/arm64/asm/processor.h | 35 ++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/lib/arm/asm/processor.h b/lib/arm/asm/processor.h index f25e7ee..3ca6b42 100644 --- a/lib/arm/asm/processor.h +++ b/lib/arm/asm/processor.h @@ -33,13 +33,40 @@ static inline unsigned long current_cpsr(void) #define current_mode() (current_cpsr() & MODE_MASK) -static inline unsigned int get_mpidr(void) -{ - unsigned int mpidr; - asm volatile("mrc p15, 0, %0, c0, c0, 5" : "=r" (mpidr)); - return mpidr; +#define DEFINE_GET_SYSREG32(name, opc1, crn, crm, opc2) \ +static inline uint32_t get_##name(void) \ +{ \ + uint32_t reg; \ + asm volatile("mrc p15, " #opc1 ", %0, " #crn ", " #crm ", " \ + #opc2 : "=r" (reg)); \ + return reg; \ +} + +#define DEFINE_SET_SYSREG32(name, opc1, crn, crm, opc2) \ +static inline void set_##name(uint32_t value) \ +{ \ + asm volatile("mcr p15, " #opc1 ", %0, " #crn ", " #crm ", " \ + #opc2 :: "r" (value)); \ +} + +#define DEFINE_GET_SYSREG64(name, opc, crm) \ +static inline uint64_t get_##name(void) \ +{ \ + uint32_t lo, hi; \ + asm volatile("mrrc p15, " #opc ", %0, %1, " #crm \ + : "=r" (lo), "=r" (hi)); \ + return (uint64_t)hi << 32 | lo; \ +} + +#define DEFINE_SET_SYSREG64(name, opc, crm) \ +static inline void set_##name(uint64_t value) \ +{ \ + asm volatile("mcrr p15, " #opc ", %0, %1, " #crm \ + :: "r" (value & 0xffffffff), "r" (value >> 32)); \ } +DEFINE_GET_SYSREG32(mpidr, 0, c0, c0, 5) + /* Only support Aff0 for now, up to 4 cpus */ #define mpidr_to_cpu(mpidr) ((int)((mpidr) & 0xff)) diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h index 84d5c7c..dfa75eb 100644 --- a/lib/arm64/asm/processor.h +++ b/lib/arm64/asm/processor.h @@ -66,14 +66,35 @@ static inline unsigned long current_level(void) return el & 0xc; } -#define DEFINE_GET_SYSREG32(reg) \ -static inline unsigned int get_##reg(void) \ -{ \ - unsigned int reg; \ - asm volatile("mrs %0, " #reg "_el1" : "=r" (reg)); \ - return reg; \ +#define DEFINE_GET_SYSREG32(reg, el) \ +static inline uint32_t get_##reg(void) \ +{ \ + uint32_t reg; \ + asm volatile("mrs %0, " #reg "_" #el : "=r" (reg)); \ + return reg; \ } -DEFINE_GET_SYSREG32(mpidr) + +#define DEFINE_SET_SYSREG32(reg, el) \ +static inline void set_##reg(uint32_t value) \ +{ \ + asm volatile("msr " #reg "_" #el ", %0" :: "r" (value)); \ +} + +#define DEFINE_GET_SYSREG64(reg, el) \ +static inline uint64_t get_##reg(void) \ +{ \ + uint64_t reg; \ + asm volatile("mrs %0, " #reg "_" #el : "=r" (reg)); \ + return reg; \ +} + +#define DEFINE_SET_SYSREG64(reg, el) \ +static inline void set_##reg(uint64_t value) \ +{ \ + asm volatile("msr " #reg "_" #el ", %0" :: "r" (value)); \ +} + +DEFINE_GET_SYSREG32(mpidr, el1) /* Only support Aff0 for now, gicv2 only */ #define mpidr_to_cpu(mpidr) ((int)((mpidr) & 0xff))