Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp252804pxb; Mon, 13 Sep 2021 18:26:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZp7bkJUf/AOSNzVbs/h7f1Rnp8E91NCJs8v/TLMHlT80/dwc0Bofyk9aASYN8AiIkad7c X-Received: by 2002:a6b:7106:: with SMTP id q6mr11821887iog.174.1631582780607; Mon, 13 Sep 2021 18:26:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631582780; cv=none; d=google.com; s=arc-20160816; b=FGLsWyljGEn595cF9IoSoQJ+TwedLQBDeH6dxDQma3TSOw9vNjuOa/nmEOTZeZQYuf wVaceFZ80bSBexR8aKqa30VL4ajtHP10P9m49PBGiaGb0V+mmJ/qih+D0Pgd8F2BKtYN 9E97PIoLfbnDkrN63DRc89WiIPJ2E1vHzs03wY6zm6nHUE/Zw2qhvoJinka66rPnipAD 9LCL5veMS5L/pVDlAhf4Ia5pxty9I+/m8vvX4efR0iw3ZCa77e+ONcXpsNgKKBQYqiu9 bUy7LYpGQ3xhxGIkFyyEaAiC4b28/7cPadVQ4i49ocP09k68Le1KfiUB9hYk6ancDmhi BcuA== 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=S2j8r1BCKqhVhJ+8bR7t/dA2J/PIIE/Rns3zAg7zZww=; b=b8pnbw1RkxBhXefIUYCYVMw/i1OX9qvlJQ83t7ofUgjCeA1RNy9nt/EcVlHittymaO x8dLdvtfHrBO/12UtNNpLT+QiXFkNeu/weAyDZF/tlbuHEIbU5G13c770j3Kdon07oQo hDTDuL3X6EmkUKiL4FN+9j7jLt1Ayb/EmeT+ktoqMpdODsk8BcG52JHGHoVGTszcTvxu 6jJi3ZvRf+B5a1pkwiuaPGaHqxAxjaQq125ucVLMPk0JTTQv6BkNqj9E3gpX13L33Pg/ zIxVzUlyxXEt7t0EoEhljC1HlUhfUFsvNoP6eaKUDRUkqJCWmdCu3TqJE5HqxBlJogeG AK9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CuGfX+E1; 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 a4si8914667ilt.54.2021.09.13.18.26.08; Mon, 13 Sep 2021 18:26:20 -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=CuGfX+E1; 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 S1344678AbhIMXMU (ORCPT + 99 others); Mon, 13 Sep 2021 19:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349385AbhIMXL4 (ORCPT ); Mon, 13 Sep 2021 19:11:56 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7726EC061764 for ; Mon, 13 Sep 2021 16:10:04 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id q23-20020a6562570000b029023cbfb4fd73so8230229pgv.14 for ; Mon, 13 Sep 2021 16:10:04 -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=S2j8r1BCKqhVhJ+8bR7t/dA2J/PIIE/Rns3zAg7zZww=; b=CuGfX+E1SqFTT5eOBisvWSFYoND4dvqTTB/VIJqY1O8Go94s/YODwQAdP0+plX7Q8H BgNk6fCKeOnA3t5HJ28w95v7aemtW3uKMH2yLOf2i7fygyTU3qd6e1V16BGwiYtoY8Im 6hNV5kQSYMzzuvz8lIuTMXWqUzyNCmIdYiyUP1tD/mn9B/ta7METDZDh7iRmPBrosoAh RiYVxGVxn7XnFrwnuiba1o/9AY07Rzs3AfP932QMyHlF+FN8hJyAtNGINbaH1ENfNh1E ZSjSdxbkzhVPwRlU/LVQ9SFgXvvNMVNBN+A+8zyTqpgbhMYo7sGbl68its1/49FBrf64 mEDw== 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=S2j8r1BCKqhVhJ+8bR7t/dA2J/PIIE/Rns3zAg7zZww=; b=jy4/KWA6UYTLlnUqdY3D1W0c8WC4/oNSZaKlQbKtaZQ4vbbFbWanS7m6jmF1mFLI5K ulLdFS/+7nmQZ8mxdQsAPxILZIEuhNQASSjnGvg3DR6DehKam2Ez+wYjG+KeJaDtDbiH Oyz12YOvjkRAGU2y340kBTNktqrsz7lt7ylYoEW/PtErY0d18gUF+2bwSjZSQTtaFpPz IaZO2dRR2xNZbs9H8yNvqO0lcjb2k+p/FnMHGmoqEp1djbINfNvmwuyoYhyBqLRV7+2P DIRAIAJC0lZxdCZFFqtuE0g8H4056CMY1sRdEaAluIP9RT51ew3M3mVzehmMysfA594H i6Xg== X-Gm-Message-State: AOAM5324WcL7O0rYtgEG2QKiSCDCSBi1Q08cBtbd60yAgSasYKqFa1SW 61ObchaKh2SCAnlPZpDYlmULbWsz487E X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:8c83:b029:129:17e5:a1cc with SMTP id t3-20020a1709028c83b029012917e5a1ccmr12488624plo.49.1631574603783; Mon, 13 Sep 2021 16:10:03 -0700 (PDT) Date: Mon, 13 Sep 2021 23:09:42 +0000 In-Reply-To: <20210913230955.156323-1-rananta@google.com> Message-Id: <20210913230955.156323-2-rananta@google.com> Mime-Version: 1.0 References: <20210913230955.156323-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v6 01/14] 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.309.g3052b89438-goog