Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp168636pxj; Wed, 16 Jun 2021 23:29:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHX9XvvS6Q1Ti62vr4Wh052brUdzqe84B3tZOWua27K6B3CXZopOa6gH8Nc8kZOTm868kX X-Received: by 2002:a05:6e02:c6b:: with SMTP id f11mr2341586ilj.140.1623911342311; Wed, 16 Jun 2021 23:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623911342; cv=none; d=google.com; s=arc-20160816; b=MIRGDVheoF52/3dO19xgdsDodEZU2/AO+4CXzxrYY/J3BGI+i+FTC6maLj3prubfEr Glad89lesNqPt4T5EY/vs09JiR8IrAqvykUARk4nlaleiPf9lX2rxPjm6t02axGM9ePM HTTQdI1Y9uzzxYfQAm4NL5Wj22z5IQFuFp2HX1wtcfubw+9aqQkS6DPp76NqNLTSPD1L Dz5K5oBPTT1wlujaSAiED6+BPs5qolygtNN7+oApDmFms+93sGrYY6iPdamqVnwnuWY3 phWeWgBHYlpgWi0uEC7riVAigUnXnUe+lEMcXQyabvmfNt7ILVBTGnd8AkHtylFvz/Aq Q6Zw== 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=EpbY4t1YqkHyM2/NW3gMAx4yclJU7uBbQcXCZDHmtKs=; b=nnxvKjFvIwUhJ5NVRCA0KQDNRUm3kgte2ye6xNL0ckk6sUtacSk6CCiUmc481HEAQm uHQY19F4w7FlIGIX0NiRbw5K5nxqcoZ+j06oDYNiKCtNPHtAtgEQ8J8M3svBIkl+CnrL g9ICluyOCF44Gd25eFZXRee85j45jXVQedQsTYf2UZtEkOilaenNv4cFmQ7uTjZYiwEW qHmRLCS/O00th7ODRMiHvcjCDKgjJPaZ/n3OlsP0DktmgDOWiONp1SskaQO7zbYRUTcj kXBlMpfvxLijbQe3b3VYWkrn5+ngbUtqHhHuR5aTlpeQKBjc1t7mE/55FkhWWlfBWJzz g1hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="e8/y/1py"; 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 8si5768075jao.112.2021.06.16.23.28.50; Wed, 16 Jun 2021 23:29:02 -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="e8/y/1py"; 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 S229560AbhFQGaG (ORCPT + 99 others); Thu, 17 Jun 2021 02:30:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230351AbhFQGaD (ORCPT ); Thu, 17 Jun 2021 02:30:03 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 637FBC06175F for ; Wed, 16 Jun 2021 23:27:56 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id t9so4097544pgn.4 for ; Wed, 16 Jun 2021 23:27:56 -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=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=mwe4QvLOyVxy1nf6UQb6pomkpacIhqNDDMt7D4u+vrRj9gNzMbsEvUNJhyeku/XPzL 8dpmDBJgLGwmt4rafvxZJNGwmkrrug9lSuZo1ZJLBcqEzDi/NEyUddeSgKAxOG7oBh4y RF4SY3w0L70rpERdQEeAayCy3pOgs3gCrLhDuYQu4Z4MoveXfxgNYnph0CGSDu+VQerh z3/eCCPU1d1pFVw6H31YEOFYANIHvFlVoF43t8hb8BUfslq5sqpey/QIMyJA6YMcIKyv VnRjuayl3udO+kA7I3Z4NtM9Ht9AtgC30c2HJy7A4DhP9lXmvRPBDatYqJcpQdr0Q62s KKdw== X-Gm-Message-State: AOAM531/go56YHoES1HK2bZWuEC0nxJ5bAD6wzJwbGt6QJ6ECnN/DpaF b04/chblzTzwNg5/K0K0C9eg4Q== 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) 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) 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: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -/* - * 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 = hwdev->dma_io_tlb_mem; + struct io_tlb_mem *mem = dev->dma_io_tlb_mem; unsigned long flags; - unsigned int offset = swiotlb_align_offset(hwdev, tlb_addr); + unsigned int offset = swiotlb_align_offset(dev, tlb_addr); int index = (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT; int nslots = nr_slots(mem->slots[index].alloc_size + offset); int count, i; - /* - * First, sync the memory before unmapping the entry - */ - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && - (dir == DMA_FROM_DEVICE || dir == 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, phys_addr_t tlb_addr, spin_unlock_irqrestore(&mem->lock, flags); } +/* + * 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 == DMA_FROM_DEVICE || dir == 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_addr, size_t size, enum dma_data_direction dir) { -- 2.32.0.288.g62a8d224e6-goog