Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2088543pxj; Sat, 19 Jun 2021 02:34:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwx03xxBo9/Wx8qU52/SqITbwljdDxQr68dOOkhUQEm0goPJVXYGKZmkYjE3gNbi/iSxWQt X-Received: by 2002:aa7:de90:: with SMTP id j16mr9821582edv.385.1624095247692; Sat, 19 Jun 2021 02:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624095247; cv=none; d=google.com; s=arc-20160816; b=Krv388zUh8L5OCI2PoqdQHF41vkRhnGOGt63UxfQti1saTqdCb/cq0wWmZbrmEPvl1 s8qJPXx4qqlU8cztw02OGPBJaulVspO9PGvd2rIYufwIURsUDCunzs5v6fATjATgGupj DddWG1UplI50fmjM1bXXKh1+B71AfjToTV7x+6Ndequ0WjZUibhTCED10I20hU9PlI1f 8862SzxB2kDM9EAvO1azxPuqZJxPikyKZjdSGiQfmypu5pI02IVfCpqx+Hqhse3mXmUe g52ruV+5vt140nk294zGRv/PpXKK//gAwpZCtPwyHGk8ZBjJFzzesiOIicvlcMC2QuS7 mfBQ== 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=yBt4hQLYm3mqRXyO6Ue9ozYRrGCBFDovL1RqQBClg04=; b=duWDIYo5oF0IFR58vOYtXEtSZgAW5m9oIZ5OiGq7hEkM0R7sImZ6sZD/4pXdahHBfT jfU9jadHiYvXv2Atd1U+ZGKtWOmdFcp/d6zU6kOo4zVsip1dLZBsShBh3w4hPtf1CABY BGwy/Up3p5Ks+HQWEjwrAmDvpaMXj7S8y1uKnRzdectMleI7gs2vbOLUol2Nvt4r/isW a6ckBs6H7tA6WJd9eukPUOnTF5EqUpdPF1v3wO/Jr8uR5A3mdfCUlc1jCd0vdPEuTFWV bAlWcIQjVNFA9AJ8HPvhZjz5v77Ku8tWS6Ig3U/533hF0uKnTH6x02oMBUL4BH2aYbMQ raGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kUc0aW3N; 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 yl23si4980476ejb.359.2021.06.19.02.33.45; Sat, 19 Jun 2021 02:34: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=kUc0aW3N; 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 S235788AbhFSDor (ORCPT + 99 others); Fri, 18 Jun 2021 23:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235723AbhFSDo2 (ORCPT ); Fri, 18 Jun 2021 23:44:28 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA659C0611C1 for ; Fri, 18 Jun 2021 20:41:57 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id y4so2232418pfi.9 for ; Fri, 18 Jun 2021 20:41:57 -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=yBt4hQLYm3mqRXyO6Ue9ozYRrGCBFDovL1RqQBClg04=; b=kUc0aW3NrRDs5U6B12hrWDg0XWc0HZESQnTqGuqF1lOwto9c+7mt8gkEytThboQsHz XLan+5H8MDt3PRVY3ReT+qPhu28xh6wjPY72lJEd12tdFryWy7Q2zgQsEGYf4tF3oitf PfRsCwU9hKassTMBsMhc64Ic4q5xVPJYHDueg= 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=yBt4hQLYm3mqRXyO6Ue9ozYRrGCBFDovL1RqQBClg04=; b=gI4w+v+Uj6eoyC349KynsFVLDT11mhtvBIWzIG686Mj/qxBrgoe8k84UyBgrgGw7NN bqw4d5ILelJK7XPuKrc2LxO/y1qVPnm3gE2anbw8Zqbznfe0C/IGK3INbZ9rk7and72f l3jirabg7G1c1rKaBFt7azA/iu3oB3rvqFUY8oFl+8qy0D9+1hR/jMFSuQ1fe36lqHn6 QMjGl0fdShKjgZix1lJrcEPFVMH5xQ5CTyxaQqPUqXr/xlagFxRQvfKyACgVuAfc0TM4 DemZ1BRxSjr7nEQ64kG5ilBGA7lzYaD/5TT5T1EmeG8lxmiW1Ocaqxr8trqlYAoptzKj KK2A== X-Gm-Message-State: AOAM533+z78Abw9qh6/P3rpC4GTE8UY6Lr2id9GOUVhcOjTWsxpC0kpj xQlQZjEJZK/hP8ucAftfbj1Vdg== X-Received: by 2002:a63:dd4a:: with SMTP id g10mr12899661pgj.144.1624074117138; Fri, 18 Jun 2021 20:41:57 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:4a46:e208:29e8:e076]) by smtp.gmail.com with UTF8SMTPSA id d8sm9801812pfq.198.2021.06.18.20.41.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Jun 2021 20:41:56 -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 Subject: [PATCH v14 07/12] swiotlb: Move alloc_size to swiotlb_find_slots Date: Sat, 19 Jun 2021 11:40:38 +0800 Message-Id: <20210619034043.199220-8-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210619034043.199220-1-tientzu@chromium.org> References: <20210619034043.199220-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 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 0d294bbf274c..daf38a52e66d 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); @@ -488,8 +488,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--) @@ -530,7 +533,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 +547,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