Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp182580pxj; Tue, 15 Jun 2021 23:26:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyav1yhO0wQuSjoC73Cdvn/PLZJEpZqm0nVtWlcvM2niPJo+Kb5+yr3YmMldQH6V8VfRZrD X-Received: by 2002:a17:907:6ef:: with SMTP id yh15mr3529256ejb.151.1623824767651; Tue, 15 Jun 2021 23:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623824767; cv=none; d=google.com; s=arc-20160816; b=QAPCoA7IKtfAA/osp9m40cpfSFz6MpdxX9PJLE0/wGOTMEVgVtQPs+b5j0Uhs+ZEy+ H0cBJIZaxER61rpQne0A7RN4gdfYAqFaBGQJc0iBV2KeZEdelsAD48IHCrNa77BXRKe+ m7eOhe//4kmANs+TZLC+MjdRBgOnWy3+2H2Htu4lOLbg1ioOWQIPaG07hjVm/OyJ83e4 vAwnpv8/Em9SukzR50mEjxG1PhfEn2WRyeFurxs0MlPtDPAMXwGX26wVVLE6GHHQGnSN aXEKLcW+gZfn9Mko32WocDeX7uFy2gXtv9snDdTLzOvEIkFdbkEqYkEReMgHdKTGPZp+ v4vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cTgFKnn3cLtvPfjI+55Cezw2EcnHDtp9/QQ3R2B3hUE=; b=fqCvO2uMgtfRHAZtk52/WybmmC1k8MFi0wcYG/3HdsWg9j18rExRkJqkFJ/Rr5hBsE xZmwBni/ly2XHioQLnE4rY6SMyBOuTAcX+8s1DUW+j91lu4CFVQIh/lB+asp8xuLlpRJ DSguiPVCbGVNK2nfB+PLALB7x/SJyGtt9Tqtq0ajfcnNSFaBYqLb40FyBGyuiSe6byMn EuQdZsushUhpOLFYDG/I/ZVDVyr2fjtvyo+pn0yEQ8FpDVIBSfDfo6sn0mc7pU2aHHcJ O14dHf40Rw95IZ5KCp8AaUlVGsQA/qnkVpGWhcjvx/mSvD1B6NtnMjH66b6gBATmI9fl 7+oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cyJuCSil; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i19si1196471edc.598.2021.06.15.23.25.45; Tue, 15 Jun 2021 23:26:07 -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=@chromium.org header.s=google header.b=cyJuCSil; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbhFPGZX (ORCPT + 99 others); Wed, 16 Jun 2021 02:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbhFPGZQ (ORCPT ); Wed, 16 Jun 2021 02:25:16 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D188AC061760 for ; Tue, 15 Jun 2021 23:23:09 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso1127148pjb.4 for ; Tue, 15 Jun 2021 23:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cTgFKnn3cLtvPfjI+55Cezw2EcnHDtp9/QQ3R2B3hUE=; b=cyJuCSilvPYniiPuEKQywgAZ2h40B6myx9TbQoS+O9qIihERcGr8FMpcEdjS0/tshr T6oF/Jqx7uEfUaJBG88Ds+6w77XhG2zyZ5Tn4UAWzJqH5XWwEFNMsFYg6ebrjJXldgCo SKPhXn/2f6RY0GqzhxLpDEImP7+pN5t8KYNM0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cTgFKnn3cLtvPfjI+55Cezw2EcnHDtp9/QQ3R2B3hUE=; b=UnuXOqwo3oI8qPNsC9rwYIQpt+dj2QLsYgAFE/XhtaTBwTcipBVstDSwouh6E7XvTZ +8m4bioc5PttNykYmxhvuZiQeGEcjmUfLqwrZ6afh4ZtUKkitKSp2OLgsk2f4dNKfo9m Gr8vRh9IkAeZsgOMJQ/kfoBDLR/iPSDpDzrP70GOiWm9JIH/vxOaqoQiKRte30YR9xL0 0y3Wybao6vVe2Esc2KH+jVviU94S1vmN1F63n6caI7qm2k2PA0JyYOa2we3/GbIgp7d0 0hGgKUyhwjhoVal4x82OMUOfz5M9ThnMn71/Yq2Z1en0MccrnzLokL37N5N32ql7/BZg Q+AQ== X-Gm-Message-State: AOAM531dMBHJ1eVBa5XuZbbR2sKTDKcGWhvPfcGkofJJqlgfC/8hokDT w63FGbZ/MjAG+mG9/HzFaFfPFQ== X-Received: by 2002:a17:90a:9511:: with SMTP id t17mr3458123pjo.108.1623824589397; Tue, 15 Jun 2021 23:23:09 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id f8sm960978pfv.73.2021.06.15.23.23.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:08 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Cc: benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, Robin Murphy , grant.likely@arm.com, xypron.glpk@gmx.de, Thierry Reding , mingo@kernel.org, bauerman@linux.ibm.com, peterz@infradead.org, Greg KH , Saravana Kannan , "Rafael J . Wysocki" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , tfiga@chromium.org, bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, tientzu@chromium.org, daniel@ffwll.ch, airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, jxgao@google.com, joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Subject: [PATCH v12 07/12] swiotlb: Move alloc_size to swiotlb_find_slots Date: Wed, 16 Jun 2021 14:21:52 +0800 Message-Id: <20210616062157.953777-8-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-1-tientzu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rename find_slots to swiotlb_find_slots and move the maintenance of alloc_size to it for better code reusability later. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig --- kernel/dma/swiotlb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index b5a9c4c0b4db..b59e689aa79d 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -431,8 +431,8 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, unsigned int index) * Find a suitable number of IO TLB entries size that will fit this request and * allocate a buffer from that IO TLB pool. */ -static int find_slots(struct device *dev, phys_addr_t orig_addr, - size_t alloc_size) +static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr, + size_t alloc_size) { struct io_tlb_mem *mem = dev->dma_io_tlb_mem; unsigned long boundary_mask = dma_get_seg_boundary(dev); @@ -487,8 +487,11 @@ static int find_slots(struct device *dev, phys_addr_t orig_addr, return -1; found: - for (i = index; i < index + nslots; i++) + for (i = index; i < index + nslots; i++) { mem->slots[i].list = 0; + mem->slots[i].alloc_size = + alloc_size - ((i - index) << IO_TLB_SHIFT); + } for (i = index - 1; io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && mem->slots[i].list; i--) @@ -529,7 +532,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr, return (phys_addr_t)DMA_MAPPING_ERROR; } - index = find_slots(dev, orig_addr, alloc_size + offset); + index = swiotlb_find_slots(dev, orig_addr, alloc_size + offset); if (index == -1) { if (!(attrs & DMA_ATTR_NO_WARN)) dev_warn_ratelimited(dev, @@ -543,11 +546,8 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr, * This is needed when we sync the memory. Then we sync the buffer if * needed. */ - for (i = 0; i < nr_slots(alloc_size + offset); i++) { + for (i = 0; i < nr_slots(alloc_size + offset); i++) mem->slots[index + i].orig_addr = slot_addr(orig_addr, i); - mem->slots[index + i].alloc_size = - alloc_size - (i << IO_TLB_SHIFT); - } tlb_addr = slot_addr(mem->start, index) + offset; if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) -- 2.32.0.272.g935e593368-goog