From patchwork Thu Oct 7 23:34:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12543793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F358BC433EF for ; Thu, 7 Oct 2021 23:34:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D93996138B for ; Thu, 7 Oct 2021 23:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236950AbhJGXgq (ORCPT ); Thu, 7 Oct 2021 19:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233854AbhJGXgo (ORCPT ); Thu, 7 Oct 2021 19:36:44 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8CEFC061570 for ; Thu, 7 Oct 2021 16:34:49 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id t7-20020a258387000000b005b6d7220c79so10041042ybk.16 for ; Thu, 07 Oct 2021 16:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DBO4AQdntb3BVMd9aTch+KZ6AR9uCpH0bw1K04j1fDg=; b=ARpgMqWjWNVSj+8W7+010xBn3FW/tNskv+xQG3e0yz5gLrFEzDJ+2s/O7Y1fpERJ6P ppRhwdqaqHMsR6b71SAFtoHB+yaLu0Qgn80I9m9mjCpEEH5LlzQRrrpDcHSZUyASE01C bNGOidHNcdHHtOnt6eCdAAPfkFxjXBwoqH2Wuw+gbzyfVnQ49jkwEuXMk++6AuviLBWB oBJDsuahFDjhWuQKOfcY0HZaBnMokKPJVr0UfcXD61ZreD28i/1W6+6p5P56fHNSa+0y 00ANJDmmc0UR2Qa2NX63DbccyUyB6NqkR0x1U/0gpVLompX9ca8U49vY6SxHxdo5xN5G rCRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DBO4AQdntb3BVMd9aTch+KZ6AR9uCpH0bw1K04j1fDg=; b=3xmQ5g7Vd68Ahs8+ihsZpZHnjK7FpgznmSfth6HQ2RKKON06TnoOx6gfAutd/aYTnC DRALUsDCiXQ8+SoZGTW7v8V5AGUlz8SYhDIuS4TqTrLRogOeFEJ3GuegJE+wNKbixgmc Mv6KYrIRoCGJFuMCZsl4RosZH8cpPt8uYOMCWQnURzbVdsMIRaIuO5VXy9HsYtlN5xGu MC6qz/d709qSzQhE+XAwB4sJgoK6U1mo6IcXtLiUfFV8fsLbyvpqiGH+mHsLtXJZYKw8 7iTShjSIWvmdSw9/rk7dmDCsKO+7HXZkSNlwe4xonIX7y6mJs0C5+hmrP6R/AY3E/NZ4 HqjQ== X-Gm-Message-State: AOAM532RPFxjTy58DnRLgmHeP6DTNgeyrn0vvYx0J3PSnu1uv8wzWqrL Ws4GwezrxZ0q6E8tcOG3ecEYaAC/T16v X-Google-Smtp-Source: ABdhPJwl5DFhG5Udcr24wfbo8ndztL2u+e+yHmwZAYy9o9DxoQ8DBaTdXFxSljDpoQjUMHomFNZy2ibYCFRr X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a25:38cc:: with SMTP id f195mr8368167yba.98.1633649689167; Thu, 07 Oct 2021 16:34:49 -0700 (PDT) Date: Thu, 7 Oct 2021 23:34:25 +0000 In-Reply-To: <20211007233439.1826892-1-rananta@google.com> Message-Id: <20211007233439.1826892-2-rananta@google.com> Mime-Version: 1.0 References: <20211007233439.1826892-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v8 01/15] KVM: arm64: selftests: Add MMIO readl/writel support From: Raghavendra Rao Ananta To: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Define the readl() and writel() functions for the guests to access (4-byte) the MMIO region. The routines, and their dependents, are inspired from the kernel's arch/arm64/include/asm/io.h and arch/arm64/include/asm/barrier.h. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Oliver Upton Reviewed-by: Andrew Jones --- .../selftests/kvm/include/aarch64/processor.h | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index c0273aefa63d..96578bd46a85 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -9,6 +9,7 @@ #include "kvm_util.h" #include +#include #define ARM64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ @@ -130,6 +131,49 @@ void vm_install_sync_handler(struct kvm_vm *vm, val; \ }) -#define isb() asm volatile("isb" : : : "memory") +#define isb() asm volatile("isb" : : : "memory") +#define dsb(opt) asm volatile("dsb " #opt : : : "memory") +#define dmb(opt) asm volatile("dmb " #opt : : : "memory") + +#define dma_wmb() dmb(oshst) +#define __iowmb() dma_wmb() + +#define dma_rmb() dmb(oshld) + +#define __iormb(v) \ +({ \ + unsigned long tmp; \ + \ + dma_rmb(); \ + \ + /* \ + * Courtesy of arch/arm64/include/asm/io.h: \ + * Create a dummy control dependency from the IO read to any \ + * later instructions. This ensures that a subsequent call \ + * to udelay() will be ordered due to the ISB in __delay(). \ + */ \ + asm volatile("eor %0, %1, %1\n" \ + "cbnz %0, ." \ + : "=r" (tmp) : "r" ((unsigned long)(v)) \ + : "memory"); \ +}) + +static __always_inline void __raw_writel(u32 val, volatile void *addr) +{ + asm volatile("str %w0, [%1]" : : "rZ" (val), "r" (addr)); +} + +static __always_inline u32 __raw_readl(const volatile void *addr) +{ + u32 val; + asm volatile("ldr %w0, [%1]" : "=r" (val) : "r" (addr)); + return val; +} + +#define writel_relaxed(v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c))) +#define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; }) + +#define writel(v,c) ({ __iowmb(); writel_relaxed((v),(c));}) +#define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(__v); __v; }) #endif /* SELFTEST_KVM_PROCESSOR_H */