From nobody Tue Feb 10 06:08:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1623911298; cv=none; d=zohomail.com; s=zohoarc; b=GpuB93ZISLrRMzjIcMEafhh5CSZWX2f7RxD7Rf1exYdTs4dHWVdtCxwB9bi26jQYLBzoGOFbPJJr61PP1KDi+sTCSkhS4rH48OlJSXQ726KuwBPRv1mKqkg3fXr64Aemk2DN5Ou9SPBSWbzErKuGaoCKiOLp8HUZI/ckwho0A1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623911298; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EpbY4t1YqkHyM2/NW3gMAx4yclJU7uBbQcXCZDHmtKs=; b=Qmrs/wbB/x28y4hHLkCdauRgzxWyO+vZ0jnkTY1ozQm5W6NwyUP1WvZVxfRHmKc7HDsuSemoBCkg2b4iwh6QFpucsJnuiNG591sVhQN2yQ1V1HQP/E5KO7icQcoTVkGdHXAPc21+VcZyYQeY3wmpmC4IX8I5zexV/wIhwnRuWnU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1623911298104635.4782585443754; Wed, 16 Jun 2021 23:28:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.143642.264673 (Exim 4.92) (envelope-from ) id 1ltlVW-0005tn-1f; Thu, 17 Jun 2021 06:28:06 +0000 Received: by outflank-mailman (output) from mailman id 143642.264673; Thu, 17 Jun 2021 06:28:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltlVV-0005tc-U7; Thu, 17 Jun 2021 06:28:05 +0000 Received: by outflank-mailman (input) for mailman id 143642; Thu, 17 Jun 2021 06:28:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltlVV-0003Kj-B2 for xen-devel@lists.xenproject.org; Thu, 17 Jun 2021 06:28:05 +0000 Received: from mail-pg1-x529.google.com (unknown [2607:f8b0:4864:20::529]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cabf9e5d-2f18-44fd-a019-e817878ad45b; Thu, 17 Jun 2021 06:27:56 +0000 (UTC) Received: by mail-pg1-x529.google.com with SMTP id i34so4089468pgl.9 for ; Wed, 16 Jun 2021 23:27:56 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:e349:a6ae:d3d0:1621]) by smtp.gmail.com with UTF8SMTPSA id n72sm3947577pfd.8.2021.06.16.23.27.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Jun 2021 23:27:55 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cabf9e5d-2f18-44fd-a019-e817878ad45b 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=EpbY4t1YqkHyM2/NW3gMAx4yclJU7uBbQcXCZDHmtKs=; b=e8/y/1pyNps/ZK6IHXKXnhI106tF8+sDmAp4xvjDP1dmGFb5bTSm6j6t7NqNrsMO3B 4ffXhEra/SRTwvklP4KTuClY8LZOyfxrzvOiJDGX4UEO5rICKDNcf7JWVSUnF4DMCc0o WVIQGrd7NhuRQi9XYwZ7O9V8e1JGPFsrUx+Uw= 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=EpbY4t1YqkHyM2/NW3gMAx4yclJU7uBbQcXCZDHmtKs=; b=njja/+k1coXxuyEyhm6LrtYJtZ9+WnexkIHIrOySa5NhSeNyYnTSPpygRXw7hc8BTx eTdXxVNGiw6TA9Hk6ThdrnnSkKLvH9PsjaiT9LIJLtohFFJYzxtpTy8rXuW7/D21Ntmu kMgc2QopHvn/t+FZ/S3vPeMU9Z0j85mmXbToUFY9kZLRGBpHFlw0kSmViyVqLjUTLCYg 6cRswAG5X9N+B17kWVl+gMHwnAncPDDAmVzFc9B2RmlZT8CTwLpO6hY2Tkrx7rShU6er nDu4awJDZtlZwU/G6MSUfh4ux9XQ8jRcPxe0STwPQJzFw4BmpaebQNt57PSdEPcV7g3K 2thQ== X-Gm-Message-State: AOAM531ji83X/kfpvfEZAbxInJkZtzOKrHVJh8sOFjmb1d+pPc1Uh/KC Yr+KYWmpOvoxUT7s0pHbYKcAQQ== X-Google-Smtp-Source: ABdhPJxztQv+POqTC9QxexHqRq0v81bxjQesrgOuptpj83OtrETFUYQg5rDYRTVu/p7cUu8j7sfWFA== X-Received: by 2002:a62:31c3:0:b029:2fe:b554:6746 with SMTP id x186-20020a6231c30000b02902feb5546746mr1602855pfx.66.1623911275926; Wed, 16 Jun 2021 23:27:55 -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 08/12] swiotlb: Refactor swiotlb_tbl_unmap_single Date: Thu, 17 Jun 2021 14:26:31 +0800 Message-Id: <20210617062635.1660944-9-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: quoted-printable X-ZohoMail-DKIM: pass (identity @chromium.org) Content-Type: text/plain; charset="utf-8" Add a new function, swiotlb_release_slots, to make the code reusable for supporting different bounce buffer pools. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon --- kernel/dma/swiotlb.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 89049d021d0d..ff09341bb9f5 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -556,27 +556,15 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev= , phys_addr_t orig_addr, return tlb_addr; } =20 -/* - * tlb_addr is the physical address of the bounce buffer to unmap. - */ -void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, - size_t mapping_size, enum dma_data_direction dir, - unsigned long attrs) +static void swiotlb_release_slots(struct device *dev, phys_addr_t tlb_addr) { - struct io_tlb_mem *mem =3D hwdev->dma_io_tlb_mem; + struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; unsigned long flags; - unsigned int offset =3D swiotlb_align_offset(hwdev, tlb_addr); + unsigned int offset =3D swiotlb_align_offset(dev, tlb_addr); int index =3D (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT; int nslots =3D nr_slots(mem->slots[index].alloc_size + offset); int count, i; =20 - /* - * First, sync the memory before unmapping the entry - */ - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && - (dir =3D=3D DMA_FROM_DEVICE || dir =3D=3D DMA_BIDIRECTIONAL)) - swiotlb_bounce(hwdev, tlb_addr, mapping_size, DMA_FROM_DEVICE); - /* * Return the buffer to the free list by setting the corresponding * entries to indicate the number of contiguous entries available. @@ -611,6 +599,23 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, ph= ys_addr_t tlb_addr, spin_unlock_irqrestore(&mem->lock, flags); } =20 +/* + * tlb_addr is the physical address of the bounce buffer to unmap. + */ +void swiotlb_tbl_unmap_single(struct device *dev, phys_addr_t tlb_addr, + size_t mapping_size, enum dma_data_direction dir, + unsigned long attrs) +{ + /* + * First, sync the memory before unmapping the entry + */ + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && + (dir =3D=3D DMA_FROM_DEVICE || dir =3D=3D DMA_BIDIRECTIONAL)) + swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_FROM_DEVICE); + + swiotlb_release_slots(dev, tlb_addr); +} + void swiotlb_sync_single_for_device(struct device *dev, phys_addr_t tlb_ad= dr, size_t size, enum dma_data_direction dir) { --=20 2.32.0.288.g62a8d224e6-goog