Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp335363pxv; Thu, 24 Jun 2021 08:58:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1Q1GFuFC5cJXlMXG1uGuh7JHoWTv5j0X66Hh4BOM16VuiXbpOE3kJw/fMDUA4hfPI1OOo X-Received: by 2002:a05:6402:886:: with SMTP id e6mr8188208edy.33.1624550319834; Thu, 24 Jun 2021 08:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624550319; cv=none; d=google.com; s=arc-20160816; b=szoglq3/sCvB/7s8zIJdh1JFJwKPtEiBDWiXH+t4GtDiHGMrhl5C3aDsAynLglh4m8 yfLbcKldXpvUos1iyF5JGqCJHOA++zYZyJ8vZF5N9+D4AsG+WwnfwwiNd4ZLMvbK2/4X 169y9ROMePUzbq/cM+GasZsDZHDlC9SmJaqsfOhKX/Bvg37PNPb++DbxJelQFRcNjfWW 3aO1K5ms9654/Xre7eQymrRtAbKmOOGBiF1clj8E4k2kE6so1twGrBfgDgLyR5PMRLMD gzF2PXL/cS/J/t+75hPMSCE8/y5CxRltWG1el8NRuBqwTkvdSrnVAc4UV48MIDxcN1Oe 3ZOA== 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=k2v4ULCUV3P/ZykooMt4RnFrTyFS8LVxGS67nnIjZ/E=; b=AwmF0mb64uHz8eeq9WoiYB03hbLjyUR++igSc6ImnPZd57HyIRN9BmP+UIpGq6kqOa Ji8xokibajCD9997e9lbQA88OlWogmaHrDfG6aCObsx81z6FVUMKXutSJnO9RLuVT5CF 6aKr7iPfZefLtALF45hO9rzZvgkrLXHoLzRZE12UMmCeXfzlsVaEmWMkxt4koyQZGfc8 8Qsk2a9a17LQumGmpgVIrmEZI9i550R36eeDs5FgrrvKzdQgB64KWqGq0MlUHoKi++Ai iSGQzbRbk6D/l5vJlNFo86apdpwN5T5P4s9L8GIjB+x0NZjjvtcizNMxTgge/n3DeoBX AxpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QrT3tJse; 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 m13si3129801ejl.589.2021.06.24.08.58.15; Thu, 24 Jun 2021 08:58:39 -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=QrT3tJse; 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 S232543AbhFXP7D (ORCPT + 99 others); Thu, 24 Jun 2021 11:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbhFXP7C (ORCPT ); Thu, 24 Jun 2021 11:59:02 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61CA7C061574 for ; Thu, 24 Jun 2021 08:56:42 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id p4-20020a17090a9304b029016f3020d867so3762942pjo.3 for ; Thu, 24 Jun 2021 08:56:42 -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=k2v4ULCUV3P/ZykooMt4RnFrTyFS8LVxGS67nnIjZ/E=; b=QrT3tJse9UwGIKHlr8MsnQ/5shpb9vzqfj7YMQ2fYijn7FCRoIijuokKPkX0W4emjg zIW9mO8KXkFug0OUuL1YqRloVsCf7/HNDUAAE7RH/8xRS3Mt1GINoLA/1NQjeCh/6ZZs IZdWLInrLmUEvcR0rzL0waTaUCb67EWeMYbx0= 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=k2v4ULCUV3P/ZykooMt4RnFrTyFS8LVxGS67nnIjZ/E=; b=p3PIfkwjhZCtK70HdL6CsSbiZ/xAJLgF3vYYMwO8LT5ZK3sQHk8Gqftp9eyLuHee6d uPc3LzeXAh0qhuEzJ2Mz+jp8e9lsZfiUEaZ3FAytBz70ci1WNNNCrrcZLQPHu8zhwsy+ poIHYyKfEu9vVeutwFf4L46vBFNl1X41gbnsnabyPua9tfwy1R1qfSfqLAbMhTNBUWTH CkK+mYLnUdXNT9DoAbX6qTeQWHQYJNMQEtZI9sj/rljMHouCXfaD4hK14VqBvFwfCJQK ZY19H9z/5nP3WtPCRAfZbVszNCT65OnUCM93lRddEHzNCdUSrV9Q11+JMrR+zMiVAp0o TKdA== X-Gm-Message-State: AOAM531S5n1Eorh51I89jhE19cLJOVWQ3Pq5ITX4jJMTnK8ioHvlyJW2 zuUARJEUZQ+JAH/FNwr5OFCc8w== X-Received: by 2002:a17:90b:1bc6:: with SMTP id oa6mr15922344pjb.151.1624550201945; Thu, 24 Jun 2021 08:56:41 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id t13sm3434704pfq.173.2021.06.24.08.56.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:56:41 -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, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 07/12] swiotlb: Move alloc_size to swiotlb_find_slots Date: Thu, 24 Jun 2021 23:55:21 +0800 Message-Id: <20210624155526.2775863-8-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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 Tested-by: Stefano Stabellini Tested-by: Will Deacon --- kernel/dma/swiotlb.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 0d294bbf274c..b41d16e92cf6 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -432,8 +432,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); @@ -444,6 +444,7 @@ static int find_slots(struct device *dev, phys_addr_t orig_addr, dma_get_min_align_mask(dev) & ~(IO_TLB_SIZE - 1); unsigned int nslots = nr_slots(alloc_size), stride; unsigned int index, wrap, count = 0, i; + unsigned int offset = swiotlb_align_offset(dev, orig_addr); unsigned long flags; BUG_ON(!nslots); @@ -488,8 +489,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 - (offset + ((i - index) << IO_TLB_SHIFT)); + } for (i = index - 1; io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && mem->slots[i].list; i--) @@ -530,7 +534,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, @@ -544,11 +548,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.288.g62a8d224e6-goog