Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp169167pxj; Wed, 16 Jun 2021 23:29:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwx89zgRawAoyvuO9PjCEkZJ5Pm0ATuwt1c3GF41EsjfsTq9P+VvqSzMRx84SCgiHq9KO3 X-Received: by 2002:a6b:6b0b:: with SMTP id g11mr2514574ioc.112.1623911394442; Wed, 16 Jun 2021 23:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623911394; cv=none; d=google.com; s=arc-20160816; b=af9x0i2RC8LjPjCyRpck0CIqn1FP9WRUhQ+ymbvoTyGXh2UhWib9k1Rluj0aEJLoQp g3V+jExqez8T1zLMXeNxu611U8dyrNqoXYujx1Yce2D/4TeK1Bdjpt10onrd7H7rm920 /8DNUZSUC8ancy5OS4MWo3xEBHMOCFo2huPMfJwsGeenHCZZ7H6rqlBdZHru0g4S9paa SZtiwSjU0jRoRRX29Dx5TXyoLAmmt6TyoirN/B9N0J0Y0y5ZeX7bCXRj/ZgzF3LCwEON QH5+CxqBBGlU3nC4K/c98hmaVzvcmeXXTNbm31Kno99NDmQoBEzylcwJn+esL+tzSV+i qxfQ== 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=vL93q1YbKGNvBEIa7UrABp5ApsQUTAD5UUYTnsdEB3Q=; b=TzXJ9hALf7SGxoo9yNClg0y/2weujaVDgJBbfbuahpOjxJ2vvPVdDCO0Pxrwfon87m oKTjAyGHkLNlYTNcs6lPTtLfqAUD8KV7v8wt0fb7yn0G25Z+GhC9L+3HViouRwJNbB/E uEZ6mb1iPPUXQM7yX8vji1O1zUnAg+AmFanDTcTjOFo6kMEg3AivtQvE7edCccQr890g 5SHkYySbyW9zAs+EbSKb79AXVsIRMElyRnZe+isnfTmlLGEOcBNc8OgkJbUNFj6F8cVa bYdpChT5eEEFLHRIMaJlN7pb0l9MQ5KqC42Sdv580SbcUh6P5EhLqX+hLivSUDSKY2Z7 pqEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CtB2mooE; 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 p16si4728990ioh.24.2021.06.16.23.29.41; Wed, 16 Jun 2021 23:29:54 -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=CtB2mooE; 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 S229580AbhFQG36 (ORCPT + 99 others); Thu, 17 Jun 2021 02:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbhFQG3z (ORCPT ); Thu, 17 Jun 2021 02:29:55 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B85C061760 for ; Wed, 16 Jun 2021 23:27:47 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id p13so4225892pfw.0 for ; Wed, 16 Jun 2021 23:27:47 -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=vL93q1YbKGNvBEIa7UrABp5ApsQUTAD5UUYTnsdEB3Q=; b=CtB2mooENzTC4i0L5rpa1zNICqjYFPsIZqEbEkBKAJa8+qd9w2N9/n64NCFrt9j45u Ih26Uj+R6NzicgrImuSogNhtDWEP6supbvO5mJkr1dAyUpDH0cFI8DnqnJG9Y3c4jeK7 STp7xwS/W8U1n8UjbDMotkZIyUJH71Vl6CqRE= 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=vL93q1YbKGNvBEIa7UrABp5ApsQUTAD5UUYTnsdEB3Q=; b=Br/ez3zkmkDtpjxegL3u7I1BmvBFX9g7pAdWkam7hba1u7TEolGGs0K2cV5SG9Eh1T GDBZYiE0g6uoZtrTThc0DWVuYDkEP45IBA5svcngTS2VhRh/E3//Q08vtC8DCY47/ggK az/Xc0hFDvuqW1tPRzqtpQwqlrI6WQCroUYRXVv9GGOKGTuo28eqXKBnaa60XSTCeEor hX8l+Ri0rh9q2BJKWZvBlyPbByR2WA92SlzQpEwMffjO9dDm0Ob3AJx5VW+0+gHRHMVZ k49YxteJP5uoxV5ZeQUD10kUwpbvnUdmI5us364U5xh+tiaxeKMn06KiVVoyLLWvBL4E PDLg== X-Gm-Message-State: AOAM5312Vt/N6NqkA+IuueINr9iKfcnxqJAA4OiUE+X+4N4v1z+l8b/w UWDbUuKVX647g6CoklUTXuddzg== X-Received: by 2002:a05:6a00:b8a:b029:2ec:761e:33e3 with SMTP id g10-20020a056a000b8ab02902ec761e33e3mr3577341pfj.35.1623911267361; Wed, 16 Jun 2021 23:27:47 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:e349:a6ae:d3d0:1621]) by smtp.gmail.com with UTF8SMTPSA id b5sm802199pgh.41.2021.06.16.23.27.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Jun 2021 23:27:46 -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 v13 07/12] swiotlb: Move alloc_size to swiotlb_find_slots Date: Thu, 17 Jun 2021 14:26:30 +0800 Message-Id: <20210617062635.1660944-8-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210617062635.1660944-1-tientzu@chromium.org> References: <20210617062635.1660944-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 13891d5de8c9..89049d021d0d 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