From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C50AACC6B38 for ; Thu, 15 Oct 2026 20:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=M5ixsAbdw/m1P57/+3HLK7jfThlRJ+tmwZshst71JoE=; b=eIoiPKWnfTebtCniew+HRR8EwD LlhPOzFCt725TreFcwDuj7xrdryDO6ID8uMS6D3GjX5PV4nslZYhx/6pqveBO1PJbbKto+MZQGFfq aZ+rmeftOI5A6h3pcSkjqaKRaA+d6u/EJEstZqYp4fDKxanFopW+PCvV93WM//OAyTfJHVbgjmyAb hwajWKQzeJJs76QuE9bQqIZElrP9R8phhDu2x26ApWd116qofMGTjbMcIl2QygoTZSUpAhwSMc0AF uuOKBJbrZfZH60rzHclYGnxZgMurOdA9xDyyThRikR707pYzAZYOxRX0NpWB0OdLtgtao3437jXMs x/at5nLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHRlQ-00000001I1A-1xmX; Thu, 15 Oct 2026 20:09:20 +0000 Received: from mail-ej1-x648.google.com ([2a00:1450:4864:20::648]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHRlM-00000001Hww-09EZ for linux-arm-kernel@lists.infradead.org; Thu, 15 Oct 2026 20:09:17 +0000 Received: by mail-ej1-x648.google.com with SMTP id a640c23a62f3a-c2e2da5823aso321220066b.0 for ; Thu, 15 Oct 2026 13:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1792094953; x=1792699753; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=M5ixsAbdw/m1P57/+3HLK7jfThlRJ+tmwZshst71JoE=; b=luKOATza4o71dLQ7pr4oXiXfqNHZvT3f0hmctvzPk+f5loEpi84dyt6f/vhEv1Q7O3 KWx0KumqlgyVGO6XV6Yj3v+j2mi4oEvd+DpNpBSTmbwJKKf5EGkpMEvyKCTFjFy7Qobp x8YhPsJTluUBsvGsYI2xClDDVqph/Mh8hvZB23QqJamB3O5PBEsf9RGV2HIg+jMIDXk7 toX/X4aelwfVkcj2MONQZvhngA4B6I9MjpFDSOQoE8oegmfpDOBujeAiFZrkx6KBu/9O qTN50CJQLbGn0WTAoVyELKN0ly7o5wJpJuZdj5Ynh/XhFkd1V+ZjXYqxZ16aqtwmDMJp lsug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792094953; x=1792699753; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=M5ixsAbdw/m1P57/+3HLK7jfThlRJ+tmwZshst71JoE=; b=ScgEMlF5u2I8Jpr+6+Z+CnSwzjZg88fWmTxRkAy6RYgSqj5Cf9gVJfQBTcS9gibuSR yydZKOAAeMItavW4avGKbR21GnbO6pf/nXhZgUdRNXgEM9lyFIOF8LEVvjC71eZzDJQ1 A4mfh+beqBEVg29AJ0nRuoQQj5D3mtzt6e6QVwDOChgHJoNF7oo+sX071APmeebCuPOr sD7UIWx/wdSnZ2lLocSfZ09v6QahCi6uI11Dr3oNfL40jqx1/MzBro3fGavumxcMhF7x PT66qCOIVYttmcrgoXdJ+1t8RMKBUaSLXDsOBIOjkD2KRjQns4HKHpLtLHCQuthFhzQu SXAQ== X-Gm-Message-State: AFq9FYJO74kIu2MJ/qhDTcg0JrlxgkSf2CI5BbK9hXaAhpvkqTrn7/lV WLBOD7sVEtpYZ6Dd9luOs15PP0RAlum9bMeYLarVurFXGqBZtRjEvA5eKf+vK7N7UeoiYNestno 7OsjoXMOiUgWaqEVmYNPXFqQhQvhRRJosYjNiOVlN7vMEuCB40oe6lLH+Tejwm4iN3PCrdGuSE6 Bzoin8aARlpAghwrBvV1q8z8v7UE8h6TBjVYjr6392hQhLlfMcWVvgrylowym95b1YyA== X-Received: from ejiq6.prod.google.com ([2002:a17:906:e46:b0:c37:a171:8eda]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:72cd:b0:c40:33d:f06f with SMTP id a640c23a62f3a-c40033df381mr136086766b.39.1792094953037; Thu, 15 Oct 2026 13:09:13 -0700 (PDT) Date: Thu, 15 Oct 2026 20:08:33 +0000 In-Reply-To: <20261015200903.2735565-1-smostafa@google.com> Mime-Version: 1.0 References: <20261015200903.2735565-1-smostafa@google.com> X-Mailer: git-send-email 2.56.0.176.g3575e65682-goog Message-ID: <20261015200903.2735565-3-smostafa@google.com> Subject: [PATCH v9 02/25] iommu/arm-smmu-v3: Move Queue and STE functions to header From: Mostafa Saleh To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev Cc: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, joro@8bytes.org, jgg@ziepe.ca, mark.rutland@arm.com, qperret@google.com, tabba@google.com, vdonnefort@google.com, nicolinc@nvidia.com, Mostafa Saleh Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261015_130916_105874_3677E4A8 X-CRM114-Status: GOOD ( 16.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The KVM SMMUv3 driver would re-use some of the CMDQ and STE code inside the hypervisor. Move those functions to the header file that would be shared between the host kernel and the hypervisor. Signed-off-by: Mostafa Saleh Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 62 -------------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 63 +++++++++++++++++++++ 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 34e916ea339f..101ece0e38d3 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -140,33 +140,6 @@ static void parse_driver_options(struct arm_smmu_device *smmu) } /* Low-level queue manipulation functions */ -static bool queue_has_space(struct arm_smmu_ll_queue *q, u32 n) -{ - u32 space, prod, cons; - - prod = Q_IDX(q, q->prod); - cons = Q_IDX(q, q->cons); - - if (Q_WRP(q, q->prod) == Q_WRP(q, q->cons)) - space = (1 << q->max_n_shift) - (prod - cons); - else - space = cons - prod; - - return space >= n; -} - -static bool queue_full(struct arm_smmu_ll_queue *q) -{ - return Q_IDX(q, q->prod) == Q_IDX(q, q->cons) && - Q_WRP(q, q->prod) != Q_WRP(q, q->cons); -} - -static bool queue_empty(struct arm_smmu_ll_queue *q) -{ - return Q_IDX(q, q->prod) == Q_IDX(q, q->cons) && - Q_WRP(q, q->prod) == Q_WRP(q, q->cons); -} - static bool queue_consumed(struct arm_smmu_ll_queue *q, u32 prod) { return ((Q_WRP(q, q->cons) == Q_WRP(q, prod)) && @@ -185,12 +158,6 @@ static void queue_sync_cons_out(struct arm_smmu_queue *q) writel_relaxed(q->llq.cons, q->cons_reg); } -static void queue_inc_cons(struct arm_smmu_ll_queue *q) -{ - u32 cons = Q_POS(q, q->cons) + 1; - q->cons = Q_OVF(q->cons) | Q_POS(q, cons); -} - static void queue_sync_cons_ovf(struct arm_smmu_queue *q) { struct arm_smmu_ll_queue *llq = &q->llq; @@ -221,12 +188,6 @@ static int queue_sync_prod_in(struct arm_smmu_queue *q) return ret; } -static u32 queue_inc_prod_n(struct arm_smmu_ll_queue *q, int n) -{ - u32 prod = Q_POS(q, q->prod) + n; - return Q_OVF(q->prod) | Q_POS(q, prod); -} - static void queue_poll_init(struct arm_smmu_device *smmu, struct arm_smmu_queue_poll *qp) { @@ -254,14 +215,6 @@ static int queue_poll(struct arm_smmu_queue_poll *qp) return 0; } -static void queue_write(__le64 *dst, u64 *src, size_t n_dwords) -{ - int i; - - for (i = 0; i < n_dwords; ++i) - *dst++ = cpu_to_le64(*src++); -} - static void queue_read(u64 *dst, __le64 *src, size_t n_dwords) { int i; @@ -1817,21 +1770,6 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) } /* Stream table manipulation functions */ -static void arm_smmu_write_strtab_l1_desc(struct arm_smmu_strtab_l1 *dst, - dma_addr_t l2ptr_dma) -{ - u64 val = 0; - - val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, STRTAB_SPLIT + 1); - val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; - - /* Ensure the new L2 table is fully visible. */ - dma_wmb(); - - /* The HW has 64 bit atomicity with stores to the L2 STE table */ - WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); -} - struct arm_smmu_ste_writer { struct arm_smmu_entry_writer writer; u32 sid; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index bb048e08d613..8c8957831286 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -1284,6 +1284,69 @@ int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, bool sync); bool arm_smmu_erratum_repeat_tlbi_cfgi(void); +/* Queue and STE functions shared between kernel and hyp. */ +static inline bool queue_has_space(struct arm_smmu_ll_queue *q, u32 n) +{ + u32 space, prod, cons; + + prod = Q_IDX(q, q->prod); + cons = Q_IDX(q, q->cons); + + if (Q_WRP(q, q->prod) == Q_WRP(q, q->cons)) + space = (1 << q->max_n_shift) - (prod - cons); + else + space = cons - prod; + + return space >= n; +} + +static inline bool queue_full(struct arm_smmu_ll_queue *q) +{ + return Q_IDX(q, q->prod) == Q_IDX(q, q->cons) && + Q_WRP(q, q->prod) != Q_WRP(q, q->cons); +} + +static inline bool queue_empty(struct arm_smmu_ll_queue *q) +{ + return Q_IDX(q, q->prod) == Q_IDX(q, q->cons) && + Q_WRP(q, q->prod) == Q_WRP(q, q->cons); +} + +static inline u32 queue_inc_prod_n(struct arm_smmu_ll_queue *q, int n) +{ + u32 prod = Q_POS(q, q->prod) + n; + return Q_OVF(q->prod) | Q_POS(q, prod); +} + +static inline void queue_inc_cons(struct arm_smmu_ll_queue *q) +{ + u32 cons = Q_POS(q, q->cons) + 1; + q->cons = Q_OVF(q->cons) | Q_POS(q, cons); +} + +static inline void queue_write(__le64 *dst, u64 *src, size_t n_dwords) +{ + int i; + + for (i = 0; i < n_dwords; ++i) + *dst++ = cpu_to_le64(*src++); +} + +static inline void arm_smmu_write_strtab_l1_desc(struct arm_smmu_strtab_l1 *dst, + dma_addr_t l2ptr_dma) +{ + u64 val = 0; + + val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, STRTAB_SPLIT + 1); + val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; + + /* Ensure the new L2 table is fully visible. */ + dma_wmb(); + + /* The HW has 64 bit atomicity with stores to the L2 STE table */ + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); +} + #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); void arm_smmu_sva_notifier_synchronize(void); -- 2.56.0.176.g3575e65682-goog