From patchwork Tue Oct 29 03:39:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 839317 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4593:b0:37d:45d0:187 with SMTP id gb19csp158705wrb; Mon, 28 Oct 2024 20:39:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVWQzBQlaoZraUolThEf7kREXHLeGGaPCFYDoNX1lZ4K3NebgvhKvFpSKcf+nUQDjEpWZFUhg==@linaro.org X-Google-Smtp-Source: AGHT+IHuGkZOjvGq6mOigbboU4+2FwGSYE8zXSyeKDV4sEyUleSof2rwSIiBWmynWasFu5LBPBub X-Received: by 2002:a5d:6603:0:b0:37c:cce8:4acc with SMTP id ffacd0b85a97d-38159d83653mr387357f8f.13.1730173185553; Mon, 28 Oct 2024 20:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1730173185; cv=none; d=google.com; s=arc-20240605; b=KHzEFxAcyLg5FtSqszQhJp1tW727rgMlTLgNS2dG8RUW+TKOFfj/AtZnXiUDVXOBT3 3Ee1qh40EHhwA1wxyzqk4onMTuCaY26P9o7C2oTb/b/UE74oHDT6MVC5kO9Psdor91O+ 8UlHDTpOExbLw0xcykeRB2Wl5je954ZENVM2ZH79+pY4wgwLJCOnDkn6HEtYO72sDnyB f+yVWxbjlWmSgb5MHOs7cjKBZ0G9xkj+GbQ1SGhjs8OBfXpvxeUGZkEVXBhi4EYYMt2D FM4CakbE0S48CPtZtl9gBjcEhm2QNKs3zQ5kiwbdwOvW/BufXAGT+Fupk5Huux2ITsgL bLRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=+/ouZ/EXiVDURGZaXVX7kajs6y28iqcI1c1ot0sKLqI=; fh=OxxVRYIH4L4eYe/dMxxa1SHIXOF10gIqAtiKzoQmGVc=; b=PL1e0S5ntaqr80LTtGZzBuuWQzPXmfGjjEkJwtpds+VqnmOBNUf9LV7MwbzbVSWzax ROj/Ycf2zk064tnsw+jAk5unRJ9QkiA8K+BeE2mSgs8ZjTS+EdOF5AuUt4MMa85q0v9v LwNd2OZtH7h1c7txC1oWahf1eFWRcaF7z9ZVDWBpBDLUnTRoPy/nDneGyFxMgONN0SN7 9tXZhA+jq3yQjP267anpNCBCl22DceaH7M1t6vIeyVK6Ah3q8uwBdzH3w1y1/A6L8GMI FBjpvy/TDjhwKM64fDwmBXzp4GfRESmXC3zlnrsMQXo+HVSuBVkkw5ZhuUadQtWKYorY 1A9A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38058bd213bsi5171303f8f.975.2024.10.28.20.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 20:39:45 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 75C3A8915D; Tue, 29 Oct 2024 04:39:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 4558389167; Tue, 29 Oct 2024 04:39:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 3124E89112 for ; Tue, 29 Oct 2024 04:39:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3014713D5; Mon, 28 Oct 2024 20:40:10 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8DA143F66E; Mon, 28 Oct 2024 20:39:38 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Janne Grunau , Mark Kettenis , Tom Rini , Sughosh Ganu Subject: [RFC PATCH] apple: dart: add logic to allocate dva addresses Date: Tue, 29 Oct 2024 09:09:15 +0530 Message-Id: <20241029033915.423211-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The Apple IOMMU driver uses LMB API's to allocate virtual addresses for IO devices. These virtual addresses fall in the first 4GB address range. Currently, the driver obtains these virtual addresses through the LMB API's. This no longer works with the global LMB map. Add a function apple_dart_dvaalloc() which mimics what was being done by the LMB allocation function. Signed-off-by: Sughosh Ganu --- Note: I have only build tested this on the m1 defconfig. drivers/iommu/apple_dart.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/apple_dart.c b/drivers/iommu/apple_dart.c index 611ac7cd6de..8e2acf50a06 100644 --- a/drivers/iommu/apple_dart.c +++ b/drivers/iommu/apple_dart.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -75,6 +74,7 @@ struct apple_dart_priv { dma_addr_t dvabase; dma_addr_t dvaend; + dma_addr_t dvaalloc; int nsid; int nttbr; @@ -109,6 +109,21 @@ static void apple_dart_t8110_flush_tlb(struct apple_dart_priv *priv) continue; } +static dma_addr_t apple_dart_dvaalloc(struct udevice *dev, phys_size_t size) +{ + dma_addr_t dva; + struct apple_dart_priv *priv = dev_get_priv(dev); + + dva = priv->dvaalloc - size; + dva &= ~(DART_PAGE_SIZE - 1); + + assert(dva > priv->dvabase); + + priv->dvaalloc = dva; + + return priv->dvaalloc; +} + static dma_addr_t apple_dart_map(struct udevice *dev, void *addr, size_t size) { struct apple_dart_priv *priv = dev_get_priv(dev); @@ -123,7 +138,7 @@ static dma_addr_t apple_dart_map(struct udevice *dev, void *addr, size_t size) off = (phys_addr_t)addr - paddr; psize = ALIGN(size + off, DART_PAGE_SIZE); - dva = lmb_alloc(psize, DART_PAGE_SIZE); + dva = apple_dart_dvaalloc(dev, psize); idx = dva / DART_PAGE_SIZE; for (i = 0; i < psize / DART_PAGE_SIZE; i++) { @@ -158,8 +173,6 @@ static void apple_dart_unmap(struct udevice *dev, dma_addr_t addr, size_t size) flush_dcache_range((unsigned long)&priv->l2[idx], (unsigned long)&priv->l2[idx + i]); priv->flush_tlb(priv); - - lmb_free(dva, psize); } static struct iommu_ops apple_dart_ops = { @@ -211,8 +224,7 @@ static int apple_dart_probe(struct udevice *dev) priv->dvabase = DART_PAGE_SIZE; priv->dvaend = SZ_4G - DART_PAGE_SIZE; - - lmb_add(priv->dvabase, priv->dvaend - priv->dvabase); + priv->dvaalloc = priv->dvaend; /* Disable translations. */ for (sid = 0; sid < priv->nsid; sid++)