Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1836288pxb; Thu, 7 Oct 2021 16:36:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaEE33VtKPzmsfptujAy/YH5tA3Sp9DCi9uY3Pa63PR3mpuaXCXrOctqGSEXCPxCoz9iPl X-Received: by 2002:a17:906:7f01:: with SMTP id d1mr9448971ejr.318.1633649800942; Thu, 07 Oct 2021 16:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633649800; cv=none; d=google.com; s=arc-20160816; b=VV7yW8LuapMvYu+KjaTsA5rGOqYBJCU1RbzDbbOdwO42z+dLfBPYenTv6FgRiySeIv vT45lvStB3uEIc0TXaOWrwqgZwjT7xzhXHj9n7uiQyfIk+6/qFy4C2Qnk9s8Mo+KOh6F j2E9KXGugLEuie67wlLwM0k8fuiMe0MkqmMNa897zAmGTWlc3H934+Oq8uokKXXhFBul 291fyMcIG6F9yr/bBZYGETfE+u5JHcUP/KGq0lUxicZZy8Wfbldkf+4JSWVKmCupYKoa JAOHZu3b/74nJucLT5RsRfidB5ZTaa4wSc0uqEOOzOD4VFGe0KD2w3Twel5t1qhjpeOM G7tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=DBO4AQdntb3BVMd9aTch+KZ6AR9uCpH0bw1K04j1fDg=; b=XrNp089AjT6fpw9z+oTp4C25TTNhNaol3kwgnkQEzAzPyKupr6jx/Sby4EqWI0eUhi jSWaVD+QxsasvDu1LnPGjqi/iQEN8htm9Hzg0LEW7Jc1n72xEfkgtYpZNfHx9yjjwGyD ND+7Sb13F2lhHQF2VN8qISuAx5XIToGLDUu9DCpz3Sf/b02N4vBaVbZaMkC/4Xpt88d1 VEx1f/LerzQyP0Gj6K1FHui77pySxzCF25Ow7Pu3aPLhTr5WKgRMU7doiPPC6/1MkOgR PTDrdvjKh2Yavx+uNM5nKt0fKtFLRy5KujLt8vUnNJObTciQSDaZK1fW/yYZ+zVYySQB pafA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ARpgMqWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jo24si1004343ejb.197.2021.10.07.16.36.15; Thu, 07 Oct 2021 16:36:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ARpgMqWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236900AbhJGXgq (ORCPT + 99 others); Thu, 7 Oct 2021 19:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233354AbhJGXgo (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 EE806C061755 for ; Thu, 7 Oct 2021 16:34:49 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id z130-20020a256588000000b005b6b4594129so10126513ybb.15 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=spIwKTl95ztiZyC16ISD0/UmaD93vFE5Zq+0W94lk3Whiexg3vJZ5eA4jfzLKFjsRy aTddKJI9Zhri8t2cVIEo2FrMi60bwfgDX5euSIyh4Js5PfPlxZFeu57Ao4tjvV7eN4un WQaGphKA2NtoLiMyKKWWUfTNBof1T40p7G9UWU63QtzPR/44/pP6MVGOfLYpLINMynwh rHTIZWVYJUVrsZFhlgKOc31E2Y09d1IsctUIJTx7v+KI3A0imgds2zFhRdFbI4vidqcZ wCAtuL62SMvP15gKn2Vhvkls28G5QxqAys0t2Da8NxdSQCbNIZYlZYCeisMDnZDDRHLJ A4Jw== X-Gm-Message-State: AOAM532n0uX0/67QEIHbrixBGP2pQAEam+kFaiBHMVRvYuS9Vea2oWah A5Qp+CLCaLL9IQQoqvw1zquGkP/5RdVi 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 */ -- 2.33.0.882.g93a45727a2-goog