From patchwork Fri Feb 10 16:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 652350 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp1060176wrr; Fri, 10 Feb 2023 08:40:08 -0800 (PST) X-Google-Smtp-Source: AK7set+kVDTqWPJeklJn8pjuteVji225rZ0jAzeioN29XJPyfbLajvc0umIdPUkWwVxdL69hkLTD X-Received: by 2002:a05:6214:ca7:b0:56e:8d51:100f with SMTP id s7-20020a0562140ca700b0056e8d51100fmr8861660qvs.16.1676047208269; Fri, 10 Feb 2023 08:40:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676047208; cv=none; d=google.com; s=arc-20160816; b=qm+ZJQrtv4Mi4KKk6XBTpVqEPoVB/4SjDYZw7hweNoivTkMSl2e35kGQeozW+mKh21 Wl/LC/1f50+s44kR169nZYK24/XDCEwqSKicp3q5RMqA/b/ZQTPqPwIduhTnTth7KZJz Ess+8hO6Mi2Oa+HGMRT2HYOP6oUVccMo/+djIAruE4/uoojph53olXXEcc+sTAz5HFL3 9lA/JmJ8esvLvADz998678a6T1FwxOtxF1gU1dSbr7n49Ou0kUsaVUSAQoDa0ZO+wPO1 +3TmgBSEXF933Pp1fBawqH5y1lXgsFt60rBjprwBSg1d+fMm3R3W5ZqqVRSHH1dXl+mx l4TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=usy+gvwS+JxR9gEW4rdKIjKndc55aNyj2tFUAGWHkSo=; b=I75OM1x97UB6XqTVkXIAVmhFhVnFpTaxekWGbWwYcFKCJhKXXQMoA24EOLaxVLyI+G Qh30Jx/tnVEdU+ulWkWxELr2mI1Yj++LWw56ZhCJ6BCDWMrnuaHui7pdXSXUIRWgwhSF SuX3gNgTmSTQMjUYl6+a73YxNJNIcNFxYP79oTR2Dq7K29g0F31uykklEeCoT4OWoppR KWjcxzedEfVWoTxy+JFkZKvtfobjBgVaXmzx2BxD4R4QMH/TLzSINdQhkomeP24+nlsZ 5rcHItARCCfSJv1dlJaC/JfpwoYVFwfAkG7WazACSFcyXWJPc7mxsAcAwK7fLfjLbkzi 6hQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x9N9jFju; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t8-20020a0cde08000000b0056c03aa2e1asi3816668qvk.190.2023.02.10.08.40.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Feb 2023 08:40:08 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x9N9jFju; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQWR9-0006ti-0B; Fri, 10 Feb 2023 11:39:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQWR7-0006i1-K5 for qemu-devel@nongnu.org; Fri, 10 Feb 2023 11:39:45 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQWR4-0000UC-AM for qemu-devel@nongnu.org; Fri, 10 Feb 2023 11:39:45 -0500 Received: by mail-wm1-x329.google.com with SMTP id n13so4227270wmr.4 for ; Fri, 10 Feb 2023 08:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=usy+gvwS+JxR9gEW4rdKIjKndc55aNyj2tFUAGWHkSo=; b=x9N9jFjug6CynwRuwkXCHfbmzOxpXYLc+dJdMrWTjdIRw3HhXJ6E5Pcjxstq5FF7gT 5mBwiCl+sMpYZ6mvzprOmVAhXFblo64VWEfl+gKyPu0b7vft+M09XJMjNh0IUkFExE6l UwW/i68WxR0y3J1d0dc2SHAVX+tMisjmx+5C5qpXg8qshNNZZB/gyzqNvFTg4DkSpfw+ 0dk5XCJRAd+SHMuQ8XOz30H3NOgfkc5wIlUQF07mkJfDu/zOAuu1UNOk+1aC4Jtni7vl UVczrnxJmIZU8h79CrpJKdup1RvL9Tko9+XGNoXX9gZQBrMyyglUf4iX60b9XP29IML5 qKhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=usy+gvwS+JxR9gEW4rdKIjKndc55aNyj2tFUAGWHkSo=; b=nYTwws3K/XIGeV316xzHbe41P6Ja3MXIoludFTZkU3khpldFOuq6+UHwhxCL3CyoRd RheNUszSrsGV6ez/WvGbDx7Xw+fLwURtZXlFDbR9f0/JzXqt2b9XufGriuzkARAmG/9e 0YUTAUNAL7jKJxoIRnwpN8WRS+4RjOcnrPc+ALxFy1C+0/crn2ypLp6sd+FvC7slYDh/ srlD5mS/NkgVSH2iDOV7kbwEr0ZttXlOrfJ9V0L6SxX3DHSI+x3ylVOiy8Bm6vXTAk0b KqC7mzmmkkAb6oH5bcNcNqhsIxc9gc2X/qopJNvcEix/M9SbckPnm30VUIb5WNzKCt0Y sxJQ== X-Gm-Message-State: AO0yUKURmfIvoZIot903/SqWLFE1IioqNdFWavlkIFK+zccam8UfsTsJ YbdpeEQTHZUUh8ykv+/P8O4scg== X-Received: by 2002:a05:600c:4919:b0:3df:a04a:1a7 with SMTP id f25-20020a05600c491900b003dfa04a01a7mr13488556wmp.22.1676047178494; Fri, 10 Feb 2023 08:39:38 -0800 (PST) Received: from localhost.localdomain (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003da28dfdedcsm6312144wmq.5.2023.02.10.08.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 08:39:37 -0800 (PST) From: Jean-Philippe Brucker To: eric.auger@redhat.com Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org, ola.hugosson@arm.com, Jean-Philippe Brucker Subject: [PATCH 0/2] hw/arm/smmu: Fixes for TTB1 Date: Fri, 10 Feb 2023 16:37:30 +0000 Message-Id: <20230210163731.970130-1-jean-philippe@linaro.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Two small changes to support TTB1. Note that I had to modify the Linux driver in order to test this (see below), but other OSes might use TTB1. Jean-Philippe Brucker (2): hw/arm/smmu-common: Support 64-bit addresses hw/arm/smmu-common: Fix TTB1 handling hw/arm/smmu-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- 8< --- Linux hacks: 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 8d772ea8a583..bf0ff699b64b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -276,6 +276,11 @@ #define CTXDESC_CD_0_TCR_IRGN0 GENMASK_ULL(9, 8) #define CTXDESC_CD_0_TCR_ORGN0 GENMASK_ULL(11, 10) #define CTXDESC_CD_0_TCR_SH0 GENMASK_ULL(13, 12) +#define CTXDESC_CD_0_TCR_T1SZ GENMASK_ULL(21, 16) +#define CTXDESC_CD_0_TCR_TG1 GENMASK_ULL(23, 22) +#define CTXDESC_CD_0_TCR_IRGN1 GENMASK_ULL(25, 24) +#define CTXDESC_CD_0_TCR_ORGN1 GENMASK_ULL(27, 26) +#define CTXDESC_CD_0_TCR_SH1 GENMASK_ULL(29, 28) #define CTXDESC_CD_0_TCR_EPD0 (1ULL << 14) #define CTXDESC_CD_0_TCR_EPD1 (1ULL << 30) @@ -293,6 +298,7 @@ #define CTXDESC_CD_0_ASID GENMASK_ULL(63, 48) #define CTXDESC_CD_1_TTB0_MASK GENMASK_ULL(51, 4) +#define CTXDESC_CD_2_TTB1_MASK GENMASK_ULL(51, 4) /* * When the SMMU only supports linear context descriptor tables, pick a 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 f2425b0f0cd6..3a4343e60a54 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1075,8 +1075,8 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid, * this substream's traffic */ } else { /* (1) and (2) */ - cdptr[1] = cpu_to_le64(cd->ttbr & CTXDESC_CD_1_TTB0_MASK); - cdptr[2] = 0; + cdptr[1] = 0; + cdptr[2] = cpu_to_le64(cd->ttbr & CTXDESC_CD_2_TTB1_MASK); cdptr[3] = cpu_to_le64(cd->mair); /* @@ -2108,13 +2108,13 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, cfg->cd.asid = (u16)asid; cfg->cd.ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr; - cfg->cd.tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) | - FIELD_PREP(CTXDESC_CD_0_TCR_TG0, tcr->tg) | - FIELD_PREP(CTXDESC_CD_0_TCR_IRGN0, tcr->irgn) | - FIELD_PREP(CTXDESC_CD_0_TCR_ORGN0, tcr->orgn) | - FIELD_PREP(CTXDESC_CD_0_TCR_SH0, tcr->sh) | + cfg->cd.tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T1SZ, tcr->tsz) | + FIELD_PREP(CTXDESC_CD_0_TCR_TG1, tcr->tg) | + FIELD_PREP(CTXDESC_CD_0_TCR_IRGN1, tcr->irgn) | + FIELD_PREP(CTXDESC_CD_0_TCR_ORGN1, tcr->orgn) | + FIELD_PREP(CTXDESC_CD_0_TCR_SH1, tcr->sh) | FIELD_PREP(CTXDESC_CD_0_TCR_IPS, tcr->ips) | - CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64; + CTXDESC_CD_0_TCR_EPD0 | CTXDESC_CD_0_AA64; cfg->cd.mair = pgtbl_cfg->arm_lpae_s1_cfg.mair; /* @@ -2212,6 +2212,7 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain, .pgsize_bitmap = smmu->pgsize_bitmap, .ias = ias, .oas = oas, + .quirks = IO_PGTABLE_QUIRK_ARM_TTBR1, .coherent_walk = smmu->features & ARM_SMMU_FEAT_COHERENCY, .tlb = &arm_smmu_flush_ops, .iommu_dev = smmu->dev, diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 38434203bf04..3fe154c9782d 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -677,6 +677,10 @@ static int dma_info_to_prot(enum dma_data_direction dir, bool coherent, } } +/* HACK */ +#define VA_SIZE 39 +#define VA_MASK (~0ULL << VA_SIZE) + static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, size_t size, u64 dma_limit, struct device *dev) { @@ -706,7 +710,7 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift, true); - return (dma_addr_t)iova << shift; + return (dma_addr_t)iova << shift | VA_MASK; } static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie, @@ -714,6 +718,7 @@ static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie, { struct iova_domain *iovad = &cookie->iovad; + iova &= ~VA_MASK; /* The MSI case is only ever cleaning up its most recent allocation */ if (cookie->type == IOMMU_DMA_MSI_COOKIE) cookie->msi_iova -= size;